From 6d6862fd0f23a5b9e0eafe6f260d80bc09fa3f53 Mon Sep 17 00:00:00 2001 From: ljm42 Date: Thu, 24 Jul 2025 13:42:10 -0700 Subject: [PATCH] refactor: use shared nchan publish function --- .../dynamix.docker.manager/scripts/container_size | 12 ++---------- .../scripts/update_container | 12 ++---------- .../dynamix.plugin.manager/scripts/checkall | 12 ++---------- .../dynamix.plugin.manager/scripts/language | 12 ++---------- .../dynamix.plugin.manager/scripts/multiplugin | 14 ++++---------- .../plugins/dynamix.plugin.manager/scripts/plugin | 12 ++---------- .../dynamix.vm.manager/scripts/VMAjaxCall.php | 12 ++---------- .../plugins/dynamix.vm.manager/scripts/VMClone.php | 12 ++---------- emhttp/plugins/dynamix/scripts/install_key | 14 ++++---------- emhttp/plugins/dynamix/scripts/newperms | 14 ++++---------- emhttp/plugins/dynamix/scripts/ssd_trim | 12 ++---------- 11 files changed, 28 insertions(+), 110 deletions(-) diff --git a/emhttp/plugins/dynamix.docker.manager/scripts/container_size b/emhttp/plugins/dynamix.docker.manager/scripts/container_size index cbc8b0a39..7ebca74db 100755 --- a/emhttp/plugins/dynamix.docker.manager/scripts/container_size +++ b/emhttp/plugins/dynamix.docker.manager/scripts/container_size @@ -14,6 +14,7 @@ 'http://localhost/pub/plugins?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('plugins', $message); } - curl_close($com); } function autoscale($value) { global $units; diff --git a/emhttp/plugins/dynamix.docker.manager/scripts/update_container b/emhttp/plugins/dynamix.docker.manager/scripts/update_container index b82feaf5a..60b7fd754 100755 --- a/emhttp/plugins/dynamix.docker.manager/scripts/update_container +++ b/emhttp/plugins/dynamix.docker.manager/scripts/update_container @@ -20,6 +20,7 @@ extract(parse_plugin_cfg('dynamix',true)); $_SERVER['REQUEST_URI'] = ''; $login_locale = _var($display,'locale'); require_once "$docroot/plugins/dynamix.docker.manager/include/DockerClient.php"; +require_once "$docroot/webGui/include/publish.php"; $var = parse_ini_file('/var/local/emhttp/var.ini'); $DockerClient = new DockerClient(); @@ -31,18 +32,9 @@ $subnet = DockerUtil::network($custom); $cpus = DockerUtil::cpus(); function write(...$messages){ - $com = curl_init(); - curl_setopt_array($com,[ - CURLOPT_URL => 'http://localhost/pub/docker?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('docker', $message); } - curl_close($com); } function stopContainer_nchan($name) { global $DockerClient; diff --git a/emhttp/plugins/dynamix.plugin.manager/scripts/checkall b/emhttp/plugins/dynamix.plugin.manager/scripts/checkall index e4e7e2096..3033b8805 100755 --- a/emhttp/plugins/dynamix.plugin.manager/scripts/checkall +++ b/emhttp/plugins/dynamix.plugin.manager/scripts/checkall @@ -20,24 +20,16 @@ extract(parse_plugin_cfg('dynamix',true)); $_SERVER['REQUEST_URI'] = 'plugins'; $login_locale = _var($display,'locale'); require_once "$docroot/webGui/include/Translations.php"; +require_once "$docroot/webGui/include/publish.php"; $nchan = $argv[$argc-1] == 'nchan'; // console or nchan output function write(...$messages){ global $nchan; if ($nchan) { - $com = curl_init(); - curl_setopt_array($com,[ - CURLOPT_URL => 'http://localhost/pub/plugins?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('plugins', $message); } - curl_close($com); } else { foreach ($messages as $message) echo $message; } diff --git a/emhttp/plugins/dynamix.plugin.manager/scripts/language b/emhttp/plugins/dynamix.plugin.manager/scripts/language index 91f1f8400..b66db21c5 100755 --- a/emhttp/plugins/dynamix.plugin.manager/scripts/language +++ b/emhttp/plugins/dynamix.plugin.manager/scripts/language @@ -8,6 +8,7 @@ $docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'); require_once "$docroot/webGui/include/Wrappers.php"; +require_once "$docroot/webGui/include/publish.php"; $logger = 'language-manager'; $usage = << 'http://localhost/pub/plugins?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('plugins', $message); } - curl_close($com); } else { foreach ($messages as $message) echo $message; } diff --git a/emhttp/plugins/dynamix.plugin.manager/scripts/multiplugin b/emhttp/plugins/dynamix.plugin.manager/scripts/multiplugin index 0cab2e0c3..cff209de0 100755 --- a/emhttp/plugins/dynamix.plugin.manager/scripts/multiplugin +++ b/emhttp/plugins/dynamix.plugin.manager/scripts/multiplugin @@ -12,6 +12,9 @@ */ ?> 'plugin', 'xml' => 'language', '' => 'language']; function write(...$messages){ global $nchan; if ($nchan) { - $com = curl_init(); - curl_setopt_array($com,[ - CURLOPT_URL => 'http://localhost/pub/plugins?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('plugins', $message); } - curl_close($com); } else { foreach ($messages as $message) echo $message; } diff --git a/emhttp/plugins/dynamix.plugin.manager/scripts/plugin b/emhttp/plugins/dynamix.plugin.manager/scripts/plugin index 947518003..52acc095b 100755 --- a/emhttp/plugins/dynamix.plugin.manager/scripts/plugin +++ b/emhttp/plugins/dynamix.plugin.manager/scripts/plugin @@ -8,6 +8,7 @@ $docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'); require_once "$docroot/webGui/include/Wrappers.php"; +require_once "$docroot/webGui/include/publish.php"; $logger = 'plugin-manager'; $usage = << 'http://localhost/pub/plugins?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('plugins', $message); } - curl_close($com); } else { foreach ($messages as $message) echo $message; } diff --git a/emhttp/plugins/dynamix.vm.manager/scripts/VMAjaxCall.php b/emhttp/plugins/dynamix.vm.manager/scripts/VMAjaxCall.php index 61596283f..495e2883d 100755 --- a/emhttp/plugins/dynamix.vm.manager/scripts/VMAjaxCall.php +++ b/emhttp/plugins/dynamix.vm.manager/scripts/VMAjaxCall.php @@ -21,20 +21,12 @@ require_once "$docroot/plugins/dynamix.docker.manager/include/DockerClient.php"; $_SERVER['REQUEST_URI'] = ''; $login_locale = _var($display,'locale'); require_once "$docroot/webGui/include/Translations.php"; +require_once "$docroot/webGui/include/publish.php"; function write(...$messages) { - $com = curl_init(); - curl_setopt_array($com,[ - CURLOPT_URL => 'http://localhost/pub/vmaction?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('vmaction', $message); } - curl_close($com); } function execCommand_nchan($command,$idx) { diff --git a/emhttp/plugins/dynamix.vm.manager/scripts/VMClone.php b/emhttp/plugins/dynamix.vm.manager/scripts/VMClone.php index f198b6c34..e5c03ab50 100755 --- a/emhttp/plugins/dynamix.vm.manager/scripts/VMClone.php +++ b/emhttp/plugins/dynamix.vm.manager/scripts/VMClone.php @@ -21,20 +21,12 @@ require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt_helpers.php"; $_SERVER['REQUEST_URI'] = ''; $login_locale = _var($display,'locale'); require_once "$docroot/webGui/include/Translations.php"; +require_once "$docroot/webGui/include/publish.php"; function write(...$messages) { - $com = curl_init(); - curl_setopt_array($com,[ - CURLOPT_URL => 'http://localhost/pub/vmaction?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('vmaction', $message); } - curl_close($com); } function execCommand_nchan_clone($command,$idx,$refcmd=false) { diff --git a/emhttp/plugins/dynamix/scripts/install_key b/emhttp/plugins/dynamix/scripts/install_key index 2831f839e..b8fbd2851 100755 --- a/emhttp/plugins/dynamix/scripts/install_key +++ b/emhttp/plugins/dynamix/scripts/install_key @@ -11,19 +11,13 @@ */ ?> 'http://localhost/pub/plugins?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('plugins', $message); } - curl_close($com); } $url = rawurldecode($argv[1]??''); diff --git a/emhttp/plugins/dynamix/scripts/newperms b/emhttp/plugins/dynamix/scripts/newperms index 34188a375..dcae2cf3b 100755 --- a/emhttp/plugins/dynamix/scripts/newperms +++ b/emhttp/plugins/dynamix/scripts/newperms @@ -17,24 +17,18 @@ # u-x Clear the 'x' bit in the user permissions (leaves rw as-is) # go+u Copy the user permissions to group and other +$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'); $nchan = $argv[$argc-1] == 'nchan'; // console or nchan output if ($nchan) unset($argv[$argc-1]); // remove nchan parameter +require_once "$docroot/webGui/include/publish.php"; + function write(...$messages){ global $nchan; if ($nchan) { - $com = curl_init(); - curl_setopt_array($com,[ - CURLOPT_URL => 'http://localhost/pub/plugins?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('plugins', $message); } - curl_close($com); } else { foreach ($messages as $message) echo $message; } diff --git a/emhttp/plugins/dynamix/scripts/ssd_trim b/emhttp/plugins/dynamix/scripts/ssd_trim index acd0e1da7..6af110af2 100755 --- a/emhttp/plugins/dynamix/scripts/ssd_trim +++ b/emhttp/plugins/dynamix/scripts/ssd_trim @@ -29,20 +29,12 @@ if ($argc==2 && $argv[1]=='cron') { $_SERVER['REQUEST_URI'] = 'settings'; $login_locale = _var($display,'locale'); require_once "$docroot/webGui/include/Translations.php"; +require_once "$docroot/webGui/include/publish.php"; function write(...$messages){ - $com = curl_init(); - curl_setopt_array($com,[ - CURLOPT_URL => 'http://localhost/pub/plugins?buffer_length=1', - CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket', - CURLOPT_POST => 1, - CURLOPT_RETURNTRANSFER => true - ]); foreach ($messages as $message) { - curl_setopt($com, CURLOPT_POSTFIELDS, $message); - curl_exec($com); + publish('plugins', $message); } - curl_close($com); } /* Check if the disk is an HDD based on rotational flag */