Migrated UmbracoSettings, GlobalSettings, XmlHelper, IOHelper and supporting classes to Umbraco.Core.
This fixes the need for Umbraco.Core to reference business logic since business logic needs to reference Umbraco.Core (Umbraco.Core should never reference any other project except for interfaces, it is the 'Core' of the new codebase.
This commit is contained in:
837
src/Umbraco.Core/Configuration/GlobalSettings.cs
Normal file
837
src/Umbraco.Core/Configuration/GlobalSettings.cs
Normal file
@@ -0,0 +1,837 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Xml;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Core.Configuration
|
||||
{
|
||||
//NOTE: Do not expose this class ever until we cleanup all configuration including removal of static classes, etc...
|
||||
// we have this two tasks logged:
|
||||
// http://issues.umbraco.org/issue/U4-58
|
||||
// http://issues.umbraco.org/issue/U4-115
|
||||
|
||||
//TODO: Re-enable Logging!!!!
|
||||
|
||||
//TODO: Remove checks for if HttpContext is null, why are we doing this? we should be checking if the config setting
|
||||
// can be read and if not then return the default.
|
||||
|
||||
/// <summary>
|
||||
/// The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information from web.config appsettings
|
||||
/// </summary>
|
||||
internal class GlobalSettings
|
||||
{
|
||||
|
||||
private static HttpContextBase _customHttpContext;
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the HttpContext object, this is generally used for unit testing. By default this will
|
||||
/// use the HttpContext.Current
|
||||
/// </summary>
|
||||
internal static HttpContextBase HttpContext
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_customHttpContext == null && System.Web.HttpContext.Current != null)
|
||||
{
|
||||
//return the current HttpContxt, do NOT store this in the _customHttpContext field
|
||||
//as it will persist across reqeusts!
|
||||
return new HttpContextWrapper(System.Web.HttpContext.Current);
|
||||
}
|
||||
|
||||
if (_customHttpContext == null && System.Web.HttpContext.Current == null)
|
||||
{
|
||||
//throw new NullReferenceException("The HttpContext property has not been set or the object execution is not running inside of an HttpContext");
|
||||
//NOTE: We should throw an exception here but the legacy code checks for null so we need to stick witht he legacy code for now.
|
||||
return null;
|
||||
}
|
||||
return _customHttpContext;
|
||||
}
|
||||
set { _customHttpContext = value; }
|
||||
}
|
||||
|
||||
#region Private static fields
|
||||
|
||||
// CURRENT UMBRACO VERSION ID
|
||||
private const string CurrentUmbracoVersion = "4.9.0";
|
||||
|
||||
private static string _reservedUrlsCache;
|
||||
private static string _reservedPathsCache;
|
||||
private static StartsWithContainer _reservedList = new StartsWithContainer();
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reserved urls from web.config.
|
||||
/// </summary>
|
||||
/// <value>The reserved urls.</value>
|
||||
public static string ReservedUrls
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext != null)
|
||||
return ConfigurationManager.AppSettings["umbracoReservedUrls"];
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reserved paths from web.config
|
||||
/// </summary>
|
||||
/// <value>The reserved paths.</value>
|
||||
public static string ReservedPaths
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext != null)
|
||||
return ConfigurationManager.AppSettings["umbracoReservedPaths"];
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the content XML file.
|
||||
/// </summary>
|
||||
/// <value>The content XML.</value>
|
||||
public static string ContentXml
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return ConfigurationManager.AppSettings["umbracoContentXML"];
|
||||
}
|
||||
catch
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path to the storage directory (/data by default).
|
||||
/// </summary>
|
||||
/// <value>The storage directory.</value>
|
||||
public static string StorageDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return ConfigurationManager.AppSettings["umbracoStorageDirectory"];
|
||||
}
|
||||
catch
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path to umbraco's root directory (/umbraco by default).
|
||||
/// </summary>
|
||||
/// <value>The path.</value>
|
||||
public static string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
return IOHelper.ResolveUrl(ConfigurationManager.AppSettings["umbracoPath"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path to umbraco's client directory (/umbraco_client by default).
|
||||
/// This is a relative path to the Umbraco Path as it always must exist beside the 'umbraco'
|
||||
/// folder since the CSS paths to images depend on it.
|
||||
/// </summary>
|
||||
/// <value>The path.</value>
|
||||
public static string ClientPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path + "/../umbraco_client";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the database connection string
|
||||
/// </summary>
|
||||
/// <value>The database connection string.</value>
|
||||
public static string DbDsn
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return ConfigurationManager.AppSettings["umbracoDbDSN"];
|
||||
}
|
||||
catch
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (DbDsn != value)
|
||||
{
|
||||
SaveSetting("umbracoDbDSN", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the configuration status. This will return the version number of the currently installed umbraco instance.
|
||||
/// </summary>
|
||||
/// <value>The configuration status.</value>
|
||||
public static string ConfigurationStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return ConfigurationManager.AppSettings["umbracoConfigurationStatus"];
|
||||
}
|
||||
catch
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
SaveSetting("umbracoConfigurationStatus", value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Forces umbraco to be medium trust compatible
|
||||
/// </summary>
|
||||
/// <value>If true, umbraco will be medium-trust compatible, no matter what Permission level the server is on.</value>
|
||||
public static bool UseMediumTrust
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var trustLevel = SystemUtilities.GetCurrentTrustLevel();
|
||||
if (trustLevel == AspNetHostingPermissionLevel.High || trustLevel == AspNetHostingPermissionLevel.Unrestricted)
|
||||
return false;
|
||||
else
|
||||
return bool.Parse(ConfigurationManager.AppSettings["umbracoUseMediumTrust"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a setting into the configuration file.
|
||||
/// </summary>
|
||||
/// <param name="key">Key of the setting to be saved.</param>
|
||||
/// <param name="value">Value of the setting to be saved.</param>
|
||||
internal static void SaveSetting(string key, string value)
|
||||
{
|
||||
var webConfig = new WebConfigurationFileMap();
|
||||
var vDirs = webConfig.VirtualDirectories;
|
||||
var vDir = FullpathToRoot;
|
||||
foreach (VirtualDirectoryMapping v in webConfig.VirtualDirectories)
|
||||
{
|
||||
if (v.IsAppRoot)
|
||||
{
|
||||
vDir = v.PhysicalDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
var doc = new XmlDocument();
|
||||
doc.Load(String.Concat(vDir, "web.config"));
|
||||
var root = doc.DocumentElement;
|
||||
var setting = doc.SelectSingleNode(String.Concat("//appSettings/add[@key='", key, "']"));
|
||||
setting.Attributes["value"].InnerText = value;
|
||||
doc.Save(String.Concat(vDir, "web.config"));
|
||||
ConfigurationManager.RefreshSection("appSettings");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full path to root.
|
||||
/// </summary>
|
||||
/// <value>The fullpath to root.</value>
|
||||
public static string FullpathToRoot
|
||||
{
|
||||
get { return HttpRuntime.AppDomainAppPath; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether umbraco is running in [debug mode].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [debug mode]; otherwise, <c>false</c>.</value>
|
||||
public static bool DebugMode
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return bool.Parse(ConfigurationManager.AppSettings["umbracoDebugMode"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current version of umbraco is configured.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if configured; otherwise, <c>false</c>.</value>
|
||||
public static bool Configured
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
string configStatus = ConfigurationStatus;
|
||||
string currentVersion = CurrentVersion;
|
||||
|
||||
|
||||
if (currentVersion != configStatus)
|
||||
{
|
||||
//Log.Add(LogTypes.Debug, User.GetUser(0), -1,
|
||||
// "CurrentVersion different from configStatus: '" + currentVersion + "','" + configStatus +
|
||||
// "'");
|
||||
}
|
||||
|
||||
|
||||
return (configStatus == currentVersion);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the time out in minutes.
|
||||
/// </summary>
|
||||
/// <value>The time out in minutes.</value>
|
||||
public static int TimeOutInMinutes
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return int.Parse(ConfigurationManager.AppSettings["umbracoTimeOutInMinutes"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether umbraco uses directory urls.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if umbraco uses directory urls; otherwise, <c>false</c>.</value>
|
||||
public static bool UseDirectoryUrls
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return bool.Parse(ConfigurationManager.AppSettings["umbracoUseDirectoryUrls"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string value to determine if umbraco should skip version-checking.
|
||||
/// </summary>
|
||||
/// <value>The version check period in days (0 = never).</value>
|
||||
public static int VersionCheckPeriod
|
||||
{
|
||||
get
|
||||
{
|
||||
int versionCheckPeriod = 7;
|
||||
if (HttpContext != null)
|
||||
{
|
||||
if (int.TryParse(ConfigurationManager.AppSettings["umbracoVersionCheckPeriod"], out versionCheckPeriod))
|
||||
return versionCheckPeriod;
|
||||
|
||||
}
|
||||
return versionCheckPeriod;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL forbitten characters.
|
||||
/// </summary>
|
||||
/// <value>The URL forbitten characters.</value>
|
||||
public static string UrlForbittenCharacters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext != null)
|
||||
return ConfigurationManager.AppSettings["umbracoUrlForbittenCharacters"];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL space character.
|
||||
/// </summary>
|
||||
/// <value>The URL space character.</value>
|
||||
public static string UrlSpaceCharacter
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext != null)
|
||||
return ConfigurationManager.AppSettings["umbracoUrlSpaceCharacter"];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the SMTP server IP-address or hostname.
|
||||
/// </summary>
|
||||
/// <value>The SMTP server.</value>
|
||||
public static string SmtpServer
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var mailSettings = ConfigurationManager.GetSection("system.net/mailSettings") as System.Net.Configuration.MailSettingsSectionGroup;
|
||||
|
||||
if (mailSettings != null)
|
||||
return mailSettings.Smtp.Network.Host;
|
||||
else
|
||||
return ConfigurationManager.AppSettings["umbracoSmtpServer"];
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string value to determine if umbraco should disbable xslt extensions
|
||||
/// </summary>
|
||||
/// <value><c>"true"</c> if version xslt extensions are disabled, otherwise, <c>"false"</c></value>
|
||||
public static string DisableXsltExtensions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext != null)
|
||||
return ConfigurationManager.AppSettings["umbracoDisableXsltExtensions"];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string value to determine if umbraco should use Xhtml editing mode in the wysiwyg editor
|
||||
/// </summary>
|
||||
/// <value><c>"true"</c> if Xhtml mode is enable, otherwise, <c>"false"</c></value>
|
||||
public static string EditXhtmlMode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext != null)
|
||||
return ConfigurationManager.AppSettings["umbracoEditXhtmlMode"];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default UI language.
|
||||
/// </summary>
|
||||
/// <value>The default UI language.</value>
|
||||
public static string DefaultUILanguage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext != null)
|
||||
return ConfigurationManager.AppSettings["umbracoDefaultUILanguage"];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the profile URL.
|
||||
/// </summary>
|
||||
/// <value>The profile URL.</value>
|
||||
public static string ProfileUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext != null)
|
||||
return ConfigurationManager.AppSettings["umbracoProfileUrl"];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether umbraco should hide top level nodes from generated urls.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if umbraco hides top level nodes from urls; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public static bool HideTopLevelNodeFromPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext != null)
|
||||
return bool.Parse(ConfigurationManager.AppSettings["umbracoHideTopLevelNodeFromPath"]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current version.
|
||||
/// </summary>
|
||||
/// <value>The current version.</value>
|
||||
public static string CurrentVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
// change this to be hardcoded in the binary
|
||||
return CurrentUmbracoVersion;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the major version number.
|
||||
/// </summary>
|
||||
/// <value>The major version number.</value>
|
||||
public static int VersionMajor
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] version = CurrentVersion.Split(".".ToCharArray());
|
||||
return int.Parse(version[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minor version number.
|
||||
/// </summary>
|
||||
/// <value>The minor version number.</value>
|
||||
public static int VersionMinor
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] version = CurrentVersion.Split(".".ToCharArray());
|
||||
return int.Parse(version[1]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the patch version number.
|
||||
/// </summary>
|
||||
/// <value>The patch version number.</value>
|
||||
public static int VersionPatch
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] version = CurrentVersion.Split(".".ToCharArray());
|
||||
return int.Parse(version[2]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version comment (like beta or RC).
|
||||
/// </summary>
|
||||
/// <value>The version comment.</value>
|
||||
public static string VersionComment
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] version = CurrentVersion.Split(".".ToCharArray());
|
||||
if (version.Length > 3)
|
||||
return version[3];
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Requests the is in umbraco application directory structure.
|
||||
/// </summary>
|
||||
/// <param name="context">The context.</param>
|
||||
/// <returns></returns>
|
||||
public static bool RequestIsInUmbracoApplication(HttpContext context)
|
||||
{
|
||||
return context.Request.Path.ToLower().IndexOf(IOHelper.ResolveUrl(SystemDirectories.Umbraco).ToLower()) > -1;
|
||||
}
|
||||
|
||||
public static bool RequestIsLiveEditRedirector(HttpContext context)
|
||||
{
|
||||
return context.Request.Path.ToLower().IndexOf(SystemDirectories.Umbraco.ToLower() + "/liveediting.aspx") > -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether umbraco should force a secure (https) connection to the backoffice.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [use SSL]; otherwise, <c>false</c>.</value>
|
||||
public static bool UseSSL
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return bool.Parse(ConfigurationManager.AppSettings["umbracoUseSSL"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the umbraco license.
|
||||
/// </summary>
|
||||
/// <value>The license.</value>
|
||||
public static string License
|
||||
{
|
||||
get
|
||||
{
|
||||
string license =
|
||||
"<A href=\"http://umbraco.org/redir/license\" target=\"_blank\">the open source license MIT</A>. The umbraco UI is freeware licensed under the umbraco license.";
|
||||
if (HttpContext != null)
|
||||
{
|
||||
var versionDoc = new XmlDocument();
|
||||
var versionReader = new XmlTextReader(IOHelper.MapPath(SystemDirectories.Umbraco + "/version.xml"));
|
||||
versionDoc.Load(versionReader);
|
||||
versionReader.Close();
|
||||
|
||||
// check for license
|
||||
try
|
||||
{
|
||||
string licenseUrl =
|
||||
versionDoc.SelectSingleNode("/version/licensing/licenseUrl").FirstChild.Value;
|
||||
string licenseValidation =
|
||||
versionDoc.SelectSingleNode("/version/licensing/licenseValidation").FirstChild.Value;
|
||||
string licensedTo =
|
||||
versionDoc.SelectSingleNode("/version/licensing/licensedTo").FirstChild.Value;
|
||||
|
||||
if (licensedTo != "" && licenseUrl != "")
|
||||
{
|
||||
license = "umbraco Commercial License<br/><b>Registered to:</b><br/>" +
|
||||
licensedTo.Replace("\n", "<br/>") + "<br/><b>For use with domain:</b><br/>" +
|
||||
licenseUrl;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return license;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Developer method to test if configuration settings are loaded properly.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if succesfull; otherwise, <c>false</c>.</value>
|
||||
internal static bool Test
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext != null)
|
||||
{
|
||||
HttpContext.Response.Write("ContentXML :" + ContentXml + "\n");
|
||||
HttpContext.Response.Write("DbDSN :" + DbDsn + "\n");
|
||||
HttpContext.Response.Write("DebugMode :" + DebugMode + "\n");
|
||||
HttpContext.Response.Write("DefaultUILanguage :" + DefaultUILanguage + "\n");
|
||||
HttpContext.Response.Write("VersionCheckPeriod :" + VersionCheckPeriod + "\n");
|
||||
HttpContext.Response.Write("DisableXsltExtensions :" + DisableXsltExtensions + "\n");
|
||||
HttpContext.Response.Write("EditXhtmlMode :" + EditXhtmlMode + "\n");
|
||||
HttpContext.Response.Write("HideTopLevelNodeFromPath :" + HideTopLevelNodeFromPath + "\n");
|
||||
HttpContext.Response.Write("Path :" + Path + "\n");
|
||||
HttpContext.Response.Write("ProfileUrl :" + ProfileUrl + "\n");
|
||||
HttpContext.Response.Write("ReservedPaths :" + ReservedPaths + "\n");
|
||||
HttpContext.Response.Write("ReservedUrls :" + ReservedUrls + "\n");
|
||||
HttpContext.Response.Write("StorageDirectory :" + StorageDirectory + "\n");
|
||||
HttpContext.Response.Write("TimeOutInMinutes :" + TimeOutInMinutes + "\n");
|
||||
HttpContext.Response.Write("UrlForbittenCharacters :" + UrlForbittenCharacters + "\n");
|
||||
HttpContext.Response.Write("UrlSpaceCharacter :" + UrlSpaceCharacter + "\n");
|
||||
HttpContext.Response.Write("UseDirectoryUrls :" + UseDirectoryUrls + "\n");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified URL is reserved or is inside a reserved path.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to check.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified URL is reserved; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public static bool IsReservedPathOrUrl(string url)
|
||||
{
|
||||
// check if GlobalSettings.ReservedPaths and GlobalSettings.ReservedUrls are unchanged
|
||||
if (!object.ReferenceEquals(_reservedPathsCache, GlobalSettings.ReservedPaths)
|
||||
|| !object.ReferenceEquals(_reservedUrlsCache, GlobalSettings.ReservedUrls))
|
||||
{
|
||||
// store references to strings to determine changes
|
||||
_reservedPathsCache = GlobalSettings.ReservedPaths;
|
||||
_reservedUrlsCache = GlobalSettings.ReservedUrls;
|
||||
|
||||
string _root = SystemDirectories.Root.Trim().ToLower();
|
||||
|
||||
// add URLs and paths to a new list
|
||||
StartsWithContainer _newReservedList = new StartsWithContainer();
|
||||
foreach (string reservedUrl in _reservedUrlsCache.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
//resolves the url to support tilde chars
|
||||
string reservedUrlTrimmed = IOHelper.ResolveUrl(reservedUrl).Trim().ToLower();
|
||||
if (reservedUrlTrimmed.Length > 0)
|
||||
_newReservedList.Add(reservedUrlTrimmed);
|
||||
}
|
||||
|
||||
foreach (string reservedPath in _reservedPathsCache.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
bool trimEnd = !reservedPath.EndsWith("/");
|
||||
//resolves the url to support tilde chars
|
||||
string reservedPathTrimmed = IOHelper.ResolveUrl(reservedPath).Trim().ToLower();
|
||||
|
||||
if (reservedPathTrimmed.Length > 0)
|
||||
_newReservedList.Add(reservedPathTrimmed + (reservedPathTrimmed.EndsWith("/") ? "" : "/"));
|
||||
}
|
||||
|
||||
// use the new list from now on
|
||||
_reservedList = _newReservedList;
|
||||
}
|
||||
|
||||
string res = "";
|
||||
foreach (string st in _reservedList._list.Keys)
|
||||
res += st + ",";
|
||||
|
||||
Debug.Write("reserverd urls: '" + res + "'");
|
||||
|
||||
// return true if url starts with an element of the reserved list
|
||||
return _reservedList.StartsWith(url.ToLower());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Structure that checks in logarithmic time
|
||||
/// if a given string starts with one of the added keys.
|
||||
/// </summary>
|
||||
private class StartsWithContainer
|
||||
{
|
||||
/// <summary>Internal sorted list of keys.</summary>
|
||||
public SortedList<string, string> _list
|
||||
= new SortedList<string, string>(StartsWithComparator.Instance);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified new key.
|
||||
/// </summary>
|
||||
/// <param name="newKey">The new key.</param>
|
||||
public void Add(string newKey)
|
||||
{
|
||||
// if the list already contains an element that begins with newKey, return
|
||||
if (String.IsNullOrEmpty(newKey) || StartsWith(newKey))
|
||||
return;
|
||||
|
||||
// create a new collection, so the old one can still be accessed
|
||||
SortedList<string, string> newList
|
||||
= new SortedList<string, string>(_list.Count + 1, StartsWithComparator.Instance);
|
||||
|
||||
// add only keys that don't already start with newKey, others are unnecessary
|
||||
foreach (string key in _list.Keys)
|
||||
if (!key.StartsWith(newKey))
|
||||
newList.Add(key, null);
|
||||
// add the new key
|
||||
newList.Add(newKey, null);
|
||||
|
||||
// update the list (thread safe, _list was never in incomplete state)
|
||||
_list = newList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the given string starts with any of the added keys.
|
||||
/// </summary>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <returns>true if a key is found that matches the start of target</returns>
|
||||
/// <remarks>
|
||||
/// Runs in O(s*log(n)), with n the number of keys and s the length of target.
|
||||
/// </remarks>
|
||||
public bool StartsWith(string target)
|
||||
{
|
||||
return _list.ContainsKey(target);
|
||||
}
|
||||
|
||||
/// <summary>Comparator that tests if a string starts with another.</summary>
|
||||
/// <remarks>Not a real comparator, since it is not reflexive. (x==y does not imply y==x)</remarks>
|
||||
private sealed class StartsWithComparator : IComparer<string>
|
||||
{
|
||||
/// <summary>Default string comparer.</summary>
|
||||
private readonly static Comparer<string> _stringComparer = Comparer<string>.Default;
|
||||
|
||||
/// <summary>Gets an instance of the StartsWithComparator.</summary>
|
||||
public static readonly StartsWithComparator Instance = new StartsWithComparator();
|
||||
|
||||
/// <summary>
|
||||
/// Tests if whole begins with all characters of part.
|
||||
/// </summary>
|
||||
/// <param name="part">The part.</param>
|
||||
/// <param name="whole">The whole.</param>
|
||||
/// <returns>
|
||||
/// Returns 0 if whole starts with part, otherwise performs standard string comparison.
|
||||
/// </returns>
|
||||
public int Compare(string part, string whole)
|
||||
{
|
||||
// let the default string comparer deal with null or when part is not smaller then whole
|
||||
if (part == null || whole == null)
|
||||
return _stringComparer.Compare(part, whole);
|
||||
|
||||
//trim the end '/' of each
|
||||
part = part.TrimEnd('/');
|
||||
whole = whole.TrimEnd('/');
|
||||
if (part.Length >= whole.Length)
|
||||
return _stringComparer.Compare(part, whole);
|
||||
|
||||
// loop through all characters that part and whole have in common
|
||||
int pos = 0;
|
||||
bool match;
|
||||
do
|
||||
{
|
||||
match = (part[pos] == whole[pos]);
|
||||
} while (match && ++pos < part.Length);
|
||||
|
||||
// return result of last comparison
|
||||
return match ? 0 : (part[pos] < whole[pos] ? -1 : 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
1303
src/Umbraco.Core/Configuration/UmbracoSettings.cs
Normal file
1303
src/Umbraco.Core/Configuration/UmbracoSettings.cs
Normal file
File diff suppressed because it is too large
Load Diff
20
src/Umbraco.Core/IO/FileSecurityException.cs
Normal file
20
src/Umbraco.Core/IO/FileSecurityException.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
public class FileSecurityException : Exception
|
||||
{
|
||||
public FileSecurityException()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public FileSecurityException(string message) : base(message)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
206
src/Umbraco.Core/IO/IOHelper.cs
Normal file
206
src/Umbraco.Core/IO/IOHelper.cs
Normal file
@@ -0,0 +1,206 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
internal static class IOHelper
|
||||
{
|
||||
private static string _rootDir = "";
|
||||
// static compiled regex for faster performance
|
||||
private readonly static Regex ResolveUrlPattern = new Regex("(=[\"\']?)(\\W?\\~(?:.(?![\"\']?\\s+(?:\\S+)=|[>\"\']))+.)[\"\']?", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
public static char DirSepChar
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
|
||||
//helper to try and match the old path to a new virtual one
|
||||
public static string FindFile(string virtualPath)
|
||||
{
|
||||
string retval = virtualPath;
|
||||
|
||||
if (virtualPath.StartsWith("~"))
|
||||
retval = virtualPath.Replace("~", SystemDirectories.Root);
|
||||
|
||||
if (virtualPath.StartsWith("/") && !virtualPath.StartsWith(SystemDirectories.Root))
|
||||
retval = SystemDirectories.Root + "/" + virtualPath.TrimStart('/');
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
//Replaces tildes with the root dir
|
||||
public static string ResolveUrl(string virtualPath)
|
||||
{
|
||||
if (virtualPath.StartsWith("~"))
|
||||
return virtualPath.Replace("~", SystemDirectories.Root).Replace("//", "/");
|
||||
else
|
||||
return VirtualPathUtility.ToAbsolute(virtualPath, SystemDirectories.Root);
|
||||
}
|
||||
|
||||
|
||||
public static string ResolveUrlsFromTextString(string text)
|
||||
{
|
||||
if (UmbracoSettings.ResolveUrlsFromTextString)
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
Debug.WriteLine("Start: " + sw.ElapsedMilliseconds);
|
||||
|
||||
// find all relative urls (ie. urls that contain ~)
|
||||
var tags =
|
||||
ResolveUrlPattern.Matches(text);
|
||||
Debug.WriteLine("After regex: " + sw.ElapsedMilliseconds);
|
||||
foreach (Match tag in tags)
|
||||
{
|
||||
Debug.WriteLine("-- inside regex: " + sw.ElapsedMilliseconds);
|
||||
string url = "";
|
||||
if (tag.Groups[1].Success)
|
||||
url = tag.Groups[1].Value;
|
||||
|
||||
// The richtext editor inserts a slash in front of the url. That's why we need this little fix
|
||||
// if (url.StartsWith("/"))
|
||||
// text = text.Replace(url, ResolveUrl(url.Substring(1)));
|
||||
// else
|
||||
if (!String.IsNullOrEmpty(url))
|
||||
{
|
||||
Debug.WriteLine("---- before resolve: " + sw.ElapsedMilliseconds);
|
||||
string resolvedUrl = (url.Substring(0, 1) == "/") ? ResolveUrl(url.Substring(1)) : ResolveUrl(url);
|
||||
Debug.WriteLine("---- after resolve: " + sw.ElapsedMilliseconds);
|
||||
Debug.WriteLine("---- before replace: " + sw.ElapsedMilliseconds);
|
||||
text = text.Replace(url, resolvedUrl);
|
||||
Debug.WriteLine("---- after replace: " + sw.ElapsedMilliseconds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Debug.WriteLine("total: " + sw.ElapsedMilliseconds);
|
||||
sw.Stop();
|
||||
Debug.WriteLine("Resolve Urls", sw.ElapsedMilliseconds.ToString());
|
||||
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public static string MapPath(string path, bool useHttpContext)
|
||||
{
|
||||
// Check if the path is already mapped
|
||||
if (path.Length >= 2 && path[1] == Path.VolumeSeparatorChar)
|
||||
return path;
|
||||
|
||||
// Check that we even have an HttpContext! otherwise things will fail anyways
|
||||
// http://umbraco.codeplex.com/workitem/30946
|
||||
|
||||
if (useHttpContext && HttpContext.Current != null)
|
||||
{
|
||||
//string retval;
|
||||
if (!string.IsNullOrEmpty(path) && (path.StartsWith("~") || path.StartsWith(SystemDirectories.Root)))
|
||||
return System.Web.Hosting.HostingEnvironment.MapPath(path);
|
||||
else
|
||||
return System.Web.Hosting.HostingEnvironment.MapPath("~/" + path.TrimStart('/'));
|
||||
}
|
||||
|
||||
//var root = (!string.IsNullOrEmpty(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath))
|
||||
// ? System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath.TrimEnd(IOHelper.DirSepChar)
|
||||
// : getRootDirectorySafe();
|
||||
|
||||
var root = GetRootDirectorySafe();
|
||||
var newPath = path.TrimStart('~', '/').Replace('/', IOHelper.DirSepChar);
|
||||
var retval = root + IOHelper.DirSepChar.ToString() + newPath;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public static string MapPath(string path)
|
||||
{
|
||||
return MapPath(path, true);
|
||||
}
|
||||
|
||||
//use a tilde character instead of the complete path
|
||||
public static string ReturnPath(string settingsKey, string standardPath, bool useTilde)
|
||||
{
|
||||
string retval = ConfigurationManager.AppSettings[settingsKey];
|
||||
|
||||
if (string.IsNullOrEmpty(retval))
|
||||
retval = standardPath;
|
||||
|
||||
return retval.TrimEnd('/');
|
||||
}
|
||||
|
||||
|
||||
public static string ReturnPath(string settingsKey, string standardPath)
|
||||
{
|
||||
return ReturnPath(settingsKey, standardPath, false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Validates if the current filepath matches a directory where the user is allowed to edit a file
|
||||
/// </summary>
|
||||
/// <param name="filePath">filepath </param>
|
||||
/// <param name="validDir"></param>
|
||||
/// <returns>true if valid, throws a FileSecurityException if not</returns>
|
||||
public static bool ValidateEditPath(string filePath, string validDir)
|
||||
{
|
||||
if (!filePath.StartsWith(MapPath(SystemDirectories.Root)))
|
||||
filePath = MapPath(filePath);
|
||||
if (!validDir.StartsWith(MapPath(SystemDirectories.Root)))
|
||||
validDir = MapPath(validDir);
|
||||
|
||||
if (!filePath.StartsWith(validDir))
|
||||
throw new FileSecurityException(String.Format("The filepath '{0}' is not within an allowed directory for this type of files", filePath.Replace(MapPath(SystemDirectories.Root), "")));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ValidateFileExtension(string filePath, List<string> validFileExtensions)
|
||||
{
|
||||
if (!filePath.StartsWith(MapPath(SystemDirectories.Root)))
|
||||
filePath = MapPath(filePath);
|
||||
var f = new FileInfo(filePath);
|
||||
|
||||
|
||||
if (!validFileExtensions.Contains(f.Extension.Substring(1)))
|
||||
throw new FileSecurityException(String.Format("The extension for the current file '{0}' is not of an allowed type for this editor. This is typically controlled from either the installed MacroEngines or based on configuration in /config/umbracoSettings.config", filePath.Replace(MapPath(SystemDirectories.Root), "")));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the path to the root of the application, by getting the path to where the assembly where this
|
||||
/// method is included is present, then traversing until it's past the /bin directory. Ie. this makes it work
|
||||
/// even if the assembly is in a /bin/debug or /bin/release folder
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static string GetRootDirectorySafe()
|
||||
{
|
||||
if (!String.IsNullOrEmpty(_rootDir))
|
||||
{
|
||||
return _rootDir;
|
||||
}
|
||||
|
||||
var codeBase = Assembly.GetExecutingAssembly().CodeBase;
|
||||
var uri = new Uri(codeBase);
|
||||
var path = uri.LocalPath;
|
||||
var baseDirectory = Path.GetDirectoryName(path);
|
||||
_rootDir = baseDirectory.Substring(0, baseDirectory.LastIndexOf("bin") - 1);
|
||||
|
||||
return _rootDir;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,11 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using umbraco;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
public static class IMediaFileSystemExtensions
|
||||
public static class MediaFileSystemExtensions
|
||||
{
|
||||
internal static string GetRelativePath(this IMediaFileSystem fs, int propertyId, string fileName)
|
||||
{
|
||||
181
src/Umbraco.Core/IO/SystemDirectories.cs
Normal file
181
src/Umbraco.Core/IO/SystemDirectories.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Configuration;
|
||||
|
||||
using System.Web;
|
||||
using System.IO;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
//all paths has a starting but no trailing /
|
||||
internal class SystemDirectories
|
||||
{
|
||||
public static string Bin
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoBinDirectory", "~/bin");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Base
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoBaseDirectory", "~/base");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Config
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoConfigDirectory", "~/config");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Css
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoCssDirectory", "~/css");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoStorageDirectory", "~/App_Data");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Install
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoInstallPath", "~/install");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Masterpages
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoMasterPagesPath", "~/masterpages");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static string Media
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoMediaPath", "~/media");
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Please use MacroScripts instead!", true)]
|
||||
public static string Python
|
||||
{
|
||||
get
|
||||
{
|
||||
return MacroScripts;
|
||||
}
|
||||
}
|
||||
|
||||
public static string MacroScripts
|
||||
{
|
||||
get
|
||||
{
|
||||
// for legacy we test for the python path first, but else we use the new default location
|
||||
string tempPath = IOHelper.ReturnPath("umbracoPythonPath", "") == String.Empty
|
||||
? IOHelper.ReturnPath("umbracoMacroScriptPath", "~/macroScripts")
|
||||
: IOHelper.ReturnPath("umbracoPythonPath", "~/python");
|
||||
return tempPath;
|
||||
}
|
||||
}
|
||||
|
||||
public static string Scripts
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoScriptsPath", "~/scripts");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Umbraco
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoPath", "~/umbraco");
|
||||
}
|
||||
}
|
||||
|
||||
public static string UmbracoClient
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoClientPath", "~/umbraco_client");
|
||||
}
|
||||
}
|
||||
|
||||
public static string UserControls
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoUsercontrolsPath", "~/usercontrols");
|
||||
}
|
||||
}
|
||||
|
||||
public static string WebServices
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOHelper.ReturnPath("umbracoWebservicesPath", "~/umbraco/webservices");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Xslt
|
||||
{
|
||||
get {
|
||||
return IOHelper.ReturnPath("umbracoXsltPath", "~/xslt");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Packages
|
||||
{
|
||||
get
|
||||
{
|
||||
//by default the packages folder should exist in the data folder
|
||||
return IOHelper.ReturnPath("umbracoPackagesPath", Data + IOHelper.DirSepChar + "packages");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Preview
|
||||
{
|
||||
get
|
||||
{
|
||||
//by default the packages folder should exist in the data folder
|
||||
return IOHelper.ReturnPath("umbracoPreviewPath", Data + IOHelper.DirSepChar + "preview");
|
||||
}
|
||||
}
|
||||
|
||||
public static string Root
|
||||
{
|
||||
get
|
||||
{
|
||||
string appPath = HttpRuntime.AppDomainAppVirtualPath ?? string.Empty;
|
||||
if (appPath == "/")
|
||||
appPath = string.Empty;
|
||||
|
||||
return appPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
122
src/Umbraco.Core/IO/SystemFiles.cs
Normal file
122
src/Umbraco.Core/IO/SystemFiles.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
internal class SystemFiles
|
||||
{
|
||||
|
||||
public static string AccessXml
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemDirectories.Data + "/access.config";
|
||||
}
|
||||
}
|
||||
|
||||
public static string CreateUiXml
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemDirectories.Umbraco + "/config/create/UI.xml";
|
||||
}
|
||||
}
|
||||
|
||||
public static string TinyMceConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemDirectories.Config + "/tinyMceConfig.config";
|
||||
}
|
||||
}
|
||||
|
||||
public static string MetablogConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemDirectories.Config + "/metablogConfig.config";
|
||||
}
|
||||
}
|
||||
|
||||
public static string DashboardConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemDirectories.Config + "/dashboard.config";
|
||||
}
|
||||
}
|
||||
|
||||
public static string XsltextensionsConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemDirectories.Config + "/xsltextensions.config";
|
||||
}
|
||||
}
|
||||
|
||||
public static string RestextensionsConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemDirectories.Config + "/restextensions.config";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static string SkinningXml
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemDirectories.Data + "/skinning.config";
|
||||
}
|
||||
}
|
||||
|
||||
public static string NotFoundhandlersConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemDirectories.Config + "/404handlers.config";
|
||||
}
|
||||
}
|
||||
|
||||
public static string FeedProxyConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Concat(SystemDirectories.Config, "/feedProxy.config");
|
||||
}
|
||||
}
|
||||
|
||||
public static string ContentCacheXml
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ContentCacheXmlIsEphemeral)
|
||||
{
|
||||
return Path.Combine(HttpRuntime.CodegenDir, @"UmbracoData\umbraco.config");
|
||||
}
|
||||
return IOHelper.ReturnPath("umbracoContentXML", "~/App_Data/umbraco.config");
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ContentCacheXmlIsEphemeral
|
||||
{
|
||||
get
|
||||
{
|
||||
bool returnValue = false;
|
||||
string configSetting = ConfigurationManager.AppSettings["umbracoContentXMLUseLocalTemp"];
|
||||
|
||||
if (!string.IsNullOrEmpty(configSetting))
|
||||
if(bool.TryParse(configSetting, out returnValue))
|
||||
return returnValue;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/Umbraco.Core/RazorDataTypeModelStaticMappingItem.cs
Normal file
31
src/Umbraco.Core/RazorDataTypeModelStaticMappingItem.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
//NOTE: I'm not sure what this does or what it is used for, have emailed Gareth about it as the name really means nothing to me
|
||||
// and don't know where this class actually belongs.
|
||||
|
||||
internal class RazorDataTypeModelStaticMappingItem
|
||||
{
|
||||
public string Raw { get; set; }
|
||||
//if all of the set (non null) properties match the property data currently being evaluated
|
||||
public string PropertyTypeAlias { get; set; }
|
||||
public string NodeTypeAlias { get; set; }
|
||||
public Guid? DataTypeGuid { get; set; }
|
||||
public string TypeName { get; set; }
|
||||
|
||||
public bool Applies(Guid dataTypeGuid, string nodeTypeAlias, string propertyTypeAlias)
|
||||
{
|
||||
return
|
||||
(
|
||||
(this.NodeTypeAlias != null || this.PropertyTypeAlias != null || this.DataTypeGuid != null) &&
|
||||
((this.DataTypeGuid != null && this.DataTypeGuid == dataTypeGuid) || this.DataTypeGuid == null) &&
|
||||
((this.PropertyTypeAlias != null && this.PropertyTypeAlias == propertyTypeAlias) || this.PropertyTypeAlias == null) &&
|
||||
((this.NodeTypeAlias != null && this.NodeTypeAlias == nodeTypeAlias) || this.NodeTypeAlias == null)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/Umbraco.Core/SystemUtilities.cs
Normal file
40
src/Umbraco.Core/SystemUtilities.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Security;
|
||||
using System.Web;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Static helper methods for returning information about the current System
|
||||
/// </summary>
|
||||
public static class SystemUtilities
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Get the current trust level of the hosted application
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static AspNetHostingPermissionLevel GetCurrentTrustLevel()
|
||||
{
|
||||
foreach (var trustLevel in new[] {
|
||||
AspNetHostingPermissionLevel.Unrestricted,
|
||||
AspNetHostingPermissionLevel.High,
|
||||
AspNetHostingPermissionLevel.Medium,
|
||||
AspNetHostingPermissionLevel.Low,
|
||||
AspNetHostingPermissionLevel.Minimal })
|
||||
{
|
||||
try
|
||||
{
|
||||
new AspNetHostingPermission(trustLevel).Demand();
|
||||
}
|
||||
catch (SecurityException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return trustLevel;
|
||||
}
|
||||
|
||||
return AspNetHostingPermissionLevel.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,31 +48,34 @@
|
||||
<Compile Include="Configuration\FileSystemProviderElement.cs" />
|
||||
<Compile Include="Configuration\FileSystemProviderElementCollection.cs" />
|
||||
<Compile Include="Configuration\FileSystemProvidersSection.cs" />
|
||||
<Compile Include="Configuration\GlobalSettings.cs" />
|
||||
<Compile Include="Configuration\UmbracoSettings.cs" />
|
||||
<Compile Include="DelegateEqualityComparer.cs" />
|
||||
<Compile Include="DynamicWrapper.cs" />
|
||||
<Compile Include="EnumerableExtensions.cs" />
|
||||
<Compile Include="IfExtensions.cs" />
|
||||
<Compile Include="IO\FileSecurityException.cs" />
|
||||
<Compile Include="IO\FileSystemProvider.cs" />
|
||||
<Compile Include="IO\FileSystemProviderAttribute.cs" />
|
||||
<Compile Include="IO\FileSystemProviderManager.cs" />
|
||||
<Compile Include="IO\IFileSystem.cs" />
|
||||
<Compile Include="IO\IFileSystemExtensions.cs" />
|
||||
<Compile Include="IO\IMediaFileSystem.cs" />
|
||||
<Compile Include="IO\IMediaFileSystemExtensions.cs" />
|
||||
<Compile Include="IO\IOHelper.cs" />
|
||||
<Compile Include="IO\MediaFileSystemExtensions.cs" />
|
||||
<Compile Include="IO\PhysicalFileSystem.cs" />
|
||||
<Compile Include="IO\SystemDirectories.cs" />
|
||||
<Compile Include="IO\SystemFiles.cs" />
|
||||
<Compile Include="IThumbnailProvider.cs" />
|
||||
<Compile Include="ObjectExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RazorDataTypeModelStaticMappingItem.cs" />
|
||||
<Compile Include="StringAliasCaseType.cs" />
|
||||
<Compile Include="StringExtensions.cs" />
|
||||
<Compile Include="SystemUtilities.cs" />
|
||||
<Compile Include="TypeExtensions.cs" />
|
||||
<Compile Include="WriteLock.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\umbraco.businesslogic\umbraco.businesslogic.csproj">
|
||||
<Project>{E469A9CE-1BEC-423F-AC44-713CD72457EA}</Project>
|
||||
<Name>umbraco.businesslogic</Name>
|
||||
</ProjectReference>
|
||||
<Compile Include="XmlHelper.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
168
src/Umbraco.Core/XmlHelper.cs
Normal file
168
src/Umbraco.Core/XmlHelper.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// The XmlHelper class contains general helper methods for working with xml in umbraco.
|
||||
/// </summary>
|
||||
internal class XmlHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Imports a XML node from text.
|
||||
/// </summary>
|
||||
/// <param name="text">The text.</param>
|
||||
/// <param name="xmlDoc">The XML doc.</param>
|
||||
/// <returns></returns>
|
||||
public static XmlNode ImportXmlNodeFromText(string text, ref XmlDocument xmlDoc)
|
||||
{
|
||||
xmlDoc.LoadXml(text);
|
||||
return xmlDoc.FirstChild;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a file as a XmlDocument.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The relative file path. ei. /config/umbraco.config</param>
|
||||
/// <returns>Returns a XmlDocument class</returns>
|
||||
public static XmlDocument OpenAsXmlDocument(string filePath)
|
||||
{
|
||||
|
||||
var reader = new XmlTextReader(IOHelper.MapPath(filePath)) {WhitespaceHandling = WhitespaceHandling.All};
|
||||
|
||||
var xmlDoc = new XmlDocument();
|
||||
//Load the file into the XmlDocument
|
||||
xmlDoc.Load(reader);
|
||||
//Close off the connection to the file.
|
||||
reader.Close();
|
||||
|
||||
return xmlDoc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// creates a XmlAttribute with the specified name and value
|
||||
/// </summary>
|
||||
/// <param name="xd">The xmldocument.</param>
|
||||
/// <param name="name">The name of the attribute.</param>
|
||||
/// <param name="value">The value of the attribute.</param>
|
||||
/// <returns>a XmlAttribute</returns>
|
||||
public static XmlAttribute AddAttribute(XmlDocument xd, string name, string value)
|
||||
{
|
||||
var temp = xd.CreateAttribute(name);
|
||||
temp.Value = value;
|
||||
return temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a text XmlNode with the specified name and value
|
||||
/// </summary>
|
||||
/// <param name="xd">The xmldocument.</param>
|
||||
/// <param name="name">The node name.</param>
|
||||
/// <param name="value">The node value.</param>
|
||||
/// <returns>a XmlNode</returns>
|
||||
public static XmlNode AddTextNode(XmlDocument xd, string name, string value)
|
||||
{
|
||||
var temp = xd.CreateNode(XmlNodeType.Element, name, "");
|
||||
temp.AppendChild(xd.CreateTextNode(value));
|
||||
return temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a cdata XmlNode with the specified name and value
|
||||
/// </summary>
|
||||
/// <param name="xd">The xmldocument.</param>
|
||||
/// <param name="name">The node name.</param>
|
||||
/// <param name="value">The node value.</param>
|
||||
/// <returns>A XmlNode</returns>
|
||||
public static XmlNode AddCDataNode(XmlDocument xd, string name, string value)
|
||||
{
|
||||
var temp = xd.CreateNode(XmlNodeType.Element, name, "");
|
||||
temp.AppendChild(xd.CreateCDataSection(value));
|
||||
return temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of a XmlNode
|
||||
/// </summary>
|
||||
/// <param name="n">The XmlNode.</param>
|
||||
/// <returns>the value as a string</returns>
|
||||
public static string GetNodeValue(XmlNode n)
|
||||
{
|
||||
var value = string.Empty;
|
||||
if (n == null || n.FirstChild == null)
|
||||
return value;
|
||||
value = n.FirstChild.Value ?? n.InnerXml;
|
||||
return value.Replace("<!--CDATAOPENTAG-->", "<![CDATA[").Replace("<!--CDATACLOSETAG-->", "]]>");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified string appears to be XML.
|
||||
/// </summary>
|
||||
/// <param name="xml">The XML string.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified string appears to be XML; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public static bool CouldItBeXml(string xml)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(xml))
|
||||
{
|
||||
xml = xml.Trim();
|
||||
|
||||
if (xml.StartsWith("<") && xml.EndsWith(">"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Splits the specified delimited string into an XML document.
|
||||
/// </summary>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <param name="separator">The separator.</param>
|
||||
/// <param name="rootName">Name of the root.</param>
|
||||
/// <param name="elementName">Name of the element.</param>
|
||||
/// <returns>Returns an <c>System.Xml.XmlDocument</c> representation of the delimited string data.</returns>
|
||||
public static XmlDocument Split(string data, string[] separator, string rootName, string elementName)
|
||||
{
|
||||
return Split(new XmlDocument(), data, separator, rootName, elementName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Splits the specified delimited string into an XML document.
|
||||
/// </summary>
|
||||
/// <param name="xml">The XML document.</param>
|
||||
/// <param name="data">The delimited string data.</param>
|
||||
/// <param name="separator">The separator.</param>
|
||||
/// <param name="rootName">Name of the root node.</param>
|
||||
/// <param name="elementName">Name of the element node.</param>
|
||||
/// <returns>Returns an <c>System.Xml.XmlDocument</c> representation of the delimited string data.</returns>
|
||||
public static XmlDocument Split(XmlDocument xml, string data, string[] separator, string rootName, string elementName)
|
||||
{
|
||||
// load new XML document.
|
||||
xml.LoadXml(string.Concat("<", rootName, "/>"));
|
||||
|
||||
// get the data-value, check it isn't empty.
|
||||
if (!string.IsNullOrEmpty(data))
|
||||
{
|
||||
// explode the values into an array
|
||||
var values = data.Split(separator, StringSplitOptions.None);
|
||||
|
||||
// loop through the array items.
|
||||
foreach (string value in values)
|
||||
{
|
||||
// add each value to the XML document.
|
||||
var xn = XmlHelper.AddTextNode(xml, elementName, value);
|
||||
xml.DocumentElement.AppendChild(xn);
|
||||
}
|
||||
}
|
||||
|
||||
// return the XML node.
|
||||
return xml;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user