From 0d87850efd2617af7dc516a4fe419a6fb4c3aa4b Mon Sep 17 00:00:00 2001 From: ljm42 Date: Thu, 1 Feb 2024 20:31:25 -0700 Subject: [PATCH] remove dependency on webgui the plugin script should be at /usr/local/sbin/plugin, independent of the webgui --- .../dynamix.plugin.manager/scripts/plugin | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/emhttp/plugins/dynamix.plugin.manager/scripts/plugin b/emhttp/plugins/dynamix.plugin.manager/scripts/plugin index f49afb17d..316ecb268 100755 --- a/emhttp/plugins/dynamix.plugin.manager/scripts/plugin +++ b/emhttp/plugins/dynamix.plugin.manager/scripts/plugin @@ -6,9 +6,6 @@ // Program updates made by Bergware International (April 2020) // Program updates made by Bergware International (June 2022) -$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'); -require_once "$docroot/webGui/include/Wrappers.php"; - $usage = <<SHA256) { - my_logger('plugin-manager',"checking: $name - SHA256"); + logger("checking: $name - SHA256"); if (hash_file('sha256', $name) != $file->SHA256) { unlink($name); } } elseif ($file->MD5) { - my_logger('plugin-manager',"checking: $name - MD5"); + logger("checking: $name - MD5"); if (md5_file($name) != $file->MD5) { unlink($name); } @@ -393,12 +396,12 @@ function plugin($method, $plugin_file, &$error) { // If file already exists, do not overwrite // if (file_exists($name)) { - my_logger('plugin-manager',"skipping: $name already exists"); + logger("skipping: $name already exists"); } elseif ($file->LOCAL) { // Create the file // // for local file, just copy it - my_logger('plugin-manager',"creating: $name - copying LOCAL file $file->LOCAL"); + logger("creating: $name - copying LOCAL file $file->LOCAL"); if (!copy($file->LOCAL, $name)) { $error = "unable to copy LOCAL file: $name"; @unlink($name); @@ -406,10 +409,10 @@ function plugin($method, $plugin_file, &$error) { } } elseif ($file->INLINE) { // for inline file, create with inline contents - my_logger('plugin-manager',"creating: $name - from INLINE content"); + logger("creating: $name - from INLINE content"); $contents = trim($file->INLINE).PHP_EOL; if ($file->attributes()->Type == 'base64') { - my_logger('plugin-manager',"decoding: $name as base64"); + logger("decoding: $name as base64"); $contents = base64_decode($contents); if ($contents === false) { $error = "unable to decode inline base64: $name"; @@ -423,20 +426,20 @@ function plugin($method, $plugin_file, &$error) { } } elseif ($file->URL) { // for download file, download and maybe verify the file MD5 - my_logger('plugin-manager',"creating: $name - downloading from URL $file->URL"); + logger("creating: $name - downloading from URL $file->URL"); if ( (download($file->URL, $name, $error) === false) && (download(filter_url($file->URL), $name, $error) === false) ) { @unlink($name); return false; } if ($file->SHA256) { - my_logger('plugin-manager',"checking: $name - SHA256"); + logger("checking: $name - SHA256"); if (hash_file('sha256', $name) != $file->SHA256) { $error = "bad file SHA256: $name"; unlink($name); return false; } } elseif ($file->MD5) { - my_logger('plugin-manager',"checking: $name - MD5"); + logger("checking: $name - MD5"); if (md5_file($name) != $file->MD5) { $error = "bad file MD5: $name"; unlink($name); @@ -449,7 +452,7 @@ function plugin($method, $plugin_file, &$error) { if ($file->attributes()->Mode) { // if file has 'Mode' attribute, apply it $mode = $file->attributes()->Mode; - my_logger('plugin-manager',"setting: $name - mode to $mode"); + logger("setting: $name - mode to $mode"); if (!chmod($name, octdec($mode))) { $error = "chmod failure: $name"; return false; @@ -461,13 +464,13 @@ function plugin($method, $plugin_file, &$error) { if ($file->attributes()->Run) { $command = $file->attributes()->Run; if ($name) { - my_logger('plugin-manager',"running: $command $name"); + logger("running: $command $name"); $retval = run("$command $name"); } elseif ($file->LOCAL) { - my_logger('plugin-manager',"running: $command $file->LOCAL"); + logger("running: $command $file->LOCAL"); $retval = run("$command $file->LOCAL"); } elseif ($file->INLINE) { - my_logger('plugin-manager',"running: 'anonymous'"); + logger("running: 'anonymous'"); $name = '/tmp/inline.sh'; file_put_contents($name, $file->INLINE); $retval = run("$command $name"); @@ -715,10 +718,10 @@ if ($method == 'install') { if ($target != $plugin_file) copy($plugin_file, $target); symlink($target, $symlink); write("plugin: $plugin installed\n"); - my_logger('plugin-manager',"$plugin installed"); + logger("$plugin installed"); } else { write("script: $plugin executed\n"); - my_logger('plugin-manager',"script: $plugin executed"); + logger("script: $plugin executed"); } // run hook scripts for post processing post_hooks(); @@ -832,7 +835,7 @@ if ($method == 'update') { copy($plugin_file, $target); symlink($target, $symlink); write("plugin: $plugin updated\n"); - my_logger('plugin-manager',"$plugin updated"); + logger("$plugin updated"); // run hook scripts for post processing post_hooks(); done(0); @@ -864,7 +867,7 @@ if ($method == 'remove') { // remove the plugin file move($installed_plugin_file, "$boot-removed"); write("plugin: $plugin removed\n"); - my_logger('plugin-manager',"$plugin removed"); + logger("$plugin removed"); exec("/usr/local/sbin/update_cron"); // run hook scripts for post processing post_hooks();