3.0 source code

This commit is contained in:
agolybev
2015-04-28 17:59:00 +03:00
parent c69fd34bdd
commit 7b3b2248e5
16311 changed files with 1445974 additions and 3108429 deletions

View File

@@ -0,0 +1,91 @@
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public static class UrlBuilder
{
public static string UrlWithoutPath(HttpRequest oHttpRequest)
{
string sSiteUrl = "";
try
{
string sHostHeader = oHttpRequest.Headers["Host"];
Uri oSiteUri = oHttpRequest.Url;
sSiteUrl = oSiteUri.Scheme + "://";
if (!String.IsNullOrEmpty(sHostHeader))
{
sSiteUrl += sHostHeader;
}
else
{
sSiteUrl += oSiteUri.Host;
if (-1 != oSiteUri.Port)
sSiteUrl += ":" + oSiteUri.Port;
}
}
catch
{
}
return sSiteUrl;
}
public static string FullUrl(HttpRequest oHttpRequest)
{
string sSiteUrl = "";
try
{
sSiteUrl = UrlWithoutPath(oHttpRequest);
sSiteUrl += oHttpRequest.Path;
}
catch
{
}
return sSiteUrl;
}
}

View File

@@ -1,282 +1,361 @@
/*
* (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;
}
}
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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 System.Linq;
using System.Collections.Generic;
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 const string gc_sJsExtention = ".js";
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>();
string sConfigFontDir = ConfigurationManager.AppSettings["utils.common.fontdir"];
if (null != sConfigFontDir && string.Empty != sConfigFontDir)
{
string sConfigSearchPattern = ConfigurationSettings.AppSettings["utils.fonts.search_patterns"] ?? "*.ttf;*.ttc;*.otf";
InitFontMapByFolder(sConfigFontDir, sConfigSearchPattern);
}
else
{
InitFontMapBySysFont();
}
}
static private void InitFontMapBySysFont()
{
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);
}
}
}
}
static private void InitFontMapByFolder(string sConfigFontDir, string sConfigSearchPattern)
{
string sFontDir = Environment.ExpandEnvironmentVariables(sConfigFontDir);
char[] aDelemiters = { '|', ',', ';' };
List<string> aSearchPatterns = (sConfigSearchPattern.Split(
aDelemiters, StringSplitOptions.RemoveEmptyEntries)).ToList();
string[] aFontFiles = { };
foreach (string sSearchPattern in aSearchPatterns)
{
aFontFiles = aFontFiles.Concat(Directory.GetFiles(
sFontDir, sSearchPattern, SearchOption.AllDirectories)).ToArray();
}
foreach (string sFontFile in aFontFiles)
{
try
{
m_mapFontNameToFullPath.Add(
Path.GetFileName(sFontFile).ToUpper(), sFontFile);
}
catch (ArgumentException)
{
}
}
}
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);
string sNameToDecode;
if (m_sFontName.Length > gc_sJsExtention.Length && gc_sJsExtention == m_sFontName.Substring(m_sFontName.Length - gc_sJsExtention.Length))
sNameToDecode = m_sFontName.Substring(0, m_sFontName.Length - gc_sJsExtention.Length);
else
sNameToDecode = m_sFontName;
byte[] data_decode = Odtff_fonts.ZBase32Encoder.Decode(sNameToDecode);
string sFontNameDecoded = System.Text.Encoding.UTF8.GetString(data_decode);
_log.Info("fontnameDecoded: " + sFontNameDecoded);
context.Response.Clear();
context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(double.Parse(ConfigurationManager.AppSettings["resource.expires"], Constants.mc_oCultureInfo)));
context.Response.Cache.SetSlidingExpiration(false);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.ContentType = Utils.GetMimeType(sFontNameDecoded);
string contentDisposition = Utils.GetContentDisposition(context.Request.UserAgent, context.Request.Browser.Browser, context.Request.Browser.Version, m_sFontName);
context.Response.AppendHeader("Content-Disposition", contentDisposition);
string sRealFontName = sFontNameDecoded;
if (gc_sJsExtention == Path.GetExtension(sRealFontName))
sRealFontName = sRealFontName.Substring(0, sRealFontName.Length - gc_sJsExtention.Length);
string strFilepath;
m_mapFontNameToFullPath.TryGetValue(sRealFontName.ToUpper(), out strFilepath);
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.ToLocalTime());
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, sFontNameDecoded);
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.QueryString.ToString());
_log.Error("Exeption catched in BeginProcessRequest:", e);
}
TransportClass oTempTransportClass = new TransportClass(context, cb, 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 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 (gc_sJsExtention == Path.GetExtension(oTransportClass.m_sFontNameDecoded))
{
aOutput = GetJsContent(oTransportClass.m_aBuffer, oTransportClass.m_sFontNameDecoded.Substring(0, oTransportClass.m_sFontNameDecoded.Length - gc_sJsExtention.Length));
oTransportClass.nReadWriteBytes = aOutput.Length;
}
else
{
aOutput = oTransportClass.m_aBuffer;
byte[] guidOdttf = {0xA0, 0x66, 0xD6, 0x20, 0x14, 0x96, 0x47, 0xfa, 0x95, 0x69, 0xB8, 0x50, 0xB0, 0x41, 0x49, 0x48};
int nMaxLen = Math.Min(32, aOutput.Length);
for (int i = 0; i < nMaxLen; ++i)
aOutput[i] ^= guidOdttf[i % 16];
}
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.AppendHeader("Content-Length", oTransportClass.nReadWriteBytes.ToString());
context.Response.StatusCode = (int)HttpStatusCode.OK;
}
catch (HttpException httpEx)
{
_log.Error("HttpException catched in WriteBufferCallback:", httpEx);
}
catch (Exception e)
{
_log.Error("Exception catched in WriteBufferCallback:", e);
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
}
try
{
if (context.Response.IsClientConnected)
{
context.Response.Flush();
}
}
catch (Exception e)
{
_log.Error("Exception catched in WriteBufferCallback, while response end:", e);
}
finally
{
try
{
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
catch(Exception e)
{
_log.Error("Exception catched in WriteBufferCallback, while callback:", e);
}
}
}
private byte[] GetJsContent(byte[] aBuffer, string sFilename)
{
string data = Convert.ToBase64String(aBuffer);
string sRes = string.Format("window[\"{0}\"] = \"{1};{2}\";", sFilename, aBuffer.Length, data);
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 string m_sFontNameDecoded;
public TransportClass(HttpContext oContext, AsyncCallback oCallback, FileStream oFileStreamInput, byte[] aBuffer, string sFontNameDecoded)
{
m_oContext = oContext;
m_oCallback = oCallback;
m_oFileStreamInput = oFileStreamInput;
m_aBuffer = aBuffer;
m_sFontNameDecoded = sFontNameDecoded;
}
}
}

View File

@@ -0,0 +1,157 @@
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
namespace Odtff_fonts
{
public static class ZBase32Encoder
{
private const string EncodingTable = "ybndrfg8ejkmcpqxot1uwisza345h769";
private static readonly byte[] DecodingTable = new byte[128];
static ZBase32Encoder()
{
for (var i = 0; i < DecodingTable.Length; ++i)
{
DecodingTable[i] = byte.MaxValue;
}
for (var i = 0; i < EncodingTable.Length; ++i)
{
DecodingTable[EncodingTable[i]] = (byte)i;
}
}
public static string Encode(byte[] data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
var encodedResult = new StringBuilder((int)Math.Ceiling(data.Length * 8.0 / 5.0));
for (var i = 0; i < data.Length; i += 5)
{
var byteCount = Math.Min(5, data.Length - i);
ulong buffer = 0;
for (var j = 0; j < byteCount; ++j)
{
buffer = (buffer << 8) | data[i + j];
}
var bitCount = byteCount * 8;
while (bitCount > 0)
{
var index = bitCount >= 5
? (int)(buffer >> (bitCount - 5)) & 0x1f
: (int)(buffer & (ulong)(0x1f >> (5 - bitCount))) << (5 - bitCount);
encodedResult.Append(EncodingTable[index]);
bitCount -= 5;
}
}
return encodedResult.ToString();
}
public static byte[] Decode(string data)
{
if (data == string.Empty)
{
return new byte[0];
}
var result = new List<byte>((int)Math.Ceiling(data.Length * 5.0 / 8.0));
var index = new int[8];
for (var i = 0; i < data.Length; )
{
i = CreateIndexByOctetAndMovePosition(ref data, i, ref index);
var shortByteCount = 0;
ulong buffer = 0;
for (var j = 0; j < 8 && index[j] != -1; ++j)
{
buffer = (buffer << 5) | (ulong)(DecodingTable[index[j]] & 0x1f);
shortByteCount++;
}
var bitCount = shortByteCount * 5;
while (bitCount >= 8)
{
result.Add((byte)((buffer >> (bitCount - 8)) & 0xff));
bitCount -= 8;
}
}
return result.ToArray();
}
private static int CreateIndexByOctetAndMovePosition(ref string data, int currentPosition, ref int[] index)
{
var j = 0;
while (j < 8)
{
if (currentPosition >= data.Length)
{
index[j++] = -1;
continue;
}
if (IgnoredSymbol(data[currentPosition]))
{
currentPosition++;
continue;
}
index[j] = data[currentPosition];
j++;
currentPosition++;
}
return currentPosition;
}
private static bool IgnoredSymbol(char checkedSymbol)
{
return checkedSymbol >= DecodingTable.Length || DecodingTable[checkedSymbol] == byte.MaxValue;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,360 @@
<%@ WebHandler Language="C#" Class="ConvertService2" %>
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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.Threading;
using FileConverterUtils2;
using log4net;
public class ConvertService2 : IHttpAsyncHandler
{
private readonly ILog _log = LogManager.GetLogger(typeof(ConvertService2));
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
{
TransportClassMainAshx oTransportClassMainAshx = new TransportClassMainAshx(context, cb);
ErrorTypes eError = ErrorTypes.NoError;
try
{
_log.Info("Starting process request...");
_log.Info(context.Request.QueryString.ToString());
InputParams oInputParams = new InputParams();
oInputParams.m_sKey = context.Request.QueryString["key"];
oInputParams.m_svKey = context.Request.QueryString["vkey"];
oInputParams.m_sUrl = context.Request.QueryString["url"];
oInputParams.m_sEmbeddedfonts = context.Request.QueryString["embeddedfonts"];
int nIndexSep = oInputParams.m_sUrl.IndexOf(',');
if (-1 != nIndexSep)
oInputParams.m_sUrl = oInputParams.m_sUrl.Substring(0, nIndexSep);
oInputParams.m_sTitle = context.Request.QueryString["title"];
if (string.IsNullOrEmpty(oInputParams.m_sTitle))
oInputParams.m_sTitle = "convert";
oInputParams.m_sFiletype = context.Request.QueryString["filetype"];
oInputParams.m_nOutputtype = FileFormats.FromString(context.Request.QueryString["outputtype"]);
oInputParams.m_bAsyncConvert = Convert.ToBoolean(context.Request.QueryString["async"]);
oInputParams.m_sCodepage = context.Request.QueryString["codePage"];
oInputParams.m_sDelimiter = context.Request.QueryString["delimiter"];
if (ErrorTypes.NoError == eError)
{
ITaskResultInterface oTaskResult = TaskResult.NewTaskResult();
TaskResultData oToAdd = new TaskResultData();
oInputParams.m_sKey = "conv_" + oInputParams.m_sKey;
oToAdd.sKey = oInputParams.m_sKey;
oToAdd.sFormat = oInputParams.m_sFiletype;
oToAdd.eStatus = FileStatus.WaitQueue;
oToAdd.sTitle = oInputParams.m_sTitle;
TransportClass1 oTransportClass1 = new TransportClass1(oTransportClassMainAshx, oTaskResult, new CTaskQueue(), oInputParams);
oTaskResult.GetOrCreateBegin(oInputParams.m_sKey, oToAdd, GetOrCreateCallback, oTransportClass1);
}
}
catch(Exception e)
{
eError = ErrorTypes.Unknown;
_log.Error(context.Request.QueryString.ToString());
_log.Error("Exeption: ", e);
}
finally
{
if( ErrorTypes.NoError != eError )
WriteOutputCommand(oTransportClassMainAshx, new OutputCommand(null, null, null, eError));
}
return new AsyncOperationData(extraData);
}
public void EndProcessRequest(IAsyncResult result)
{
}
public void ProcessRequest(HttpContext context)
{
throw new InvalidOperationException();
}
public bool IsReusable
{
get
{
return false;
}
}
private void WriteOutputCommand(TransportClassMainAshx oTransportClassMainAshx, OutputCommand oOutputCommand)
{
HttpContext oHttpContext = oTransportClassMainAshx.m_oHttpContext;
AsyncCallback fAsyncCallback = oTransportClassMainAshx.m_oAsyncCallback;
oHttpContext.Response.ContentType = "text/xml";
oHttpContext.Response.Charset = "UTF-8";
string sXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><FileResult>";
if (null != oOutputCommand.m_sFileUrl)
sXml += string.Format("<FileUrl>{0}</FileUrl>", HttpUtility.HtmlEncode(oOutputCommand.m_sFileUrl));
if (null != oOutputCommand.m_sPercent)
sXml += string.Format("<Percent>{0}</Percent>", oOutputCommand.m_sPercent);
if (true == oOutputCommand.m_bIsEndConvert.HasValue)
sXml += string.Format("<EndConvert>{0}</EndConvert>", oOutputCommand.m_bIsEndConvert.Value.ToString());
if (ErrorTypes.NoError != oOutputCommand.m_eError)
sXml += string.Format("<Error>{0}</Error>", Utils.mapAscServerErrorToOldError(oOutputCommand.m_eError).ToString());
sXml += "</FileResult>";
oHttpContext.Response.Write(sXml);
fAsyncCallback.Invoke(new AsyncOperationData(null));
}
private void GetOrCreateCallback(IAsyncResult ar)
{
TransportClass1 oTransportClass1 = ar.AsyncState as TransportClass1;
try
{
TaskResultData oTaskResultData;
bool bCreate;
ErrorTypes eError = oTransportClass1.m_oTaskResult.GetOrCreateEnd(ar, out oTaskResultData, out bCreate);
if (ErrorTypes.NoError == eError)
{
if(bCreate)
{
InputParams oInputParams = oTransportClass1.m_oInputParams;
TaskQueueData oTaskQueueData = new TaskQueueData(oInputParams.m_sKey, oInputParams.m_nOutputtype, "output." + FileFormats.ToString(oInputParams.m_nOutputtype));
oTaskQueueData.m_sFromUrl = oInputParams.m_sUrl;
oTaskQueueData.m_sFromFormat = oInputParams.m_sFiletype;
if (null != oInputParams.m_sDelimiter && string.Empty != oInputParams.m_sDelimiter)
oTaskQueueData.m_nCsvDelimiter = int.Parse(oInputParams.m_sDelimiter);
else
oTaskQueueData.m_nCsvDelimiter = (int)CsvDelimiter.Comma;
if (null != oInputParams.m_sCodepage && string.Empty != oInputParams.m_sCodepage)
oTaskQueueData.m_nCsvTxtEncoding = int.Parse(oInputParams.m_sCodepage);
else
oTaskQueueData.m_nCsvTxtEncoding = Encoding.UTF8.CodePage;
if ("true" == oInputParams.m_sEmbeddedfonts)
oTaskQueueData.m_bEmbeddedFonts = true;
oTransportClass1.m_oTaskQueue.AddTaskBegin(oTaskQueueData, Priority.Low, AddTaskCallback, oTransportClass1);
}
else
CheckStatus(oTransportClass1, oTaskResultData);
}
else
WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, eError));
}
catch
{
WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, ErrorTypes.Unknown));
}
}
private void AddTaskCallback(IAsyncResult ar)
{
TransportClass1 oTransportClass1 = ar.AsyncState as TransportClass1;
try
{
ErrorTypes eError = oTransportClass1.m_oTaskQueue.AddTaskEnd(ar);
if (ErrorTypes.NoError == eError)
{
if (true == oTransportClass1.m_oInputParams.m_bAsyncConvert)
WriteOutputCommand(oTransportClass1, new OutputCommand("", "0", false, ErrorTypes.NoError));
else
WaitEnd(oTransportClass1);
}
else
WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, eError));
}
catch
{
WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, ErrorTypes.Unknown));
}
}
private void CheckStatus(TransportClass1 oTransportClass1, TaskResultData oTaskResultData)
{
switch (oTaskResultData.eStatus)
{
case FileStatus.Ok:
string sFilename = HttpUtility.UrlEncode("output." + FileFormats.ToString(oTransportClass1.m_oInputParams.m_nOutputtype));
string sPath = HttpUtility.UrlEncode(Path.GetFileNameWithoutExtension(oTransportClass1.m_oInputParams.m_sKey) + "/output." + FileFormats.ToString(oTransportClass1.m_oInputParams.m_nOutputtype));
string sDeletePath = HttpUtility.UrlEncode(Path.GetFileNameWithoutExtension(oTransportClass1.m_oInputParams.m_sKey));
string sSiteUrl = UrlBuilder.UrlWithoutPath(oTransportClass1.m_oHttpContext.Request);
string strFileUrl = sSiteUrl + Constants.mc_sResourceServiceUrlRel + sPath + "&nocache=true" +"&deletepath=" + sDeletePath + "&filename=" + sFilename;
WriteOutputCommand(oTransportClass1, new OutputCommand(strFileUrl, "100", true, ErrorTypes.NoError));
break;
case FileStatus.WaitQueue:
if (oTransportClass1.m_oInputParams.m_bAsyncConvert)
WriteOutputCommand(oTransportClass1, new OutputCommand("", "0", false, ErrorTypes.NoError));
else
WaitEnd(oTransportClass1);
break;
case FileStatus.Convert:
if (oTransportClass1.m_oInputParams.m_bAsyncConvert)
WriteOutputCommand(oTransportClass1, new OutputCommand("", oTaskResultData.nStatusInfo.ToString(), false, ErrorTypes.NoError));
else
WaitEnd(oTransportClass1);
break;
case FileStatus.Err:
case FileStatus.ErrToReload:
AsyncClearCacheOperation oAsyncClearCacheOperation = new AsyncClearCacheOperation();
TransportClass2 oTransportClass2 = new TransportClass2(oTransportClass1, oAsyncClearCacheOperation, (ErrorTypes)oTaskResultData.nStatusInfo);
oAsyncClearCacheOperation.ClearCacheBegin(oTransportClass1.m_oInputParams.m_sKey, ClearCacheCallback, oTransportClass2);
break;
default:
WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, ErrorTypes.Unknown));
break;
}
}
private void WaitEnd(TransportClass1 oTransportClass1)
{
try
{
Timer oTimer = new Timer(WaitEndTimerCallback, oTransportClass1, TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
oTransportClass1.m_oTimer = oTimer;
oTimer.Change(TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(-1));
}
catch
{
WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, ErrorTypes.Unknown));
}
}
private void WaitEndTimerCallback(Object stateInfo)
{
TransportClass1 oTransportClass1 = stateInfo as TransportClass1;
try
{
if (null != oTransportClass1.m_oTimer)
oTransportClass1.m_oTimer.Dispose();
oTransportClass1.m_oTaskResult.GetBegin(oTransportClass1.m_oInputParams.m_sKey, WaitEndCallback, oTransportClass1);
}
catch
{
WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, ErrorTypes.Unknown));
}
}
private void WaitEndCallback(IAsyncResult ar)
{
TransportClass1 oTransportClass1 = ar.AsyncState as TransportClass1;
try
{
TaskResultData oTaskResultData;
ErrorTypes eError = oTransportClass1.m_oTaskResult.GetEnd(ar, out oTaskResultData);
if (ErrorTypes.NoError == eError)
CheckStatus(oTransportClass1, oTaskResultData);
else
WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, eError));
}
catch
{
WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, ErrorTypes.Unknown));
}
}
private void ClearCacheCallback(IAsyncResult ar)
{
TransportClass2 oTransportClass2 = ar.AsyncState as TransportClass2;
try
{
ErrorTypes eError = oTransportClass2.m_oAsyncClearCacheOperation.ClearCacheEnd(ar);
if (ErrorTypes.NoError == eError)
{
WriteOutputCommand(oTransportClass2, new OutputCommand(null, null, null, oTransportClass2.m_eError));
}
else
WriteOutputCommand(oTransportClass2, new OutputCommand(null, null, null, eError));
}
catch
{
WriteOutputCommand(oTransportClass2, new OutputCommand(null, null, null, ErrorTypes.Unknown));
}
}
private class TransportClass1 : TransportClassMainAshx
{
public ITaskResultInterface m_oTaskResult;
public CTaskQueue m_oTaskQueue;
public InputParams m_oInputParams;
public Timer m_oTimer;
public TransportClass1(TransportClassMainAshx oTransportClassMainAshx, ITaskResultInterface oTaskResult, CTaskQueue oTaskQueue, InputParams oInputParams)
: base(oTransportClassMainAshx.m_oHttpContext, oTransportClassMainAshx.m_oAsyncCallback)
{
m_oTaskResult = oTaskResult;
m_oInputParams = oInputParams;
m_oTaskQueue = oTaskQueue;
m_oTimer = null;
}
}
private class TransportClass2 : TransportClassMainAshx
{
public AsyncClearCacheOperation m_oAsyncClearCacheOperation;
public ErrorTypes m_eError;
public TransportClass2(TransportClassMainAshx oTransportClassMainAshx, AsyncClearCacheOperation oAsyncClearCacheOperation, ErrorTypes eError)
: base(oTransportClassMainAshx.m_oHttpContext, oTransportClassMainAshx.m_oAsyncCallback)
{
m_oAsyncClearCacheOperation = oAsyncClearCacheOperation;
m_eError = eError;
}
}
private class InputParams
{
public string m_sKey;
public string m_svKey;
public string m_sUrl;
public string m_sTitle;
public string m_sFiletype;
public int m_nOutputtype;
public bool m_bAsyncConvert;
public string m_sEmbeddedfonts;
public string m_sCodepage;
public string m_sDelimiter;
}
private class OutputCommand
{
public string m_sFileUrl;
public string m_sPercent;
public bool? m_bIsEndConvert;
public ErrorTypes m_eError;
public OutputCommand(string strFileUrl, string strPercent, bool? bIsEndConvert, ErrorTypes eError)
{
m_sFileUrl = strFileUrl;
m_sPercent = strPercent;
m_bIsEndConvert = bIsEndConvert;
m_eError = eError;
}
}
}

View File

@@ -1,205 +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;
}
}
<%@ WebHandler Language="C#" Class="FileUploader" %>
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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.QueryString.ToString());
string vKey = context.Request.QueryString["vkey"];
string sKey = context.Request.QueryString["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 sFilename = sKey + ".tmp";
string sPath = sTempKey + "/" + sFilename;
AsyncContextReadOperation asynch = new AsyncContextReadOperation();
TransportClass oTransportClass = new TransportClass(context, cb, oStorage, asynch, sPath, sTempKey, sFilename);
asynch.ReadContextBegin(context.Request.InputStream, ReadContextCallback, oTransportClass);
}
}
}
catch(Exception e)
{
eError = ErrorTypes.Unknown;
_log.Error(context.Request.QueryString.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, 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);
oTransportClass.m_oAsyncContextRead.m_aOutput.Position = 0;
oTransportClass.m_oStorage.WriteFileBegin(oTransportClass.m_sPath, oTransportClass.m_oAsyncContextRead.m_aOutput, 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)
{
string sSiteUrl = UrlBuilder.UrlWithoutPath(oTransportClass.m_oContext.Request);
string sFileUrl = sSiteUrl + Constants.mc_sResourceServiceUrlRel + HttpUtility.UrlEncode(oTransportClass.m_sPath) + "&nocache=true" + "&deletepath=" + HttpUtility.UrlEncode(oTransportClass.m_sDeletePath) + "&filename=" + HttpUtility.UrlEncode(oTransportClass.m_sFilename);
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 string m_sFilename;
public TransportClass(HttpContext oContext, AsyncCallback oCallback, Storage oStorage, AsyncContextReadOperation oAsyncContextRead, string sPath, string sDeletePath, string sFilename)
{
m_oContext = oContext;
m_oCallback = oCallback;
m_oStorage = oStorage;
m_oAsyncContextRead = oAsyncContextRead;
m_sPath = sPath;
m_sDeletePath = sDeletePath;
m_sFilename = sFilename;
}
}
}

View File

@@ -1,33 +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
*
*/
<%@ WebHandler Language="C#" CodeBehind="App_Code/FontService.ashx.cs" Class="FontService" %>
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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
*
*/

