From 3e1e33094cfbd6c819c5407b96c7051b2fe553a8 Mon Sep 17 00:00:00 2001 From: dlandon Date: Mon, 10 Jun 2024 03:48:28 -0500 Subject: [PATCH 1/7] Add zfs pool information and deal with html special characters. --- emhttp/plugins/dynamix/DeviceInfo.page | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/emhttp/plugins/dynamix/DeviceInfo.page b/emhttp/plugins/dynamix/DeviceInfo.page index 739bd8978..9ba2a92be 100755 --- a/emhttp/plugins/dynamix/DeviceInfo.page +++ b/emhttp/plugins/dynamix/DeviceInfo.page @@ -761,7 +761,7 @@ _(Critical disk utilization threshold)_ (%):
_(pool device stats)_: -: ".shell_exec("/sbin/btrfs dev stats -T /mnt/$tag").""?> +: " . htmlspecialchars(shell_exec("/sbin/btrfs dev stats -T /mnt/$tag"), ENT_QUOTES, 'UTF-8') . ""; ?> @@ -779,7 +779,7 @@ _(pool device stats)_: _(btrfs filesystem usage)_: -: ".shell_exec("/sbin/btrfs fi usage -T /mnt/$tag").""?> +: " . htmlspecialchars(shell_exec("/sbin/btrfs fi usage -T /mnt/$tag"), ENT_QUOTES, 'UTF-8') . ""; ?> _(btrfs balance status)_: : ".implode("\n", $balance_status).""?> @@ -934,6 +934,7 @@ _(btrfs scrub status)_: + _(Scrub schedule)_: : "._('Scrub')." "._('is only available when the filesyestem is mounted') : sprintf(_('See %s Settings'),ucfirst(prefix($tag)))?> +
_(Pool Information)_
+ + +_(zfs pool information)_: +:
+

