From ba098f49c4e9f0b236e712ffad3b3b5ab9093f86 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Thu, 24 Jan 2019 13:59:17 +0000 Subject: [PATCH] =?UTF-8?q?=E2=98=A0=EF=B8=8F=E2=98=A0=EF=B8=8F=20Bye=20by?= =?UTF-8?q?e=20feedproxy.config=20=E2=98=A0=EF=B8=8F=E2=98=A0=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Umbraco.Core/IO/SystemFiles.cs | 4 +- .../common/resources/dashboard.resource.js | 18 +++-- .../src/common/services/help.service.js | 21 +++--- .../dashboard/dashboard.tabs.controller.js | 18 +++-- .../members/membersdashboardvideos.html | 6 +- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 5 -- .../Umbraco/dashboard/FeedProxy.aspx | 2 - .../config/feedProxy.Release.config | 12 --- src/Umbraco.Web.UI/config/feedProxy.config | 12 --- .../Editors/DashboardController.cs | 73 ++++++++++++++++++- src/Umbraco.Web/Umbraco.Web.csproj | 8 -- .../umbraco/dashboard/FeedProxy.aspx | 2 - .../umbraco/dashboard/FeedProxy.aspx.cs | 65 ----------------- .../dashboard/FeedProxy.aspx.designer.cs | 15 ---- 14 files changed, 111 insertions(+), 150 deletions(-) delete mode 100644 src/Umbraco.Web.UI/Umbraco/dashboard/FeedProxy.aspx delete mode 100644 src/Umbraco.Web.UI/config/feedProxy.Release.config delete mode 100644 src/Umbraco.Web.UI/config/feedProxy.config delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx.cs delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx.designer.cs diff --git a/src/Umbraco.Core/IO/SystemFiles.cs b/src/Umbraco.Core/IO/SystemFiles.cs index 511c39c98b..7d0b31b578 100644 --- a/src/Umbraco.Core/IO/SystemFiles.cs +++ b/src/Umbraco.Core/IO/SystemFiles.cs @@ -12,9 +12,7 @@ namespace Umbraco.Core.IO public static string TinyMceConfig => SystemDirectories.Config + "/tinyMceConfig.config"; public static string NotFoundhandlersConfig => SystemDirectories.Config + "/404handlers.config"; - - public static string FeedProxyConfig => string.Concat(SystemDirectories.Config, "/feedProxy.config"); - + public static string GetContentCacheXml(IGlobalSettings globalSettings) { switch (globalSettings.LocalTempStorageLocation) diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/dashboard.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/dashboard.resource.js index c48b2dd2a7..1459822c96 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/dashboard.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/dashboard.resource.js @@ -14,7 +14,7 @@ function dashboardResource($q, $http, umbRequestHelper) { * * @description * Retrieves the dashboard configuration for a given section - * + * * @param {string} section Alias of section to retrieve dashboard configuraton for * @returns {Promise} resourcePromise object containing the user array. * @@ -36,7 +36,7 @@ function dashboardResource($q, $http, umbRequestHelper) { * * @description * Retrieves dashboard content from a remote source for a given section - * + * * @param {string} section Alias of section to retrieve dashboard content for * @returns {Promise} resourcePromise object containing the user array. * @@ -70,10 +70,18 @@ function dashboardResource($q, $http, umbRequestHelper) { "dashboardApiBaseUrl", "GetRemoteDashboardCss", values); + }, + + getRemoteXmlData: function (site, url) { + //build request values with optional params + var values = { site: site, url: url }; + return umbRequestHelper.resourcePromise( + $http.get( + umbRequestHelper.getApiUrl( + "dashboardApiBaseUrl", + "GetRemoteXml", + values)), "Failed to get remote xml"); } - - - }; } diff --git a/src/Umbraco.Web.UI.Client/src/common/services/help.service.js b/src/Umbraco.Web.UI.Client/src/common/services/help.service.js index ff8d487bb7..cd727ac32b 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/help.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/help.service.js @@ -1,9 +1,9 @@ angular.module('umbraco.services') - .factory('helpService', function ($http, $q, umbRequestHelper) { + .factory('helpService', function ($http, $q, umbRequestHelper, dashboardResource) { var helpTopics = {}; - var defaultUrl = "https://our.umbraco.com/rss/help"; - var tvUrl = "https://umbraco.tv/feeds/help"; + var defaultUrl = "rss/help"; + var tvUrl = "feeds/help"; function getCachedHelp(url){ if(helpTopics[url]){ @@ -17,16 +17,14 @@ angular.module('umbraco.services') helpTopics[url] = data; } - function fetchUrl(url){ + function fetchUrl(site, url){ var deferred = $q.defer(); var found = getCachedHelp(url); if(found){ deferred.resolve(found); }else{ - - var proxyUrl = "dashboard/feedproxy.aspx?url=" + url; - $http.get(proxyUrl).then(function(data){ + dashboardResource.getRemoteXmlData(site, url).then(function (data) { var feed = $(data.data); var topics = []; @@ -41,7 +39,12 @@ angular.module('umbraco.services') setCachedHelp(topics); deferred.resolve(topics); + + }, + function (exception) { + console.error('ex from remote data', exception); }); + } return deferred.promise; @@ -50,12 +53,12 @@ angular.module('umbraco.services') var service = { findHelp: function (args) { var url = service.getUrl(defaultUrl, args); - return fetchUrl(url); + return fetchUrl('OUR', url); }, findVideos: function (args) { var url = service.getUrl(tvUrl, args); - return fetchUrl(url); + return fetchUrl('TV', url); }, getContextHelpForPage: function (section, tree, baseurl) { diff --git a/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js b/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js index 877135c105..ed3d6ded33 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js @@ -1,9 +1,9 @@ -function startUpVideosDashboardController($scope, xmlhelper, $log, $http) { +function startUpVideosDashboardController($scope, dashboardResource) { $scope.videos = []; $scope.init = function(url){ - var proxyUrl = "dashboard/feedproxy.aspx?url=" + url; - $http.get(proxyUrl).then(function(data){ - var feed = $(data.data); + + dashboardResource.getRemoteXmlData('COM', url).then(function (data) { + var feed = $(data.data); $('item', feed).each(function (i, item) { var video = {}; video.thumbnail = $(item).find('thumbnail').attr('url'); @@ -11,6 +11,10 @@ function startUpVideosDashboardController($scope, xmlhelper, $log, $http) { video.link = $("guid", item).text(); $scope.videos.push(video); }); + + }, + function (exception) { + console.error('ex from remote data', exception); }); }; } @@ -24,7 +28,7 @@ function startUpDynamicContentController($timeout, $scope, dashboardResource, as vm.loading = true; vm.showDefault = false; - + vm.startTour = startTour; function onInit() { @@ -93,7 +97,7 @@ function startUpDynamicContentController($timeout, $scope, dashboardResource, as }); }); })); - + //proxy remote css through the local server assetsService.loadCss(dashboardResource.getRemoteDashboardCssUrl("content"), $scope); dashboardResource.getRemoteDashboardContent("content").then( @@ -117,7 +121,7 @@ function startUpDynamicContentController($timeout, $scope, dashboardResource, as vm.showDefault = true; }); - + onInit(); } diff --git a/src/Umbraco.Web.UI.Client/src/views/dashboard/members/membersdashboardvideos.html b/src/Umbraco.Web.UI.Client/src/views/dashboard/members/membersdashboardvideos.html index a403e6186a..83f3fb2f7a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dashboard/members/membersdashboardvideos.html +++ b/src/Umbraco.Web.UI.Client/src/views/dashboard/members/membersdashboardvideos.html @@ -1,5 +1,5 @@ -
@@ -8,7 +8,7 @@

Want to master Umbraco? Spend a couple of minutes learning some best practices by watching one of these videos about using Umbraco. And visit umbraco.tv for even more Umbraco videos

- +

To get you started:

    diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index d51c2f7814..e414b0521d 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -212,9 +212,6 @@ scripting.config - - feedProxy.config - Dashboard.config Designer @@ -236,7 +233,6 @@ - Designer @@ -255,7 +251,6 @@ Designer - diff --git a/src/Umbraco.Web.UI/Umbraco/dashboard/FeedProxy.aspx b/src/Umbraco.Web.UI/Umbraco/dashboard/FeedProxy.aspx deleted file mode 100644 index 22fbd78837..0000000000 --- a/src/Umbraco.Web.UI/Umbraco/dashboard/FeedProxy.aspx +++ /dev/null @@ -1,2 +0,0 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FeedProxy.aspx.cs" Inherits="dashboardUtilities.FeedProxy" %> -<%@ OutputCache Duration="1800" VaryByParam="url" %> diff --git a/src/Umbraco.Web.UI/config/feedProxy.Release.config b/src/Umbraco.Web.UI/config/feedProxy.Release.config deleted file mode 100644 index 38e7d27acf..0000000000 --- a/src/Umbraco.Web.UI/config/feedProxy.Release.config +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/src/Umbraco.Web.UI/config/feedProxy.config b/src/Umbraco.Web.UI/config/feedProxy.config deleted file mode 100644 index 38e7d27acf..0000000000 --- a/src/Umbraco.Web.UI/config/feedProxy.config +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/src/Umbraco.Web/Editors/DashboardController.cs b/src/Umbraco.Web/Editors/DashboardController.cs index c6e0049865..44fe04ef92 100644 --- a/src/Umbraco.Web/Editors/DashboardController.cs +++ b/src/Umbraco.Web/Editors/DashboardController.cs @@ -79,7 +79,7 @@ namespace Umbraco.Web.Editors } catch (HttpRequestException ex) { - Logger.Error(ex.InnerException ?? ex, "Error getting dashboard content from '{Url}'", url); + Logger.Error(ex.InnerException ?? ex, "Error getting dashboard content from {Url}", url); //it's still new JObject() - we return it like this to avoid error codes which triggers UI warnings AppCaches.RuntimeCache.InsertCacheItem(key, () => result, new TimeSpan(0, 5, 0)); @@ -117,7 +117,7 @@ namespace Umbraco.Web.Editors } catch (HttpRequestException ex) { - Logger.Error(ex.InnerException ?? ex, "Error getting dashboard CSS from '{Url}'", url); + Logger.Error(ex.InnerException ?? ex, "Error getting dashboard CSS from {Url}", url); //it's still string.Empty - we return it like this to avoid error codes which triggers UI warnings AppCaches.RuntimeCache.InsertCacheItem(key, () => result, new TimeSpan(0, 5, 0)); @@ -130,6 +130,75 @@ namespace Umbraco.Web.Editors }; } + public async Task GetRemoteXml(string site, string url) + { + // This is used in place of the old feedproxy.config + // Which was used to grab data from our.umbraco.com, umbraco.com or umbraco.tv + // for certain dashboards or the help drawer + var urlPrefix = string.Empty; + switch (site.ToUpper()) + { + case "TV": + urlPrefix = "https://umbraco.tv/"; + break; + + case "OUR": + urlPrefix = "https://our.umbraco.org/"; + break; + + case "COM": + urlPrefix = "https://umbraco.com/"; + break; + + default: + //Throw error + return new HttpResponseMessage(HttpStatusCode.Unauthorized) + { + Content = new StringContent($"The Site {site} and {url} is not on the whitelist"), + }; + } + + + //Make remote call to fetch videos or remote dashboard feed data + var key = $"umbraco-XML-feed-{site}-{url.ToCleanString(Core.Strings.CleanStringType.UrlSegment)}"; + + var content = AppCaches.RuntimeCache.GetCacheItem(key); + var result = string.Empty; + + if (content != null) + { + result = content; + } + else + { + //content is null, go get it + try + { + //fetch remote css + content = await HttpClient.GetStringAsync($"{urlPrefix}{url}"); + + //can't use content directly, modified closure problem + result = content; + + //save server content for 30 mins + AppCaches.RuntimeCache.InsertCacheItem(key, () => result, new TimeSpan(0, 30, 0)); + } + catch (HttpRequestException ex) + { + Logger.Error(ex.InnerException ?? ex, "Error getting remote dashboard data from {UrlPrefix}{Url}", urlPrefix, url); + + //it's still string.Empty - we return it like this to avoid error codes which triggers UI warnings + AppCaches.RuntimeCache.InsertCacheItem(key, () => result, new TimeSpan(0, 5, 0)); + } + } + + return new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(result, Encoding.UTF8, "text/xml") + }; + + } + [ValidateAngularAntiForgeryToken] [OutgoingEditorModelEvent] public IEnumerable> GetDashboard(string section) diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 3843c3d1d3..ec19acb00d 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -1194,13 +1194,6 @@ True Settings.settings - - FeedProxy.aspx - ASPXCodeBehind - - - FeedProxy.aspx - @@ -1240,7 +1233,6 @@ - diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx b/src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx deleted file mode 100644 index 22fbd78837..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx +++ /dev/null @@ -1,2 +0,0 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FeedProxy.aspx.cs" Inherits="dashboardUtilities.FeedProxy" %> -<%@ OutputCache Duration="1800" VaryByParam="url" %> diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx.cs deleted file mode 100644 index 58d219e0c6..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Net.Http; -using Umbraco.Core; -using Umbraco.Core.Logging; -using Umbraco.Web; -using Umbraco.Web.UI.Pages; -using System; -using System.Linq; -using System.Net.Mime; -using Umbraco.Core.IO; -using Umbraco.Core.Xml; -using Umbraco.Web.Composing; - -namespace dashboardUtilities -{ - - - public partial class FeedProxy : UmbracoEnsuredPage - { - private static HttpClient _httpClient; - - protected void Page_Load(object sender, EventArgs e) - { - try - { - if (Request.QueryString.AllKeys.Contains("url") == false || Request.QueryString["url"] == null) - return; - - var url = Request.QueryString["url"]; - if (string.IsNullOrWhiteSpace(url) || url.StartsWith("/")) - return; - - if (Uri.TryCreate(url, UriKind.Absolute, out var requestUri) == false) - return; - - var feedProxyXml = XmlHelper.OpenAsXmlDocument(IOHelper.MapPath(SystemFiles.FeedProxyConfig)); - if (feedProxyXml?.SelectSingleNode($"//allow[@host = '{requestUri.Host}']") != null && (requestUri.Port == 80 || requestUri.Port == 443)) - { - if (_httpClient == null) - _httpClient = new HttpClient(); - - using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri)) - { - var response = _httpClient.SendAsync(request).Result; - var result = response.Content.ReadAsStringAsync().Result; - - if (string.IsNullOrEmpty(result)) - return; - - Response.Clear(); - Response.ContentType = Request.CleanForXss("type") ?? MediaTypeNames.Text.Xml; - Response.Write(result); - } - } - else - { - Current.Logger.Debug("Access to unallowed feedproxy attempted: {RequestUrl}", requestUri); - } - } - catch (Exception ex) - { - Current.Logger.Error(ex, "Exception occurred"); - } - } - } -} diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx.designer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx.designer.cs deleted file mode 100644 index 1996437167..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx.designer.cs +++ /dev/null @@ -1,15 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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 dashboardUtilities { - - - public partial class FeedProxy { - } -}