#!/usr/local/bin/php . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ require("guiconfig.inc"); /* redirect to wizard if shaper isn't already configured */ if(isset($config['shaper']['enable'])) { $pconfig['enable'] = TRUE; } else { if(!is_array($config['shaper']['queue'])) Header("Location: wizard.php?xml=traffic_shaper_wizard.xml"); } if (!is_array($config['shaper']['rule'])) { $config['shaper']['rule'] = array(); } if (!is_array($config['shaper']['queue'])) { $config['shaper']['queue'] = array(); } $a_shaper = &$config['shaper']['rule']; $a_queue = &$config['shaper']['queue']; function wipe_magic () { global $config; /* wipe previous */ unset($config['shaper']['queue']); unset($config['shaper']['rule']); $config['shaper']['enable'] = FALSE; filter_configure(); } if ($_POST['remove']) { wipe_magic(); $savemsg = '

Note: The traffic shaper has been disabled.
'; touch($d_shaperconfdirty_path); unset($config['shaper']['enable']); write_config(); Header("Location: index.php"); exit; } if ($_POST) { if ($_POST['submit']) { $pconfig = $_POST; $config['shaper']['enable'] = $_POST['enable'] ? true : false; write_config(); } if ($_POST['apply'] || $_POST['submit']) { $config['shaper']['enable'] = $_POST['enable'] ? true : false; write_config(); $retval = 0; $savemsg = get_std_save_message($retval); /* Setup pf rules since the user may have changed the optimization value */ config_lock(); $retval = filter_configure(); config_unlock(); if(stristr($retval, "error") <> true) $savemsg = get_std_save_message($retval); else $savemsg = $retval; if(file_exists($d_shaperconfdirty_path)) unlink($d_shaperconfdirty_path); } } if (isset($_POST['del_x'])) { /* delete selected rules */ if (is_array($_POST['rule']) && count($_POST['rule'])) { foreach ($_POST['rule'] as $rulei) { unset($a_shaper[$rulei]); } write_config(); touch($d_natconfdirty_path); header("Location: firewall_shaper.php"); exit; } } if ($_GET['act'] == "down") { if ($a_shaper[$_GET['id']] && $a_shaper[$_GET['id']+1]) { $tmp = $a_shaper[$_GET['id']+1]; $a_shaper[$_GET['id']+1] = $a_shaper[$_GET['id']]; $a_shaper[$_GET['id']] = $tmp; write_config(); touch($d_shaperconfdirty_path); header("Location: firewall_shaper.php"); exit; } } else if ($_GET['act'] == "up") { if (($_GET['id'] > 0) && $a_shaper[$_GET['id']]) { $tmp = $a_shaper[$_GET['id']-1]; $a_shaper[$_GET['id']-1] = $a_shaper[$_GET['id']]; $a_shaper[$_GET['id']] = $tmp; write_config(); touch($d_shaperconfdirty_path); header("Location: firewall_shaper.php"); exit; } } else if ($_GET['act'] == "toggle") { if ($a_shaper[$_GET['id']]) { $a_shaper[$_GET['id']]['disabled'] = !isset($a_shaper[$_GET['id']]['disabled']); write_config(); touch($d_shaperconfdirty_path); header("Location: firewall_shaper.php"); exit; } } else { /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to fine move button clicks instead... */ unset($movebtn); foreach ($_POST as $pn => $pd) { if (preg_match("/move_(\d+)_x/", $pn, $matches)) { $movebtn = $matches[1]; break; } } /* move selected rules before this rule */ if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) { $a_shaper_new = array(); /* copy all rules < $movebtn and not selected */ for ($i = 0; $i < $movebtn; $i++) { if (!in_array($i, $_POST['rule'])) $a_shaper_new[] = $a_shaper[$i]; } /* copy all selected rules */ for ($i = 0; $i < count($a_shaper); $i++) { if ($i == $movebtn) continue; if (in_array($i, $_POST['rule'])) $a_shaper_new[] = $a_shaper[$i]; } /* copy $movebtn rule */ if ($movebtn < count($a_shaper)) $a_shaper_new[] = $a_shaper[$movebtn]; /* copy all rules > $movebtn and not selected */ for ($i = $movebtn+1; $i < count($a_shaper); $i++) { if (!in_array($i, $_POST['rule'])) $a_shaper_new[] = $a_shaper[$i]; } $a_shaper = $a_shaper_new; write_config(); touch($d_shaperconfdirty_path); header("Location: firewall_shaper.php"); exit; } } $pgtitle = "Firewall: Shaper: Rules"; include("head.inc"); ?>

You must apply the changes in order for them to take effect.");?>

> Enable traffic shaper

    If Proto Source Destination Target Description
"; $textse = ""; } else { $textss = $textse = ""; } $iflabels = array('lan' => 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP'); for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) $iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr']; echo $textss . htmlspecialchars($iflabels[$shaperent['interface']]); echo "
"; echo ""; if ($shaperent['direction'] == "in") echo ""; if ($shaperent['direction'] == "out") echo ""; echo "" . $textse;; ?>

Port:

Port:
{$desc}"; $desc = htmlspecialchars($shaperent['inqueue']); echo "/{$desc}"; } ?>   0): ?>

Note:
The last rule that matches a packet will be executed.
The following match patterns are not shown in the list above: IP packet length, TCP flags.
You can check the results of your queues at Status:Queues.