View File

@@ -1,160 +1,101 @@
<%@ 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>
<%@ 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-2015
*
* 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
*
*/
static public Object lockThis = new Object();
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()));
routes.Add(new Route(sRoute + "odttf/{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);
}
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

@@ -1,298 +1,356 @@
<%@ 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 sPathOriginal = context.Request.Params["path"];
string sPath = null;
if (null != sPathOriginal)
{
sPath = sPathOriginal.Replace("../", "").Replace("..\\", "");
if (sPathOriginal != sPath)
{
_log.Error("Possible XSS attack:" + sPathOriginal);
}
}
string sOutputFilename = context.Request.Params["filename"];
string sDeletePathOriginal = context.Request.Params["deletepath"];
string sDeletePath = null;
if (null != sDeletePathOriginal)
{
sDeletePath = sDeletePathOriginal.Replace("../", "").Replace("..\\", "");
if (sDeletePathOriginal != sDeletePath)
{
_log.Error("Possible XSS attack:" + sDeletePathOriginal);
}
}
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;
}
}
<%@ WebHandler Language="C#" Class="ResourceService" %>
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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.QueryString.ToString());
Storage oStorage = new Storage();
ITaskResultInterface oTaskResult = TaskResult.NewTaskResult();
string sPathOriginal = context.Request.QueryString["path"];
string sPath = null;
if (null != sPathOriginal)
{
sPath = sPathOriginal.Replace("../", "").Replace("..\\", "");
if (sPathOriginal != sPath)
{
_log.Error("Possible XSS attack:" + sPathOriginal);
}
}
string sOutputFilename = context.Request.QueryString["filename"];
string sDeletePathOriginal = context.Request.QueryString["deletepath"];
string sDeletePath = null;
if (null != sDeletePathOriginal)
{
sDeletePath = sDeletePathOriginal.Replace("../", "").Replace("..\\", "");
if (sDeletePathOriginal != sDeletePath)
{
_log.Error("Possible XSS attack:" + sDeletePathOriginal);
}
}
string sNoCache = context.Request.QueryString["nocache"];
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.SetCacheability(HttpCacheability.Public);
context.Response.ContentType = Utils.GetMimeType(sOutputFilename);
string contentDisposition = Utils.GetContentDisposition(context.Request.UserAgent, context.Request.Browser.Browser, context.Request.Browser.Version, sOutputFilename);
context.Response.AppendHeader("Content-Disposition", contentDisposition);
if (null != sPath)
{
TransportClass oTransportClass = new TransportClass(context, cb, oStorage, oTaskResult, sPath, sDeletePath);
oStorage.GetFileInfoBegin(sPath, GetFileInfoCallback, oTransportClass);
bStartAsync = true;
}
else
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
}
catch(Exception e)
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
_log.Error(context.Request.QueryString.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)
{
return;
}
private void GetFileInfoCallback(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
HttpContext context = oTransportClass.m_oContext;
bool bStartAsync = false;
try
{
string sPath = oTransportClass.m_sPath;
Storage oStorage = oTransportClass.m_oStorage;
StorageFileInfo oStorageFileInfo;
if (ErrorTypes.NoError == oStorage.GetFileInfoEnd(result, out oStorageFileInfo) && null != oStorageFileInfo)
{
string sETag = oStorageFileInfo.m_oLastModify.Ticks.ToString("x");
DateTime oLastModified = oStorageFileInfo.m_oLastModify;
DateTime oDateTimeUtcNow = DateTime.UtcNow;
_log.InfoFormat("oLastModified = {0}", oLastModified);
_log.InfoFormat("oDateTimeUtcNow = {0}", oDateTimeUtcNow);
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.ToLocalTime());
oStorage.ReadFileBegin(sPath, context.Response.OutputStream, ReadFileCallback, oTransportClass);
bStartAsync = true;
}
}
else
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
}
catch (Exception e)
{
_log.Error("Exception catched in GetFileInfoCallback:", e);
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
}
if (!bStartAsync)
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
private void ReadFileCallback(IAsyncResult result)
{
SendResponse(result);
DeletePath(result);
}
private void DeletePath(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
try
{
if (null != oTransportClass.m_sDeletePath && false == string.IsNullOrEmpty(oTransportClass.m_sDeletePath))
{
ITaskResultInterface oTaskResult = oTransportClass.m_oTaskResult;
string sKey = oTransportClass.m_sDeletePath;
oTaskResult.RemoveBegin(sKey, RemoveTaskCallback, oTransportClass);
}
else
{
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
}
catch (Exception e)
{
_log.Error("Exception catched in DeletePath:", e);
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
}
private void SendResponse(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
HttpContext context = oTransportClass.m_oContext;
try
{
Storage oStorage = oTransportClass.m_oStorage;
if (null == oStorage)
{
throw new NullReferenceException();
}
int nReadWriteBytes = 0;
ErrorTypes eResult = oStorage.ReadFileEnd(result, out nReadWriteBytes);
if (ErrorTypes.NoError == eResult)
{
context.Response.AppendHeader("Content-Length", nReadWriteBytes.ToString());
context.Response.StatusCode = (int)HttpStatusCode.OK;
}
}
catch (HttpException httpEx)
{
_log.Error("HttpException catched in SendResponse:", httpEx);
}
catch (Exception e)
{
_log.Error("Exception catched in SendResponse:", e);
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
}
try
{
if (context.Response.IsClientConnected)
{
context.Response.Flush();
}
}
catch (Exception e)
{
_log.Error("Exception catched in SendResponse, while response end:", e);
}
}
private void RemoveTaskCallback(IAsyncResult result)
{
TransportClass oTransportClass = result.AsyncState as TransportClass;
try
{
ITaskResultInterface 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)
{
_log.Error("Exception catched in RemoveTaskCallback:", e);
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
}
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)
{
_log.Error("Exception catched in RemoveFileCallback:", e);
oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
}
}
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 ITaskResultInterface m_oTaskResult;
public string m_sPath;
public string m_sDeletePath;
public TransportClass(HttpContext oContext, AsyncCallback oCallback, Storage oStorage, ITaskResultInterface 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,55 @@
<%@ WebHandler Language="C#" Class="TrackingService" %>
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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.Web;
using System.Xml;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using FileConverterUtils2;
public class TrackingService : IHttpHandler {
public void ProcessRequest (HttpContext context)
{
}
public bool IsReusable {
get {
return false;
}
}
}

View File

@@ -1,333 +1,363 @@
<%@ 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
<%@ WebHandler Language="C#" Class="UploadService" %>
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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;
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)
{
TransportClassMainAshx oTransportClassMainAshx = new TransportClassMainAshx(context, cb);
ErrorTypes eError = ErrorTypes.NoError;
try
{
_log.Info("Starting process request...");
_log.Info(context.Request.QueryString.ToString());
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)
{
int nParamsCount = 0;
string sInputParams = "";
for (int i = 0, length = context.Request.QueryString.Count; i < length; ++i)
{
sInputParams += context.Request.QueryString.Get(i) + ":" + context.Request.QueryString.GetKey(i);
if (nParamsCount > 0)
sInputParams += ",";
nParamsCount++;
}
AsyncMediaXmlOperation oAsyncMediaXmlOperation = new AsyncMediaXmlOperation();
List<string> aUrls = new List<string>();
TransportClass1 oTransportClass1 = new TransportClass1(oTransportClassMainAshx, oAsyncMediaXmlOperation, context.Request.QueryString, aUrls, sGuid, Path.Combine(sGuid, @"media/media.xml"), context.Request.Files, context.Request.Files.GetEnumerator());
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.QueryString.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, List<string> aUrls, 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));
}
oOutputCommand.urls = aUrls;
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 GetMediaXmlCallbackProcess(TransportClass1 oTransportClass1, Dictionary<string, string> aMediaXmlMapHash, Dictionary<string, string> aMediaXmlMapFilename)
{
AsyncContextReadOperation oAsyncContextReadOperation = new AsyncContextReadOperation();
TransportClass2 oTransportClass2 = new TransportClass2(oTransportClass1, aMediaXmlMapHash, aMediaXmlMapFilename, oAsyncContextReadOperation);
HttpPostedFile oCurrentFile = (HttpPostedFile)oTransportClass1.m_oFiles[(string)oTransportClass1.m_oFilesEnumerator.Current];
oCurrentFile.InputStream.Position = 0;
oAsyncContextReadOperation.ReadContextBegin(oCurrentFile.InputStream, ReadContextCallback, oTransportClass2);
}
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 && oTransportClass1.m_oFilesEnumerator.MoveNext())
{
GetMediaXmlCallbackProcess(oTransportClass1, aMediaXmlMapHash, aMediaXmlMapFilename);
}
else
WriteToResponse(oTransportClass1, eError, null, oTransportClass1.m_aInputParams);
}
catch(Exception e)
{
_log.Error("Exeption: ", e);
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)
{
HttpPostedFile oCurrentFile = ((HttpPostedFile)oTransportClass2.m_oFiles[(string)oTransportClass2.m_oFilesEnumerator.Current]);
oCurrentFile.InputStream.Position = 0;
Stream oImageStream = oCurrentFile.InputStream;
byte[] aBuffer = oTransportClass2.m_oAsyncContextReadOperation.m_aOutput.ToArray();
int nImageFormat = FormatChecker.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)))
{
if (FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE_GIF == nImageFormat || FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE_ICO == nImageFormat)
{
byte[] aNewBuffer;
if (Utils.ConvertGifIcoToPng(aBuffer, nImageFormat, out aNewBuffer))
{
nImageFormat = FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE_PNG;
aBuffer = aNewBuffer;
oImageStream = new MemoryStream(aBuffer);
}
}
string sImageHash = null;
using (MemoryStream ms = new MemoryStream(aBuffer))
sImageHash = Utils.getMD5HexString(ms);
string sFileName;
if (oTransportClass2.m_oMediaXmlMapHash.TryGetValue(sImageHash, out sFileName))
{
ImageUrlProcess(oTransportClass2, Constants.mc_sResourceServiceUrlRel + Path.Combine(oTransportClass2.m_sKey, @"media\" + sFileName).Replace('\\', '/'));
}
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);
oTransportClass3.m_oStorage.WriteFileBegin(sNewPath, oImageStream, WriteUploadedFileCallback, oTransportClass3);
}
}
else
WriteToResponse(oTransportClass2, ErrorTypes.UploadExtension, null, oTransportClass2.m_aInputParams);
}
else
WriteToResponse(oTransportClass2, eError, null, oTransportClass2.m_aInputParams);
}
catch (Exception e)
{
_log.Error("Exeption: ", e);
WriteToResponse(oTransportClass2, ErrorTypes.Upload, null, oTransportClass2.m_aInputParams);
}
}
private void ImageUrlProcess(TransportClass2 oTransportClass2, string sUrl)
{
oTransportClass2.m_aUrls.Add(sUrl);
if (oTransportClass2.m_oFilesEnumerator.MoveNext())
GetMediaXmlCallbackProcess(oTransportClass2, oTransportClass2.m_oMediaXmlMapHash, oTransportClass2.m_oMediaXmlMapFilename);
else
oTransportClass2.m_oAsyncMediaXmlOperation.WriteMediaXmlBegin(oTransportClass2.m_sMediaXml, oTransportClass2.m_oMediaXmlMapHash, WriteMediaXmlCallback, oTransportClass2);
}
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_oMediaXmlMapFilename.Add(oTransportClass3.m_sFilename, oTransportClass3.m_sHash);
ImageUrlProcess(oTransportClass3, Constants.mc_sResourceServiceUrlRel + oTransportClass3.m_sPath.Replace('\\', '/'));
}
else
WriteToResponse(oTransportClass3, eError, null, oTransportClass3.m_aInputParams);
}
catch (Exception e)
{
_log.Error("Exeption: ", e);
WriteToResponse(oTransportClass3, ErrorTypes.Upload, null, oTransportClass3.m_aInputParams);
}
}
private void WriteMediaXmlCallback(IAsyncResult ar)
{
TransportClass1 oTransportClass1 = ar.AsyncState as TransportClass1;
try
{
ErrorTypes eError = oTransportClass1.m_oAsyncMediaXmlOperation.WriteMediaXmlEnd(ar);
if (ErrorTypes.NoError == eError)
WriteToResponse(oTransportClass1, ErrorTypes.NoError, oTransportClass1.m_aUrls, oTransportClass1.m_aInputParams);
else
WriteToResponse(oTransportClass1, eError, null, oTransportClass1.m_aInputParams);
}
catch (Exception e)
{
_log.Error("Exeption: ", e);
WriteToResponse(oTransportClass1, ErrorTypes.Upload, null, oTransportClass1.m_aInputParams);
}
}
#endregion
#region TransportClass
private class TransportClass1 : TransportClassMainAshx
{
public AsyncMediaXmlOperation m_oAsyncMediaXmlOperation;
public NameValueCollection m_aInputParams;
public List<string> m_aUrls = new List<string>();
public string m_sKey;
public string m_sMediaXml;
public HttpFileCollection m_oFiles;
public IEnumerator m_oFilesEnumerator;
public TransportClass1(TransportClassMainAshx oTransportClassMainAshx, AsyncMediaXmlOperation oAsyncMediaXmlOperation, NameValueCollection aInputParams, List<string> aUrls, string sKey, string sMediaXml, HttpFileCollection oFiles, IEnumerator oFilesEnumerator)
: base(oTransportClassMainAshx.m_oHttpContext, oTransportClassMainAshx.m_oAsyncCallback)
{
m_oAsyncMediaXmlOperation = oAsyncMediaXmlOperation;
m_aInputParams = aInputParams;
m_sKey = sKey;
m_oFiles = oFiles;
m_oFilesEnumerator = oFilesEnumerator;
m_sMediaXml = sMediaXml;
m_aUrls = aUrls;
}
}
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_aUrls, oTransportClass1.m_sKey, oTransportClass1.m_sMediaXml, oTransportClass1.m_oFiles, oTransportClass1.m_oFilesEnumerator)
{
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(oTransportClass2, 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 List<string> urls = new List<string>();
public int error;
public Dictionary<string, object> input = new Dictionary<string,object>();
}
#endregion
}

