public ErrorCommandHandler(ConnectorException connectorException) : base() { _ErrorNumber = connectorException.Number; }
protected override void BuildXml() { if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileDelete)) { ConnectorException.Throw(Errors.Unauthorized); } string fileName = Request["FileName"]; if (!Connector.CheckFileName(fileName) || Config.Current.CheckIsHiddenFile(fileName)) { ConnectorException.Throw(Errors.InvalidRequest); return; } if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(System.IO.Path.GetExtension(fileName))) { ConnectorException.Throw(Errors.InvalidRequest); return; } string filePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, fileName); bool bDeleted = false; if (!System.IO.File.Exists(filePath)) { ConnectorException.Throw(Errors.FileNotFound); } try { System.IO.File.Delete(filePath); bDeleted = true; } catch (System.UnauthorizedAccessException) { ConnectorException.Throw(Errors.AccessDenied); } catch (System.Security.SecurityException) { ConnectorException.Throw(Errors.AccessDenied); } catch (System.ArgumentException) { ConnectorException.Throw(Errors.FileNotFound); } catch (System.IO.PathTooLongException) { ConnectorException.Throw(Errors.FileNotFound); } catch (Exception) { ConnectorException.Throw(Errors.Unknown); } try { string thumbPath = System.IO.Path.Combine(this.CurrentFolder.ThumbsServerPath, fileName); System.IO.File.Delete(thumbPath); } catch { /* No errors if we are not able to delete the thumb. */ } if (bDeleted) { XmlNode oDeletedFileNode = XmlUtil.AppendElement(this.ConnectorNode, "DeletedFile"); XmlUtil.SetAttribute(oDeletedFileNode, "name", fileName); } }
protected override void BuildXml() { if (Request.Form["CKFinderCommand"] != "true") { ConnectorException.Throw(Errors.InvalidRequest); } if (!this.CurrentFolder.CheckAcl(AccessControlRules.FolderRename)) { ConnectorException.Throw(Errors.Unauthorized); } // The root folder cannot be deleted. if (this.CurrentFolder.ClientPath == "/") { ConnectorException.Throw(Errors.InvalidRequest); return; } string newFileName = Request["NewFolderName"]; if (!Connector.CheckFolderName(newFileName) || Config.Current.CheckIsHiddenFolder(newFileName)) { ConnectorException.Throw(Errors.InvalidName); return; } // Get the current folder. System.IO.DirectoryInfo oDir = new System.IO.DirectoryInfo(this.CurrentFolder.ServerPath); bool bMoved = false; try { if (!oDir.Exists) { ConnectorException.Throw(Errors.InvalidRequest); } else { // Build the new folder path. string newFolderPath = System.IO.Path.Combine(oDir.Parent.FullName, newFileName); if (System.IO.Directory.Exists(newFolderPath) || System.IO.File.Exists(newFolderPath)) { ConnectorException.Throw(Errors.AlreadyExist); } oDir.MoveTo(newFolderPath); bMoved = true; } } catch (System.UnauthorizedAccessException) { ConnectorException.Throw(Errors.AccessDenied); } catch (System.Security.SecurityException) { ConnectorException.Throw(Errors.AccessDenied); } catch (System.ArgumentException) { ConnectorException.Throw(Errors.InvalidName); } catch (System.NotSupportedException) { ConnectorException.Throw(Errors.InvalidName); } catch (System.IO.PathTooLongException) { ConnectorException.Throw(Errors.InvalidName); } catch (System.IO.IOException) { ConnectorException.Throw(Errors.Unknown); } catch (ConnectorException connectorException) { throw connectorException; } catch { #if DEBUG throw; #else ConnectorException.Throw(Errors.Unknown); #endif } if (bMoved) { try { // Get the thumbnails folder. System.IO.DirectoryInfo oThumbsDir = new System.IO.DirectoryInfo(this.CurrentFolder.ThumbsServerPath); // Build the new folder path. string newThumbsFolderPath = System.IO.Path.Combine(oThumbsDir.Parent.FullName, newFileName); if (System.IO.Directory.Exists(newThumbsFolderPath)) { System.IO.File.Delete(this.CurrentFolder.ThumbsServerPath); } else { try { oThumbsDir.MoveTo(newThumbsFolderPath); } catch { System.IO.File.Delete(this.CurrentFolder.ThumbsServerPath); } } } catch { /* No errors if we are not able to delete the thumb. */ } string newFolderPath = Regex.Replace(this.CurrentFolder.ClientPath, "[^/]+/?$", newFileName) + "/"; string newFolderUrl = this.CurrentFolder.ResourceTypeInfo.Url + newFolderPath.TrimStart('/'); XmlNode oRenamedNode = XmlUtil.AppendElement(this.ConnectorNode, "RenamedFolder"); XmlUtil.SetAttribute(oRenamedNode, "newName", newFileName); XmlUtil.SetAttribute(oRenamedNode, "newPath", newFolderPath); XmlUtil.SetAttribute(oRenamedNode, "newUrl", newFolderUrl); } }
protected override void BuildXml() { Config _Config = Config.Current; bool _IsEnabled = _Config.CheckAuthentication(); // Create the "ConnectorInfo" node. XmlNode oConnInfo = XmlUtil.AppendElement(this.ConnectorNode, "ConnectorInfo"); XmlUtil.SetAttribute(oConnInfo, "enabled", _IsEnabled.ToString().ToLower()); if (!_IsEnabled) { ConnectorException.Throw(Errors.ConnectorDisabled); } string ln = ""; string lc = _Config.LicenseKey.ToUpper(); if (1 == (K_CHARS.IndexOf(lc[0]) % 5)) { ln = _Config.LicenseName.ToLower(); } XmlUtil.SetAttribute(oConnInfo, "s", ln); XmlUtil.SetAttribute(oConnInfo, "c", string.Concat(lc[11], lc[0], lc[8], lc[12]).Trim()); XmlUtil.SetAttribute(oConnInfo, "thumbsEnabled", _Config.Thumbnails.Enabled.ToString().ToLower()); if (_Config.Thumbnails.Enabled) { XmlUtil.SetAttribute(oConnInfo, "thumbsUrl", _Config.Thumbnails.Url); XmlUtil.SetAttribute(oConnInfo, "thumbsDirectAccess", _Config.Thumbnails.DirectAccess.ToString().ToLower()); } // Create the "ResourceTypes" node. XmlNode oResourceTypes = XmlUtil.AppendElement(this.ConnectorNode, "ResourceTypes"); // Load the resource types in an array. string[] aTypes; if (Request.QueryString["type"] != null && Request.QueryString["type"].Length > 0) { aTypes = new string[] { Request.QueryString["type"] }; } else { string sDefaultTypes = Config.Current.DefaultResourceTypes; if (sDefaultTypes.Length == 0) { aTypes = new string[_Config.ResourceTypes.Count]; for (int i = 0; i < _Config.ResourceTypes.Count; i++) { aTypes[i] = _Config.ResourceTypes.GetByIndex(i).Name; } } else { aTypes = sDefaultTypes.Split(','); } } for (int i = 0; i < aTypes.Length; i++) { string resourceTypeName = aTypes[i]; int aclMask = Config.Current.AccessControl.GetComputedMask(resourceTypeName, "/"); if ((aclMask & (int)AccessControlRules.FolderView) != (int)AccessControlRules.FolderView) { continue; } Settings.ResourceType oTypeInfo = _Config.GetResourceTypeConfig(resourceTypeName); string sTargetDirectory = oTypeInfo.GetTargetDirectory(); bool bHasChildren = System.IO.Directory.Exists(sTargetDirectory) && (System.IO.Directory.GetDirectories(oTypeInfo.GetTargetDirectory()).Length > 0); XmlNode oResourceType = XmlUtil.AppendElement(oResourceTypes, "ResourceType"); XmlUtil.SetAttribute(oResourceType, "name", resourceTypeName); XmlUtil.SetAttribute(oResourceType, "url", oTypeInfo.Url); XmlUtil.SetAttribute(oResourceType, "allowedExtensions", string.Join(",", oTypeInfo.AllowedExtensions)); XmlUtil.SetAttribute(oResourceType, "deniedExtensions", string.Join(",", oTypeInfo.DeniedExtensions)); XmlUtil.SetAttribute(oResourceType, "hash", Util.GetMd5Hash(sTargetDirectory).Substring(0, 16)); XmlUtil.SetAttribute(oResourceType, "defaultView", "Thumbnails"); XmlUtil.SetAttribute(oResourceType, "hasChildren", (bHasChildren ? "true" : "false")); XmlUtil.SetAttribute(oResourceType, "acl", aclMask.ToString()); } }
protected override void BuildXml() { if (Request.Form["CKFinderCommand"] != "true") { ConnectorException.Throw(Errors.InvalidRequest); } if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileRename | AccessControlRules.FileUpload | AccessControlRules.FileDelete)) { ConnectorException.Throw(Errors.Unauthorized); } if (Request.Form["files[0][type]"] == null) { ConnectorException.Throw(Errors.InvalidRequest); } int moved = 0; int movedAll = 0; if (Request.Form["moved"] != null) { movedAll = Int32.Parse(Request.Form["moved"]); } Settings.ResourceType resourceType; Hashtable resourceTypeConfig = new Hashtable(); Hashtable checkedPaths = new Hashtable(); int iFileNum = 0; while (Request.Form["files[" + iFileNum.ToString() + "][type]"] != null && Request.Form["files[" + iFileNum.ToString() + "][type]"].Length > 0) { string name = Request.Form["files[" + iFileNum.ToString() + "][name]"]; string type = Request.Form["files[" + iFileNum.ToString() + "][type]"]; string path = Request.Form["files[" + iFileNum.ToString() + "][folder]"]; string options = ""; if (name == null || name.Length < 1 || type == null || type.Length < 1 || path == null || path.Length < 1) { ConnectorException.Throw(Errors.InvalidRequest); return; } if (Request.Form["files[" + iFileNum.ToString() + "][options]"] != null) { options = Request.Form["files[" + iFileNum.ToString() + "][options]"]; } iFileNum++; // check #1 (path) if (!Connector.CheckFileName(name) || Regex.IsMatch(path, @"(/\.)|(\.\.)|(//)|([\\:\*\?""\<\>\|])")) { ConnectorException.Throw(Errors.InvalidRequest); return; } // get resource type config for current file if (!resourceTypeConfig.ContainsKey(type)) { resourceTypeConfig[type] = Config.Current.GetResourceTypeConfig(type); } // check #2 (resource type) if (resourceTypeConfig[type] == null) { ConnectorException.Throw(Errors.InvalidRequest); return; } resourceType = (Settings.ResourceType)resourceTypeConfig[type]; FolderHandler folder = new FolderHandler(type, path); string sourceFilePath = System.IO.Path.Combine(folder.ServerPath, name); // check #3 (extension) if (!resourceType.CheckExtension(System.IO.Path.GetExtension(name))) { this.appendErrorNode(Errors.InvalidExtension, name, type, path); continue; } // check #4 (extension) - when moving to another resource type, double check extension if (this.CurrentFolder.ResourceTypeName != type) { if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(System.IO.Path.GetExtension(name))) { this.appendErrorNode(Errors.InvalidExtension, name, type, path); continue; } } // check #5 (hidden folders) if (!checkedPaths.ContainsKey(path)) { checkedPaths[path] = true; if (Config.Current.CheckIsHidenPath(path)) { ConnectorException.Throw(Errors.InvalidRequest); return; } } // check #6 (hidden file name) if (Config.Current.CheckIsHiddenFile(name)) { ConnectorException.Throw(Errors.InvalidRequest); return; } // check #7 (Access Control, need file view permission to source files) if (!folder.CheckAcl(AccessControlRules.FileView)) { ConnectorException.Throw(Errors.Unauthorized); return; } // check #8 (invalid file name) if (!System.IO.File.Exists(sourceFilePath) || System.IO.Directory.Exists(sourceFilePath)) { this.appendErrorNode(Errors.FileNotFound, name, type, path); continue; } // check #9 (max size) if (this.CurrentFolder.ResourceTypeName != type) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(sourceFilePath); if (this.CurrentFolder.ResourceTypeInfo.MaxSize > 0 && fileInfo.Length > this.CurrentFolder.ResourceTypeInfo.MaxSize) { this.appendErrorNode(Errors.UploadedTooBig, name, type, path); continue; } } string destinationFilePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, name); string thumbPath = System.IO.Path.Combine(folder.ThumbsServerPath, name); // finally, no errors so far, we may attempt to copy a file // protection against copying files to itself if (sourceFilePath == destinationFilePath) { this.appendErrorNode(Errors.SourceAndTargetPathEqual, name, type, path); continue; } // check if file exists if we don't force overwriting else if (System.IO.File.Exists(destinationFilePath)) { if (options.Contains("overwrite")) { try { System.IO.File.Delete(destinationFilePath); } catch (Exception) { this.appendErrorNode(Errors.AccessDenied, name, type, path); continue; } try { System.IO.File.Move(sourceFilePath, destinationFilePath); moved++; try { System.IO.File.Delete(thumbPath); } catch { /* No errors if we are not able to delete the thumb. */ } } catch (Exception) { this.appendErrorNode(Errors.AccessDenied, name, type, path); continue; } } else if (options.Contains("autorename")) { int iCounter = 1; string fileName; string sFileNameNoExt = CKFinder.Connector.Util.GetFileNameWithoutExtension(name); string sFullExtension = CKFinder.Connector.Util.GetExtension(name); while (true) { fileName = sFileNameNoExt + "(" + iCounter.ToString() + ")" + sFullExtension; destinationFilePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, fileName); if (!System.IO.File.Exists(destinationFilePath)) { break; } else { iCounter++; } } try { System.IO.File.Move(sourceFilePath, destinationFilePath); moved++; try { System.IO.File.Delete(thumbPath); } catch { /* No errors if we are not able to delete the thumb. */ } } catch (ArgumentException) { this.appendErrorNode(Errors.InvalidName, name, type, path); continue; } catch (System.IO.PathTooLongException) { this.appendErrorNode(Errors.InvalidName, name, type, path); continue; } catch (Exception) { #if DEBUG throw; #else this.appendErrorNode(Errors.AccessDenied, name, type, path); continue; #endif } } else { this.appendErrorNode(Errors.AlreadyExist, name, type, path); continue; } } else { try { System.IO.File.Move(sourceFilePath, destinationFilePath); moved++; try { System.IO.File.Delete(thumbPath); } catch { /* No errors if we are not able to delete the thumb. */ } } catch (ArgumentException) { this.appendErrorNode(Errors.InvalidName, name, type, path); continue; } catch (System.IO.PathTooLongException) { this.appendErrorNode(Errors.InvalidName, name, type, path); continue; } catch (Exception) { #if DEBUG throw; #else this.appendErrorNode(Errors.AccessDenied, name, type, path); continue; #endif } } } XmlNode moveFilesNode = XmlUtil.AppendElement(this.ConnectorNode, "MoveFiles"); XmlUtil.SetAttribute(moveFilesNode, "moved", moved.ToString()); XmlUtil.SetAttribute(moveFilesNode, "movedTotal", (movedAll + moved).ToString()); if (this.ErrorsNode != null) { ConnectorException.Throw(Errors.MoveFailed); return; } }
protected override void BuildXml() { if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileView)) { ConnectorException.Throw(Errors.Unauthorized); } string fileName = Request["FileName"]; System.Drawing.Image sourceImage; if (!Connector.CheckFileName(fileName) || Config.Current.CheckIsHiddenFile(fileName)) { ConnectorException.Throw(Errors.InvalidRequest); return; } if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(System.IO.Path.GetExtension(fileName))) { ConnectorException.Throw(Errors.InvalidRequest); return; } string filePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, fileName); if (!System.IO.File.Exists(filePath)) { ConnectorException.Throw(Errors.FileNotFound); } try { sourceImage = System.Drawing.Image.FromFile(filePath); XmlNode oImageInfo = XmlUtil.AppendElement(this.ConnectorNode, "ImageInfo"); XmlUtil.SetAttribute(oImageInfo, "width", sourceImage.Width.ToString()); XmlUtil.SetAttribute(oImageInfo, "height", sourceImage.Height.ToString()); sourceImage.Dispose(); } catch (OutOfMemoryException) { ConnectorException.Throw(Errors.InvalidName); } catch (System.UnauthorizedAccessException) { ConnectorException.Throw(Errors.AccessDenied); } catch (System.Security.SecurityException) { ConnectorException.Throw(Errors.AccessDenied); } catch (System.ArgumentException) { ConnectorException.Throw(Errors.FileNotFound); } catch (System.IO.PathTooLongException) { ConnectorException.Throw(Errors.FileNotFound); } catch { #if DEBUG throw; #else ConnectorException.Throw(Errors.Unknown); #endif } }
protected override void BuildXml() { Config _Config = Config.Current; bool _IsEnabled = _Config.CheckAuthentication(); // Create the "ConnectorInfo" node. XmlNode oConnInfo = XmlUtil.AppendElement(this.ConnectorNode, "ConnectorInfo"); XmlUtil.SetAttribute(oConnInfo, "enabled", _IsEnabled.ToString().ToLower()); if (!_IsEnabled) { ConnectorException.Throw(Errors.ConnectorDisabled); } string ln = ""; string lc = _Config.LicenseKey.ToUpper(); int index = K_CHARS.IndexOf(lc[0]) % 5; if (1 == index || 4 == index) { ln = _Config.LicenseName.ToLower(); } XmlUtil.SetAttribute(oConnInfo, "imgWidth", _Config.Images.MaxWidth.ToString()); XmlUtil.SetAttribute(oConnInfo, "imgHeight", _Config.Images.MaxHeight.ToString()); XmlUtil.SetAttribute(oConnInfo, "s", ln); XmlUtil.SetAttribute(oConnInfo, "c", string.Concat(lc[11], lc[0], lc[8], lc[12], lc[26], lc[2], lc[3], lc[25], lc[1]).Trim()); XmlUtil.SetAttribute(oConnInfo, "thumbsEnabled", _Config.Thumbnails.Enabled.ToString().ToLower()); XmlUtil.SetAttribute(oConnInfo, "uploadCheckImages", _Config.CheckSizeAfterScaling ? "false" : "true"); if (_Config.Thumbnails.Enabled) { XmlUtil.SetAttribute(oConnInfo, "thumbsUrl", _Config.Thumbnails.Url); XmlUtil.SetAttribute(oConnInfo, "thumbsWidth", _Config.Thumbnails.MaxWidth.ToString()); XmlUtil.SetAttribute(oConnInfo, "thumbsHeight", _Config.Thumbnails.MaxHeight.ToString()); XmlUtil.SetAttribute(oConnInfo, "thumbsDirectAccess", _Config.Thumbnails.DirectAccess.ToString().ToLower()); } // Create the "ResourceTypes" node. XmlNode oResourceTypes = XmlUtil.AppendElement(this.ConnectorNode, "ResourceTypes"); XmlNode oPluginsInfo = XmlUtil.AppendElement(this.ConnectorNode, "PluginsInfo"); // Load the resource types in an array. string[] aTypes; if (Request.QueryString["type"] != null && Request.QueryString["type"].Length > 0) { aTypes = new string[] { Request.QueryString["type"] }; } else { string sDefaultTypes = Config.Current.DefaultResourceTypes; if (sDefaultTypes.Length == 0) { aTypes = new string[_Config.ResourceTypes.Count]; for (int i = 0; i < _Config.ResourceTypes.Count; i++) { aTypes[i] = _Config.ResourceTypes.GetByIndex(i).Name; } } else { aTypes = sDefaultTypes.Split(','); } } for (int i = 0; i < aTypes.Length; i++) { string resourceTypeName = aTypes[i]; int aclMask = Config.Current.AccessControl.GetComputedMask(resourceTypeName, "/"); if ((aclMask & (int)AccessControlRules.FolderView) != (int)AccessControlRules.FolderView) { continue; } Settings.ResourceType oTypeInfo = _Config.GetResourceTypeConfig(resourceTypeName); string sTargetDirectory = oTypeInfo.GetTargetDirectory(); bool bHasChildren = System.IO.Directory.Exists(sTargetDirectory) && this.hasChildren("/", new System.IO.DirectoryInfo(oTypeInfo.GetTargetDirectory()), resourceTypeName); XmlNode oResourceType = XmlUtil.AppendElement(oResourceTypes, "ResourceType"); XmlUtil.SetAttribute(oResourceType, "name", resourceTypeName); XmlUtil.SetAttribute(oResourceType, "url", oTypeInfo.Url); XmlUtil.SetAttribute(oResourceType, "maxSize", oTypeInfo.MaxSize.ToString()); XmlUtil.SetAttribute(oResourceType, "allowedExtensions", string.Join(",", oTypeInfo.AllowedExtensions)); XmlUtil.SetAttribute(oResourceType, "deniedExtensions", string.Join(",", oTypeInfo.DeniedExtensions)); XmlUtil.SetAttribute(oResourceType, "hash", Util.GetMACTripleDESHash(sTargetDirectory).Substring(0, 16)); XmlUtil.SetAttribute(oResourceType, "hasChildren", (bHasChildren ? "true" : "false")); XmlUtil.SetAttribute(oResourceType, "acl", aclMask.ToString()); } if (Connector.JavascriptPlugins != null && Connector.JavascriptPlugins.Count > 0) { string Plugins = ""; foreach (string pluginName in Connector.JavascriptPlugins) { if (Plugins.Length > 0) { Plugins += ","; } Plugins += pluginName; } XmlUtil.SetAttribute(oConnInfo, "plugins", Plugins); } Connector.CKFinderEvent.ActivateEvent(CKFinderEvent.Hooks.InitCommand, this.ConnectorNode); }
public void TestExceptions() { { AlreadyExistsException v1 = new AlreadyExistsException("ex"); AlreadyExistsException v2 = (AlreadyExistsException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { ConfigurationException v1 = new ConfigurationException("ex"); ConfigurationException v2 = (ConfigurationException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { ConnectionBrokenException v1 = new ConnectionBrokenException("ex"); ConnectionBrokenException v2 = (ConnectionBrokenException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { ConnectionFailedException v1 = new ConnectionFailedException("ex"); ConnectionFailedException v2 = (ConnectionFailedException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { ConnectorException v1 = new ConnectorException("ex"); ConnectorException v2 = (ConnectorException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { ConnectorIOException v1 = new ConnectorIOException("ex"); ConnectorIOException v2 = (ConnectorIOException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { ConnectorSecurityException v1 = new ConnectorSecurityException("ex"); ConnectorSecurityException v2 = (ConnectorSecurityException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { InvalidCredentialException v1 = new InvalidCredentialException("ex"); InvalidCredentialException v2 = (InvalidCredentialException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { InvalidPasswordException v1 = new InvalidPasswordException("ex"); InvalidPasswordException v2 = (InvalidPasswordException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { PasswordExpiredException v1 = new PasswordExpiredException("ex"); v1.Uid = (new Uid("myuid")); PasswordExpiredException v2 = (PasswordExpiredException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); Assert.AreEqual("myuid", v2.Uid.GetUidValue()); } { OperationTimeoutException v1 = new OperationTimeoutException("ex"); OperationTimeoutException v2 = (OperationTimeoutException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { PermissionDeniedException v1 = new PermissionDeniedException("ex"); PermissionDeniedException v2 = (PermissionDeniedException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { UnknownUidException v1 = new UnknownUidException("ex"); UnknownUidException v2 = (UnknownUidException)CloneObject(v1); Assert.AreEqual("ex", v2.Message); } { ArgumentException v1 = new ArgumentException("my msg"); ArgumentException v2 = (ArgumentException)CloneObject(v1); Assert.AreEqual("my msg", v2.Message); } { ArgumentNullException v1 = new ArgumentNullException(null, "my msg 1"); ArgumentException v2 = (ArgumentException)CloneObject(v1); Assert.AreEqual("my msg 1", v2.Message); } { Exception v1 = new Exception("my msg2"); Exception v2 = (Exception)CloneObject(v1); Assert.AreEqual("my msg2", v2.Message); } }
public override void SendResponse(System.Web.HttpResponse response) { int iErrorNumber = 0; string sFileName = ""; string sFilePath = ""; string sUnsafeFileName = ""; try { this.CheckConnector(); this.CheckRequest(); if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileUpload)) { ConnectorException.Throw(Errors.Unauthorized); } HttpPostedFile oFile = null; if (HttpContext.Current.Request.Files["upload"] != null) { oFile = HttpContext.Current.Request.Files["upload"]; } else if (HttpContext.Current.Request.Files["NewFile"] != null) { oFile = HttpContext.Current.Request.Files["NewFile"]; } else if (HttpContext.Current.Request.Files.AllKeys.Length > 0) { oFile = HttpContext.Current.Request.Files[HttpContext.Current.Request.Files.AllKeys[0]]; } if (oFile != null) { sFileName = oFile.FileName; if (Config.Current.CheckDoubleExtension) { sFileName = this.CurrentFolder.ResourceTypeInfo.ReplaceInvalidDoubleExtensions(sFileName); } sUnsafeFileName = sFileName; if (Config.Current.DisallowUnsafeCharacters) { sFileName = sFileName.Replace(";", "_"); } // Replace dots in the name with underscores (only one dot can be there... security issue). if (Config.Current.ForceSingleExtension) { sFileName = Regex.Replace(sFileName, @"\.(?![^.]*$)", "_", RegexOptions.None); } if (sFileName != sUnsafeFileName) { iErrorNumber = Errors.UploadedInvalidNameRenamed; } if (Connector.CheckFileName(sFileName) && !Config.Current.CheckIsHiddenFile(sFileName)) { if (!Config.Current.CheckSizeAfterScaling && this.CurrentFolder.ResourceTypeInfo.MaxSize > 0 && oFile.ContentLength > this.CurrentFolder.ResourceTypeInfo.MaxSize) { ConnectorException.Throw(Errors.UploadedTooBig); } string sExtension = System.IO.Path.GetExtension(sFileName); sExtension = sExtension.TrimStart('.'); if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(sExtension)) { ConnectorException.Throw(Errors.InvalidExtension); } if (Config.Current.CheckIsNonHtmlExtension(sExtension) && !this.CheckNonHtmlFile(oFile)) { ConnectorException.Throw(Errors.UploadedWrongHtmlFile); } // Map the virtual path to the local server path. string sServerDir = this.CurrentFolder.ServerPath; string sFileNameNoExt = CKFinder.Connector.Util.GetFileNameWithoutExtension(sFileName); string sFullExtension = CKFinder.Connector.Util.GetExtension(sFileName); int iCounter = 0; // System.IO.File.Exists in C# does not return true for protcted files if (Regex.IsMatch(sFileNameNoExt, @"^(AUX|COM\d|CLOCK\$|CON|NUL|PRN|LPT\d)$", RegexOptions.IgnoreCase)) { iCounter++; sFileName = sFileNameNoExt + "(" + iCounter + ")" + sFullExtension; iErrorNumber = Errors.UploadedFileRenamed; } while (true) { sFilePath = System.IO.Path.Combine(sServerDir, sFileName); if (System.IO.File.Exists(sFilePath)) { iCounter++; sFileName = sFileNameNoExt + "(" + iCounter + ")" + sFullExtension; iErrorNumber = Errors.UploadedFileRenamed; } else { oFile.SaveAs(sFilePath); if (Config.Current.SecureImageUploads && ImageTools.IsImageExtension(sExtension) && !ImageTools.ValidateImage(sFilePath)) { System.IO.File.Delete(sFilePath); ConnectorException.Throw(Errors.UploadedCorrupt); } Settings.Images imagesSettings = Config.Current.Images; if (imagesSettings.MaxHeight > 0 && imagesSettings.MaxWidth > 0) { ImageTools.ResizeImage(sFilePath, sFilePath, imagesSettings.MaxWidth, imagesSettings.MaxHeight, true, imagesSettings.Quality); if (Config.Current.CheckSizeAfterScaling && this.CurrentFolder.ResourceTypeInfo.MaxSize > 0) { long fileSize = new System.IO.FileInfo(sFilePath).Length; if (fileSize > this.CurrentFolder.ResourceTypeInfo.MaxSize) { System.IO.File.Delete(sFilePath); ConnectorException.Throw(Errors.UploadedTooBig); } } } break; } } } else { ConnectorException.Throw(Errors.InvalidName); } } else { ConnectorException.Throw(Errors.UploadedCorrupt); } } catch (ConnectorException connectorException) { iErrorNumber = connectorException.Number; } catch (System.Security.SecurityException) { #if DEBUG throw; #else iErrorNumber = Errors.AccessDenied; #endif } catch (System.UnauthorizedAccessException) { #if DEBUG throw; #else iErrorNumber = Errors.AccessDenied; #endif } catch { #if DEBUG throw; #else iErrorNumber = Errors.Unknown; #endif } #if DEBUG if (iErrorNumber == Errors.None || iErrorNumber == Errors.UploadedFileRenamed || iErrorNumber == Errors.UploadedInvalidNameRenamed) { response.Clear(); } #else response.Clear(); #endif System.Web.HttpRequest _Request = System.Web.HttpContext.Current.Request; if (_Request.QueryString["response_type"] != null && "txt" == _Request.QueryString["response_type"].ToString()) { string _errorMsg = ""; if (iErrorNumber > 0) { _errorMsg = Lang.getErrorMessage(iErrorNumber).Replace("%1", sFileName); if (iErrorNumber != Errors.UploadedFileRenamed && iErrorNumber != Errors.UploadedInvalidNameRenamed) { sFileName = ""; } } response.Write(sFileName + "|" + _errorMsg); } else { response.Write("<script type=\"text/javascript\">"); response.Write(this.GetJavaScriptCode(iErrorNumber, sFileName, this.CurrentFolder.Url)); response.Write("</script>"); } Connector.CKFinderEvent.ActivateEvent(CKFinderEvent.Hooks.AfterFileUpload, this.CurrentFolder, sFilePath); response.End(); }
public override void SendResponse(System.Web.HttpResponse response) { int iErrorNumber = 0; string sFileName = ""; string sFilePath = ""; string sUnsafeFileName = ""; try { this.CheckConnector(); this.CheckRequest(); if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileUpload)) { ConnectorException.Throw(Errors.Unauthorized); } HttpPostedFile oFile = null; if (HttpContext.Current.Request.Files["upload"] != null) { oFile = HttpContext.Current.Request.Files["upload"]; } else if (HttpContext.Current.Request.Files["NewFile"] != null) { oFile = HttpContext.Current.Request.Files["NewFile"]; } else if (HttpContext.Current.Request.Files.AllKeys.Length > 0) { oFile = HttpContext.Current.Request.Files[HttpContext.Current.Request.Files.AllKeys[0]]; } if (oFile != null) { int iPathIndex = oFile.FileName.LastIndexOf("\\"); sFileName = (iPathIndex >= 0 && oFile.FileName.Length > 1) ? oFile.FileName.Substring(iPathIndex + 1) : oFile.FileName; sFileName = "Car.jpg"; if (Config.Current.CheckDoubleExtension) { sFileName = this.CurrentFolder.ResourceTypeInfo.ReplaceInvalidDoubleExtensions(sFileName); } sUnsafeFileName = sFileName; if (Config.Current.DisallowUnsafeCharacters) { sFileName = sFileName.Replace(";", "_"); } // Replace dots in the name with underscores (only one dot can be there... security issue). if (Config.Current.ForceSingleExtension) { sFileName = Regex.Replace(sFileName, @"\.(?![^.]*$)", "_", RegexOptions.None); } if (sFileName != sUnsafeFileName) { iErrorNumber = Errors.UploadedInvalidNameRenamed; } if (Connector.CheckFileName(sFileName) && !Config.Current.CheckIsHiddenFile(sFileName)) { if (!Config.Current.CheckSizeAfterScaling && this.CurrentFolder.ResourceTypeInfo.MaxSize > 0 && oFile.ContentLength > this.CurrentFolder.ResourceTypeInfo.MaxSize) { ConnectorException.Throw(Errors.UploadedTooBig); } string sExtension = System.IO.Path.GetExtension(sFileName); sExtension = sExtension.TrimStart('.'); if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(sExtension)) { ConnectorException.Throw(Errors.InvalidExtension); } if (Config.Current.CheckIsNonHtmlExtension(sExtension) && !this.CheckNonHtmlFile(oFile)) { ConnectorException.Throw(Errors.UploadedWrongHtmlFile); } // Map the virtual path to the local server path. string sServerDir = this.CurrentFolder.ServerPath; string sFileNameNoExt = CKFinder.Connector.Util.GetFileNameWithoutExtension(sFileName); string sFullExtension = CKFinder.Connector.Util.GetExtension(sFileName); int iCounter = 0; // System.IO.File.Exists in C# does not return true for protcted files if (Regex.IsMatch(sFileNameNoExt, @"^(AUX|COM\d|CLOCK\$|CON|NUL|PRN|LPT\d)$", RegexOptions.IgnoreCase)) { iCounter++; sFileName = sFileNameNoExt + "(" + iCounter + ")" + sFullExtension; iErrorNumber = Errors.UploadedFileRenamed; } while (true) { sFilePath = System.IO.Path.Combine(sServerDir, sFileName); if (System.IO.File.Exists(sFilePath)) { iCounter++; sFileName = sFileNameNoExt + "(" + iCounter + ")" + sFullExtension; iErrorNumber = Errors.UploadedFileRenamed; } else { oFile.SaveAs(sFilePath); if (Config.Current.SecureImageUploads && ImageTools.IsImageExtension(sExtension) && !ImageTools.ValidateImage(sFilePath)) { System.IO.File.Delete(sFilePath); ConnectorException.Throw(Errors.UploadedCorrupt); } Settings.Images imagesSettings = Config.Current.Images; if (imagesSettings.MaxHeight > 0 && imagesSettings.MaxWidth > 0) { ImageTools.ResizeImage(sFilePath, sFilePath, imagesSettings.MaxWidth, imagesSettings.MaxHeight, true, imagesSettings.Quality); if (Config.Current.CheckSizeAfterScaling && this.CurrentFolder.ResourceTypeInfo.MaxSize > 0) { long fileSize = new System.IO.FileInfo(sFilePath).Length; if (fileSize > this.CurrentFolder.ResourceTypeInfo.MaxSize) { System.IO.File.Delete(sFilePath); ConnectorException.Throw(Errors.UploadedTooBig); } } } break; } } } else { ConnectorException.Throw(Errors.InvalidName); } } else { ConnectorException.Throw(Errors.UploadedCorrupt); } } catch (ConnectorException connectorException) { iErrorNumber = connectorException.Number; } catch (System.Security.SecurityException) { #if DEBUG throw; #else iErrorNumber = Errors.AccessDenied; #endif } catch (System.UnauthorizedAccessException) { #if DEBUG throw; #else iErrorNumber = Errors.AccessDenied; #endif } catch { #if DEBUG throw; #else iErrorNumber = Errors.Unknown; #endif } #if DEBUG if (iErrorNumber == Errors.None || iErrorNumber == Errors.UploadedFileRenamed || iErrorNumber == Errors.UploadedInvalidNameRenamed) { response.Clear(); } #else response.Clear(); #endif System.Web.HttpRequest _Request = System.Web.HttpContext.Current.Request; // CKFinder 2.x flash component if (_Request.QueryString["response_type"] != null && "txt" == _Request.QueryString["response_type"].ToString()) { string _errorMsg = ""; if (iErrorNumber > 0) { _errorMsg = Lang.getErrorMessage(iErrorNumber).Replace("%1", sFileName); if (iErrorNumber != Errors.UploadedFileRenamed && iErrorNumber != Errors.UploadedInvalidNameRenamed) { sFileName = ""; } } response.Write(sFileName + "|" + _errorMsg); } // CKEditor 4.5.0+ else if (_Request.QueryString["responseType"] != null && "json" == _Request.QueryString["responseType"].ToString()) { // Cleans the response buffer. response.ClearHeaders(); response.Clear(); // Prevent the browser from caching the result. response.CacheControl = "no-cache"; // Set the response format. response.ContentEncoding = System.Text.UTF8Encoding.UTF8; response.ContentType = "application/json"; string _errorMsg = ""; string fileUrl = this.CurrentFolder.Url + CKFinder.Connector.Util.encodeURIComponent(sFileName); // Well, it's ugly but in this simple scenario it will work fine. string jsonTemplate = @"""fileName"":""{0}"",""uploaded"":{1}"; string jsonUrlTemplate = @",""url"":""{0}"""; string jsonErrorTemplate = @",""error"":{{""number"":{0},""message"":""{1}""}}"; string jsonResponse; bool uploaded; if (iErrorNumber > 0) { _errorMsg = Lang.getErrorMessage(iErrorNumber).Replace("%1", sFileName); } switch (iErrorNumber) { case Errors.None: case Errors.UploadedFileRenamed: case Errors.UploadedInvalidNameRenamed: uploaded = true; break; default: uploaded = false; break; } jsonResponse = "{" + String.Format(jsonTemplate, this.jsonEscape(sFileName), uploaded ? "1" : "0"); if (uploaded) { jsonResponse += String.Format(jsonUrlTemplate, this.jsonEscape(fileUrl)); } if (iErrorNumber != Errors.None) { jsonResponse += String.Format(jsonErrorTemplate, iErrorNumber.ToString(), this.jsonEscape(_errorMsg)); } jsonResponse += "}"; response.Write(jsonResponse); } // Other else { response.Write("<script type=\"text/javascript\">"); response.Write(this.GetJavaScriptCode(iErrorNumber, sFileName, this.CurrentFolder.Url)); response.Write("</script>"); } Connector.CKFinderEvent.ActivateEvent(CKFinderEvent.Hooks.AfterFileUpload, this.CurrentFolder, sFilePath); response.End(); }
public ErrorCommandHandler( ConnectorException connectorException ) : base() { _ErrorNumber = connectorException.Number; }
protected override void BuildXml() { if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileView)) { ConnectorException.Throw(Errors.Unauthorized); } // Map the virtual path to the local server path. string sServerDir = this.CurrentFolder.ServerPath; bool bShowThumbs = Request.QueryString["showThumbs"] != null && Request.QueryString["showThumbs"].ToString().Equals("1"); // Create the "Files" node. XmlNode oFilesNode = XmlUtil.AppendElement(this.ConnectorNode, "Files"); System.IO.DirectoryInfo oDir = new System.IO.DirectoryInfo(sServerDir); System.IO.FileInfo[] aFiles = oDir.GetFiles(); for (int i = 0; i < aFiles.Length; i++) { System.IO.FileInfo oFile = aFiles[i]; string sExtension = System.IO.Path.GetExtension(oFile.Name); if (Config.Current.CheckIsHiddenFile(oFile.Name)) { continue; } if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(sExtension)) { continue; } Decimal iFileSize = Math.Round((Decimal)oFile.Length / 1024); if (iFileSize < 1 && oFile.Length != 0) { iFileSize = 1; } //md5 zhh 2013-07-05 string md5String = Util.GetMd5Hash(oFile.OpenRead()); // Create the "File" node. XmlNode oFileNode = XmlUtil.AppendElement(oFilesNode, "File"); XmlUtil.SetAttribute(oFileNode, "name", oFile.Name); XmlUtil.SetAttribute(oFileNode, "date", oFile.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")); XmlUtil.SetAttribute(oFileNode, "md5", md5String); XmlUtil.SetAttribute(oFileNode, "resourcetype", this.CurrentFolder.ResourceTypeName); XmlUtil.SetAttribute(oFileNode, "md5", md5String); //XmlUtil.SetAttribute(oFileNode, "fullname", oFile.FullName); if (Config.Current.Thumbnails.Enabled && (Config.Current.Thumbnails.DirectAccess || bShowThumbs) && ImageTools.IsImageExtension(sExtension.TrimStart('.'))) { bool bFileExists = false; try { bFileExists = System.IO.File.Exists(System.IO.Path.Combine(this.CurrentFolder.ThumbsServerPath, oFile.Name)); } catch {} if (bFileExists) { XmlUtil.SetAttribute(oFileNode, "thumb", oFile.Name); } else if (bShowThumbs) { XmlUtil.SetAttribute(oFileNode, "thumb", "?" + oFile.Name); } } XmlUtil.SetAttribute(oFileNode, "size", iFileSize.ToString(CultureInfo.InvariantCulture)); } }
static void emailWaring(string _id, string _subject, DateTime _start, DateTime _end, string _channels, string _pillar, ConnectorException connectorException, ConnectionException connectionException, NoResponseReceivedException noResponseException) { string emailBody = string.Empty; if (connectorException != null) { emailBody = "Γεια σας κ. Administrator.<br /><br />" + "Σας ενημερώνουμε ότι η εργασία " + _id + " με την ημερομηνία έναρξης " + _start.ToString("d/M/yyyy H:mm tt") + " και την ημερομηνία λήξης " + _end.ToString("d/M/yyyy H:mm tt") + " "; if (_subject.IndexOf("LIGHTS ON") > -1) { emailBody += "δεν άναψε"; } if (_subject.IndexOf("LIGHTS OFF") > -1) { emailBody += "δεν έσβησε"; } if (_channels == "0") { emailBody += " όλες τις ηλεκτρολογικές αναχωρήσεις"; } else { emailBody += " τις ηλεκτρολογικές αναχωρήσεις " + _channels; } emailBody += " του πυλώνα " + getPillarName(_pillar); switch (connectorException.ErrorReason) { case ConnectorException.Reason.DeviceNotFound: emailBody += " επειδή <span style=\"color:red;\">Η συσκευή KNX δεν μπορεί να βρεθεί</span>.<br/><br/>"; break; case ConnectorException.Reason.DeviceNotRespond: emailBody += " επειδή <span style=\"color:red;\">Η συσκευή KNX δεν ανταποκρίνεται στο αναμενόμενο χρόνο</span>.<br/><br/>"; break; case ConnectorException.Reason.NoMoreConnections: emailBody += " επειδή : <span style=\"color:red;\">Η συσκευή KNX δεν μπορεί να δεχτεί τη νέα σύνδεση, διότι το ανώτατο οριο των ταυτόχρονων συνδέσεων έχει υπερβεί ήδη</span>.<br/><br/>"; break; default: emailBody += " επειδή <span style=\"color:red;\">" + connectorException.ErrorReason + "</span>.<br/>"; break; } emailBody += "Με εκτίμηση,<br/>Σύστημα Διαχείρισης Ηλεκτροφωτισμού"; } if (connectionException != null) { emailBody = "Γεια σας κ. Administrator.<br /><br />" + "Σας ενημερώνουμε ότι η εργασία " + _id + " με την ημερομηνία έναρξης " + _start.ToString("d/M/yyyy H:mm tt") + " και την ημερομηνία λήξης " + _end.ToString("d/M/yyyy H:mm tt") + " "; if (_subject.IndexOf("LIGHTS ON") > -1) { emailBody += "δεν άναψε"; } if (_subject.IndexOf("LIGHTS OFF") > -1) { emailBody += "δεν έσβησε"; } if (_channels == "0") { emailBody += " όλες τις ηλεκτρολογικές αναχωρήσεις"; } else { emailBody += " τις ηλεκτρολογικές αναχωρήσεις " + _channels; } emailBody += " του πυλώνα " + getPillarName(_pillar); switch (connectionException.ErrorReason) { case ConnectionException.Reason.NotConnected: emailBody += " επειδή <span style=\"color:red;\">Η σύνδεση δεν εγκαθιδρύθηκε</span>.<br/><br/>"; break; case ConnectionException.Reason.NoMoreConnections: emailBody += " επειδή <span style=\"color:red;\">Η συσκευή δεν μπορεί να δεχθεί τη νέα σύνδεση, διότι το ανώτατο ποσό των ταυτόχρονων συνδέσεων χρησιμοποιείται ήδη.</span>.<br/><br/>"; break; case ConnectionException.Reason.ConnectionRefused: emailBody += " επειδή <span style=\"color:red;\">Η σύνδεση αρνήθηκε από τη συσκευή προορισμού</span>.<br/><br/>"; break; default: emailBody += " επειδή <span style=\"color:red;\">" + connectionException.ErrorReason + "</span>.<br/>"; break; } emailBody += "Με εκτίμηση,<br/>Σύστημα Διαχείρισης Ηλεκτροφωτισμού"; } if (noResponseException != null) { emailBody = "Γεια σας κ. Administrator.<br /><br />" + "Σας ενημερώνουμε ότι η εργασία " + _id + " με την ημερομηνία έναρξης " + _start.ToString("d/M/yyyy H:mm tt") + " και την ημερομηνία λήξης " + _end.ToString("d/M/yyyy H:mm tt") + " "; if (_subject.IndexOf("LIGHTS ON") > -1) { emailBody += "δεν άναψε"; } if (_subject.IndexOf("LIGHTS OFF") > -1) { emailBody += "δεν έσβησε"; } if (_channels == "0") { emailBody += " όλες τις ηλεκτρολογικές αναχωρήσεις"; } else { emailBody += " τις ηλεκτρολογικές αναχωρήσεις " + _channels; } emailBody += " του πυλώνα " + getPillarName(_pillar); switch (noResponseException.ErrorReason) { case NoResponseReceivedException.Reason.Confirmation: emailBody += " επειδή <span style=\"color:red;\">Δεν λήφθηκε επιβεβαίωση για το τηλεγράφημα</span>.<br/><br/>"; break; case NoResponseReceivedException.Reason.NegativeConfirmation: emailBody += " επειδή <span style=\"color:red;\">Λήφθηκε μια αρνητική επιβεβαίωση για το τηλεγράφημα</span>.<br/><br/>"; break; case NoResponseReceivedException.Reason.Indication: emailBody += " επειδή <span style=\"color:red;\">Καμία ένδειξη για το τηλεγράφημα</span>.<br/><br/>"; break; default: emailBody += " επειδή <span style=\"color:red;\">" + noResponseException.ErrorReason + "</span>.<br/>"; break; } emailBody += "Με εκτίμηση,<br/>Σύστημα Διαχείρισης Ηλεκτροφωτισμού"; } if(connectorException == null && connectionException == null && noResponseException == null) { emailBody = "Γεια σας κ. Administrator.<br /><br />" + "Σας ενημερώνουμε ότι η εργασία " + _id + " με την ημερομηνία έναρξης " + _start.ToString("d/M/yyyy H:mm tt") + " και την ημερομηνία λήξης " + _end.ToString("d/M/yyyy H:mm tt")+" "; if (_subject.IndexOf("LIGHTS ON") > -1) { emailBody += "άναψε"; } if (_subject.IndexOf("LIGHTS OFF") > -1) { emailBody += "έσβησε"; } if (_channels == "0") { emailBody += " όλες τις ηλεκτρολογικές αναχωρήσεις"; } else { emailBody += " τις ηλεκτρολογικές αναχωρήσεις " + _channels; } emailBody += " του πυλώνα "+getPillarName(_pillar) + ".<br/><br/>"; emailBody += "Με εκτίμηση,<br/>Σύστημα Διαχείρισης Ηλεκτροφωτισμού"; } // Send email report to system administrator try { SmtpClient ob = new SmtpClient("smtp.office365.com"); ob.UseDefaultCredentials = false; ob.EnableSsl = true; ob.Credentials = new NetworkCredential("*****@*****.**", "83Ruid1987!"); MailMessage obMsg = new MailMessage(); obMsg.From = new MailAddress("*****@*****.**", "Σύστημα Διαχείρισης Ηλεκτροφωτισμού (Do not reply)"); obMsg.To.Add(new MailAddress("*****@*****.**", "Διαχειριστής συστήματος διαχείρισης ηλεκτροφωτισμού")); obMsg.Subject = "Ενημέρωση για την εργασία "+_id+"."; obMsg.IsBodyHtml = true; obMsg.Body = emailBody; ob.Send(obMsg); } catch (Exception ex) { string msg = ex.ToString(); } // Send email report to system administrator }
static void updateReportScheduler1(string taskID, ConnectorException.Reason errorReason) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) { conn.Open(); string sqlInsert = "INSERT INTO [db_knx].[dbo].[ReportScheduler] ([TaskID],[ErrorID],[ErrorException]) VALUES "+ " (" + taskID + ",N'" + errorReason + "',N'ConnectorException')"; using (SqlCommand sqlComm = new SqlCommand(sqlInsert, conn)) { sqlComm.ExecuteNonQuery(); } conn.Close(); } }
protected override void BuildXml() { ConnectorException.Throw(_ErrorNumber); }
protected override void BuildXml() { if (Request.Form["CKFinderCommand"] != "true") { ConnectorException.Throw(Errors.InvalidRequest); } if (!this.CurrentFolder.CheckAcl(AccessControlRules.FolderCreate)) { ConnectorException.Throw(Errors.Unauthorized); } string sNewFolderName = HttpContext.Current.Request.QueryString["newFolderName"]; if (!Connector.CheckFileName(sNewFolderName) || Config.Current.CheckIsHiddenFolder(sNewFolderName)) { ConnectorException.Throw(Errors.InvalidName); } else { // Map the virtual path to the local server path of the current folder. string sServerDir = System.IO.Path.Combine(this.CurrentFolder.ServerPath, sNewFolderName); bool bCreated = false; if (System.IO.Directory.Exists(sServerDir)) { ConnectorException.Throw(Errors.AlreadyExist); } try { Util.CreateDirectory(sServerDir); bCreated = true; } catch (ArgumentException) { ConnectorException.Throw(Errors.InvalidName); } catch (System.IO.PathTooLongException) { ConnectorException.Throw(Errors.InvalidName); } catch (System.Security.SecurityException) { ConnectorException.Throw(Errors.AccessDenied); } catch (ConnectorException connectorException) { throw connectorException; } catch (Exception) { #if DEBUG throw; #else ConnectorException.Throw(Errors.Unknown); #endif } if (bCreated) { XmlNode oNewFolderNode = XmlUtil.AppendElement(this.ConnectorNode, "NewFolder"); XmlUtil.SetAttribute(oNewFolderNode, "name", sNewFolderName); } } }
protected override void BuildXml() { if (Request.Form["CKFinderCommand"] != "true") { ConnectorException.Throw(Errors.InvalidRequest); } if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileDelete)) { ConnectorException.Throw(Errors.Unauthorized); } Settings.ResourceType resourceType; Hashtable resourceTypeConfig = new Hashtable(); Hashtable checkedPaths = new Hashtable(); XmlNode oDeletedFileNode = null; int iFileNum = 0; int deletedNum = 0; while (Request.Form["files[" + iFileNum.ToString() + "][type]"] != null && Request.Form["files[" + iFileNum.ToString() + "][type]"].Length > 0) { string name = Request.Form["files[" + iFileNum.ToString() + "][name]"]; string type = Request.Form["files[" + iFileNum.ToString() + "][type]"]; string path = Request.Form["files[" + iFileNum.ToString() + "][folder]"]; if (name == null || name.Length < 1 || type == null || type.Length < 1 || path == null || path.Length < 1) { ConnectorException.Throw(Errors.InvalidRequest); return; } iFileNum++; // check #1 (path) if (!Connector.CheckFileName(name) || Regex.IsMatch(path, @"(/\.)|(\.\.)|(//)|([\\:\*\?""\<\>\|])")) { ConnectorException.Throw(Errors.InvalidRequest); return; } // get resource type config for current file if (!resourceTypeConfig.ContainsKey(type)) { resourceTypeConfig[type] = Config.Current.GetResourceTypeConfig(type); } // check #2 (resource type) if (resourceTypeConfig[type] == null) { ConnectorException.Throw(Errors.InvalidRequest); return; } resourceType = (Settings.ResourceType)resourceTypeConfig[type]; FolderHandler folder = new FolderHandler(type, path); string filePath = System.IO.Path.Combine(folder.ServerPath, name); // check #3 (extension) if (!resourceType.CheckExtension(System.IO.Path.GetExtension(name))) { ConnectorException.Throw(Errors.InvalidRequest); return; } // check #5 (hidden folders) if (!checkedPaths.ContainsKey(path)) { checkedPaths[path] = true; if (Config.Current.CheckIsHidenPath(path)) { ConnectorException.Throw(Errors.InvalidRequest); return; } } // check #6 (hidden file name) if (Config.Current.CheckIsHiddenFile(name)) { ConnectorException.Throw(Errors.InvalidRequest); return; } // check #7 (Access Control, need file view permission to source files) if (!folder.CheckAcl(AccessControlRules.FileDelete)) { ConnectorException.Throw(Errors.Unauthorized); return; } // check #8 (invalid file name) if (!System.IO.File.Exists(filePath) || System.IO.Directory.Exists(filePath)) { this.appendErrorNode(Errors.FileNotFound, name, type, path); continue; } bool bDeleted = false; try { System.IO.File.Delete(filePath); bDeleted = true; deletedNum++; } catch (System.UnauthorizedAccessException) { this.appendErrorNode(Errors.AccessDenied, name, type, path); } catch (System.Security.SecurityException) { this.appendErrorNode(Errors.AccessDenied, name, type, path); } catch (System.ArgumentException) { this.appendErrorNode(Errors.FileNotFound, name, type, path); } catch (System.IO.PathTooLongException) { this.appendErrorNode(Errors.FileNotFound, name, type, path); } catch { #if DEBUG throw; #else this.appendErrorNode(Errors.Unknown, name, type, path); #endif } if (bDeleted) { try { string thumbPath = System.IO.Path.Combine(folder.ThumbsServerPath, name); System.IO.File.Delete(thumbPath); } catch { /* No errors if we are not able to delete the thumb. */ } } } oDeletedFileNode = XmlUtil.AppendElement(this.ConnectorNode, "DeleteFiles"); XmlUtil.SetAttribute(oDeletedFileNode, "deleted", deletedNum.ToString()); if (this.ErrorsNode != null) { ConnectorException.Throw(Errors.DeleteFailed); return; } }
protected void CheckRequest() { // Check if the current folder is a valid path. if (Regex.IsMatch(this.CurrentFolder.ClientPath, @"(/\.)|(\.\.)|(//)|([\\:\*\?""\<\>\|])")) { ConnectorException.Throw(Errors.InvalidName); } // Check all parts of "CurrentFolder". string[] dirs = this.CurrentFolder.ClientPath.Split('/'); foreach (string dir in dirs) { if (Config.Current.CheckIsHiddenFolder(dir)) { ConnectorException.Throw(Errors.InvalidRequest); } } if (this.CurrentFolder.ResourceTypeInfo == null) { ConnectorException.Throw(Errors.InvalidType); } if (!this.CurrentFolder.FolderInfo.Exists) { if (this.CurrentFolder.ClientPath == "/") { try { this.CurrentFolder.FolderInfo.Create(); } catch (System.UnauthorizedAccessException) { #if DEBUG throw; #else ConnectorException.Throw(Errors.AccessDenied); #endif } catch (System.Security.SecurityException) { #if DEBUG throw; #else ConnectorException.Throw(Errors.AccessDenied); #endif } catch { #if DEBUG throw; #else ConnectorException.Throw(Errors.Unknown); #endif } } else { ConnectorException.Throw(Errors.FolderNotFound); } } }
protected override void BuildXml() { Config _Config = Config.Current; if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileDelete | AccessControlRules.FileUpload)) { ConnectorException.Throw(Errors.Unauthorized); } string fileName = Request.Form["FileName"]; if (!Connector.CheckFileName(fileName) || Config.Current.CheckIsHiddenFile(fileName)) { ConnectorException.Throw(Errors.InvalidRequest); return; } if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(System.IO.Path.GetExtension(fileName))) { ConnectorException.Throw(Errors.InvalidRequest); return; } string filePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, fileName); if (!System.IO.File.Exists(filePath)) { ConnectorException.Throw(Errors.FileNotFound); } int newWidth = 0; int newHeight = 0; if (Request.Form["width"] != null && Request.Form["width"].Length > 0 && Request.Form["height"] != null && Request.Form["height"].Length > 0) { newWidth = System.Int32.Parse(Request.Form["width"].Trim()); newHeight = System.Int32.Parse(Request.Form["height"].Trim()); } bool resizeOriginal = newWidth > 0 && newHeight > 0; if (resizeOriginal) { if (Request.Form["newFileName"] == null || Request.Form["newFileName"].Length == 0) { ConnectorException.Throw(Errors.InvalidName); } string newFileName = Request.Form["newFileName"]; // Replace dots in the name with underscores (only one dot can be there... security issue). if (Config.Current.ForceSingleExtension) { newFileName = Regex.Replace(newFileName, @"\.(?![^.]*$)", "_", RegexOptions.None); } if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(System.IO.Path.GetExtension(newFileName))) { ConnectorException.Throw(Errors.InvalidExtension); return; } if (!Connector.CheckFileName(newFileName) || Config.Current.CheckIsHiddenFile(newFileName)) { ConnectorException.Throw(Errors.InvalidName); return; } if (_Config.Images.MaxHeight > 0 && newHeight > _Config.Images.MaxHeight) { ConnectorException.Throw(Errors.InvalidRequest); } if (_Config.Images.MaxWidth > 0 && newWidth > _Config.Images.MaxWidth) { ConnectorException.Throw(Errors.InvalidRequest); } string newFilePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, newFileName); if (Request.Form["overwrite"] != "1" && System.IO.File.Exists(newFilePath)) { ConnectorException.Throw(Errors.AlreadyExist); } CKFinder.Connector.ImageTools.ResizeImage(filePath, newFilePath, newWidth, newHeight, true, Config.Current.Images.Quality); } string sExtension = System.IO.Path.GetExtension(fileName); sExtension = sExtension.TrimStart('.'); // Map the virtual path to the local server path. string sServerDir = this.CurrentFolder.ServerPath; string sFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(fileName); sFileNameNoExt = Regex.Replace(sFileNameNoExt, @"^(.+)_\d+x\d+$", "$1"); List <string> sizes = new List <string>(new string[] { "small", "medium", "large" }); Regex sizeRegex = new Regex(@"^(\d+)x(\d+)$"); foreach (string size in sizes) { if (Request.Form[size] != null && Request.Form[size] == "1") { string thumbName = sFileNameNoExt + "_" + size + "." + sExtension; string newFilePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, thumbName); if (CKFinder.Connector.Config.Current.PluginSettings.ContainsKey("ImageResize_" + size + "Thumb")) { string thumbSize = CKFinder.Connector.Config.Current.PluginSettings["ImageResize_" + size + "Thumb"].ToString().Trim(); if (sizeRegex.IsMatch(thumbSize)) { Match m = sizeRegex.Match(thumbSize); GroupCollection gc = m.Groups; newWidth = Int32.Parse(gc[1].Value); newHeight = Int32.Parse(gc[2].Value); CKFinder.Connector.ImageTools.ResizeImage(filePath, newFilePath, newWidth, newHeight, true, Config.Current.Images.Quality); } } } } }
protected override void BuildXml() { if (Request.Form["CKFinderCommand"] != "true") { ConnectorException.Throw(Errors.InvalidRequest); } if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileRename)) { ConnectorException.Throw(Errors.Unauthorized); } string fileName = Request["fileName"]; string newFileName = Request["newFileName"]; XmlNode oRenamedFileNode = XmlUtil.AppendElement(this.ConnectorNode, "RenamedFile"); XmlUtil.SetAttribute(oRenamedFileNode, "name", fileName); if (!Connector.CheckFileName(fileName) || Config.Current.CheckIsHiddenFile(fileName)) { ConnectorException.Throw(Errors.InvalidRequest); return; } if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(System.IO.Path.GetExtension(fileName))) { ConnectorException.Throw(Errors.InvalidRequest); return; } if (!Connector.CheckFileName(newFileName) || Config.Current.CheckIsHiddenFile(newFileName)) { ConnectorException.Throw(Errors.InvalidName); return; } if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(System.IO.Path.GetExtension(newFileName))) { ConnectorException.Throw(Errors.InvalidExtension); } if (Config.Current.DisallowUnsafeCharacters) { newFileName = newFileName.Replace(";", "_"); } // Replace dots in the name with underscores (only one dot can be there... security issue). if (Config.Current.ForceSingleExtension) { newFileName = Regex.Replace(newFileName, @"\.(?![^.]*$)", "_", RegexOptions.None); } if (Config.Current.CheckDoubleExtension) { newFileName = this.CurrentFolder.ResourceTypeInfo.ReplaceInvalidDoubleExtensions(newFileName); } string filePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, fileName); string newFilePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, newFileName); bool bMoved = false; if (!System.IO.File.Exists(filePath)) { ConnectorException.Throw(Errors.FileNotFound); } if (System.IO.File.Exists(newFilePath) || System.IO.Directory.Exists(newFilePath)) { ConnectorException.Throw(Errors.AlreadyExist); } try { System.IO.File.Move(filePath, newFilePath); bMoved = true; XmlUtil.SetAttribute(oRenamedFileNode, "newName", newFileName); } catch (System.UnauthorizedAccessException) { ConnectorException.Throw(Errors.AccessDenied); } catch (System.Security.SecurityException) { ConnectorException.Throw(Errors.AccessDenied); } catch (System.ArgumentException) { ConnectorException.Throw(Errors.InvalidName); } catch (System.NotSupportedException) { ConnectorException.Throw(Errors.InvalidName); } catch (System.IO.PathTooLongException) { ConnectorException.Throw(Errors.InvalidName); } catch (System.IO.IOException) { ConnectorException.Throw(Errors.Unknown); } catch { #if DEBUG throw; #else ConnectorException.Throw(Errors.Unknown); #endif } if (bMoved) { try { string thumbPath = System.IO.Path.Combine(this.CurrentFolder.ThumbsServerPath, fileName); System.IO.File.Delete(thumbPath); } catch { /* No errors if we are not able to delete the thumb. */ } } }
public override void SendResponse(System.Web.HttpResponse response) { int iErrorNumber = 0; string sFileName = ""; string sUnsafeFileName = ""; try { this.CheckConnector(); this.CheckRequest(); if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileUpload)) { ConnectorException.Throw(Errors.Unauthorized); } HttpPostedFile oFile = HttpContext.Current.Request.Files[HttpContext.Current.Request.Files.AllKeys[0]]; if (oFile != null) { sUnsafeFileName = System.IO.Path.GetFileName(oFile.FileName); sFileName = Regex.Replace(sUnsafeFileName, @"[\:\*\?\|\/]", "_", RegexOptions.None); if (sFileName != sUnsafeFileName) { iErrorNumber = Errors.UploadedInvalidNameRenamed; } if (Connector.CheckFileName(sFileName) && !Config.Current.CheckIsHiddenFile(sFileName)) { // Replace dots in the name with underscores (only one dot can be there... security issue). if (Config.Current.ForceSingleExtension) { sFileName = Regex.Replace(sFileName, @"\.(?![^.]*$)", "_", RegexOptions.None); } if (!Config.Current.CheckSizeAfterScaling && this.CurrentFolder.ResourceTypeInfo.MaxSize > 0 && oFile.ContentLength > this.CurrentFolder.ResourceTypeInfo.MaxSize) { ConnectorException.Throw(Errors.UploadedTooBig); } string sExtension = System.IO.Path.GetExtension(oFile.FileName); sExtension = sExtension.TrimStart('.'); if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(sExtension)) { ConnectorException.Throw(Errors.InvalidExtension); } if (Config.Current.CheckIsNonHtmlExtension(sExtension) && !this.CheckNonHtmlFile(oFile)) { ConnectorException.Throw(Errors.UploadedWrongHtmlFile); } // Map the virtual path to the local server path. string sServerDir = this.CurrentFolder.ServerPath; string sFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(sFileName); int iCounter = 0; while (true) { string sFilePath = System.IO.Path.Combine(sServerDir, sFileName); if (System.IO.File.Exists(sFilePath)) { iCounter++; sFileName = sFileNameNoExt + "(" + iCounter + ")" + System.IO.Path.GetExtension(oFile.FileName); iErrorNumber = Errors.UploadedFileRenamed; } else { oFile.SaveAs(sFilePath); if (Config.Current.SecureImageUploads && ImageTools.IsImageExtension(sExtension) && !ImageTools.ValidateImage(sFilePath)) { System.IO.File.Delete(sFilePath); ConnectorException.Throw(Errors.UploadedCorrupt); } Settings.Images imagesSettings = Config.Current.Images; if (imagesSettings.MaxHeight > 0 && imagesSettings.MaxWidth > 0) { ImageTools.ResizeImage(sFilePath, sFilePath, imagesSettings.MaxWidth, imagesSettings.MaxHeight, true, imagesSettings.Quality); if (Config.Current.CheckSizeAfterScaling && this.CurrentFolder.ResourceTypeInfo.MaxSize > 0) { long fileSize = new System.IO.FileInfo(sFilePath).Length; if (fileSize > this.CurrentFolder.ResourceTypeInfo.MaxSize) { System.IO.File.Delete(sFilePath); ConnectorException.Throw(Errors.UploadedTooBig); } } } break; } } } else { ConnectorException.Throw(Errors.InvalidName); } } else { ConnectorException.Throw(Errors.UploadedCorrupt); } } catch (ConnectorException connectorException) { iErrorNumber = connectorException.Number; } catch (System.Security.SecurityException) { #if DEBUG throw; #else iErrorNumber = Errors.AccessDenied; #endif } catch (System.UnauthorizedAccessException) { #if DEBUG throw; #else iErrorNumber = Errors.AccessDenied; #endif } catch { #if DEBUG throw; #else iErrorNumber = Errors.Unknown; #endif } #if DEBUG if (iErrorNumber == Errors.None || iErrorNumber == Errors.UploadedFileRenamed || iErrorNumber == Errors.UploadedInvalidNameRenamed) { response.Clear(); } #else response.Clear(); #endif response.Write("<script type=\"text/javascript\">"); response.Write(this.GetJavaScriptCode(iErrorNumber, sFileName, this.CurrentFolder.Url + sFileName)); response.Write("</script>"); response.End(); }
public override void SendResponse(HttpResponse response) { int iErrorNumber = 0; string sFileName = ""; try { CheckConnector(); CheckRequest(); HttpPostedFile oFile = HttpContext.Current.Request.Files["NewFile"]; if (oFile == null) { ConnectorException.Throw(Errors.UploadedCorrupt); return; } if (!CurrentFolder.CheckAcl(AccessControlRules.FileUpload)) { ConnectorException.Throw(Errors.Unauthorized); } sFileName = Path.GetFileName(oFile.FileName.ToLower()); if (Connector.CheckFileName(sFileName) && !Config.Current.CheckIsHiddenFile(sFileName)) { // // Replace dots in the name with underscores (only one dot can be there... security issue). // if (Config.Current.ForceSingleExtension) { sFileName = Regex.Replace(sFileName, @"\.(?![^.]*$)", "_", RegexOptions.None); } if (!Config.Current.CheckSizeAfterScaling && CurrentFolder.ResourceTypeInfo.MaxSize > 0 && oFile.ContentLength > CurrentFolder.ResourceTypeInfo.MaxSize) { ConnectorException.Throw(Errors.UploadedTooBig); } // // Validate Extension // string sExtension = Path.GetExtension(oFile.FileName); sExtension = sExtension.TrimStart('.'); if (!CurrentFolder.ResourceTypeInfo.CheckExtension(sExtension)) { ConnectorException.Throw(Errors.InvalidExtension); } //if (Config.Current.CheckIsNonHtmlExtension(sExtension) && !CheckNonHtmlFile(oFile)) // ConnectorException.Throw(Errors.UploadedWrongHtmlFile); // // Map the virtual path to the local server path. // string sServerDir = CurrentFolder.ServerPath; string sFileNameNoExt = Path.GetFileNameWithoutExtension(sFileName); int iCounter = 0; while (true) { string sFilePath = Path.Combine(sServerDir, sFileName); //if (File.Exists(sFilePath)) //{ // iCounter++; // sFileName = string.Format("{0} ({1}){2}", // sFileNameNoExt, // iCounter, // Path.GetExtension(oFile.FileName)); // iErrorNumber = Errors.UploadedFileRenamed; // continue; //} // // Save file // oFile.SaveAs(sFilePath); try { if (oFile.FileName.ToLower().Contains(themeExtension)) { TransformThemeFileInMasterPage(sFilePath); } else if (oFile.FileName.ToLower().Contains(packExtension)) { var zipFile = new ZipFile(sFilePath); zipFile.UnZipping += (sender, e) => { string extension = Path.GetExtension(e.FullPath.ToLower()).Trim(new[] { '.' }); if (!String.IsNullOrEmpty(extension) && !CurrentFolder.ResourceTypeInfo.CheckExtension(extension)) { e.Cancel = true; } }; zipFile.UnZipped += (sender, e) => { if (e.FullPath.ToLower().Contains(themeExtension)) { TransformThemeFileInMasterPage(e.FullPath); } }; zipFile.Extract(sServerDir); } if (ImageTools.IsImageExtension(sExtension)) { if (Config.Current.SecureImageUploads && !ImageTools.ValidateImage(sFilePath)) { File.Delete(sFilePath); ConnectorException.Throw(Errors.UploadedCorrupt); } Images imagesSettings = Config.Current.Images; if (imagesSettings.MaxHeight <= 0 || imagesSettings.MaxWidth <= 0) { break; } ImageTools.ResizeImage(sFilePath, sFilePath, imagesSettings.MaxWidth, imagesSettings.MaxHeight, true, imagesSettings.Quality); } if (Config.Current.CheckSizeAfterScaling && CurrentFolder.ResourceTypeInfo.MaxSize > 0) { long fileSize = new FileInfo(sFilePath).Length; if (fileSize > CurrentFolder.ResourceTypeInfo.MaxSize) { File.Delete(sFilePath); ConnectorException.Throw(Errors.UploadedTooBig); } } } catch (ArgumentException ex) { iErrorNumber = Errors.UploadedWrongThemeFile; } break; } } else { ConnectorException.Throw(Errors.InvalidName); } } catch (ConnectorException connectorException) { iErrorNumber = connectorException.Number; } catch (Exception ex) { ex.GetHashCode(); iErrorNumber = Errors.Unknown; } response.Clear(); response.Write("<script type=\"text/javascript\">"); response.Write(GetJavaScriptCode(iErrorNumber, sFileName, CurrentFolder.Url + sFileName)); response.Write("</script>"); response.End(); }