Skip to content

Commit be53ccf

Browse files
elit0451bergmania
authored andcommitted
Implement #11776 for v9
1 parent 4240f89 commit be53ccf

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) Umbraco.
2+
// See LICENSE for more details.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
using Microsoft.Extensions.Options;
8+
using Umbraco.Cms.Core.Configuration.Models;
9+
using Umbraco.Cms.Core.Services;
10+
using Umbraco.Extensions;
11+
12+
namespace Umbraco.Cms.Core.HealthChecks.Checks.Security
13+
{
14+
[HealthCheck(
15+
"6708CA45-E96E-40B8-A40A-0607C1CA7F28",
16+
"Application URL Configuration",
17+
Description = "Checks if the Umbraco application URL is configured for your site.",
18+
Group = "Security")]
19+
public class UmbracoApplicationUrlCheck : HealthCheck
20+
{
21+
private readonly ILocalizedTextService _textService;
22+
private readonly IOptionsMonitor<WebRoutingSettings> _webRoutingSettings;
23+
24+
public UmbracoApplicationUrlCheck(ILocalizedTextService textService, IOptionsMonitor<WebRoutingSettings> webRoutingSettings)
25+
{
26+
_textService = textService;
27+
_webRoutingSettings = webRoutingSettings;
28+
}
29+
30+
/// <summary>
31+
/// Executes the action and returns its status
32+
/// </summary>
33+
public override HealthCheckStatus ExecuteAction(HealthCheckAction action) => throw new InvalidOperationException("UmbracoApplicationUrlCheck has no executable actions");
34+
35+
/// <summary>
36+
/// Get the status for this health check
37+
/// </summary>
38+
public override Task<IEnumerable<HealthCheckStatus>> GetStatus() =>
39+
Task.FromResult(CheckUmbracoApplicationUrl().Yield());
40+
41+
private HealthCheckStatus CheckUmbracoApplicationUrl()
42+
{
43+
var url = _webRoutingSettings.CurrentValue.UmbracoApplicationUrl;
44+
45+
string resultMessage;
46+
StatusResultType resultType;
47+
var success = false;
48+
49+
if (url.IsNullOrWhiteSpace())
50+
{
51+
resultMessage = _textService.Localize("healthcheck", "umbracoApplicationUrlCheckResultFalse");
52+
resultType = StatusResultType.Warning;
53+
}
54+
else
55+
{
56+
resultMessage = _textService.Localize("healthcheck", "umbracoApplicationUrlCheckResultTrue", new[] { url });
57+
resultType = StatusResultType.Success;
58+
success = true;
59+
}
60+
61+
return new HealthCheckStatus(resultMessage)
62+
{
63+
ResultType = resultType,
64+
ReadMoreLink = success ? null : Constants.HealthChecks.DocumentationLinks.Security.UmbracoApplicationUrlCheck
65+
};
66+
}
67+
}
68+
}

src/Umbraco.Web.UI/umbraco/config/lang/en.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,8 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
22902290
<!-- The following keys get these tokens passed in:
22912291
0: Comma delimitted list of failed folder paths
22922292
-->
2293+
<key alias="umbracoApplicationUrlCheckResultTrue"><![CDATA[The appSetting 'Umbraco:CMS:WebRouting:UmbracoApplicationUrl' is set to <strong>%0%</strong>.]]></key>
2294+
<key alias="umbracoApplicationUrlCheckResultFalse">The appSetting 'Umbraco:CMS:WebRouting:UmbracoApplicationUrl' is not set.</key>
22932295
<key alias="clickJackingCheckHeaderFound">
22942296
<![CDATA[The header or meta-tag <strong>X-Frame-Options</strong> used to control whether a site can be IFRAMEd by another was found.]]></key>
22952297
<key alias="clickJackingCheckHeaderNotFound">

src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,8 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
23722372
<!-- The following keys get these tokens passed in:
23732373
0: Comma delimitted list of failed folder paths
23742374
-->
2375+
<key alias="umbracoApplicationUrlCheckResultTrue"><![CDATA[The appSetting 'Umbraco:CMS:WebRouting:UmbracoApplicationUrl' is set to <strong>%0%</strong>.]]></key>
2376+
<key alias="umbracoApplicationUrlCheckResultFalse">The appSetting 'Umbraco:CMS:WebRouting:UmbracoApplicationUrl' is not set.</key>
23752377
<key alias="clickJackingCheckHeaderFound">
23762378
<![CDATA[The header or meta-tag <strong>X-Frame-Options</strong> used to control whether a site can be IFRAMEd by another was found.]]></key>
23772379
<key alias="clickJackingCheckHeaderNotFound">

0 commit comments

Comments
 (0)