FeedProxy: Introduced a config file to define the allowed hostnames. Also added a package action to allow hostnames.
This commit is contained in:
9
config templates/config/feedProxy.config
Normal file
9
config templates/config/feedProxy.config
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<feedProxy>
|
||||
<!-- To enable the FeedProxy to access other domains, please add the hostname to an 'allow' element. -->
|
||||
<!-- <allow host="domain.com" /> -->
|
||||
|
||||
<!-- The following hostnames are used by on the dashboards, please do not delete these. -->
|
||||
<allow host="umbraco.com" />
|
||||
<allow host="umbraco.org" />
|
||||
</feedProxy>
|
||||
@@ -38,6 +38,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{05329D
|
||||
config templates\config\Dashboard.config = config templates\config\Dashboard.config
|
||||
config templates\config\ExamineIndex.config = config templates\config\ExamineIndex.config
|
||||
config templates\config\ExamineSettings.config = config templates\config\ExamineSettings.config
|
||||
config templates\config\feedProxy.config = config templates\config\feedProxy.config
|
||||
config templates\config\formHandlers.config = config templates\config\formHandlers.config
|
||||
config templates\config\metablogConfig.config = config templates\config\metablogConfig.config
|
||||
config templates\config\restExtensions.config = config templates\config\restExtensions.config
|
||||
|
||||
@@ -84,6 +84,14 @@ namespace umbraco.IO
|
||||
}
|
||||
}
|
||||
|
||||
public static string FeedProxyConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Concat(SystemDirectories.Config, "/feedProxy.config");
|
||||
}
|
||||
}
|
||||
|
||||
public static string ContentCacheXml
|
||||
{
|
||||
get
|
||||
|
||||
@@ -520,6 +520,98 @@ namespace umbraco.cms.businesslogic.packager.standardPackageActions
|
||||
|
||||
}
|
||||
|
||||
public class addProxyFeedHost : umbraco.interfaces.IPackageAction
|
||||
{
|
||||
#region IPackageAction Members
|
||||
|
||||
public bool Execute(string packageName, XmlNode xmlData)
|
||||
{
|
||||
var hostname = xmlData.Attributes["host"].Value;
|
||||
if (string.IsNullOrEmpty(hostname))
|
||||
return false;
|
||||
|
||||
var xdoc = xmlHelper.OpenAsXmlDocument(SystemFiles.FeedProxyConfig);
|
||||
|
||||
xdoc.PreserveWhitespace = true;
|
||||
|
||||
var xn = xdoc.SelectSingleNode("//feedProxy");
|
||||
if (xn != null)
|
||||
{
|
||||
var insert = true;
|
||||
|
||||
if (xn.HasChildNodes)
|
||||
{
|
||||
foreach (XmlNode node in xn.SelectNodes("//allow"))
|
||||
{
|
||||
if (node.Attributes["host"] != null && node.Attributes["host"].Value == hostname)
|
||||
insert = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (insert)
|
||||
{
|
||||
var newHostname = xmlHelper.addTextNode(xdoc, "allow", string.Empty);
|
||||
newHostname.Attributes.Append(xmlHelper.addAttribute(xdoc, "host", hostname));
|
||||
xn.AppendChild(newHostname);
|
||||
|
||||
xdoc.Save(IOHelper.MapPath(SystemFiles.FeedProxyConfig));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public string Alias()
|
||||
{
|
||||
return "addProxyFeedHost";
|
||||
}
|
||||
|
||||
public bool Undo(string packageName, XmlNode xmlData)
|
||||
{
|
||||
var hostname = xmlData.Attributes["host"].Value;
|
||||
if (string.IsNullOrEmpty(hostname))
|
||||
return false;
|
||||
|
||||
var xdoc = xmlHelper.OpenAsXmlDocument(SystemFiles.FeedProxyConfig);
|
||||
xdoc.PreserveWhitespace = true;
|
||||
|
||||
var xn = xdoc.SelectSingleNode("//feedProxy");
|
||||
if (xn != null)
|
||||
{
|
||||
bool inserted = false;
|
||||
if (xn.HasChildNodes)
|
||||
{
|
||||
foreach (XmlNode node in xn.SelectNodes("//allow"))
|
||||
{
|
||||
if (node.Attributes["host"] != null && node.Attributes["host"].Value == hostname)
|
||||
{
|
||||
xn.RemoveChild(node);
|
||||
inserted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inserted)
|
||||
{
|
||||
xdoc.Save(IOHelper.MapPath(SystemFiles.FeedProxyConfig));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public XmlNode SampleXml()
|
||||
{
|
||||
string sample = "<Action runat=\"install\" undo=\"true\" alias=\"addProxyFeedHost\" host=\"umbraco.com\"/>";
|
||||
return helper.parseStringToXmlNode(sample);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class implements the IPackageAction Interface, used to execute code when packages are installed.
|
||||
/// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode.
|
||||
|
||||
9
umbraco/presentation/config/feedProxy.config
Normal file
9
umbraco/presentation/config/feedProxy.config
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<feedProxy>
|
||||
<!-- To enable the FeedProxy to access other domains, please add the hostname to an 'allow' element. -->
|
||||
<!-- <allow host="domain.com" /> -->
|
||||
|
||||
<!-- The following hostnames are used by on the dashboards, please do not delete these. -->
|
||||
<allow host="umbraco.com" />
|
||||
<allow host="umbraco.org" />
|
||||
</feedProxy>
|
||||
@@ -2572,6 +2572,7 @@
|
||||
<Content Include="config\ExamineIndex.config" />
|
||||
<Content Include="config\scripting.config" />
|
||||
<Content Include="config\Skinning.config" />
|
||||
<Content Include="config\feedProxy.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings1.Designer.cs</LastGenOutput>
|
||||
|
||||
@@ -1,37 +1,53 @@
|
||||
namespace dashboardUtilities
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.Net.Mime;
|
||||
using System.Xml;
|
||||
using umbraco.BasePages;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.IO;
|
||||
using umbraco;
|
||||
|
||||
public partial class FeedProxy : UmbracoEnsuredPage
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (Request["url"] != null)
|
||||
try
|
||||
{
|
||||
var requestUri = new Uri(Request["url"]);
|
||||
if (requestUri != null)
|
||||
if (Request.QueryString.AllKeys.Contains("url") && Request.QueryString["url"] != null)
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
|
||||
request.Method = WebRequestMethods.Http.Get;
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
StreamReader reader = new StreamReader(response.GetResponseStream());
|
||||
string tmp = reader.ReadToEnd();
|
||||
response.Close();
|
||||
var url = Request.QueryString["url"];
|
||||
if (!string.IsNullOrWhiteSpace(url) && !url.StartsWith("/"))
|
||||
{
|
||||
Uri requestUri;
|
||||
if (Uri.TryCreate(url, UriKind.Absolute, out requestUri))
|
||||
{
|
||||
var feedProxyXml = xmlHelper.OpenAsXmlDocument(IOHelper.MapPath(SystemFiles.FeedProxyConfig));
|
||||
if (feedProxyXml != null && feedProxyXml.SelectSingleNode(string.Concat("//access[@host = '", requestUri.Host, "']")) == null)
|
||||
{
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
var response = client.DownloadString(requestUri);
|
||||
|
||||
Response.Clear();
|
||||
Response.ContentType = "text/xml";
|
||||
|
||||
Response.Write(tmp);
|
||||
if (!string.IsNullOrEmpty(response))
|
||||
{
|
||||
Response.Clear();
|
||||
Response.ContentType = Request.QueryString["type"] ?? MediaTypeNames.Text.Xml;
|
||||
Response.Write(response);
|
||||
Response.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Add(LogTypes.Error, -1, ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user