Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if ($var['shareCacheEnabled']!='yes') {
} elseif ($var['shareUser']=='-') {
echo "<p class='notice'>User shares not enabled!</p>";
}
$vars = @parse_ini_file("/var/local/emhttp/var.ini");
$plugin = 'ca.mover.tuning';
$config_file = '/boot/config/plugins/' . $plugin . '/' . $plugin . '.cfg';
$config_default_file = '/usr/local/emhttp/plugins/' . $plugin . '/default.cfg';
Expand Down Expand Up @@ -49,9 +50,10 @@ $.fn.toggleAttr = function(attr) {

function updateCron() {
var cron = $("#cronSchedule").val();
var tune_cron = $("#tune_cronSchedule").val();
var cronEnabled = $("#forceCron").val();
var ismoverDisabled = $("#moverDisabled").val();
$.post("/plugins/ca.mover.tuning/updateCron.php",{cronEnabled:cronEnabled,cron:cron,ismoverDisabled:ismoverDisabled});
$.post("/plugins/ca.mover.tuning/updateCron.php",{cronEnabled:cronEnabled,cron:cron,tune_cron:tune_cron,ismoverDisabled:ismoverDisabled});
}

function moveNow() {
Expand Down Expand Up @@ -147,6 +149,16 @@ _(Disable Mover running on a schedule)_:
:end

<div markdown="1" id="moverTuningSettings">
<?php if (version_compare($vars['version'], '7.2.1', '>=')): ?>
_(Mover Tuning schedule)_:
: <input type='text' id='tune_cronSchedule' name='cron' size='1' class='tune_mycron' placeholder='0 */4 * * *' value='<?=htmlspecialchars($cfg['moverTuneCron'])?>'>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The new input field for "Mover Tuning schedule" has name='cron', which is the same as the name attribute of the existing input field for "Cron Schedule to force move all of files" on line 336. Using the same name for multiple form inputs can cause unpredictable behavior, potentially resulting in only one of the values being saved upon form submission. To prevent this conflict, the name attribute should be unique. Given that the value is loaded from $cfg['moverTuneCron'], the name should likely be moverTuneCron.

: <input type='text' id='tune_cronSchedule' name='moverTuneCron' size='1' class='tune_mycron' placeholder='0 */4 * * *' value='<?=htmlspecialchars($cfg['moverTuneCron'])?>'>


<blockquote class="inline_help">
<p>Runs the <strong><code>age_mover</code></strong> schedule from the Mover Tuning plugin using your custom cron entry (includes all plugin filters).</p>
<p> Cron Schedule entry example <strong>0 */4 * * *</strong>.&nbsp; To run at <em>every</em><strong> 4 hours</strong>.&nbsp; <a href="https://crontab.guru/" target="_blank" rel="noopener noreferrer"><i class="fa fa-clock-o"></i> What Is Cron</a></p>
</blockquote>
<?php endif; ?>

_(Test Mode (dry run))_:
: <select name='testmode' size='1' id='testmode' onchange="toggleTestModeWarning(this.value)">
<?=mk_option($cfg['testmode'],"no",_('No'))?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ sparsnessv="1"
filetypesv=""
omoverthresh=""
cron=""
moverTuneCron=""
forceParity="no"
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@
if ($cfg['movenow'] == "yes") {
$mover_str = "/usr/local/emhttp/plugins/ca.mover.tuning/age_mover";
} else {
$mover_str = "/usr/local/sbin/mover.old";
if (version_compare($vars['version'], '7.2.1', '<')) {

Check warning on line 93 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/mover.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/mover.php#L93

Implicit true comparisons prohibited; use === TRUE instead
$mover_str = "/usr/local/sbin/mover.old";
} else {
$mover_str = "/usr/local/sbin/mover";
}
}

if ($options == "stop") {
Expand All @@ -117,13 +121,18 @@
//Default "move now" button has been hit.
$niceLevel = $cfg['moverNice'] ?: "0";
$ioLevel = $cfg['moverIO'] ?: "-c 2 -n 0";
if (version_compare($vars['version'], '7.2.1', '<')) {
logger("ionice $ioLevel nice -n $niceLevel /usr/local/sbin/mover.old $options");
passthru("ionice $ioLevel nice -n $niceLevel /usr/local/sbin/mover.old $options");
} else {
logger("ionice $ioLevel nice -n $niceLevel /usr/local/sbin/mover $options");
passthru("ionice $ioLevel nice -n $niceLevel /usr/local/sbin/mover $options");

Check failure on line 129 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/mover.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/mover.php#L129

Executing non-constant commands.

Check failure on line 129 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/mover.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/mover.php#L129

Executing non-constant commands.

Check failure on line 129 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/mover.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/mover.php#L129

System program execution function passthru() detected with dynamic parameter
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code contains duplication. The correct mover binary path is already determined and stored in the $mover_str variable on lines 90-98. Instead of repeating the version_compare logic, you can reuse $mover_str. This will make the code more maintainable and reduce redundancy.

        logger("ionice $ioLevel nice -n $niceLevel $mover_str $options");
        passthru("ionice $ioLevel nice -n $niceLevel $mover_str $options");

}
}

if ($cron && $cfg['moverDisabled'] == 'yes') {
logger("Mover schedule disabled");
logger("Mover Tuning schedule disabled");
exit();
}

Expand All @@ -132,7 +141,7 @@
exit();
}

logger("Starting Mover ...");
logger("Starting Mover Tuning ...");

startMover();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
require_once("/usr/local/emhttp/plugins/dynamix/include/Wrappers.php");

$cfg = parse_plugin_cfg("ca.mover.tuning");
$vars = @parse_ini_file("/var/local/emhttp/var.ini");

Check warning on line 6 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L6

The use of function parse_ini_file() is discouraged

// Get config value of forced cron
$cfg_cronEnabled = $cfg['force'];
// Get cron time of forced cron (normalized)
$cfg_cron = trim($cfg['cron'] ?? '');
// Get config value of mover disabled
$cfg_moverDisabled = $cfg['moverDisabled'];
// Get Mover Tuning cron time (normalized)
$cfg_moverTuneCron = trim($cfg['moverTuneCron'] ?? $vars['shareMoverSchedule'] ?? '');

function logger($string)
{
Expand All @@ -20,9 +23,26 @@
}
}

