summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2022-05-02 18:49:09 +0200
committerSimon Rettberg2022-05-02 18:49:09 +0200
commit5eb8df7432a708284862e4b126e418265d36b4ab (patch)
treed8812cc2bd6245e0b02ca6866a4c14e977e1bb62
parent[rebootcontrol] Show time of execution for WOL/reboot/shutdown (diff)
downloadslx-admin-5eb8df7432a708284862e4b126e418265d36b4ab.tar.gz
slx-admin-5eb8df7432a708284862e4b126e418265d36b4ab.tar.xz
slx-admin-5eb8df7432a708284862e4b126e418265d36b4ab.zip
[inc/Util] Add types, move error printing functions to their own class
-rw-r--r--api.php2
-rw-r--r--apis/getconfig.inc.php2
-rw-r--r--inc/arrayutil.inc.php18
-rw-r--r--inc/crypto.inc.php2
-rw-r--r--inc/database.inc.php12
-rw-r--r--inc/download.inc.php6
-rw-r--r--inc/errorhandler.inc.php148
-rw-r--r--inc/module.inc.php2
-rw-r--r--inc/paginate.inc.php12
-rw-r--r--inc/permission.inc.php2
-rw-r--r--inc/render.inc.php6
-rw-r--r--inc/session.inc.php10
-rw-r--r--inc/taskmanager.inc.php2
-rw-r--r--inc/util.inc.php221
-rw-r--r--index.php2
-rw-r--r--modules-available/baseconfig/inc/validator.inc.php2
-rw-r--r--modules-available/dozmod/api.inc.php2
-rw-r--r--modules-available/dozmod/page.inc.php2
-rw-r--r--modules-available/dozmod/pages/actionlog.inc.php2
-rw-r--r--modules-available/exams/page.inc.php4
-rw-r--r--modules-available/locationinfo/page.inc.php2
-rw-r--r--modules-available/locations/inc/location.inc.php4
-rw-r--r--modules-available/rebootcontrol/pages/task.inc.php2
-rw-r--r--modules-available/statistics/inc/statistics.inc.php2
-rw-r--r--modules-available/statistics/inc/statisticsfilter.inc.php4
-rw-r--r--modules-available/statistics/pages/projectors.inc.php2
-rw-r--r--modules-available/sysconfig/addconfig.inc.php8
-rw-r--r--modules-available/sysconfig/addmodule.inc.php10
-rw-r--r--modules-available/sysconfig/inc/configmodule.inc.php24
-rw-r--r--modules-available/sysconfig/inc/configmodulebaseldap.inc.php2
-rw-r--r--modules-available/sysconfig/inc/configtgz.inc.php12
31 files changed, 276 insertions, 255 deletions
diff --git a/api.php b/api.php
index 23328993..a40a0a1c 100644
--- a/api.php
+++ b/api.php
@@ -55,7 +55,7 @@ if (Module::isAvailable($module)) {
}
if (!file_exists($module)) {
- Util::traceError('Invalid module, or module without API: ' . $module);
+ ErrorHandler::traceError('Invalid module, or module without API: ' . $module);
}
if (php_sapi_name() === 'cli') {
register_shutdown_function(function() {
diff --git a/apis/getconfig.inc.php b/apis/getconfig.inc.php
index 3fe05ed1..a5d5254d 100644
--- a/apis/getconfig.inc.php
+++ b/apis/getconfig.inc.php
@@ -6,7 +6,7 @@
*/
if (!Module::isAvailable('baseconfig')) {
- Util::traceError('Module baseconfig not available');
+ ErrorHandler::traceError('Module baseconfig not available');
}
require 'modules/baseconfig/api.inc.php'; \ No newline at end of file
diff --git a/inc/arrayutil.inc.php b/inc/arrayutil.inc.php
index 3beceb41..d82cdbeb 100644
--- a/inc/arrayutil.inc.php
+++ b/inc/arrayutil.inc.php
@@ -48,4 +48,22 @@ class ArrayUtil
array_multisort($sorter, $sortFlags, $array);
}
+ /**
+ * Check whether $array contains all keys given in $keyList
+ *
+ * @param array $array An array
+ * @param array $keyList A list of strings which must all be valid keys in $array
+ * @return boolean
+ */
+ public static function hasAllKeys(array $array, array $keyList): bool
+ {
+ if (!is_array($array))
+ return false;
+ foreach ($keyList as $key) {
+ if (!isset($array[$key]))
+ return false;
+ }
+ return true;
+ }
+
} \ No newline at end of file
diff --git a/inc/crypto.inc.php b/inc/crypto.inc.php
index d3dd60dc..eb0d344f 100644
--- a/inc/crypto.inc.php
+++ b/inc/crypto.inc.php
@@ -13,7 +13,7 @@ class Crypto
$salt = substr(str_replace('+', '.',
base64_encode(pack('N4', mt_rand(), mt_rand(), mt_rand(), mt_rand()))), 0, 16);
$hash = crypt($password, '$6$' . $salt);
- if (strlen($hash) < 60) Util::traceError('Error hashing password using SHA-512');
+ if (strlen($hash) < 60) ErrorHandler::traceError('Error hashing password using SHA-512');
return $hash;
}
diff --git a/inc/database.inc.php b/inc/database.inc.php
index 8d50a02d..8f2ba6d1 100644
--- a/inc/database.inc.php
+++ b/inc/database.inc.php
@@ -34,7 +34,7 @@ class Database
} catch (PDOException $e) {
if (self::$returnErrors)
return false;
- Util::traceError('Connecting to the local database failed: ' . $e->getMessage());
+ ErrorHandler::traceError('Connecting to the local database failed: ' . $e->getMessage());
}
if (CONFIG_DEBUG) {
Database::exec("SET SESSION sql_mode='STRICT_ALL_TABLES,NO_ENGINE_SUBSTITUTION,ERROR_FOR_DIVISION_BY_ZERO'");
@@ -203,7 +203,7 @@ class Database
self::$lastError = implode("\n", $stmt->errorInfo());
if ($ignoreError === true || ($ignoreError === null && self::$returnErrors))
return false;
- Util::traceError("Database Error: \n" . self::$lastError);
+ ErrorHandler::traceError("Database Error: \n" . self::$lastError);
}
if (CONFIG_DEBUG) {
$duration = microtime(true) - $start;
@@ -221,7 +221,7 @@ class Database
self::$lastError = '(' . $e->getCode() . ') ' . $e->getMessage();
if ($ignoreError === true || ($ignoreError === null && self::$returnErrors))
return false;
- Util::traceError("Database Error: \n" . self::$lastError);
+ ErrorHandler::traceError("Database Error: \n" . self::$lastError);
}
return false;
}
@@ -383,10 +383,10 @@ class Database
{
// Sanity checks
if (array_key_exists($aiKey, $uniqueValues)) {
- Util::traceError("$aiKey must not be in \$uniqueValues");
+ ErrorHandler::traceError("$aiKey must not be in \$uniqueValues");
}
if (is_array($additionalValues) && array_key_exists($aiKey, $additionalValues)) {
- Util::traceError("$aiKey must not be in \$additionalValues");
+ ErrorHandler::traceError("$aiKey must not be in \$additionalValues");
}
// Simple SELECT first
$selectSql = 'SELECT ' . $aiKey . ' FROM ' . $table . ' WHERE 1';
@@ -444,7 +444,7 @@ class Database
// Insert done, retrieve key again
$res = self::queryFirst($selectSql, $uniqueValues);
if ($res === false) {
- Util::traceError('Could not find value in table ' . $table . ' that was just inserted');
+ ErrorHandler::traceError('Could not find value in table ' . $table . ' that was just inserted');
}
return $res[$aiKey];
}
diff --git a/inc/download.inc.php b/inc/download.inc.php
index 39f8e2e2..5a71014e 100644
--- a/inc/download.inc.php
+++ b/inc/download.inc.php
@@ -14,7 +14,7 @@ class Download
if (self::$curlHandle === false) {
self::$curlHandle = curl_init();
if (self::$curlHandle === false) {
- Util::traceError('Could not initialize cURL');
+ ErrorHandler::traceError('Could not initialize cURL');
}
curl_setopt(self::$curlHandle, CURLOPT_CONNECTTIMEOUT, ceil($timeout / 2));
curl_setopt(self::$curlHandle, CURLOPT_TIMEOUT, $timeout);
@@ -30,7 +30,7 @@ class Download
$head = fopen($tmpfile, 'w+b');
unlink($tmpfile);
if ($head === false)
- Util::traceError("Could not open temporary head file $tmpfile for writing.");
+ ErrorHandler::traceError("Could not open temporary head file $tmpfile for writing.");
curl_setopt(self::$curlHandle, CURLOPT_WRITEHEADER, $head);
return self::$curlHandle;
}
@@ -111,7 +111,7 @@ class Download
{
$fh = fopen($target, 'wb');
if ($fh === false)
- Util::traceError("Could not open $target for writing.");
+ ErrorHandler::traceError("Could not open $target for writing.");
$ch = self::initCurl($url, $timeout, $head);
curl_setopt($ch, CURLOPT_FILE, $fh);
$res = curl_exec($ch);
diff --git a/inc/errorhandler.inc.php b/inc/errorhandler.inc.php
new file mode 100644
index 00000000..c7a32b02
--- /dev/null
+++ b/inc/errorhandler.inc.php
@@ -0,0 +1,148 @@
+<?php
+
+class ErrorHandler
+{
+
+
+ /**
+ * Displays an error message and stops script execution.
+ * If CONFIG_DEBUG is true, it will also dump a stack trace
+ * and all globally defined variables.
+ * (As this might reveal sensitive data you should never enable it in production)
+ */
+ public static function traceError($message)
+ {
+ if ((defined('API') && API) || (defined('AJAX') && AJAX) || php_sapi_name() === 'cli') {
+ error_log('API ERROR: ' . $message);
+ error_log(self::formatBacktracePlain(debug_backtrace()));
+ }
+ if (php_sapi_name() === 'cli') {
+ // Don't spam HTML when invoked via cli, above error_log should have gone to stdout/stderr
+ exit(1);
+ }
+ Header('HTTP/1.1 500 Internal Server Error');
+ if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'html') === false) {
+ Header('Content-Type: text/plain; charset=utf-8');
+ echo 'API ERROR: ', $message, "\n", self::formatBacktracePlain(debug_backtrace());
+ exit(0);
+ }
+ Header('Content-Type: text/html; charset=utf-8');
+ echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><style>', "\n",
+ ".arg { color: red; background: white; }\n",
+ "h1 a { color: inherit; text-decoration: inherit; font-weight: inherit; }\n",
+ '</style><title>Fatal Error</title></head><body>';
+ echo '<h1>Flagrant <a href="https://www.youtube.com/watch?v=7rrZ-sA4FQc&t=2m2s" target="_blank">S</a>ystem error</h1>';
+ echo "<h2>Message</h2><pre>$message</pre>";
+ if (strpos($message, 'Database') !== false) {
+ echo '<div><a href="install.php">Try running database setup</a></div>';
+ }
+ echo "<br><br>";
+ if (defined('CONFIG_DEBUG') && CONFIG_DEBUG) {
+ global $SLX_ERRORS;
+ if (!empty($SLX_ERRORS)) {
+ echo '<h2>PHP Errors</h2><pre>';
+ foreach ($SLX_ERRORS as $error) {
+ echo htmlspecialchars("{$error['errstr']} ({$error['errfile']}:{$error['errline']}\n");
+ }
+ echo '</pre>';
+ }
+ echo "<h2>Stack Trace</h2>";
+ echo '<pre>', self::formatBacktraceHtml(debug_backtrace()), '</pre>';
+ echo "<h2>Globals</h2><pre>";
+ echo htmlspecialchars(print_r($GLOBALS, true));
+ echo '</pre>';
+ } else {
+ echo <<<SADFACE
+<pre>
+________________________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶________
+____________________¶¶¶___________________¶¶¶¶_____
+________________¶¶¶_________________________¶¶¶¶___
+______________¶¶______________________________¶¶¶__
+___________¶¶¶_________________________________¶¶¶_
+_________¶¶_____________________________________¶¶¶
+________¶¶_________¶¶¶¶¶___________¶¶¶¶¶_________¶¶
+______¶¶__________¶¶¶¶¶¶__________¶¶¶¶¶¶_________¶¶
+_____¶¶___________¶¶¶¶____________¶¶¶¶___________¶¶
+____¶¶___________________________________________¶¶
+___¶¶___________________________________________¶¶_
+__¶¶____________________¶¶¶¶____________________¶¶_
+_¶¶_______________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶______________¶¶__
+_¶¶____________¶¶¶¶___________¶¶¶¶¶___________¶¶___
+¶¶¶_________¶¶¶__________________¶¶__________¶¶____
+¶¶_________¶______________________¶¶________¶¶_____
+¶¶¶______¶________________________¶¶_______¶¶______
+¶¶¶_____¶_________________________¶¶_____¶¶________
+_¶¶¶___________________________________¶¶__________
+__¶¶¶________________________________¶¶____________
+___¶¶¶____________________________¶¶_______________
+____¶¶¶¶______________________¶¶¶__________________
+_______¶¶¶¶¶_____________¶¶¶¶¶_____________________
+</pre>
+SADFACE;
+ }
+ echo '</body></html>';
+ exit(0);
+ }
+
+ public static function formatBacktraceHtml($trace): string
+ {
+ $output = '';
+ foreach ($trace as $idx => $line) {
+ $args = array();
+ foreach ($line['args'] as $arg) {
+ $arg = self::formatArgument($arg);
+ $args[] = '<span class="arg">' . htmlspecialchars($arg) . '</span>';
+ }
+ $frame = str_pad('#' . $idx, 3, ' ', STR_PAD_LEFT);
+ $function = htmlspecialchars($line['function']);
+ $args = implode(', ', $args);
+ $file = preg_replace('~(/[^/]+)$~', '<b>$1</b>', htmlspecialchars($line['file']));
+ // Add line
+ $output .= $frame . ' ' . $function . '<b>(</b>'
+ . $args . '<b>)</b>' . ' @ <i>' . $file . '</i>:' . $line['line'] . "\n";
+ }
+ return $output;
+ }
+
+ public static function formatBacktracePlain($trace): string
+ {
+ $output = '';
+ foreach ($trace as $idx => $line) {
+ $args = array();
+ foreach ($line['args'] as $arg) {
+ $args[] = self::formatArgument($arg);
+ }
+ $frame = str_pad('#' . $idx, 3, ' ', STR_PAD_LEFT);
+ $args = implode(', ', $args);
+ // Add line
+ $output .= "\n" . $frame . ' ' . $line['function'] . '('
+ . $args . ')' . ' @ ' . $line['file'] . ':' . $line['line'];
+ }
+ return $output;
+ }
+
+ private static function formatArgument($arg, $expandArray = true)
+ {
+ if (is_string($arg)) {
+ $arg = "'$arg'";
+ } elseif (is_object($arg)) {
+ $arg = 'instanceof ' . get_class($arg);
+ } elseif (is_array($arg)) {
+ if ($expandArray && count($arg) < 20) {
+ $expanded = '';
+ foreach ($arg as $key => $value) {
+ if (!empty($expanded)) {
+ $expanded .= ', ';
+ }
+ $expanded .= $key . ': ' . self::formatArgument($value, false);
+ if (strlen($expanded) > 200)
+ break;
+ }
+ if (strlen($expanded) <= 200)
+ return '[' . $expanded . ']';
+ }
+ $arg = 'Array(' . count($arg) . ')';
+ }
+ return $arg;
+ }
+} \ No newline at end of file
diff --git a/inc/module.inc.php b/inc/module.inc.php
index 55713cd0..ea3af1ba 100644
--- a/inc/module.inc.php
+++ b/inc/module.inc.php
@@ -189,7 +189,7 @@ class Module
{
$modulePath = 'modules/' . $this->name . '/page.inc.php';
if (!file_exists($modulePath)) {
- Util::traceError("Module doesn't have a page: " . $modulePath);
+ ErrorHandler::traceError("Module doesn't have a page: " . $modulePath);
}
require_once $modulePath;
$class = 'Page_' . $this->name;
diff --git a/inc/paginate.inc.php b/inc/paginate.inc.php
index b212e252..3187261c 100644
--- a/inc/paginate.inc.php
+++ b/inc/paginate.inc.php
@@ -19,30 +19,30 @@ class Paginate
$this->currentPage = (isset($_GET['page']) ? (int)$_GET['page'] : 0);
$this->perPage = (int)$perPage;
if ($this->currentPage < 0) {
- Util::traceError('Current page < 0');
+ ErrorHandler::traceError('Current page < 0');
}
if ($this->perPage < 1) {
- Util::traceError('Per page < 1');
+ ErrorHandler::traceError('Per page < 1');
}
// Query
if (!preg_match('/\s*SELECT\s/is', $query)) {
- Util::traceError('Query has to start with SELECT!');
+ ErrorHandler::traceError('Query has to start with SELECT!');
}
// XXX: MySQL only
if (preg_match('/^mysql/i', CONFIG_SQL_DSN)) {
// Sanity: Check for LIMIT specification at the end
if (preg_match('/LIMIT\s+(\d+|\:\w+|\?)\s*,\s*(\d+|\:\w+|\?)(\s|;)*(\-\-.*)?$/is', $query)) {
- Util::traceError("You cannot pass a query containing a LIMIT to the Paginator class!");
+ ErrorHandler::traceError("You cannot pass a query containing a LIMIT to the Paginator class!");
}
// Sanity: no comment or semi-colon at end (sloppy, might lead to false negatives)
if (preg_match('/(\-\-|;)(\s|[^\'"`])*$/is', $query)) {
- Util::traceError("Your query must not end in a comment or semi-colon!");
+ ErrorHandler::traceError("Your query must not end in a comment or semi-colon!");
}
// Don't use SQL_CALC_FOUND_ROWS as it leads to filesort frequently thus being slower than two queries
// See https://www.percona.com/blog/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/
} else {
- Util::traceError('Unsupported database engine');
+ ErrorHandler::traceError('Unsupported database engine');
}
// Mangle URL
if ($url === false) $url = $_SERVER['REQUEST_URI'];
diff --git a/inc/permission.inc.php b/inc/permission.inc.php
index cd9cc43c..abeabb1d 100644
--- a/inc/permission.inc.php
+++ b/inc/permission.inc.php
@@ -11,7 +11,7 @@ class Permission
public static function get($permission)
{
- if (!isset(self::$permissions[$permission])) Util::traceError('Invalid permission: ' . $permission);
+ if (!isset(self::$permissions[$permission])) ErrorHandler::traceError('Invalid permission: ' . $permission);
return self::$permissions[$permission];
}
diff --git a/inc/render.inc.php b/inc/render.inc.php
index 2c3a1da7..697646c5 100644
--- a/inc/render.inc.php
+++ b/inc/render.inc.php
@@ -28,7 +28,7 @@ class Render
public static function init()
{
if (self::$mustache !== false)
- Util::traceError('Called Render::init() twice!');
+ ErrorHandler::traceError('Called Render::init() twice!');
$options = array();
$tmp = '/tmp/bwlp-cache';
$dir = is_dir($tmp);
@@ -262,10 +262,10 @@ class Render
public static function closeTag($tag)
{
if (empty(self::$tags))
- Util::traceError('Tried to close tag ' . $tag . ' when no open tags exist.');
+ ErrorHandler::traceError('Tried to close tag ' . $tag . ' when no open tags exist.');
$last = array_pop(self::$tags);
if ($last !== $tag)
- Util::traceError('Tried to close tag ' . $tag . ' when last opened tag was ' . $last);
+ ErrorHandler::traceError('Tried to close tag ' . $tag . ' when last opened tag was ' . $last);
self::$body .= '</' . $tag . '>';
}
diff --git a/inc/session.inc.php b/inc/session.inc.php
index fc875669..3afbc4ce 100644
--- a/inc/session.inc.php
+++ b/inc/session.inc.php
@@ -13,7 +13,7 @@ class Session
private static function generateSessionId(string $salt)
{
if (self::$sid !== false)
- Util::traceError('Error: Asked to generate session id when already set.');
+ ErrorHandler::traceError('Error: Asked to generate session id when already set.');
self::$sid = sha1($salt . ','
. mt_rand(0, 65535)
. $_SERVER['REMOTE_ADDR']
@@ -74,7 +74,7 @@ class Session
public static function set(string $key, $value, $validMinutes = 60)
{
if (self::$data === false)
- Util::traceError('Tried to set session data with no active session');
+ ErrorHandler::traceError('Tried to set session data with no active session');
if ($value === false) {
unset(self::$data[$key]);
} else {
@@ -86,7 +86,7 @@ class Session
private static function loadSessionId(): bool
{
if (self::$sid !== false)
- Util::traceError('Error: Asked to load session id when already set.');
+ ErrorHandler::traceError('Error: Asked to load session id when already set.');
if (empty($_COOKIE['sid']))
return false;
$id = preg_replace('/[^a-zA-Z0-9]/', '', $_COOKIE['sid']);
@@ -115,7 +115,7 @@ class Session
private static function readSessionData(): bool
{
if (self::$data !== false)
- Util::traceError('Tried to call read session data twice');
+ ErrorHandler::traceError('Tried to call read session data twice');
$row = Database::queryFirst("SELECT userid, dateline, lastip, fixedip, data FROM session WHERE sid = :sid",
['sid' => self::$sid]);
$now = time();
@@ -149,7 +149,7 @@ class Session
$ret = setcookie('sid', self::$sid, time() + CONFIG_SESSION_TIMEOUT,
null, null, !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off', true);
if (!$ret)
- Util::traceError('Error: Could not set Cookie for Client (headers already sent)');
+ ErrorHandler::traceError('Error: Could not set Cookie for Client (headers already sent)');
}
register_shutdown_function(function () {
Session::saveInternal();
diff --git a/inc/taskmanager.inc.php b/inc/taskmanager.inc.php
index f7c72e04..a21dc5f7 100644
--- a/inc/taskmanager.inc.php
+++ b/inc/taskmanager.inc.php
@@ -288,7 +288,7 @@ class Taskmanager
if (count($parts) !== 2) {
error_log('TM: Invalid reply, no "," in payload');
} elseif ($parts[0] === 'ERROR') {
- Util::traceError('Taskmanager remote error: ' . $parts[1]);
+ ErrorHandler::traceError('Taskmanager remote error: ' . $parts[1]);
} elseif ($parts[0] === 'WARNING') {
Message::addWarning('main.taskmanager-warning', $parts[1]);
} else {
diff --git a/inc/util.inc.php b/inc/util.inc.php
index c3e70f89..d95265f4 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -5,158 +5,17 @@ class Util
private static $redirectParams = array();
/**
- * Displays an error message and stops script execution.
- * If CONFIG_DEBUG is true, it will also dump a stack trace
- * and all globally defined variables.
- * (As this might reveal sensitive data you should never enable it in production)
- */
- public static function traceError($message)
- {
- if ((defined('API') && API) || (defined('AJAX') && AJAX) || php_sapi_name() === 'cli') {
- error_log('API ERROR: ' . $message);
- error_log(self::formatBacktracePlain(debug_backtrace()));
- }
- if (php_sapi_name() === 'cli') {
- // Don't spam HTML when invoked via cli, above error_log should have gone to stdout/stderr
- exit(1);
- }
- Header('HTTP/1.1 500 Internal Server Error');
- if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'html') === false ) {
- Header('Content-Type: text/plain; charset=utf-8');
- echo 'API ERROR: ', $message, "\n", self::formatBacktracePlain(debug_backtrace());
- exit(0);
- }
- Header('Content-Type: text/html; charset=utf-8');
- echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><style>', "\n",
- ".arg { color: red; background: white; }\n",
- "h1 a { color: inherit; text-decoration: inherit; font-weight: inherit; }\n",
- '</style><title>Fatal Error</title></head><body>';
- echo '<h1>Flagrant <a href="https://www.youtube.com/watch?v=7rrZ-sA4FQc&t=2m2s" target="_blank">S</a>ystem error</h1>';
- echo "<h2>Message</h2><pre>$message</pre>";
- if (strpos($message, 'Database') !== false) {
- echo '<div><a href="install.php">Try running database setup</a></div>';
- }
- echo "<br><br>";
- if (defined('CONFIG_DEBUG') && CONFIG_DEBUG) {
- global $SLX_ERRORS;
- if (!empty($SLX_ERRORS)) {
- echo '<h2>PHP Errors</h2><pre>';
- foreach ($SLX_ERRORS as $error) {
- echo htmlspecialchars("{$error['errstr']} ({$error['errfile']}:{$error['errline']}\n");
- }
- echo '</pre>';
- }
- echo "<h2>Stack Trace</h2>";
- echo '<pre>', self::formatBacktraceHtml(debug_backtrace()), '</pre>';
- echo "<h2>Globals</h2><pre>";
- echo htmlspecialchars(print_r($GLOBALS, true));
- echo '</pre>';
- } else {
- echo <<<SADFACE
-<pre>
-________________________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶________
-____________________¶¶¶___________________¶¶¶¶_____
-________________¶¶¶_________________________¶¶¶¶___
-______________¶¶______________________________¶¶¶__
-___________¶¶¶_________________________________¶¶¶_
-_________¶¶_____________________________________¶¶¶
-________¶¶_________¶¶¶¶¶___________¶¶¶¶¶_________¶¶
-______¶¶__________¶¶¶¶¶¶__________¶¶¶¶¶¶_________¶¶
-_____¶¶___________¶¶¶¶____________¶¶¶¶___________¶¶
-____¶¶___________________________________________¶¶
-___¶¶___________________________________________¶¶_
-__¶¶____________________¶¶¶¶____________________¶¶_
-_¶¶_______________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶______________¶¶__
-_¶¶____________¶¶¶¶___________¶¶¶¶¶___________¶¶___
-¶¶¶_________¶¶¶__________________¶¶__________¶¶____
-¶¶_________¶______________________¶¶________¶¶_____
-¶¶¶______¶________________________¶¶_______¶¶______
-¶¶¶_____¶_________________________¶¶_____¶¶________
-_¶¶¶___________________________________¶¶__________
-__¶¶¶________________________________¶¶____________
-___¶¶¶____________________________¶¶_______________
-____¶¶¶¶______________________¶¶¶__________________
-_______¶¶¶¶¶_____________¶¶¶¶¶_____________________
-</pre>
-SADFACE;
- }
- echo '</body></html>';
- exit(0);
- }
-
- private static function formatArgument($arg, $expandArray = true)
- {
- if (is_string($arg)) {
- $arg = "'$arg'";
- } elseif (is_object($arg)) {
- $arg = 'instanceof ' . get_class($arg);
- } elseif (is_array($arg)) {
- if ($expandArray && count($arg) < 20) {
- $expanded = '';
- foreach ($arg as $key => $value) {
- if (!empty($expanded)) {
- $expanded .= ', ';
- }
- $expanded .= $key . ': ' . self::formatArgument($value, false);
- if (strlen($expanded) > 200)
- break;
- }
- if (strlen($expanded) <= 200)
- return '[' . $expanded . ']';
- }
- $arg = 'Array(' . count($arg) . ')';
- }
- return $arg;
- }
-
- public static function formatBacktraceHtml($trace)
- {
- $output = '';
- foreach ($trace as $idx => $line) {
- $args = array();
- foreach ($line['args'] as $arg) {
- $arg = self::formatArgument($arg);
- $args[] = '<span class="arg">' . htmlspecialchars($arg) . '</span>';
- }
- $frame = str_pad('#' . $idx, 3, ' ', STR_PAD_LEFT);
- $function = htmlspecialchars($line['function']);
- $args = implode(', ', $args);
- $file = preg_replace('~(/[^/]+)$~', '<b>$1</b>', htmlspecialchars($line['file']));
- // Add line
- $output .= $frame . ' ' . $function . '<b>(</b>'
- . $args . '<b>)</b>' . ' @ <i>' . $file . '</i>:' . $line['line'] . "\n";
- }
- return $output;
- }
-
- public static function formatBacktracePlain($trace)
- {
- $output = '';
- foreach ($trace as $idx => $line) {
- $args = array();
- foreach ($line['args'] as $arg) {
- $args[] = self::formatArgument($arg);
- }
- $frame = str_pad('#' . $idx, 3, ' ', STR_PAD_LEFT);
- $args = implode(', ', $args);
- // Add line
- $output .= "\n" . $frame . ' ' . $line['function'] . '('
- . $args . ')' . ' @ ' . $line['file'] . ':' . $line['line'];
- }
- return $output;
- }
-
- /**
* Redirects the user via a '302 Moved' header.
* An active session will be saved, any messages that haven't
* been displayed yet will be appended to the redirect.
+ *
* @param string|false $location Location to redirect to. "false" to redirect to same URL (useful after POSTs)
* @param bool $preferRedirectPost if true, use the value from $_POST['redirect'] instead of $location
*/
- public static function redirect($location = false, $preferRedirectPost = false)
+ public static function redirect($location = false, bool $preferRedirectPost = false)
{
if ($location === false) {
- $location = preg_replace('/([&?])message\[\]\=[^&]*/', '\1', $_SERVER['REQUEST_URI']);
+ $location = preg_replace('/([&?])message\[\]=[^&]*/', '\1', $_SERVER['REQUEST_URI']);
}
$messages = Message::toRequest();
if ($preferRedirectPost
@@ -189,7 +48,7 @@ SADFACE;
exit(0);
}
- public static function addRedirectParam($key, $value)
+ public static function addRedirectParam(string $key, string $value)
{
self::$redirectParams[] = $key . '=' . urlencode($value);
}
@@ -201,7 +60,7 @@ SADFACE;
* token, this function will return false and display an error.
* If the token matches, or the user is not logged in, it will return true.
*/
- public static function verifyToken()
+ public static function verifyToken(): bool
{
if (!User::isLoggedIn() && Session::get('token') === false)
return true;
@@ -218,12 +77,12 @@ SADFACE;
* _word_ is underlined
* \n is line break
*/
- public static function markup($string)
+ public static function markup(string $string): string
{
$string = htmlspecialchars($string);
- $string = preg_replace('#(^|[\n \-_/\.])\*(.+?)\*($|[ \-_/\.\!\?,:])#is', '$1<b>$2</b>$3', $string);
- $string = preg_replace('#(^|[\n \-\*/\.])_(.+?)_($|[ \-\*/\.\!\?,:])#is', '$1<u>$2</u>$3', $string);
- $string = preg_replace('#(^|[\n \-_\*\.])/(.+?)/($|[ \-_\*\.\!\?,:])#is', '$1<i>$2</i>$3', $string);
+ $string = preg_replace('#(^|[\n \-_/.])\*(.+?)\*($|[ \-_/.!?,:])#is', '$1<b>$2</b>$3', $string);
+ $string = preg_replace('#(^|[\n \-*/.])_(.+?)_($|[ \-*/.!?,:])#is', '$1<u>$2</u>$3', $string);
+ $string = preg_replace('#(^|[\n \-_*.])/(.+?)/($|[ \-_*.!?,:])#is', '$1<i>$2</i>$3', $string);
return nl2br($string);
}
@@ -236,7 +95,7 @@ SADFACE;
* @param int $shift how many units to skip, i.e. if you pass in KiB or MiB
* @return string human readable string representing the given file size
*/
- public static function readableFileSize($bytes, $decimals = -1, $shift = 0)
+ public static function readableFileSize(float $bytes, int $decimals = -1, int $shift = 0): string
{
// round doesn't reliably work for large floats, pick workaround depending on OS
if (PHP_INT_SIZE === 4) {
@@ -257,17 +116,26 @@ SADFACE;
return sprintf("%.{$decimals}f", $bytes) . "\xe2\x80\x89" . $sz[$factor + $shift];
}
- public static function sanitizeFilename($name)
+ public static function sanitizeFilename(string $name)
{
return preg_replace('/[^a-zA-Z0-9_\-]+/', '_', $name);
}
- public static function safePath($path, $prefix = '')
+ /**
+ * Make sure given path is not absolute, and does not contain '..', or weird characters.
+ * Returns sanitized path, or false if invalid. If prefix is given, also make sure
+ * $path starts with it.
+ *
+ * @param string $path path to check for safety
+ * @param string $prefix required prefix of $path
+ * @return false|string
+ */
+ public static function safePath(string $path, string $prefix = '')
{
if (empty($path))
return false;
$path = trim($path);
- if ($path[0] == '/' || preg_match('/[\x00-\x19\?\*]/', $path))
+ if ($path[0] == '/' || preg_match('/[\x00-\x19?*]/', $path))
return false;
if (strpos($path, '..') !== false)
return false;
@@ -288,7 +156,7 @@ SADFACE;
* @param int $code the code to turn into an error description
* @return string the error description
*/
- public static function uploadErrorString($code)
+ public static function uploadErrorString(int $code): string
{
switch ($code) {
case UPLOAD_ERR_INI_SIZE:
@@ -326,7 +194,7 @@ SADFACE;
* @param string $ip_addr input to check
* @return boolean true iff $ip_addr is a valid public ipv4 address
*/
- public static function isPublicIpv4($ip_addr)
+ public static function isPublicIpv4(string $ip_addr): bool
{
if (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $ip_addr))
return false;
@@ -348,23 +216,6 @@ SADFACE;
}
/**
- * Check whether $arrax contains all keys given in $keyList
- * @param array $array An array
- * @param array $keyList A list of strings which must all be valid keys in $array
- * @return boolean
- */
- public static function hasAllKeys($array, $keyList)
- {
- if (!is_array($array))
- return false;
- foreach ($keyList as $key) {
- if (!isset($array[$key]))
- return false;
- }
- return true;
- }
-
- /**
* Send a file to user for download.
*
* @param string $file path of local file
@@ -374,7 +225,7 @@ SADFACE;
* true: error while reading the file
* - on success, the function does not return
*/
- public static function sendFile($file, $name, $delete = false)
+ public static function sendFile(string $file, string $name, bool $delete = false): bool
{
while ((@ob_get_level()) > 0)
@ob_end_clean();
@@ -404,7 +255,7 @@ SADFACE;
* @param bool $secure true = only use strong random sources
* @return string|bool string of requested length, false on error
*/
- public static function randomBytes($length, $secure = true)
+ public static function randomBytes(int $length, bool $secure = true)
{
if (function_exists('random_bytes')) {
try {
@@ -453,7 +304,7 @@ SADFACE;
/**
* @return string a random UUID, v4.
*/
- public static function randomUuid()
+ public static function randomUuid(): string
{
$b = unpack('h8a/h4b/h12c', self::randomBytes(12));
return sprintf('%08s-%04s-%04x-%04x-%012s',
@@ -481,10 +332,11 @@ SADFACE;
/**
* Transform timestamp to easily readable string.
* The format depends on how far the timestamp lies in the past.
+ *
* @param int $ts unix timestamp
* @return string human readable representation
*/
- public static function prettyTime($ts)
+ public static function prettyTime(int $ts): string
{
settype($ts, 'int');
if ($ts === 0)
@@ -507,10 +359,11 @@ SADFACE;
/**
* Return localized strings for yes or no depending on $bool
+ *
* @param bool $bool Input to evaluate
* @return string Yes or No, in user's selected language
*/
- public static function boolToString($bool)
+ public static function boolToString(bool $bool): string
{
if ($bool)
return Dictionary::translate('lang_yes', true);
@@ -519,11 +372,12 @@ SADFACE;
/**
* Format a duration, in seconds, into a readable string.
+ *
* @param int $seconds The number to format
- * @param int $showSecs whether to show seconds, or rather cut after minutes
+ * @param bool $showSecs whether to show seconds, or rather cut after minutes
* @return string
*/
- public static function formatDuration($seconds, $showSecs = true)
+ public static function formatDuration(int $seconds, bool $showSecs = true): string
{
settype($seconds, 'int');
static $UNITS = ['y' => 31536000, 'mon' => 2592000, 'd' => 86400];
@@ -550,9 +404,10 @@ SADFACE;
* was a weird problem where firefox would keep sending a cookie with
* path /slx-admin/ but trying to delete it from /slx-admin, which php's
* setcookie automatically sends by default, did not clear it.
+ *
* @param string $name cookie name
*/
- public static function clearCookie($name)
+ public static function clearCookie(string $name)
{
$parts = explode('/', $_SERVER['SCRIPT_NAME']);
$path = '';
@@ -567,7 +422,7 @@ SADFACE;
/**
* Remove any non-utf8 sequences from string.
*/
- public static function cleanUtf8(string $string) : string
+ public static function cleanUtf8(string $string): string
{
// https://stackoverflow.com/a/1401716/2043481
$regex = '/
@@ -586,7 +441,7 @@ SADFACE;
/**
* Remove non-printable < 0x20 chars from ANSI string, then convert to UTF-8
*/
- public static function ansiToUtf8(string $string) : string
+ public static function ansiToUtf8(string $string): string
{
$regex = '/
(
diff --git a/index.php b/index.php
index 5b968dae..d5364306 100644
--- a/index.php
+++ b/index.php
@@ -77,7 +77,7 @@ abstract class Page
Module::init();
self::$module = Module::get($name);
if (self::$module === false) {
- Util::traceError('Invalid Module: ' . $name);
+ ErrorHandler::traceError('Invalid Module: ' . $name);
}
self::$module->activate(null, null);
self::$instance = self::$module->newPage();
diff --git a/modules-available/baseconfig/inc/validator.inc.php b/modules-available/baseconfig/inc/validator.inc.php
index f7bbc861..38c595c4 100644
--- a/modules-available/baseconfig/inc/validator.inc.php
+++ b/modules-available/baseconfig/inc/validator.inc.php
@@ -34,7 +34,7 @@ class Validator
case 'multiinput':
return self::validateMultiInput($data[1] ?? [], $displayValue);
default:
- Util::traceError('Unknown validation method: ' . $data[0]);
+ ErrorHandler::traceError('Unknown validation method: ' . $data[0]);
}
return false; // make code inspector happy - doesn't know traceError doesn't return
}
diff --git a/modules-available/dozmod/api.inc.php b/modules-available/dozmod/api.inc.php
index c2dc1cfa..c71ea946 100644
--- a/modules-available/dozmod/api.inc.php
+++ b/modules-available/dozmod/api.inc.php
@@ -291,7 +291,7 @@ function readImageParam()
$resource = Request::get('resource', false, 'string');
if ($resource === false) {
- Util::traceError("you have to specify the 'resource' parameter");
+ ErrorHandler::traceError("you have to specify the 'resource' parameter");
}
if (!in_array($resource, $availableRessources)) {
diff --git a/modules-available/dozmod/page.inc.php b/modules-available/dozmod/page.inc.php
index cf6e4857..a38c9d9d 100644
--- a/modules-available/dozmod/page.inc.php
+++ b/modules-available/dozmod/page.inc.php
@@ -22,7 +22,7 @@ class Page_DozMod extends Page
break;
}
} elseif (!in_array($this->section, $this->validSections)) {
- Util::traceError('Invalid section: ' . $this->section);
+ ErrorHandler::traceError('Invalid section: ' . $this->section);
}
// Check permissions
User::assertPermission($this->section . '.*');
diff --git a/modules-available/dozmod/pages/actionlog.inc.php b/modules-available/dozmod/pages/actionlog.inc.php
index 51fccb4f..0b6feb6f 100644
--- a/modules-available/dozmod/pages/actionlog.inc.php
+++ b/modules-available/dozmod/pages/actionlog.inc.php
@@ -11,7 +11,7 @@ class SubPage
User::assertPermission("actionlog.view");
self::$action = Request::get('action', '', 'string');
if (self::$action !== '' && self::$action !== 'showtarget' && self::$action !== 'showuser') {
- Util::traceError('Invalid action for actionlog: "' . self::$action . '"');
+ ErrorHandler::traceError('Invalid action for actionlog: "' . self::$action . '"');
}
self::$uuid = Request::get('uuid', '', 'string');
}
diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php
index 317e56c0..458ae5b1 100644
--- a/modules-available/exams/page.inc.php
+++ b/modules-available/exams/page.inc.php
@@ -296,7 +296,7 @@ class Page_Exams extends Page
private function saveExam()
{
if (!Request::isPost()) {
- Util::traceError('Is not post');
+ ErrorHandler::traceError('Is not post');
}
/* process form-data */
$locationids = Request::post('locations', [], "ARRAY");
@@ -453,7 +453,7 @@ class Page_Exams extends Page
} elseif ($this->action === false) {
- Util::traceError("action not implemented");
+ ErrorHandler::traceError("action not implemented");
}
}
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index d4fa50ac..440a115d 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -425,7 +425,7 @@ class Page_LocationInfo extends Page
private function checkConnection($serverid = 0)
{
if ($serverid === 0) {
- Util::traceError('checkConnection called with no server id');
+ ErrorHandler::traceError('checkConnection called with no server id');
}
User::assertPermission('backend.check');
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index 718d32e3..65ea06f5 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -87,7 +87,7 @@ class Location
private static function flattenTreeAssoc($tree, $parents = array(), $depth = 0)
{
if ($depth > 20) {
- Util::traceError('Recursive location definition detected at ' . print_r($tree, true));
+ ErrorHandler::traceError('Recursive location definition detected at ' . print_r($tree, true));
}
$output = array();
foreach ($tree as $node) {
@@ -230,7 +230,7 @@ class Location
private static function flattenTree($tree, $depth = 0)
{
if ($depth > 20) {
- Util::traceError('Recursive location definition detected at ' . print_r($tree, true));
+ ErrorHandler::traceError('Recursive location definition detected at ' . print_r($tree, true));
}
$output = array();
foreach ($tree as $node) {
diff --git a/modules-available/rebootcontrol/pages/task.inc.php b/modules-available/rebootcontrol/pages/task.inc.php
index 322b1ea9..0e770618 100644
--- a/modules-available/rebootcontrol/pages/task.inc.php
+++ b/modules-available/rebootcontrol/pages/task.inc.php
@@ -93,7 +93,7 @@ class SubPage
} elseif ($type === RebootControl::TASK_WOL) {
// Nothing (yet)
} else {
- Util::traceError('oopsie');
+ ErrorHandler::traceError('oopsie');
}
$job['timestamp_s'] = Util::prettyTime($job['timestamp']);
Render::addTemplate('status-' . $template, $job);
diff --git a/modules-available/statistics/inc/statistics.inc.php b/modules-available/statistics/inc/statistics.inc.php
index e3eaccc0..d27c1a6a 100644
--- a/modules-available/statistics/inc/statistics.inc.php
+++ b/modules-available/statistics/inc/statistics.inc.php
@@ -19,7 +19,7 @@ class Statistics
} elseif ($returnData === Machine::RAW_DATA) {
self::$machineFields['data'] = true;
} else {
- Util::traceError('Invalid $returnData option passed');
+ ErrorHandler::traceError('Invalid $returnData option passed');
}
return implode(',', array_keys(self::$machineFields));
}
diff --git a/modules-available/statistics/inc/statisticsfilter.inc.php b/modules-available/statistics/inc/statisticsfilter.inc.php
index f33c423f..a53ef4d1 100644
--- a/modules-available/statistics/inc/statisticsfilter.inc.php
+++ b/modules-available/statistics/inc/statisticsfilter.inc.php
@@ -107,7 +107,7 @@ abstract class StatisticsFilter
if (empty($this->ops))
return;
if (!in_array($operator, $this->ops)) {
- Util::traceError("Invalid op '$operator' for " . get_class($this) . '::' . $this->column);
+ ErrorHandler::traceError("Invalid op '$operator' for " . get_class($this) . '::' . $this->column);
}
}
@@ -574,7 +574,7 @@ class LocationStatisticsFilter extends EnumStatisticsFilter
$operator = str_replace('~', '=', $operator);
if ($recursive && is_array($argument)) {
- Util::traceError('Cannot use ~ operator for location with array');
+ ErrorHandler::traceError('Cannot use ~ operator for location with array');
}
if ($recursive) {
$argument = array_keys(Location::getRecursiveFlat($argument));
diff --git a/modules-available/statistics/pages/projectors.inc.php b/modules-available/statistics/pages/projectors.inc.php
index 91abfe9c..01be2971 100644
--- a/modules-available/statistics/pages/projectors.inc.php
+++ b/modules-available/statistics/pages/projectors.inc.php
@@ -16,7 +16,7 @@ class SubPage
User::assertPermission('hardware.projectors.edit');
$hwid = Request::post('hwid', false, 'int');
if ($hwid === false) {
- Util::traceError('Param hwid missing');
+ ErrorHandler::traceError('Param hwid missing');
}
if ($action === 'addprojector') {
Database::exec('INSERT IGNORE INTO statistic_hw_prop (hwid, prop, value)'
diff --git a/modules-available/sysconfig/addconfig.inc.php b/modules-available/sysconfig/addconfig.inc.php
index af8aab37..8df700f9 100644
--- a/modules-available/sysconfig/addconfig.inc.php
+++ b/modules-available/sysconfig/addconfig.inc.php
@@ -33,7 +33,7 @@ abstract class AddConfig_Base
if (($editId = Request::any('edit', 0, 'int')) !== 0) {
self::$instance->edit = ConfigTgz::get($editId);
if (self::$instance->edit === false)
- Util::traceError('Invalid config id for editing');
+ ErrorHandler::traceError('Invalid config id for editing');
Util::addRedirectParam('edit', self::$instance->edit->id());
}
}
@@ -74,7 +74,7 @@ abstract class AddConfig_Base
public static function preprocess()
{
if (self::$instance === false) {
- Util::traceError('No step instance yet');
+ ErrorHandler::traceError('No step instance yet');
}
self::$instance->preprocessInternal();
}
@@ -82,7 +82,7 @@ abstract class AddConfig_Base
public static function render()
{
if (self::$instance === false)
- Util::traceError('No step instance yet');
+ ErrorHandler::traceError('No step instance yet');
if (self::$instance->edit !== false)
Message::addInfo('replacing-config', self::$instance->edit->title());
self::$instance->renderInternal();
@@ -91,7 +91,7 @@ abstract class AddConfig_Base
public static function ajax()
{
if (self::$instance === false) {
- Util::traceError('No step instance yet');
+ ErrorHandler::traceError('No step instance yet');
}
self::$instance->ajaxInternal();
}
diff --git a/modules-available/sysconfig/addmodule.inc.php b/modules-available/sysconfig/addmodule.inc.php
index 91fee45d..477326b8 100644
--- a/modules-available/sysconfig/addmodule.inc.php
+++ b/modules-available/sysconfig/addmodule.inc.php
@@ -34,9 +34,9 @@ abstract class AddModule_Base
if ($editId = $editId ? $editId : Request::any('edit')) {
self::$instance->edit = ConfigModule::get($editId);
if (self::$instance->edit === false)
- Util::traceError('Invalid module id for editing');
+ ErrorHandler::traceError('Invalid module id for editing');
if ($step !== 'AddModule_Assign' && !preg_match('/^' . self::$instance->edit->moduleType() . '_/', $step))
- Util::traceError('Module to edit is of different type!');
+ ErrorHandler::traceError('Module to edit is of different type!');
Util::addRedirectParam('edit', self::$instance->edit->id());
}
}
@@ -90,7 +90,7 @@ abstract class AddModule_Base
public static function preprocess()
{
if (self::$instance === false) {
- Util::traceError('No step instance yet');
+ ErrorHandler::traceError('No step instance yet');
}
self::$instance->preprocessInternal();
}
@@ -98,7 +98,7 @@ abstract class AddModule_Base
public static function render()
{
if (self::$instance === false) {
- Util::traceError('No step instance yet');
+ ErrorHandler::traceError('No step instance yet');
}
if (get_class(self::$instance) !== 'AddModule_Assign' && self::$instance->edit !== false) {
Message::addInfo('replacing-module', self::$instance->edit->title());
@@ -109,7 +109,7 @@ abstract class AddModule_Base
public static function ajax()
{
if (self::$instance === false) {
- Util::traceError('No step instance yet');
+ ErrorHandler::traceError('No step instance yet');
}
self::$instance->ajaxInternal();
}
diff --git a/modules-available/sysconfig/inc/configmodule.inc.php b/modules-available/sysconfig/inc/configmodule.inc.php
index fadc649a..269146d3 100644
--- a/modules-available/sysconfig/inc/configmodule.inc.php
+++ b/modules-available/sysconfig/inc/configmodule.inc.php
@@ -68,15 +68,15 @@ abstract class ConfigModule
public static function registerModule($id, $title, $description, $group, $unique, $sortOrder = 0)
{
if (isset(self::$moduleTypes[$id])) {
- Util::traceError("Config Module $id already registered!");
+ ErrorHandler::traceError("Config Module $id already registered!");
}
$moduleClass = 'ConfigModule_' . $id;
$wizardClass = $id . '_Start';
if (!class_exists($moduleClass)) {
- Util::traceError("Class $moduleClass does not exist!");
+ ErrorHandler::traceError("Class $moduleClass does not exist!");
}
if (!is_subclass_of($moduleClass, 'ConfigModule')) {
- Util::traceError("$moduleClass does not have ConfigModule as its parent!");
+ ErrorHandler::traceError("$moduleClass does not have ConfigModule as its parent!");
}
self::$moduleTypes[$id] = array(
'title' => $title,
@@ -277,10 +277,10 @@ abstract class ConfigModule
{
$name = get_class($this);
if ($name === false)
- Util::traceError('ConfigModule::moduleType: get_class($this) returned false!');
+ ErrorHandler::traceError('ConfigModule::moduleType: get_class($this) returned false!');
// ConfigModule_*
if (!preg_match('/^ConfigModule_(\w+)$/', $name, $out))
- Util::traceError('ConfigModule::moduleType: get_class($this) returned "' . $name . '"');
+ ErrorHandler::traceError('ConfigModule::moduleType: get_class($this) returned "' . $name . '"');
return $out[1];
}
@@ -295,7 +295,7 @@ abstract class ConfigModule
public final function insert($title)
{
if ($this->moduleId !== 0)
- Util::traceError('ConfigModule::insert called when moduleId != 0');
+ ErrorHandler::traceError('ConfigModule::insert called when moduleId != 0');
if (!$this->validateConfig())
return false;
$this->moduleTitle = $title;
@@ -311,7 +311,7 @@ abstract class ConfigModule
));
$this->moduleId = Database::lastInsertId();
if (!is_numeric($this->moduleId))
- Util::traceError('Inserting new config module into DB did not yield a numeric insert id');
+ ErrorHandler::traceError('Inserting new config module into DB did not yield a numeric insert id');
$this->moduleArchive = $this->createFileName();
Database::exec("UPDATE configtgz_module SET filepath = :path WHERE moduleid = :moduleid LIMIT 1", array(
'path' => $this->moduleArchive,
@@ -329,7 +329,7 @@ abstract class ConfigModule
public final function update($title = '')
{
if ($this->moduleId === 0)
- Util::traceError('ConfigModule::update called when moduleId == 0');
+ ErrorHandler::traceError('ConfigModule::update called when moduleId == 0');
if (!empty($title)) {
$this->moduleTitle = $title;
}
@@ -362,7 +362,7 @@ abstract class ConfigModule
public final function generate($deleteOnError, $parent = NULL, $timeoutMs = 0)
{
if ($this->moduleId === 0 || $this->moduleTitle === false)
- Util::traceError('ConfigModule::generateAsync called on uninitialized/uninserted module!');
+ ErrorHandler::traceError('ConfigModule::generateAsync called on uninitialized/uninserted module!');
$tmpTgz = '/tmp/bwlp-id-' . $this->moduleId . '_' . mt_rand() . '_' . time() . '.tgz';
$ret = $this->generateInternal($tmpTgz, $parent);
// Wait for generation if requested
@@ -398,7 +398,7 @@ abstract class ConfigModule
public final function delete()
{
if ($this->moduleId === 0)
- Util::traceError('ConfigModule::delete called with invalid module id!');
+ ErrorHandler::traceError('ConfigModule::delete called with invalid module id!');
$ret = Database::exec("DELETE FROM configtgz_module WHERE moduleid = :moduleid LIMIT 1", array(
'moduleid' => $this->moduleId
), true) !== false;
@@ -416,7 +416,7 @@ abstract class ConfigModule
private final function markUpdated($tmpTgz)
{
if ($this->moduleId === 0)
- Util::traceError('ConfigModule::markUpdated called with invalid module id!');
+ ErrorHandler::traceError('ConfigModule::markUpdated called with invalid module id!');
if ($this->moduleArchive === false)
$this->moduleArchive = $this->createFileName();
// Move file
@@ -463,7 +463,7 @@ abstract class ConfigModule
private final function markFailed()
{
if ($this->moduleId === 0)
- Util::traceError('ConfigModule::markFailed called with invalid module id!');
+ ErrorHandler::traceError('ConfigModule::markFailed called with invalid module id!');
if ($this->moduleArchive === false)
$this->moduleArchive = $this->createFileName();
if (!file_exists($this->moduleArchive))
diff --git a/modules-available/sysconfig/inc/configmodulebaseldap.inc.php b/modules-available/sysconfig/inc/configmodulebaseldap.inc.php
index 54e0febf..e3d99025 100644
--- a/modules-available/sysconfig/inc/configmodulebaseldap.inc.php
+++ b/modules-available/sysconfig/inc/configmodulebaseldap.inc.php
@@ -126,7 +126,7 @@ abstract class ConfigModuleBaseLdap extends ConfigModule
protected function validateConfig()
{
// Check if required fields are filled
- return Util::hasAllKeys($this->moduleData, self::$REQUIRED_FIELDS);
+ return ArrayUtil::hasAllKeys($this->moduleData, self::$REQUIRED_FIELDS);
}
public function setData($key, $value)
diff --git a/modules-available/sysconfig/inc/configtgz.inc.php b/modules-available/sysconfig/inc/configtgz.inc.php
index 015b5ccf..67e02503 100644
--- a/modules-available/sysconfig/inc/configtgz.inc.php
+++ b/modules-available/sysconfig/inc/configtgz.inc.php
@@ -26,7 +26,7 @@ class ConfigTgz
public function areAllModulesUpToDate()
{
if (!$this->configId > 0)
- Util::traceError('ConfigTgz::areAllModulesUpToDate called on un-inserted config.tgz!');
+ ErrorHandler::traceError('ConfigTgz::areAllModulesUpToDate called on un-inserted config.tgz!');
foreach ($this->modules as $module) {
if (!empty($module['filepath']) && file_exists($module['filepath'])) {
if ($module['status'] !== 'OK')
@@ -96,7 +96,7 @@ class ConfigTgz
public function generate($deleteOnError = false, $timeoutMs = 0, $parentTask = null)
{
if (!($this->configId > 0) || !is_array($this->modules) || $this->file === false)
- Util::traceError ('configId <= 0 or modules not array in ConfigTgz::rebuild()');
+ ErrorHandler::traceError('configId <= 0 or modules not array in ConfigTgz::rebuild()');
$files = array();
// Get all config modules for system config
foreach ($this->modules as $module) {
@@ -137,7 +137,7 @@ class ConfigTgz
public function delete()
{
if ($this->configId === 0)
- Util::traceError('ConfigTgz::delete called with invalid config id!');
+ ErrorHandler::traceError('ConfigTgz::delete called with invalid config id!');
$ret = Database::exec("DELETE FROM configtgz WHERE configid = :configid LIMIT 1",
['configid' => $this->configId], true);
if ($ret !== false) {
@@ -153,14 +153,14 @@ class ConfigTgz
public function markOutdated()
{
if ($this->configId === 0)
- Util::traceError('ConfigTgz::markOutdated called with invalid config id!');
+ ErrorHandler::traceError('ConfigTgz::markOutdated called with invalid config id!');
return $this->mark('OUTDATED');
}
private function markUpdated($task)
{
if ($this->configId === 0)
- Util::traceError('ConfigTgz::markUpdated called with invalid config id!');
+ ErrorHandler::traceError('ConfigTgz::markUpdated called with invalid config id!');
if ($this->areAllModulesUpToDate()) {
if (empty($task['data']['warnings'])) {
$warnings = '';
@@ -194,7 +194,7 @@ class ConfigTgz
private function markFailed()
{
if ($this->configId === 0)
- Util::traceError('ConfigTgz::markFailed called with invalid config id!');
+ ErrorHandler::traceError('ConfigTgz::markFailed called with invalid config id!');
if ($this->file === false || !file_exists($this->file))
return $this->mark('MISSING');
return $this->mark('OUTDATED');