private string GetCurrentDirectory() { string hiddenCurrentFolder = hdnFolder.Value; if (string.IsNullOrEmpty(hiddenCurrentFolder)) { return(rootDirectory); } if (hiddenCurrentFolder.StartsWith("/")) { hiddenCurrentFolder = "~" + hiddenCurrentFolder; } if (!fileSystem.FolderExists(hiddenCurrentFolder)) { return(rootDirectory); } if (WebFolder.IsDecendentVirtualPath(rootDirectory, hiddenCurrentFolder)) { return(hiddenCurrentFolder); } return(rootDirectory); }
void btnDelete_Click(object sender, EventArgs e) { // this is using a LinkButton which I normally never use for accessibility reasons // because linkbuttons don't work if javascript is disabled // but in this case this dialog can't work any if javascript is disabled // so I'm using one if (userCanDeleteFiles) { string fileToDelete = string.Empty; if (hdnFileUrl.Value.Length > 0) { fileToDelete = hdnFileUrl.Value; } bool canDelete = WebFolder.IsDecendentVirtualPath(rootDirectory, fileToDelete); if (canDelete) { //File.Delete(Server.MapPath(fileToDelete)); fileSystem.DeleteFile(fileToDelete); } } if ((hdnFolder.Value.Length > 0) && (hdnFolder.Value != rootDirectory)) { currentDir = hdnFolder.Value; } WebUtils.SetupRedirect(this, GetRedirectUrl()); }
private void LoadSettings() { try { // this keeps the action from changing during ajax postback in folder based sites SiteUtils.SetFormAction(Page, Request.RawUrl); } catch (MissingMethodException) { //this method was introduced in .NET 3.5 SP1 } siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { return; } userCanDeleteFiles = WebUser.IsInRoles(siteSettings.RolesThatCanDeleteFilesInEditor); FileSystemProvider p = FileSystemManager.Providers[WebConfigSettings.FileSystemProvider]; if (p == null) { log.Error("Could not load file system provider " + WebConfigSettings.FileSystemProvider); return; } fileSystem = p.GetFileSystem(); if (fileSystem == null) { log.Error("Could not load file system from provider " + WebConfigSettings.FileSystemProvider); return; } rootDirectory = fileSystem.VirtualRoot; if ((WebUser.IsAdminOrContentAdmin) || (SiteUtils.UserIsSiteEditor())) { allowedExtensions = WebConfigSettings.AllowedUploadFileExtensions; regexFile.ValidationExpression = SecurityHelper.GetRegexValidationForAllowedExtensions(allowedExtensions); uploader.AcceptFileTypes = SecurityHelper.GetRegexValidationForAllowedExtensionsJqueryFileUploader(allowedExtensions); canEdit = true; userCanDeleteFiles = true; } else if (WebUser.IsInRoles(siteSettings.GeneralBrowseAndUploadRoles)) { allowedExtensions = WebConfigSettings.AllowedUploadFileExtensions; regexFile.ValidationExpression = SecurityHelper.GetRegexValidationForAllowedExtensions(allowedExtensions); uploader.AcceptFileTypes = SecurityHelper.GetRegexValidationForAllowedExtensionsJqueryFileUploader(allowedExtensions); canEdit = true; } else if (WebUser.IsInRoles(siteSettings.UserFilesBrowseAndUploadRoles)) { currentUser = SiteUtils.GetCurrentSiteUser(); if (currentUser == null) { return; } allowedExtensions = WebConfigSettings.AllowedLessPriveledgedUserUploadFileExtensions; regexFile.ValidationExpression = SecurityHelper.GetRegexValidationForAllowedExtensions(allowedExtensions); uploader.AcceptFileTypes = SecurityHelper.GetRegexValidationForAllowedExtensionsJqueryFileUploader(allowedExtensions); canEdit = true; if (!userCanDeleteFiles) { // user is not in a role that can delete files but config setting alows delete from user specific folder anyway userCanDeleteFiles = WebConfigSettings.AllowDeletingFilesFromUserFolderWithoutDeleteRole; } } resizeWidth = WebConfigSettings.ResizeImageDefaultMaxWidth; resizeHeight = WebConfigSettings.ResizeImageDefaultMaxHeight; if (!IsPostBack) { chkConstrainImageSize.Checked = WebConfigSettings.ResizeEditorUploadedImages; } pnlUpload.Visible = canEdit; if (Request.QueryString["ed"] != null) { editorType = Request.QueryString["ed"]; } string requestedType = "image"; if (Request.QueryString["type"] != null) { requestedType = Request.QueryString["type"]; } if (Request.QueryString["dir"] != null) { currentDir = Request.QueryString["dir"]; if (!WebFolder.IsDecendentVirtualPath(rootDirectory, currentDir)) { currentDir = string.Empty; } } if (Request.QueryString["CKEditor"] != null) { CKEditor = Request.QueryString["CKEditor"]; } if (Request.QueryString["CKEditorFuncNum"] != null) { CKEditorFuncNum = Request.QueryString["CKEditorFuncNum"]; } if (Request.QueryString["langCode"] != null) { langCode = Request.QueryString["langCode"]; } if (Request.QueryString["tbi"] != null) { clientTextBoxId = Request.QueryString["tbi"]; } switch (requestedType) { case "media": browserType = "media"; break; case "audio": browserType = "audio"; break; case "video": browserType = "video"; break; case "file": browserType = "file"; break; case "folder": browserType = "folder"; divFileUpload.Visible = false; //divFilePreview.Visible = false; break; case "image": default: browserType = "image"; break; } navigationRoot = SiteUtils.GetNavigationSiteRoot(); lnkRoot.Text = rootDirectory.Replace("~", string.Empty); lnkRoot.NavigateUrl = navigationRoot + "/Dialog/FileDialog.aspx?type=" + browserType; if (!Page.IsPostBack) { hdnFolder.Value = rootDirectory; if (currentDir.Length > 0) { hdnFolder.Value = currentDir; } txtMaxWidth.Text = resizeWidth.ToInvariantString(); txtMaxHeight.Text = resizeHeight.ToInvariantString(); } else { int.TryParse(txtMaxWidth.Text, out resizeWidth); int.TryParse(txtMaxHeight.Text, out resizeHeight); } imageCropperUrl = navigationRoot + "/Dialog/ImageCropperDialog.aspx"; lnkImageCropper.NavigateUrl = imageCropperUrl; if ((canEdit) && (browserType != "folder")) { string fileSystemToken = Global.FileSystemToken.ToString(); uploader.UseDropZone = WebConfigSettings.FileDialogEnableDragDrop; uploader.UploadButtonClientId = btnUpload.ClientID; uploader.ServiceUrl = navigationRoot + "/Services/FileService.ashx?cmd=uploadfromeditor&q=" + Server.UrlEncode(hdnFolder.ClientID) + "&t=" + fileSystemToken; StringBuilder refreshScript = new StringBuilder(); refreshScript.Append("function refresh() {"); refreshScript.Append("var selDir = document.getElementById('" + hdnFolder.ClientID + "').value; "); refreshScript.Append("window.location.href = updateQueryStringParameter(window.location.href,'dir',selDir); "); refreshScript.Append("} "); //string refreshFunction = "function refresh" // + " () { window.location.reload(true)'; } "; uploader.UploadCompleteCallback = "refresh"; ScriptManager.RegisterClientScriptBlock( this, this.GetType(), "refresh", refreshScript.ToString(), true); } }
private bool IsChildDirectory(HttpContext context, string requestedDirectory) { return(WebFolder.IsDecendentVirtualPath(fileSystem.VirtualRoot, requestedDirectory)); }
private void LoadSettings() { if (Request.QueryString["return"] != null) { returnUrl = Request.QueryString["return"]; lnkReturn.NavigateUrl = returnUrl; lnkReturn.Visible = true; } siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { return; } FileSystemProvider p = FileSystemManager.Providers[WebConfigSettings.FileSystemProvider]; if (p == null) { return; } fileSystem = p.GetFileSystem(); if (fileSystem == null) { return; } rootDirectory = fileSystem.VirtualRoot; if (WebUser.IsAdminOrContentAdmin) { canEdit = true; } else if (WebUser.IsInRoles(siteSettings.GeneralBrowseAndUploadRoles)) { canEdit = true; } else if (WebUser.IsInRoles(siteSettings.UserFilesBrowseAndUploadRoles)) { canEdit = true; } if (Request.QueryString["src"] != null) { sourceImageVirtualPath = Request.QueryString["src"]; if (sourceImageVirtualPath.Length > 0) { if ((fileSystem.FileBaseUrl.Length > 0) && (sourceImageVirtualPath.StartsWith(fileSystem.FileBaseUrl))) { sourceImageVirtualPath = sourceImageVirtualPath.Substring(fileSystem.FileBaseUrl.Length); } isAllowedPath = WebFolder.IsDecendentVirtualPath(rootDirectory, sourceImageVirtualPath); sourceExists = fileSystem.FileExists(sourceImageVirtualPath); isAllowedPath = WebFolder.IsDecendentVirtualPath(rootDirectory, sourceImageVirtualPath); } } if (sourceImageVirtualPath.Length == 0) { cropper.Visible = false; return; } destImageVirtualPath = VirtualPathUtility.Combine(VirtualPathUtility.GetDirectory(sourceImageVirtualPath), Path.GetFileNameWithoutExtension(sourceImageVirtualPath) + "crop" + VirtualPathUtility.GetExtension(sourceImageVirtualPath)); SiteUtils.SetFormAction(Page, Request.RawUrl); }