2016-02-08 12:34:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2016-02-08 12:53:08 +00:00
|
|
|
* This file is part of the Froxlor project.
|
2022-04-28 18:48:00 +00:00
|
|
|
* Copyright (c) 2010 the Froxlor Team (see authors).
|
2016-02-08 12:53:08 +00:00
|
|
|
*
|
2022-04-28 18:48:00 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2016-02-08 12:34:24 +00:00
|
|
|
*
|
2022-04-28 18:48:00 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2016-02-08 12:53:08 +00:00
|
|
|
*
|
2022-04-28 18:48:00 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you can also view it online at
|
|
|
|
* https://files.froxlor.org/misc/COPYING.txt
|
2016-02-08 12:53:08 +00:00
|
|
|
*
|
2022-04-28 18:48:00 +00:00
|
|
|
* @copyright the authors
|
|
|
|
* @author Froxlor team <team@froxlor.org>
|
|
|
|
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
2016-02-08 12:34:24 +00:00
|
|
|
*/
|
2022-02-20 17:00:44 +00:00
|
|
|
|
|
|
|
const AREA = 'admin';
|
|
|
|
require __DIR__ . '/lib/init.php';
|
2016-02-08 12:34:24 +00:00
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
use Froxlor\Froxlor;
|
|
|
|
use Froxlor\FroxlorLogger;
|
2018-12-21 11:24:07 +00:00
|
|
|
use Froxlor\Http\HttpClient;
|
2022-04-28 18:48:00 +00:00
|
|
|
use Froxlor\Settings;
|
2022-03-16 13:32:10 +00:00
|
|
|
use Froxlor\UI\Panel\UI;
|
2022-04-28 18:48:00 +00:00
|
|
|
use Froxlor\UI\Response;
|
2018-12-18 12:45:05 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// define update-uri
|
2022-04-28 18:48:00 +00:00
|
|
|
define('UPDATE_URI', "https://version.froxlor.org/Froxlor/api/" . Froxlor::VERSION);
|
2016-02-23 20:52:35 +00:00
|
|
|
define('RELEASE_URI', "https://autoupdate.froxlor.org/froxlor-{version}.zip");
|
|
|
|
define('CHECKSUM_URI', "https://autoupdate.froxlor.org/froxlor-{version}.zip.sha256");
|
2016-02-08 12:34:24 +00:00
|
|
|
|
2022-04-20 14:12:42 +00:00
|
|
|
if ($page != 'error') {
|
|
|
|
// check for archive-stuff
|
|
|
|
if (!extension_loaded('zip')) {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2022-04-20 14:12:42 +00:00
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 2
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2022-04-20 14:12:42 +00:00
|
|
|
}
|
2016-02-08 12:34:24 +00:00
|
|
|
|
2022-04-20 14:12:42 +00:00
|
|
|
// 0.11.x requires 7.4 at least
|
|
|
|
if (version_compare("7.4.0", PHP_VERSION, ">=")) {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2022-04-20 14:12:42 +00:00
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 10
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2022-04-20 14:12:42 +00:00
|
|
|
}
|
2019-10-12 12:04:43 +00:00
|
|
|
|
2022-04-20 14:12:42 +00:00
|
|
|
// check for webupdate to be enabled
|
2022-04-28 18:48:00 +00:00
|
|
|
if (Settings::Config('enable_webupdate') != true) {
|
|
|
|
Response::redirectTo($filename, [
|
2022-04-20 14:12:42 +00:00
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 11
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2022-04-20 14:12:42 +00:00
|
|
|
}
|
2022-04-20 13:18:50 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// display initial version check
|
|
|
|
if ($page == 'overview') {
|
|
|
|
// log our actions
|
2022-04-28 18:48:00 +00:00
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "checking auto-update");
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// check for new version
|
2019-10-06 16:53:30 +00:00
|
|
|
try {
|
|
|
|
$latestversion = HttpClient::urlGet(UPDATE_URI, true, 3);
|
2022-04-28 18:48:00 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
Response::dynamicError("Version-check currently unavailable, please try again later");
|
2019-10-06 16:53:30 +00:00
|
|
|
}
|
2018-02-09 09:50:14 +00:00
|
|
|
$latestversion = explode('|', $latestversion);
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2018-02-09 09:50:14 +00:00
|
|
|
if (is_array($latestversion) && count($latestversion) >= 1) {
|
|
|
|
$_version = $latestversion[0];
|
|
|
|
$_message = isset($latestversion[1]) ? $latestversion[1] : '';
|
2022-03-25 07:11:31 +00:00
|
|
|
$_link = isset($latestversion[2]) ? $latestversion[2] : htmlspecialchars($filename . '?page=' . urlencode($page) . '&lookfornewversion=yes');
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2018-02-09 09:50:14 +00:00
|
|
|
// add the branding so debian guys are not gettings confused
|
|
|
|
// about their version-number
|
2022-04-28 18:48:00 +00:00
|
|
|
$version_label = $_version . Froxlor::BRANDING;
|
2018-02-09 09:50:14 +00:00
|
|
|
$version_link = $_link;
|
|
|
|
$message_addinfo = $_message;
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2018-02-09 09:50:14 +00:00
|
|
|
// not numeric -> error-message
|
2022-03-14 21:51:59 +00:00
|
|
|
if (!preg_match('/^((\d+\\.)(\d+\\.)(\d+\\.)?(\d+)?(\-(svn|dev|rc)(\d+))?)$/', $_version)) {
|
2018-02-09 09:50:14 +00:00
|
|
|
// check for customized version to not output
|
|
|
|
// "There is a newer version of froxlor" besides the error-message
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2018-02-09 09:50:14 +00:00
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 3
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
|
|
|
} elseif (Froxlor::versionCompare2(Froxlor::VERSION, $_version) == -1) {
|
2018-02-09 09:50:14 +00:00
|
|
|
// there is a newer version - yay
|
|
|
|
$isnewerversion = 1;
|
|
|
|
} else {
|
|
|
|
// nothing new
|
|
|
|
$isnewerversion = 0;
|
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2018-02-09 09:50:14 +00:00
|
|
|
// anzeige über version-status mit ggfls. formular
|
|
|
|
// zum update schritt #1 -> download
|
|
|
|
if ($isnewerversion == 1) {
|
2022-04-28 18:48:00 +00:00
|
|
|
$text = 'There is a newer version available. Update to version <b>' . $_version . '</b> now?<br/>(Your current version is: ' . Froxlor::VERSION . ')';
|
2022-03-16 13:32:10 +00:00
|
|
|
|
|
|
|
$upd_formfield = [
|
|
|
|
'updates' => [
|
2022-04-28 18:48:00 +00:00
|
|
|
'title' => lng('update.update'),
|
2022-03-16 13:32:10 +00:00
|
|
|
'image' => 'fa-solid fa-download',
|
|
|
|
'sections' => [
|
|
|
|
'section_autoupd' => [
|
|
|
|
'fields' => [
|
|
|
|
'newversion' => ['type' => 'hidden', 'value' => $_version]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'buttons' => [
|
|
|
|
[
|
|
|
|
'class' => 'btn-outline-secondary',
|
2022-04-28 18:48:00 +00:00
|
|
|
'label' => lng('panel.cancel'),
|
2022-03-16 13:32:10 +00:00
|
|
|
'type' => 'reset'
|
|
|
|
],
|
|
|
|
[
|
2022-04-28 18:48:00 +00:00
|
|
|
'label' => lng('update.proceed')
|
2022-03-16 13:32:10 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2022-03-18 11:53:34 +00:00
|
|
|
UI::view('user/form-note.html.twig', [
|
2022-04-28 18:48:00 +00:00
|
|
|
'formaction' => $linker->getLink(['section' => 'autoupdate', 'page' => 'getdownload']),
|
2022-03-16 13:32:10 +00:00
|
|
|
'formdata' => $upd_formfield['updates'],
|
|
|
|
// alert
|
|
|
|
'type' => 'warning',
|
|
|
|
'alert_msg' => $text
|
|
|
|
]);
|
2018-02-09 09:50:14 +00:00
|
|
|
} elseif ($isnewerversion == 0) {
|
|
|
|
// all good
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::standardSuccess('noupdatesavail');
|
2018-02-09 09:50:14 +00:00
|
|
|
} else {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::standardError('customized_version');
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
} // download the new archive
|
2016-02-08 12:34:24 +00:00
|
|
|
elseif ($page == 'getdownload') {
|
2016-02-16 20:56:32 +00:00
|
|
|
// retrieve the new version from the form
|
2016-02-08 12:34:24 +00:00
|
|
|
$newversion = isset($_POST['newversion']) ? $_POST['newversion'] : null;
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// valid?
|
|
|
|
if ($newversion !== null) {
|
|
|
|
// define files to get
|
|
|
|
$toLoad = str_replace('{version}', $newversion, RELEASE_URI);
|
2016-02-23 20:52:35 +00:00
|
|
|
$toCheck = str_replace('{version}', $newversion, CHECKSUM_URI);
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// check for local destination folder
|
2022-04-28 18:48:00 +00:00
|
|
|
if (!is_dir(Froxlor::getInstallDir() . '/updates/')) {
|
|
|
|
mkdir(Froxlor::getInstallDir() . '/updates/');
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// name archive
|
2022-04-28 18:48:00 +00:00
|
|
|
$localArchive = Froxlor::getInstallDir() . '/updates/' . basename($toLoad);
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "Downloading " . $toLoad . " to " . $localArchive);
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// remove old archive
|
|
|
|
if (file_exists($localArchive)) {
|
2016-08-04 19:49:33 +00:00
|
|
|
@unlink($localArchive);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2018-02-09 09:50:14 +00:00
|
|
|
// get archive data
|
|
|
|
try {
|
|
|
|
HttpClient::fileGet($toLoad, $localArchive);
|
|
|
|
} catch (Exception $e) {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2018-02-09 09:50:14 +00:00
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 4
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2016-02-23 20:52:35 +00:00
|
|
|
// validate the integrity of the downloaded file
|
2018-02-09 09:50:14 +00:00
|
|
|
$_shouldsum = HttpClient::urlGet($toCheck);
|
2022-03-14 21:51:59 +00:00
|
|
|
if (!empty($_shouldsum)) {
|
2016-08-04 19:49:33 +00:00
|
|
|
$_t = explode(" ", $_shouldsum);
|
|
|
|
$shouldsum = $_t[0];
|
2016-02-08 12:34:24 +00:00
|
|
|
} else {
|
2016-08-04 19:49:33 +00:00
|
|
|
$shouldsum = null;
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2016-02-23 20:52:35 +00:00
|
|
|
$filesum = hash_file('sha256', $localArchive);
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
if ($filesum != $shouldsum) {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2018-02-09 09:50:14 +00:00
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 9
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// to the next step
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2018-02-09 09:50:14 +00:00
|
|
|
'page' => 'extract',
|
|
|
|
'archive' => basename($localArchive)
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2018-02-09 09:50:14 +00:00
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 6
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2018-12-21 11:24:07 +00:00
|
|
|
} // extract and install new version
|
2016-02-08 12:34:24 +00:00
|
|
|
elseif ($page == 'extract') {
|
2018-02-09 09:50:14 +00:00
|
|
|
if (isset($_POST['send']) && $_POST['send'] == 'send') {
|
2022-03-16 13:32:10 +00:00
|
|
|
$toExtract = isset($_POST['archive']) ? $_POST['archive'] : null;
|
2022-04-28 18:48:00 +00:00
|
|
|
$localArchive = Froxlor::getInstallDir() . '/updates/' . $toExtract;
|
2016-02-08 12:34:24 +00:00
|
|
|
// decompress from zip
|
2018-02-09 09:50:14 +00:00
|
|
|
$zip = new ZipArchive();
|
2016-02-08 12:34:24 +00:00
|
|
|
$res = $zip->open($localArchive);
|
|
|
|
if ($res === true) {
|
2022-04-28 18:48:00 +00:00
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "Extracting " . $localArchive . " to " . Froxlor::getInstallDir());
|
|
|
|
$zip->extractTo(Froxlor::getInstallDir());
|
2016-02-08 12:34:24 +00:00
|
|
|
$zip->close();
|
|
|
|
// success - remove unused archive
|
|
|
|
@unlink($localArchive);
|
2019-10-10 12:55:45 +00:00
|
|
|
// wait a bit before we redirect to be sure
|
|
|
|
sleep(2);
|
2016-02-08 12:34:24 +00:00
|
|
|
} else {
|
|
|
|
// error
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2018-02-09 09:50:14 +00:00
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 8
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// redirect to update-page?
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo('admin_updates.php');
|
2022-03-16 13:32:10 +00:00
|
|
|
} else {
|
|
|
|
$toExtract = isset($_GET['archive']) ? $_GET['archive'] : null;
|
2022-04-28 18:48:00 +00:00
|
|
|
$localArchive = Froxlor::getInstallDir() . '/updates/' . $toExtract;
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2022-03-14 21:51:59 +00:00
|
|
|
if (!file_exists($localArchive)) {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2018-02-09 09:50:14 +00:00
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 7
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2018-02-09 09:50:14 +00:00
|
|
|
$text = 'Extract downloaded archive "' . $toExtract . '"?';
|
2022-03-16 13:32:10 +00:00
|
|
|
|
|
|
|
$upd_formfield = [
|
|
|
|
'updates' => [
|
2022-04-28 18:48:00 +00:00
|
|
|
'title' => lng('update.update'),
|
2022-03-16 13:32:10 +00:00
|
|
|
'image' => 'fa-solid fa-download',
|
|
|
|
'sections' => [
|
|
|
|
'section_autoupd' => [
|
|
|
|
'fields' => [
|
|
|
|
'archive' => ['type' => 'hidden', 'value' => $toExtract]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'buttons' => [
|
|
|
|
[
|
|
|
|
'class' => 'btn-outline-secondary',
|
2022-04-28 18:48:00 +00:00
|
|
|
'label' => lng('panel.cancel'),
|
2022-03-16 13:32:10 +00:00
|
|
|
'type' => 'reset'
|
|
|
|
],
|
|
|
|
[
|
2022-04-28 18:48:00 +00:00
|
|
|
'label' => lng('update.proceed')
|
2022-03-16 13:32:10 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2022-03-18 11:53:34 +00:00
|
|
|
UI::view('user/form-note.html.twig', [
|
2022-04-28 18:48:00 +00:00
|
|
|
'formaction' => $linker->getLink(['section' => 'autoupdate', 'page' => 'extract']),
|
2022-03-16 13:32:10 +00:00
|
|
|
'formdata' => $upd_formfield['updates'],
|
|
|
|
// alert
|
|
|
|
'type' => 'warning',
|
|
|
|
'alert_msg' => $text
|
|
|
|
]);
|
2018-12-21 11:24:07 +00:00
|
|
|
} // display error
|
2016-02-08 12:34:24 +00:00
|
|
|
elseif ($page == 'error') {
|
2016-02-16 20:56:32 +00:00
|
|
|
// retrieve error-number via url-parameter
|
2022-04-28 18:48:00 +00:00
|
|
|
$errno = isset($_GET['errno']) ? (int)$_GET['errno'] : 0;
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// 2 = no Zlib
|
|
|
|
// 3 = custom version detected
|
|
|
|
// 4 = could not store archive to local hdd
|
|
|
|
// 5 = some weird value came from version.froxlor.org
|
|
|
|
// 6 = download without valid version
|
|
|
|
// 7 = local archive does not exist
|
|
|
|
// 8 = could not extract archive
|
2016-02-23 20:52:35 +00:00
|
|
|
// 9 = checksum mismatch
|
2022-03-14 21:51:59 +00:00
|
|
|
// 10 = <php-7.4
|
2022-04-20 13:18:50 +00:00
|
|
|
// 11 = enable_webupdate = false
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::standardError('autoupdate_' . $errno);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|