+
_(Scrub Schedule)_
+ _(Scrub schedule)_: : > =2) echo mk_option(_var($disk,'fsProfile'),"raid0", _('raid0'))?> - =2) echo mk_option(_var($disk,'fsProfile'),"raid1", _('raid1'), btrfs_default())?> + =2) echo mk_option(_var($disk,'fsProfile'),"raid1", _('raid1'))?> =3) echo mk_option(_var($disk,'fsProfile'),"raid1c3", _('raid1c3'))?> =4) echo mk_option(_var($disk,'fsProfile'),"raid1c4", _('raid1c4'))?> =4) echo mk_option(_var($disk,'fsProfile'),"raid10", _('raid10'))?> @@ -661,8 +652,8 @@ _(File system type)_: @@ -770,7 +761,7 @@ _(Critical disk utilization threshold)_ (%): _(pool device stats)_: -: " . htmlspecialchars(shell_exec("/sbin/btrfs dev stats -T /mnt/$tag"), ENT_QUOTES, 'UTF-8') . ""; ?> +: " . htmlspecialchars(shell_exec("/sbin/btrfs dev stats -T ".escapeshellarg("/mnt/$tag")), ENT_QUOTES, 'UTF-8') . ""; ?> @@ -784,11 +775,11 @@ _(pool device stats)_:
_(Balance Status)_
- - + + _(btrfs filesystem usage)_: -: " . htmlspecialchars(shell_exec("/sbin/btrfs fi usage -T /mnt/$tag"), ENT_QUOTES, 'UTF-8') . ""; ?> +: " . htmlspecialchars(shell_exec("/sbin/btrfs fi usage -T ".escapeshellarg("/mnt/$tag")), ENT_QUOTES, 'UTF-8') . ""; ?> _(btrfs balance status)_: : ".implode("\n", $balance_status).""?> @@ -901,7 +892,7 @@ _(Block group usage)_ (%):
_(Scrub Status)_
- + _(btrfs scrub status)_: : ".implode("\n", $scrub_status).""?> @@ -1034,7 +1025,7 @@ _(btrfs check status)_:
_(Pool Status)_
- + _(zfs pool status)_: @@ -1068,7 +1059,7 @@ _(zfs pool status)_:
_(Pool Information)_
- + _(zfs pool information)_: :
From 1da8308b81dfd55536dd6641a02d67c2064438db Mon Sep 17 00:00:00 2001 From: dlandon Date: Mon, 10 Jun 2024 12:47:32 -0500 Subject: [PATCH 5/7] Revert "Update DeviceInfo.page" This reverts commit 243b838d8043f4f6acebf4be5b9a0772042916a5. --- emhttp/plugins/dynamix/DeviceInfo.page | 29 +++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/emhttp/plugins/dynamix/DeviceInfo.page b/emhttp/plugins/dynamix/DeviceInfo.page index d2433d805..b8479d378 100755 --- a/emhttp/plugins/dynamix/DeviceInfo.page +++ b/emhttp/plugins/dynamix/DeviceInfo.page @@ -48,6 +48,15 @@ $text = isPool($name) ? _('This will ERASE content of ALL devices in the pool') function disabled_if($condition) { if ($condition !== false) echo ' disabled'; } +function btrfs_default() { + global $disk; + return (_var($disk,'fsProfile')=="") ? "selected" : ""; +} +function zfs_default($case) { + global $disk; + return (($case==1)&&(_var($disk,'slots',0) <= 2) || + ($case==2)&&(_var($disk,'slots',0) >= 3)) ? "selected" : ""; +} function sanitize(&$val) { $data = explode('.',str_replace([' ',','],['','.'],$val)); $last = array_pop($data); @@ -642,7 +651,7 @@ _(File system type)_: > =2) echo mk_option(_var($disk,'fsProfile'),"", _('stripe'))?> - - =3) echo mk_option(_var($disk,'fsProfile'),"raidz1", _('raidz'))?> + + =3) echo mk_option(_var($disk,'fsProfile'),"raidz1", _('raidz'), zfs_default(2))?> =3) echo mk_option(_var($disk,'fsProfile'),"raidz2", _('raidz2'))?> =4) echo mk_option(_var($disk,'fsProfile'),"raidz3", _('raidz3'))?> @@ -761,7 +770,7 @@ _(Critical disk utilization threshold)_ (%): _(pool device stats)_: -: " . htmlspecialchars(shell_exec("/sbin/btrfs dev stats -T ".escapeshellarg("/mnt/$tag")), ENT_QUOTES, 'UTF-8') . ""; ?> +: " . htmlspecialchars(shell_exec("/sbin/btrfs dev stats -T /mnt/$tag"), ENT_QUOTES, 'UTF-8') . ""; ?> @@ -775,11 +784,11 @@ _(pool device stats)_:
_(Balance Status)_
- - + + _(btrfs filesystem usage)_: -: " . htmlspecialchars(shell_exec("/sbin/btrfs fi usage -T ".escapeshellarg("/mnt/$tag")), ENT_QUOTES, 'UTF-8') . ""; ?> +: " . htmlspecialchars(shell_exec("/sbin/btrfs fi usage -T /mnt/$tag"), ENT_QUOTES, 'UTF-8') . ""; ?> _(btrfs balance status)_: : ".implode("\n", $balance_status).""?> @@ -892,7 +901,7 @@ _(Block group usage)_ (%):
_(Scrub Status)_
- + _(btrfs scrub status)_: : ".implode("\n", $scrub_status).""?> @@ -1025,7 +1034,7 @@ _(btrfs check status)_:
_(Pool Status)_
- + _(zfs pool status)_: @@ -1059,7 +1068,7 @@ _(zfs pool status)_:
_(Pool Information)_
- + _(zfs pool information)_: :
From 6d2de179a0e1f87c9ebdde45bccebc9d0ba31e00 Mon Sep 17 00:00:00 2001 From: dlandon Date: Mon, 10 Jun 2024 12:59:57 -0500 Subject: [PATCH 6/7] Update DeviceInfo.page --- emhttp/plugins/dynamix/DeviceInfo.page | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/emhttp/plugins/dynamix/DeviceInfo.page b/emhttp/plugins/dynamix/DeviceInfo.page index b8479d378..b2d7b39fe 100755 --- a/emhttp/plugins/dynamix/DeviceInfo.page +++ b/emhttp/plugins/dynamix/DeviceInfo.page @@ -770,7 +770,7 @@ _(Critical disk utilization threshold)_ (%): _(pool device stats)_: -: " . htmlspecialchars(shell_exec("/sbin/btrfs dev stats -T /mnt/$tag"), ENT_QUOTES, 'UTF-8') . ""; ?> +: " . htmlspecialchars(shell_exec("/sbin/btrfs dev stats -T ".escapeshellarg("/mnt/$tag")), ENT_QUOTES, 'UTF-8') . ""; ?> @@ -784,11 +784,11 @@ _(pool device stats)_:
_(Balance Status)_
- - + + _(btrfs filesystem usage)_: -: " . htmlspecialchars(shell_exec("/sbin/btrfs fi usage -T /mnt/$tag"), ENT_QUOTES, 'UTF-8') . ""; ?> +: " . htmlspecialchars(shell_exec("/sbin/btrfs fi usage -T ".escapeshellarg("/mnt/$tag")), ENT_QUOTES, 'UTF-8') . ""; ?> _(btrfs balance status)_: : ".implode("\n", $balance_status).""?> @@ -901,7 +901,7 @@ _(Block group usage)_ (%):
_(Scrub Status)_
- + _(btrfs scrub status)_: : ".implode("\n", $scrub_status).""?> @@ -1034,7 +1034,7 @@ _(btrfs check status)_:
_(Pool Status)_
- + _(zfs pool status)_: @@ -1068,7 +1068,7 @@ _(zfs pool status)_:
_(Pool Information)_
- + _(zfs pool information)_: :
From c4eff321f28ff5abd0125a78811986b98817abac Mon Sep 17 00:00:00 2001 From: dlandon Date: Mon, 10 Jun 2024 13:21:00 -0500 Subject: [PATCH 7/7] Use atomic file write. --- emhttp/plugins/dynamix/include/UpdateOne.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/emhttp/plugins/dynamix/include/UpdateOne.php b/emhttp/plugins/dynamix/include/UpdateOne.php index 16bff2a60..8a5d2b576 100644 --- a/emhttp/plugins/dynamix/include/UpdateOne.php +++ b/emhttp/plugins/dynamix/include/UpdateOne.php @@ -51,7 +51,7 @@ switch ($data['id']) { if ($cpus != $cpuset || strlen($cpus) != strlen($cpuset)) { $changes[] = $name; /* used by UpdateTwo.php to read new assignments */ - file_put_contents("/var/tmp/$name.tmp", $cpuset); + file_put_contents_atomic("/var/tmp/$name.tmp", $cpuset); } } $reply = ['success' => (count($changes) ? implode(';', $changes) : '')]; @@ -78,7 +78,7 @@ switch ($data['id']) { if ($ct['CPUset'] != $cpuset || strlen($ct['CPUset']) != strlen($cpuset)) { $changes[] = $name; /* used by UpdateTwo.php to read new assignments */ - file_put_contents($file, $xml->saveXML()); + file_put_contents_atomic($file, $xml->saveXML()); exec("sed -ri 's/^(<(\\/Container)/>\\n <\\1/' \"$file\""); /* aftercare */ } } @@ -87,7 +87,7 @@ switch ($data['id']) { case 'is': /* report changed isolcpus in temporary file */ foreach ($map as $name => $isolcpu) { - file_put_contents("/var/tmp/$name.tmp", $isolcpu); + file_put_contents_atomic("/var/tmp/$name.tmp", $isolcpu); $changes[] = $name; } $reply = ['success' => (count($changes) ? implode(';', $changes) : '')];