init repo

This commit is contained in:
nikolay ivanov
2014-07-05 18:22:49 +00:00
commit a8be6b9e72
17348 changed files with 9229832 additions and 0 deletions

View File

@@ -0,0 +1,282 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using System;
using System.Net;
using System.Configuration;
using System.Web;
using System.Web.Routing;
using System.IO;
using System.Text;
using Microsoft.Win32;
using FileConverterUtils2;
using log4net;
public class FontServiceRoute : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new FontService(requestContext);
}
}
public class FontService : IHttpAsyncHandler
{
private readonly ILog _log = LogManager.GetLogger(typeof(FontServiceRoute));
private string m_sFontName = null;
private readonly static System.Collections.Generic.Dictionary<string, string> m_mapFontNameToFullPath;
static FontService()
{
m_mapFontNameToFullPath = new System.Collections.Generic.Dictionary<string, string>();
DirectoryInfo dirWindowsFolder = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System));
string sWinFontDir = Path.Combine(dirWindowsFolder.FullName, "Fonts");
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts");
if (null == key)
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts");
if (null != key)
{
string[] aValues = key.GetValueNames();
for (int i = 0, length = aValues.Length; i < length; i++)
{
string sCurPath = key.GetValue(aValues[i]) as string;
if (null != sCurPath && !string.IsNullOrEmpty(sCurPath))
{
if (Path.IsPathRooted(sCurPath))
m_mapFontNameToFullPath[Path.GetFileName(sCurPath).ToUpper()] = sCurPath;
else
m_mapFontNameToFullPath[sCurPath.ToUpper()] = Path.Combine(sWinFontDir, sCurPath);
}
}
}
}
public FontService(RequestContext context)
{
m_sFontName = Convert.ToString(context.RouteData.Values["fontname"]);
}
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
{
bool bStartAsync = false;
try
{
_log.Info("Starting process request...");
_log.Info("fontname: " + m_sFontName);
context.Response.Clear();
context.Response.Cache.SetExpires(DateTime.Now);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.ContentType = Utils.GetMimeType(m_sFontName);
if (context.Request.ServerVariables.Get("HTTP_USER_AGENT").Contains("MSIE"))
context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + context.Server.UrlEncode(m_sFontName) + "\"");
else
context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + m_sFontName + "\"");
string sConfigFontDir = ConfigurationManager.AppSettings["utils.common.fontdir"];
string strFilepath;
if (null != sConfigFontDir && string.Empty != sConfigFontDir)
strFilepath = Path.Combine(Environment.ExpandEnvironmentVariables(sConfigFontDir), m_sFontName);
else
m_mapFontNameToFullPath.TryGetValue(m_sFontName.ToUpper(), out strFilepath);
if (".js" == Path.GetExtension(m_sFontName))
{
string[] aFontExts = {".ttf", ".ttc", ".otf"};
for(int i = 0; i < aFontExts.Length; i++)
{
strFilepath = Path.ChangeExtension(strFilepath, aFontExts[i]);
if (File.Exists(strFilepath))
break;
}
}
FileInfo oFileInfo = new FileInfo(strFilepath);
if (oFileInfo.Exists)
{
DateTime oLastModified = oFileInfo.LastWriteTimeUtc;
string sETag = oLastModified.Ticks.ToString("x");
DateTime oDateTimeUtcNow = DateTime.UtcNow;
if (oLastModified.CompareTo(oDateTimeUtcNow) > 0)
{
_log.DebugFormat("LastModifiedTimeStamp changed from {0} to {1}", oLastModified, oDateTimeUtcNow);
oLastModified = oDateTimeUtcNow;
}
string sRequestIfModifiedSince = context.Request.Headers["If-Modified-Since"];
string sRequestETag = context.Request.Headers["If-None-Match"];
bool bNoModify = false;
if (false == string.IsNullOrEmpty(sRequestETag) || false == string.IsNullOrEmpty(sRequestIfModifiedSince))
{
bool bRequestETag = true;
if (false == string.IsNullOrEmpty(sRequestETag) && sRequestETag != sETag)
bRequestETag = false;
bool bRequestIfModifiedSince = true;
if (false == string.IsNullOrEmpty(sRequestIfModifiedSince))
{
try
{
DateTime oRequestIfModifiedSince = DateTime.ParseExact(sRequestIfModifiedSince, "R", System.Globalization.CultureInfo.InvariantCulture);
if ((oRequestIfModifiedSince - oLastModified).TotalSeconds > 1)
bRequestIfModifiedSince = false;
}
catch
{
bRequestIfModifiedSince = false;
}
}
if (bRequestETag && bRequestIfModifiedSince)
{
context.Response.StatusCode = (int)HttpStatusCode.NotModified;
bNoModify = true;
}
}
if (false == bNoModify)
{
context.Response.Cache.SetETag(sETag);
context.Response.Cache.SetLastModified(oLastModified);
FileStream oFileStreamInput = new FileStream(strFilepath, FileMode.Open, FileAccess.Read, FileShare.Read, (int)oFileInfo.Length, true);
byte[] aBuffer = new byte[oFileStreamInput.Length];
TransportClass oTransportClass = new TransportClass(context, cb, oFileStreamInput, aBuffer);
oFileStreamInput.BeginRead(aBuffer, 0, aBuffer.Length, ReadFileCallback, oTransportClass);
bStartAsync = true;
}
}
else
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
}
catch(Exception e)
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
_log.Error(context.Request.Params.ToString());
_log.Error("Exeption catched in BeginProcessRequest:", e);
}
TransportClass oTempTransportClass = new TransportClass(context, cb, null, null);
if (false == bStartAsync)
cb(new AsyncOperationData(oTempTransportClass));
return new AsyncOperationData(oTempTransportClass);
}
public void EndProcessRequest(IAsyncResult result)
{
}
public void ProcessRequest(HttpContext context)
{
throw new InvalidOperationException();
}
public bool IsReusable
{
get
{
return false;
}
}
private void ReadFileCallback(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
HttpContext context = oTransportClass.m_oContext;
try
{
FileStream oFileStreamInput = oTransportClass.m_oFileStreamInput;
oTransportClass.nReadWriteBytes = oFileStreamInput.EndRead(result);
oFileStreamInput.Dispose();
if (oTransportClass.nReadWriteBytes <= 0)
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
else
{
byte[] aOutput = null;
if (".js" == Path.GetExtension(m_sFontName))
{
aOutput = GetJsContent(oTransportClass.m_aBuffer);
oTransportClass.nReadWriteBytes = aOutput.Length;
}
else
aOutput = oTransportClass.m_aBuffer;
context.Response.OutputStream.BeginWrite(aOutput, 0, aOutput.Length, WriteBufferCallback, oTransportClass);
}
}
catch (Exception e)
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
_log.Error("Exception catched in ReadFileCallback:", e);
}
}
private void WriteBufferCallback(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
HttpContext context = oTransportClass.m_oContext;
try
{
context.Response.OutputStream.EndWrite(result);
context.Response.AddHeader("Content-Length", oTransportClass.nReadWriteBytes.ToString());
context.Response.StatusCode = (int)HttpStatusCode.OK;
context.Response.Flush();
context.Response.End();
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
catch (Exception e)
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
_log.Error("Exception catched in WriteBufferCallback:", e);
}
}
private byte[] GetJsContent(byte[] aBuffer)
{
string data = Convert.ToBase64String(aBuffer);
string sRes = string.Format("var __font_data1=\"{0}\";var __font_data1_idx = g_fonts_streams.length;g_fonts_streams[__font_data1_idx] = CreateFontData2(__font_data1,{1});__font_data1 = null;g_font_files[1].SetStreamIndex(__font_data1_idx);", data, aBuffer.Length);
return Encoding.UTF8.GetBytes(sRes);
}
private class TransportClass
{
public HttpContext m_oContext;
public AsyncCallback m_oCallback;
public FileStream m_oFileStreamInput;
public byte[] m_aBuffer;
public int nReadWriteBytes;
public TransportClass(HttpContext oContext, AsyncCallback oCallback, FileStream oFileStreamInput, byte[] aBuffer)
{
m_oContext = oContext;
m_oCallback = oCallback;
m_oFileStreamInput = oFileStreamInput;
m_aBuffer = aBuffer;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,205 @@
<%@ WebHandler Language="C#" Class="FileUploader" %>
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using System;
using System.Net;
using System.Configuration;
using System.Web;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.Collections.Specialized;
using FileConverterUtils2;
using log4net;
public class FileUploader : IHttpAsyncHandler
{
private readonly ILog _log = LogManager.GetLogger(typeof(FileUploader));
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
{
bool bStartAsync = false;
ErrorTypes eError = ErrorTypes.Unknown;
try
{
_log.Info("Starting process request...");
_log.Info(context.Request.Params.ToString());
string vKey = context.Request.Params["vkey"];
string sKey = context.Request.Params["key"];
if (null != sKey && false == string.IsNullOrEmpty(sKey))
{
eError = ErrorTypes.NoError;
if (ErrorTypes.NoError == eError)
{
bStartAsync = true;
Storage oStorage = new Storage();
string sTempKey = "temp_" + sKey;
string sPath = sTempKey + "/" + sKey + ".tmp";
AsyncContextReadOperation asynch = new AsyncContextReadOperation();
TransportClass oTransportClass = new TransportClass(context, cb, oStorage, asynch, sPath, sTempKey);
asynch.ReadContextBegin(context.Request.InputStream, ReadContextCallback, oTransportClass);
}
}
}
catch(Exception e)
{
eError = ErrorTypes.Unknown;
_log.Error(context.Request.Params.ToString());
_log.Error("Exeption: ", e);
}
finally
{
if (ErrorTypes.NoError != eError)
writeXml(context, null, null, null, eError);
}
TransportClass oTempTransportClass = new TransportClass(context, cb, null, null, null, null);
if (false == bStartAsync)
cb(new AsyncOperationData(oTempTransportClass));
return new AsyncOperationData(oTempTransportClass);
}
public void EndProcessRequest(IAsyncResult result)
{
}
public void ProcessRequest(HttpContext context)
{
throw new InvalidOperationException();
}
public bool IsReusable {
get {
return false;
}
}
private void ReadContextCallback(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
try
{
oTransportClass.m_oAsyncContextRead.ReadContextEnd(result);
MemoryStream ms = new MemoryStream(oTransportClass.m_oAsyncContextRead.m_aBuffer);
oTransportClass.m_oStorage.WriteFileBegin(oTransportClass.m_sPath, ms, WriteFileCallback, oTransportClass);
}
catch
{
writeXml(oTransportClass.m_oContext, null, null, null, ErrorTypes.StorageWrite);
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
}
private void WriteFileCallback(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
try
{
int nWriteBytes;
ErrorTypes eError = oTransportClass.m_oStorage.WriteFileEnd(result, out nWriteBytes);
if (ErrorTypes.NoError == eError)
{
System.Uri oUrl = oTransportClass.m_oContext.Request.Url;
string sSiteUrl = oUrl.Scheme + "://" + oUrl.Host;
if (-1 != oUrl.Port)
sSiteUrl += ":" + oUrl.Port;
string sFileUrl = sSiteUrl + "/ResourceService.ashx?deletepath=" + HttpUtility.UrlEncode(oTransportClass.m_sDeletePath) + "&path=" + HttpUtility.UrlEncode(oTransportClass.m_sPath);
writeXml(oTransportClass.m_oContext, sFileUrl, "100", true, null);
}
else
writeXml(oTransportClass.m_oContext, null, null, null, eError);
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
catch
{
writeXml(oTransportClass.m_oContext, null, null, null, ErrorTypes.StorageWrite);
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
}
private void writeXml(HttpContext context, string strFileUrl, string strPercent, bool? bIsEndConvert, ErrorTypes? eError)
{
XmlDocument oDoc = new XmlDocument();
XmlElement oRootElem = oDoc.CreateElement("FileResult");
oDoc.AppendChild(oRootElem);
if (null != strFileUrl)
{
XmlElement oFileUrl = oDoc.CreateElement("FileUrl");
oFileUrl.InnerText = strFileUrl;
oRootElem.AppendChild(oFileUrl);
}
if (null != strPercent)
{
XmlElement oPercent = oDoc.CreateElement("Percent");
oPercent.InnerText = strPercent;
oRootElem.AppendChild(oPercent);
}
if (bIsEndConvert.HasValue)
{
XmlElement oEndConvert = oDoc.CreateElement("EndConvert");
oEndConvert.InnerText = bIsEndConvert.Value.ToString();
oRootElem.AppendChild(oEndConvert);
}
if (eError.HasValue)
{
XmlElement oError = oDoc.CreateElement("Error");
oError.InnerText = Utils.mapAscServerErrorToOldError(eError.Value).ToString();
oRootElem.AppendChild(oError);
}
oDoc.Save(context.Response.Output);
context.Response.ContentType = "text/xml";
}
private class TransportClass
{
public HttpContext m_oContext;
public AsyncCallback m_oCallback;
public Storage m_oStorage;
public AsyncContextReadOperation m_oAsyncContextRead;
public string m_sPath;
public string m_sDeletePath;
public TransportClass(HttpContext oContext, AsyncCallback oCallback, Storage oStorage, AsyncContextReadOperation oAsyncContextRead, string sPath, string sDeletePath)
{
m_oContext = oContext;
m_oCallback = oCallback;
m_oStorage = oStorage;
m_oAsyncContextRead = oAsyncContextRead;
m_sPath = sPath;
m_sDeletePath = sDeletePath;
}
}
}

View File

@@ -0,0 +1,33 @@
<%@ WebHandler Language="C#" CodeBehind="App_Code/FontService.ashx.cs" Class="FontService" %>
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/

160
DocService/Global.asax Normal file
View File

@@ -0,0 +1,160 @@
<%@ Application Language="C#" %>
<%@ Assembly Name="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Threading"%>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="log4net.Config" %>
<%@ Import Namespace="FileConverterUtils2" %>
<script runat="server">
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
const int c_nBuildTimeYear = 2014;
const int c_nBuildTimeMonth = 02;
const int c_nBuildTimeDay = 04;
public class LanguageInfo
{
public string languageCode;
public string languageName;
public string hunspellAffFile;
public string hunspellDictFile;
public string hunspellKey;
public string hyphenDictFile;
public string thesIdxFile;
public string thesDatFile;
};
static public Object lockThis = new Object();
static public Dictionary<int, LanguageInfo> dictMap;
static LicenseInfo licenseInfo;
static public LicenseInfo LicenseInfo { get { return licenseInfo; } }
private void InitLangInfo()
{
LanguageInfo info_de_DE = new LanguageInfo();
info_de_DE.languageCode = "de-DE";
info_de_DE.languageName = "German, Germany";
info_de_DE.hunspellAffFile = "de_DE_frami.aff";
info_de_DE.hunspellDictFile = "de_DE_frami.dic";
info_de_DE.hunspellKey = "";
info_de_DE.hyphenDictFile = "hyph_de_DE.dic";
dictMap.Add(0x0407, info_de_DE);
LanguageInfo info_en_US = new LanguageInfo ();
info_en_US.languageCode = "en-US";
info_en_US.languageName = "English, United States";
info_en_US.hunspellAffFile = "en_us.aff";
info_en_US.hunspellDictFile = "en_us.dic";
info_en_US.hunspellKey = "";
info_en_US.hyphenDictFile = "hyph_en_us.dic";
info_en_US.thesIdxFile = "th_en_us_new.idx";
info_en_US.thesDatFile = "th_en_us_new.dat";
dictMap.Add(0x0409, info_en_US);
LanguageInfo info_ru_RU = new LanguageInfo();
info_ru_RU.languageCode = "ru-RU";
info_ru_RU.languageName = "Russian, Russian Federation";
info_ru_RU.hunspellAffFile = "ru_RU.aff";
info_ru_RU.hunspellDictFile = "ru_RU.dic";
info_ru_RU.hunspellKey = "";
dictMap.Add(0x0419, info_ru_RU);
}
public static void RegisterRoutes(RouteCollection routes)
{
string sRoute = ConfigurationSettings.AppSettings["fonts.route"] ?? "fonts/";
routes.Add(new Route(sRoute + "native/{fontname}", new FontServiceRoute()));
routes.Add(new Route(sRoute + "js/{fontname}", new FontServiceRoute()));
}
void Application_Start(object sender, EventArgs e)
{
System.Diagnostics.Debug.Print("Application_Start() fired!" + sender.ToString());
try
{
XmlConfigurator.Configure();
}
catch(Exception ex)
{
}
RegisterRoutes(RouteTable.Routes);
licenseInfo = LicenseInfo.CreateLicenseInfo(new DateTime(c_nBuildTimeYear, c_nBuildTimeMonth, c_nBuildTimeDay));
}
void Application_End(object sender, EventArgs e)
{
System.Diagnostics.Debug.Print("Application_End() fired!" + sender.ToString());
}
void Application_Error(object sender, EventArgs e)
{
}
void Session_Start(object sender, EventArgs e)
{
}
void Session_End(object sender, EventArgs e)
{
}
void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
}
void Application_BeginRequest(Object sender, EventArgs e)
{
}
</script>

View File

@@ -0,0 +1,278 @@
<%@ WebHandler Language="C#" Class="ResourceService" %>
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using System;
using System.Net;
using System.Configuration;
using System.Web;
using System.IO;
using System.Text;
using FileConverterUtils2;
using log4net;
public class ResourceService : IHttpAsyncHandler
{
private readonly ILog _log = LogManager.GetLogger(typeof(ResourceService));
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
{
bool bStartAsync = false;
try
{
_log.Info("Starting process request...");
_log.Info(context.Request.Params.ToString());
Storage oStorage = new Storage();
TaskResult oTaskResult = new TaskResult();
string sPath = context.Request.Params["path"];
string sOutputFilename = context.Request.Params["filename"];
string sDeletePath = context.Request.Params["deletepath"];
if (string.IsNullOrEmpty(sOutputFilename))
{
if (null != sPath)
{
int nIndex1 = sPath.LastIndexOf('/');
int nIndex2 = sPath.LastIndexOf('\\');
if (-1 != nIndex1 || -1 != nIndex2)
{
int nIndex = Math.Max(nIndex1, nIndex2);
sOutputFilename = sPath.Substring(nIndex + 1);
}
else
sOutputFilename = "resource";
}
}
context.Response.Clear();
context.Response.Cache.SetExpires(DateTime.Now);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.ContentType = Utils.GetMimeType(sOutputFilename);
string sUserAgent = context.Request.ServerVariables.Get("HTTP_USER_AGENT");
if (false == string.IsNullOrEmpty(sUserAgent) && sUserAgent.Contains("MSIE"))
context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + context.Server.UrlEncode(sOutputFilename) + "\"");
else
context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + sOutputFilename + "\"");
if (null != sPath)
{
TransportClass oTransportClass = new TransportClass(context, cb, oStorage, oTaskResult, sPath, sDeletePath);
StorageFileInfo oStorageFileInfo;
if (ErrorTypes.NoError == oStorage.GetFileInfo(sPath, out oStorageFileInfo) && null != oStorageFileInfo)
{
string sETag = oStorageFileInfo.m_oLastModify.Ticks.ToString("x");
DateTime oLastModified = oStorageFileInfo.m_oLastModify;
DateTime oDateTimeUtcNow = DateTime.UtcNow;
if (oLastModified.CompareTo(oDateTimeUtcNow) > 0)
{
_log.DebugFormat("LastModifiedTimeStamp changed from {0} to {1}", oLastModified, oDateTimeUtcNow);
oLastModified = oDateTimeUtcNow;
}
string sRequestIfModifiedSince = context.Request.Headers["If-Modified-Since"];
string sRequestETag = context.Request.Headers["If-None-Match"];
bool bNoModify = false;
if (false == string.IsNullOrEmpty(sRequestETag) || false == string.IsNullOrEmpty(sRequestIfModifiedSince))
{
bool bRequestETag = true;
if (false == string.IsNullOrEmpty(sRequestETag) && sRequestETag != sETag)
bRequestETag = false;
bool bRequestIfModifiedSince = true;
if (false == string.IsNullOrEmpty(sRequestIfModifiedSince))
{
try
{
DateTime oRequestIfModifiedSince = DateTime.ParseExact(sRequestIfModifiedSince, "R", System.Globalization.CultureInfo.InvariantCulture);
if ((oRequestIfModifiedSince - oLastModified).TotalSeconds > 1)
bRequestIfModifiedSince = false;
}
catch
{
bRequestIfModifiedSince = false;
}
}
if (bRequestETag && bRequestIfModifiedSince)
{
context.Response.StatusCode = (int)HttpStatusCode.NotModified;
bNoModify = true;
}
}
if (false == bNoModify)
{
context.Response.Cache.SetETag(sETag);
context.Response.Cache.SetLastModified(oLastModified);
oStorage.ReadFileBegin(sPath, context.Response.OutputStream, ReadFileCallback, oTransportClass);
bStartAsync = true;
}
}
else
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
}
else
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
}
catch(Exception e)
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
_log.Error(context.Request.Params.ToString());
_log.Error("Exeption catched in BeginProcessRequest:", e);
}
TransportClass oTempTransportClass = new TransportClass(context, cb, null, null, null, null);
if (false == bStartAsync)
cb(new AsyncOperationData(oTempTransportClass));
return new AsyncOperationData(oTempTransportClass);
}
public void EndProcessRequest(IAsyncResult result)
{
}
private void ReadFileCallback(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
HttpContext context = oTransportClass.m_oContext;
try
{
Storage oStorage = oTransportClass.m_oStorage;
if (null != oStorage)
{
int nReadWriteBytes = 0;
ErrorTypes eResult = oStorage.ReadFileEnd(result, out nReadWriteBytes);
if (ErrorTypes.NoError != eResult)
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
else
{
context.Response.AddHeader("Content-Length", nReadWriteBytes.ToString());
context.Response.StatusCode = (int)HttpStatusCode.OK;
}
context.Response.Flush();
context.Response.End();
}
if (null != oTransportClass.m_sDeletePath && false == string.IsNullOrEmpty(oTransportClass.m_sDeletePath))
{
TaskResult oTaskResult = oTransportClass.m_oTaskResult;
string sKey = oTransportClass.m_sDeletePath;
oTaskResult.RemoveBegin(sKey, RemoveTaskCallback, oTransportClass);
}
else
{
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
}
catch(Exception e)
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
_log.Error("Exception catched in ReadFileCallback:", e);
}
}
private void RemoveTaskCallback(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
HttpContext context = oTransportClass.m_oContext;
try
{
TaskResult oTaskResult = oTransportClass.m_oTaskResult;
if (null != oTaskResult)
oTaskResult.RemoveEnd(result);
Storage oStorage = oTransportClass.m_oStorage;
if (null != oStorage)
oStorage.RemovePathBegin(oTransportClass.m_sDeletePath, RemoveFileCallback, oTransportClass);
}
catch(Exception e)
{
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
_log.Error("Exception catched in RemoveTaskCallback:", e);
}
}
private void RemoveFileCallback(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
HttpContext context = oTransportClass.m_oContext;
try
{
Storage oStorage = oTransportClass.m_oStorage;
if (null != oStorage)
oStorage.RemovePathEnd(result);
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
catch(Exception e)
{
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
_log.Error("Exception catched in RemoveFileCallback:", e);
}
}
public void ProcessRequest(HttpContext context)
{
throw new InvalidOperationException();
}
public bool IsReusable
{
get
{
return false;
}
}
private class TransportClass
{
public HttpContext m_oContext;
public AsyncCallback m_oCallback;
public Storage m_oStorage;
public TaskResult m_oTaskResult;
public string m_sPath;
public string m_sDeletePath;
public TransportClass(HttpContext oContext, AsyncCallback oCallback, Storage oStorage, TaskResult oTaskResult, string sPath, string sDeletePath)
{
m_oContext = oContext;
m_oCallback = oCallback;
m_oStorage = oStorage;
m_oTaskResult = oTaskResult;
m_sPath = sPath;
m_sDeletePath = sDeletePath;
}
}
}

View File

@@ -0,0 +1,333 @@
<%@ WebHandler Language="C#" Class="UploadService" %>
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using System;
using System.Net;
using System.Configuration;
using System.Web;
using System.IO;
using System.Text;
using System.Xml;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.Collections.Specialized;
using FileConverterUtils2;
using log4net;
public class UploadService : IHttpAsyncHandler
{
private readonly ILog _log = LogManager.GetLogger(typeof(UploadService));
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
{
_log.Info("Starting process request...");
_log.Info(context.Request.Params.ToString());
TransportClassMainAshx oTransportClassMainAshx = new TransportClassMainAshx(context, cb);
ErrorTypes eError = ErrorTypes.NoError;
try
{
string sGuid = context.Request.QueryString["key"];
int nMaxBytes = Convert.ToInt32(ConfigurationSettings.AppSettings["limits.image.size"] ?? "25000000");
if (context.Request.ContentLength <= nMaxBytes)
{
if (context.Request.Files.Count > 0)
{
HttpPostedFile file = context.Request.Files[0];
string sFileExtension = Path.GetExtension(file.FileName).ToLower();
int nParamsCount = 0;
string sInputParams = "";
for (int i = 0, length = context.Request.Params.Count; i < length; ++i)
{
sInputParams += context.Request.Params.Get(i) + ":" + context.Request.Params.GetKey(i);
if (nParamsCount > 0)
sInputParams += ",";
nParamsCount++;
}
AsyncMediaXmlOperation oAsyncMediaXmlOperation = new AsyncMediaXmlOperation();
TransportClass1 oTransportClass1 = new TransportClass1(oTransportClassMainAshx, oAsyncMediaXmlOperation, context.Request.QueryString, sGuid, Path.Combine(sGuid, @"media/media.xml"), file);
oAsyncMediaXmlOperation.GetMediaXmlBegin(oTransportClass1.m_sMediaXml, GetMediaXmlCallback, oTransportClass1);
}
else
eError = ErrorTypes.UploadCountFiles;
}
else
eError = ErrorTypes.UploadContentLength;
}
catch(Exception e)
{
eError = ErrorTypes.Upload;
_log.Error(context.Request.Params.ToString());
_log.Error("Exeption: ", e);
}
if (ErrorTypes.NoError != eError)
WriteToResponse(oTransportClassMainAshx, eError, null, context.Request.QueryString);
return new AsyncOperationData(extraData);
}
public void EndProcessRequest(IAsyncResult result)
{
}
public void ProcessRequest(HttpContext context)
{
throw new InvalidOperationException();
}
public bool IsReusable
{
get
{
return false;
}
}
#region HelpFunctions
private void WriteToResponse(TransportClassMainAshx oTransportClassMainAshx, ErrorTypes eError, string sPath, NameValueCollection aNameValueCollection)
{
HttpContext oHttpContext = oTransportClassMainAshx.m_oHttpContext;
AsyncCallback oAsyncCallback = oTransportClassMainAshx.m_oAsyncCallback;
OutputCommand oOutputCommand = new OutputCommand();
if (null != aNameValueCollection)
{
for (int i = 0, length = aNameValueCollection.Count; i < length; ++i)
oOutputCommand.input.Add(aNameValueCollection.GetKey(i), aNameValueCollection.Get(i));
}
if (null != sPath)
oOutputCommand.url = sPath;
oOutputCommand.error = (int)eError;
oOutputCommand.type = (int)PostMessageType.UploadImage;
JavaScriptSerializer serializer = new JavaScriptSerializer();
StringBuilder sb = new StringBuilder();
serializer.Serialize(oOutputCommand, sb);
string sJson = sb.ToString();
oHttpContext.Response.Write("<html><head><script type=\"text/javascript\">function load(){ parent.postMessage(\"" + sJson.Replace("\"", "\\\"") + "\", '*'); }</script></head><body onload='load()'></body></html>");
oAsyncCallback.Invoke(new AsyncOperationData(null));
}
#endregion
#region Callbacks
private void GetMediaXmlCallback(IAsyncResult ar)
{
TransportClass1 oTransportClass1 = ar.AsyncState as TransportClass1;
try
{
Dictionary<string, string> aMediaXmlMapHash;
Dictionary<string, string> aMediaXmlMapFilename;
ErrorTypes eError = oTransportClass1.m_oAsyncMediaXmlOperation.GetMediaXmlEnd(ar, out aMediaXmlMapHash, out aMediaXmlMapFilename);
if (ErrorTypes.NoError == eError)
{
AsyncContextReadOperation oAsyncContextReadOperation = new AsyncContextReadOperation();
TransportClass2 oTransportClass2 = new TransportClass2(oTransportClass1, aMediaXmlMapHash, aMediaXmlMapFilename, oAsyncContextReadOperation);
oTransportClass1.m_oFile.InputStream.Position = 0;
oAsyncContextReadOperation.ReadContextBegin(oTransportClass1.m_oFile.InputStream, ReadContextCallback, oTransportClass2);
}
else
WriteToResponse(oTransportClass1, ErrorTypes.Upload, null, oTransportClass1.m_aInputParams);
}
catch
{
WriteToResponse(oTransportClass1, ErrorTypes.Upload, null, oTransportClass1.m_aInputParams);
}
}
private void ReadContextCallback(IAsyncResult ar)
{
TransportClass2 oTransportClass2 = ar.AsyncState as TransportClass2;
try
{
ErrorTypes eError = oTransportClass2.m_oAsyncContextReadOperation.ReadContextEnd(ar);
if (ErrorTypes.NoError == eError)
{
byte[] aBuffer = oTransportClass2.m_oAsyncContextReadOperation.m_aBuffer;
int nImageFormat = Utils.GetFileFormat(aBuffer);
string sSupportedFormats = ConfigurationSettings.AppSettings["limits.image.types.upload"] ?? "jpg";
if (0 != (FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE & nImageFormat) && -1 != sSupportedFormats.IndexOf(FileFormats.ToString(nImageFormat)))
{
string sImageHash = null;
using (MemoryStream ms = new MemoryStream(aBuffer))
sImageHash = Utils.getMD5HexString(ms);
string sFileName;
if (oTransportClass2.m_oMediaXmlMapHash.TryGetValue(sImageHash, out sFileName))
{
string sUrl = Constants.mc_sResourceServiceUrlRel + Path.Combine(oTransportClass2.m_sKey, @"media\" + sFileName).Replace('\\', '/');
WriteToResponse(oTransportClass2, ErrorTypes.NoError, sUrl, oTransportClass2.m_aInputParams);
}
else
{
string sSearchName = "image";
List<int> aIndexes = new List<int>();
foreach (KeyValuePair<string, string> kvp in oTransportClass2.m_oMediaXmlMapFilename)
{
string sFilename = Path.GetFileNameWithoutExtension(kvp.Key);
if (0 == sFilename.IndexOf(sSearchName))
{
int nCurIndex;
if (int.TryParse(sFilename.Substring(sSearchName.Length), out nCurIndex))
aIndexes.Add(nCurIndex);
}
}
int nMaxIndex = -1;
for (int i = 0, length = aIndexes.Count; i < length; ++i)
{
int nCurIndex = aIndexes[i];
if (nMaxIndex < nCurIndex)
nMaxIndex = nCurIndex;
}
int nNewIndex = 1;
if (nMaxIndex >= nNewIndex)
nNewIndex = nMaxIndex + 1;
string sNewName = sSearchName + nNewIndex + "." + FileFormats.ToString(nImageFormat);
string sNewPath = Path.Combine(oTransportClass2.m_sKey, @"media\" + sNewName).Replace('\\', '/');
Storage oStorage = new Storage();
TransportClass3 oTransportClass3 = new TransportClass3(oTransportClass2, sNewName, sImageHash, sNewPath, oStorage);
oTransportClass2.m_oFile.InputStream.Position = 0;
oTransportClass3.m_oStorage.WriteFileBegin(sNewPath, oTransportClass2.m_oFile.InputStream, WriteUploadedFileCallback, oTransportClass3);
}
}
else
WriteToResponse(oTransportClass2, ErrorTypes.UploadExtension, null, oTransportClass2.m_aInputParams);
}
else
WriteToResponse(oTransportClass2, eError, null, oTransportClass2.m_aInputParams);
}
catch
{
WriteToResponse(oTransportClass2, ErrorTypes.Upload, null, oTransportClass2.m_aInputParams);
}
}
private void WriteUploadedFileCallback(IAsyncResult ar)
{
TransportClass3 oTransportClass3 = ar.AsyncState as TransportClass3;
try
{
int nReadWriteBytes;
ErrorTypes eError = oTransportClass3.m_oStorage.WriteFileEnd(ar, out nReadWriteBytes);
if (ErrorTypes.NoError == eError)
{
oTransportClass3.m_oMediaXmlMapHash.Add(oTransportClass3.m_sHash, oTransportClass3.m_sFilename);
oTransportClass3.m_oAsyncMediaXmlOperation.WriteMediaXmlBegin(oTransportClass3.m_sMediaXml, oTransportClass3.m_oMediaXmlMapHash, WriteMediaXmlCallback, oTransportClass3);
}
else
WriteToResponse(oTransportClass3, eError, null, oTransportClass3.m_aInputParams);
}
catch
{
WriteToResponse(oTransportClass3, ErrorTypes.Upload, null, oTransportClass3.m_aInputParams);
}
}
private void WriteMediaXmlCallback(IAsyncResult ar)
{
TransportClass3 oTransportClass3 = ar.AsyncState as TransportClass3;
try
{
ErrorTypes eError = oTransportClass3.m_oAsyncMediaXmlOperation.WriteMediaXmlEnd(ar);
if (ErrorTypes.NoError == eError)
{
string sUrl = Constants.mc_sResourceServiceUrlRel + oTransportClass3.m_sPath.Replace('\\', '/');
WriteToResponse(oTransportClass3, ErrorTypes.NoError, sUrl, oTransportClass3.m_aInputParams);
}
else
WriteToResponse(oTransportClass3, ErrorTypes.Upload, null, oTransportClass3.m_aInputParams);
}
catch
{
WriteToResponse(oTransportClass3, ErrorTypes.Upload, null, oTransportClass3.m_aInputParams);
}
}
#endregion
#region TransportClass
private class TransportClass1 : TransportClassMainAshx
{
public AsyncMediaXmlOperation m_oAsyncMediaXmlOperation;
public NameValueCollection m_aInputParams;
public string m_sKey;
public string m_sMediaXml;
public HttpPostedFile m_oFile;
public TransportClass1(TransportClassMainAshx oTransportClassMainAshx, AsyncMediaXmlOperation oAsyncMediaXmlOperation, NameValueCollection aInputParams, string sKey, string sMediaXml, HttpPostedFile oFile)
: base(oTransportClassMainAshx.m_oHttpContext, oTransportClassMainAshx.m_oAsyncCallback)
{
m_oAsyncMediaXmlOperation = oAsyncMediaXmlOperation;
m_aInputParams = aInputParams;
m_sKey = sKey;
m_oFile = oFile;
m_sMediaXml = sMediaXml;
}
}
private class TransportClass2 : TransportClass1
{
public Dictionary<string, string> m_oMediaXmlMapHash = new Dictionary<string, string>();
public Dictionary<string, string> m_oMediaXmlMapFilename = new Dictionary<string, string>();
public AsyncContextReadOperation m_oAsyncContextReadOperation;
public TransportClass2(TransportClass1 oTransportClass1, Dictionary<string, string> oMediaXmlMapHash, Dictionary<string, string> oMediaXmlMapFilename, AsyncContextReadOperation oAsyncContextReadOperation)
: base(oTransportClass1, oTransportClass1.m_oAsyncMediaXmlOperation, oTransportClass1.m_aInputParams, oTransportClass1.m_sKey, oTransportClass1.m_sMediaXml, oTransportClass1.m_oFile)
{
m_oMediaXmlMapHash = oMediaXmlMapHash;
m_oMediaXmlMapFilename = oMediaXmlMapFilename;
m_oAsyncContextReadOperation = oAsyncContextReadOperation;
}
}
private class TransportClass3 : TransportClass2
{
public string m_sFilename;
public string m_sHash;
public string m_sPath;
public Storage m_oStorage;
public TransportClass3(TransportClass2 oTransportClass2, string sFilename, string sHash, string sPath, Storage oStorage)
: base(new TransportClass1(oTransportClass2, oTransportClass2.m_oAsyncMediaXmlOperation, oTransportClass2.m_aInputParams, oTransportClass2.m_sKey, oTransportClass2.m_sMediaXml, oTransportClass2.m_oFile), oTransportClass2.m_oMediaXmlMapHash, oTransportClass2.m_oMediaXmlMapFilename, oTransportClass2.m_oAsyncContextReadOperation)
{
m_sFilename = sFilename;
m_sHash = sHash;
m_sPath = sPath;
m_oStorage = oStorage;
}
}
public class OutputCommand
{
public int type;
public string url;
public int error;
public Dictionary<string, object> input = new Dictionary<string,object>();
}
#endregion
}

9
DocService/default.aspx Normal file
View File

@@ -0,0 +1,9 @@
<%@ Page Language="C#" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
Response.Redirect(ConfigurationSettings.AppSettings["DefaultURL"]);
base.OnLoad(e);
}
</script>

View File

@@ -0,0 +1,106 @@
<%@ WebHandler Language="C#" Class="fileDownloader" %>
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
using System;
using System.Net;
using System.Configuration;
using System.Web;
using System.IO;
using System.Text;
public class fileDownloader : IHttpHandler {
public void ProcessRequest (HttpContext context) {
try
{
System.IO.FileInfo file = new System.IO.FileInfo(Convert.ToString(context.Server.MapPath(context.Server.UrlDecode("~" + context.Request.Params[0]))));
string sOutputFilename = null;
if (context.Request.Params.Count > 1)
sOutputFilename = context.Server.UrlDecode(context.Request.Params[1]);
if (string.IsNullOrEmpty(sOutputFilename))
sOutputFilename = file.Name;
if (!file.Exists)
return;
context.Response.Clear();
context.Response.ContentType = "application/octet-stream";
if (context.Request.ServerVariables.Get("HTTP_USER_AGENT").Contains("MSIE"))
context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + context.Server.UrlEncode(sOutputFilename) + "\"");
else
context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + sOutputFilename + "\"");
context.Response.AddHeader("Content-Length", file.Length.ToString());
context.Response.TransmitFile(file.FullName);
context.Response.Flush();
context.Response.End();
}
catch(Exception){}
}
public bool IsReusable {
get {
return false;
}
}
public static string GetIP4Address()
{
string IP4Address = String.Empty;
foreach (IPAddress IPA in Dns.GetHostAddresses(HttpContext.Current.Request.UserHostAddress))
{
if (IPA.AddressFamily.ToString() == "InterNetwork")
{
IP4Address = IPA.ToString();
break;
}
}
if (IP4Address != String.Empty)
{
return IP4Address;
}
foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (IPA.AddressFamily.ToString() == "InterNetwork")
{
IP4Address = IPA.ToString();
break;
}
}
return IP4Address;
}
}

