From 7c33625f4b9b390072caae980b554eaf6bb0bb2c Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Mon, 25 Apr 2022 15:00:16 +0200 Subject: [PATCH 01/12] - resolve php warning --- install/lib/installer_base.lib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index a73b9d0922..b7e22d6ace 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -83,13 +83,13 @@ class installer_base { global $autoinstall, $autoupdate; $finished = false; do { - if($name != '' && $autoinstall[$name] != '') { + if($name != '' && isset($autoinstall[$name]) && $autoinstall[$name] != '') { if($autoinstall[$name] == 'default') { $input = $default; } else { $input = $autoinstall[$name]; } - } elseif($name != '' && $autoupdate[$name] != '') { + } elseif($name != '' && isset($autoupdate[$name]) && $autoupdate[$name] != '') { if($autoupdate[$name] == 'default') { $input = $default; } else { @@ -126,13 +126,13 @@ class installer_base { public function free_query($query, $default, $name = '') { global $autoinstall, $autoupdate; - if($name != '' && $autoinstall[$name] != '') { + if($name != '' && isset($autoinstall[$name]) && $autoinstall[$name] != '') { if($autoinstall[$name] == 'default') { $input = $default; } else { $input = $autoinstall[$name]; } - } elseif($name != '' && $autoupdate[$name] != '') { + } elseif($name != '' && isset($autoupdate[$name]) && $autoupdate[$name] != '') { if($autoupdate[$name] == 'default') { $input = $default; } else { -- GitLab From 0b6c05545bcce3669d30d0e6f0eec40b30d292b7 Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Mon, 25 Apr 2022 17:05:47 +0200 Subject: [PATCH 02/12] - set mysqli reporting to OFF as it was prior to PHP 8.1 --- install/lib/installer_base.lib.php | 2 +- install/lib/mysql.lib.php | 30 ++++++++++--------- interface/lib/classes/db_mysql.inc.php | 2 ++ server/lib/classes/db_mysql.inc.php | 2 ++ .../mysql_clientdb_plugin.inc.php | 21 ++++++++----- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index b7e22d6ace..a38e49dd1a 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -249,7 +249,7 @@ class installer_base { $msg = ''; if(version_compare(phpversion(), '5.4', '<')) $msg .= "PHP Version 5.4 or newer is required. The currently used PHP version is ".phpversion().".\n"; - if(version_compare(phpversion(), '8.0', '>=')) $msg .= "PHP Version 8 is not supported yet. Change PHP version back to the default version of the OS. The currently used PHP version is ".phpversion().".\n"; + if(version_compare(phpversion(), '8.2', '>=')) $msg .= "PHP Version 8.2+ is not supported yet. Change PHP version back to the default version of the OS. The currently used PHP version is ".phpversion().".\n"; if(!function_exists('curl_init')) $msg .= "PHP Curl Module is missing.\n"; if(!function_exists('mysqli_connect')) $msg .= "PHP MySQLi Module is nmissing.\n"; if(!function_exists('mb_detect_encoding')) $msg .= "PHP Multibyte Module (MB) is missing.\n"; diff --git a/install/lib/mysql.lib.php b/install/lib/mysql.lib.php index 1085ed0d5b..4d9e71f44a 100644 --- a/install/lib/mysql.lib.php +++ b/install/lib/mysql.lib.php @@ -64,9 +64,11 @@ class db public function __destruct() { if($this->_iConnId) mysqli_close($this->_iConnId); } - + private function do_connect() { global $conf; + + mysqli_report(MYSQLI_REPORT_OFF); if($this->_iConnId) return true; $this->dbHost = $conf['mysql']['host']; @@ -77,7 +79,7 @@ class db $this->dbCharset = $conf["mysql"]["charset"]; $this->dbNewLink = false; $this->dbClientFlags = null; - + $this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort); $try = 0; while((!is_object($this->_iConnId) || mysqli_connect_error()) && $try < 5) { @@ -92,19 +94,19 @@ class db $this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!'); return false; } - + if($this->dbName) $this->setDBName($this->dbName); $this->_setCharset(); } - + public function setDBData($host, $user, $password, $port) { $this->dbHost = $host; $this->dbUser = $user; $this->dbPass = $password; $this->dbPort = $port; } - + public function setDBName($name) { $this->dbName = $name; $this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort); @@ -114,7 +116,7 @@ class db return false; } } - + public function close() { if($this->_iConnId) mysqli_close($this->_iConnId); $this->_iConnId = null; @@ -192,7 +194,7 @@ class db } private function _query($sQuery = '') { - + $aArgs = func_get_args(); $this->do_connect(); @@ -284,7 +286,7 @@ class db * @return array result row or NULL if none found */ public function queryOneRecord($sQuery = '') { - + $aArgs = func_get_args(); if(!empty($aArgs)) { $sQuery = array_shift($aArgs); @@ -293,7 +295,7 @@ class db } array_unshift($aArgs, $sQuery); } - + $oResult = call_user_func_array([&$this, 'query'], $aArgs); if(!$oResult) return null; @@ -534,7 +536,7 @@ class db if($debug == 1) echo "mySQL Error Message: ".$this->errorMessage; } } - + /* TODO: rewrite SQL */ function update($tablename, $form, $bedingung, $debug = 0) { @@ -761,14 +763,14 @@ class db break; } } - + /** * Get the database type (mariadb or mysql) * * @access public * @return string 'mariadb' or string 'mysql' */ - + public function getDatabaseType() { $tmp = $this->queryOneRecord('SELECT VERSION() as version'); if(stristr($tmp['version'],'mariadb')) { @@ -777,7 +779,7 @@ class db return 'mysql'; } } - + /** * Get the database version * @@ -785,7 +787,7 @@ class db * @param bool $major_version_only = true will return the major version only, e.g. 8 for MySQL 8 * @return string version number */ - + public function getDatabaseVersion($major_version_only = false) { $tmp = $this->queryOneRecord('SELECT VERSION() as version'); $version = explode('-', $tmp['version']); diff --git a/interface/lib/classes/db_mysql.inc.php b/interface/lib/classes/db_mysql.inc.php index cd9c333b22..1bfc9102b6 100644 --- a/interface/lib/classes/db_mysql.inc.php +++ b/interface/lib/classes/db_mysql.inc.php @@ -82,6 +82,8 @@ class db $this->dbClientFlags = ($flags !== NULL) ? $flags : $conf['db_client_flags']; $this->_iConnId = mysqli_init(); + mysqli_report(MYSQLI_REPORT_OFF); + mysqli_real_connect($this->_iConnId, $this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort, NULL, $this->dbClientFlags); for($try=0;(!is_object($this->_iConnId) || mysqli_connect_errno()) && $try < 5;++$try) { sleep($try); diff --git a/server/lib/classes/db_mysql.inc.php b/server/lib/classes/db_mysql.inc.php index 9b9d43b442..723360aa83 100644 --- a/server/lib/classes/db_mysql.inc.php +++ b/server/lib/classes/db_mysql.inc.php @@ -82,6 +82,8 @@ class db $this->dbClientFlags = ($flags !== NULL) ? $flags : $conf['db_client_flags']; $this->_iConnId = mysqli_init(); + mysqli_report(MYSQLI_REPORT_OFF); + mysqli_real_connect($this->_iConnId, $this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort, NULL, $this->dbClientFlags); for($try=0;(!is_object($this->_iConnId) || mysqli_connect_errno()) && $try < 5;++$try) { sleep($try); diff --git a/server/plugins-available/mysql_clientdb_plugin.inc.php b/server/plugins-available/mysql_clientdb_plugin.inc.php index 4d637ef37f..9cf750a84d 100644 --- a/server/plugins-available/mysql_clientdb_plugin.inc.php +++ b/server/plugins-available/mysql_clientdb_plugin.inc.php @@ -166,9 +166,9 @@ class mysql_clientdb_plugin { $link->escape_string($database_password)); if(!$link->query($query)) $success = false; } - + $app->log("PASSWORD SET FOR '".$link->escape_string($database_user)."'@'$db_host' success? " . ($success ? 'yes' : 'no'), LOGLEVEL_DEBUG); - + if($success == true){ $link->query("FLUSH PRIVILEGES"); } @@ -261,6 +261,7 @@ class mysql_clientdb_plugin { return; } + mysqli_report(MYSQLI_REPORT_OFF); //* Connect to the database $link = new mysqli($clientdb_host, $clientdb_user, $clientdb_password); if ($link->connect_error) { @@ -324,6 +325,7 @@ class mysql_clientdb_plugin { return; } + mysqli_report(MYSQLI_REPORT_OFF); //* Connect to the database $link = new mysqli($clientdb_host, $clientdb_user, $clientdb_password); if ($link->connect_error) { @@ -654,6 +656,7 @@ class mysql_clientdb_plugin { return; } + mysqli_report(MYSQLI_REPORT_OFF); //* Connect to the database $link = new mysqli($clientdb_host, $clientdb_user, $clientdb_password); if ($link->connect_error) { @@ -709,6 +712,7 @@ class mysql_clientdb_plugin { return; } + mysqli_report(MYSQLI_REPORT_OFF); //* Connect to the database $link = new mysqli($clientdb_host, $clientdb_user, $clientdb_password); if ($link->connect_error) { @@ -782,6 +786,7 @@ class mysql_clientdb_plugin { return; } + mysqli_report(MYSQLI_REPORT_OFF); //* Connect to the database $link = new mysqli($clientdb_host, $clientdb_user, $clientdb_password); if ($link->connect_error) { @@ -807,16 +812,16 @@ class mysql_clientdb_plugin { $link->close(); } - - - - + + + + function getDatabaseType($link) { $result = $link->query('SELECT VERSION() as version'); if($result) { $tmp = $result->fetch_assoc(); $result->free(); - + if(stristr($tmp['version'],'mariadb')) { return 'mariadb'; } else { @@ -832,7 +837,7 @@ class mysql_clientdb_plugin { if($result) { $tmp = $result->fetch_assoc(); $result->free(); - + $version = explode('-', $tmp['version']); if($major_version_only == true) { $version_parts = explode('.', $version[0]); -- GitLab From 3fb40e5846e942fb41f41d37b2f6a6159d5749ec Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Mon, 25 Apr 2022 17:15:56 +0200 Subject: [PATCH 03/12] - prevent undefined var in loop count for tpl lib --- install/lib/classes/tpl.inc.php | 21 ++++++++++++++++---- install/lib/installer_base.lib.php | 8 ++++---- interface/lib/classes/tpl.inc.php | 31 +++++++++++++++++------------- server/lib/classes/tpl.inc.php | 21 ++++++++++++-------- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/install/lib/classes/tpl.inc.php b/install/lib/classes/tpl.inc.php index 5bd8ded1f8..342b4125f8 100644 --- a/install/lib/classes/tpl.inc.php +++ b/install/lib/classes/tpl.inc.php @@ -931,12 +931,17 @@ if (!defined('vlibTemplateClassLoaded')) { { array_push($this->_namespace, $varname); $tempvar = count($this->_namespace) - 1; - $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < count(\$this->_arrvars"; + $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars"; for ($i=0; $i < count($this->_namespace); $i++) { $retstr .= "['".$this->_namespace[$i]."']"; if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; } - return $retstr."); \$_".$tempvar."++) {"; + $retstr .= ") ? count(\$this->_arrvars"; + for ($i=0; $i < count($this->_namespace); $i++) { + $retstr .= "['".$this->_namespace[$i]."']"; + if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; + } + return $retstr.") : 0); \$_".$tempvar."++) {"; } /** @@ -1035,7 +1040,7 @@ if (!defined('vlibTemplateClassLoaded')) { $wholetag = $args[0]; $openclose = $args[1]; $tag = strtolower($args[2]); - + if ($tag == 'else') return ''; if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags @@ -1170,7 +1175,15 @@ if (!defined('vlibTemplateClassLoaded')) { array_push($this->_currentincludedir, dirname($this->_tmplfilename)); $this->_includedepth++; - $success = @eval($this->_tmplfilep); + try { + $success = @eval($this->_tmplfilep); + } catch(Exception $ex) { + print $this->_tmplfilep; + throw $ex; + } catch(TypeError $ex) { + print $this->_tmplfilep; + throw $ex; + } $this->_includedepth--; array_pop($this->_currentincludedir); diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index a38e49dd1a..fc27fba678 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -1914,10 +1914,10 @@ class installer_base { } $tpl->setVar('dkim_path', $mail_config['dkim_path']); - $tpl->setVar('rspamd_redis_servers', $mail_config['rspamd_redis_servers']); - $tpl->setVar('rspamd_redis_password', $mail_config['rspamd_redis_password']); - $tpl->setVar('rspamd_redis_bayes_servers', $mail_config['rspamd_redis_bayes_servers']); - $tpl->setVar('rspamd_redis_bayes_password', $mail_config['rspamd_redis_bayes_password']); + $tpl->setVar('rspamd_redis_servers', (isset($mail_config['rspamd_redis_servers']) ? $mail_config['rspamd_redis_servers'] : '')); + $tpl->setVar('rspamd_redis_password', (isset($mail_config['rspamd_redis_password']) ? $mail_config['rspamd_redis_password'] : '')); + $tpl->setVar('rspamd_redis_bayes_servers', (isset($mail_config['rspamd_redis_bayes_servers']) ? $mail_config['rspamd_redis_bayes_servers'] : '')); + $tpl->setVar('rspamd_redis_bayes_password', (isset($mail_config['rspamd_redis_bayes_password']) ? $mail_config['rspamd_redis_bayes_password'] : '')); if(count($local_addrs) > 0) { $tpl->setLoop('local_addrs', $local_addrs); } diff --git a/interface/lib/classes/tpl.inc.php b/interface/lib/classes/tpl.inc.php index efaf4c072a..8c7f51b8c7 100644 --- a/interface/lib/classes/tpl.inc.php +++ b/interface/lib/classes/tpl.inc.php @@ -233,7 +233,7 @@ if (!defined('vlibTemplateClassLoaded')) { public function setVar($k, $v = null, $encode = false) { global $app; - + if (is_array($k)) { foreach($k as $key => $value){ $key = ($this->OPTIONS['CASELESS']) ? strtolower(trim($key)) : trim($key); @@ -1079,12 +1079,12 @@ if (!defined('vlibTemplateClassLoaded')) { private function _parseHook ($name) { global $app; - + if(!$name) return false; - + $module = isset($_SESSION['s']['module']['name']) ? $_SESSION['s']['module']['name'] : ''; $form = isset($app->tform->formDef['name']) ? $app->tform->formDef['name'] : ''; - + $events = array(); if($module) { $events[] = $module . ':' . ($form ? $form : '') . ':' . $name; @@ -1093,9 +1093,9 @@ if (!defined('vlibTemplateClassLoaded')) { $events[] = $name; $events[] = 'on_template_content'; } - + $events = array_unique($events); - + for($e = 0; $e < count($events); $e++) { $tmpresult = $app->plugin->raiseEvent($events[$e], array( 'name' => $name, @@ -1104,10 +1104,10 @@ if (!defined('vlibTemplateClassLoaded')) { ), true); if(!$tmpresult) $tmpresult = ''; else $tmpresult = $this->_getData($tmpresult, false, true); - + $result .= $tmpresult; } - + return $result; } @@ -1121,12 +1121,17 @@ if (!defined('vlibTemplateClassLoaded')) { { array_push($this->_namespace, $varname); $tempvar = count($this->_namespace) - 1; - $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < count(\$this->_arrvars"; + $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars"; for ($i=0; $i < count($this->_namespace); $i++) { $retstr .= "['".$this->_namespace[$i]."']"; if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; } - return $retstr."); \$_".$tempvar."++) {"; + $retstr .= ") ? count(\$this->_arrvars"; + for ($i=0; $i < count($this->_namespace); $i++) { + $retstr .= "['".$this->_namespace[$i]."']"; + if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; + } + return $retstr.") : 0); \$_".$tempvar."++) {"; } /** @@ -1225,7 +1230,7 @@ if (!defined('vlibTemplateClassLoaded')) { $wholetag = $args[0]; $openclose = $args[1]; $tag = strtolower($args[2]); - + if ($tag == 'else') return ''; if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags @@ -1303,10 +1308,10 @@ if (!defined('vlibTemplateClassLoaded')) { if ($this->OPTIONS['ENABLE_PHPINCLUDE']) { return ''; } - + case 'hook': return $this->_parseHook(@$var); - + case 'include': return '_getData($this->_fileSearch(\''.$file.'\'), 1); ?>'; diff --git a/server/lib/classes/tpl.inc.php b/server/lib/classes/tpl.inc.php index 70dc2e783c..2af1bf141b 100644 --- a/server/lib/classes/tpl.inc.php +++ b/server/lib/classes/tpl.inc.php @@ -1074,10 +1074,10 @@ if (!defined('vlibTemplateClassLoaded')) { private function _parseHook ($name) { global $app; - + $namespace = ''; if(strpos($name, ':') !== false) list($namespace, $name) = explode(':', $name, 2); - + $result = $app->plugins->raiseAction('on_template_content_hook', array( 'name' => $name, 'namespace' => $namespace, @@ -1085,7 +1085,7 @@ if (!defined('vlibTemplateClassLoaded')) { ), true); if(!$result) $result = ''; else $result = $this->_getData($result, false, true); - + return $result; } @@ -1099,12 +1099,17 @@ if (!defined('vlibTemplateClassLoaded')) { { array_push($this->_namespace, $varname); $tempvar = count($this->_namespace) - 1; - $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < count(\$this->_arrvars"; + $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars"; + for ($i=0; $i < count($this->_namespace); $i++) { + $retstr .= "['".$this->_namespace[$i]."']"; + if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; + } + $retstr .= ") ? count(\$this->_arrvars"; for ($i=0; $i < count($this->_namespace); $i++) { $retstr .= "['".$this->_namespace[$i]."']"; if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; } - return $retstr."); \$_".$tempvar."++) {"; + return $retstr.") : 0); \$_".$tempvar."++) {"; } /** @@ -1203,7 +1208,7 @@ if (!defined('vlibTemplateClassLoaded')) { $wholetag = $args[0]; $openclose = $args[1]; $tag = strtolower($args[2]); - + if ($tag == 'else') return ''; if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags @@ -1281,10 +1286,10 @@ if (!defined('vlibTemplateClassLoaded')) { if ($this->OPTIONS['ENABLE_PHPINCLUDE']) { return ''; } - + case 'hook': return $this->_parseHook(@$var); - + case 'include': return '_getData($this->_fileSearch(\''.$file.'\'), 1); ?>'; -- GitLab From acf2114f0b73577c7de00a9d34d84e823c809bdf Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Mon, 25 Apr 2022 17:25:26 +0200 Subject: [PATCH 04/12] - resolve multiple php warnings due to undefined indexes --- install/install.php | 39 ++++++++++++++------------ install/lib/installer_base.lib.php | 7 +++-- server/lib/classes/letsencrypt.inc.php | 6 ++-- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/install/install.php b/install/install.php index 9cc6bb5fa7..64d05feecd 100644 --- a/install/install.php +++ b/install/install.php @@ -508,6 +508,9 @@ if($conf['apparmor']['installed']){ if($install_mode == 'standard' || strtolower($inst->simple_query('Configure Firewall Server', array('y', 'n'), 'y','configure_firewall')) == 'y') { //* Check for Firewall + if(!isset($conf['firewall']['installed'])) { + $conf['firewall']['installed'] = false; + } if(!$conf['ufw']['installed'] && !$conf['firewall']['installed']) { $conf['ufw']['installed'] = $inst->force_configure_app('Ubuntu Firewall', ($install_mode == 'expert')); $conf['firewall']['installed'] = $inst->force_configure_app('Bastille Firewall', ($install_mode == 'expert')); @@ -631,12 +634,12 @@ swriteln('Detect IP addresses'); $inst->detect_ips(); swriteln('Restarting services ...'); -if($conf['mysql']['installed'] == true && $conf['mysql']['init_script'] != '') system($inst->getinitcommand($conf['mysql']['init_script'], 'restart').' >/dev/null 2>&1'); -if($conf['postfix']['installed'] == true && $conf['postfix']['init_script'] != '') system($inst->getinitcommand($conf['postfix']['init_script'], 'restart')); -if($conf['saslauthd']['installed'] == true && $conf['saslauthd']['init_script'] != '') system($inst->getinitcommand($conf['saslauthd']['init_script'], 'restart')); -if($conf['amavis']['installed'] == true && $conf['amavis']['init_script'] != '') system($inst->getinitcommand($conf['amavis']['init_script'], 'restart')); -if($conf['rspamd']['installed'] == true && $conf['rspamd']['init_script'] != '') system($inst->getinitcommand($conf['rspamd']['init_script'], 'restart')); -if($conf['clamav']['installed'] == true && $conf['clamav']['init_script'] != '' && $conf['amavis']['installed'] == true) system($inst->getinitcommand($conf['clamav']['init_script'], 'restart')); +if($conf['mysql']['installed'] == true && isset($conf['mysql']['init_script']) && $conf['mysql']['init_script'] != '') system($inst->getinitcommand($conf['mysql']['init_script'], 'restart').' >/dev/null 2>&1'); +if($conf['postfix']['installed'] == true && isset($conf['postfix']['init_script']) && $conf['postfix']['init_script'] != '') system($inst->getinitcommand($conf['postfix']['init_script'], 'restart')); +if($conf['saslauthd']['installed'] == true && isset($conf['saslauthd']['init_script']) && $conf['saslauthd']['init_script'] != '') system($inst->getinitcommand($conf['saslauthd']['init_script'], 'restart')); +if($conf['amavis']['installed'] == true && isset($conf['amavis']['init_script']) && $conf['amavis']['init_script'] != '') system($inst->getinitcommand($conf['amavis']['init_script'], 'restart')); +if($conf['rspamd']['installed'] == true && isset($conf['rspamd']['init_script']) && $conf['rspamd']['init_script'] != '') system($inst->getinitcommand($conf['rspamd']['init_script'], 'restart')); +if($conf['clamav']['installed'] == true && isset($conf['clamav']['init_script']) && $conf['clamav']['init_script'] != '' && $conf['amavis']['installed'] == true) system($inst->getinitcommand($conf['clamav']['init_script'], 'restart')); if($conf['courier']['installed'] == true){ if($conf['courier']['courier-authdaemon'] != '') system($inst->getinitcommand($conf['courier']['courier-authdaemon'], 'restart')); if($conf['courier']['courier-imap'] != '') system($inst->getinitcommand($conf['courier']['courier-imap'], 'restart')); @@ -644,22 +647,22 @@ if($conf['courier']['installed'] == true){ if($conf['courier']['courier-pop'] != '') system($inst->getinitcommand($conf['courier']['courier-pop'], 'restart')); if($conf['courier']['courier-pop-ssl'] != '') system($inst->getinitcommand($conf['courier']['courier-pop-ssl'], 'restart')); } -if($conf['dovecot']['installed'] == true && $conf['dovecot']['init_script'] != '') system($inst->getinitcommand($conf['dovecot']['init_script'], 'restart')); -if($conf['mailman']['installed'] == true && $conf['mailman']['init_script'] != '') system('nohup '.$inst->getinitcommand($conf['mailman']['init_script'], 'restart').' >/dev/null 2>&1 &'); -if($conf['apache']['installed'] == true && $conf['apache']['init_script'] != '') system($inst->getinitcommand($conf['apache']['init_script'], 'restart')); +if($conf['dovecot']['installed'] == true && isset($conf['dovecot']['init_script']) && $conf['dovecot']['init_script'] != '') system($inst->getinitcommand($conf['dovecot']['init_script'], 'restart')); +if($conf['mailman']['installed'] == true && isset($conf['mailman']['init_script']) && $conf['mailman']['init_script'] != '') system('nohup '.$inst->getinitcommand($conf['mailman']['init_script'], 'restart').' >/dev/null 2>&1 &'); +if($conf['apache']['installed'] == true && isset($conf['apache']['init_script']) && $conf['apache']['init_script'] != '') system($inst->getinitcommand($conf['apache']['init_script'], 'restart')); //* Reload is enough for nginx if($conf['nginx']['installed'] == true){ if($conf['nginx']['php_fpm_init_script'] != '') system($inst->getinitcommand($conf['nginx']['php_fpm_init_script'], 'reload')); - if($conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'reload')); + if(isset($conf['nginx']['init_script']) && $conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'reload')); } -if($conf['pureftpd']['installed'] == true && $conf['pureftpd']['init_script'] != '') system($inst->getinitcommand($conf['pureftpd']['init_script'], 'restart')); -if($conf['mydns']['installed'] == true && $conf['mydns']['init_script'] != '') system($inst->getinitcommand($conf['mydns']['init_script'], 'restart').' &> /dev/null'); -if($conf['powerdns']['installed'] == true && $conf['powerdns']['init_script'] != '') system($inst->getinitcommand($conf['powerdns']['init_script'], 'restart').' &> /dev/null'); -if($conf['bind']['installed'] == true && $conf['bind']['init_script'] != '') system($inst->getinitcommand($conf['bind']['init_script'], 'restart').' &> /dev/null'); -//if($conf['squid']['installed'] == true && $conf['squid']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['squid']['init_script'])) system($conf['init_scripts'].'/'.$conf['squid']['init_script'].' restart &> /dev/null'); -if($conf['nginx']['installed'] == true && $conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'restart').' &> /dev/null'); -if($conf['ufw']['installed'] == true && $conf['ufw']['init_script'] != '') system($inst->getinitcommand($conf['ufw']['init_script'], 'restart').' &> /dev/null'); -if($conf['xmpp']['installed'] == true && $conf['xmpp']['init_script'] != '') system($inst->getinitcommand($conf['xmpp']['init_script'], 'restart').' &> /dev/null'); +if($conf['pureftpd']['installed'] == true && isset($conf['pureftpd']['init_script']) && $conf['pureftpd']['init_script'] != '') system($inst->getinitcommand($conf['pureftpd']['init_script'], 'restart')); +if($conf['mydns']['installed'] == true && isset($conf['mydns']['init_script']) && $conf['mydns']['init_script'] != '') system($inst->getinitcommand($conf['mydns']['init_script'], 'restart').' &> /dev/null'); +if($conf['powerdns']['installed'] == true && isset($conf['powerdns']['init_script']) && $conf['powerdns']['init_script'] != '') system($inst->getinitcommand($conf['powerdns']['init_script'], 'restart').' &> /dev/null'); +if($conf['bind']['installed'] == true && isset($conf['bind']['init_script']) && $conf['bind']['init_script'] != '') system($inst->getinitcommand($conf['bind']['init_script'], 'restart').' &> /dev/null'); +//if($conf['squid']['installed'] == true && isset($conf['squid']['init_script']) && $conf['squid']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['squid']['init_script'])) system($conf['init_scripts'].'/'.$conf['squid']['init_script'].' restart &> /dev/null'); +if($conf['nginx']['installed'] == true && isset($conf['nginx']['init_script']) && $conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'restart').' &> /dev/null'); +if($conf['ufw']['installed'] == true && isset($conf['ufw']['init_script']) && $conf['ufw']['init_script'] != '') system($inst->getinitcommand($conf['ufw']['init_script'], 'restart').' &> /dev/null'); +if($conf['xmpp']['installed'] == true && isset($conf['xmpp']['init_script']) && $conf['xmpp']['init_script'] != '') system($inst->getinitcommand($conf['xmpp']['init_script'], 'restart').' &> /dev/null'); $inst->create_mount_script(); diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index fc27fba678..05ce26bb69 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -3012,12 +3012,15 @@ class installer_base { $hook = $pre_hook . $renew_hook; } + $which_certbot = shell_exec('which certbot /root/.local/share/letsencrypt/bin/letsencrypt /opt/eff.org/certbot/venv/bin/certbot letsencrypt'); + // Get the default LE client name and version - $le_client = explode("\n", shell_exec('which certbot /root/.local/share/letsencrypt/bin/letsencrypt /opt/eff.org/certbot/venv/bin/certbot letsencrypt')); + $le_client = explode("\n", $which_certbot ? $which_certbot : ''); $le_client = reset($le_client); + $which_acme = shell_exec('which acme.sh /usr/local/ispconfig/server/scripts/acme.sh /root/.acme.sh/acme.sh'); // Check for Neilpang acme.sh as well - $acme = explode("\n", shell_exec('which acme.sh /usr/local/ispconfig/server/scripts/acme.sh /root/.acme.sh/acme.sh')); + $acme = explode("\n", $which_acme ? $which_acme : ''); $acme = reset($acme); if((!$acme || !is_executable($acme)) && (!$le_client || !is_executable($le_client))) { diff --git a/server/lib/classes/letsencrypt.inc.php b/server/lib/classes/letsencrypt.inc.php index e78ef2636e..8b7559fc43 100644 --- a/server/lib/classes/letsencrypt.inc.php +++ b/server/lib/classes/letsencrypt.inc.php @@ -44,7 +44,8 @@ class letsencrypt { } public function get_acme_script() { - $acme = explode("\n", shell_exec('which acme.sh /usr/local/ispconfig/server/scripts/acme.sh /root/.acme.sh/acme.sh')); + $which_acme = shell_exec('which acme.sh /usr/local/ispconfig/server/scripts/acme.sh /root/.acme.sh/acme.sh'); + $acme = explode("\n", $which_acme ? $which_acme : ''); $acme = reset($acme); if(is_executable($acme)) { return $acme; @@ -80,7 +81,8 @@ class letsencrypt { } public function get_certbot_script() { - $letsencrypt = explode("\n", shell_exec('which certbot /root/.local/share/letsencrypt/bin/letsencrypt /opt/eff.org/certbot/venv/bin/certbot letsencrypt')); + $which_certbot = shell_exec('which certbot /root/.local/share/letsencrypt/bin/letsencrypt /opt/eff.org/certbot/venv/bin/certbot letsencrypt'); + $letsencrypt = explode("\n", $which_certbot ? $which_certbot : ''); $letsencrypt = reset($letsencrypt); if(is_executable($letsencrypt)) { return $letsencrypt; -- GitLab From 02564b6ece469d05ee1b4448195e0518efbb0485 Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Mon, 25 Apr 2022 17:27:06 +0200 Subject: [PATCH 05/12] - fixed undefined index warnings --- .../z_php_fpm_incron_reload_plugin.inc.php | 2 +- server/server.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/plugins-available/z_php_fpm_incron_reload_plugin.inc.php b/server/plugins-available/z_php_fpm_incron_reload_plugin.inc.php index b2dd92265e..628abe0a2d 100644 --- a/server/plugins-available/z_php_fpm_incron_reload_plugin.inc.php +++ b/server/plugins-available/z_php_fpm_incron_reload_plugin.inc.php @@ -106,7 +106,7 @@ class z_php_fpm_incron_reload_plugin { $app->uses('getconf'); $serverConfig = $app->getconf->get_server_config($conf['server_id'], 'web'); - return $serverConfig['php_fpm_incron_reload'] === 'y'; + return (isset($serverConfig['php_fpm_incron_reload']) && $serverConfig['php_fpm_incron_reload'] === 'y'); } private function createIncronConfiguration($triggerFile, $systemUser, $fastcgiPhpVersion) { diff --git a/server/server.php b/server/server.php index 164451babe..878376a154 100644 --- a/server/server.php +++ b/server/server.php @@ -94,7 +94,7 @@ if ($app->dbmaster->testConnection()) { // retrieve admin email address for notifications $sys_ini = $app->db->queryOneRecord("SELECT * FROM sys_ini WHERE sysini_id = 1"); $conf['sys_ini'] = $app->ini_parser->parse_ini_string(stripslashes($sys_ini['config'])); - $conf['admin_mail'] = $conf['sys_ini']['mail']['admin_mail']; + $conf['admin_mail'] = (isset($conf['sys_ini']['mail']['admin_mail']) ? $conf['sys_ini']['mail']['admin_mail'] : ''); unset($sys_ini); /* @@ -170,9 +170,9 @@ if ($app->db->testConnection() && $app->dbmaster->testConnection()) { $app->modules->loadModules('all'); //** Load the plugins that are in the plugins-enabled folder $app->plugins->loadPlugins('all'); - + $app->plugins->raiseAction('server_plugins_loaded', ''); - + if ($tmp_num_records > 0) { $app->log("Found $tmp_num_records changes, starting update process.", LOGLEVEL_DEBUG); //** Go through the sys_datalog table and call the processing functions -- GitLab From 07fb684d5ff60c4466e49965ffe8a10d010db685 Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Mon, 25 Apr 2022 17:32:01 +0200 Subject: [PATCH 06/12] - fixed undefined index warnings --- install/lib/installer_base.lib.php | 2 +- install/update.php | 36 +++++++++++++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 05ce26bb69..3d73591293 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -1507,7 +1507,7 @@ class installer_base { } $new_options[] = $value; } - if ($configure_lmtp && $conf['mail']['content_filter'] === 'amavisd') { + if ($configure_lmtp && (!isset($conf['mail']['content_filter']) || $conf['mail']['content_filter'] === 'amavisd')) { for ($i = 0; isset($new_options[$i]); $i++) { if ($new_options[$i] == 'reject_unlisted_recipient') { array_splice($new_options, $i+1, 0, array("check_recipient_access proxy:mysql:${config_dir}/mysql-verify_recipients.cf")); diff --git a/install/update.php b/install/update.php index 56316546ac..35a68cccb6 100644 --- a/install/update.php +++ b/install/update.php @@ -562,7 +562,7 @@ if($conf['apache']['installed'] == true) { if ($inst->install_ispconfig_interface) { //** Customise the port ISPConfig runs on $ispconfig_port_number = get_ispconfig_port_number(); - if($autoupdate['ispconfig_port'] == 'default') $autoupdate['ispconfig_port'] = $ispconfig_port_number; + if(isset($autoupdate['ispconfig_port']) && $autoupdate['ispconfig_port'] == 'default') $autoupdate['ispconfig_port'] = $ispconfig_port_number; if($conf['webserver']['server_type'] == 'nginx'){ $conf['nginx']['vhost_port'] = $inst->free_query('ISPConfig Port', $ispconfig_port_number,'ispconfig_port'); } else { @@ -607,13 +607,13 @@ if($update_crontab_answer == 'yes') { //** Restart services: if($reconfigure_services_answer == 'yes') { swriteln('Restarting services ...'); - if($conf['mysql']['installed'] == true && $conf['mysql']['init_script'] != '') system($inst->getinitcommand($conf['mysql']['init_script'], 'restart').' >/dev/null 2>&1'); + if($conf['mysql']['installed'] == true && isset($conf['mysql']['init_script']) && $conf['mysql']['init_script'] != '') system($inst->getinitcommand($conf['mysql']['init_script'], 'restart').' >/dev/null 2>&1'); if($conf['services']['mail']) { - if($conf['postfix']['installed'] == true && $conf['postfix']['init_script'] != '') system($inst->getinitcommand($conf['postfix']['init_script'], 'restart')); - if($conf['saslauthd']['installed'] == true && $conf['saslauthd']['init_script'] != '') system($inst->getinitcommand($conf['saslauthd']['init_script'], 'restart')); - if($conf['amavis']['installed'] == true && $conf['amavis']['init_script'] != '') system($inst->getinitcommand($conf['amavis']['init_script'], 'restart')); - if($conf['rspamd']['installed'] == true && $conf['rspamd']['init_script'] != '') system($inst->getinitcommand($conf['rspamd']['init_script'], 'restart')); - if($conf['clamav']['installed'] == true && $conf['clamav']['init_script'] != '' && $conf['amavis']['installed'] == true) system($inst->getinitcommand($conf['clamav']['init_script'], 'restart')); + if($conf['postfix']['installed'] == true && isset($conf['postfix']['init_script']) && $conf['postfix']['init_script'] != '') system($inst->getinitcommand($conf['postfix']['init_script'], 'restart')); + if($conf['saslauthd']['installed'] == true && isset($conf['saslauthd']['init_script']) && $conf['saslauthd']['init_script'] != '') system($inst->getinitcommand($conf['saslauthd']['init_script'], 'restart')); + if($conf['amavis']['installed'] == true && isset($conf['amavis']['init_script']) && $conf['amavis']['init_script'] != '') system($inst->getinitcommand($conf['amavis']['init_script'], 'restart')); + if($conf['rspamd']['installed'] == true && isset($conf['rspamd']['init_script']) && $conf['rspamd']['init_script'] != '') system($inst->getinitcommand($conf['rspamd']['init_script'], 'restart')); + if($conf['clamav']['installed'] == true && isset($conf['clamav']['init_script']) && $conf['clamav']['init_script'] != '' && $conf['amavis']['installed'] == true) system($inst->getinitcommand($conf['clamav']['init_script'], 'restart')); if($conf['courier']['installed'] == true){ if($conf['courier']['courier-authdaemon'] != '') system($inst->getinitcommand($conf['courier']['courier-authdaemon'], 'restart')); if($conf['courier']['courier-imap'] != '') system($inst->getinitcommand($conf['courier']['courier-imap'], 'restart')); @@ -621,8 +621,8 @@ if($reconfigure_services_answer == 'yes') { if($conf['courier']['courier-pop'] != '') system($inst->getinitcommand($conf['courier']['courier-pop'], 'restart')); if($conf['courier']['courier-pop-ssl'] != '') system($inst->getinitcommand($conf['courier']['courier-pop-ssl'], 'restart')); } - if($conf['dovecot']['installed'] == true && $conf['dovecot']['init_script'] != '') system($inst->getinitcommand($conf['dovecot']['init_script'], 'restart')); - if($conf['mailman']['installed'] == true && $conf['mailman']['init_script'] != '') system('nohup '.$inst->getinitcommand($conf['mailman']['init_script'], 'restart').' >/dev/null 2>&1 &'); + if($conf['dovecot']['installed'] == true && isset($conf['dovecot']['init_script']) && $conf['dovecot']['init_script'] != '') system($inst->getinitcommand($conf['dovecot']['init_script'], 'restart')); + if($conf['mailman']['installed'] == true && isset($conf['mailman']['init_script']) && $conf['mailman']['init_script'] != '') system('nohup '.$inst->getinitcommand($conf['mailman']['init_script'], 'restart').' >/dev/null 2>&1 &'); } if($conf['services']['web'] || $inst->install_ispconfig_interface) { if($conf['webserver']['server_type'] == 'apache') { @@ -636,27 +636,27 @@ if($reconfigure_services_answer == 'yes') { //* Reload is enough for nginx if($conf['webserver']['server_type'] == 'nginx'){ if($conf['nginx']['php_fpm_init_script'] != '') system($inst->getinitcommand($conf['nginx']['php_fpm_init_script'], 'reload')); - if($conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'reload')); + if(isset($conf['nginx']['init_script']) && $conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'reload')); } - if($conf['pureftpd']['installed'] == true && $conf['pureftpd']['init_script'] != '') system($inst->getinitcommand($conf['pureftpd']['init_script'], 'restart')); + if($conf['pureftpd']['installed'] == true && isset($conf['pureftpd']['init_script']) && $conf['pureftpd']['init_script'] != '') system($inst->getinitcommand($conf['pureftpd']['init_script'], 'restart')); } if($conf['services']['dns']) { - if($conf['mydns']['installed'] == true && $conf['mydns']['init_script'] != '') system($inst->getinitcommand($conf['mydns']['init_script'], 'restart').' &> /dev/null'); - if($conf['powerdns']['installed'] == true && $conf['powerdns']['init_script'] != '') system($inst->getinitcommand($conf['powerdns']['init_script'], 'restart').' &> /dev/null'); - if($conf['bind']['installed'] == true && $conf['bind']['init_script'] != '') system($inst->getinitcommand($conf['bind']['init_script'], 'restart').' &> /dev/null'); + if($conf['mydns']['installed'] == true && isset($conf['mydns']['init_script']) && $conf['mydns']['init_script'] != '') system($inst->getinitcommand($conf['mydns']['init_script'], 'restart').' &> /dev/null'); + if($conf['powerdns']['installed'] == true && isset($conf['powerdns']['init_script']) && $conf['powerdns']['init_script'] != '') system($inst->getinitcommand($conf['powerdns']['init_script'], 'restart').' &> /dev/null'); + if($conf['bind']['installed'] == true && isset($conf['bind']['init_script']) && $conf['bind']['init_script'] != '') system($inst->getinitcommand($conf['bind']['init_script'], 'restart').' &> /dev/null'); } if($conf['services']['xmpp']) { - if($conf['xmpp']['installed'] == true && $conf['xmpp']['init_script'] != '') system($inst->getinitcommand($conf['xmpp']['init_script'], 'restart').' &> /dev/null'); + if($conf['xmpp']['installed'] == true && isset($conf['xmpp']['init_script']) && $conf['xmpp']['init_script'] != '') system($inst->getinitcommand($conf['xmpp']['init_script'], 'restart').' &> /dev/null'); } if($conf['services']['proxy']) { - // if($conf['squid']['installed'] == true && $conf['squid']['init_script'] != '' && is_executable($conf['init_scripts'].'/'.$conf['squid']['init_script'])) system($conf['init_scripts'].'/'.$conf['squid']['init_script'].' restart &> /dev/null'); - if($conf['nginx']['installed'] == true && $conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'restart').' &> /dev/null'); + // if($conf['squid']['installed'] == true && isset($conf['squid']['init_script']) && $conf['squid']['init_script'] != '' && is_executable($conf['init_scripts'].'/'.$conf['squid']['init_script'])) system($conf['init_scripts'].'/'.$conf['squid']['init_script'].' restart &> /dev/null'); + if($conf['nginx']['installed'] == true && isset($conf['nginx']['init_script']) && $conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'restart').' &> /dev/null'); } if($conf['services']['firewall']) { - if($conf['ufw']['installed'] == true && $conf['ufw']['init_script'] != '' && is_executable($conf['init_scripts'].'/'.$conf['ufw']['init_script'])) system($conf['init_scripts'].'/'.$conf['ufw']['init_script'].' restart &> /dev/null'); + if($conf['ufw']['installed'] == true && isset($conf['ufw']['init_script']) && $conf['ufw']['init_script'] != '' && is_executable($conf['init_scripts'].'/'.$conf['ufw']['init_script'])) system($conf['init_scripts'].'/'.$conf['ufw']['init_script'].' restart &> /dev/null'); } } -- GitLab From c382be21ca5206bd4d4baedd3d5ab2288a3a0f63 Mon Sep 17 00:00:00 2001 From: Till Date: Thu, 15 Sep 2022 18:17:30 +0200 Subject: [PATCH 07/12] PHP 8.1 compat changes in interface part --- install/lib/classes/tpl.inc.php | 32 +++++++++--- interface/lib/classes/db_mysql.inc.php | 2 +- interface/lib/classes/listform.inc.php | 11 ++-- .../lib/classes/listform_actions.inc.php | 11 ++-- interface/lib/classes/simplepie.inc.php | 8 +-- interface/lib/classes/system.inc.php | 1 + interface/lib/classes/tform_base.inc.php | 3 +- interface/lib/classes/tpl.inc.php | 52 ++++++++++++------- interface/web/dashboard/dashlets/limits.php | 4 +- server/lib/classes/cron.inc.php | 2 +- server/lib/classes/tpl.inc.php | 42 ++++++++++----- 11 files changed, 110 insertions(+), 58 deletions(-) diff --git a/install/lib/classes/tpl.inc.php b/install/lib/classes/tpl.inc.php index 342b4125f8..2bea1e1fd5 100644 --- a/install/lib/classes/tpl.inc.php +++ b/install/lib/classes/tpl.inc.php @@ -931,17 +931,12 @@ if (!defined('vlibTemplateClassLoaded')) { { array_push($this->_namespace, $varname); $tempvar = count($this->_namespace) - 1; - $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars"; + $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < \$this->_tpl_count(\$this->_arrvars"; for ($i=0; $i < count($this->_namespace); $i++) { $retstr .= "['".$this->_namespace[$i]."']"; if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; } - $retstr .= ") ? count(\$this->_arrvars"; - for ($i=0; $i < count($this->_namespace); $i++) { - $retstr .= "['".$this->_namespace[$i]."']"; - if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; - } - return $retstr.") : 0); \$_".$tempvar."++) {"; + return $retstr."); \$_".$tempvar."++) {"; } /** @@ -1040,7 +1035,7 @@ if (!defined('vlibTemplateClassLoaded')) { $wholetag = $args[0]; $openclose = $args[1]; $tag = strtolower($args[2]); - + if ($tag == 'else') return ''; if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags @@ -1281,6 +1276,27 @@ if (!defined('vlibTemplateClassLoaded')) { return $return; } + /** + * Used during in evaled code to replace PHP count function for PHP 8 compatibility + * @var variable to be counted + */ + private function _tpl_count($var) + { + $retvar = 0; + if(isset($var)) { + if(is_array($var)) { + $retvar = count($var); + } elseif(is_null($var)) { + $retvar = 0; + } else { + $retvar = 1; + } + } else { + $retvar = 0; + } + return $retvar; + } + /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The following functions have no use and are included just so that if the user is making use of vlibTemplateCache functions, this doesn't crash when changed to diff --git a/interface/lib/classes/db_mysql.inc.php b/interface/lib/classes/db_mysql.inc.php index 1bfc9102b6..78eee8c997 100644 --- a/interface/lib/classes/db_mysql.inc.php +++ b/interface/lib/classes/db_mysql.inc.php @@ -526,7 +526,7 @@ class db $sString = ''; } - $cur_encoding = mb_detect_encoding($sString); + $cur_encoding = mb_detect_encoding($sString, "auto"); if($cur_encoding != "UTF-8") { if($cur_encoding != 'ASCII') { if(is_object($app) && method_exists($app, 'log')) $app->log('String ' . substr($sString, 0, 25) . '... is ' . $cur_encoding . '.', LOGLEVEL_DEBUG); diff --git a/interface/lib/classes/listform.inc.php b/interface/lib/classes/listform.inc.php index 4b92daa73c..1206e3668a 100644 --- a/interface/lib/classes/listform.inc.php +++ b/interface/lib/classes/listform.inc.php @@ -80,7 +80,7 @@ class listform { private function getDatasourceData($field) { - global $app; + global $app, $api; $values = array(); if($field['datasource']['type'] == 'SQL') { @@ -97,7 +97,8 @@ class listform { $querystring = str_replace("{AUTHSQL}", $app->tform->getAuthSQL('r'), $querystring); $querystring = str_replace("{AUTHSQL-A}", $app->tform->getAuthSQL('r', 'a'), $querystring); $querystring = str_replace("{AUTHSQL-B}", $app->tform->getAuthSQL('r', 'b'), $querystring); - $querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', create_function('$matches','global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;'), $querystring); + //$querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', create_function('$matches','global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;'), $querystring); + $querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', function($matches) {global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;}, $querystring); //* Getting the records $tmp_records = $app->db->queryAllRecords($querystring); @@ -195,9 +196,9 @@ class listform { if(@is_array($this->listDef['item'])) { foreach($this->listDef['item'] as $i) { $field = $i['field']; - $table = $i['table']; + $table = (isset($i['table']))?$i['table']:''; - $searchval = $_SESSION['search'][$list_name][$search_prefix.$field]; + $searchval = (isset($_SESSION['search'][$list_name][$search_prefix.$field]))?$_SESSION['search'][$list_name][$search_prefix.$field]:''; // IDN if($searchval != ''){ if(is_array($i['filters'])) { @@ -325,7 +326,7 @@ class listform { if($this->searchChanged == 1) $_SESSION['search'][$list_name]['page'] = 0; $sql_von = $app->functions->intval($_SESSION['search'][$list_name]['page'] * $records_per_page); - $record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM ??".($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')." WHERE $sql_where", $table); + $record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM ??".(isset($app->listform->listDef['additional_tables']) && $app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')." WHERE $sql_where", $table); $pages = $app->functions->intval(($record_count['anzahl'] - 1) / $records_per_page); diff --git a/interface/lib/classes/listform_actions.inc.php b/interface/lib/classes/listform_actions.inc.php index 86eebd3d64..45973cb470 100644 --- a/interface/lib/classes/listform_actions.inc.php +++ b/interface/lib/classes/listform_actions.inc.php @@ -135,7 +135,7 @@ class listform_actions { } } - if($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php']) $php_sort = true; + if(@$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php']) $php_sort = true; // Getting Datasets from DB $records = $app->db->queryAllRecords($this->getQueryString($php_sort)); @@ -226,7 +226,7 @@ class listform_actions { } $sql_where = $app->listform->getSearchSQL($sql_where); - if($app->listform->listDef['join_sql']) $sql_where .= ' AND '.$app->listform->listDef['join_sql']; + if(isset($app->listform->listDef['join_sql'])) $sql_where .= ' AND '.$app->listform->listDef['join_sql']; $app->tpl->setVar($app->listform->searchValues); $order_by_sql = $this->SQLOrderBy; @@ -245,8 +245,9 @@ class listform_actions { $table_selects = array(); $table_selects[] = trim($app->listform->listDef['table']).'.*'; - $app->listform->listDef['additional_tables'] = trim($app->listform->listDef['additional_tables']); - if($app->listform->listDef['additional_tables'] != ''){ + + if(isset($app->listform->listDef['additional_tables']) && trim($app->listform->listDef['additional_tables']) != ''){ + $app->listform->listDef['additional_tables'] = trim($app->listform->listDef['additional_tables']); $additional_tables = explode(',', $app->listform->listDef['additional_tables']); foreach($additional_tables as $additional_table){ $table_selects[] = trim($additional_table).'.*'; @@ -254,7 +255,7 @@ class listform_actions { } $select = implode(', ', $table_selects); - $sql = 'SELECT '.$select.$extselect.' FROM '.$app->listform->listDef['table'].($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')."$join WHERE $sql_where $order_by_sql"; + $sql = 'SELECT '.$select.$extselect.' FROM '.$app->listform->listDef['table'].(isset($app->listform->listDef['additional_tables']) && $app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')."$join WHERE $sql_where $order_by_sql"; if($no_limit == false) $sql .= " $limit_sql"; //echo $sql; return $sql; diff --git a/interface/lib/classes/simplepie.inc.php b/interface/lib/classes/simplepie.inc.php index a2b80ed25b..64f4d946f9 100644 --- a/interface/lib/classes/simplepie.inc.php +++ b/interface/lib/classes/simplepie.inc.php @@ -13186,8 +13186,8 @@ class SimplePie_Parse_Date */ function __construct() { - $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')'; - $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')'; + $this->day_pcre = '(' . implode('|', array_keys($this->day)) . ')'; + $this->month_pcre = '(' . implode('|', array_keys($this->month)) . ')'; static $cache; if (!isset($cache[get_class($this)])) @@ -13338,9 +13338,9 @@ class SimplePie_Parse_Date } // Convert the number of seconds to an integer, taking decimals into account - $second = @round($match[6] + $match[7] / @pow(10, strlen($match[7]))); + $second = @round((int)$match[6] + (int)$match[7] / @pow(10, strlen($match[7]))); - return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone; + return gmmktime((int)$match[4], (int)$match[5], (int)$second, (int)$match[2], (int)$match[3], (int)$match[1]) - $timezone; } else { diff --git a/interface/lib/classes/system.inc.php b/interface/lib/classes/system.inc.php index 9cb171cae5..c33137d6c1 100644 --- a/interface/lib/classes/system.inc.php +++ b/interface/lib/classes/system.inc.php @@ -33,6 +33,7 @@ class system { var $client_service = null; private $_last_exec_out = null; private $_last_exec_retcode = null; + private $server_count = null; public function has_service($userid, $service) { global $app; diff --git a/interface/lib/classes/tform_base.inc.php b/interface/lib/classes/tform_base.inc.php index cfaf0958d5..a4624d4af5 100644 --- a/interface/lib/classes/tform_base.inc.php +++ b/interface/lib/classes/tform_base.inc.php @@ -276,7 +276,8 @@ class tform_base { unset($tmp_recordid); $querystring = str_replace("{AUTHSQL}", $this->getAuthSQL('r'), $querystring); - $querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', create_function('$matches','global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;'), $querystring); + //$querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', create_function('$matches','global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;'), $querystring); + $querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', function($matches) {global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;}, $querystring); // Getting the records $tmp_records = $app->db->queryAllRecords($querystring); diff --git a/interface/lib/classes/tpl.inc.php b/interface/lib/classes/tpl.inc.php index 8c7f51b8c7..977ed0901d 100644 --- a/interface/lib/classes/tpl.inc.php +++ b/interface/lib/classes/tpl.inc.php @@ -233,7 +233,7 @@ if (!defined('vlibTemplateClassLoaded')) { public function setVar($k, $v = null, $encode = false) { global $app; - + if (is_array($k)) { foreach($k as $key => $value){ $key = ($this->OPTIONS['CASELESS']) ? strtolower(trim($key)) : trim($key); @@ -1079,12 +1079,12 @@ if (!defined('vlibTemplateClassLoaded')) { private function _parseHook ($name) { global $app; - + if(!$name) return false; - + $module = isset($_SESSION['s']['module']['name']) ? $_SESSION['s']['module']['name'] : ''; $form = isset($app->tform->formDef['name']) ? $app->tform->formDef['name'] : ''; - + $events = array(); if($module) { $events[] = $module . ':' . ($form ? $form : '') . ':' . $name; @@ -1093,9 +1093,9 @@ if (!defined('vlibTemplateClassLoaded')) { $events[] = $name; $events[] = 'on_template_content'; } - + $events = array_unique($events); - + for($e = 0; $e < count($events); $e++) { $tmpresult = $app->plugin->raiseEvent($events[$e], array( 'name' => $name, @@ -1104,10 +1104,10 @@ if (!defined('vlibTemplateClassLoaded')) { ), true); if(!$tmpresult) $tmpresult = ''; else $tmpresult = $this->_getData($tmpresult, false, true); - + $result .= $tmpresult; } - + return $result; } @@ -1121,17 +1121,12 @@ if (!defined('vlibTemplateClassLoaded')) { { array_push($this->_namespace, $varname); $tempvar = count($this->_namespace) - 1; - $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars"; - for ($i=0; $i < count($this->_namespace); $i++) { - $retstr .= "['".$this->_namespace[$i]."']"; - if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; - } - $retstr .= ") ? count(\$this->_arrvars"; + $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < \$this->_tpl_count(\$this->_arrvars"; for ($i=0; $i < count($this->_namespace); $i++) { $retstr .= "['".$this->_namespace[$i]."']"; if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; } - return $retstr.") : 0); \$_".$tempvar."++) {"; + return $retstr."); \$_".$tempvar."++) {"; } /** @@ -1230,7 +1225,7 @@ if (!defined('vlibTemplateClassLoaded')) { $wholetag = $args[0]; $openclose = $args[1]; $tag = strtolower($args[2]); - + if ($tag == 'else') return ''; if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags @@ -1308,10 +1303,10 @@ if (!defined('vlibTemplateClassLoaded')) { if ($this->OPTIONS['ENABLE_PHPINCLUDE']) { return ''; } - + case 'hook': return $this->_parseHook(@$var); - + case 'include': return '_getData($this->_fileSearch(\''.$file.'\'), 1); ?>'; @@ -1466,6 +1461,27 @@ if (!defined('vlibTemplateClassLoaded')) { return $return; } + /** + * Used during in evaled code to replace PHP count function for PHP 8 compatibility + * @var variable to be counted + */ + private function _tpl_count($var) + { + $retvar = 0; + if(isset($var)) { + if(is_array($var)) { + $retvar = count($var); + } elseif(is_null($var)) { + $retvar = 0; + } else { + $retvar = 1; + } + } else { + $retvar = 0; + } + return $retvar; + } + /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The following functions have no use and are included just so that if the user is making use of vlibTemplateCache functions, this doesn't crash when changed to diff --git a/interface/web/dashboard/dashlets/limits.php b/interface/web/dashboard/dashlets/limits.php index a649fef0f7..50bcad9122 100644 --- a/interface/web/dashboard/dashlets/limits.php +++ b/interface/web/dashboard/dashlets/limits.php @@ -169,13 +169,13 @@ class dashlet_limits } if ($value != 0 || $value == $wb['unlimited_txt']) { $value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value; - if ($limit['q_type']!='') { + if (isset($limit['q_type']) && $limit['q_type'] != '') { $usage = $this->_get_assigned_quota($limit) . " MB"; $value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value . " MB"; } else { $usage = $this->_get_limit_usage($limit); } - $percentage = ($value == '-1' || $value == 0 ? -1 : round(100 * $usage / $value)); + $percentage = ($value == '-1' || intval($value) == 0 || trim($value) == '' ? -1 : round(100 * (int)$usage / (int)$value)); $progressbar = $percentage > 100 ? 100 : $percentage; $rows[] = array('field' => $field, 'field_txt' => $wb[$field.'_txt'], diff --git a/server/lib/classes/cron.inc.php b/server/lib/classes/cron.inc.php index 67be475fe3..2c7f16170c 100644 --- a/server/lib/classes/cron.inc.php +++ b/server/lib/classes/cron.inc.php @@ -246,7 +246,7 @@ class cron { $ts = mktime($iHour, $iMinute, 0, $iMonth, $iDay, $iYear); //print strftime('%d.%m.%Y (%A) %H:%M', $ts) . "\n"; //var_dump($iCurMinute, $iCurHour, $iCurDay, $iCurMonth, $iCurWDay, '--', $iNextMinute, $iNextHour, $iNextDay, $iNextMonth, $iNextWDay); - if(ISPConfigDateTime::last_day($iMonth, $iYear) >= $iDay && in_array($app->functions->intval(strftime('%w', $ts)), $this->_aValidValues['weekday'], true) === true) { + if(ISPConfigDateTime::last_day($iMonth, $iYear) >= $iDay && in_array($app->functions->intval(date('w', $ts)), $this->_aValidValues['weekday'], true) === true) { $bValid = true; } else { if($iYear - $iStartYear > 5) { diff --git a/server/lib/classes/tpl.inc.php b/server/lib/classes/tpl.inc.php index 2af1bf141b..a4ba160252 100644 --- a/server/lib/classes/tpl.inc.php +++ b/server/lib/classes/tpl.inc.php @@ -1074,10 +1074,10 @@ if (!defined('vlibTemplateClassLoaded')) { private function _parseHook ($name) { global $app; - + $namespace = ''; if(strpos($name, ':') !== false) list($namespace, $name) = explode(':', $name, 2); - + $result = $app->plugins->raiseAction('on_template_content_hook', array( 'name' => $name, 'namespace' => $namespace, @@ -1085,7 +1085,7 @@ if (!defined('vlibTemplateClassLoaded')) { ), true); if(!$result) $result = ''; else $result = $this->_getData($result, false, true); - + return $result; } @@ -1099,17 +1099,12 @@ if (!defined('vlibTemplateClassLoaded')) { { array_push($this->_namespace, $varname); $tempvar = count($this->_namespace) - 1; - $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars"; + $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < \$this->_tpl_count(\$this->_arrvars"; for ($i=0; $i < count($this->_namespace); $i++) { $retstr .= "['".$this->_namespace[$i]."']"; if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; } - $retstr .= ") ? count(\$this->_arrvars"; - for ($i=0; $i < count($this->_namespace); $i++) { - $retstr .= "['".$this->_namespace[$i]."']"; - if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]"; - } - return $retstr.") : 0); \$_".$tempvar."++) {"; + return $retstr."); \$_".$tempvar."++) {"; } /** @@ -1208,7 +1203,7 @@ if (!defined('vlibTemplateClassLoaded')) { $wholetag = $args[0]; $openclose = $args[1]; $tag = strtolower($args[2]); - + if ($tag == 'else') return ''; if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags @@ -1286,10 +1281,10 @@ if (!defined('vlibTemplateClassLoaded')) { if ($this->OPTIONS['ENABLE_PHPINCLUDE']) { return ''; } - + case 'hook': return $this->_parseHook(@$var); - + case 'include': return '_getData($this->_fileSearch(\''.$file.'\'), 1); ?>'; @@ -1444,6 +1439,27 @@ if (!defined('vlibTemplateClassLoaded')) { return $return; } + /** + * Used during in evaled code to replace PHP count function for PHP 8 compatibility + * @var variable to be counted + */ + private function _tpl_count($var) + { + $retvar = 0; + if(isset($var)) { + if(is_array($var)) { + $retvar = count($var); + } elseif(is_null($var)) { + $retvar = 0; + } else { + $retvar = 1; + } + } else { + $retvar = 0; + } + return $retvar; + } + /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The following functions have no use and are included just so that if the user is making use of vlibTemplateCache functions, this doesn't crash when changed to -- GitLab From 0023b2212291a85cbc55ee97158f5b12ba48fd6a Mon Sep 17 00:00:00 2001 From: Till Date: Fri, 16 Sep 2022 15:53:11 +0200 Subject: [PATCH 08/12] More php 8 fixes. --- .../lib/classes/validate_datetime.inc.php | 4 +- .../mailuser/mail_user_autoresponder_edit.php | 4 +- .../classes/cron.d/100-monitor_cpu.inc.php | 2 +- .../cron.d/100-monitor_disk_usage.inc.php | 2 +- .../cron.d/100-monitor_hd_quota.inc.php | 4 +- .../cron.d/100-monitor_mail_queue.inc.php | 4 +- .../cron.d/100-monitor_mem_usage.inc.php | 2 +- server/lib/classes/libdatetime.inc.php | 52 +++++++++---------- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/interface/lib/classes/validate_datetime.inc.php b/interface/lib/classes/validate_datetime.inc.php index 2cb35f44e9..055c0e25a0 100755 --- a/interface/lib/classes/validate_datetime.inc.php +++ b/interface/lib/classes/validate_datetime.inc.php @@ -42,7 +42,7 @@ class validate_datetime { if (is_array($field_value) && count($field_value) >= 5) { - $result = array_filter($field_value, create_function('$dt_unit', 'return ($dt_unit > 0);')); + $result = array_filter($field_value, function($dt_unit) {return ($dt_unit > 0);}); return count($result) !== 0; } @@ -86,7 +86,7 @@ class validate_datetime { if(!is_array($field_value)) return 0; $second = 0; - $filtered_values = array_map(create_function('$item', 'return (int)$item;'), $field_value); + $filtered_values = array_map(function($item) {return (int)$item;}, $field_value); extract($filtered_values, EXTR_OVERWRITE); return mktime($hour, $minute, $second, $month, $day, $year); diff --git a/interface/web/mailuser/mail_user_autoresponder_edit.php b/interface/web/mailuser/mail_user_autoresponder_edit.php index 827a585e50..848a3339f0 100644 --- a/interface/web/mailuser/mail_user_autoresponder_edit.php +++ b/interface/web/mailuser/mail_user_autoresponder_edit.php @@ -64,8 +64,8 @@ class page_action extends tform_actions { //* if autoresponder checkbox not selected, do not save dates if (!isset($_POST['autoresponder']) && array_key_exists('autoresponder_start_date', $_POST)) { - $this->dataRecord['autoresponder_start_date'] = array_map(create_function('$item', 'return 0;'), $this->dataRecord['autoresponder_start_date']); - $this->dataRecord['autoresponder_end_date'] = array_map(create_function('$item', 'return 0;'), $this->dataRecord['autoresponder_end_date']); + $this->dataRecord['autoresponder_start_date'] = array_map(function($item) { return 0;}), $this->dataRecord['autoresponder_start_date']); + $this->dataRecord['autoresponder_end_date'] = array_map(function($item) { return 0;}), $this->dataRecord['autoresponder_end_date']); /* To be used when we go to PHP 7.x as min PHP version $this->dataRecord['autoresponder_start_date'] = array_map( function ('$item') { 'return 0;' }, $this->dataRecord['autoresponder_start_date']); diff --git a/server/lib/classes/cron.d/100-monitor_cpu.inc.php b/server/lib/classes/cron.d/100-monitor_cpu.inc.php index f570eeb819..1d67be7370 100644 --- a/server/lib/classes/cron.d/100-monitor_cpu.inc.php +++ b/server/lib/classes/cron.d/100-monitor_cpu.inc.php @@ -78,7 +78,7 @@ class cronjob_monitor_cpu extends cronjob { $part = preg_split('/:/', $line); $key = trim($part[0]); - $value = trim($part[1]); + $value = (isset($part[1]))?trim($part[1]):''; if ($key == 'processor') $processor = intval($value); if ($key != '') diff --git a/server/lib/classes/cron.d/100-monitor_disk_usage.inc.php b/server/lib/classes/cron.d/100-monitor_disk_usage.inc.php index 1d03949a8c..a3c3a3448f 100644 --- a/server/lib/classes/cron.d/100-monitor_disk_usage.inc.php +++ b/server/lib/classes/cron.d/100-monitor_disk_usage.inc.php @@ -83,7 +83,7 @@ class cronjob_monitor_disk_usage extends cronjob { * ignore the first line, process the rest */ for ($i = 1; $i <= sizeof($df); $i++) { - if ($df[$i] != '') { + if (isset($df[$i]) && $df[$i] != '') { /* * Make an array of the data */ diff --git a/server/lib/classes/cron.d/100-monitor_hd_quota.inc.php b/server/lib/classes/cron.d/100-monitor_hd_quota.inc.php index 33c7e59589..32a9c410e8 100644 --- a/server/lib/classes/cron.d/100-monitor_hd_quota.inc.php +++ b/server/lib/classes/cron.d/100-monitor_hd_quota.inc.php @@ -78,7 +78,7 @@ class cronjob_monitor_hd_quota extends cronjob { //* ignore the first 5 lines, process the rest for ($i = 5; $i <= sizeof($df); $i++) { - if ($df[$i] != '') { + if (isset($df[$i]) && $df[$i] != '') { //* Make a array of the data $s = preg_split('/[\s]+/', $df[$i]); $username = $s[0]; @@ -106,7 +106,7 @@ class cronjob_monitor_hd_quota extends cronjob { //* ignore the first 5 lines, process the rest for ($i = 5; $i <= sizeof($df); $i++) { - if ($df[$i] != '') { + if (isset($df[$i]) && $df[$i] != '') { //* Make a array of the data $s = preg_split('/[\s]+/', $df[$i]); $groupname = $s[0]; diff --git a/server/lib/classes/cron.d/100-monitor_mail_queue.inc.php b/server/lib/classes/cron.d/100-monitor_mail_queue.inc.php index b259904d55..f39dd00a6e 100644 --- a/server/lib/classes/cron.d/100-monitor_mail_queue.inc.php +++ b/server/lib/classes/cron.d/100-monitor_mail_queue.inc.php @@ -89,8 +89,8 @@ class cronjob_monitor_mail_queue extends cronjob { $tmp = explode("\n", $data['output']); $more = $tmp[sizeof($tmp) - 1]; $res = $this->_getIntArray($more); - $data['bytes'] = $res[0]; - $data['requests'] = $res[1]; + $data['bytes'] = (isset($res[0]))?$res[0]:0; + $data['requests'] = (isset($res[1]))?$res[1]:0; /** The state of the mailq. */ $state = 'ok'; diff --git a/server/lib/classes/cron.d/100-monitor_mem_usage.inc.php b/server/lib/classes/cron.d/100-monitor_mem_usage.inc.php index 73567478dc..613287267d 100644 --- a/server/lib/classes/cron.d/100-monitor_mem_usage.inc.php +++ b/server/lib/classes/cron.d/100-monitor_mem_usage.inc.php @@ -78,7 +78,7 @@ class cronjob_monitor_mem_usage extends cronjob { $key = trim($part[0]); $tmp = explode(' ', trim($part[1])); $value = 0; - if ($tmp[1] == 'kB') + if (isset($tmp[1]) && $tmp[1] == 'kB') $value = $tmp[0] * 1024; $data[$key] = $value; } diff --git a/server/lib/classes/libdatetime.inc.php b/server/lib/classes/libdatetime.inc.php index fe2b81553b..a0633266fc 100644 --- a/server/lib/classes/libdatetime.inc.php +++ b/server/lib/classes/libdatetime.inc.php @@ -152,7 +152,7 @@ abstract class ISPConfigDateTime { * - onlytime: HH:MM * - rss: Rss time format for XML * - nice: if you prepend a nice: (like nice:long) you will get results like "today" or "yesterday" if applicable - * - custom: you can give a strftime format like %d.%m.%Y %H:%M if you prepend custom: to it + * - custom: you can give a php date function format like d.m.Y H:i if you prepend custom: to it * @param bool $time if true apped the time to the date string * @param bool $seconds if true append the seconds to the time * @return string date string @@ -174,15 +174,15 @@ abstract class ISPConfigDateTime { $fmt = ''; $prepend = ''; if(substr($format, 0, 5) == 'nice:') { - if(strftime('%d.%m.%Y', $date) == strftime('%d.%m.%Y', $portal->getTime())) { + if(date('d.m.Y', $date) == date('d.m.Y', $portal->getTime())) { if($time == true) $format = 'onlytime'; else $format = ''; $prepend = 'Heute'; - } elseif(strftime('%d.%m.%Y', $date) == strftime('%d.%m.%Y', $portal->getTime() - 86400)) { + } elseif(date('d.m.Y', $date) == date('d.m.Y', $portal->getTime() - 86400)) { if($time == true) $format = 'onlytime'; else $format = ''; $prepend = 'Gestern'; - } elseif(strftime('%d.%m.%Y', $date) == strftime('%d.%m.%Y', $portal->getTime() + 86400)) { + } elseif(date('d.m.Y', $date) == date('d.m.Y', $portal->getTime() + 86400)) { if($time == true) $format = 'onlytime'; else $format = ''; $prepend = 'Morgen'; @@ -195,21 +195,21 @@ abstract class ISPConfigDateTime { $time = false; } - if($format == 'short') $fmt = '%d.%m.%y'; - elseif($format == 'veryshort') $fmt = '%d.%m.'; - elseif($format == 'medium') $fmt = '%d.%m.%Y'; - elseif($format == 'long') $fmt = '%d. %B %Y'; - elseif($format == 'extra') $fmt = '%A, %d. %B %Y'; - elseif($format == 'day') $fmt = '%d'; - elseif($format == 'monthnum') $fmt = '%m'; - elseif($format == 'shortmonth') $fmt = '%b'; - elseif($format == 'month') $fmt = '%B'; - elseif($format == 'shortyear') $fmt = '%y'; - elseif($format == 'year') $fmt = '%Y'; - elseif($format == 'onlydate') $fmt = '%d.%m.'; - elseif($format == 'onlydatelong') $fmt = '%d. %B'; + if($format == 'short') $fmt = 'd.m.y'; + elseif($format == 'veryshort') $fmt = 'd.m.'; + elseif($format == 'medium') $fmt = 'd.m.Y'; + elseif($format == 'long') $fmt = 'd. B Y'; + elseif($format == 'extra') $fmt = 'A, d. B Y'; + elseif($format == 'day') $fmt = 'd'; + elseif($format == 'monthnum') $fmt = 'm'; + elseif($format == 'shortmonth') $fmt = 'b'; + elseif($format == 'month') $fmt = 'B'; + elseif($format == 'shortyear') $fmt = 'y'; + elseif($format == 'year') $fmt = 'Y'; + elseif($format == 'onlydate') $fmt = 'd.m.'; + elseif($format == 'onlydatelong') $fmt = 'd. B'; elseif($format == 'onlytime') { - $fmt = '%H:%M'; + $fmt = 'H:i'; $time = false; } elseif($format == 'rss') { $ret = date(DATE_RSS, $date); @@ -220,9 +220,9 @@ abstract class ISPConfigDateTime { if($prepend != '') $ret = $prepend . ' ' . $ret; return $ret; } - if($time == true) $fmt .= ' %H:%M' . ($seconds == true ? ':%S' : ''); + if($time == true) $fmt .= ' H:i' . ($seconds == true ? ':s' : ''); - if($fmt != '') $ret = strftime($fmt, $date); + if($fmt != '') $ret = date($fmt, $date); else $ret = ''; if($prepend != '') $ret = trim($prepend . ' ' . $ret); @@ -249,10 +249,10 @@ abstract class ISPConfigDateTime { * @return mixed either int (months) or array of int (0 => years, 1 => months) or FALSE on invalid dates */ public static function months_between($date_from, $date_to, $return_years = false, $include_both = false) { - $date_from = self::to_string($date_from, 'custom:%Y%m'); + $date_from = self::to_string($date_from, 'custom:Ym'); if($date_from === false) return $date_from; - $date_to = self::to_string($date_to, 'custom:%Y%m'); + $date_to = self::to_string($date_to, 'custom:Ym'); if($date_to === false) return $date_to; $date_from = intval($date_from); @@ -294,12 +294,12 @@ abstract class ISPConfigDateTime { * @return mixed either int (days) or FALSE on invalid dates */ public static function days_between($date_from, $date_to, $include_both = false) { - $date_from = self::to_string($date_from, 'custom:%Y-%m-%d'); + $date_from = self::to_string($date_from, 'custom:Y-m-d'); if($date_from === false) return $date_from; list($y, $m, $d) = explode('-', $date_from); $ts_from = mktime(0, 0, 0, $m, $d, $y); - $date_to = self::to_string($date_to, 'custom:%Y-%m-%d'); + $date_to = self::to_string($date_to, 'custom:Y-m-d'); if($date_to === false) return $date_to; list($y, $m, $d) = explode('-', $date_to); $ts_to = mktime(0, 0, 0, $m, $d, $y); @@ -364,7 +364,7 @@ abstract class ISPConfigDateTime { if($date === false) $date = $portal->getTime(true); if(is_numeric($date)) { - return $no_time ? strftime('%Y-%m-%d', $date) : strftime('%Y-%m-%d %H:%M:%S', $date); + return $no_time ? date('Y-m-d', $date) : date('Y-m-d H:i:s', $date); } if(preg_match('/^(.*)(\d{1,2}:\d{1,2}(:\d{1,2})?)(\D|$)/', $date, $matches)) { @@ -473,7 +473,7 @@ abstract class ISPConfigDateTime { if($date === false) return $date; list($year, $month, $day) = explode('-', $date); - list($curyear, $curmonth, $curday) = explode('-', strftime('%Y-%m-%d', $portal->getTime())); + list($curyear, $curmonth, $curday) = explode('-', date('Y-m-d', $portal->getTime())); $year_diff = $curyear - $year; $month_diff = $curmonth - $month; -- GitLab From 351c2b6d92d99209a7f5b9c855610f88ce863779 Mon Sep 17 00:00:00 2001 From: Till Date: Fri, 16 Sep 2022 16:19:47 +0200 Subject: [PATCH 09/12] PHP 8 fixes --- interface/lib/classes/listform_actions.inc.php | 2 +- interface/lib/classes/tform_base.inc.php | 2 +- interface/web/client/client_edit.php | 14 +++++++------- .../web/mailuser/mail_user_autoresponder_edit.php | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/interface/lib/classes/listform_actions.inc.php b/interface/lib/classes/listform_actions.inc.php index 45973cb470..7ffc84c32b 100644 --- a/interface/lib/classes/listform_actions.inc.php +++ b/interface/lib/classes/listform_actions.inc.php @@ -189,7 +189,7 @@ class listform_actions { //* substitute value for select fields if(is_array($app->listform->listDef['item']) && count($app->listform->listDef['item']) > 0) { foreach($app->listform->listDef['item'] as $field) { - if($rec['active'] == 'n') $rec['warn_inactive'] = 'y'; + if(isset($rec['active']) && $rec['active'] == 'n') $rec['warn_inactive'] = 'y'; $key = $field['field']; if(isset($field['formtype']) && $field['formtype'] == 'SELECT') { if(strtolower($rec[$key]) == 'y' or strtolower($rec[$key]) == 'n') { diff --git a/interface/lib/classes/tform_base.inc.php b/interface/lib/classes/tform_base.inc.php index a4624d4af5..3b35a722d2 100644 --- a/interface/lib/classes/tform_base.inc.php +++ b/interface/lib/classes/tform_base.inc.php @@ -1585,7 +1585,7 @@ class tform_base { // Set form title $form_hint = $this->lng($this->formDef["title"]); - if($this->formDef["description"] != '') $form_hint .= '
'.$this->lng($this->formDef["description"]).'
'; + if(isset($this->formDef["description"]) && $this->formDef["description"] != '') $form_hint .= '
'.$this->lng($this->formDef["description"]).'
'; $app->tpl->setVar('form_hint', $form_hint); // Set Wordbook for this form diff --git a/interface/web/client/client_edit.php b/interface/web/client/client_edit.php index f1964d7eff..598c307c8c 100644 --- a/interface/web/client/client_edit.php +++ b/interface/web/client/client_edit.php @@ -119,7 +119,7 @@ class page_action extends tform_actions { $this->oldTemplatesAssigned = array(); } - $this->_template_additional = explode('/', $this->dataRecord['template_additional']); + $this->_template_additional = (isset($this->dataRecord['template_additional']) && $this->dataRecord['template_additional'] != '')?explode('/', $this->dataRecord['template_additional']):array(); $this->dataRecord['template_additional'] = ''; parent::onSubmit(); @@ -169,7 +169,7 @@ class page_action extends tform_actions { // old style $sql = "SELECT template_additional FROM client WHERE client_id = ?"; $result = $app->db->queryOneRecord($sql, $this->id); - $tplAdd = explode("/", $result['template_additional']); + $tplAdd = (isset($result['template_additional']) && $result['template_additional'] != '')?explode("/", $result['template_additional']):array(); $text = ''; foreach($tplAdd as $item){ if (trim($item) != ''){ @@ -293,7 +293,7 @@ class page_action extends tform_actions { $app->auth->add_group_to_user($_SESSION['s']['user']['userid'], $groupid); $app->db->query("UPDATE client SET parent_client_id = ? WHERE client_id = ?", $_SESSION['s']['user']['client_id'], $this->id); } else { - if($this->dataRecord['parent_client_id'] > 0) { + if(isset($this->dataRecord['parent_client_id']) && $this->dataRecord['parent_client_id'] > 0) { //* get userid of the reseller and add it to the group of the client $tmp = $app->db->queryOneRecord("SELECT sys_user.userid FROM sys_user,sys_group WHERE sys_user.default_group = sys_group.groupid AND sys_group.client_id = ?", $this->dataRecord['parent_client_id']); $app->auth->add_group_to_user($tmp['userid'], $groupid); @@ -304,14 +304,14 @@ class page_action extends tform_actions { //* Set the default servers $tmp = $app->getconf->get_global_config('mail'); - $default_mailserver = $app->functions->intval($tmp['default_mailserver']); + $default_mailserver = (isset($tmp['default_mailserver']))?$app->functions->intval($tmp['default_mailserver']):0; if (!$default_mailserver) { $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE mail_server = 1 AND mirror_server_id = 0 LIMIT 0,1'); $default_mailserver = $app->functions->intval($tmp['server_id']); } $tmp = $app->getconf->get_global_config('sites'); - $default_webserver = $app->functions->intval($tmp['default_webserver']); - $default_dbserver = $app->functions->intval($tmp['default_dbserver']); + $default_webserver = (isset($tmp['default_webserver']))?$app->functions->intval($tmp['default_webserver']):0; + $default_dbserver = (isset($tmp['default_dbserver']))?$app->functions->intval($tmp['default_dbserver']):0; if (!$default_webserver) { $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE web_server = 1 AND mirror_server_id = 0 LIMIT 0,1'); $default_webserver = $app->functions->intval($tmp['server_id']); @@ -321,7 +321,7 @@ class page_action extends tform_actions { $default_dbserver = $app->functions->intval($tmp['server_id']); } $tmp = $app->getconf->get_global_config('dns'); - $default_dnsserver = $app->functions->intval($tmp['default_dnsserver']); + $default_dnsserver = (isset($tmp['default_dnsserver']))?$app->functions->intval($tmp['default_dnsserver']):0; if (!$default_dnsserver) { $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE dns_server = 1 AND mirror_server_id = 0 LIMIT 0,1'); $default_dnsserver = $app->functions->intval($tmp['server_id']); diff --git a/interface/web/mailuser/mail_user_autoresponder_edit.php b/interface/web/mailuser/mail_user_autoresponder_edit.php index 848a3339f0..9ec98f39af 100644 --- a/interface/web/mailuser/mail_user_autoresponder_edit.php +++ b/interface/web/mailuser/mail_user_autoresponder_edit.php @@ -64,8 +64,8 @@ class page_action extends tform_actions { //* if autoresponder checkbox not selected, do not save dates if (!isset($_POST['autoresponder']) && array_key_exists('autoresponder_start_date', $_POST)) { - $this->dataRecord['autoresponder_start_date'] = array_map(function($item) { return 0;}), $this->dataRecord['autoresponder_start_date']); - $this->dataRecord['autoresponder_end_date'] = array_map(function($item) { return 0;}), $this->dataRecord['autoresponder_end_date']); + $this->dataRecord['autoresponder_start_date'] = array_map(function($item) { return 0;}, $this->dataRecord['autoresponder_start_date']); + $this->dataRecord['autoresponder_end_date'] = array_map(function($item) { return 0;}, $this->dataRecord['autoresponder_end_date']); /* To be used when we go to PHP 7.x as min PHP version $this->dataRecord['autoresponder_start_date'] = array_map( function ('$item') { 'return 0;' }, $this->dataRecord['autoresponder_start_date']); -- GitLab From bdabb06103ef352cc926e1fd8bff4a4826282261 Mon Sep 17 00:00:00 2001 From: Till Date: Tue, 18 Oct 2022 20:28:35 +0200 Subject: [PATCH 10/12] Fix cache directory not found warning in templating system. --- server/lib/classes/tpl_ini.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/lib/classes/tpl_ini.inc.php b/server/lib/classes/tpl_ini.inc.php index 792dacbece..6f9f83731b 100644 --- a/server/lib/classes/tpl_ini.inc.php +++ b/server/lib/classes/tpl_ini.inc.php @@ -89,7 +89,7 @@ if (!defined('vlibIniClassLoaded')) { /* the following are only used by the vlibTemplateCache class. */ - 'CACHE_DIRECTORY' => $conf["template"]["cache_dir"], + 'CACHE_DIRECTORY' => (isset($conf["template"]["cache_dir"]))?$conf["template"]["cache_dir"]:'', // Directory where the cached filesystem // will be set up (full path, and must be writable) // '/' or '\' off the end of the directory. -- GitLab From b09eb07f87a55e6ff6ce24b2e6ad6c51a583fdae Mon Sep 17 00:00:00 2001 From: Till Date: Tue, 18 Oct 2022 20:29:56 +0200 Subject: [PATCH 11/12] Show PHP warnings in dev mode only and change dev mode constant from 0/1 to true/false value. --- install/tpl/config.inc.php.master | 2 +- interface/lib/app.inc.php | 4 ++-- interface/lib/config.inc.php | 2 +- server/lib/app.inc.php | 5 +++++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/install/tpl/config.inc.php.master b/install/tpl/config.inc.php.master index bd5cc8f47f..aa9329fb7b 100644 --- a/install/tpl/config.inc.php.master +++ b/install/tpl/config.inc.php.master @@ -56,7 +56,7 @@ $revision = str_replace(array('Revision:','$',' '), '', $svn_revision); //** Application define('ISPC_APP_TITLE', 'ISPConfig'); define('ISPC_APP_VERSION', '3.2dev'); -define('DEVSYSTEM', 0); +define('DEVSYSTEM', false); //** Database diff --git a/interface/lib/app.inc.php b/interface/lib/app.inc.php index 6a8e563d80..0350e28051 100644 --- a/interface/lib/app.inc.php +++ b/interface/lib/app.inc.php @@ -39,8 +39,8 @@ ob_start('ob_gzhandler'); if(isset($conf['timezone']) && $conf['timezone'] != '') date_default_timezone_set($conf['timezone']); //* Set error reporting level when we are not on a developer system -if(DEVSYSTEM == 0) { - @ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_DEPRECATED); +if(DEVSYSTEM !== true) { + @ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING); } /* diff --git a/interface/lib/config.inc.php b/interface/lib/config.inc.php index c492680513..73e8273cbf 100644 --- a/interface/lib/config.inc.php +++ b/interface/lib/config.inc.php @@ -46,7 +46,7 @@ $revision = str_replace(array('Revision:', '$', ' '), '', $svn_revision); //** Application define('ISPC_APP_TITLE', 'ISPConfig'); define('ISPC_APP_VERSION', '3.2dev'); -define('DEVSYSTEM', 0); +define('DEVSYSTEM', false); //** Database diff --git a/server/lib/app.inc.php b/server/lib/app.inc.php index ffd20e9fb6..b6adb3a102 100644 --- a/server/lib/app.inc.php +++ b/server/lib/app.inc.php @@ -36,6 +36,11 @@ if(isset($conf['timezone']) && $conf['timezone'] != '') { // note: !empty($conf[ date_default_timezone_set($conf['timezone']); } +//* Set error reporting level when we are not on a developer system +if(DEVSYSTEM !== true) { + @ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING); +} + /** * Class for defining (mostly static) methods that are commonly used across the whole application. * -- GitLab From 06111e8d8ea7b82228c3a30633fd6f5c282f6d76 Mon Sep 17 00:00:00 2001 From: Till Date: Thu, 20 Oct 2022 21:16:56 +0200 Subject: [PATCH 12/12] Fix warnings in BIND plugin. --- server/plugins-available/bind_plugin.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/plugins-available/bind_plugin.inc.php b/server/plugins-available/bind_plugin.inc.php index d337a039d1..643f34e618 100644 --- a/server/plugins-available/bind_plugin.inc.php +++ b/server/plugins-available/bind_plugin.inc.php @@ -548,11 +548,11 @@ class bind_plugin { if ($tmp['dnssec_wanted'] == 'Y') $zone_file .= '.signed'; //.signed is for DNSSEC-Implementation $options = ''; - if(trim($tmp['xfer']) != '') { + if($tmp['xfer'] != null && trim($tmp['xfer']) != '') { $options .= " allow-transfer {".str_replace(',', ';', $tmp['xfer']).";};\n"; } - if(trim($tmp['also_notify']) != '') $options .= ' also-notify {'.str_replace(',', ';', $tmp['also_notify']).";};\n"; - if(trim($tmp['update_acl']) != '') $options .= " allow-update {".str_replace(',', ';', $tmp['update_acl']).";};\n"; + if($tmp['also_notify'] != null && trim($tmp['also_notify']) != '') $options .= ' also-notify {'.str_replace(',', ';', $tmp['also_notify']).";};\n"; + if($tmp['update_acl'] != null && trim($tmp['update_acl']) != '') $options .= " allow-update {".str_replace(',', ';', $tmp['update_acl']).";};\n"; if(file_exists($zone_file)) { $zones[] = array( 'zone' => substr($tmp['origin'], 0, -1), -- GitLab