Updated logger registration

This commit is contained in:
bergware
2023-10-03 10:21:19 +02:00
parent b51719bce4
commit ac0e67eeac
15 changed files with 81 additions and 47 deletions

View File

@@ -6,7 +6,10 @@ cfg=/boot/config/plugins/dynamix.apcupsd/dynamix.apcupsd.cfg
[[ -f /var/run/apcupsd.pid || ! -f $cfg ]] && exit
# Read settings
source $cfg
. $cfg
# run & log functions
. /etc/rc.d/rc.runlog
# Apply settings
sed -i -e '/^NISIP/c\\NISIP 0.0.0.0' $conf
@@ -27,4 +30,4 @@ else
fi
# Start daemon
[[ $SERVICE == enable ]] && /etc/rc.d/rc.apcupsd start |& logger
[[ $SERVICE == enable ]] && /etc/rc.d/rc.apcupsd start |& log

View File

@@ -368,7 +368,7 @@ class DockerTemplates {
@copy($iconRAM,$icon);
}
if ( !is_file($iconRAM) ) {
exec("/usr/bin/logger -- ".escapeshellarg("$imageName: Could not download icon $imgUrl"));
exec("logger -t webGUI -- \"$imageName: Could not download icon $imgUrl\"");
}
return (is_file($iconRAM)) ? str_replace($docroot, '', $iconRAM) : '';

View File

