function sabSpeedAdjuster() { /* global $sabnzbd_ip; global $sabnzbd_port; global $sabnzbd_api; global $sabnabdSpeedLimitMax; global $sabnzbdSpeedLimitMin; // Set how high ping we want to hit before throttling global $ping_throttle; global $wan1_ip; global $wan2_ip; global $ping_ip; */ // Check the current ping $avgPing = getping($wan2_ip, $ping_ip); // Get SABnzbd XML $sabnzbdXML = simplexml_load_file('http://' . $sabnzbd_ip . ':' . $sabnzbd_port . '/api?mode=queue&start=START&limit=LIMIT&output=xml&apikey=' . $sabnzbd_api); // Get current SAB speed limit $sabSpeedLimitCurrent = $sabnzbdXML->speedlimit; // Check to see if SAB is downloading if ($sabnzbdXML->status == 'Downloading') { // If it is downloading and ping is over X value, slow it down if ($avgPing > $ping_throttle) { if ($sabSpeedLimitCurrent > $sabnzbdSpeedLimitMin) { // Reduce speed by 256KBps echo 'Ping is over ' . $ping_throttle; echo '<br>'; echo 'Slowing down SAB'; $sabSpeedLimitSet = $sabSpeedLimitCurrent - 256; shell_exec('curl "http://' . $sabnzbd_ip . ':' . $sabnzbd_port . '/api?mode=config&name=speedlimit&value=' . $sabSpeedLimitSet . '&apikey=' . $sabnzbd_api . '"'); } else { echo 'Ping is over ' . $ping_throttle . ' but SAB cannot slow down anymore'; } } elseif ($avgPing + 9 < $ping_throttle) { if ($sabSpeedLimitCurrent < $sabnabdSpeedLimitMax) { // Increase speed by 256KBps echo 'SAB is downloading and ping is ' . ($avgPing + 9) . ' so increasing download speed.'; $sabSpeedLimitSet = $sabSpeedLimitCurrent + 256; shell_exec('curl "http://' . $sabnzbd_ip . ':' . $sabnzbd_port . '/api?mode=config&name=speedlimit&value=' . $sabSpeedLimitSet . '&apikey=' . $sabnzbd_api . '"'); } else { echo 'SAB is downloading. Ping is low enough but we are at global download speed limit.'; } } else { echo 'SAB is downloading. Ping is ok but not low enough to speed up SAB.'; } } else { // do nothing, echo 'SAB is not downloading.'; } }
<!DOCTYPE html> <?php Ini_Set('display_errors', true); include '../../init.php'; include ROOT_DIR . '/assets/php/functions.php'; ?> <html lang="en"> <script> // Enable bootstrap tooltips $(function () { $("[rel=tooltip]").tooltip(); }); </script> <?php global $wan1_ip; global $wan2_ip; global $ping_ip; echo '<div class="exolight">'; echo 'WAN1 Ping: ' . getping($wan1_ip, $ping_ip) . ' ms'; echo '<br>'; echo ''; echo '<br>'; makeBandwidthBars('rl1'); echo '<br>'; echo 'WAN2 Ping: ' . getping($wan2_ip, $ping_ip) . ' ms'; echo '<br>'; echo ''; echo '<br>'; makeBandwidthBars('rl4'); echo '</div>';