update UI version check via AutoUpdate class in Froxlor.checkUpdate()

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-05-26 13:14:43 +02:00
parent ac143b2bbf
commit 282e6f4cd7
2 changed files with 40 additions and 64 deletions

View File

@@ -31,12 +31,11 @@ use Froxlor\Cron\TaskId;
use Froxlor\Database\Database; use Froxlor\Database\Database;
use Froxlor\Database\IntegrityCheck; use Froxlor\Database\IntegrityCheck;
use Froxlor\FroxlorLogger; use Froxlor\FroxlorLogger;
use Froxlor\Http\HttpClient; use Froxlor\Install\AutoUpdate;
use Froxlor\Settings; use Froxlor\Settings;
use Froxlor\SImExporter; use Froxlor\SImExporter;
use Froxlor\System\Cronjob; use Froxlor\System\Cronjob;
use Froxlor\System\Crypt; use Froxlor\System\Crypt;
use Froxlor\UI\Response;
use PDO; use PDO;
use RecursiveDirectoryIterator; use RecursiveDirectoryIterator;
use RecursiveIteratorIterator; use RecursiveIteratorIterator;
@@ -62,74 +61,51 @@ class Froxlor extends ApiCommand
define('UPDATE_URI', "https://version.froxlor.org/Froxlor/api/" . $this->version); define('UPDATE_URI', "https://version.froxlor.org/Froxlor/api/" . $this->version);
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) { if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
if (function_exists('curl_version')) {
// log our actions // log our actions
$this->logger()->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] checking for updates"); $this->logger()->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] checking for updates");
// check for new version // check for new version
try { $aucheck = AutoUpdate::checkVersion();
$latestversion = HttpClient::urlGet(UPDATE_URI, true, 3);
} catch (Exception $e) {
$latestversion = \Froxlor\Froxlor::getVersion() . "|Version-check currently unavailable, please try again later";
}
$latestversion = explode('|', $latestversion);
if (is_array($latestversion) && count($latestversion) >= 1) {
$_version = $latestversion[0];
$_message = isset($latestversion[1]) ? $latestversion[1] : '';
$_link = isset($latestversion[2]) ? $latestversion[2] : '';
// add the branding so debian guys are not gettings confused
// about their version-number
$version_label = $_version . $this->branding;
$version_link = $_link;
$message_addinfo = $_message;
// not numeric -> error-message
if (!preg_match('/^((\d+\\.)(\d+\\.)(\d+\\.)?(\d+)?(\-(svn|dev|rc)(\d+))?)$/', $_version)) {
// check for customized version to not output
// "There is a newer version of froxlor" besides the error-message
$isnewerversion = -1;
} elseif (\Froxlor\Froxlor::versionCompare2($this->version, $_version) == -1) {
// there is a newer version - yay
$isnewerversion = 1;
} else {
// nothing new
$isnewerversion = 0;
}
if ($aucheck == 1) {
// anzeige über version-status mit ggfls. formular // anzeige über version-status mit ggfls. formular
// zum update schritt #1 -> download // zum update schritt #1 -> download
if ($isnewerversion == 1) { $text = 'There is a newer version available: "' . AutoUpdate::getFromResult('version') . '" (Your current version is: ' . $this->version . ')';
$text = 'There is a newer version available: "' . $_version . '" (Your current version is: ' . $this->version . ')';
return $this->response([ return $this->response([
'isnewerversion' => $isnewerversion, 'isnewerversion' => (int) !AutoUpdate::getFromResult('has_latest'),
'version' => $_version, 'version' => AutoUpdate::getFromResult('version'),
'message' => $text, 'message' => $text,
'link' => $version_link, 'link' => AutoUpdate::getFromResult('url'),
'additional_info' => $message_addinfo 'additional_info' => AutoUpdate::getFromResult('info')
]);
} elseif ($isnewerversion == 0) {
// all good
return $this->response([
'isnewerversion' => $isnewerversion,
'version' => $version_label,
'message' => "",
'link' => $version_link,
'additional_info' => $message_addinfo
]); ]);
} else if ($aucheck < 0 || $aucheck > 1) {
// errors
if ($aucheck < 0) {
$errmsg = AutoUpdate::getLastError();
} else { } else {
Response::standardError('customized_version', '', true); if ($aucheck == 3) {
} $errmsg = lng('error.customized_version');
} else {
$errmsg = lng('error.autoupdate_' . $aucheck);
} }
} }
return $this->response([ return $this->response([
'isnewerversion' => 0, 'isnewerversion' => 0,
'version' => $this->version . $this->branding, 'version' => $this->version,
'message' => 'Version-check not available due to missing php-curl extension', 'message' => $errmsg,
'link' => UPDATE_URI . '/pretty', 'link' => '',
'additional_info' => "" 'additional_info' => ''
], 502); ]);
} else {
return $this->response([
'isnewerversion' => 0,
'version' => $this->version,
'message' => lng('update.noupdatesavail'),
'link' => '',
'additional_info' => ''
]);
}
} }
throw new Exception("Not allowed to execute given command.", 403); throw new Exception("Not allowed to execute given command.", 403);
} }

View File

@@ -33,7 +33,7 @@ use Froxlor\Http\HttpClient;
class AutoUpdate class AutoUpdate
{ {
// define update-uri // define update-uri
const UPDATE_URI = "https://version.froxlor.org/froxlor/api2/"; const UPDATE_URI = "https://version.froxlor.org/froxlor/api/v2/";
const RELEASE_URI = "https://autoupdate.froxlor.org/froxlor-{version}.zip"; const RELEASE_URI = "https://autoupdate.froxlor.org/froxlor-{version}.zip";
const CHECKSUM_URI = "https://autoupdate.froxlor.org/froxlor-{version}.zip.sha256"; const CHECKSUM_URI = "https://autoupdate.froxlor.org/froxlor-{version}.zip.sha256";