From 261e680c7d9b470548f7d3b80842a345a7ecd2fa Mon Sep 17 00:00:00 2001 From: bergware Date: Wed, 27 Dec 2023 10:09:17 +0100 Subject: [PATCH] Restore favorites on reboot --- .../plugins/dynamix/include/MyFavorites.php | 17 ++++++++++++--- .../plugins/dynamix/scripts/restore_favorites | 21 +++++++++++++++++++ etc/rc.d/rc.local | 5 +++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 emhttp/plugins/dynamix/scripts/restore_favorites diff --git a/emhttp/plugins/dynamix/include/MyFavorites.php b/emhttp/plugins/dynamix/include/MyFavorites.php index 47e64e294..c326d4bd8 100644 --- a/emhttp/plugins/dynamix/include/MyFavorites.php +++ b/emhttp/plugins/dynamix/include/MyFavorites.php @@ -15,6 +15,8 @@ $docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'); $permit = ['del','add']; $action = $_POST['action']??''; $page = glob("$docroot/plugins/*/{$_POST['page']}.page",GLOB_NOSORT)[0]; +$cfg = '/boot/config/favorites.cfg'; + // validate input if (!$page || !in_array($action,$permit)) exit; @@ -26,11 +28,20 @@ fclose($file); // remove label and escape single quotes for sed command $Menu = str_replace([' MyFavorites',"'"],['',"'\''"],$Menu); switch ($action) { -case $permit[0]: +case $permit[0]: // del + $del = str_replace('/','\/',$page); + exec("sed -i '/$del/d' $cfg 2>/dev/null"); break; -case $permit[1]: +case $permit[1]: // add + $file = fopen($cfg,'a+'); + fseek($file,0,0); + while (($line = fgets($file))!==false) { + if (rtrim($line) == $page) break; + } + if (feof($file)) fwrite($file, $page."\n"); + fclose($file); $Menu .= ' MyFavorites'; break; } // update Menu settings -exec("sed -ri '0,/^Menu=\".+\"$/s//Menu=\"$Menu\"/' $page"); +exec("sed -ri '0,/^Menu=\".+\"$/s//Menu=\"$Menu\"/' $page 2>/dev/null"); diff --git a/emhttp/plugins/dynamix/scripts/restore_favorites b/emhttp/plugins/dynamix/scripts/restore_favorites new file mode 100644 index 000000000..f978ca577 --- /dev/null +++ b/emhttp/plugins/dynamix/scripts/restore_favorites @@ -0,0 +1,21 @@ +#!/usr/bin/php -q +/dev/null"); +} +fclose($file); +exit(0); +?> diff --git a/etc/rc.d/rc.local b/etc/rc.d/rc.local index 3e10f5a23..b73cd534f 100755 --- a/etc/rc.d/rc.local +++ b/etc/rc.d/rc.local @@ -54,6 +54,11 @@ fi /usr/local/emhttp/webGui/scripts/notify smtp-init /usr/local/emhttp/webGui/scripts/notify cron-init +# restore favorites +if [[ -x /usr/local/emhttp/webGui/scripts/restore_favorites ]]; then + /usr/local/emhttp/webGui/scripts/restore_favorites +fi + # start nchan monitoring -> stop all running nchan processes when no subscribers are connected if [[ -x /usr/local/sbin/monitor_nchan ]]; then /usr/local/sbin/monitor_nchan