@@ -2,9 +2,12 @@
# Intialize libvirt config storage
# Invoked by emhttp after mounting libvirt loopback but before starting libvirt.
# run & log functions
. /etc/rc.d/rc.runlog
# missing qemu directory would indicate new libvirt image file created
if [ ! -d /etc/libvirt/qemu ]; then
logger -- "initializing /etc/libvirt"
log "initializing /etc/libvirt"
# initialize with default settings
cp -rp /etc/libvirt-/* /etc/libvirt
# check if libvirt image file exists on USB flash

View File

@@ -1,3 +1,7 @@
#!/bin/bash
/usr/bin/logger -- "Submitting SysDrivers Build"
/usr/local/emhttp/plugins/dynamix/include/SysDriversInit.php &> /dev/null &
# run & log functions
. /etc/rc.d/rc.runlog
log "Submitting SysDrivers Build"
/usr/local/emhttp/plugins/dynamix/include/SysDriversInit.php &>/dev/null &

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
exec("logger -t webGUI -- ".escapeshellarg("2FA code for {$username} is invalid, blocking access!"));
exec("logger -t webGUI -- \"2FA code for {$username} is invalid, blocking access!\"");
return false;
}
// Log success to syslog
exec("logger -t webGUI -- ".escapeshellarg("2FA code for {$username} is valid, allowing login!"));
exec("logger -t webGUI -- \"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) exec("logger -t webGUI -- ".escapeshellarg("Ignoring login attempts for {$username} from {$remote_addr}"));
if ($failCount == $maxFails) exec("logger -t webGUI -- \"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();
exec("logger -t webGUI -- ".escapeshellarg("Successful login user {$username} from {$remote_addr}"));
exec("logger -t webGUI -- \"Successful login user {$username} from {$remote_addr}\"");
// Redirect the user to the start page
header("Location: /".$var['START_PAGE']);
@@ -226,7 +226,7 @@ if (!empty($username) && !empty($password)) {
$error = $exception->getMessage();
// Log error to syslog
exec("logger -t webGUI -- ".escapeshellarg("Unsuccessful login user {$username} from {$remote_addr}"));
exec("logger -t webGUI -- \"Unsuccessful login user {$username} from {$remote_addr}\"");
appendToFile($failFile, $time."\n");
}
}

View File

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

View File

@@ -1,13 +1,11 @@
#!/usr/bin/php
<?php
function SysDriverslog($m, $type = "NOTICE") {
if ($type == "DEBUG" ) return NULL;
$m = print_r($m,true);
$m = str_replace("\n", " ", $m);
$m = str_replace('"', "'", $m);
$cmd = "/usr/bin/logger -t SysDrivers -- \"$m\"";
exec($cmd);
if ($type == "DEBUG") return NULL;
$m = print_r($m,true);
$m = str_replace("\n", " ", $m);
$m = str_replace('"', "'", $m);
exec("logger -t webGUI -- \"$m\"");
}
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
@@ -15,7 +13,7 @@ $docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/Translations.php";
require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/webGui/include/SysDriversHelpers.php";
require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php";
require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php";
$kernel = shell_exec("uname -r") ;
$kernel = trim($kernel,"\n") ;
@@ -27,6 +25,6 @@ $arrModtoPlg = json_decode(file_get_contents("/tmp/modulestoplg.json") ,TRUE) ;
file_put_contents("/tmp/sysdrivers.init","1") ;
SysDriverslog("SysDrivers Build Starting") ;
modtoplg() ;
createlist() ;
createlist() ;
SysDriverslog("SysDrivers Build Complete") ;
?>

View File

@@ -10,14 +10,15 @@
*/
?>
<?
/* This file provides basic local setup for php cli and is
* named in /etc/php/php.ini like this:
* auto_prepend_file="/usr/local/emhttp/webGui/include/local_prepend.php"
*/
// This file provides basic local setup for php cli and is
// named in /etc/php/php.ini like this:
// auto_prepend_file="/usr/local/emhttp/webGui/include/local_prepend.php"
function csrf_terminate($reason) {
shell_exec("logger -- ".escapeshellarg("error: ".$_SERVER['REQUEST_URI']).": $reason csrf_token");
exit;
exec("logger -t webGUI -- \"error: {$_SERVER['REQUEST_URI']} - {$reason} csrf_token\"");
exit;
}
putenv('PATH=.:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin');
chdir('/usr/local/emhttp');
setlocale(LC_ALL,'en_US.UTF-8');
@@ -28,14 +29,14 @@ ini_set("session.use_strict_mode", "1");
// ini_set("session.cookie_samesite", $secure?'Strict':'Lax');
ini_set("session.cookie_samesite", 'Lax');
if (array_key_exists('HTTP_HOST', $_SERVER)) {
session_name("unraid_".md5(strstr($_SERVER['HTTP_HOST'].':', ':', true)));
session_name("unraid_".md5(strstr($_SERVER['HTTP_HOST'].':', ':', true)));
}
session_set_cookie_params(0, '/', null, $secure, true);
if ($_SERVER['SCRIPT_NAME'] != '/login.php' && $_SERVER['SCRIPT_NAME'] != '/auth-request.php' && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
if (!isset($var)) $var = parse_ini_file('state/var.ini');
if (!isset($var['csrf_token'])) csrf_terminate("uninitialized");
if (!isset($_POST['csrf_token'])) csrf_terminate("missing");
if ($var['csrf_token'] != $_POST['csrf_token']) csrf_terminate("wrong");
unset($_POST['csrf_token']);
if (!isset($var)) $var = parse_ini_file('state/var.ini');
if (!isset($var['csrf_token'])) csrf_terminate("uninitialized");
if (!isset($_POST['csrf_token'])) csrf_terminate("missing");
if ($var['csrf_token'] != $_POST['csrf_token']) csrf_terminate("wrong");
unset($_POST['csrf_token']);
}
?>

View File

@@ -4,9 +4,13 @@ SERVICES="rpc nfsd ntpd nginx sshd avahidaemon samba"
if [[ -n $1 ]]; then
[[ ! -e $1 ]] && touch $1 || exit 0
fi
# run & log functions
. /etc/rc.d/rc.runlog
for cmd in $SERVICES; do
if /etc/rc.d/rc.$cmd update; then
logger -t network -- "reload service: $cmd"
log "$cmd"
/etc/rc.d/rc.$cmd reload >/dev/null 2>&1
fi
done

View File

@@ -1,7 +1,10 @@
#!/bin/bash
lock=/tmp/atlock.tmp
logger -t network -- "update services: ${1:-1}s"
# run & log functions
. /etc/rc.d/rc.runlog
log "${1:-1}s"
rm -f $lock
echo "sleep ${1:-1};/usr/local/emhttp/webGui/scripts/reload_services $lock"|at -M now 2>/dev/null
exit 0

View File

