Merge pull request #2310 from unraid/refactor-nchan-publish

refactor: use shared nchan publish function
This commit is contained in:
tom mortensen
2025-07-27 13:40:01 -07:00
committed by GitHub
11 changed files with 28 additions and 110 deletions

View File

@@ -14,6 +14,7 @@
<?
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
require_once "$docroot/webGui/include/Wrappers.php";
require_once "$docroot/webGui/include/publish.php";
extract(parse_plugin_cfg('dynamix',true));
// add translations
@@ -25,18 +26,9 @@ $units = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
$list = [];
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);
}
function autoscale($value) {
global $units;

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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 = <<<EOF
@@ -69,18 +70,9 @@ function done($code) {
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;
}

View File

@@ -12,6 +12,9 @@
*/
?>
<?
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
require_once "$docroot/webGui/include/publish.php";
$method = $argv[1]??'';
$plugins = explode('*',$argv[2]??'');
$nchan = $argv[$argc-1] == 'nchan'; // console or nchan output
@@ -20,18 +23,9 @@ $call = ['plg' => '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;
}

View File

@@ -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 = <<<EOF
@@ -180,18 +181,9 @@ function done($code) {
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;
}

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -11,19 +11,13 @@
*/
?>
<?
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
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);
}
$url = rawurldecode($argv[1]??'');

View File

@@ -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;
}

View File

@@ -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 */