introduce static configs to enable/disable web-update (and possibly more later on)

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-04-20 15:18:50 +02:00
parent b362c1f232
commit ebceab96b4
6 changed files with 68 additions and 7 deletions

View File

@@ -45,6 +45,14 @@ if (version_compare("7.4.0", PHP_VERSION, ">=")) {
)); ));
} }
// check for webupdate to be enabled
if (\Froxlor\Settings::Config('enable_webupdate') != true) {
\Froxlor\UI\Response::redirectTo($filename, array(
'page' => 'error',
'errno' => 11
));
}
// display initial version check // display initial version check
if ($page == 'overview') { if ($page == 'overview') {
@@ -281,5 +289,6 @@ elseif ($page == 'error') {
// 8 = could not extract archive // 8 = could not extract archive
// 9 = checksum mismatch // 9 = checksum mismatch
// 10 = <php-7.4 // 10 = <php-7.4
// 11 = enable_webupdate = false
\Froxlor\UI\Response::standard_error('autoupdate_' . $errno); \Froxlor\UI\Response::standard_error('autoupdate_' . $errno);
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace Froxlor; namespace Froxlor;
use Froxlor\Database\Database; use Froxlor\Database\Database;
@@ -43,6 +44,13 @@ class Settings
*/ */
private static $data = null; private static $data = null;
/**
* local config overrides
*
* @var array
*/
private static $conf = null;
/** /**
* changed and unsaved settings data * changed and unsaved settings data
* *
@@ -65,6 +73,7 @@ class Settings
{ {
if (empty(self::$data)) { if (empty(self::$data)) {
self::readSettings(); self::readSettings();
self::readConfig();
self::$updatedata = array(); self::$updatedata = array();
// prepare statement // prepare statement
@@ -92,6 +101,24 @@ class Settings
return true; return true;
} }
/**
* Read in all config overrides from
* config/config.inc.php
*/
private static function readConfig()
{
// set defaults
self::$conf = [
'enable_webupdate' => false
];
$configfile = Froxlor::getInstallDir() . '/lib/config.inc.php';
if (@file_exists($configfile) && is_readable($configfile)) {
self::$conf = include $configfile;
}
return true;
}
/** /**
* update a value in the database * update a value in the database
* *
@@ -122,7 +149,7 @@ class Settings
self::init(); self::init();
$sstr = explode(".", $setting); $sstr = explode(".", $setting);
// no separator - do'h // no separator - do'h
if (! isset($sstr[1])) { if (!isset($sstr[1])) {
return null; return null;
} }
$result = null; $result = null;
@@ -170,7 +197,7 @@ class Settings
if (self::Get($setting) !== null) { if (self::Get($setting) !== null) {
// set new value in array // set new value in array
$sstr = explode(".", $setting); $sstr = explode(".", $setting);
if (! isset($sstr[1])) { if (!isset($sstr[1])) {
return false; return false;
} }
self::$data[$sstr[0]][$sstr[1]] = $value; self::$data[$sstr[0]][$sstr[1]] = $value;
@@ -179,12 +206,12 @@ class Settings
self::storeSetting($sstr[0], $sstr[1], $value); self::storeSetting($sstr[0], $sstr[1], $value);
} else { } else {
// set temporary data for usage // set temporary data for usage
if (! isset(self::$data[$sstr[0]]) || ! is_array(self::$data[$sstr[0]])) { if (!isset(self::$data[$sstr[0]]) || !is_array(self::$data[$sstr[0]])) {
self::$data[$sstr[0]] = array(); self::$data[$sstr[0]] = array();
} }
self::$data[$sstr[0]][$sstr[1]] = $value; self::$data[$sstr[0]][$sstr[1]] = $value;
// set update-data when invoking Flush() // set update-data when invoking Flush()
if (! isset(self::$updatedata[$sstr[0]]) || ! is_array(self::$updatedata[$sstr[0]])) { if (!isset(self::$updatedata[$sstr[0]]) || !is_array(self::$updatedata[$sstr[0]])) {
self::$updatedata[$sstr[0]] = array(); self::$updatedata[$sstr[0]] = array();
} }
self::$updatedata[$sstr[0]][$sstr[1]] = $value; self::$updatedata[$sstr[0]][$sstr[1]] = $value;
@@ -210,7 +237,7 @@ class Settings
if (self::Get($setting) === null) { if (self::Get($setting) === null) {
// validate parameter // validate parameter
$sstr = explode(".", $setting); $sstr = explode(".", $setting);
if (! isset($sstr[1])) { if (!isset($sstr[1])) {
return false; return false;
} }
// prepare statement // prepare statement
@@ -291,7 +318,7 @@ class Settings
'varname' => $field_details['varname'] 'varname' => $field_details['varname']
)); ));
if (! empty($row)) { if (!empty($row)) {
$varvalue = $row['value']; $varvalue = $row['value'];
} else { } else {
$varvalue = $field_details['default']; $varvalue = $field_details['default'];
@@ -306,4 +333,19 @@ class Settings
} }
} }
} }
/**
* get value from config by identifier
*/
public static function Config(string $config)
{
self::init();
$sstr = explode(".", $config);
$result = self::$conf;
foreach ($sstr as $key) {
$result = $result[$key] ?? null;
if (empty($result)) break;
}
return $result;
}
} }

8
lib/config.inc.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
/**
* change the options below to either true or false
*/
return [
'enable_webupdate' => false
];

View File

@@ -228,7 +228,7 @@ return array(
'url' => 'admin_autoupdate.php?page=overview', 'url' => 'admin_autoupdate.php?page=overview',
'label' => $lng['admin']['autoupdate'], 'label' => $lng['admin']['autoupdate'],
'required_resources' => 'change_serversettings', 'required_resources' => 'change_serversettings',
'show_element' => extension_loaded('zip') 'show_element' => extension_loaded('zip') && \Froxlor\Settings::Config('enable_webupdate')
), ),
array( array(
'url' => 'admin_settings.php?page=wipecleartextmailpws', 'url' => 'admin_settings.php?page=wipecleartextmailpws',

View File

@@ -1878,6 +1878,7 @@ $lng['error']['autoupdate_7'] = 'The downloaded archive could not be found :(';
$lng['error']['autoupdate_8'] = 'The archive could not be extracted :('; $lng['error']['autoupdate_8'] = 'The archive could not be extracted :(';
$lng['error']['autoupdate_9'] = 'The downloaded file did not pass the integrity check. Please try to update again.'; $lng['error']['autoupdate_9'] = 'The downloaded file did not pass the integrity check. Please try to update again.';
$lng['error']['autoupdate_10'] = 'Minimum supported version of PHP is 7.4.0'; $lng['error']['autoupdate_10'] = 'Minimum supported version of PHP is 7.4.0';
$lng['error']['autoupdate_11'] = 'Webupdate is disabled';
$lng['admin']['server_php'] = 'PHP'; $lng['admin']['server_php'] = 'PHP';
$lng['domains']['termination_date'] = 'Date of termination'; $lng['domains']['termination_date'] = 'Date of termination';

View File

@@ -1525,6 +1525,7 @@ $lng['error']['autoupdate_7'] = 'Das heruntergeladene Archiv konnte nicht gefund
$lng['error']['autoupdate_8'] = 'Das Archiv konnte nicht entpackt werden :('; $lng['error']['autoupdate_8'] = 'Das Archiv konnte nicht entpackt werden :(';
$lng['error']['autoupdate_9'] = 'Die heruntergeladene Datei konnte nicht verifiziert werden. Bitte erneut versuchen zu aktualisieren.'; $lng['error']['autoupdate_9'] = 'Die heruntergeladene Datei konnte nicht verifiziert werden. Bitte erneut versuchen zu aktualisieren.';
$lng['error']['autoupdate_10'] = 'Minimum unterstützte Version von PHP ist 7.4.0'; $lng['error']['autoupdate_10'] = 'Minimum unterstützte Version von PHP ist 7.4.0';
$lng['error']['autoupdate_11'] = 'Webupdate ist deaktiviert';
$lng['domains']['termination_date'] = 'Kündigungsdatum'; $lng['domains']['termination_date'] = 'Kündigungsdatum';
$lng['domains']['termination_date_overview'] = 'gekündigt zum '; $lng['domains']['termination_date_overview'] = 'gekündigt zum ';