Skip to content
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Configuration is done through a user-friendly interface, with custom thresholds,
- Lays the fan configurations out side by side, wrapping to the next row, so a wide screen shows several at once and a phone shows one
- Dashboard tile and system integration
- Optional FCP Airflow Dashboard tile, similar to Unraid’s built-in Airflow tile but enhanced with support for custom fan labels
- Optionally shows each fan's speed and PWM percentage in the status bar at the bottom of every Unraid page. Dynamix System Temperature shows the percentage only with Dynamix Auto Fan, which should not run alongside FanCtrlPlus. Turn it on per fan under Syslog & Alerts
- Reorder fan configurations with a button per direction, on a desktop or a phone. The new order is saved and reflected in both the UI and Dashboard.

---
Expand Down
11 changes: 9 additions & 2 deletions src/usr/local/emhttp/plugins/fanctrlplus2/Fanctrl2Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
exit;
}

foreach (glob("$cfg_path/{$plugin}_*.cfg") as $file) {
// The settings page's order, so the footer lists fans the same way.
require_once __DIR__.'/include/OrderManager.php';
$rank = array_flip(OrderManager::readOrder());
$files = glob("$cfg_path/{$plugin}_*.cfg") ?: [];
usort($files, fn($a, $b) => ($rank[basename($a)] ?? PHP_INT_MAX) <=> ($rank[basename($b)] ?? PHP_INT_MAX));

foreach ($files as $file) {
$cfg = parse_ini_file($file);
$custom = $cfg['custom'] ?? basename($file, '.cfg');
$label = $custom;
Expand Down Expand Up @@ -64,7 +70,8 @@
'temp_origin' => $temp_origin,
'rpm_val' => $rpm_val,
'percent' => $pct_val,
'status' => $status
'status' => $status,
'footer' => ($cfg['footer'] ?? '0') !== '0'
];
}

