From 9e239f135d363cf3e477d8bb315e7d395bb4b11f Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Fri, 5 Apr 2013 06:06:10 +0600 Subject: [PATCH] Fixes: #U4-2027, changes DirectoryBrowser over to use correct webforms file structure, cleans up (a teeny bit) how this page is structured, at least its not all inline c# code with inline styles. --- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 8 + .../Packages/DirectoryBrowser.aspx.cs | 149 +++++++++++++++++ .../DirectoryBrowser.aspx.designer.cs | 42 +++++ .../developer/Packages/directoryBrowser.aspx | 150 ++---------------- .../Editors/DirectoryBrowser.css | 28 ++++ src/Umbraco.Web/Umbraco.Web.csproj | 13 +- .../developer/Packages/directoryBrowser.aspx | 142 ----------------- .../Packages/directoryBrowser.aspx.cs | 12 +- .../directoryBrowser.aspx.designer.cs | 25 --- 9 files changed, 256 insertions(+), 313 deletions(-) create mode 100644 src/Umbraco.Web.UI/umbraco/developer/Packages/DirectoryBrowser.aspx.cs create mode 100644 src/Umbraco.Web.UI/umbraco/developer/Packages/DirectoryBrowser.aspx.designer.cs create mode 100644 src/Umbraco.Web.UI/umbraco_client/Editors/DirectoryBrowser.css delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx.designer.cs diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 9550a18117..3dc9e8c257 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -406,6 +406,13 @@ editMacro.aspx + + directoryBrowser.aspx + ASPXCodeBehind + + + directoryBrowser.aspx + StarterKits.aspx ASPXCodeBehind @@ -785,6 +792,7 @@ + diff --git a/src/Umbraco.Web.UI/umbraco/developer/Packages/DirectoryBrowser.aspx.cs b/src/Umbraco.Web.UI/umbraco/developer/Packages/DirectoryBrowser.aspx.cs new file mode 100644 index 0000000000..8c7526a4ef --- /dev/null +++ b/src/Umbraco.Web.UI/umbraco/developer/Packages/DirectoryBrowser.aspx.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Web; +using System.Web.UI; +using Umbraco.Core; +using Umbraco.Core.IO; +using Umbraco.Web.UI.Pages; + +namespace Umbraco.Web.UI.Umbraco.Developer.Packages +{ + public partial class DirectoryBrowser : UmbracoEnsuredPage + { + + string _lsTitle; + string _lsLink; + string _lsScriptName; + string _lsWebPath; + protected string Target = ""; + private readonly Regex _xssElementIdClean = new Regex(@"^([a-zA-Z0-9-_:\.]+)"); + + private readonly StringBuilder _sb = new StringBuilder(); + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + Response.Cache.SetExpires(DateTime.Now.AddSeconds(5)); + Response.Cache.SetCacheability(HttpCacheability.Public); + _lsTitle = Request.QueryString.Get("title"); + + //we need to clean this string: + //http://issues.umbraco.org/issue/U4-2027 + var target = Request.QueryString.Get("target"); + if (target.IsNullOrWhiteSpace()) + throw new InvalidOperationException("The target query string must be set to a valid html element id"); + var matched = _xssElementIdClean.Matches(target); + if (matched.Count == 0) + throw new InvalidOperationException("The target query string must be set to a valid html element id"); + + Target = matched[0].Value; + + if (string.IsNullOrEmpty(_lsTitle)) { _lsTitle = "Web Browse"; } + + try + { + + //Variables used in script + var sebChar = IOHelper.DirSepChar.ToString(); + + //Write header, get link param + _lsLink = Request.QueryString.Get("link"); + if (!string.IsNullOrEmpty(_lsLink)) + { + _sb.Append("[ Return ]
"); + } + + //Work on path and ensure no back tracking + string sSubDir = Request.QueryString.Get("path"); + if (string.IsNullOrEmpty(sSubDir)) { sSubDir = "/"; } + + sSubDir = sSubDir.Replace(IOHelper.DirSepChar.ToString(), ""); + sSubDir = sSubDir.Replace("//", "/"); + sSubDir = sSubDir.Replace("..", "./"); + sSubDir = sSubDir.Replace('/', IOHelper.DirSepChar); + + //Clean path for processing and collect path varitations + if (sSubDir.Substring(0, 1) != sebChar) { sSubDir = sebChar + sSubDir; } + if (sSubDir.Substring(sSubDir.Length - 1, 1) != "\\") { sSubDir = sSubDir + sebChar; } + + //Get name of the browser script file + _lsScriptName = Request.ServerVariables.Get("SCRIPT_NAME"); + var j = _lsScriptName.LastIndexOf("/"); + if (j > 0) { _lsScriptName = _lsScriptName.Substring(j + 1, _lsScriptName.Length - (j + 1)).ToLower(); } + + //Create navigation string and other path strings + GetNavLink("", "root"); + if (sSubDir != sebChar) + { + j = 0; int i = 0; + do + { + i = sSubDir.IndexOf(sebChar, j + 1); + _lsWebPath += sSubDir.Substring(j + 1, i - (j + 1)) + "/"; + GetNavLink(_lsWebPath, sSubDir.Substring(j + 1, i - (j + 1))); + j = i; + } while (i != sSubDir.Length - 1); + } + + //Output header + _sb.Append(""); + + //Output directorys + var oDirInfo = new DirectoryInfo(IOHelper.MapPath("~/" + sSubDir)); + var oDirs = oDirInfo.GetDirectories(); + foreach (var oDir in oDirs) + { + try + { + _sb.Append(""); + } + catch (Exception ex) + { + _sb.Append(""); + } + } + + //Ouput files + var oFiles = oDirInfo.GetFiles(); + foreach (var oFile in oFiles.Where(oFile => oFile.Name.ToLower() != _lsScriptName)) + { + decimal iLen = oFile.Length; + string sLen; + if (iLen >= 1048960) { iLen = iLen / 1048960; sLen = "mb"; } else { iLen = iLen / 1024; sLen = "kb"; } + sLen = Decimal.Round(iLen, 2).ToString() + sLen; + _sb.Append(""); + } + + //Output footer + _sb.Append("
" + oDir.Name + " (Include entire folder)
" + oDir.Name + " (Access Denied)
" + oFile.Name + "
"); + + } + catch (Exception ex) + { + RptErr(ex.Message); + } + } + + protected override void OnPreRender(EventArgs e) + { + base.OnPreRender(e); + Output.Controls.Add(new LiteralControl(_sb.ToString())); + } + + private void RptErr(string psMessage) + { + _sb.Append("
Script Reported Error:  " + psMessage + "