255
DocService/web.config Normal file
View File

@@ -0,0 +1,255 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<system.serviceModel>
<client>
<endpoint address="http://teamlab/billing/v1.2/Service.svc" binding="basicHttpBinding" contract="ASC.Core.Billing.IService" bindingConfiguration="billing" />
</client>
<bindings>
<basicHttpBinding>
<binding name="billing" maxReceivedMessageSize="1000000">
<readerQuotas maxStringContentLength="1000000" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<log4net>
<appender name="DebugAppender" type="log4net.Appender.DebugAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<root>
<level value="ERROR" />
<appender-ref ref="DebugAppender" />
</root>
</log4net>
<system.data>
<DbProviderFactories>
<clear />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<appSettings file=".\Bin\Settings.config">
<add key="WebCacheExpireSeconds" value="900" />
<add key="ResourceServiceExpireSeconds" value="3600" />
<add key="keyIp" value="ip" />
<add key="keyKey" value="key" />
<add key="keyDate" value="expire" />
<add key="keyDateInterval" value="1" />
<add key="keyPaid" value="paid" />
<add key="keyKeyID" value="key_id" />
<add key="keyUserCount" value="user_count" />
<add key="FilesDir" value="TestDocs\files" />
<add key="NewFilesDir" value="TestDocs\res" />
<add key="DefaultURL" value="http://www.onlyoffice.com" />
<!-- Necessary to test the efficiency of docs service -->
<add key="urlTestValue" value="/TestSiteEfficiency/empty.docx" />
<add key="fileTypeTestValue" value="docx" />
<add key="isErrorRedirectPage" value="TestSiteEfficiency/error.html" />
<!--Test Efficiency Site-->
<add key="testEfficiencyGuidWord" value="test_site_efficiency_guid.docx" />
<add key="testEfficiencyGuidExcel" value="test_site_efficiency_guid.xls" />
<add key="testEfficiencyUrlWord" value="http://localhost/testdocs/res/new.docx" />
<add key="testEfficiencyUrlExcel" value="http://localhost/testdocs/res/new.xls" />
<add key="editor.settings.viewerformats" value="pdf;xps;djvu;tiff" />
<add key="editor.settings.readerformats" value="doct;docx;doc;odt;rtf;txt;mht;html;htm;epub;mobi" />
<add key="editor.settings.editorformats" value="doct;xlst;pptt;docx;doc;odt;xlsx;xls;ods;csv;pptx;ppt;ppsx;pps;odp;rtf;txt;mht;html;htm;epub;mobi" />
<add key="editor.settings.autosave.enable" value="true" />
<add key="editor.settings.autosave.mininterval" value="300" />
<add key="editor.settings.coauthoring.url" value="" />
<add key="editor.settings.spellchecker.url" value="" />
<add key="limits.image.types.upload" value="jpg;png;gif;bmp;"/>
<add key="limits.image.types.copy" value="jpg;png;gif;bmp;emf;wmf;svg"/>
<add key="limits.image.size" value="25000000"/>
<add key="fonts.route" value="OfficeWeb/sdk/Fonts/" />
</appSettings>
<connectionStrings configSource=".\Bin\ConnectionStrings.config"/>
<system.web>
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="Accessibility, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx" />
<remove verb="POST,GET" path="template.ashx" />
<remove verb="POST,GET" path="JavaScriptResource.ashx" />
<remove verb="POST,GET" path="UploadProgress.ashx" />
<remove verb="POST,GET" path="fckuploader.ashx" />
<remove verb="POST,GET" path="ajaxupload.ashx" />
<remove verb="POST,GET" path="ajaxpro/*.ashx" />
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpHandlers>
<httpModules>
<remove name="UploadProgress" />
<remove name="MobileDetector" />
<remove name="TcpIpFilter" />
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
<providerOption name="CompilerVersion" value="v3.5" />
<providerOption name="WarnAsError" value="false" />
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
<providerOption name="CompilerVersion" value="v3.5" />
<providerOption name="OptionInfer" value="true" />
<providerOption name="WarnAsError" value="false" />
</compiler>
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<remove name="UploadProgress" />
<remove name="MobileDetector" />
<remove name="TcpIpFilter" />
<remove name="ScriptModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<remove name="ScriptHandlerFactory" />
<remove name="ScriptHandlerFactoryAppServices" />
<remove name="ScriptResource" />
<remove name="Template" />
<remove name="JavaScriptResource" />
<remove name="UpProgress" />
<remove name="FCKUp" />
<remove name="AjaxUp" />
<remove name="AjaxPro" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
<staticContent>
<remove fileExtension=".ods" />
<remove fileExtension=".odt" />
<remove fileExtension=".odp" />
<remove fileExtension=".svg" />
<remove fileExtension=".json" />
<remove fileExtension=".epub" />
<remove fileExtension=".djvu" />
<remove fileExtension=".xps" />
<remove fileExtension=".doct" />
<remove fileExtension=".xlst" />
<remove fileExtension=".pptt" />
<remove fileExtension=".fb2" />
<remove fileExtension=".ttc" />
<remove fileExtension=".mobi" />
<remove fileExtension=".prc" />
<remove fileExtension=".otf" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".json" mimeType="application/json" />
<mimeMap fileExtension=".ods" mimeType="application/vnd.oasis.opendocument.spreadsheet" />
<mimeMap fileExtension=".odt" mimeType="application/vnd.oasis.opendocument.text" />
<mimeMap fileExtension=".odp" mimeType="application/vnd.oasis.opendocument.presentation" />
<mimeMap fileExtension=".epub" mimeType="application/epub+zip" />
<mimeMap fileExtension=".djvu" mimeType="image/vnd.djvu" />
<mimeMap fileExtension=".xps" mimeType="application/vnd.ms-xpsdocument" />
<mimeMap fileExtension=".doct" mimeType="application/doct" />
<mimeMap fileExtension=".xlst" mimeType="application/xlst" />
<mimeMap fileExtension=".pptt" mimeType="application/pptt" />
<mimeMap fileExtension=".fb2" mimeType="text/xml" />
<mimeMap fileExtension=".ttc" mimeType="application/octet-stream" />
<mimeMap fileExtension=".otf" mimeType="application/octet-stream" />
<mimeMap fileExtension=".mobi" mimeType="application/x-mobipocket-ebook" />
<mimeMap fileExtension=".prc" mimeType="application/x-mobipocket-ebook" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
<defaultDocument>
<files>
<clear />
<add value="default.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
</files>
</defaultDocument>
<urlCompression doDynamicCompression="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v2.0.50727"><dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
</assemblyBinding></runtime>
</configuration>