my_logger: make the tag optional

This commit is contained in:
ljm42
2024-02-02 13:02:40 -07:00
parent 551f85ad92
commit 0287d8dfac
7 changed files with 12 additions and 12 deletions

View File

@@ -367,7 +367,7 @@ class DockerTemplates {
@copy($iconRAM,$icon);
}
if (!is_file($iconRAM)) {
my_logger('webGUI', "$contName: Could not download icon $imgUrl");
my_logger("$contName: Could not download icon $imgUrl");
}
return (is_file($iconRAM)) ? str_replace($docroot, '', $iconRAM) : '';

View File

@@ -119,12 +119,12 @@ function verifyTwoFactorToken(string $username, string $token): bool {
// This should accept 200 or 204 status codes
if ($httpCode !== 200 && $httpCode !== 204) {
// Log error to syslog
my_logger('webGUI', "2FA code for {$username} is invalid, blocking access!");
my_logger("2FA code for {$username} is invalid, blocking access!");
return false;
}
// Log success to syslog
my_logger('webGUI', "2FA code for {$username} is valid, allowing login!");
my_logger("2FA code for {$username} is valid, allowing login!");
// Success
return true;
@@ -199,7 +199,7 @@ if (!empty($username) && !empty($password)) {
// Check if we're limited
if ($failCount >= $maxFails) {
if ($failCount == $maxFails) my_logger('webGUI', "Ignoring login attempts for {$username} from {$remote_addr}");
if ($failCount == $maxFails) my_logger("Ignoring login attempts for {$username} from {$remote_addr}");
throw new Exception(_('Too many invalid login attempts'));
}
@@ -216,7 +216,7 @@ if (!empty($username) && !empty($password)) {
$_SESSION['unraid_user'] = $username;
session_regenerate_id(true);
session_write_close();
my_logger('webGUI', "Successful login user {$username} from {$remote_addr}");
my_logger("Successful login user {$username} from {$remote_addr}");
// Redirect the user to the start page
header("Location: /".$start_page);
@@ -226,7 +226,7 @@ if (!empty($username) && !empty($password)) {
$error = $exception->getMessage();
// Log error to syslog
my_logger('webGUI', "Unsuccessful login user {$username} from {$remote_addr}");
my_logger("Unsuccessful login user {$username} from {$remote_addr}");
appendToFile($failFile, $time."\n");
}
}

View File

@@ -36,7 +36,7 @@ if (!empty($_POST['password']) && !empty($_POST['confirmPassword'])) {
}
// Error when attempting to set password
my_logger('webGUI', "{$VALIDATION_MESSAGES['saveError']} [REMOTE_ADDR]: {$REMOTE_ADDR}");
my_logger("{$VALIDATION_MESSAGES['saveError']} [REMOTE_ADDR]: {$REMOTE_ADDR}");
return $POST_ERROR = $VALIDATION_MESSAGES['saveError'];
}

View File

@@ -33,7 +33,7 @@ function build_pages($pattern) {
foreach (glob($pattern,GLOB_NOSORT) as $entry) {
[$header, $content] = my_explode("\n---\n",file_get_contents($entry));
$page = @parse_ini_string($header);
if (!$page) {my_logger('webGUI', "Invalid .page format: $entry"); continue;}
if (!$page) {my_logger("Invalid .page format: $entry"); continue;}
$page['file'] = $entry;
$page['root'] = dirname($entry);
$page['name'] = basename($entry, '.page');

View File

@@ -146,7 +146,7 @@ function my_date($fmt, $time) {
return date(strtr($fmt,$legacy), $time);
}
// ensure params passed to logger are properly escaped
function my_logger($tag, $message) {
function my_logger($message, $tag="webgui") {
exec('logger -t '.escapeshellarg($tag).' -- '.escapeshellarg($message));
}
?>

View File

@@ -20,7 +20,7 @@ function curl_socket($socket, $url, $message='') {
if ($message) curl_setopt_array($com, [CURLOPT_POSTFIELDS => $message, CURLOPT_POST => 1]);
$reply = curl_exec($com);
curl_close($com);
if ($reply===false) my_logger('curl_socket', "curl to $url failed");
if ($reply===false) my_logger("curl to $url failed", 'curl_socket');
return $reply;
}
@@ -35,7 +35,7 @@ function publish($endpoint, $message, $len=1) {
]);
$reply = curl_exec($com);
curl_close($com);
if ($reply===false) my_logger('publish', "curl to $endpoint failed");
if ($reply===false) my_logger("curl to $endpoint failed", 'publish');
return $reply;
}
?>

View File

@@ -28,7 +28,7 @@ function update_wireguard($ifname) {
$vtun = basename($wg,'.conf');
// interface has changed?
if (exec("grep -Pom1 ' dev $nic ' $wg")=='') {
my_logger('netconfig', "updated wireguard $vtun configuration");
my_logger("updated wireguard $vtun configuration", 'netconfig');
exec("sed -ri 's/ dev (br0|bond0|eth0) / dev $nic /' $wg");
}
// restart active wireguard tunnels