From 68cf94f04ffc6c6398d155e10e3541a62de804ba Mon Sep 17 00:00:00 2001 From: dlandon Date: Tue, 25 Jul 2023 15:08:09 -0500 Subject: [PATCH 1/2] Add ntp.conf, sshd.config, and servers.conf; apply maskIP to testparm; fix php warning. --- emhttp/plugins/dynamix/scripts/diagnostics | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/emhttp/plugins/dynamix/scripts/diagnostics b/emhttp/plugins/dynamix/scripts/diagnostics index c1c7b5945..0c7047499 100755 --- a/emhttp/plugins/dynamix/scripts/diagnostics +++ b/emhttp/plugins/dynamix/scripts/diagnostics @@ -100,7 +100,7 @@ function anonymize($text, $select) { function maskIP($file) { // anonymize public IPv4 addresses $rfc1918 = "(127|10|172\.1[6-9]|172\.2[0-9]|172\.3[0-1]|192\.168)((\.[0-9]{1,3}){2,3}([/\" .]|$))"; - run("sed -ri 's/([\"\[ ])${rfc1918}/\\1@@@\\2\\3/g; s/([\"\[ ][0-9]{1,3}\.)([0-9]{1,3}\.){2}([0-9]{1,3})([/\" .]|$)/\\1XXX.XXX.\\3\\4/g; s/@@@//g' ".escapeshellarg($file)." 2>/dev/null"); + run("sed -ri 's/([\"\[ ]){$rfc1918}/\\1@@@\\2\\3/g; s/([\"\[ ][0-9]{1,3}\.)([0-9]{1,3}\.){2}([0-9]{1,3})([/\" .]|$)/\\1XXX.XXX.\\3\\4/g; s/@@@//g' ".escapeshellarg($file)." 2>/dev/null"); // anonymize full IPv6 addresses run("sed -ri 's/([\"\[ ]([0-9a-f]{1,4}:){4})(([0-9a-f]{1,4}:){3}|:)([0-9a-f]{1,4})([/\" .]|$)/\\1XXXX:XXXX:XXXX:\\5\\6/g' ".escapeshellarg($file)." 2>/dev/null"); } @@ -672,6 +672,19 @@ $testparm = run("testparm -s 2>/dev/null"); if (!$all) $testparm = preg_replace("/(?<=\[.)(.*)(?=.\])|(?<=(write list = .)|(comment = .)|(valid users = .)|(path = \/mnt\/addons\/.)|(path = \/mnt\/remotes\/.)|(path = \/mnt\/disks\/.)|(path = \/mnt\/user\/.)).*(?=.)/","...",$testparm); file_put_contents("/$diag/system/testparm.txt",str_replace("\n","\r\n",$testparm)); +maskIP("/$diag/system/testparm.txt"); + +// copy ntp.conf +copy("/etc/ntp.conf", "/$diag/system/ntp.txt"); +maskIP("/$diag/system/ntp.txt"); + +// copy sshd_config +copy("/etc/ssh/sshd_config", "/$diag/system/sshd.txt"); +maskIP("/$diag/system/sshd.txt"); + +// copy servers.conf +copy("/etc/nginx/conf.d/servers.conf", "/$diag/system/servers.conf.txt"); +maskIP("/$diag/system/servers.conf.txt"); // BEGIN - third party plugins diagnostics // list third party packages in /boot/config/plugins/*/packages/ From 9ec5e7974c69746749b70f3608468396413b0a44 Mon Sep 17 00:00:00 2001 From: dlandon Date: Tue, 25 Jul 2023 21:05:34 -0500 Subject: [PATCH 2/2] Insure all files have newline changed to cr, lf; don't do maskIP if 'all' option is specified; fix linefeed routine not working; change update date to mtime.. --- emhttp/plugins/dynamix/scripts/diagnostics | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/emhttp/plugins/dynamix/scripts/diagnostics b/emhttp/plugins/dynamix/scripts/diagnostics index 0c7047499..988f0bcae 100755 --- a/emhttp/plugins/dynamix/scripts/diagnostics +++ b/emhttp/plugins/dynamix/scripts/diagnostics @@ -58,9 +58,14 @@ function run($cmd, &$save=null) { exec("timeout -s9 30 $cmd", $save); return implode("\n",$save); } + function newline($file) { - exec("echo|todos >>".escapeshellarg($file)); + $tmp_file = "/tmp/".basename($file); + copy($file, $tmp_file); + exec("/usr/bin/todos < ".escapeshellarg($tmp_file)." > ".escapeshellarg($file)); + unlink($tmp_file); } + function shareDisks($share) { return str_replace(',',', ',exec("shopt -s dotglob; getfattr --no-dereference --absolute-names --only-values -n system.LOCATIONS ".escapeshellarg("/mnt/user/$share")." 2>/dev/null") ?: ""); } @@ -97,13 +102,19 @@ function anonymize($text, $select) { return dirname($text)."/$name.cfg"; } } + function maskIP($file) { + global $all; + + if ($all) return; + // anonymize public IPv4 addresses $rfc1918 = "(127|10|172\.1[6-9]|172\.2[0-9]|172\.3[0-1]|192\.168)((\.[0-9]{1,3}){2,3}([/\" .]|$))"; run("sed -ri 's/([\"\[ ]){$rfc1918}/\\1@@@\\2\\3/g; s/([\"\[ ][0-9]{1,3}\.)([0-9]{1,3}\.){2}([0-9]{1,3})([/\" .]|$)/\\1XXX.XXX.\\3\\4/g; s/@@@//g' ".escapeshellarg($file)." 2>/dev/null"); // anonymize full IPv6 addresses run("sed -ri 's/([\"\[ ]([0-9a-f]{1,4}:){4})(([0-9a-f]{1,4}:){3}|:)([0-9a-f]{1,4})([/\" .]|$)/\\1XXXX:XXXX:XXXX:\\5\\6/g' ".escapeshellarg($file)." 2>/dev/null"); } + function prefix($key) { return preg_replace('/\d+$/','',$key); } @@ -355,7 +366,8 @@ if (file_exists($changes)) { $previous_version = "Previous Version: ".$version; file_put_contents("/$diag/unraid-".$unraid['version'].".txt", "\r\n".$previous_version."\r\n", FILE_APPEND); - $upgraded = "Upgraded on: ".date("F d Y", filemtime($changes)); + $file_stat = stat("/$diag/unraid-".$unraid['version'].".txt"); + $upgraded = "Upgraded on: ".date("F d Y", $file_stat[9]); file_put_contents("/$diag/unraid-".$unraid['version'].".txt", $upgraded."\r\n", FILE_APPEND); } else { file_put_contents("/$diag/unraid-".$unraid['version'].".txt", "\r\nNo Previous Version Found\r\n", FILE_APPEND); @@ -677,14 +689,17 @@ maskIP("/$diag/system/testparm.txt"); // copy ntp.conf copy("/etc/ntp.conf", "/$diag/system/ntp.txt"); maskIP("/$diag/system/ntp.txt"); +newline("/$diag/system/ntp.txt"); // copy sshd_config copy("/etc/ssh/sshd_config", "/$diag/system/sshd.txt"); maskIP("/$diag/system/sshd.txt"); +newline("/$diag/system/sshd.txt"); // copy servers.conf copy("/etc/nginx/conf.d/servers.conf", "/$diag/system/servers.conf.txt"); maskIP("/$diag/system/servers.conf.txt"); +newline("/$diag/system/servers.conf.txt"); // BEGIN - third party plugins diagnostics // list third party packages in /boot/config/plugins/*/packages/