2021-06-15 15:05:57 +10:00
|
|
|
using System.IO;
|
2021-02-10 11:42:04 +01:00
|
|
|
using System.Threading.Tasks;
|
2020-07-08 11:18:23 +02:00
|
|
|
using Microsoft.AspNetCore.Http.Extensions;
|
2020-04-20 12:20:47 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-05-13 17:14:09 +10:00
|
|
|
using Microsoft.AspNetCore.Routing;
|
2020-09-21 09:52:58 +02:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-08-21 14:52:47 +01:00
|
|
|
using Microsoft.Extensions.Options;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
using Umbraco.Cms.Core.Configuration;
|
|
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Hosting;
|
|
|
|
|
using Umbraco.Cms.Core.Security;
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Core.WebAssets;
|
2021-02-12 11:11:44 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Install;
|
2021-12-02 10:01:23 +01:00
|
|
|
using Umbraco.Cms.Web.Common.Attributes;
|
2021-02-10 11:42:04 +01:00
|
|
|
using Umbraco.Cms.Web.Common.Filters;
|
2021-05-18 19:19:58 +02:00
|
|
|
using Umbraco.Extensions;
|
2014-02-26 04:15:14 +11:00
|
|
|
|
2021-05-18 19:19:58 +02:00
|
|
|
namespace Umbraco.Cms.Web.BackOffice.Install
|
2014-02-26 04:15:14 +11:00
|
|
|
{
|
2020-05-12 10:21:40 +10:00
|
|
|
|
2014-03-11 18:09:54 +11:00
|
|
|
/// <summary>
|
2020-05-12 17:10:02 +10:00
|
|
|
/// The Installation controller
|
2014-03-11 18:09:54 +11:00
|
|
|
/// </summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
[InstallAuthorize]
|
2021-02-09 10:22:42 +01:00
|
|
|
[Area(Cms.Core.Constants.Web.Mvc.InstallArea)]
|
2014-02-26 04:15:14 +11:00
|
|
|
public class InstallController : Controller
|
|
|
|
|
{
|
2020-10-21 16:51:00 +11:00
|
|
|
private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor;
|
2018-04-06 13:51:54 +10:00
|
|
|
private readonly InstallHelper _installHelper;
|
2016-09-01 19:06:08 +02:00
|
|
|
private readonly IRuntimeState _runtime;
|
2020-08-21 14:52:47 +01:00
|
|
|
private readonly GlobalSettings _globalSettings;
|
2020-04-03 11:03:06 +11:00
|
|
|
private readonly IHostingEnvironment _hostingEnvironment;
|
2020-05-05 14:28:01 +02:00
|
|
|
private readonly IUmbracoVersion _umbracoVersion;
|
2020-09-21 09:52:58 +02:00
|
|
|
private readonly ILogger<InstallController> _logger;
|
2020-05-13 17:14:09 +10:00
|
|
|
private readonly LinkGenerator _linkGenerator;
|
2020-03-17 10:28:03 +01:00
|
|
|
private readonly IRuntimeMinifier _runtimeMinifier;
|
2014-02-26 04:15:14 +11:00
|
|
|
|
2020-03-17 10:28:03 +01:00
|
|
|
public InstallController(
|
2020-10-21 16:51:00 +11:00
|
|
|
IBackOfficeSecurityAccessor backofficeSecurityAccessor,
|
2020-03-17 10:28:03 +01:00
|
|
|
InstallHelper installHelper,
|
|
|
|
|
IRuntimeState runtime,
|
2020-08-23 23:36:48 +02:00
|
|
|
IOptions<GlobalSettings> globalSettings,
|
2020-04-03 11:03:06 +11:00
|
|
|
IRuntimeMinifier runtimeMinifier,
|
2020-05-05 14:28:01 +02:00
|
|
|
IHostingEnvironment hostingEnvironment,
|
2020-05-13 17:14:09 +10:00
|
|
|
IUmbracoVersion umbracoVersion,
|
2020-09-21 09:52:58 +02:00
|
|
|
ILogger<InstallController> logger,
|
2020-05-13 17:14:09 +10:00
|
|
|
LinkGenerator linkGenerator)
|
2017-07-20 11:21:28 +02:00
|
|
|
{
|
2020-09-22 10:01:00 +02:00
|
|
|
_backofficeSecurityAccessor = backofficeSecurityAccessor;
|
2018-04-06 13:51:54 +10:00
|
|
|
_installHelper = installHelper;
|
2016-09-01 19:06:08 +02:00
|
|
|
_runtime = runtime;
|
2020-08-21 14:52:47 +01:00
|
|
|
_globalSettings = globalSettings.Value;
|
2020-03-17 10:28:03 +01:00
|
|
|
_runtimeMinifier = runtimeMinifier;
|
2020-04-03 11:03:06 +11:00
|
|
|
_hostingEnvironment = hostingEnvironment;
|
2020-05-05 14:28:01 +02:00
|
|
|
_umbracoVersion = umbracoVersion;
|
2020-05-13 17:14:09 +10:00
|
|
|
_logger = logger;
|
|
|
|
|
_linkGenerator = linkGenerator;
|
2017-07-20 11:21:28 +02:00
|
|
|
}
|
2014-02-26 04:15:14 +11:00
|
|
|
|
|
|
|
|
[HttpGet]
|
2020-04-27 10:09:10 +02:00
|
|
|
[StatusCodeResult(System.Net.HttpStatusCode.ServiceUnavailable)]
|
2020-05-06 20:37:03 +02:00
|
|
|
[TypeFilter(typeof(StatusCodeResultAttribute), Arguments = new object []{System.Net.HttpStatusCode.ServiceUnavailable})]
|
2020-05-12 10:21:40 +10:00
|
|
|
public async Task<ActionResult> Index()
|
2014-02-26 04:15:14 +11:00
|
|
|
{
|
2020-05-13 14:49:00 +10:00
|
|
|
var umbracoPath = Url.GetBackOfficeUrl();
|
|
|
|
|
|
2016-09-01 19:06:08 +02:00
|
|
|
if (_runtime.Level == RuntimeLevel.Run)
|
2020-05-13 14:49:00 +10:00
|
|
|
return Redirect(umbracoPath);
|
2014-02-27 10:16:30 +01:00
|
|
|
|
2021-06-15 15:05:57 +10:00
|
|
|
// TODO: Update for package migrations
|
2016-09-01 19:06:08 +02:00
|
|
|
if (_runtime.Level == RuntimeLevel.Upgrade)
|
2015-06-22 16:22:47 +02:00
|
|
|
{
|
2020-12-02 15:49:28 +11:00
|
|
|
var authResult = await this.AuthenticateBackOfficeAsync();
|
2014-02-26 04:15:14 +11:00
|
|
|
|
2020-12-02 14:28:16 +11:00
|
|
|
if (!authResult.Succeeded)
|
2014-02-26 04:15:14 +11:00
|
|
|
{
|
2020-12-02 14:28:16 +11:00
|
|
|
return Redirect(_globalSettings.UmbracoPath + "/AuthorizeUpgrade?redir=" + Request.GetEncodedUrl());
|
2014-02-26 04:15:14 +11:00
|
|
|
}
|
2015-06-22 16:22:47 +02:00
|
|
|
}
|
2014-02-26 16:01:31 +01:00
|
|
|
|
2020-12-01 11:34:13 +01:00
|
|
|
// gen the install base URL
|
2020-08-21 13:53:27 +02:00
|
|
|
ViewData.SetInstallApiBaseUrl(_linkGenerator.GetInstallerApiUrl());
|
2016-09-01 19:06:08 +02:00
|
|
|
|
|
|
|
|
// get the base umbraco folder
|
2020-07-08 11:18:23 +02:00
|
|
|
var baseFolder = _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath);
|
|
|
|
|
ViewData.SetUmbracoBaseFolder(baseFolder);
|
2014-02-26 16:01:31 +01:00
|
|
|
|
2020-05-05 14:28:01 +02:00
|
|
|
ViewData.SetUmbracoVersion(_umbracoVersion.SemanticVersion);
|
|
|
|
|
|
2020-06-02 13:47:58 +10:00
|
|
|
await _installHelper.SetInstallStatusAsync(false, "");
|
2014-04-07 16:08:34 +02:00
|
|
|
|
2021-09-01 10:57:21 +02:00
|
|
|
return View(Path.Combine(Constants.SystemDirectories.Umbraco.TrimStart("~") , Cms.Core.Constants.Web.Mvc.InstallArea, nameof(Index) + ".cshtml"));
|
2014-02-26 04:15:14 +11:00
|
|
|
}
|
2020-05-13 17:14:09 +10:00
|
|
|
|
2020-05-14 22:50:27 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// Used to perform the redirect to the installer when the runtime level is <see cref="RuntimeLevel.Install"/> or <see cref="RuntimeLevel.Upgrade"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2020-05-13 17:14:09 +10:00
|
|
|
[HttpGet]
|
2021-12-02 10:01:23 +01:00
|
|
|
[IgnoreFromNotFoundSelectorPolicy]
|
2020-05-13 17:14:09 +10:00
|
|
|
public ActionResult Redirect()
|
|
|
|
|
{
|
|
|
|
|
var uri = HttpContext.Request.GetEncodedUrl();
|
2020-07-08 11:18:23 +02:00
|
|
|
|
2020-05-13 17:14:09 +10:00
|
|
|
// redirect to install
|
|
|
|
|
ReportRuntime(_logger, _runtime.Level, "Umbraco must install or upgrade.");
|
|
|
|
|
|
|
|
|
|
var installUrl = $"{_linkGenerator.GetInstallerUrl()}?redir=true&url={uri}";
|
|
|
|
|
return Redirect(installUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool _reported;
|
|
|
|
|
private static RuntimeLevel _reportedLevel;
|
|
|
|
|
|
2020-09-21 09:52:58 +02:00
|
|
|
private static void ReportRuntime(ILogger<InstallController> logger, RuntimeLevel level, string message)
|
2020-05-13 17:14:09 +10:00
|
|
|
{
|
|
|
|
|
if (_reported && _reportedLevel == level) return;
|
|
|
|
|
_reported = true;
|
|
|
|
|
_reportedLevel = level;
|
2020-09-14 14:10:19 +02:00
|
|
|
logger.LogWarning(message);
|
2020-05-13 17:14:09 +10:00
|
|
|
}
|
2014-02-26 04:15:14 +11:00
|
|
|
}
|
|
|
|
|
}
|