diff --git a/src/Umbraco.Web.UI/App_Plugins/RedirectUrlDashboard/redirecturlsearch.controller.js b/src/Umbraco.Web.UI/App_Plugins/RedirectUrlDashboard/redirecturlsearch.controller.js index a3f809187b..76101ab5c7 100644 --- a/src/Umbraco.Web.UI/App_Plugins/RedirectUrlDashboard/redirecturlsearch.controller.js +++ b/src/Umbraco.Web.UI/App_Plugins/RedirectUrlDashboard/redirecturlsearch.controller.js @@ -1,5 +1,4 @@ angular.module("umbraco").controller("Umbraco.RedirectUrlSearch", function ($scope, $http, angularHelper, notificationsService, entityResource, $routeParams) { - //...todo //search by url or url part //search by domain @@ -17,26 +16,26 @@ angular.module("umbraco").controller("Umbraco.RedirectUrlSearch", function ($sco }; $scope.options = { - pageSize: 10, + pageSize: 20, pageNumber: ($routeParams.page && Number($routeParams.page) !== NaN && Number($routeParams.page) > 0) ? $routeParams.page : 1 }; $scope.next = function () { - if ($scope.options.pageNumber < $scope.listViewResultSet.totalPages) { + if ($scope.options.pageNumber < $scope.pageCount) { $scope.options.pageNumber++; - $scope.reloadView(); + $scope.load(); } }; $scope.goToPage = function (pageNumber) { $scope.options.pageNumber = pageNumber + 1; - $scope.reloadView(); + $scope.load(); }; $scope.prev = function () { if ($scope.options.pageNumber > 1) { $scope.options.pageNumber--; - $scope.reloadView(); + $scope.load(); } }; @@ -52,6 +51,62 @@ angular.module("umbraco").controller("Umbraco.RedirectUrlSearch", function ($sco $scope.StatusMessage = matchingItems.StatusMessage; $scope.hasResults = matchingItems.HasSearchResults; $scope.redirectUrls = matchingItems.SearchResults; + + $scope.urlTrackerDisabled = matchingItems.UrlTrackerDisabled; + $scope.action = ""; + if ($scope.urlTrackerDisabled !== true) { + $scope.action = "Disable"; + } else { + $scope.action = "Enable"; + } + + $scope.pageCount = matchingItems.PageCount; + $scope.totalCount = matchingItems.TotalCount; + $scope.options.pageNumber = matchingItems.CurrentPage; + + if ($scope.options.pageNumber > $scope.pageCount) { + $scope.options.pageNumber = $scope.pageCount; + } + + $scope.pagination = []; + + var i; + if ($scope.pageCount <= 10) { + for (i = 0; i < $scope.pageCount; i++) { + $scope.pagination.push({ + val: (i + 1), + isActive: $scope.options.pageNumber === (i + 1) + }); + } + } + else { + //if there is more than 10 pages, we need to do some fancy bits + + //get the max index to start + var maxIndex = $scope.pageCount - 10; + //set the start, but it can't be below zero + var start = Math.max($scope.options.pageNumber - 5, 0); + //ensure that it's not too far either + start = Math.min(maxIndex, start); + + for (i = start; i < (10 + start) ; i++) { + $scope.pagination.push({ + val: (i + 1), + isActive: $scope.options.pageNumber === (i + 1) + }); + } + + //now, if the start is greater than 0 then '1' will not be displayed, so do the elipses thing + if (start > 0) { + $scope.pagination.unshift({ name: "First", val: 1, isActive: false }, { val: "...", isActive: false }); + } + + //same for the end + if (start < maxIndex) { + $scope.pagination.push({ val: "...", isActive: false }, { name: "Last", val: $scope.pageCount, isActive: false }); + } + } + angular.forEach($scope.redirectUrls, function (item) { $http.get("backoffice/api/RedirectUrlManagement/GetPublishedUrl/?id=" + item.ContentId).then(function (response) { item.ContentUrl = response.data; @@ -68,7 +123,7 @@ angular.module("umbraco").controller("Umbraco.RedirectUrlSearch", function ($sco $scope.removeRedirect = function (redirectToDelete) { $http.post("backoffice/api/RedirectUrlManagement/DeleteRedirectUrl/" + redirectToDelete.Id).then(function (response) { if (response.status === 200) { - notificationsService.success('Redirect Url Removed!', 'Redirect Url ' + redirectToDelete.Url + ' has been deleted'); + notificationsService.success("Redirect Url Removed!", "Redirect Url " + redirectToDelete.Url + " has been deleted"); // now remove from table client sides var index = -1; var urlArr = eval($scope.redirectUrls); @@ -79,26 +134,28 @@ angular.module("umbraco").controller("Umbraco.RedirectUrlSearch", function ($sco } } if (index === -1) { - notificationsService.warning('Redirect Url Removal Error!', 'Redirect Url ' + redirectToDelete.Url + ' may have already been removed'); + notificationsService.warning("Redirect Url Removal Error!", "Redirect Url " + redirectToDelete.Url + " may have already been removed"); } $scope.redirectUrls.splice(index, 1); } else { - notificationsService.warning('Redirect Url Error!','Redirect Url ' + redirectToDelete.Url + ' was not deleted'); + notificationsService.warning("Redirect Url Error!", "Redirect Url " + redirectToDelete.Url + " was not deleted"); } }); }; - $scope.disableUrlTracker = function() { - var disable = confirm("Are you sure you want to disable the URL tracker completely?"); - if (disable) { - $http.post("backoffice/api/RedirectUrlManagement/DisableUrlTracker/").then(function(response) { + $scope.toggleUrlTracker = function () { + var toggleConfirm = confirm("Are you sure you want to " + $scope.action.toLowerCase() + " the URL tracker?"); + if (toggleConfirm) { + $http.post("backoffice/api/RedirectUrlManagement/ToggleUrlTracker/?disable=" + (!$scope.urlTrackerDisabled)).then(function (response) { if (response.status === 200) { - notificationsService.success("URL Tracker has now been diabled."); + notificationsService.success("URL Tracker has now been " + $scope.action.toLowerCase() + "d."); + + $scope.load(); } else { - notificationsService.warning("Error diabling the URL Tracker, more information can be found in your log file."); + notificationsService.warning("Error " + $scope.action.toLowerCase() + "ing the URL Tracker, more information can be found in your log file."); } - }); + }); } }; diff --git a/src/Umbraco.Web.UI/ImageProcessorValidation.cs b/src/Umbraco.Web.UI/ImageProcessorValidation.cs new file mode 100644 index 0000000000..f788dcf30a --- /dev/null +++ b/src/Umbraco.Web.UI/ImageProcessorValidation.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Web; +using ImageProcessor.Web.Processors; +using ImageProcessor.Web.Configuration; +using ImageProcessor.Web.HttpModules; +using Umbraco.Core; + +namespace Umbraco.Web.UI +{ + public class ImageProcessorValidation : ApplicationEventHandler + { + protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + ImageProcessingModule.ValidatingRequest += ImageProcessingModule_ValidatingRequest; + } + + private static void ImageProcessingModule_ValidatingRequest(object sender, ImageProcessor.Web.Helpers.ValidatingRequestEventArgs e) + { +// Blur is disabled by default, add it to the list of available processors again +var configuration = ImageProcessorConfiguration.Instance; +var settings = new Dictionary +{ + { "MaxSize", "15" }, + { "MaxSigma", "1.5" }, + { "MaxThreshold", "10" } +}; + +configuration.AvailableWebGraphicsProcessors.TryAdd(typeof(GaussianBlur), settings); + + // Nothing to process, return immediately + if (string.IsNullOrWhiteSpace(e.QueryString)) + return; + + // Don't support alpha whatsoever + var queryCollection = HttpUtility.ParseQueryString(e.QueryString); + if (queryCollection.AllKeys.Contains("alpha")) + { + e.Cancel = true; + return; + } + + // If there's a crop parameter, force it to always just be a specific value + if (queryCollection.AllKeys.Contains("crop")) + { + queryCollection["crop"] = "100,100,100,100"; + // this performs the reverse of ParseQueryString since the result of ParseQueryString + // is actually an instance of System.Web.HttpValueCollection + e.QueryString = queryCollection.ToString(); + } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Redirects/RedirectUrlManagementController.cs b/src/Umbraco.Web/Redirects/RedirectUrlManagementController.cs index 27791136e1..7f3334d3f2 100644 --- a/src/Umbraco.Web/Redirects/RedirectUrlManagementController.cs +++ b/src/Umbraco.Web/Redirects/RedirectUrlManagementController.cs @@ -1,6 +1,10 @@ -using System.Net.Http; +using System.IO; +using System.Net.Http; using System.Text; +using System.Web; using System.Web.Http; +using System.Xml; +using Umbraco.Core.Configuration; using Umbraco.Web.WebApi; namespace Umbraco.Web.Redirects @@ -9,20 +13,19 @@ namespace Umbraco.Web.Redirects { //add paging [HttpGet] - public RedirectUrlSearchResult SearchRedirectUrls(string searchTerm, int page = 0) + public RedirectUrlSearchResult SearchRedirectUrls(string searchTerm, int page = 0, int pageSize = 10) { - - int pageSize = 20; - var searchResult = new RedirectUrlSearchResult(); + page = page - 1; + var searchResult = new RedirectUrlSearchResult { UrlTrackerDisabled = UmbracoConfig.For.UmbracoSettings().WebRouting.DisableRedirectUrlTracking }; var redirectUrlService = Services.RedirectUrlService; long resultCount = 0L; // need endpoint for search functionality // by url, by domain ? it's the url that you want to find them by, that's what you see.. - var redirects = redirectUrlService.GetAllRedirectUrls(page, 20, out resultCount); + var redirects = redirectUrlService.GetAllRedirectUrls(page, pageSize, out resultCount); searchResult.SearchResults = redirects; searchResult.TotalCount = resultCount; - searchResult.CurrentPage = page; + searchResult.CurrentPage = page + 1; //hmm how many results 'could there be ? searchResult.PageCount = ((int)resultCount + pageSize - 1) / pageSize; @@ -60,6 +63,29 @@ namespace Umbraco.Web.Redirects return new HttpResponseMessage(System.Net.HttpStatusCode.OK); } + [HttpPost] + public HttpResponseMessage ToggleUrlTracker(bool disable) + { + var configFilePath = HttpContext.Current.Server.MapPath("~/config/umbracoSettings.config"); + if (File.Exists(configFilePath)) + { + var umbracoConfig = new XmlDocument {PreserveWhitespace = true}; + umbracoConfig.Load(configFilePath); + + var webRoutingElement = umbracoConfig.SelectSingleNode("//web.routing") as XmlElement; + if (webRoutingElement != null) + { + // note: this adds the attribute if it does not exist + webRoutingElement.SetAttribute("disableRedirectUrlTracking", disable.ToString().ToLowerInvariant()); + umbracoConfig.Save(configFilePath); + } + + + return new HttpResponseMessage(System.Net.HttpStatusCode.OK); + } + + return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Redirects/RedirectUrlSearchResults.cs b/src/Umbraco.Web/Redirects/RedirectUrlSearchResults.cs index 1dac259a88..4fe790e588 100644 --- a/src/Umbraco.Web/Redirects/RedirectUrlSearchResults.cs +++ b/src/Umbraco.Web/Redirects/RedirectUrlSearchResults.cs @@ -12,5 +12,7 @@ namespace Umbraco.Web.Redirects public long TotalCount { get; set; } public int PageCount { get; set; } public int CurrentPage { get; set; } + + public bool UrlTrackerDisabled { get; set; } } } \ No newline at end of file