From 30a7f6eb90f81177257cc2ad0f227bf6b29a1ac4 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Fri, 9 May 2025 08:25:38 -0400 Subject: [PATCH 1/5] feat: add tweaks for the Unraid API - enables API support for 7.2 - do not merge before the API is integrated, will break notifications - includes authentication fix for now --- emhttp/auth-request.php | 41 +++++- emhttp/plugins/dynamix/LogViewer.page | 8 + .../dynamix/include/DefaultPageLayout.php | 138 +++++++++--------- .../DefaultPageLayout/BodyInlineJS.php | 27 +--- .../DefaultPageLayout/GUIModeSessionFix.php | 26 ++++ .../include/DefaultPageLayout/Header.php | 4 - .../include/DefaultPageLayout/ToastSetup.php | 1 + 7 files changed, 145 insertions(+), 100 deletions(-) create mode 100644 emhttp/plugins/dynamix/LogViewer.page create mode 100644 emhttp/plugins/dynamix/include/DefaultPageLayout/GUIModeSessionFix.php create mode 100644 emhttp/plugins/dynamix/include/DefaultPageLayout/ToastSetup.php diff --git a/emhttp/auth-request.php b/emhttp/auth-request.php index 59f663118..e32448694 100644 --- a/emhttp/auth-request.php +++ b/emhttp/auth-request.php @@ -14,6 +14,32 @@ if (isset($_COOKIE[session_name()])) { session_write_close(); } +// Function to recursively find JS files in a directory +function findJsFiles($directory) { + if (!is_dir($directory)) { + return []; + } + + $jsFiles = []; + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS) + ); + + foreach ($iterator as $file) { + if ($file->isFile() && $file->getExtension() === 'js') { + $path = $file->getPathname(); + $baseDir = '/usr/local/emhttp'; + if (strpos($path, $baseDir) === 0) { + $path = substr($path, strlen($baseDir)); + } + $jsFiles[] = $path; + } + } + + return $jsFiles; +} + +// Base whitelist of files $arrWhitelist = [ '/webGui/styles/clear-sans-bold-italic.eot', '/webGui/styles/clear-sans-bold-italic.woff', @@ -39,8 +65,21 @@ $arrWhitelist = [ '/webGui/images/case-model.png', '/webGui/images/green-on.png', '/webGui/images/red-on.png', - '/webGui/images/yellow-on.png' + '/webGui/images/yellow-on.png', + '/webGui/images/UN-logotype-gradient.svg' ]; + +// Add JS files from the unraid-components directory +$webComponentsDirectory = '/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/'; +$jsFiles = findJsFiles($webComponentsDirectory); + +// Add logo asset if needed +// Note: In the original JS, there was a getters.paths().webgui.logo.assetPath that we'd add +// Since we don't have access to that here, you may need to add the specific logo path if known + +// Merge the JS files with the whitelist +$arrWhitelist = array_merge($arrWhitelist, $jsFiles); + if (in_array(preg_replace(['/\?v=\d+$/','/\?\d+$/'],'',$_SERVER['REQUEST_URI']),$arrWhitelist)) { // authorized http_response_code(200); diff --git a/emhttp/plugins/dynamix/LogViewer.page b/emhttp/plugins/dynamix/LogViewer.page new file mode 100644 index 000000000..fb9eb150c --- /dev/null +++ b/emhttp/plugins/dynamix/LogViewer.page @@ -0,0 +1,8 @@ +Menu="UNRAID-OS" +Title="Log Viewer (new)" +Icon="icon-log" +Tag="list" +--- + + + \ No newline at end of file diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout.php b/emhttp/plugins/dynamix/include/DefaultPageLayout.php index 0bdf4ec2c..76b5d2931 100644 --- a/emhttp/plugins/dynamix/include/DefaultPageLayout.php +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout.php @@ -28,22 +28,22 @@ $entity = $notify['entity'] & 1 == 1; $alerts = '/tmp/plugins/my_alerts.txt'; $wlan0 = file_exists('/sys/class/net/wlan0'); -$safemode = _var($var,'safeMode')=='yes'; +$safemode = _var($var, 'safeMode') == 'yes'; $banner = "$config/webGui/banner.png"; $notes = '/var/tmp/unRAIDServer.txt'; if (!file_exists($notes)) { - file_put_contents($notes, shell_exec("$docroot/plugins/dynamix.plugin.manager/scripts/plugin changes $docroot/plugins/unRAIDServer/unRAIDServer.plg")); + file_put_contents($notes, shell_exec("$docroot/plugins/dynamix.plugin.manager/scripts/plugin changes $docroot/plugins/unRAIDServer/unRAIDServer.plg")); } $taskPages = find_pages('Tasks'); $buttonPages = find_pages('Buttons'); $pages = []; // finds subpages if (!empty($myPage['text'])) $pages[$myPage['name']] = $myPage; -if (_var($myPage,'Type')=='xmenu') $pages = array_merge($pages, find_pages($myPage['name'])); +if (_var($myPage, 'Type') == 'xmenu') $pages = array_merge($pages, find_pages($myPage['name'])); // nchan related actions -$nchan = ['webGui/nchan/notify_poller','webGui/nchan/session_check']; +$nchan = ['webGui/nchan/notify_poller', 'webGui/nchan/session_check']; if ($wlan0) $nchan[] = 'webGui/nchan/wlan0'; // build nchan scripts from found pages $allPages = array_merge($taskPages, $buttonPages, $pages); @@ -52,96 +52,94 @@ foreach ($allPages as $page) { } // act on nchan scripts if (count($pages)) { - $running = file_exists($nchan_pid) ? file($nchan_pid,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES) : []; + $running = file_exists($nchan_pid) ? file($nchan_pid, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : []; $start = array_diff($nchan, $running); // returns any new scripts to be started $stop = array_diff($running, $nchan); // returns any old scripts to be stopped $running = array_merge($start, $running); // update list of current running nchan scripts // start nchan scripts which are new foreach ($start as $row) { - $script = explode(':',$row)[0]; + $script = explode(':', $row)[0]; exec("$docroot/$script &>/dev/null &"); } // stop nchan scripts with the :stop option foreach ($stop as $row) { - [$script,$opt] = my_explode(':',$row); + [$script, $opt] = my_explode(':', $row); if ($opt == 'stop') { exec("pkill -f $docroot/$script &>/dev/null &"); - array_splice($running,array_search($row,$running),1); + array_splice($running, array_search($row, $running), 1); } } - if (count($running)) file_put_contents($nchan_pid,implode("\n",$running)."\n"); else @unlink($nchan_pid); + if (count($running)) file_put_contents($nchan_pid, implode("\n", $running) . "\n"); + else @unlink($nchan_pid); } ?> -lang="" class="getThemeHtmlClass() ?>"> +lang="" class="getThemeHtmlClass() ?>"> + -<?=_var($var, 'NAME')?>/<?=_var($myPage, 'name')?> - - - - - - - - -"> -"> -"> -"> -"> -"> + <?= _var($var, 'NAME') ?>/<?= _var($myPage, 'name') ?> + + + + + + + + + "> + "> + "> + "> + "> + "> -"> -"> -"> -"> + "> + "> + "> + "> - + isSidebarTheme()) { + echo generate_sidebar_icon_css($taskPages, $buttonPages); + } + ?> + - + - - + + - + + ' . parse_text($button['text'])); + } -'.parse_text($button['text'])); -} + foreach ($pages as $page) { + annotate($page['file']); + includePageStylesheets($page); + } + ?> -foreach ($pages as $page) { - annotate($page['file']); - includePageStylesheets($page); -} -?> - - + + + @@ -149,5 +147,7 @@ foreach ($pages as $page) { + - + + \ No newline at end of file diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php b/emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php index ae5f5eb67..be71c6f72 100644 --- a/emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php @@ -71,32 +71,7 @@ defaultPage.on('message', function(msg,meta) { $('#statusbar').html(status); break; case 2: - // notifications - var bell1 = 0, bell2 = 0, bell3 = 0; - $.each($.parseJSON(msg), function(i, notify){ - switch (notify.importance) { - case 'alert' : bell1++; break; - case 'warning': bell2++; break; - case 'normal' : bell3++; break; - } - - if (notify.show) { - $.jGrowl(notify.subject+'
'+notify.description,{ - group: notify.importance, - header: notify.event+': '+notify.timestamp, - theme: notify.file, - beforeOpen: function(e,m,o){if ($('div.jGrowl-notification').hasClass(notify.file)) return(false);}, - afterOpen: function(e,m,o){if (notify.link) $(e).css('cursor','pointer');}, - click: function(e,m,o){if (notify.link) location.replace(notify.link);}, - close: function(e,m,o){$.post('/webGui/include/Notify.php',{cmd:'hide',file:""+notify.file,csrf_token:csrf_token},function(){$.post('/webGui/include/Notify.php',{cmd:'archive',file:notify.file,csrf_token:csrf_token});});} - }); - } - - }); - $('#bell').removeClass('red-orb yellow-orb green-orb').prop('title'," ["+bell1+']\n'+" ["+bell2+']\n'+" ["+bell3+']'); - if (bell1) $('#bell').addClass('red-orb'); else - if (bell2) $('#bell').addClass('yellow-orb'); else - if (bell3) $('#bell').addClass('green-orb'); + // notifications - moved to the Unraid API break; } }); diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout/GUIModeSessionFix.php b/emhttp/plugins/dynamix/include/DefaultPageLayout/GUIModeSessionFix.php new file mode 100644 index 000000000..516284e1e --- /dev/null +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout/GUIModeSessionFix.php @@ -0,0 +1,26 @@ + \ No newline at end of file diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout/Header.php b/emhttp/plugins/dynamix/include/DefaultPageLayout/Header.php index 4a33aef78..2bd197073 100644 --- a/emhttp/plugins/dynamix/include/DefaultPageLayout/Header.php +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout/Header.php @@ -1,9 +1,5 @@