From 6c5e3c5eb880642f988b8af634b9d4445d094799 Mon Sep 17 00:00:00 2001
From: Phy <git@phy25.com>
Date: Sun, 27 Aug 2017 17:01:09 +0800
Subject: [PATCH] Update check supports HTTPS

If SSL is not supported, a HTTP request will be made. In the log the request type will be indicated, but on the frontend no additional message would be shown (I think it's better to notify admins about non-SSL situations, but currently when this fetch encounter error, no error message will be shown, so it's better not to add any warning).
---
 inc/infoutils.php | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/inc/infoutils.php b/inc/infoutils.php
index 933eb7cce..57f89e508 100644
--- a/inc/infoutils.php
+++ b/inc/infoutils.php
@@ -6,7 +6,14 @@
  * @author     Andreas Gohr <andi@splitbrain.org>
  */
 if(!defined('DOKU_INC')) die('meh.');
-if(!defined('DOKU_MESSAGEURL')) define('DOKU_MESSAGEURL','http://update.dokuwiki.org/check/');
+
+if(!defined('DOKU_MESSAGEURL')){
+    if(in_array('ssl', stream_get_transports())) {
+        define('DOKU_MESSAGEURL','https://update.dokuwiki.org/check/');
+    }else{
+        define('DOKU_MESSAGEURL','http://update.dokuwiki.org/check/');
+    }
+}
 
 /**
  * Check for new messages from upstream
@@ -22,11 +29,12 @@ function checkUpdateMessages(){
 
     $cf = getCacheName($updateVersion, '.updmsg');
     $lm = @filemtime($cf);
+    $is_http = substr(DOKU_MESSAGEURL, 0, 5) != 'https';
 
     // check if new messages needs to be fetched
     if($lm < time()-(60*60*24) || $lm < @filemtime(DOKU_INC.DOKU_SCRIPT)){
         @touch($cf);
-        dbglog("checkUpdateMessages(): downloading messages to ".$cf);
+        dbglog("checkUpdateMessages(): downloading messages to ".$cf.($is_http?' (without SSL)':' (with SSL)'));
         $http = new DokuHTTPClient();
         $http->timeout = 12;
         $resp = $http->get(DOKU_MESSAGEURL.$updateVersion);
-- 
GitLab