2018-06-29 19:52:40 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
|
using System.Web.Http.Filters;
|
2019-01-07 10:43:28 +01:00
|
|
|
|
using Umbraco.Core;
|
2018-12-12 17:49:24 +01:00
|
|
|
|
using Umbraco.Core.Composing;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
using Umbraco.Core.Configuration;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Web.Models;
|
|
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Editors
|
|
|
|
|
|
{
|
|
|
|
|
|
[PluginController("UmbracoApi")]
|
|
|
|
|
|
public class UpdateCheckController : UmbracoAuthorizedJsonController
|
|
|
|
|
|
{
|
|
|
|
|
|
[UpdateCheckResponseFilter]
|
|
|
|
|
|
public UpgradeCheckResponse GetCheck()
|
|
|
|
|
|
{
|
|
|
|
|
|
var updChkCookie = Request.Headers.GetCookies("UMB_UPDCHK").FirstOrDefault();
|
|
|
|
|
|
var updateCheckCookie = updChkCookie != null ? updChkCookie["UMB_UPDCHK"].Value : "";
|
2019-06-18 18:44:22 +02:00
|
|
|
|
if (GlobalSettings.VersionCheckPeriod > 0 && string.IsNullOrEmpty(updateCheckCookie) && Security.CurrentUser.IsAdmin())
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2019-06-18 11:44:56 +02:00
|
|
|
|
var check = new org.umbraco.update.CheckForUpgrade { Timeout = 2000 };
|
|
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
|
var result = check.CheckUpgrade(UmbracoVersion.Current.Major,
|
|
|
|
|
|
UmbracoVersion.Current.Minor,
|
|
|
|
|
|
UmbracoVersion.Current.Build,
|
2018-11-15 08:47:47 +01:00
|
|
|
|
UmbracoVersion.Comment);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
|
|
return new UpgradeCheckResponse(result.UpgradeType.ToString(), result.Comment, result.UpgradeUrl);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.Net.WebException)
|
|
|
|
|
|
{
|
|
|
|
|
|
//this occurs if the server is down or cannot be reached
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2019-06-18 08:11:18 +02:00
|
|
|
|
catch (System.Web.Services.Protocols.SoapException)
|
|
|
|
|
|
{
|
|
|
|
|
|
//this occurs if the server has a timeout
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Adds the cookie response if it was successful
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// A filter is required because we are returning an object from the get method and not an HttpResponseMessage
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
internal class UpdateCheckResponseFilter : ActionFilterAttribute
|
|
|
|
|
|
{
|
|
|
|
|
|
public override void OnActionExecuted(HttpActionExecutedContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (context.Response == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
var objectContent = context.Response.Content as ObjectContent;
|
|
|
|
|
|
if (objectContent == null || objectContent.Value == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
//there is a result, set the outgoing cookie
|
|
|
|
|
|
var cookie = new CookieHeaderValue("UMB_UPDCHK", "1")
|
|
|
|
|
|
{
|
|
|
|
|
|
Path = "/",
|
2019-01-07 10:43:28 +01:00
|
|
|
|
Expires = DateTimeOffset.Now.AddDays(Current.Configs.Global().VersionCheckPeriod),
|
2018-06-29 19:52:40 +02:00
|
|
|
|
HttpOnly = true,
|
2019-01-07 10:43:28 +01:00
|
|
|
|
Secure = Current.Configs.Global().UseHttps
|
2018-06-29 19:52:40 +02:00
|
|
|
|
};
|
|
|
|
|
|
context.Response.Headers.AddCookies(new[] { cookie });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|