From 202f6fec50d28bca9af0de7412c2e91b818d20fb Mon Sep 17 00:00:00 2001 From: bergware Date: Sun, 4 Feb 2024 12:02:02 +0100 Subject: [PATCH] scripts: code simplification --- emhttp/plugins/dynamix/scripts/parity_history | 13 ++-- emhttp/plugins/dynamix/scripts/select_case | 65 +++++++++-------- .../dynamix/scripts/system_information | 49 ++++++------- emhttp/plugins/dynamix/scripts/wg_config | 69 +++++++++---------- 4 files changed, 98 insertions(+), 98 deletions(-) diff --git a/emhttp/plugins/dynamix/scripts/parity_history b/emhttp/plugins/dynamix/scripts/parity_history index 2a812f4b1..7feb86d8e 100755 --- a/emhttp/plugins/dynamix/scripts/parity_history +++ b/emhttp/plugins/dynamix/scripts/parity_history @@ -22,6 +22,8 @@ $login_locale = _var($display,'locale'); require_once "$docroot/webGui/include/Translations.php"; $month = [' Jan '=>'-01-',' Feb '=>'-02-',' Mar '=>'-03-',' Apr '=>'-04-',' May '=>'-05-',' Jun '=>'-06-',' Jul '=>'-07-',' Aug '=>'-08-',' Sep '=>'-09-',' Oct '=>'-10-',' Nov '=>'-11-',' Dec '=>'-12-']; +$log = "/boot/config/parity-checks.log"; +$list = []; function this_plus($val, $word, $last) { return $val>0 ? (($val||$last)?($val.' '.$word.($last?'':', ')):'') : ''; @@ -35,10 +37,10 @@ function this_duration($time) { $secs = $hmss%60; return this_plus($days,_('day'),($hour|$mins|$secs)==0).this_plus($hour,_('hr'),($mins|$secs)==0).this_plus($mins,_('min'),$secs==0).this_plus($secs,_('sec'),true); } -$log = "/boot/config/parity-checks.log"; -$head = ""; -$list = []; - +?> +
"._('Action').""._('Date').""._('Size').""._('Duration').""._('Speed').""._('Status').""._('Errors')."
+ +"; } -echo $head,implode($list),"
"._('No parity check history present')."!
"; +echo implode($list); ?> + diff --git a/emhttp/plugins/dynamix/scripts/select_case b/emhttp/plugins/dynamix/scripts/select_case index ce4cfbf8f..51dcad32c 100755 --- a/emhttp/plugins/dynamix/scripts/select_case +++ b/emhttp/plugins/dynamix/scripts/select_case @@ -24,34 +24,35 @@ require_once "$docroot/webGui/include/Translations.php"; $boot = "/boot/config/plugins/dynamix"; $file = $argv[1]; $cmodel = is_file("$boot/$file") ? file_get_contents("$boot/$file") : ''; +?> + -$style = [""; + -$script = [""; - -$html = ["
"]; +
+
$title
"; + echo "
$title
\n"; } $select = $cmodel=='case-model.png' ? 'color:#e68a00' : ''; -$html[] = "
"._('custom image')."
"; -$html[] = "
"; -$html[] = ""; -$html[] = ""; - -echo implode($style),implode($script),implode($html); ?> +
+ + + diff --git a/emhttp/plugins/dynamix/scripts/system_information b/emhttp/plugins/dynamix/scripts/system_information index 36ee74fc8..f3fc8e5cc 100755 --- a/emhttp/plugins/dynamix/scripts/system_information +++ b/emhttp/plugins/dynamix/scripts/system_information @@ -136,23 +136,28 @@ if ($memory_installed >= 1024) { // If maximum < installed then roundup maximum to the next power of 2 size of installed. E.g. 6 -> 8 or 12 -> 16 $low = $memory_maximum < $memory_installed; if ($low) $memory_maximum = pow(2,ceil(log($memory_installed)/log(2))); +?> + -$style = ""; - -$list = []; -$list[] = ""; -$list[] = ""; -$list[] = ""; -$list[] = ""; -$list[] = ""; -$list[] = ""; -$list[] = ""; -$list[] = ""; - +
"._('Model').":$model
".('M/B').":{$board['Manufacturer']} {$board['Product Name']} {$board['Version']} {$board['Serial Number']}
"._('BIOS').":{$bios['Vendor']} {$bios['Version']} {$bios['Release Date']}
"._('CPU').":$cpumodel {$cpu['Current Speed']}
"._('HVM').":$hvm
"._('IOMMU').":$iommu
"._('Cache').":".implode(', ',$cache_installed)."
$memory$memory_installed $unit $memory_type $ecc("._('max. installable capacity')." $memory_maximum $unit".($low?'*':'').")
+ + + + + + + + +"; + echo ""; } exec("ls --indicator-style=none /sys/class/net|grep -Po '^(bond|eth)\d+$'",$sPorts); @@ -167,24 +172,22 @@ foreach ($sPorts as $port) { if (substr($port,0,4)=='bond') { if ($link) { $bond_mode = str_replace('Bonding Mode: ','',file("/proc/net/bonding/$port",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)[1]); - $list[] = ""; + echo ""; } else { - $list[] = ""; + echo ""; } } else { if ($link) { $speed = file_get_contents("$int/speed"); $duplex = file_get_contents("$int/duplex"); - $list[] = ""; + echo ""; } else { - $list[] = ""; + echo ""; } } } - -$list[] = ""; -$list[] = ""; -$list[] = "
:
:
:
:
:
:
:
)
".$device['Locator'].": "._var($device,'Manufacturer')." "._var($device,'Part Number').", $size "._var($device,'Type')." @ "._var($device,'Configured Memory Speed')."
",$device['Locator'],": ",_var($device,'Manufacturer')," ",_var($device,'Part Number'),", $size ",_var($device,'Type')," @ ",_var($device,'Configured Memory Speed'),"
$name$port: $bond_mode, mtu $mtu
$name$port: $bond_mode, mtu $mtu
$name$port: "._("bond down")."
$name$port: ",_('bond down'),"
$name$port: $speed Mbps, $duplex duplex, mtu $mtu
$name$port: $speed Mbps, $duplex duplex, mtu $mtu
$name$port: "._("interface down")."
$name$port: ",_('interface down'),"
"._('Kernel').":$kernel
"._('OpenSSL').":$openssl
"._('Uptime').":
"; - -echo $style,implode($list); ?> +: +: +: + diff --git a/emhttp/plugins/dynamix/scripts/wg_config b/emhttp/plugins/dynamix/scripts/wg_config index 10c0490c5..f0249e059 100755 --- a/emhttp/plugins/dynamix/scripts/wg_config +++ b/emhttp/plugins/dynamix/scripts/wg_config @@ -24,47 +24,42 @@ require_once "$docroot/webGui/include/Translations.php"; $file = $argv[1]; $path = realpath('/etc/wireguard'.($argv[2]??'')); $root = '/boot/config/wireguard'; +?> + -$style = [""; + -$script = [""; - -$html = []; -$html[] = "

".($argv[2] ? _('Remote peer configuration') : _('Local server configuration'))."

"; -$html[] = "
"; -$html[] = "
";
-$html[] = @file_get_contents("$path/$file.conf");
-$html[] = "\n";
-$html[] = "
"; +

+
','.zip')">
+
+"; + echo ""; } - -echo implode($style),implode($script),implode($html); ?>