add interval for external update-check; add parameter 'force' to Froxlor.checkUpdate() API call; fix session/language update when changing language

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-07-24 11:47:10 +02:00
parent 771d6c483a
commit b6267e610a
9 changed files with 84 additions and 45 deletions

View File

@@ -254,6 +254,7 @@ if ($page == 'overview') {
'id' => $userinfo['adminid'], 'id' => $userinfo['adminid'],
'def_language' => $def_language 'def_language' => $def_language
])->update(); ])->update();
CurrentUser::setField('language', $def_language);
} catch (Exception $e) { } catch (Exception $e) {
Response::dynamicError($e->getMessage()); Response::dynamicError($e->getMessage());
} }

View File

@@ -215,6 +215,7 @@ if ($page == 'overview') {
'id' => $userinfo['customerid'], 'id' => $userinfo['customerid'],
'def_language' => $def_language 'def_language' => $def_language
])->update(); ])->update();
CurrentUser::setField('language', $def_language);
} catch (Exception $e) { } catch (Exception $e) {
Response::dynamicError($e->getMessage()); Response::dynamicError($e->getMessage());
} }

View File

@@ -82,7 +82,6 @@ if (Froxlor::isFroxlorVersion('0.10.99')) {
} }
Update::lastStepStatus(0); Update::lastStepStatus(0);
Update::showUpdateStep("Cleaning up old files"); Update::showUpdateStep("Cleaning up old files");
$to_clean = array( $to_clean = array(
"install/lib", "install/lib",
@@ -134,6 +133,7 @@ if (Froxlor::isFroxlorVersion('0.10.99')) {
$system_distribution = isset($_POST['system_distribution']) ? $_POST['system_distribution'] : ''; $system_distribution = isset($_POST['system_distribution']) ? $_POST['system_distribution'] : '';
Settings::AddNew("system.distribution", $system_distribution); Settings::AddNew("system.distribution", $system_distribution);
Settings::AddNew("system.update_channel", 'stable'); Settings::AddNew("system.update_channel", 'stable');
Settings::AddNew("system.updatecheck_data", '');
Update::lastStepStatus(0); Update::lastStepStatus(0);
Update::showUpdateStep("Adjusting existing settings"); Update::showUpdateStep("Adjusting existing settings");
@@ -152,9 +152,5 @@ if (Froxlor::isFroxlorVersion('0.10.99')) {
Settings::Set('panel.standardlanguage', $lang_map[Settings::Get('panel_standardlanguage')] ?? 'en'); Settings::Set('panel.standardlanguage', $lang_map[Settings::Get('panel_standardlanguage')] ?? 'en');
Update::lastStepStatus(0); Update::lastStepStatus(0);
Froxlor::updateToVersion('0.11.0-dev1');
if (Froxlor::isFroxlorVersion('0.10.99')) {
Update::showUpdateStep("Updating from 0.10.99 to 0.11.0-dev1", false);
Froxlor::updateToVersion('0.11.0-dev1');
}
} }

View File

@@ -32,6 +32,7 @@ use Froxlor\Database\Database;
use Froxlor\Database\IntegrityCheck; use Froxlor\Database\IntegrityCheck;
use Froxlor\FroxlorLogger; use Froxlor\FroxlorLogger;
use Froxlor\Install\AutoUpdate; use Froxlor\Install\AutoUpdate;
use Froxlor\Install\Update;
use Froxlor\Settings; use Froxlor\Settings;
use Froxlor\SImExporter; use Froxlor\SImExporter;
use Froxlor\System\Cronjob; use Froxlor\System\Cronjob;
@@ -49,9 +50,13 @@ use ReflectionMethod;
class Froxlor extends ApiCommand class Froxlor extends ApiCommand
{ {
const UPDATE_CHECK_INTERVAL = 21600; // 6 hrs
/** /**
* checks whether there is a newer version of froxlor available * checks whether there is a newer version of froxlor available
* *
* @param bool $force optional, force live update-check
*
* @access admin * @access admin
* @return string json-encoded array * @return string json-encoded array
* @throws Exception * @throws Exception
@@ -60,50 +65,62 @@ class Froxlor extends ApiCommand
{ {
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) { if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
// log our actions $uc_data = Update::getUpdateCheckData();
$this->logger()->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] checking for updates");
// check for new version $force_ucheck = $this->getBoolParam('force', true, 0);
$aucheck = AutoUpdate::checkVersion(); $response = $uc_data['data'];
if ($aucheck == 1) { if (empty($uc_data) || $uc_data['ts'] + self::UPDATE_CHECK_INTERVAL < time() || $uc_data['channel'] != Settings::Get('system.update_channel') || $force_ucheck) {
// anzeige über version-status mit ggfls. formular // log our actions
// zum update schritt #1 -> download $this->logger()->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] checking for updates");
$text = 'There is a newer ' . (Settings::Get('system.update_channel') == 'testing' ? 'testing ' : '') . 'version available: "' . AutoUpdate::getFromResult('version') . '" (Your current version is: ' . $this->version . ')';
return $this->response([ // check for new version
'isnewerversion' => (int) !AutoUpdate::getFromResult('has_latest'), $aucheck = AutoUpdate::checkVersion();
'version' => $this->version,
'message' => $text, $response = [];
'link' => AutoUpdate::getFromResult('url'), if ($aucheck == 1) {
'additional_info' => AutoUpdate::getFromResult('info') // anzeige über version-status mit ggfls. formular
]); // zum update schritt #1 -> download
} else if ($aucheck < 0 || $aucheck > 1) { $text = lng('update.uc_newinfo', [(Settings::Get('system.update_channel') == 'testing' ? 'testing ' : ''), AutoUpdate::getFromResult('version'), $this->version]);
// errors $response = [
if ($aucheck < 0) { 'isnewerversion' => (int) !AutoUpdate::getFromResult('has_latest'),
$errmsg = AutoUpdate::getLastError(); 'version' => $this->version,
} else { 'message' => $text,
if ($aucheck == 3) { 'link' => AutoUpdate::getFromResult('url'),
$errmsg = lng('error.customized_version'); 'additional_info' => AutoUpdate::getFromResult('info')
];
} else if ($aucheck < 0 || $aucheck > 1) {
// errors
if ($aucheck < 0) {
$errmsg = AutoUpdate::getLastError();
} else { } else {
$errmsg = lng('error.autoupdate_' . $aucheck); if ($aucheck == 3) {
$errmsg = lng('error.customized_version');
} else {
$errmsg = lng('error.autoupdate_' . $aucheck);
}
} }
$response = [
'isnewerversion' => 0,
'version' => $this->version,
'message' => '',
'link' => '',
'additional_info' => $errmsg
];
} else {
$response = [
'isnewerversion' => 0,
'version' => $this->version,
'message' => '',
'link' => '',
'additional_info' => lng('update.noupdatesavail', [(Settings::Get('system.update_channel') == 'testing' ? lng('serversettings.uc_testing') . ' ' : '')])
];
} }
return $this->response([
'isnewerversion' => 0, Update::storeUpdateCheckData($response);
'version' => $this->version,
'message' => '',
'link' => '',
'additional_info' => $errmsg
]);
} else {
return $this->response([
'isnewerversion' => 0,
'version' => $this->version,
'message' => '',
'link' => '',
'additional_info' => lng('update.noupdatesavail', [(Settings::Get('system.update_channel') == 'testing' ? lng('serversettings.uc_testing') . ' ' : '')])
]);
} }
return $this->response($response);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new Exception("Not allowed to execute given command.", 403);
} }

View File

@@ -27,6 +27,7 @@ namespace Froxlor\Install;
use Froxlor\Froxlor; use Froxlor\Froxlor;
use Froxlor\FroxlorLogger; use Froxlor\FroxlorLogger;
use Froxlor\Settings;
class Update class Update
{ {
@@ -106,4 +107,24 @@ class Update
return Froxlor::versionCompare2($current_version, $version_to_check) == -1; return Froxlor::versionCompare2($current_version, $version_to_check) == -1;
} }
public static function storeUpdateCheckData(array $response)
{
$data = [
'ts' => time(),
'channel' => Settings::Get('system.update_channel'),
'data' => $response
];
Settings::Set('system.updatecheck_data', json_encode($data));
}
public static function getUpdateCheckData()
{
$uc_data = Settings::Get('system.updatecheck_data');
if (!empty($uc_data)) {
$data = json_decode($uc_data, true);
return $data;
}
return null;
}
} }

View File

@@ -119,5 +119,6 @@ class Language
public static function setLanguage(string $string) public static function setLanguage(string $string)
{ {
self::$requestedLanguage = $string; self::$requestedLanguage = $string;
self::$lng = null;
} }
} }

View File

@@ -2116,6 +2116,7 @@ Vielen Dank, Ihr Administrator',
], ],
'noupdatesavail' => 'Die genutzte %sVersion von Froxlor ist aktuell.', 'noupdatesavail' => 'Die genutzte %sVersion von Froxlor ist aktuell.',
'description' => 'Aktualisierung der froxlor Datenbank', 'description' => 'Aktualisierung der froxlor Datenbank',
'uc_newinfo' => 'Eine neuere %sVersion ist verfügbar: "%s" (Aktuell installierte Version: %s)',
], ],
'usersettings' => [ 'usersettings' => [
'custom_notes' => [ 'custom_notes' => [

View File

@@ -2501,6 +2501,7 @@ Yours sincerely, your administrator',
], ],
'noupdatesavail' => 'You already have the latest %sversion of Froxlor installed.', 'noupdatesavail' => 'You already have the latest %sversion of Froxlor installed.',
'description' => 'Running database updates for your froxlor installation', 'description' => 'Running database updates for your froxlor installation',
'uc_newinfo' => 'There is a newer %sversion available: "%s" (Your current version is: %s)',
], ],
'usersettings' => [ 'usersettings' => [
'custom_notes' => [ 'custom_notes' => [

View File

@@ -34,7 +34,7 @@
<form id="search" method="post"> <form id="search" method="post">
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<i class="fa fa-search text-muted"></i> <i class="fa fa-search text-muted"></i>
<input title="search" type="search" class="search-input" placeholder="Search for ..."> <input title="search" type="search" class="search-input" placeholder="{{ lng('panel.search') }}...">
</div> </div>
<div class="search-results-box" style="display:none;"> <div class="search-results-box" style="display:none;">
<div class="search-results list-group-flush"></div> <div class="search-results list-group-flush"></div>