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-05-22 18:18:18 +00:00
|
|
|
use Froxlor\Install\AutoUpdate;
|
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
|
|
|
|
2022-04-20 14:12:42 +00:00
|
|
|
if ($page != 'error') {
|
|
|
|
// 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 {
|
2022-05-22 18:18:18 +00:00
|
|
|
$result = AutoUpdate::checkVersion();
|
2022-04-28 18:48:00 +00:00
|
|
|
} catch (Exception $e) {
|
2022-05-22 18:18:18 +00:00
|
|
|
Response::dynamicError($e->getMessage());
|
2019-10-06 16:53:30 +00:00
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2022-05-22 18:18:18 +00:00
|
|
|
if ($result == 1) {
|
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
|
2022-05-22 18:18:18 +00:00
|
|
|
$text = lng('admin.newerversionavailable') . ' ' . lng('admin.newerversiondetails', [AutoUpdate::getFromResult('version'), Froxlor::VERSION]);
|
|
|
|
|
|
|
|
$upd_formfield = [
|
|
|
|
'updates' => [
|
|
|
|
'title' => lng('update.update'),
|
|
|
|
'image' => 'fa-solid fa-download',
|
|
|
|
'sections' => [
|
|
|
|
'section_autoupd' => [
|
|
|
|
'fields' => [
|
|
|
|
'newversion' => ['type' => 'hidden', 'value' => AutoUpdate::getFromResult('version')]
|
2022-03-16 13:32:10 +00:00
|
|
|
]
|
2022-05-22 18:18:18 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'buttons' => [
|
|
|
|
[
|
|
|
|
'class' => 'btn-outline-secondary',
|
|
|
|
'label' => lng('panel.cancel'),
|
|
|
|
'type' => 'reset'
|
2022-03-16 13:32:10 +00:00
|
|
|
],
|
2022-05-22 18:18:18 +00:00
|
|
|
[
|
|
|
|
'label' => lng('update.proceed')
|
2022-03-16 13:32:10 +00:00
|
|
|
]
|
|
|
|
]
|
2022-05-22 18:18:18 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
UI::view('user/form-note.html.twig', [
|
|
|
|
'formaction' => $linker->getLink(['section' => 'autoupdate', 'page' => 'getdownload']),
|
|
|
|
'formdata' => $upd_formfield['updates'],
|
|
|
|
// alert
|
|
|
|
'type' => 'warning',
|
|
|
|
'alert_msg' => $text
|
|
|
|
]);
|
|
|
|
} else if ($result < 0 || $result > 1) {
|
|
|
|
// remote errors
|
|
|
|
if ($result < 0) {
|
|
|
|
Response::dynamicError(AutoUpdate::getLastError());
|
2018-02-09 09:50:14 +00:00
|
|
|
} else {
|
2022-05-22 18:18:18 +00:00
|
|
|
Response::redirectTo($filename, [
|
|
|
|
'page' => 'error',
|
|
|
|
'errno' => $result
|
|
|
|
]);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2022-05-22 18:18:18 +00:00
|
|
|
} else {
|
|
|
|
// no new version
|
2022-05-26 12:06:32 +00:00
|
|
|
Response::standardSuccess('update.noupdatesavail', [(Settings::Get('system.update_channel') == 'testing' ? lng('serversettings.uc_testing') . ' ' : '')]);
|
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
|
|
|
|
2022-05-22 18:18:18 +00:00
|
|
|
$result = 6;
|
2016-02-08 12:34:24 +00:00
|
|
|
// valid?
|
|
|
|
if ($newversion !== null) {
|
2022-05-22 18:18:18 +00:00
|
|
|
$result = AutoUpdate::downloadZip($newversion);
|
|
|
|
if (!is_numeric($result)) {
|
|
|
|
// to the next step
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2022-05-22 18:18:18 +00:00
|
|
|
'page' => 'extract',
|
|
|
|
'archive' => $result
|
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',
|
2022-05-22 18:18:18 +00:00
|
|
|
'errno' => $result
|
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;
|
2022-05-22 18:18:18 +00:00
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "Extracting " . $localArchive . " to " . Froxlor::getInstallDir());
|
|
|
|
$result = AutoUpdate::extractZip($localArchive);
|
|
|
|
if ($result > 0) {
|
2016-02-08 12:34:24 +00:00
|
|
|
// error
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo($filename, [
|
2018-02-09 09:50:14 +00:00
|
|
|
'page' => 'error',
|
2022-05-22 18:18:18 +00:00
|
|
|
'errno' => $result
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2022-05-22 18:18:18 +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
|
|
|
|
2022-05-22 18:18:18 +00:00
|
|
|
$text = lng('admin.extractdownloadedzip', [$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-05-02 06:56:39 +00:00
|
|
|
$errmsg = 'autoupdate_' . $errno;
|
|
|
|
if ($errno == 3) {
|
|
|
|
$errmsg = 'customized_version';
|
|
|
|
}
|
|
|
|
Response::standardError($errmsg);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|