View File

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

View File

@@ -1,106 +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;
}
<%@ WebHandler Language="C#" Class="fileDownloader" %>
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* 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.QueryString[0]))));
string sOutputFilename = null;
if (context.Request.QueryString.Count > 1)
sOutputFilename = context.Server.UrlDecode(context.Request.QueryString[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.AppendHeader("Content-Length", file.Length.ToString());
context.Response.TransmitFile(file.FullName);
context.Response.Flush();
context.ApplicationInstance.CompleteRequest();
}
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;
}
}

View File

@@ -1,255 +1,275 @@
<?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="" 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>
<?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="" 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="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
<conversionPattern value="%date %-5level [%thread] %logger - %message%newline" />
</layout>
<file value="/var/log/onlyoffice/documentserver/DocService.log" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd-HHmm" />
</appender>
<root>
<level value="WARN" />
<appender-ref ref="RollingFileAppender" />
</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" />
</DbProviderFactories>
</system.data>
<appSettings file="/var/www/onlyoffice/documentserver/DocService/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="OnlineEditorsExample" />
<!-- 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;fb2" />
<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;fb2" />
<add key="editor.settings.autosave.enable" value="true" />
<add key="editor.settings.autosave.mininterval" value="300" />
<add key="editor.settings.coauthoring.url" value="/coauthoring" />
<add key="editor.settings.spellchecker.url" value="/spellchecker" />
<add key="resource.expires" value="1440" />
<add key="limits.image.types.upload" value="jpg;png;gif;bmp;ico" />
<add key="limits.image.types.copy" value="jpg;png;gif;bmp;emf;wmf;svg" />
<add key="limits.image.size" value="25000000" />
<add key="license.type" value="7" />
<add key="license.activeconnections.tracking.interval" value="300" />
<add key="license.activeconnections.tracking.cleanupperiods" value="2" />
<add key="license.file.path" value="/var/www/onlyoffice/Data/" />
<add key="fonts.route" value="OfficeWeb/sdk/Fonts/" />
<add key="sfc.webrequest.attempcount" value="3" />
<add key="sfc.webrequest.attempdelay" value="1000" />
</appSettings>
<connectionStrings configSource="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>
<customErrors mode="Off" />
</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" compilerOptions="/d:OPEN_SOURCE">
<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" compilerOptions="/d:OPEN_SOURCE">
<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" />
<remove fileExtension=".woff" />
<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" />
<mimeMap fileExtension=".template" mimeType="text/html" />
<mimeMap fileExtension=".less" mimeType="text/css" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<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>