if ($PWM_MODE != 1) { $DEFAULT_PWM_MODE = $PWM_MODE; file_put_contents("{$PWM_CONTROLLER}_enable", 1); } # Calculate size of increments. $TEMP_INCREMENTS = $TEMP_HIGH - $TEMP_LOW; $PWM_INCREMENTS = round(($PWM_HIGH - $PWM_LOW) / $TEMP_INCREMENTS); # Get current fan rpm and pwm $CURRENT_PWM = preg_replace("/\\s*/", "", file_get_contents($PWM_CONTROLLER)); $CURRENT_RPM = preg_replace("/\\s*/", "", file_get_contents($PWM_FAN)); # Get current fan PWM percentage $CURRENT_PERCENT_PWM = round($CURRENT_PWM * 100 / $PWM_HIGH); $CURRENT_OUTPUT = "{$CURRENT_PWM} ({$CURRENT_PERCENT_PWM}% @ {$CURRENT_RPM}rpm)"; # Calculate a new scenario # Get highest drive temperature $HIGHEST_TEMP = get_highest_temp($hdds); if ($HIGHEST_TEMP <= $TEMP_LOW) { $NEW_PWM = $PWM_OFF; $NEW_PERCENT_PWM = 0; } else { if ($HIGHEST_TEMP >= $TEMP_HIGH) { $NEW_PWM = $PWM_HIGH; $NEW_PERCENT_PWM = 100; } else { $NEW_PWM = ($HIGHEST_TEMP - $TEMP_LOW) * $PWM_INCREMENTS + $PWM_LOW; $NEW_PERCENT_PWM = round($NEW_PWM * 100 / $PWM_HIGH); } } # Change the fan speed as needed if ($CURRENT_PWM != $NEW_PWM) { file_put_contents($PWM_CONTROLLER, $NEW_PWM);
<?php require_once '/usr/local/emhttp/plugins/ipmi/include/ipmi_options.php'; require_once '/usr/local/emhttp/plugins/ipmi/include/fan_helpers.php'; $action = array_key_exists('action', $_GET) ? $_GET['action'] : ''; $hdd_temp = get_highest_temp(); if (!empty($action)) { $state = ['Critical' => 'red', 'Warning' => 'yellow', 'Nominal' => 'green', 'N/A' => 'blue']; if ($action == 'ipmisensors') { $return = ['Sensors' => ipmi_sensors($ignore), 'Network' => $netsvc == 'enable', 'State' => $state]; echo json_encode($return); } elseif ($action == 'ipmievents') { $return = ['Events' => ipmi_events(), 'Network' => $netsvc == 'enable', 'State' => $state]; echo json_encode($return); } elseif ($action == 'ipmiarch') { $return = ['Archives' => ipmi_events(true), 'Network' => $netsvc == 'enable', 'State' => $state]; echo json_encode($return); } elseif ($action == 'ipmidash') { $return = ['Sensors' => ipmi_sensors($dignore), 'Network' => $netsvc == 'enable', 'State' => $state]; echo json_encode($return); } } /* get highest temp of hard drives */ function get_highest_temp() { $hdds = parse_ini_file('/var/local/emhttp/disks.ini', true); $highest_temp = 0; foreach ($hdds as $hdd) { $temp = $hdd['temp']; if (is_numeric($temp)) { $highest_temp = $temp > $highest_temp ? $temp : $highest_temp;