Merge branch 'unraid:master' into master

This commit is contained in:
Zack Spear
2023-10-11 20:12:49 -05:00
committed by GitHub
384 changed files with 10556 additions and 3049 deletions
+36 -25
View File
@@ -306,6 +306,36 @@ function geturls() {
return str_replace("\n", "\r\n", $urls);
}
// anonymize individual syslog files
function anonymize_syslog($file) {
global $diag, $all;
$max = 2*1024*1024; //=2MB
$log = "/$diag/logs/".basename($file);
run("todos <".escapeshellarg($file)." >".escapeshellarg("$log.txt"));
if (!$all) {
unset($titles,$rows);
run("grep -Po 'file: \K[^\"\\x27]+' ".escapeshellarg("$log.txt")." 2>/dev/null|sort|uniq", $titles);
run("sed -ri 's|\b\S+@\S+\.\S+\b|email@removed.com|;s|\b(username\|password)([=:])\S+\b|\\1\\2xxx|;s|(GUID: \S)\S+(\S) |\\1..\\2 |;s|(moving \"\S\|\"/mnt/user/\S).*(\S)\"|\\1..\\2\"|' ".escapeshellarg("$log.txt"));
run("sed -ri 's|(server: ).+(\.(my)?unraid\.net(:[0-9]+)?,)|\\1hash\\2|;s|(host: \").+(\.(my)?unraid\.net(:[0-9]+)?\")|\\1hash\\2|;s|(referrer: \"https?://).+(\.(my)?unraid\.net)|\\1hash\\2|' ".escapeshellarg("$log.txt"));
maskIP("$log.txt");
foreach ($titles as $mover) {
if (!$mover) continue;
$title = "/{$mover[0]}..".substr($mover,-1)."/...";
run("sed -i 's/".str_replace("/","\/",$mover)."/".str_replace("/","\/",$title)."/g' ".escapeshellarg("$log.txt")." 2>/dev/null");
//run("sed -ri 's|(file: [.>cr].*)[ /]$mover/.*$|\\1 file: $title|' ".escapeshellarg("$log.txt")." 2>/dev/null");
}
run("grep -n ' cache_dirs: -' ".escapeshellarg("$log.txt")." 2>/dev/null|cut -d: -f1", $rows);
for ($i = 0; $i < count($rows); $i += 2) for ($row = $rows[$i]+1; $row < $rows[$i+1]; $row++) run("sed -ri '$row s|(cache_dirs: \S).*(\S)|\\1..\\2|' ".escapeshellarg("$log.txt")." 2>/dev/null");
}
// replace consecutive repeated lines in syslog
run("awk -i inplace '{if(s!=substr(\$0,17)){if(x>0)print\"### [PREVIOUS LINE REPEATED \"x\" TIMES] ###\\r\";print;x=0}else{x++}s=substr(\$0,17)}END{if(x>0)print\"### [PREVIOUS LINE REPEATED \"x\" TIMES] ###\\r\"}' ".escapeshellarg("$log.txt"));
// remove SHA256 hashes
run("sed -ri 's/(SHA256:).+[^\s\b]/SHA256:***REMOVED***/gm' $log.txt");
// truncate syslog if too big
if (basename($file)=='syslog' && filesize($file)>=$max) run("tail -n 200 ".escapeshellarg("$log.txt")." >".escapeshellarg("$log.last200.txt"));
run("truncate -s '<$max' ".escapeshellarg("$log.txt"));
}
// diagnostics start
run("mkdir -p /boot/logs");
@@ -612,32 +642,11 @@ foreach ($all_xml as $xml) {
}
// copy syslog information (anonymize if applicable)
$max = 2*1024*1024; //=2MB
foreach (glob("/var/log/syslog*") as $file) {
$log = "/$diag/logs/".basename($file);
run("todos <".escapeshellarg($file)." >".escapeshellarg("$log.txt"));
if (!$all) {
unset($titles,$rows);
run("grep -Po 'file: \K[^\"\\x27]+' ".escapeshellarg("$log.txt")." 2>/dev/null|sort|uniq", $titles);
run("sed -ri 's|\b\S+@\S+\.\S+\b|email@removed.com|;s|\b(username\|password)([=:])\S+\b|\\1\\2xxx|;s|(GUID: \S)\S+(\S) |\\1..\\2 |;s|(moving \"\S\|\"/mnt/user/\S).*(\S)\"|\\1..\\2\"|' ".escapeshellarg("$log.txt"));
run("sed -ri 's|(server: ).+(\.(my)?unraid\.net(:[0-9]+)?,)|\\1hash\\2|;s|(host: \").+(\.(my)?unraid\.net(:[0-9]+)?\")|\\1hash\\2|;s|(referrer: \"https?://).+(\.(my)?unraid\.net)|\\1hash\\2|' ".escapeshellarg("$log.txt"));
maskIP("$log.txt");
foreach ($titles as $mover) {
if (!$mover) continue;
$title = "/{$mover[0]}..".substr($mover,-1)."/...";
run("sed -i 's/".str_replace("/","\/",$mover)."/".str_replace("/","\/",$title)."/g' ".escapeshellarg("$log.txt")." 2>/dev/null");
//run("sed -ri 's|(file: [.>cr].*)[ /]$mover/.*$|\\1 file: $title|' ".escapeshellarg("$log.txt")." 2>/dev/null");
}
run("grep -n ' cache_dirs: -' ".escapeshellarg("$log.txt")." 2>/dev/null|cut -d: -f1", $rows);
for ($i = 0; $i < count($rows); $i += 2) for ($row = $rows[$i]+1; $row < $rows[$i+1]; $row++) run("sed -ri '$row s|(cache_dirs: \S).*(\S)|\\1..\\2|' ".escapeshellarg("$log.txt")." 2>/dev/null");
}
// replace consecutive repeated lines in syslog
run("awk -i inplace '{if(s!=substr(\$0,17)){if(x>0)print\"### [PREVIOUS LINE REPEATED \"x\" TIMES] ###\\r\";print;x=0}else{x++}s=substr(\$0,17)}END{if(x>0)print\"### [PREVIOUS LINE REPEATED \"x\" TIMES] ###\\r\"}' ".escapeshellarg("$log.txt"));
// remove SHA256 hashes
run("sed -ri 's/(SHA256:).+[^\s\b]/SHA256:***REMOVED***/gm' $log.txt");
// truncate syslog if too big
if (basename($file)=='syslog' && filesize($file)>=$max) run("tail -n 200 ".escapeshellarg("$log.txt")." >".escapeshellarg("$log.last200.txt"));
run("truncate -s '<$max' ".escapeshellarg("$log.txt"));
anonymize_syslog($file);
}
foreach (glob("/boot/logs/syslog-previous*") as $file) {
anonymize_syslog($file);
}
// copy dhcplog
@@ -720,6 +729,8 @@ if (is_dir("/boot/config/plugins/lxc")) {
run("cat /boot/config/plugins/lxc/lxc.conf 2>/dev/null|todos >>".escapeshellarg("/$diag/lxc/lxc.conf"));
run("cat /boot/config/plugins/lxc/default.conf 2>/dev/null|todos >>".escapeshellarg("/$diag/lxc/default.conf"));
run("lxc-checkconfig 2>/dev/null|todos >>".escapeshellarg("/$diag/lxc/checkconfig.txt"));
// remove username and token
run("sed -i -e '/LXC_GITHUB_USER/c ***line removed***' -e '/LXC_GITHUB_TOKEN/c ***line removed***' ".escapeshellarg("/$diag/lxc/plugin.cfg"));
} else {
null;
}
@@ -6,7 +6,7 @@ while IFS='\n' read -r net; do
[[ -n $net4 ]] && nets+=("$net4 = $net;")
done <<< $(ip -br -4 addr|awk '/^(br|bond|eth|wg)[0-9]+(\.[0-9]+)?/ {print $3}'|uniq -d)
while IFS='\n' read -r net; do
while IFS=$'\n' read -r net; do
net=${net%/*}
net6=$(ip -br -6 addr show to $net 2>/dev/null|awk '$1 !~ "^shim" {print $1}'|tr '\n' ','|sed 's/,$//')
[[ -n $net6 ]] && nets+=("$net6 = $net;")
@@ -41,6 +41,32 @@ if (in_array($host,['keys.lime-technology.com','lime-technology.com'])) {
}
} else {
write("ERROR: $return_var\n");
switch($return_var) {
case 1:
write("Generic error code - Contact Support\n");
break;
case 2:
write("Parse Error - Contact Support\n");
break;
case 3:
write("File I/O error - Contact Support\n");
break;
case 4:
write("Network Failure: Try setting static DNS addresses within Settings - Network Settings or Contact Support\n");
break;
case 5:
write("SSL verification failure. Is the date & time set correctly? (Settings - Date & Time Settings) or Contact Support\n");
break;
case 6:
write("Username/password authentication failure - Contact Support\n");
break;
case 7:
write("Protocol error - Contact Support\n");
break;
case 8:
write("Server issued an error response - Contact Support\n");
break;
}
}
} else {
write("ERROR, bad or missing key file URL: $url\n");
+4 -4
View File
@@ -25,7 +25,7 @@ function update_wireguard($ifname) {
$vtun = basename($wg,'.conf');
// interface has changed?
if (exec("grep -Pom1 ' dev $nic ' $wg")=='') {
exec("logger -t netconfig 'updated wireguard $vtun configuration'");
exec("logger -t netconfig -- \"updated wireguard $vtun configuration\"");
exec("sed -ri 's/ dev (br0|bond0|eth0) / dev $nic /' $wg");
}
// restart active wireguard tunnels
@@ -81,7 +81,7 @@ if ($run) {
}
// create configuration file for all available interfaces
$i = 0; $new = []; $new[] = "# Generated settings:";
$i = 0; $new = ["# Generated settings:"];
foreach ($ini as $name => $port) {
$bonding = $port['BONDING']=='yes';
$bridging = $port['BRIDGING']=='yes';
@@ -126,8 +126,8 @@ file_put_contents($cfg,implode("\r\n",$new)."\r\n");
// start interface with updated (new) configuration
// don't execute when only interface description has changed
if ($run) {
exec("/etc/rc.d/rc.inet1 {$ifname}_start >/dev/null 2>&1");
exec("/usr/local/sbin/create_network_ini $ifname >/dev/null 2>&1 &");
exec("/etc/rc.d/rc.inet1 {$ifname}_start &>/dev/null");
exec("/usr/local/sbin/create_network_ini $ifname &>/dev/null &");
update_wireguard($ifname);
}
exit(0);
@@ -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
@@ -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 "delay = ${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
+5 -1
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
+10 -7
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