Expand Down
46 changes: 46 additions & 0 deletions src/usr/local/emhttp/plugins/fanctrlplus2/FanctrlPlus2Footer.page
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Menu="Buttons"
Link="nav-user"
---
<?php
// Show the speed and PWM of each fan whose Footer switch is on in the status
// bar at the bottom of every page, like Dynamix System Temperature does (#45).
// Pages load the script only while at least one fan has the switch on.
$fcp_footer = false;
foreach (glob('/boot/config/plugins/fanctrlplus2/fanctrlplus2_*.cfg') ?: [] as $fcp_footer_cfg) {
if (((@parse_ini_file($fcp_footer_cfg) ?: [])['footer'] ?? '0') !== '0') {
$fcp_footer = true;
break;
}
}
?>
<?if ($fcp_footer):?>
<script>
$(function fcpFooter() {
var shown = true;
$.getJSON('/plugins/fanctrlplus2/Fanctrl2Dashboard.php', function(data) {
var $footer = $("<span id='fcp-footer' style='margin-right:24px'></span>");
var fans = (data.fans || []).filter(function(f) { return f.footer; });
shown = fans.length > 0;
fans.forEach(function(f) {
var rpm = /^\d+$/.test(f.rpm_val) ? f.rpm_val : '⋅⋅⋅';
var pct = typeof f.percent === 'number' ? ' (' + f.percent + '%)' : '';
$('<span>').attr('title', f.label)
.append("<i class='fa fa-flag-o' style='margin:0 6px 0 24px'></i>", document.createTextNode(rpm + ' rpm' + pct))
.appendTo($footer);
});
// showFooter() removes and prepends, so entries that other plugins also
// refresh with it would keep swapping places. Prepend once, then update in place.
var $old = $('#fcp-footer');
if (!shown) $old.remove();
else if ($old.length) $old.replaceWith($footer);
else showFooter($footer, 'fcp-footer');
}).fail(function() {
// No reading: show nothing rather than old values as if they were live.
$('#fcp-footer').remove();
}).always(function() {
// Every Footer switch turned off: stop polling until the next page load.
if (shown) setTimeout(fcpFooter, 5000);
});
});
</script>
<?endif;?>
2 changes: 1 addition & 1 deletion src/usr/local/emhttp/plugins/fanctrlplus2/css/fcp.base.css
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ dt.containerSettingsDt {

.fcp-airflow-switch{ display: none; }
.fcp-history-switch{ display: none; }
.syslog-switch, .notify-switch{ display: none; }
.syslog-switch, .notify-switch, .footer-switch{ display: none; }
.switch-button-label{ font-size: 12px; }
.switch-button-label.on{ display: none; }
.switch-button-background.checked ~ .switch-button-label.on{ display: inline; }
Expand Down
15 changes: 9 additions & 6 deletions src/usr/local/emhttp/plugins/fanctrlplus2/fanctrlplus2.page
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,9 @@ $(function() {
$area.find('.switch-button-button').css('left', checked ? '12px' : '-1px');

// Persist the relevant switch.
if ($input.hasClass('syslog-switch') || $input.hasClass('notify-switch')) {
saveFanSwitchState($input.hasClass('syslog-switch') ? 'setsyslog' : 'setnotify', $input.data('cfg'), checked);
var fanKey = ['syslog', 'notify', 'footer'].find(function(k) { return $input.hasClass(k + '-switch'); });
if (fanKey) {
saveFanSwitchState('set' + fanKey, $input.data('cfg'), checked);
} else if ($input.hasClass('fcp-airflow-switch')) {
saveAirflowSwitchState(checked);
} else if ($input.hasClass('fcp-history-switch')) {
Expand All @@ -1292,7 +1293,7 @@ $(function() {
});

// Shared change handler for the per-fan and FCP Airflow/History switches.
$(document).on('change', '.syslog-switch, .notify-switch, .fcp-airflow-switch, .fcp-history-switch', function() {
$(document).on('change', '.syslog-switch, .notify-switch, .footer-switch, .fcp-airflow-switch, .fcp-history-switch', function() {
var checked = $(this).prop('checked');
var $area = $(this).closest('.switch-area');

Expand Down Expand Up @@ -1841,7 +1842,7 @@ $(function() {

<p><strong>Identify PWM Controller:</strong> Use this tool to help locate which physical fan is linked to each PWM controller. After identification, adding a custom label makes it easier to recognize and configure later.</p>

<p><strong>Syslog &amp; Alerts:</strong> Enable or disable syslog logging for each fan individually. When enabled, changes in temperature and fan speed will be recorded in the system log. If a fan setup is already stable or updates too frequently, you can turn off its logging to reduce clutter. Problem alerts send Unraid notifications when a fan has a problem; turn them off for a fan whose controller raises false alarms.</p>
<p><strong>Syslog &amp; Alerts:</strong> Enable or disable syslog logging for each fan individually. When enabled, changes in temperature and fan speed will be recorded in the system log. If a fan setup is already stable or updates too frequently, you can turn off its logging to reduce clutter. Problem alerts send Unraid notifications when a fan has a problem; turn them off for a fan whose controller raises false alarms. Footer shows the fan's speed and PWM percentage in the status bar at the bottom of every page; it is off by default.</p>

<p><strong>Notes:</strong></p>
<ul>
Expand Down Expand Up @@ -2075,6 +2076,7 @@ $(function() {
<p>This helps you track fan behavior in real time. However, if a particular fan changes frequently and generates too many log entries, you can <strong>disable logging</strong> for that fan.</p>
<p><strong>Note:</strong> The plugin only writes to syslog when the <strong>PWM value changes by more than 5</strong> compared to the previous value — small changes are ignored to reduce log noise.</p>
<p><strong>Problem Alerts</strong> are also <strong>enabled by default</strong>. Fan control keeps running either way; the alerts only send Unraid notifications. A fan gets one warning when, for at least 30 seconds, its PWM controller has disappeared, the BIOS or another program has taken it over, its controller reports a speed 10 or more percentage points away from the one set, or it reports 0 RPM while set above 40% after spinning earlier. A fan whose controller is missing when fan control starts, and a configured sensor without a reading for 60 seconds, also warn. Once the problem has stayed away for 30 seconds, a notice says so. Turn the alerts off for a fan whose controller raises false alarms, such as one with only a few speed steps.</p>
<p><strong>Footer</strong> is <strong>disabled by default</strong>. When on, the fan's speed and PWM percentage appear in the status bar at the bottom of every Unraid page, for example <code>1539 rpm (63%)</code>. Hover over a value to see the fan's name. A change shows from the next page load.</p>
<p>When RPM has changed in the requested direction at least 30 seconds after a substantial speed change, a PWM mismatch warning includes that observation. It suggests that the fan may have responded despite the reported PWM; it does not prove which controller changed the fan.</p>
</blockquote>
</div>
Expand All @@ -2087,6 +2089,7 @@ $(function() {
<th class="name">Configured Fan</th>
<th class="switch">Syslog</th>
<th class="switch">Problem Alerts</th>
<th class="switch" title="Display on footer">Footer</th>
</tr>
</thead>
<tbody>
Expand All @@ -2100,8 +2103,8 @@ $(function() {
?>
<tr class="sortable" id="syslog-row-<?= $custom_id ?>">
<td class="name"><?= htmlspecialchars($cfg['custom']) ?></td>
<?php foreach (['syslog', 'notify'] as $switch):
$is_on = ($cfg[$switch] ?? "1") != "0";
<?php foreach (['syslog' => '1', 'notify' => '1', 'footer' => '0'] as $switch => $default):
$is_on = ($cfg[$switch] ?? $default) != "0";
$switch_id = "$switch-switch-" . htmlspecialchars($cfg['custom']);
?>
<td class="switch">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function fcp_backup_assignments(string $text): array {

function fcp_validate_fan_config(string $text): array {
$values = fcp_backup_assignments($text);
$boolean = ['service','syslog','notify','log_enable','cpu_enable','aux_enable'];
$boolean = ['service','syslog','notify','footer','log_enable','cpu_enable','aux_enable'];
$numeric = ['pwm','max','idle','idle_percent','low','high','interval','interval_sec','disk_group_count','cpu_min_temp','cpu_max_temp','aux_min_temp','aux_max_temp'];
$string = ['custom','label','controller','controller_identity','fan','disks','cpu_sensor','aux_sensor'];
foreach ($values as $key=>$value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Numeric cfg settings that may be reported, with the range each may take.
const FCP_DIAG_SETTINGS = [
'service'=>[0,1], 'syslog'=>[0,1], 'notify'=>[0,1], 'log_enable'=>[0,1], 'cpu_enable'=>[0,1], 'aux_enable'=>[0,1],
'service'=>[0,1], 'syslog'=>[0,1], 'notify'=>[0,1], 'footer'=>[0,1], 'log_enable'=>[0,1], 'cpu_enable'=>[0,1], 'aux_enable'=>[0,1],
'pwm'=>[0,255], 'max'=>[0,255], 'idle'=>[0,255], 'idle_percent'=>[0,100],
'low'=>[-100,300], 'high'=>[-100,300], 'cpu_min_temp'=>[-100,300], 'cpu_max_temp'=>[-100,300],
'aux_min_temp'=>[-100,300], 'aux_max_temp'=>[-100,300],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$op = $_GET['op'] ?? $_POST['op'] ?? '';

// Serialize restore/export with every HTTP writer of these configuration files.
if (in_array($op, ['savelabel','newtemp','delete','setsyslog','setnotify','saveorder','start','stop','fcp_airflow_toggle','fcp_history_toggle'], true)) {
if (in_array($op, ['savelabel','newtemp','delete','setsyslog','setnotify','setfooter','saveorder','start','stop','fcp_airflow_toggle','fcp_history_toggle'], true)) {
try { $config_lock = fcp_config_lock($cfg_dir); }
catch (Throwable $error) { http_response_code(500); json_response(['status'=>'error','message'=>$error->getMessage()]); }
register_shutdown_function(function () use ($config_lock) {
Expand Down Expand Up @@ -271,10 +271,12 @@ function () use ($service, &$was_running) { if ($was_running) $service('start');
echo render_disk_group_row($fan_index, $group_index, $empty_group, $disks);
exit;

// Per-fan switches: Syslog, and Problem Alerts (read by the loop on each alert).
// Per-fan switches: Syslog, Problem Alerts (read by the loop on each alert),
// and Footer (read by FanctrlPlus2Footer.page).
case 'setsyslog':
case 'setnotify':
$key = $op === 'setsyslog' ? 'syslog' : 'notify';
case 'setfooter':
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
$key = substr($op, 3);
$cfg_file = basename($_POST['cfg']);
$enabled = isset($_POST['enabled']) && $_POST['enabled'] == 1 ? 1 : 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,11 @@
'interval' => (string)max(1, (int)ceil($interval_seconds / 60)),
'disks' => $legacy_disks,
'disk_group_count' => (string)$disk_group_count,
// Per-fan switches set outside this form: keep them, both default on.
// Per-fan switches set outside this form: keep them. Syslog and alerts
// default on, the footer off.
'syslog' => (string)($previous['syslog'] ?? '1'),
'notify' => (string)($previous['notify'] ?? '1'),
'footer' => (string)($previous['footer'] ?? '0'),
'cpu_enable' => $cpu_enable,
'cpu_sensor' => $cpu_sensor,
'cpu_min_temp' => $legacy['cpu_min_temp'],
Expand Down
4 changes: 4 additions & 0 deletions tests/curve_config_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@
$check(($saved['cpu_sensor'] ?? '') === $cpuPath && ($saved['aux_sensor'] ?? '') === 'storcli:c0:roc', 'Disabled sources must keep their saved sensors.');
$saved = $bindingSave(['aux_sensor' => 'storcli:c0:roc'], function (&$post) { $post['aux_enable'][0] = '1'; });
$check(($saved['aux_sensor'] ?? null) === '', 'An enabled aux source with nothing selected must save no sensor.');
$saved = $bindingSave(['footer' => '1'], function (&$post) {});
$check(($saved['footer'] ?? '') === '1', 'Saving must keep the Footer switch, which is set outside the form.');
$saved = $bindingSave([], function (&$post) {});
$check(($saved['footer'] ?? '') === '0', 'The Footer switch must default to off.');
$write('fanctrlplus2_Raw.cfg', $rawLegacy);

$write('fanctrlplus2_JBOD.cfg', $legacyFan);
Expand Down
5 changes: 3 additions & 2 deletions tests/diagnostics_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
disk_group_0_emergency_pwm="255"
syslog="1"
notify="1"
footer="1"
cpu_enable="1"
cpu_sensor="/sys/devices/platform/coretemp.0/hwmon/hwmon2/temp1_input"
cpu_curve="40:80,70:200"
Expand Down Expand Up @@ -165,8 +166,8 @@
$check(count($fans['fans']) === 3 && $fans['custom_sensor_scripts'] === 2 && $fans['skipped_configs'] === 2, 'Badly named files must not prevent diagnostics and must be counted.');
[$broken, $legacy, $secret] = $fans['fans'];
$check($broken === ['index'=>0, 'parsed'=>false], 'A configuration that fails to parse must be reported as unparsed and nothing else.');
$check($same(array_intersect_key($secret, array_flip(['service','pwm','max','idle','interval_sec','disk_group_count','syslog','notify','cpu_enable','aux_enable'])),
['service'=>1, 'pwm'=>102, 'max'=>255, 'idle'=>30, 'interval_sec'=>60, 'disk_group_count'=>1, 'syslog'=>1, 'notify'=>1, 'cpu_enable'=>1, 'aux_enable'=>1]), 'Numeric fan settings must be reported.');
$check($same(array_intersect_key($secret, array_flip(['service','pwm','max','idle','interval_sec','disk_group_count','syslog','notify','footer','cpu_enable','aux_enable'])),
['service'=>1, 'pwm'=>102, 'max'=>255, 'idle'=>30, 'interval_sec'=>60, 'disk_group_count'=>1, 'syslog'=>1, 'notify'=>1, 'footer'=>1, 'cpu_enable'=>1, 'aux_enable'=>1]), 'Numeric fan settings must be reported.');
$check($secret['disk_groups'] === [['disks'=>2]] && !array_key_exists('disks', $secret), 'Disks are counted per group, never identified.');
$check($secret['cpu_sensor_configured'] === true
&& $secret['aux_sensors'] === ['hwmon'=>1, 'custom'=>2, 'storcli'=>0, 'nvidia'=>1, 'mlx'=>0, 'other'=>0]
Expand Down
23 changes: 23 additions & 0 deletions tests/settings_layout_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@
$failures[] = 'The raw History checkbox must be hidden (slider is the visible control).';
}

// The per-fan Footer switch (#45): off by default, saved by its own op, and
// read by the footer page and the endpoint it polls.
if (!str_contains($page, "'footer' => '0'") || !str_contains($page, "['syslog', 'notify', 'footer'].find(")) {
$failures[] = 'The Footer switch must default to off and save through its own op.';
}
$logic = file_get_contents($sourceRoot . '/include/FanctrlLogic.php');
if (!preg_match("/case 'setfooter':\s*\\\$key = substr\(\\\$op, 3\);/", $logic)) {
$failures[] = 'FanctrlLogic.php must save the Footer switch under the footer key.';
}
if (!str_contains($logic, "'setnotify','setfooter','saveorder'")) {
$failures[] = 'setfooter must hold the configuration lock, like the other switches.';
}
$footerPage = file_get_contents($sourceRoot . '/FanctrlPlus2Footer.page');
$endpoint = file_get_contents($sourceRoot . '/Fanctrl2Dashboard.php');
if (!str_contains($footerPage, 'Menu="Buttons"') || !str_contains($footerPage, "showFooter(\$footer, 'fcp-footer')")
|| !str_contains($endpoint, "'footer' => (\$cfg['footer'] ?? '0') !== '0'")) {
$failures[] = 'The footer page must show the fans the endpoint flags with their Footer switch on.';
}
// showFooter() re-prepends; calling it on every poll swaps places with other footer entries.
if (!str_contains($footerPage, 'else if ($old.length) $old.replaceWith($footer);')) {
$failures[] = 'The footer entry must be updated in place after it is first shown.';
}

if ($failures) {
fwrite(STDERR, implode("\n", $failures) . "\n");
exit(1);
Expand Down
Loading