"); + } + + private string GetNavLink(string psHref, string psText) + { + return ("/" + psText + ""); + } + + } +} \ No newline at end of file diff --git a/src/Umbraco.Web.UI/umbraco/developer/Packages/DirectoryBrowser.aspx.designer.cs b/src/Umbraco.Web.UI/umbraco/developer/Packages/DirectoryBrowser.aspx.designer.cs new file mode 100644 index 0000000000..aadd756173 --- /dev/null +++ b/src/Umbraco.Web.UI/umbraco/developer/Packages/DirectoryBrowser.aspx.designer.cs @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Umbraco.Web.UI.Umbraco.Developer.Packages { + + + public partial class DirectoryBrowser { + + /// + /// CssInclude1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::ClientDependency.Core.Controls.CssInclude CssInclude1; + + /// + /// pane control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.Pane pane; + + /// + /// Output control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.PlaceHolder Output; + } +} diff --git a/src/Umbraco.Web.UI/umbraco/developer/Packages/directoryBrowser.aspx b/src/Umbraco.Web.UI/umbraco/developer/Packages/directoryBrowser.aspx index 375cf2f3d1..d7988fd0cc 100644 --- a/src/Umbraco.Web.UI/umbraco/developer/Packages/directoryBrowser.aspx +++ b/src/Umbraco.Web.UI/umbraco/developer/Packages/directoryBrowser.aspx @@ -1,142 +1,24 @@ -<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="../../masterpages/umbracoPage.Master"Inherits="umbraco.presentation.developer.packages.directoryBrowser" %> -<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %> -<%@ Import Namespace="System.IO" %> +<%@ Page Language="C#" AutoEventWireup="True" MasterPageFile="../../masterpages/umbracoPage.Master" CodeBehind="DirectoryBrowser.aspx.cs" Inherits="Umbraco.Web.UI.Umbraco.Developer.Packages.DirectoryBrowser" %> +<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %> +<%@ Register TagPrefix="cdf" Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" %> - - - - - + + + + - - <% - try - { - - //Variables used in script - string sSubDir; int i; int j; - string sPrevLink = ""; - string sebChar = umbraco.IO.IOHelper.DirSepChar.ToString(); - decimal iLen; string sLen; - - //Write header, get link param - lsLink = Request.QueryString.Get("link"); - if (lsLink != null && lsLink != "") { Response.Write("[ Return ]
"); } - - //Work on path and ensure no back tracking - sSubDir = Request.QueryString.Get("path"); - if (sSubDir == null || sSubDir == "") { sSubDir = "/"; } - - sSubDir = sSubDir.Replace(umbraco.IO.IOHelper.DirSepChar.ToString(), ""); - sSubDir = sSubDir.Replace("//", "/"); - sSubDir = sSubDir.Replace("..", "./"); - sSubDir = sSubDir.Replace('/', umbraco.IO.IOHelper.DirSepChar); - - //Clean path for processing and collect path varitations - if (sSubDir.Substring(0, 1) != sebChar) { sSubDir = sebChar + sSubDir; } - if (sSubDir.Substring(sSubDir.Length - 1, 1) != "\\") { sSubDir = sSubDir + sebChar; } - - //Get name of the browser script file - lsScriptName = Request.ServerVariables.Get("SCRIPT_NAME"); - j = lsScriptName.LastIndexOf("/"); - if (j > 0) { lsScriptName = lsScriptName.Substring(j + 1, lsScriptName.Length - (j + 1)).ToLower(); } - - //Create navigation string and other path strings - sPrevLink += GetNavLink("", "root"); - if (sSubDir != sebChar) - { - j = 0; i = 0; - do - { - i = sSubDir.IndexOf(sebChar, j + 1); - lsWebPath += sSubDir.Substring(j + 1, i - (j + 1)) + "/"; - sPrevLink += GetNavLink(lsWebPath, sSubDir.Substring(j + 1, i - (j + 1))); - j = i; - } while (i != sSubDir.Length - 1); - } - - //Output header - Response.Write(""); - - //Output directorys - DirectoryInfo oDirInfo = new DirectoryInfo(umbraco.IO.IOHelper.MapPath("~/" + sSubDir)); - DirectoryInfo[] oDirs = oDirInfo.GetDirectories(); - foreach (DirectoryInfo oDir in oDirs) - { - try - { - Response.Write(""); - } - catch (Exception ex) - { - Response.Write(""); - } - } - - //Ouput files - FileInfo[] oFiles = oDirInfo.GetFiles(); - foreach (FileInfo oFile in oFiles) - { - if (oFile.Name.ToLower() != lsScriptName) - { - iLen = oFile.Length; - if (iLen >= 1048960) { iLen = iLen / 1048960; sLen = "mb"; } else { iLen = iLen / 1024; sLen = "kb"; } - sLen = Decimal.Round(iLen, 2).ToString() + sLen; - Response.Write(""); - } - } - - //Output footer - Response.Write("
" + oDir.Name + " (Include entire folder)
" + oDir.Name + " (Access Denied)
" + oFile.Name + "
"); - - } - catch (Exception ex) - { - RptErr(ex.Message); - } - %> + + -
\ No newline at end of file + diff --git a/src/Umbraco.Web.UI/umbraco_client/Editors/DirectoryBrowser.css b/src/Umbraco.Web.UI/umbraco_client/Editors/DirectoryBrowser.css new file mode 100644 index 0000000000..e9e1a2b382 --- /dev/null +++ b/src/Umbraco.Web.UI/umbraco_client/Editors/DirectoryBrowser.css @@ -0,0 +1,28 @@ +a +{ + color: #3C6B96; +} + +.tdDir a +{ + color: #3C6B96; + padding: 3px; + padding-left: 25px; + background: url(../../umbraco/images/foldericon.png) no-repeat 2px 2px; +} + +.tdFile a +{ + color: #3C6B96; + padding: 3px; + padding-left: 25px; + background: url(../../umbraco/images/file.png) no-repeat 2px 2px; +} + +small a +{ + color: #999; + padding-left: 3px !Important; + background-image: none !Important; + text-decoration: none; +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index acff13eccf..aa17426500 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -345,6 +345,9 @@ + + ASPXCodeBehind + AssignDomain2.aspx ASPXCodeBehind @@ -1140,13 +1143,6 @@ BrowseRepository.aspx - - directoryBrowser.aspx - ASPXCodeBehind - - - directoryBrowser.aspx - editPackage.aspx ASPXCodeBehind @@ -1868,9 +1864,6 @@ - - ASPXCodeBehind - diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx deleted file mode 100644 index 375cf2f3d1..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx +++ /dev/null @@ -1,142 +0,0 @@ -<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="../../masterpages/umbracoPage.Master"Inherits="umbraco.presentation.developer.packages.directoryBrowser" %> -<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %> -<%@ Import Namespace="System.IO" %> - - - - - - - - - - - - - - <% - try - { - - //Variables used in script - string sSubDir; int i; int j; - string sPrevLink = ""; - string sebChar = umbraco.IO.IOHelper.DirSepChar.ToString(); - decimal iLen; string sLen; - - //Write header, get link param - lsLink = Request.QueryString.Get("link"); - if (lsLink != null && lsLink != "") { Response.Write("[ Return ]
"); } - - //Work on path and ensure no back tracking - sSubDir = Request.QueryString.Get("path"); - if (sSubDir == null || sSubDir == "") { sSubDir = "/"; } - - sSubDir = sSubDir.Replace(umbraco.IO.IOHelper.DirSepChar.ToString(), ""); - sSubDir = sSubDir.Replace("//", "/"); - sSubDir = sSubDir.Replace("..", "./"); - sSubDir = sSubDir.Replace('/', umbraco.IO.IOHelper.DirSepChar); - - //Clean path for processing and collect path varitations - if (sSubDir.Substring(0, 1) != sebChar) { sSubDir = sebChar + sSubDir; } - if (sSubDir.Substring(sSubDir.Length - 1, 1) != "\\") { sSubDir = sSubDir + sebChar; } - - //Get name of the browser script file - lsScriptName = Request.ServerVariables.Get("SCRIPT_NAME"); - j = lsScriptName.LastIndexOf("/"); - if (j > 0) { lsScriptName = lsScriptName.Substring(j + 1, lsScriptName.Length - (j + 1)).ToLower(); } - - //Create navigation string and other path strings - sPrevLink += GetNavLink("", "root"); - if (sSubDir != sebChar) - { - j = 0; i = 0; - do - { - i = sSubDir.IndexOf(sebChar, j + 1); - lsWebPath += sSubDir.Substring(j + 1, i - (j + 1)) + "/"; - sPrevLink += GetNavLink(lsWebPath, sSubDir.Substring(j + 1, i - (j + 1))); - j = i; - } while (i != sSubDir.Length - 1); - } - - //Output header - Response.Write(""); - - //Output directorys - DirectoryInfo oDirInfo = new DirectoryInfo(umbraco.IO.IOHelper.MapPath("~/" + sSubDir)); - DirectoryInfo[] oDirs = oDirInfo.GetDirectories(); - foreach (DirectoryInfo oDir in oDirs) - { - try - { - Response.Write(""); - } - catch (Exception ex) - { - Response.Write(""); - } - } - - //Ouput files - FileInfo[] oFiles = oDirInfo.GetFiles(); - foreach (FileInfo oFile in oFiles) - { - if (oFile.Name.ToLower() != lsScriptName) - { - iLen = oFile.Length; - if (iLen >= 1048960) { iLen = iLen / 1048960; sLen = "mb"; } else { iLen = iLen / 1024; sLen = "kb"; } - sLen = Decimal.Round(iLen, 2).ToString() + sLen; - Response.Write(""); - } - } - - //Output footer - Response.Write("
" + oDir.Name + " (Include entire folder)
" + oDir.Name + " (Access Denied)
" + oFile.Name + "
"); - - } - catch (Exception ex) - { - RptErr(ex.Message); - } - %> -
-
\ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx.cs index 4df0e46441..cb6cc75fca 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Data; using System.Configuration; using System.Collections; @@ -11,8 +11,16 @@ using System.Web.UI.HtmlControls; namespace umbraco.presentation.developer.packages { + [Obsolete("This class is no longer used and will be removed from the codebase in the future")] public partial class directoryBrowser : BasePages.UmbracoEnsuredPage { - + /// + /// pane control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.Pane pane; } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx.designer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx.designer.cs deleted file mode 100644 index 6d4229a166..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/directoryBrowser.aspx.designer.cs +++ /dev/null @@ -1,25 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:2.0.50727.4200 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace umbraco.presentation.developer.packages { - - - public partial class directoryBrowser { - - /// - /// pane control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.Pane pane; - } -}