@@ -1,4 +1,8 @@
#!/bin/bash
# run & log functions
. /etc/rc.d/rc.runlog
while :; do
if [[ -x /usr/bin/upnpc ]]; then
UPNP=/var/tmp/upnp
@@ -34,7 +38,7 @@ while :; do
IP=$(ip -4 addr show dev $LINK|grep -Pom1 'inet \K.[^/]+')
PORT=$(wg show $WG listen-port)
upnpc -u $XML -m $LINK -e "WireGuard-$WG" -a $IP $PORT $PORT udp >/dev/null 2>&1
[[ $? -eq 0 ]] && logger -t upnpc -- "Added port $PORT/udp" || logger -t upnpc -- "Failed to add port $PORT/udp"
[[ $? -eq 0 ]] && log "Added port $PORT/udp" || log "Failed to add port $PORT/udp"
fi
done
fi

View File

@@ -9,6 +9,9 @@ LINK=$2
UPNP=/var/tmp/upnp
XML=$(cat $UPNP 2>/dev/null)
# run & log functions
. /etc/rc.d/rc.runlog
if [[ -n $XML ]]; then
# validate XML
timeout 6 stdbuf -o0 upnpc -u $XML -m $LINK -l 2>&1|grep -qm1 'refused'
@@ -33,23 +36,23 @@ fi
WG=$(wg show interfaces)
POLLER=/usr/local/emhttp/webGui/scripts/upnp_poller
case $1 in
add)
case "$1" in
'add')
upnpc -u $XML -m $LINK -e $3 -a $4 $5 $6 $7 >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
[[ -n $WG ]] && at -M -f ${POLLER}_start now 2>/dev/null
logger -t upnpc -- "Added port $5/$7"
log "Added port $5/$7"
else
logger -t upnpc -- "Failed to add port $5/$7"
log "Failed to add port $5/$7"
fi
;;
del)
'del')
upnpc -u $XML -m $LINK -d $3 $4 >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
[[ -z $WG && -n $(pgrep -f $POLLER) ]] && pkill -f $POLLER
logger -t upnpc -- "Deleted port $3/$4"
log "Deleted port $3/$4"
else
logger -t upnpc -- "Failed to delete port $3/$4"
log "Failed to delete port $3/$4"
fi
;;
esac

View File

@@ -17,6 +17,9 @@ CFG=/boot/config/network.cfg
declare -A VLANID USE_DHCP IPADDR NETMASK GATEWAY METRIC USE_DHCP6 IPADDR6 NETMASK6 GATEWAY6 PRIVACY6 METRIC6 DESCRIPTION PROTOCOL
# run & log functions
. /etc/rc.d/rc.runlog
mask(){
# convert prefix to netmask
set -- $((5-(${1:-0}/8))) 255 255 255 255 $(((255<<(8-(${1:-0}%8)))&255)) 0 0 0
@@ -31,7 +34,7 @@ dns() {
if [[ -s $CFG ]]; then
# import existing settings
. <(fromdos < $CFG)
. <(fromdos <$CFG)
else
# import default settings
IPADDR=
@@ -222,7 +225,7 @@ done
# atomically update file
mv $INI ${INI%.*}
logger -t network -- "hook services: interface=${interface:-$1}, reason=$reason, protocol=$protocol"
log "hook services: interface=${interface:-$1}, reason=$reason, protocol=$protocol"
# delayed execution
/usr/local/emhttp/webGui/scripts/update_services 30

View File

@@ -5,6 +5,9 @@ disk_load=/var/local/emhttp/diskload.ini # disk load statistics
nginx=/var/run/nginx.socket # nginx local access
status=http://localhost/pub/session?buffer_length=1 # nchan information about GUI subscribers
# run & log functions
. /etc/rc.d/rc.runlog
while :; do
# only act when GUI registered nchan processes are running
if [[ -e $nchan_pid ]]; then
@@ -15,7 +18,7 @@ while :; do
# steady state?
subs=$(curl --unix-socket $nginx $status 2>/dev/null|grep -Pom1 'subscribers: \K\d+')
if [[ -z $subs || $subs -eq 0 ]]; then
logger -t monitor "Stop running nchan processes"
log "Stop running nchan processes"
# kill GUI registered nchan processes
while IFS=$'\n' read -r running; do
pkill -f $docroot/${running/:stop/}

View File

@@ -1,5 +1,10 @@
#!/bin/bash
logger "/usr/local/sbin/powerdown has been deprecated"
# run & log functions
. /etc/rc.d/rc.runlog
log "/usr/local/sbin/powerdown has been deprecated"
if [[ "$1" == "-r" ]]; then
/sbin/reboot
else