function make_tune_cron()
{
global $vars;
if (!empty($var['shareMoverSchedule'])) {

Check warning on line 29 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L29

Avoid using undefined variables such as '$var' which will lead to PHP notices.

Check warning on line 29 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L29

Operator ! prohibited; use === FALSE instead

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

There is a typo in the variable name. It should be $vars instead of $var. Due to this typo, the condition !empty($var['shareMoverSchedule']) will likely not evaluate as intended, and the Unraid mover schedule may not be disabled correctly.

	if (!empty($vars['shareMoverSchedule'])) {

// Disable Unraid mover
$vars['shareMoverSchedule'] = "";
}

$cronTuneFile = "# Generated schedule for Mover Tuning move\n" . trim($_POST['tune_cron']) . " /usr/local/emhttp/plugins/ca.mover.tuning/age_mover start |& logger -t move\n\n";

Check failure on line 34 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L34

Detected usage of a possibly undefined superglobal array index: $_POST['tune_cron']. Use isset() or empty() to check the index exists before using it

Check warning on line 34 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L34

Direct use of $_POST Superglobal detected.

Check failure on line 34 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L34

Processing form data without nonce verification.
file_put_contents("/boot/config/plugins/ca.mover.tuning/mover.tune.cron", $cronTuneFile);

Check warning on line 35 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L35

The use of function file_put_contents() is discouraged
}

function make_cron()
{
$cronFile = "# Generated schedule for forced move\n" . trim($_POST['cron']) . " /usr/local/sbin/mover.old start |& logger -t move\n\n";
global $vars;
if (version_compare($vars['version'], '7.2.1', '<')) {

Check warning on line 41 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L41

Implicit true comparisons prohibited; use === TRUE instead
$cronFile = "# Generated schedule for forced move\n" . trim($_POST['cron']) . " /usr/local/sbin/mover.old start |& logger -t move\n\n";
} else {
$cronFile = "# Generated schedule for forced move\n" . trim($_POST['cron']) . " /usr/local/sbin/mover start |& logger -t move\n\n";

Check failure on line 44 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L44

Detected usage of a possibly undefined superglobal array index: $_POST['cron']. Use isset() or empty() to check the index exists before using it

Check warning on line 44 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L44

Direct use of $_POST Superglobal detected.

Check failure on line 44 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L44

Processing form data without nonce verification.
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The code for generating the cron file content is duplicated within the if/else block. You can determine the mover binary path first based on the version, and then construct the $cronFile string once. This will make the code cleaner and easier to maintain.

		$mover_binary = version_compare($vars['version'], '7.2.1', '<') ? '/usr/local/sbin/mover.old' : '/usr/local/sbin/mover';
		$cronFile = "# Generated schedule for forced move\n" . trim($_POST['cron']) . " $mover_binary start |& logger -t move\n\n";

file_put_contents("/boot/config/plugins/ca.mover.tuning/mover.cron", $cronFile);
}

Expand Down Expand Up @@ -63,5 +83,17 @@
}
}

// Handle Mover Tuning custom cron schedule
if ($cfg_moverTuneCron != $_POST['tune_cron']) {

Check failure on line 87 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L87

Detected usage of a possibly undefined superglobal array index: $_POST['tune_cron']. Use isset() or empty() to check the index exists before using it

Check warning on line 87 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L87

Direct use of $_POST Superglobal detected.

Check warning on line 87 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L87

Operator != prohibited; use !== instead

Check failure on line 87 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L87

Processing form data without nonce verification.

if (trim($_POST['tune_cron']) != "") {

Check failure on line 89 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L89

Detected usage of a possibly undefined superglobal array index: $_POST['tune_cron']. Use isset() or empty() to check the index exists before using it

Check warning on line 89 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L89

Direct use of $_POST Superglobal detected.

Check warning on line 89 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L89

Operator != prohibited; use !== instead

Check failure on line 89 in source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php#L89

Processing form data without nonce verification.
make_tune_cron();
logger("Mover Tuning cron schedule updated successfully.");
} else {
@unlink("/boot/config/plugins/ca.mover.tuning/mover.tune.cron");
logger("Mover Tuning cron schedule removed.");
}
}

exec("update_cron");
?>