From 1b0af1678e423ceaaf6bab301de1a9223e5ab8d2 Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:02:22 +0800 Subject: [PATCH 01/94] Make the cron files follow the saved settings when Apply is pressed The page sent the schedule to updateCron.php in a request that raced the settings save. When the save landed first, updateCron.php saw no change and kept the old cron file, so a schedule migrated from Unraid (such as 3:40) kept running whatever the page showed. - update.php now runs updateCron.php apply after it saves the settings, and Defaults runs the same apply. - sync also rewrites a cron file that differs from the settings, so an install heals a stale one. - A saved schedule that is not valid cron is still not applied; the page now says so under its field. - Debug zips include mover.tuning.cron, mover.watchdog.cron and the mover lines crond runs. --- plugins/ca.mover.tuning.plg | 22 +- .../plugins/ca.mover.tuning/Mover.tuning.page | 19 +- .../emhttp/plugins/ca.mover.tuning/age_mover | 3 +- .../plugins/ca.mover.tuning/cronSchedule.php | 61 +++++ .../plugins/ca.mover.tuning/debug_mover | 10 + .../ca.mover.tuning/languages/de_DE.txt | 3 + .../ca.mover.tuning/languages/en_US.txt | 3 + .../ca.mover.tuning/languages/fr_FR.txt | 3 + .../ca.mover.tuning/languages/ru_RU.txt | 3 + .../ca.mover.tuning/languages/zh_CN.txt | 3 + .../plugins/ca.mover.tuning/updateCron.php | 227 +++++------------- 11 files changed, 153 insertions(+), 204 deletions(-) create mode 100644 source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/cronSchedule.php diff --git a/plugins/ca.mover.tuning.plg b/plugins/ca.mover.tuning.plg index f42fbeb5..f0a39b82 100644 --- a/plugins/ca.mover.tuning.plg +++ b/plugins/ca.mover.tuning.plg @@ -841,14 +841,7 @@ if version_ge "$UNRAID_VERSION" "7.2.1"; then echo "Found shareMoverSchedule: [$SHARE_MOV_SCHED]" echo "Setting moverTuneCron to: [$SHARE_MOV_SCHED]" echo "moverTuneCron=\"$SHARE_MOV_SCHED\"" >> "$config_file" - - # Create cron file for Mover Tuning, unless its schedule was disabled before 7.2.1 - if grep -q '^moverDisabled="yes"' "$config_file"; then - echo "Mover Tuning schedule is disabled — no Mover Tuning cron file created." - else - echo "Creating Mover Tuning cron file: $TUNING_CRON_FILE" - printf '# Generated schedule for Mover Tuning move:\n%s /usr/local/emhttp/plugins/&name;/mover start |& logger -t move\n' "$SHARE_MOV_SCHED" > "$TUNING_CRON_FILE" - fi + # mover.tuning.cron is left to the updateCron.php sync further down # Rename old dynamix cron file echo "Renaming old schedule: mover.cron → mover.cron.old" @@ -858,12 +851,6 @@ if version_ge "$UNRAID_VERSION" "7.2.1"; then fi fi - # Fix old cron entries using age_mover -> mover - if [[ -f "$TUNING_CRON_FILE" ]] && grep -q '/age_mover start' "$TUNING_CRON_FILE"; then - sed -i 's|/age_mover start|/mover start|' "$TUNING_CRON_FILE" - echo "Migrated cron entry: age_mover → mover" - fi - else echo "Unraid version below 7.2.1 — performing mover script backup." @@ -933,11 +920,6 @@ if [[ -x /usr/local/emhttp/plugins/&name;/age_mover ]]; then echo "Created symlink: /usr/local/sbin/age_mover → plugin age_mover" fi -# The forced move runs through mover.php again so its parity option applies; rewrite schedules saved before that -if [[ -f /boot/config/plugins/&name;/mover.cron ]]; then - sed -i -E 's#/usr/local/sbin/mover(\.old)? (start|force)#/usr/local/emhttp/plugins/&name;/mover.php force start#' /boot/config/plugins/&name;/mover.cron -fi - # Once per install history: a share override saved before Use global existed followed the global setting where it said No # for these keys. The marker is also in default.cfg, so a No saved after Defaults is never rewritten. if [[ -f "$config_file" ]] && ! grep -q '^migratedOverrideNo=' "$config_file"; then @@ -952,7 +934,7 @@ if [[ -f "$config_file" ]] && ! grep -q '^migratedOverrideNo=' "$config_ echo 'migratedOverrideNo="yes"' >> "$config_file" fi -# The plugin's own cron files follow the saved settings: missing ones are written back (reinstall), stale ones removed +# Bring the plugin's own cron files in line with the saved settings; an invalid schedule is logged and its file kept /usr/bin/php -q /usr/local/emhttp/plugins/&name;/updateCron.php sync # Refresh cron diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page index b82ffe64..b50f169f 100644 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page @@ -14,6 +14,7 @@ $config_file = '/boot/config/plugins/' . $plugin . '/' . $plugin . '.cfg'; $config_default_file = '/usr/local/emhttp/plugins/' . $plugin . '/default.cfg'; $cfg = parse_plugin_cfg($plugin); require_once '/usr/local/emhttp/plugins/ca.mover.tuning/logFiles.php'; +require_once '/usr/local/emhttp/plugins/ca.mover.tuning/cronSchedule.php'; $moverLogFiles = array_keys(moverLogFiles($cfg)); $advancedSettings = ($cfg['advancedSettings'] != "yes") ? "no" : "yes"; $advancedFilters = ($cfg['advancedFilters'] != "yes") ? "no" : "yes"; @@ -113,15 +114,6 @@ function toggleResync() { $('input[name="resynchronizeCache"]').prop('disabled', !off); } -function updateCron() { - var cron = $("#cronSchedule").val(); - var tune_cron = $("#tune_cronSchedule").val(); - var cronEnabled = $("#forceCron").val(); - var ismoverDisabled = $("#moverDisabled").val(); - var watchdog = $("#watchdog").val(); - $.post("/plugins/ca.mover.tuning/updateCron.php",{cronEnabled:cronEnabled,cron:cron,tune_cron:tune_cron,ismoverDisabled:ismoverDisabled,watchdog:watchdog}); -} - // the View and Download links follow the file picked in the Log files row function mtLogLinks() { var file = encodeURIComponent(document.getElementById('moverLogFile').value); @@ -579,8 +571,11 @@ if (localStorage.getItem(newYearSeasonKey) === 'yes') {
-
+ + + + _(Disable Mover running on a schedule)_: : '> + _(Not a valid cron schedule: it is not applied.)_ :mover_tune_movertunecron_plug: > Runs the age_mover schedule from the Mover Tuning plugin using your custom cron entry (includes all plugin filters). > > Cron Schedule entry example 0 */4 * * *.  To run at every 4 hours.  What Is Cron +> +> The schedule must be a valid cron entry: an invalid one is not applied, and the error is written to the syslog. :end @@ -912,6 +910,7 @@ _(Force move of all files on a schedule)_: _(Cron Schedule to force move all of files)_: : ' > + _(Not a valid cron schedule: it is not applied.)_ :mover_tune_cron_plug: diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover index 8cba3f80..8298b231 100755 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover @@ -3430,8 +3430,7 @@ reset() { # Remove the schedule files, then write back the ones default.cfg sets; this runs after a failed step too, so the # schedules follow whichever settings are left rm -f "${MOVERTUNINGCFGFILE%/*}/mover.cron" "${MOVERTUNINGCFGFILE%/*}/mover.tuning.cron" "${MOVERTUNINGCFGFILE%/*}/mover.watchdog.cron" || failed=1 - /usr/bin/php -q /usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php sync || failed=1 - /usr/local/sbin/update_cron || failed=1 + /usr/bin/php -q /usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php apply || failed=1 if [ "$failed" -ne 0 ]; then echo "mover: Error: The reset did not complete, see the lines above." exit 1 diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/cronSchedule.php b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/cronSchedule.php new file mode 100644 index 00000000..f2660344 --- /dev/null +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/cronSchedule.php @@ -0,0 +1,61 @@ + $field) { + if (cron_field_ok($field, $limits[$i][0], $limits[$i][1], $limits[$i][2]) === false) { + return false; + } + } + return true; +} + +// One cron field: a comma list of * / n / n-m, each with an optional /step; numbers within min..max, names looked up in $names +function cron_field_ok($field, $min, $max, $names) +{ + foreach (explode(',', $field) as $item) { + if (preg_match('/^(\*|([a-z0-9]+)(?:-([a-z0-9]+))?)(?:\/([0-9]+))?\z/i', $item, $m) !== 1) { + return false; + } + if (isset($m[4]) === true && (int)$m[4] < 1) { + return false; + } + if ($m[1] === '*') { + continue; + } + foreach ([$m[2], $m[3] ?? ''] as $value) { + if ($value === '') { + continue; + } + // names count from $min, so jan is 1 and sun is 0 + $index = array_search(strtolower($value), $names, true); + $n = ctype_digit($value) === true ? (int)$value : ($index === false ? -1 : $index + $min); + if ($n < $min || $n > $max) { + return false; + } + } + } + return true; +} + +/** True when a saved schedule is set but valid_cron rejects it, so updateCron.php does not apply it */ +function saved_cron_invalid($cron) +{ + $cron = trim($cron); + return $cron !== '' && valid_cron($cron) === false; +} +?> diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/debug_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/debug_mover index 64d75524..9a89ccc4 100755 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/debug_mover +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/debug_mover @@ -140,6 +140,16 @@ mkdir -p $DEBUGROOT/PLUGIN 2>&1 [ -f $CRON ] && cp -f $CRON $DEBUGROOT/PLUGIN/ca.mover.tuning.cron.txt 2>&1 +for file in "${CRON%/*}/mover.tuning.cron" "${CRON%/*}/mover.watchdog.cron"; do + [ -f "$file" ] && cp -f "$file" "$DEBUGROOT/PLUGIN/${file##*/}.txt" 2>&1 +done + +# the mover lines crond runs now, to compare with the cron files and the settings +{ + echo "### mover lines in /etc/cron.d/root" + grep -F -e ca.mover.tuning -e /usr/local/sbin/mover /etc/cron.d/root || echo "none" +} >$DEBUGROOT/PLUGIN/crontab.txt 2>&1 + for file in $UNRAID_CRON; do if [[ -f $file ]]; then cp -f "$file" "${DEBUGROOT}/PLUGIN/unraid.${file##*/}.txt" 2>&1 diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt index b903c435..099ff00d 100644 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt @@ -125,6 +125,7 @@ Mover Tuning thresholds=Mover‑Tuning‑Schwellwerte No files were movedsynced by Mover Tuning plugin Elapsed time %s=Keine Dateien wurden durch das Mover Tuning Plugin verschoben/synchronisiert. Verstrichene Zeit %s No log files yet=Noch keine Protokolldateien Not Applicable Share Does Not Exist Yet=Nicht anwendbar (Freigabe existiert noch nicht) +Not a valid cron schedule it is not applied=Kein gültiger Cron‑Zeitplan: Er wird nicht übernommen. Notify Mover Tuning plugin actions=Aktionen des Mover‑Tuning‑Plugins melden Oldest first=Älteste zuerst Only move files larger than this in MB=Nur Dateien verschieben, die größer sind als dieser Wert (in MB) @@ -237,6 +238,8 @@ Youre welcome 😊 Thanks for using=Gern geschehen 😊 Danke für die Nutzung! > Führt den age_mover‑Zeitplan des Mover‑Tuning‑Plugins anhand deines eigenen Cron‑Eintrags aus (inklusive aller Plugin‑Filter). > > Beispiel Cron‑Eintrag: 0 */4 * * *.  Führt den Vorgang alle 4 Stunden aus. Was ist Cron? +> +> Der Zeitplan muss ein gültiger Cron‑Eintrag sein: Ein ungültiger wird nicht übernommen, und der Fehler wird ins Syslog geschrieben. :end :mover_tune_testmode_plug: diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt index 26072628..af928ffd 100644 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt @@ -127,6 +127,7 @@ Mover Tuning thresholds= No files were movedsynced by Mover Tuning plugin Elapsed time %s=No files were moved/synced by Mover Tuning plugin. Elapsed time: %s No log files yet= Not Applicable Share Does Not Exist Yet=Not Applicable (Share Does Not Exist Yet) +Not a valid cron schedule it is not applied=Not a valid cron schedule: it is not applied. Notify Mover Tuning plugin actions= Oldest first= Only move files larger than this in MB=Only move files larger than this (in MB) @@ -239,6 +240,8 @@ Youre welcome 😊 Thanks for using=You're welcome! 😊 Thanks for using! > Runs the age_mover schedule from the Mover Tuning plugin using your custom cron entry (includes all plugin filters). > > Cron Schedule entry example 0 */4 * * *.  To run at every 4 hours.  What Is Cron +> +> The schedule must be a valid cron entry: an invalid one is not applied, and the error is written to the syslog. :end :mover_tune_testmode_plug: diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt index 6a769b9e..ddc311a2 100644 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt @@ -125,6 +125,7 @@ Mover Tuning thresholds=Seuils Mover Tuning No files were movedsynced by Mover Tuning plugin Elapsed time %s=Aucun fichier n’a été déplacé/synchronisé par le plugin Mover Tuning. Temps écoulé : %s No log files yet=Aucun fichier journal pour le moment Not Applicable Share Does Not Exist Yet=Non applicable (la part n’existe pas encore) +Not a valid cron schedule it is not applied=Planification cron invalide : elle n’est pas appliquée. Notify Mover Tuning plugin actions=Notifier les actions du plugin Mover Tuning Oldest first=Les plus anciens d’abord Only move files larger than this in MB=Déplacer uniquement les fichiers plus grands que cette taille (en Mo) @@ -237,6 +238,8 @@ Youre welcome 😊 Thanks for using=Avec plaisir 😊 Merci pour votre utilisati > Exécute le calendrier age_mover du plugin Mover Tuning en utilisant votre entrée cron personnalisée (inclut tous les filtres du plugin). > > Exemple d’entrée Cron : 0 */4 * * *.  Pour exécuter toutes les 4 heures.  Qu’est‑ce que Cron +> +> La planification doit être une entrée cron valide : une entrée invalide n’est pas appliquée, et l’erreur est écrite dans le syslog. :end :mover_tune_testmode_plug: diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt index c68ce129..bebb8630 100644 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt @@ -125,6 +125,7 @@ Mover Tuning thresholds=Пороги Mover Tuning No files were movedsynced by Mover Tuning plugin Elapsed time %s=Файлы не были перемещены/синхронизированы плагином Mover Tuning. Затраченное время: %s No log files yet=Файлов журнала пока нет Not Applicable Share Does Not Exist Yet=Не применимо (шара ещё не существует) +Not a valid cron schedule it is not applied=Некорректное расписание cron: оно не применяется. Notify Mover Tuning plugin actions=Уведомлять о действиях плагина Mover Tuning Oldest first=Сначала самые старые Only move files larger than this in MB=Перемещать только файлы больше указанного размера (в МБ) @@ -236,6 +237,8 @@ Youre welcome 😊 Thanks for using=Пожалуйста! 😊 Спасибо, > Запускает расписание age_mover плагина Mover Tuning с использованием вашей пользовательской записи cron (включает все фильтры плагина). > > Пример записи расписания Cron: 0 */4 * * *.  Для запуска каждые 4 часа.  Что такое Cron +> +> Расписание должно быть корректной записью cron: некорректное не применяется, а ошибка записывается в syslog. :end :mover_tune_testmode_plug: diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt index 13860bf7..4e828a9d 100644 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt @@ -124,6 +124,7 @@ Mover Tuning thresholds=Mover Tuning 阈值 No files were movedsynced by Mover Tuning plugin Elapsed time %s=Mover Tuning 插件没有移动/同步任何文件。耗时:%s No log files yet=暂无日志文件 Not Applicable Share Does Not Exist Yet=不适用(共享尚不存在) +Not a valid cron schedule it is not applied=无效的 cron 计划:不会生效。 Notify Mover Tuning plugin actions=通知设置 Oldest first=最旧的优先 Only move files larger than this in MB=仅移动大于此大小的文件(MB) @@ -236,6 +237,8 @@ Youre welcome 😊 Thanks for using=不客气!😊 感谢使用! > 使用自定义 cron 条目运行 Mover Tuning 插件的 age_mover 计划(应用所有插件过滤器)。 > > Cron 计划示例 0 */4 * * *。  表示每 4 小时运行一次。  什么是 Cron +> +> 计划必须是有效的 cron 条目:无效的计划不会生效,错误会写入系统日志。 :end :mover_tune_testmode_plug: diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php index 561f559a..f5858786 100755 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php @@ -1,6 +1,7 @@ #!/usr/bin/php $field) { - if (cron_field_ok($field, $limits[$i][0], $limits[$i][1], $limits[$i][2]) === false) { - return false; - } - } - return true; -} - -// One cron field: a comma list of * / n / n-m, each with an optional /step; numbers within min..max, names looked up in $names -function cron_field_ok($field, $min, $max, $names) -{ - foreach (explode(',', $field) as $item) { - if (preg_match('/^(\*|([a-z0-9]+)(?:-([a-z0-9]+))?)(?:\/([0-9]+))?\z/i', $item, $m) !== 1) { - return false; - } - if (isset($m[4]) === true && (int)$m[4] < 1) { - return false; - } - if ($m[1] === '*') { - continue; - } - foreach ([$m[2], $m[3] ?? ''] as $value) { - if ($value === '') { - continue; - } - // names count from $min, so jan is 1 and sun is 0 - $index = array_search(strtolower($value), $names, true); - $n = ctype_digit($value) === true ? (int)$value : ($index === false ? -1 : $index + $min); - if ($n < $min || $n > $max) { - return false; - } - } + if (file_put_contents($file, $content) === false) { + logger("Error: Failed to write $file."); + return; } - return true; + logger($done); } -/** Writes Unraid's mover.cron from the Mover Settings schedule, before Unraid 7.2.1; true when the file was written */ +/** Makes Unraid's mover.cron run the Mover Settings schedule, before Unraid 7.2.1 */ function make_unraid_cron() { global $vars; @@ -107,66 +64,42 @@ function make_unraid_cron() $moverCron = trim($vars['shareMoverSchedule']); if (valid_cron($moverCron) === false) { logger("Error: Invalid Unraid mover schedule: " . preg_replace('/[^[:print:]]/', '?', $moverCron)); - return false; + return; } $cronMoverFile = "# Generated mover schedule:\n" . $moverCron . " /usr/local/sbin/mover start |& logger -t move\n\n"; - if (file_put_contents("/boot/config/plugins/dynamix/mover.cron", $cronMoverFile) === false) { - logger("Error: Failed to write mover.cron file."); - return false; - } - return true; + put_cron_file("/boot/config/plugins/dynamix/mover.cron", $cronMoverFile, "Mover schedule set to $moverCron."); + return; } logger("No mover schedule set in Mover Settings."); - return false; } -/** Writes mover.tuning.cron for the $tuneCron schedule, from Unraid 7.2.1; true when the file was written */ +/** Makes mover.tuning.cron run Mover Tuning on the $tuneCron schedule, from Unraid 7.2.1 */ function make_tune_cron($tuneCron) { - if (empty($tuneCron) === true) { - logger("No cron schedule provided for Mover Tuning move."); - return false; // Nothing to write - } if (valid_cron($tuneCron) === false) { logger("Error: Invalid cron schedule for Mover Tuning move: " . preg_replace('/[^[:print:]]/', '?', $tuneCron)); - return false; + return; } $cronTuneFile = "# Generated schedule for Mover Tuning move:\n" . $tuneCron . " /usr/local/emhttp/plugins/ca.mover.tuning/mover start |& logger -t move\n\n"; - if (file_put_contents("/boot/config/plugins/ca.mover.tuning/mover.tuning.cron", $cronTuneFile) === false) { - logger("Error: Failed to write mover.tuning.cron file."); - return false; - } - return true; + put_cron_file("/boot/config/plugins/ca.mover.tuning/mover.tuning.cron", $cronTuneFile, "Mover Tuning schedule set to $tuneCron."); } -/** Writes the forced move's mover.cron for the $cron schedule, run through mover.php force; true when the file was written */ +/** Makes the forced move's mover.cron run mover.php force on the $cron schedule */ function make_cron($cron) { - if (empty($cron) === true) { - logger("No cron schedule provided for forced move."); - return false; - } if (valid_cron($cron) === false) { logger("Error: Invalid cron schedule for forced move: " . preg_replace('/[^[:print:]]/', '?', $cron)); - return false; + return; } $cronFile = "# Generated schedule for forced move:\n{$cron} /usr/local/emhttp/plugins/ca.mover.tuning/mover.php force start |& logger -t move\n\n"; - if (file_put_contents("/boot/config/plugins/ca.mover.tuning/mover.cron", $cronFile) === false) { - logger("Error: Failed to write forced mover.cron file."); - return false; - } - return true; + put_cron_file("/boot/config/plugins/ca.mover.tuning/mover.cron", $cronFile, "Forced move schedule set to $cron."); } -/** Writes mover.watchdog.cron, the cache watchdog every 5 minutes (a run it starts logs to syslog itself, so the line discards output); true when written */ +/** Makes mover.watchdog.cron run the cache watchdog every 5 minutes (a run it starts logs to syslog itself, so the line discards output) */ function make_watchdog_cron() { $cronFile = "# Generated schedule for the Mover Tuning cache watchdog:\n*/5 * * * * /usr/local/emhttp/plugins/ca.mover.tuning/age_mover watchdog >/dev/null 2>&1\n\n"; - if (file_put_contents("/boot/config/plugins/ca.mover.tuning/mover.watchdog.cron", $cronFile) === false) { - logger("Error: Failed to write mover.watchdog.cron file."); - return false; - } - return true; + put_cron_file("/boot/config/plugins/ca.mover.tuning/mover.watchdog.cron", $cronFile, "Cache watchdog schedule set to every 5 minutes."); } /** Deletes a cron file, logging $why when given; false, with an error logged, when it exists and cannot be deleted */ @@ -185,7 +118,7 @@ function remove_cron_file($file, $why = '') return true; } -/** Makes the plugin's own cron files follow the saved settings: writes a missing one they call for, removes one they do not, never rewrites one */ +/** Writes each plugin cron file the saved settings call for when missing or different (an invalid schedule is logged, its file kept), removes the rest; false when the settings file does not parse */ function sync_cron_files() { // parse_plugin_cfg reads it with my_parse_ini_file from Unraid 6.12.14, parse_ini_file before; a file that does not @@ -195,12 +128,13 @@ function sync_cron_files() $saved = function_exists('my_parse_ini_file') === true ? @my_parse_ini_file($cfgFile) : @parse_ini_file($cfgFile); if (is_array($saved) === false) { logger("Error: $cfgFile does not parse, so the cron files are left as they are."); - return; + return false; } } sync_forced_cron(); sync_tune_cron(); sync_watchdog_cron(); + return true; } /** sync_cron_files() for the forced move's mover.cron */ @@ -213,8 +147,8 @@ function sync_forced_cron() remove_cron_file($forcedFile, "force move is off"); } elseif ($cfg_cron === '') { remove_cron_file($forcedFile, "no forced move schedule is set"); - } elseif (file_exists($forcedFile) === false && make_cron($cfg_cron) === true) { - logger("Forced move schedule written back from the saved settings."); + } else { + make_cron($cfg_cron); } } @@ -232,8 +166,8 @@ function sync_tune_cron() remove_cron_file($tuneFile, "the Mover Tuning schedule is disabled"); } elseif ($cfg_moverTuneCron === '') { remove_cron_file($tuneFile, "no Mover Tuning schedule is set"); - } elseif (file_exists($tuneFile) === false && make_tune_cron($cfg_moverTuneCron) === true) { - logger("Mover Tuning schedule written back from the saved settings."); + } else { + make_tune_cron($cfg_moverTuneCron); } } @@ -245,92 +179,41 @@ function sync_watchdog_cron() $watchdogFile = "/boot/config/plugins/ca.mover.tuning/mover.watchdog.cron"; if ($cfg_watchdog !== 'yes') { remove_cron_file($watchdogFile, "the cache watchdog is off"); - } elseif (file_exists($watchdogFile) === false && make_watchdog_cron() === true) { - logger("Cache watchdog schedule written back from the saved settings."); + } else { + make_watchdog_cron(); } } -// From the CLI (plugin install, age_mover reset) the plugin's cron files are brought in line with the saved settings, -// exiting 1 when an error was logged; the caller runs update_cron afterwards -if (PHP_SAPI === 'cli' && ($argv[1] ?? '') === 'sync') { - sync_cron_files(); - exit($loggedErrors === 0 ? 0 : 1); -} - -// Check if value was changed to prevent the logger of printing when cron was not changed and not make cron file when avalible already -if ($cfg_cronEnabled !== post_string('cronEnabled')) { - if (post_string('cronEnabled') === "yes") { - if (make_cron(trim(post_string('cron'))) === true) { - logger("Forced move schedule enabled successfully."); - } - } elseif (remove_cron_file("/boot/config/plugins/ca.mover.tuning/mover.cron") === true) { - logger("Forced move schedule disabled successfully."); - } -} else { - // If cron already enabled and cron time was changed update cron file - if ($cfg_cronEnabled === "yes" && $cfg_cron !== post_string('cron')) { - if (make_cron(trim(post_string('cron'))) === true) { - logger("Forced move schedule updated successfully."); - } - } -} +/** Before Unraid 7.2.1, where Unraid's own mover.cron starts Mover Tuning: removed while the schedule is disabled, else written back when missing and the array is started */ +function apply_unraid_cron() +{ + global $vars, $cfg_moverDisabled; -// Check if value was changed -if ($cfg_moverDisabled !== post_string('ismoverDisabled')) { - // If mover schedule is disabled - if (post_string('ismoverDisabled') === "yes") { - if (version_compare($vars['version'], '7.2.1', '>=') === true) { - // Check if the file exists - if (file_exists("/boot/config/plugins/ca.mover.tuning/mover.tuning.cron") === false) { - logger("Mover Tuning cron file does not exist"); - } elseif (remove_cron_file("/boot/config/plugins/ca.mover.tuning/mover.tuning.cron") === true) { - logger("Mover Tuning schedule disabled successfully."); - } - } else { - // Check if the file exists - if (file_exists("/boot/config/plugins/dynamix/mover.cron") === false) { - logger("Mover cron file does not exist"); - } elseif (remove_cron_file("/boot/config/plugins/dynamix/mover.cron") === true) { - logger("Mover schedule disabled successfully."); - } - } - } else { - if (version_compare($vars['version'], '7.2.1', '>=') === true) { - $tuneCron = isset($_POST['tune_cron']) === true ? trim(post_string('tune_cron')) : $cfg_moverTuneCron; - if (make_tune_cron($tuneCron) === true) { - logger("Mover Tuning schedule enabled successfully."); - } - } elseif (make_unraid_cron() === true) { - logger("Mover schedule enabled successfully."); - } + $unraidFile = "/boot/config/plugins/dynamix/mover.cron"; + if ($vars['version'] === '' || version_compare($vars['version'], '7.2.1', '>=') === true) { + return; } -} - -// Handle Mover Tuning custom cron schedule, unless this request disables Mover Tuning -if (version_compare($vars['version'], '7.2.1', '>=') === true && post_string('ismoverDisabled') !== 'yes') { - $postTuneCron = post_string('tune_cron'); - if ($cfg_moverTuneCron !== $postTuneCron) { - $tuneCron = trim($postTuneCron); - if ($tuneCron === "" && remove_cron_file("/boot/config/plugins/ca.mover.tuning/mover.tuning.cron") === true) { - logger("Mover Tuning cron schedule removed."); - } elseif ($tuneCron !== "" && make_tune_cron($tuneCron) === true) { - logger("Mover Tuning cron schedule updated successfully."); - } + if ($cfg_moverDisabled === 'yes') { + remove_cron_file($unraidFile, "the Mover Tuning schedule is disabled"); + } elseif (is_file($unraidFile) === false && ($vars['mdState'] ?? '') === 'STARTED') { + // as emhttpd does: it writes this file from Mover Settings and removes it at array stop + make_unraid_cron(); } } -// The watchdog cron file follows the posted setting rather than a comparison with the saved one, which update.php -// may already have written; age_mover watchdog also checks the setting, so a leftover file does nothing -$watchdogCron = "/boot/config/plugins/ca.mover.tuning/mover.watchdog.cron"; -if (post_string('watchdog') === 'yes') { - if (is_file($watchdogCron) === false && make_watchdog_cron() === true) { - logger("Cache watchdog enabled."); +// "sync" runs at plugin install, whose caller runs update_cron; "apply" runs at age_mover reset and as the settings form's +// #command, which update.php runs once it has saved the settings. A web request, such as a page loaded before an update, does nothing. +$mode = PHP_SAPI === 'cli' ? ($argv[1] ?? '') : ''; +if ($mode === 'sync') { + sync_cron_files(); +} elseif ($mode === 'apply') { + if (sync_cron_files() === true) { + apply_unraid_cron(); } -} elseif (isset($_POST['watchdog']) === true && is_file($watchdogCron) === true) { - if (remove_cron_file($watchdogCron) === true) { - logger("Cache watchdog disabled."); + exec("/usr/local/sbin/update_cron", $output, $status); + if ($status !== 0) { + logger("Error: /usr/local/sbin/update_cron exited with $status, so crond may still run the previous schedules."); } } - -exec("update_cron"); +exit($loggedErrors === 0 ? 0 : 1); ?> \ No newline at end of file From 5632d28e18b924258b3e87bdf05c91c149abb28b Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Tue, 24 Nov 2026 06:39:21 +0800 Subject: [PATCH 02/94] Keep the install's cron path migrations and match dcron's name forms - The install again rewrites age_mover and old forced-move commands in the cron files: sync keeps a file whose saved schedule is invalid, so it would not heal those lines. - A day or month name is valid only as dcron reads it (mon or Mon), so a schedule such as 0 4 * * MON is flagged instead of written and skipped. --- plugins/ca.mover.tuning.plg | 11 +++++++++++ .../emhttp/plugins/ca.mover.tuning/cronSchedule.php | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/ca.mover.tuning.plg b/plugins/ca.mover.tuning.plg index f0a39b82..7d78b768 100644 --- a/plugins/ca.mover.tuning.plg +++ b/plugins/ca.mover.tuning.plg @@ -851,6 +851,12 @@ if version_ge "$UNRAID_VERSION" "7.2.1"; then fi fi + # Fix old cron entries using age_mover -> mover + if [[ -f "$TUNING_CRON_FILE" ]] && grep -q '/age_mover start' "$TUNING_CRON_FILE"; then + sed -i 's|/age_mover start|/mover start|' "$TUNING_CRON_FILE" + echo "Migrated cron entry: age_mover → mover" + fi + else echo "Unraid version below 7.2.1 — performing mover script backup." @@ -920,6 +926,11 @@ if [[ -x /usr/local/emhttp/plugins/&name;/age_mover ]]; then echo "Created symlink: /usr/local/sbin/age_mover → plugin age_mover" fi +# The forced move runs through mover.php again so its parity option applies; rewrite schedules saved before that +if [[ -f /boot/config/plugins/&name;/mover.cron ]]; then + sed -i -E 's#/usr/local/sbin/mover(\.old)? (start|force)#/usr/local/emhttp/plugins/&name;/mover.php force start#' /boot/config/plugins/&name;/mover.cron +fi + # Once per install history: a share override saved before Use global existed followed the global setting where it said No # for these keys. The marker is also in default.cfg, so a No saved after Defaults is never rewritten. if [[ -f "$config_file" ]] && ! grep -q '^migratedOverrideNo=' "$config_file"; then diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/cronSchedule.php b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/cronSchedule.php index f2660344..1fa68a8e 100644 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/cronSchedule.php +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/cronSchedule.php @@ -41,8 +41,8 @@ function cron_field_ok($field, $min, $max, $names) if ($value === '') { continue; } - // names count from $min, so jan is 1 and sun is 0 - $index = array_search(strtolower($value), $names, true); + // names count from $min, so jan is 1 and sun is 0; dcron reads a name only as mon or Mon, so MON is rejected + $index = array_search(lcfirst($value), $names, true); $n = ctype_digit($value) === true ? (int)$value : ($index === false ? -1 : $index + $min); if ($n < $min || $n > $max) { return false; From 77393fdac8d036efc4d8aafad0c642dc33bc3322 Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Tue, 24 Nov 2026 07:50:00 +0800 Subject: [PATCH 03/94] Keep Unraid's old schedule until its replacement is written The migration renamed mover.cron before the sync wrote mover.tuning.cron. When the settings file does not parse, the sync writes nothing, so no schedule was left. The rename now waits for the sync to write the replacement or find the Mover Tuning schedule disabled. --- plugins/ca.mover.tuning.plg | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/ca.mover.tuning.plg b/plugins/ca.mover.tuning.plg index 7d78b768..1d82a649 100644 --- a/plugins/ca.mover.tuning.plg +++ b/plugins/ca.mover.tuning.plg @@ -841,11 +841,14 @@ if version_ge "$UNRAID_VERSION" "7.2.1"; then echo "Found shareMoverSchedule: [$SHARE_MOV_SCHED]" echo "Setting moverTuneCron to: [$SHARE_MOV_SCHED]" echo "moverTuneCron=\"$SHARE_MOV_SCHED\"" >> "$config_file" - # mover.tuning.cron is left to the updateCron.php sync further down - # Rename old dynamix cron file - echo "Renaming old schedule: mover.cron → mover.cron.old" - mv "$DYNAMIX_CRON_FILE" "$DYNAMIX_CRON_OLD" + # the old schedule goes once the sync has written its replacement or found the Mover Tuning schedule disabled + if /usr/bin/php -q /usr/local/emhttp/plugins/&name;/updateCron.php sync || [[ -f "$TUNING_CRON_FILE" ]]; then + echo "Renaming old schedule: mover.cron → mover.cron.old" + mv "$DYNAMIX_CRON_FILE" "$DYNAMIX_CRON_OLD" + else + echo "mover.tuning.cron was not written (the reason is in the syslog), so the old schedule stays in mover.cron." + fi else echo "shareMoverSchedule is empty — nothing to migrate." fi From 6a2a13906c2caf7e94ac6117ddc942e8315584c1 Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Tue, 24 Nov 2026 07:55:11 +0800 Subject: [PATCH 04/94] Remove the filename check, so names holding $, <, : and the like move A file name reaches rsync as its own argument and Unraid's move as a line on stdin, never through a shell, so no character in it can run anything. The check's other two parts never fired on a real name: a name is at most 255 bytes, and a name cannot hold /, so the traversal test caught only names starting ..\ or holding \.., which are plain names on Linux. The check kept those files on the cache and reported each one as a failure. A name that ends in | now also moves in a rebalance with sync: the move loop took the path through read, which drops a | that ends the row. Anyone who added characters to the list to keep files on the cache can list those files under "Ignore files and folders listed inside of a text file" or "Ignore file types" instead. Fixes #285 --- README.md | 5 +- .../plugins/ca.mover.tuning/Mover.tuning.page | 54 ------------ .../emhttp/plugins/ca.mover.tuning/age_mover | 86 +------------------ .../plugins/ca.mover.tuning/default.cfg | 2 - .../ca.mover.tuning/languages/de_DE.txt | 29 ------- .../ca.mover.tuning/languages/en_US.txt | 29 ------- .../ca.mover.tuning/languages/fr_FR.txt | 28 ------ .../ca.mover.tuning/languages/ru_RU.txt | 29 ------- .../ca.mover.tuning/languages/zh_CN.txt | 29 ------- 9 files changed, 6 insertions(+), 285 deletions(-) diff --git a/README.md b/README.md index dc5a2ea5..1ae045d5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ This is an [Unraid](https://unraid.net/) plugin that lets you fine-tune the operation of the [mover](https://docs.unraid.net/unraid-os/using-unraid-to/manage-storage/cache-pools/#using-mover). -This fork merges all [pull requests](https://github.com/R3yn4ld/ca.mover.tuning/pulls) from [R3yn4ld](https://github.com/R3yn4ld/ca.mover.tuning) after review (cosmetics, per-share skipfiletypes merge, automatic age threshold, filename sanitizing, Unraid 7.x compatibility) and adds many new features. See [CHANGELOG.md](CHANGELOG.md) for the full history. +This fork merges all [pull requests](https://github.com/R3yn4ld/ca.mover.tuning/pulls) from [R3yn4ld](https://github.com/R3yn4ld/ca.mover.tuning) after review (cosmetics, per-share skipfiletypes merge, automatic age threshold, Unraid 7.x compatibility) and adds many new features. See [CHANGELOG.md](CHANGELOG.md) for the full history. **Requires Unraid 6.9.0-rc2 or newer.** Unraid 7.2.1+ and the 7.4 rc1 are supported (see [Unraid 7.2.1 and newer](#unraid-721-and-newer)). @@ -53,7 +53,6 @@ This fork merges all [pull requests](https://github.com/R3yn4ld/ca.mover.tuning/ **Safety, logging and troubleshooting** - Test Mode (dry run) with clear warnings. -- Optional filename validation with a configurable list of blocked characters. - Live progress of a run (file being processed, action, overall progress, estimated completion). - Pause and Resume buttons on Main and next to "Move now" while a run moves files. An Rsync copy pauses at once; with Move, the run pauses once the current file is done. The per-share Move and the runs of the built-in mover that the plugin starts (forced move, "Move now" without the filters) pause once their current file is done; runs Unraid starts itself are left alone. The next scheduled run or a cache watchdog trigger resumes a paused run. - Detailed logs (file only, or file and syslog), configurable log folder and log age, a Log files row that views or downloads any run's log, and a "Run by" entry showing whether the run came from cron, the CLI or the web UI. @@ -116,7 +115,7 @@ You'll find the settings on the Mover Tuning page within Settings - [Scheduler]( | Section | What you can set | | --- | --- | -| **Plugin Settings** | Disable the plugin's schedule, cache watchdog and its trigger level, Mover Tuning schedule, Test Mode (dry run), filename validation and blocked characters, logging, debug logging and notifications, log folder, log files (view or download) and log retention, parity check behavior, mover and disk I/O priority, force move of all files on a schedule, before/after scripts. | +| **Plugin Settings** | Disable the plugin's schedule, cache watchdog and its trigger level, Mover Tuning schedule, Test Mode (dry run), logging, debug logging and notifications, log folder, log files (view or download) and log retention, parity check behavior, mover and disk I/O priority, force move of all files on a schedule, before/after scripts. | | **Filters** | Whether "Move now" follows the plugin filters, thresholds (move above, free down, fill up), age, move order, CTIME/ATIME, minimum size, sync maximum size, sparseness, ignore list file, ignored file types, hidden files, and "Move All" for cache:yes shares above a pool percentage. | | **Options** | Force turbo write, move files tool, move files that are in use, move/clean empty folders, clean empty ZFS datasets, share size calculation, Synchronize, Rebalance and Resynchronize. Buttons: Apply, Done, Defaults and Move Now, and Pause or Resume while a run moves files. | | **Help** | Debug package (.zip), a link to the support thread, GitHub link and a collapsible "CLI help commands" panel. | diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page index b82ffe64..24c97296 100644 --- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page +++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page @@ -19,7 +19,6 @@ $advancedSettings = ($cfg['advancedSettings'] != "yes") ? "no" : "yes"; $advancedFilters = ($cfg['advancedFilters'] != "yes") ? "no" : "yes"; $advancedOptions = ($cfg['advancedOptions'] != "yes") ? "no" : "yes"; $moverDisabled = ($cfg['moverDisabled'] != "yes") ? "no" : "yes"; -$validateFilenames = ($cfg['validateFilenames'] != "yes") ? "no" : "yes"; $ageDisabled = ($cfg['age'] != "yes") ? "disabled" : ""; $cronDisabled = ($cfg['force'] != "yes") ? "disabled" : ""; $filelistfDisabled = ($cfg['filelistf'] != "yes") ? "disabled" : ""; @@ -338,17 +337,6 @@ function updateScreenMoverAdvancedOptions(option,slow) { } } -function updateScreenMoverInvalidCharsToBlock(option,slow) { - switch (option) { - case 'no': - $('#moverInvalidCharsToBlock').hide(slow); - break; - case 'yes': - $('#moverInvalidCharsToBlock').show(slow); - break; - } -} - // What the config holds, before the selects below capped it to a range. var mtSaved = { moving: , @@ -436,7 +424,6 @@ $(function() { updateScreenMoverAdvancedSettings(''); updateScreenMoverAdvancedFilters(''); updateScreenMoverAdvancedOptions(''); - updateScreenMoverInvalidCharsToBlock(''); mtWatchdogWarning(); toggleTime('ctime'); @@ -687,47 +674,6 @@ function toggleTestModeWarning(val) { :end -_(Validate input filenames to prevent attacks)_: -: -  _(No)_ - _(disables validation of input filenames)_ - -
-:mover_tune_validate_plug: -

In cybersecurity, filenames can be a critical vector for potential attacks and system vulnerabilities. Unsanitized filenames pose significant risks that can compromise system integrity and security.

-

Validate input filenames will check every filename before it is processed by the Mover. This ensures that only valid filenames are accepted, reducing the risk of attacks and vulnerabilities.

-

Disable Only if you have many files to move and you are sure that all filenames are valid and do not contain any potential security risks.

-

1. Check filename length - If the filename exceeds 255 characters, it will be rejected.

-

2. Check for invalid characters - The filename should not contain any characters that are considered invalid for filenames, such as -( $ ), ( / ), ( < ), ( > ), ( : ), ( " ), ( | ), ( ? ), ( * ).

-

3. Prevent path traversal - The filename should not contain any characters that can be used to traverse directories, such as ( ../ ).

-

If one of these checks fails, the filename will be rejected.

-:end -
- -
-_(Invalid characters to block)_: -: '> - -
-:mover_tune_invalidfilechars_plug: -

The filename characters such as: - $ - / - < - > - : - " - | - ? - *. -

-:end -
-
- _(Log Mover Tuning plugin actions)_: :