From f84061ee14f18a24d26a18fecfb8667c40a44df4 Mon Sep 17 00:00:00 2001 From: TimZ99 Date: Thu, 26 Sep 2019 14:07:16 +0200 Subject: [PATCH] Get latest version from Github. The latest version number will now come from Github instead of phpservermonitor.org. --- src/includes/functions.inc.php | 10 ++++++---- src/includes/psmconfig.inc.php | 6 +++--- src/templates/default/main/body.tpl.html | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 4ea81309..496b8f1b 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -476,17 +476,19 @@ function psm_update_available() { // update last check date psm_update_conf('last_update_check', time()); $latest = psm_curl_get(PSM_UPDATE_URL); + // extract latest version from Github. + preg_match('/"tag_name":"[v](([\d][.][\d][.][\d])(-?\w*))"/', $latest, $latest); // add latest version to database - if ($latest !== false && strlen($latest) < 15) { - psm_update_conf('version_update_check', $latest); + if ($latest[2] !== false && strlen($latest[2]) < 15) { + psm_update_conf('version_update_check', $latest[2]); } } else { $latest = psm_get_conf('version_update_check'); } - if ($latest !== false) { + if ($latest[2] !== false) { $current = psm_get_conf('version'); - return version_compare($latest, $current, '>'); + return version_compare($latest[2], $current, '>'); } else { return false; } diff --git a/src/includes/psmconfig.inc.php b/src/includes/psmconfig.inc.php index 34b068fe..56cc60ad 100644 --- a/src/includes/psmconfig.inc.php +++ b/src/includes/psmconfig.inc.php @@ -35,13 +35,13 @@ define('PSM_VERSION', '3.4.4'); * URL to check for updates. Will not be checked if turned off on config page. * @see psm_update_available() */ -define('PSM_UPDATE_URL', 'http://www.phpservermonitor.org/version.php'); +define('PSM_UPDATE_URL', 'https://api.github.com/repos/phpservermon/phpservermon/releases/latest'); /** - * Default update interval (1 week). Only applicable when updates are enabled. + * Default update interval (1 day). Only applicable when updates are enabled. * @see psm_update_available() */ -define('PSM_UPDATE_INTERVAL', 7 * 24 * 60 * 60); +define('PSM_UPDATE_INTERVAL', 1 * 24 * 60 * 60); /** * Configuration for: Hashing strength diff --git a/src/templates/default/main/body.tpl.html b/src/templates/default/main/body.tpl.html index 35168a6d..beff84e0 100644 --- a/src/templates/default/main/body.tpl.html +++ b/src/templates/default/main/body.tpl.html @@ -68,8 +68,7 @@ Powered by PHP Server Monitor {{ version }}. - - {{ update_available }} {{ label_back_to_top }} + {{ update_available|raw }}{{ label_back_to_top }}