diff --git a/etc/inc/m0n0/shaper.inc b/etc/inc/m0n0/shaper.inc deleted file mode 100644 index 807d4e62e2..0000000000 --- a/etc/inc/m0n0/shaper.inc +++ /dev/null @@ -1,411 +0,0 @@ -. - 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. -*/ - -/* include all configuration functions */ -require_once("functions.inc"); - -function shaper_configure() { - global $config, $g; - - if (isset($config['shaper']['enable'])) { - - if ($g['booting']) - echo "Starting traffic shaper... "; - - /* generate shaper rules */ - $shaperrules = shaper_rules_generate(); - - /* make sure ipfw and dummynet are loaded */ - mwexec("/sbin/kldload ipfw"); - mwexec("/sbin/kldload dummynet"); - - /* change one_pass to 1 so ipfw stops checking after - a rule has matched */ - mwexec("/sbin/sysctl net.inet.ip.fw.one_pass=1"); - - /* load shaper rules */ - mwexec("/sbin/ipfw -f delete set 4"); - mwexec("/sbin/ipfw -f pipe flush"); - - /* XXX - seems like ipfw cannot accept rules directly on stdin, - so we have to write them to a temporary file first */ - $fd = fopen("{$g['tmp_path']}/ipfw.rules", "w"); - if (!$fd) { - printf("Cannot open ipfw.rules in shaper_configure()\n"); - return 1; - } - - fwrite($fd, $shaperrules); - fclose($fd); - - mwexec("/sbin/ipfw {$g['tmp_path']}/ipfw.rules"); - - unlink("{$g['tmp_path']}/ipfw.rules"); - - /* make sure bridged packets are shaped as well */ - mwexec("/sbin/sysctl net.link.ether.bridge_ipfw=1"); - - if ($g['booting']) - echo "done\n"; - - } else { - mwexec("/sbin/sysctl net.link.ether.bridge_ipfw=0"); - if (!isset($config['captiveportal']['enable'])) { - /* unload ipfw and dummynet */ - mwexec("/sbin/kldunload dummynet"); - mwexec("/sbin/kldunload ipfw"); - } else { - /* captive portal is on - just remove our rules */ - mwexec("/sbin/ipfw -f delete set 4"); - mwexec("/sbin/ipfw -f pipe flush"); - } - } - - return 0; -} - -function shaper_rules_generate() { - global $config, $g; - - $wancfg = $config['interfaces']['wan']; - $lancfg = $config['interfaces']['lan']; - $pptpdcfg = $config['pptpd']; - - $lanif = $lancfg['if']; - $wanif = get_real_wan_interface(); - - $lanip = $lancfg['ipaddr']; - $lansa = gen_subnet($lancfg['ipaddr'], $lancfg['subnet']); - $lansn = $lancfg['subnet']; - - /* optional interfaces */ - $optcfg = array(); - - for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) { - $oc = $config['interfaces']['opt' . $i]; - - if (isset($oc['enable']) && $oc['if']) { - $oic = array(); - $oic['ip'] = $oc['ipaddr']; - $oic['if'] = $oc['if']; - $oic['sa'] = gen_subnet($oc['ipaddr'], $oc['subnet']); - $oic['sn'] = $oc['subnet']; - - $optcfg['opt' . $i] = $oic; - } - } - - if ($pptpdcfg['mode'] == "server") { - $pptpip = $pptpdcfg['localip']; - $pptpsa = $pptpdcfg['remoteip']; - $pptpsn = $g['pptp_subnet']; - } - - $rulei = 50000; - - /* add a rule to pass all traffic from/to the firewall, - so the user cannot lock himself out of the webConfigurator */ - $shaperrules = "add $rulei set 4 pass all from $lanip to any\n"; $rulei++; - $shaperrules .= "add $rulei set 4 pass all from any to $lanip\n"; $rulei++; - - /* generate rules */ - if (isset($config['shaper']['rule'])) - foreach ($config['shaper']['rule'] as $rule) { - - /* don't include disabled rules */ - if (isset($rule['disabled'])) { - $i++; - continue; - } - - /* does the rule deal with a PPTP interface? */ - if ($rule['interface'] == "pptp") { - - if ($pptpdcfg['mode'] != "server") { - $i++; - continue; - } - - $nif = $g['n_pptp_units']; - $ispptp = true; - } else { - - if (strstr($rule['interface'], "opt")) { - if (!array_key_exists($rule['interface'], $optcfg)) { - $i++; - continue; - } - } - - $nif = 1; - $ispptp = false; - } - - if ($pptpdcfg['mode'] != "server") { - if (($rule['source']['network'] == "pptp") || - ($rule['destination']['network'] == "pptp")) { - $i++; - continue; - } - } - - if (strstr($rule['source']['network'], "opt")) { - if (!array_key_exists($rule['source']['network'], $optcfg)) { - $i++; - continue; - } - } - if (strstr($rule['destination']['network'], "opt")) { - if (!array_key_exists($rule['destination']['network'], $optcfg)) { - $i++; - continue; - } - } - - /* check for unresolvable aliases */ - if ($rule['source']['address'] && !alias_expand($rule['source']['address'])) { - $i++; - continue; - } - if ($rule['destination']['address'] && !alias_expand($rule['destination']['address'])) { - $i++; - continue; - } - - for ($iif = 0; $iif < $nif; $iif++) { - - /* pipe or queue? */ - if (isset($rule['targetpipe']) && isset($config['shaper']['pipe'][$rule['targetpipe']])) { - $pipen = $rule['targetpipe'] + 1; - $line = "add $rulei set 4 pipe $pipen "; $rulei++; - } else if (isset($rule['targetqueue']) && isset($config['shaper']['queue'][$rule['targetqueue']])) { - $queuen = $rule['targetqueue'] + 1; - $line = "add $rulei set 4 queue $queuen "; $rulei++; - } else { - printf("Neither existing pipe nor queue found in rule $i\n"); - break; - } - - if (isset($rule['protocol'])) { - $line .= "{$rule['protocol']} "; - } else { - $line .= "all "; - } - - /* source address */ - if (isset($rule['source']['any'])) { - $src = "any"; - } else if ($rule['source']['network']) { - - if (strstr($rule['source']['network'], "opt")) { - $src = $optcfg[$rule['source']['network']]['sa'] . "/" . - $optcfg[$rule['source']['network']]['sn']; - } else { - switch ($rule['source']['network']) { - case 'lan': - $src = "$lansa/$lansn"; - break; - case 'pptp': - $src = "$pptpsa/$pptpsn"; - break; - } - } - } else if ($rule['source']['address']) { - $src = alias_expand($rule['source']['address']); - } - - if (!$src) { - printf("No source address found in rule $i\n"); - break; - } - - if (isset($rule['source']['not'])) { - $line .= "from not $src "; - } else { - $line .= "from $src "; - } - - if (!isset($rule['protocol']) || in_array($rule['protocol'], array("tcp","udp"))) { - - if ($rule['source']['port']) { - $srcport = explode("-", $rule['source']['port']); - - if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) { - $line .= "{$srcport[0]} "; - } else { - $line .= "{$srcport[0]}-{$srcport[1]} "; - } - } - } - - /* destination address */ - if (isset($rule['destination']['any'])) { - $dst = "any"; - } else if ($rule['destination']['network']) { - - if (strstr($rule['destination']['network'], "opt")) { - $dst = $optcfg[$rule['destination']['network']]['sa'] . "/" . - $optcfg[$rule['destination']['network']]['sn']; - } else { - switch ($rule['destination']['network']) { - case 'lan': - $dst = "$lansa/$lansn"; - break; - case 'pptp': - $dst = "$pptpsa/$pptpsn"; - break; - } - } - } else if ($rule['destination']['address']) { - $dst = alias_expand($rule['destination']['address']); - } - - if (!$dst) { - printf("No destination address found in rule $i\n"); - break; - } - - if (isset($rule['destination']['not'])) { - $line .= "to not $dst "; - } else { - $line .= "to $dst "; - } - - if (!isset($rule['protocol']) || in_array($rule['protocol'], array("tcp","udp"))) { - - if ($rule['destination']['port']) { - $dstport = explode("-", $rule['destination']['port']); - - if ((!$dstport[1]) || ($dstport[0] == $dstport[1])) { - $line .= "{$dstport[0]} "; - } else { - $line .= "{$dstport[0]}-{$dstport[1]} "; - } - } - } - - if ($rule['iplen']) - $line .= "iplen {$rule['iplen']} "; - - if ($rule['iptos']) - $line .= "iptos {$rule['iptos']} "; - - if ($rule['tcpflags']) - $line .= "tcpflags {$rule['tcpflags']} "; - - if ($rule['direction'] == "in") - $line .= "in "; - else if ($rule['direction'] == "out") - $line .= "out "; - - if ($ispptp) { - $line .= "via ng" . ($iif+1); - } else { - if ($rule['interface'] == "wan") - $if = $wanif; - else - $if = $config['interfaces'][$rule['interface']]['if']; - - $line .= "via {$if}"; - } - - $line .= "\n"; - $shaperrules .= $line; - } - - $i++; - } - - /* generate pipes */ - if (isset($config['shaper']['pipe'])) { - $pipei = 1; - foreach ($config['shaper']['pipe'] as $pipe) { - $line = "pipe $pipei config bw {$pipe['bandwidth']}Kbit/s "; - - if ($pipe['delay']) { - $line .= "delay {$pipe['delay']} "; - } - - if ($pipe['plr']) { - $line .= "plr {$pipe['plr']} "; - } - - if ($pipe['qsize']) { - $line .= "queue {$pipe['qsize']} "; - } - - switch ($pipe['mask']) { - case 'source': - $line .= "mask src-ip 0xffffffff "; - break; - case 'destination': - $line .= "mask dst-ip 0xffffffff "; - break; - } - - $line .= "\n"; - $shaperrules .= $line; - $pipei++; - } - } - - /* generate queues */ - if (isset($config['shaper']['queue'])) { - $queuei = 1; - foreach ($config['shaper']['queue'] as $queue) { - - $pipen = $queue['targetpipe'] + 1; - if (!isset($queue['targetpipe']) || !isset($config['shaper']['pipe'][$queue['targetpipe']])) { - printf("Pipe $pipen for queue $queuei not found!\n"); - continue; - } - - $line = "queue $queuei config pipe {$pipen}"; - $line .= " weight {$queue['weight']}"; - - switch ($queue['mask']) { - case 'source': - $line .= " mask src-ip 0xffffffff "; - break; - case 'destination': - $line .= " mask dst-ip 0xffffffff "; - break; - } - - $line .= "\n"; - $shaperrules .= $line; - $queuei++; - } - } - - return $shaperrules; -} - -?> \ No newline at end of file diff --git a/usr/local/www/m0n0/firewall_shaper.php b/usr/local/www/m0n0/firewall_shaper.php deleted file mode 100755 index f4380ddcfe..0000000000 --- a/usr/local/www/m0n0/firewall_shaper.php +++ /dev/null @@ -1,264 +0,0 @@ -#!/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"); - -if (!is_array($config['shaper']['rule'])) { - $config['shaper']['rule'] = array(); -} -if (!is_array($config['shaper']['pipe'])) { - $config['shaper']['pipe'] = array(); -} -if (!is_array($config['shaper']['queue'])) { - $config['shaper']['queue'] = array(); -} -$a_shaper = &$config['shaper']['rule']; -$a_pipe = &$config['shaper']['pipe']; -$a_queue = &$config['shaper']['queue']; - -$pconfig['enable'] = isset($config['shaper']['enable']); - -if ($_POST) { - - if ($_POST['submit']) { - $pconfig = $_POST; - $config['shaper']['enable'] = $_POST['enable'] ? true : false; - write_config(); - } - - if ($_POST['apply'] || $_POST['submit']) { - $retval = 0; - if (!file_exists($d_sysrebootreqd_path)) { - config_lock(); - require_once("m0n0/shaper.inc"); - $retval = shaper_configure(); - config_unlock(); - } - $savemsg = get_std_save_message($retval); - if ($retval == 0) { - if (file_exists($d_shaperconfdirty_path)) - unlink($d_shaperconfdirty_path); - } - } -} - -if ($_GET['act'] == "del") { - if ($a_shaper[$_GET['id']]) { - unset($a_shaper[$_GET['id']]); - write_config(); - touch($d_shaperconfdirty_path); - header("Location: firewall_shaper.php"); - exit; - } -} else 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; - } -} - -$pgtitle = "Firewall: Traffic Shaper"; -include("head.inc"); - -?> -"> - -

-
- -

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

- - - - - - -
- -
- - - - - - - -
- > - Enable traffic shaper
-
-  
- - - - - - - - - - - - - - - - - - - - - - - - - -
IfProtoSourceDestinationTargetDescription
- "; - $textse = ""; - } else { - $textss = $textse = ""; - } - $iflabels = get_configured_interface_with_descr(); - - echo $textss . htmlspecialchars($iflabels[$shaperent['interface']]); - echo "
"; - echo ""; - if ($shaperent['direction'] != "in") - echo ""; - if ($shaperent['direction'] != "out") - echo ""; - echo "" . $textse;; - ?> -
- - -
- Port: - -
-
- Port: - -
- {$desc}"; - } else if (isset($shaperent['targetqueue'])) { - if ($a_queue[$shaperent['targetqueue']]['descr']) - $desc = htmlspecialchars($a_queue[$shaperent['targetqueue']]['descr']); - else - $desc = "Queue " . ($shaperent['targetqueue']+1); - echo "{$desc}"; - } - ?> - - -   - 0): ?> - - - -
- - - - - - - -
- - - - - - - - - - - - - - - - - - - -
incoming (as seen by firewall)outgoing (as seen by firewall)
incoming (disabled)outgoing (disabled)

- Note:
-
the first rule that matches a packet will be executed.
- The following match patterns are not shown in the list above: - IP packet length, TCP flags.
-
- - - diff --git a/usr/local/www/m0n0/firewall_shaper_edit.php b/usr/local/www/m0n0/firewall_shaper_edit.php deleted file mode 100755 index cccc7f6b34..0000000000 --- a/usr/local/www/m0n0/firewall_shaper_edit.php +++ /dev/null @@ -1,778 +0,0 @@ -#!/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. -*/ - -$pgtitle = array("Firewall", "Traffic shaper", "Edit rule"); -require("guiconfig.inc"); - -if (!is_array($config['shaper']['rule'])) { - $config['shaper']['rule'] = array(); -} -$a_shaper = &$config['shaper']['rule']; - -$specialsrcdst = explode(" ", "any lan pptp"); - -$id = $_GET['id']; -if (isset($_POST['id'])) - $id = $_POST['id']; - -$after = $_GET['after']; -if (isset($_POST['after'])) - $after = $_POST['after']; - -if (isset($_GET['dup'])) { - $id = $_GET['dup']; - $after = $_GET['dup']; -} - -function is_specialnet($net) { - global $specialsrcdst; - - if (in_array($net, $specialsrcdst) || strstr($net, "opt")) - return true; - else - return false; -} - -function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) { - - if (isset($adr['any'])) - $padr = "any"; - else if ($adr['network']) - $padr = $adr['network']; - else if ($adr['address']) { - list($padr, $pmask) = explode("/", $adr['address']); - if (!$pmask) - $pmask = 32; - } - - if (isset($adr['not'])) - $pnot = 1; - else - $pnot = 0; - - if ($adr['port']) { - list($pbeginport, $pendport) = explode("-", $adr['port']); - if (!$pendport) - $pendport = $pbeginport; - } else { - $pbeginport = "any"; - $pendport = "any"; - } -} - -function pconfig_to_address(&$adr, $padr, $pmask, $pnot, $pbeginport, $pendport) { - - $adr = array(); - - if ($padr == "any") - $adr['any'] = true; - else if (is_specialnet($padr)) - $adr['network'] = $padr; - else { - $adr['address'] = $padr; - if ($pmask != 32) - $adr['address'] .= "/" . $pmask; - } - - $adr['not'] = $pnot ? true : false; - - if (($pbeginport != 0) && ($pbeginport != "any")) { - if ($pbeginport != $pendport) - $adr['port'] = $pbeginport . "-" . $pendport; - else - $adr['port'] = $pbeginport; - } -} - -if (isset($id) && $a_shaper[$id]) { - $pconfig['interface'] = $a_shaper[$id]['interface']; - - if (isset($a_shaper[$id]['protocol'])) - $pconfig['proto'] = $a_shaper[$id]['protocol']; - else - $pconfig['proto'] = "any"; - - address_to_pconfig($a_shaper[$id]['source'], $pconfig['src'], - $pconfig['srcmask'], $pconfig['srcnot'], - $pconfig['srcbeginport'], $pconfig['srcendport']); - - address_to_pconfig($a_shaper[$id]['destination'], $pconfig['dst'], - $pconfig['dstmask'], $pconfig['dstnot'], - $pconfig['dstbeginport'], $pconfig['dstendport']); - - if (isset($a_shaper[$id]['targetpipe'])) { - $pconfig['target'] = "targetpipe:" . $a_shaper[$id]['targetpipe']; - } else if (isset($a_shaper[$id]['targetqueue'])) { - $pconfig['target'] = "targetqueue:" . $a_shaper[$id]['targetqueue']; - } - - $pconfig['direction'] = $a_shaper[$id]['direction']; - $pconfig['iptos'] = $a_shaper[$id]['iptos']; - $pconfig['iplen'] = $a_shaper[$id]['iplen']; - $pconfig['tcpflags'] = $a_shaper[$id]['tcpflags']; - $pconfig['descr'] = $a_shaper[$id]['descr']; - $pconfig['disabled'] = isset($a_shaper[$id]['disabled']); - - if ($pconfig['srcbeginport'] == 0) { - $pconfig['srcbeginport'] = "any"; - $pconfig['srcendport'] = "any"; - } - if ($pconfig['dstbeginport'] == 0) { - $pconfig['dstbeginport'] = "any"; - $pconfig['dstendport'] = "any"; - } - -} else { - /* defaults */ - $pconfig['src'] = "any"; - $pconfig['dst'] = "any"; -} - -if (isset($_GET['dup'])) - unset($id); - -if ($_POST) { - - if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "any")) { - $_POST['srcbeginport'] = 0; - $_POST['srcendport'] = 0; - $_POST['dstbeginport'] = 0; - $_POST['dstendport'] = 0; - } else { - - if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport']) - $_POST['srcbeginport'] = $_POST['srcbeginport_cust']; - if ($_POST['srcendport_cust'] && !$_POST['srcendport']) - $_POST['srcendport'] = $_POST['srcendport_cust']; - - if ($_POST['srcbeginport'] == "any") { - $_POST['srcbeginport'] = 0; - $_POST['srcendport'] = 0; - } else { - if (!$_POST['srcendport']) - $_POST['srcendport'] = $_POST['srcbeginport']; - } - if ($_POST['srcendport'] == "any") - $_POST['srcendport'] = $_POST['srcbeginport']; - - if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport']) - $_POST['dstbeginport'] = $_POST['dstbeginport_cust']; - if ($_POST['dstendport_cust'] && !$_POST['dstendport']) - $_POST['dstendport'] = $_POST['dstendport_cust']; - - if ($_POST['dstbeginport'] == "any") { - $_POST['dstbeginport'] = 0; - $_POST['dstendport'] = 0; - } else { - if (!$_POST['dstendport']) - $_POST['dstendport'] = $_POST['dstbeginport']; - } - if ($_POST['dstendport'] == "any") - $_POST['dstendport'] = $_POST['dstbeginport']; - } - - if (is_specialnet($_POST['srctype'])) { - $_POST['src'] = $_POST['srctype']; - $_POST['srcmask'] = 0; - } else if ($_POST['srctype'] == "single") { - $_POST['srcmask'] = 32; - } - if (is_specialnet($_POST['dsttype'])) { - $_POST['dst'] = $_POST['dsttype']; - $_POST['dstmask'] = 0; - } else if ($_POST['dsttype'] == "single") { - $_POST['dstmask'] = 32; - } - - $intos = array(); - foreach ($iptos as $tos) { - if ($_POST['iptos_' . $tos] == "on") - $intos[] = $tos; - else if ($_POST['iptos_' . $tos] == "off") - $intos[] = "!" . $tos; - } - $_POST['iptos'] = join(",", $intos); - - $intcpflags = array(); - foreach ($tcpflags as $tcpflag) { - if ($_POST['tcpflags_' . $tcpflag] == "on") - $intcpflags[] = $tcpflag; - else if ($_POST['tcpflags_' . $tcpflag] == "off") - $intcpflags[] = "!" . $tcpflag; - } - $_POST['tcpflags'] = join(",", $intcpflags); - - unset($input_errors); - $pconfig = $_POST; - - /* input validation */ - $reqdfields = explode(" ", "target proto src dst"); - $reqdfieldsn = explode(",", "Target,Protocol,Source,Destination"); - - if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) { - $reqdfields[] = "srcmask"; - $reqdfieldsn[] = "Source bit count"; - } - if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) { - $reqdfields[] = "dstmask"; - $reqdfieldsn[] = "Destination bit count"; - } - - do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - - if (!$_POST['srcbeginport']) { - $_POST['srcbeginport'] = 0; - $_POST['srcendport'] = 0; - } - if (!$_POST['dstbeginport']) { - $_POST['dstbeginport'] = 0; - $_POST['dstendport'] = 0; - } - - if (($_POST['srcbeginport'] && !is_port($_POST['srcbeginport']))) { - $input_errors[] = "The start source port must be an integer between 1 and 65535."; - } - if (($_POST['srcendport'] && !is_port($_POST['srcendport']))) { - $input_errors[] = "The end source port must be an integer between 1 and 65535."; - } - if (($_POST['dstbeginport'] && !is_port($_POST['dstbeginport']))) { - $input_errors[] = "The start destination port must be an integer between 1 and 65535."; - } - if (($_POST['dstendport'] && !is_port($_POST['dstendport']))) { - $input_errors[] = "The end destination port must be an integer between 1 and 65535."; - } - - if (!is_specialnet($_POST['srctype'])) { - if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) { - $input_errors[] = "A valid source IP address or alias must be specified."; - } - if (($_POST['srcmask'] && !is_int($_POST['srcmask']))) { - $input_errors[] = "A valid source bit count must be specified."; - } - } - if (!is_specialnet($_POST['dsttype'])) { - if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) { - $input_errors[] = "A valid destination IP address or alias must be specified."; - } - if (($_POST['dstmask'] && !is_int($_POST['dstmask']))) { - $input_errors[] = "A valid destination bit count must be specified."; - } - } - - if ($_POST['srcbeginport'] > $_POST['srcendport']) { - /* swap */ - $tmp = $_POST['srcendport']; - $_POST['srcendport'] = $_POST['srcbeginport']; - $_POST['srcbeginport'] = $tmp; - } - if ($_POST['dstbeginport'] > $_POST['dstendport']) { - /* swap */ - $tmp = $_POST['dstendport']; - $_POST['dstendport'] = $_POST['dstbeginport']; - $_POST['dstbeginport'] = $tmp; - } - - if (($_POST['iplen'] && !preg_match("/^(\d+)(-(\d+))?$/", $_POST['iplen']))) { - $input_errors[] = "The IP packet length must be an integer or a range (from-to)."; - } - - if (!$input_errors) { - $shaperent = array(); - $shaperent['interface'] = $_POST['interface']; - - if ($_POST['proto'] != "any") - $shaperent['protocol'] = $_POST['proto']; - else - unset($shaperent['protocol']); - - pconfig_to_address($shaperent['source'], $_POST['src'], - $_POST['srcmask'], $_POST['srcnot'], - $_POST['srcbeginport'], $_POST['srcendport']); - - pconfig_to_address($shaperent['destination'], $_POST['dst'], - $_POST['dstmask'], $_POST['dstnot'], - $_POST['dstbeginport'], $_POST['dstendport']); - - $shaperent['direction'] = $_POST['direction']; - $shaperent['iplen'] = $_POST['iplen']; - $shaperent['iptos'] = $_POST['iptos']; - $shaperent['tcpflags'] = $_POST['tcpflags']; - $shaperent['descr'] = $_POST['descr']; - $shaperent['disabled'] = $_POST['disabled'] ? true : false; - - list($targettype,$target) = explode(":", $_POST['target']); - $shaperent[$targettype] = $target; - - if (isset($id) && $a_shaper[$id]) - $a_shaper[$id] = $shaperent; - else { - if (is_numeric($after)) - array_splice($a_shaper, $after+1, 0, array($shaperent)); - else - $a_shaper[] = $shaperent; - } - - write_config(); - touch($d_shaperconfdirty_path); - - header("Location: firewall_shaper.php"); - exit; - } -} -$pgtitle = "Firewall: Traffic Shaper Edit"; -include("head.inc"); - -?> -"> - - - -

- - 0)): ?> -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Target
- Choose a pipe or queue where packets that - match this rule should be sent.
Disabled - > - Disable this rule
- Set this option to disable this rule without removing it from the list.
Interface
- Choose which interface packets must pass - through to match this rule.
Protocol
Choose which IP protocol - this rule should match.
- Hint: in most cases, you should specify TCP  here.
Source > - not
- Use this option to invert the sense of the match.

- - - - - - - - - - - -
Type:  
Address:   - / -
Source port range - - - - - - - - - -
from:  
to:
-
Specify the port or port range for - the source of the packet for this rule.
- Hint: you can leave the 'to' field empty if you only - want to filter a single port
Destination > - not
- Use this option to invert the sense of the match.

- - - - - - - - - - - -
Type:  
Address:   - / -
Destination port - range - - - - - - - - -
from:  
to:
-
Specify the port or port range for - the destination of the packet for this rule.
- Hint: you can leave the 'to' field empty if you only - want to filter a single port
Direction
- Use this to match only packets travelling in a given direction - on the interface specified above (as seen from the firewall's - perspective).
IP Type of Service (TOS) - - - - - - - - -
- - > - yes    > - no    > - don't care
- Use this to match packets according to their IP TOS values. -
IP packet length -
- Setting this makes the rule match packets of a given length - (either a single value or a range in the syntax from-to, - e.g. 0-80).
TCP flags - - - - - - - - -
- - > - set    > - cleared    > - don't care
- Use this to choose TCP flags that must - be set or cleared for this rule to match.
Description -
You may enter a description here - for your reference (not parsed).
  - - - - -
-
- - -

You need to create a pipe or queue before you can add a new rule.

- - - - - - diff --git a/usr/local/www/m0n0/firewall_shaper_magic.php b/usr/local/www/m0n0/firewall_shaper_magic.php deleted file mode 100755 index f4f25c1395..0000000000 --- a/usr/local/www/m0n0/firewall_shaper_magic.php +++ /dev/null @@ -1,418 +0,0 @@ -#!/usr/local/bin/php - - Copyright (C) 2004 Dinesh Nair - - 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. -*/ - -$pgtitle = array("Firewall", "Traffic shaper"); -require("guiconfig.inc"); - -function wipe_magic () { - global $config; - - /* wipe previous */ - $types=array("pipe","queue","rule"); - foreach ($types as $type) { - foreach (array_keys($config['shaper'][$type]) as $num) { - if (substr($config['shaper'][$type][$num]['descr'],0,2) == "m_") { - unset($config['shaper'][$type][$num]); - } - } - } - /* Although we don't delete user-defined rules, it's probably best to - disable the shaper to prevent bad things from happening */ - $config['shaper']['enable'] = FALSE; -} - -function populate_p2p(&$rulei) { - global $config; - - /* To add p2p clients, push Descr,Protocol,Start,End,src/dest/both onto p2plist */ - $p2plist[] = array('BitTorrent','tcp','6881','6999','both'); - $p2plist[] = array('DirectConnect','','412','412','both'); - $p2plist[] = array('DirectFileExpress','','1044','1045','both'); - $p2plist[] = array('FastTrack','','1214','1214','both'); - $p2plist[] = array('CuteMX','','2340','2340','both'); - $p2plist[] = array('iMest','','4329','4329','both'); - $p2plist[] = array('EDonkey2000','','4661','4665','both'); - $p2plist[] = array('SongSpy','','5190','5190','both'); - $p2plist[] = array('HotlineConnect','','5500','5503','both'); - $p2plist[] = array('Gnutella','','6346','6346','both'); - $p2plist[] = array('dcc','','6666','6668','both'); - $p2plist[] = array('Napster','','6699','6701','both'); - $p2plist[] = array('Aimster','','7668','7668','both'); - $p2plist[] = array('BuddyShare','','7788','7788','both'); - $p2plist[] = array('Scour','','8311','8311','both'); - $p2plist[] = array('OpenNap','','8888','8889','both'); - $p2plist[] = array('hotComm','','28864','28865','both'); - - /* Set up/down p2p as lowest weight */ - $direction = array("in","out"); - foreach ($p2plist as $p2pclient) { - foreach ($direction as $dir) { - foreach (array('source','destination') as $srcdest) { - if (($p2pclient[4] == $srcdest) || ($p2pclient[4] == 'both')) { - $config['shaper']['rule'][$rulei]['descr'] = "m_P2P $p2pclient[0]"; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "$dir"; - $config['shaper']['rule'][$rulei]['source']['any'] = 1; - $config['shaper']['rule'][$rulei]['destination']['any'] = 1; - $config['shaper']['rule'][$rulei][$srcdest]['port'] = $p2pclient[2]."-".$p2pclient[3]; - if($p2pclient[1] != '') - $config['shaper']['rule'][$rulei]['protocol'] = $p2pclient[1]; - if ($dir == "out") { - $config['shaper']['rule'][$rulei]['targetqueue'] = 4; - } else { - $config['shaper']['rule'][$rulei]['targetqueue'] = 6; - } - $rulei++; - } - } - } - } -} - -function create_magic ($maxup, $maxdown, $p2plow,$maskq) { - global $config; - - $config['shaper']['enable'] = TRUE; - $pipei = 0; - $queuei = 0; - $rulei = 0; - - /* Create new pipes */ - $config['shaper']['pipe'][$pipei]['descr'] = "m_Total Upload"; - $config['shaper']['pipe'][$pipei]['bandwidth'] = round($maxup * .90); - $pipei++; - $config['shaper']['pipe'][$pipei]['descr'] = "m_Total Download"; - $config['shaper']['pipe'][$pipei]['bandwidth'] = round($maxdown * .95); - $pipei++; - - /* Create new queues */ - $config['shaper']['queue'][$queuei]['descr'] = "m_High Priority #1 Upload"; - $config['shaper']['queue'][$queuei]['targetpipe'] = 0; - $config['shaper']['queue'][$queuei]['weight'] = 50; - $queuei++; - $config['shaper']['queue'][$queuei]['descr'] = "m_High Priority #2 Upload"; - $config['shaper']['queue'][$queuei]['targetpipe'] = 0; - $config['shaper']['queue'][$queuei]['weight'] = 30; - $queuei++; - $config['shaper']['queue'][$queuei]['descr'] = "m_High Priority #3 Upload"; - $config['shaper']['queue'][$queuei]['targetpipe'] = 0; - $config['shaper']['queue'][$queuei]['weight'] = 15; - $queuei++; - $config['shaper']['queue'][$queuei]['descr'] = "m_Bulk Upload"; - $config['shaper']['queue'][$queuei]['targetpipe'] = 0; - $config['shaper']['queue'][$queuei]['weight'] = 4; - $queuei++; - $config['shaper']['queue'][$queuei]['descr'] = "m_Hated Upload"; - $config['shaper']['queue'][$queuei]['targetpipe'] = 0; - $config['shaper']['queue'][$queuei]['weight'] = 1; - $queuei++; - $config['shaper']['queue'][$queuei]['descr'] = "m_Bulk Download"; - $config['shaper']['queue'][$queuei]['targetpipe'] = 1; - $config['shaper']['queue'][$queuei]['weight'] = 30; - $queuei++; - $config['shaper']['queue'][$queuei]['descr'] = "m_Hated Download"; - $config['shaper']['queue'][$queuei]['targetpipe'] = 1; - $config['shaper']['queue'][$queuei]['weight'] = 10; - $queuei++; - $config['shaper']['queue'][$queuei]['descr'] = "m_High Priority Download"; - $config['shaper']['queue'][$queuei]['targetpipe'] = 1; - $config['shaper']['queue'][$queuei]['weight'] = 60; - $queuei++; - if ($maskq) { - for ($i = 0; $i < $queuei; $i++) { - if (stristr($config['shaper']['queue'][$i]['descr'],"upload")) { - $config['shaper']['queue'][$i]['mask'] = 'source'; - } else if (stristr($config['shaper']['queue'][$i]['descr'],"download")) { - $config['shaper']['queue'][$i]['mask'] = 'destination'; - } - } - } - - /* Create new rules */ - if ($p2plow) - populate_p2p($rulei); - - $config['shaper']['rule'][$rulei]['descr'] = "m_TCP ACK Upload"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 2; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "out"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['iplen'] = "0-80"; - $config['shaper']['rule'][$rulei]['protocol'] = "tcp"; - $config['shaper']['rule'][$rulei]['tcpflags'] = "ack"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_Small Pkt Upload"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 0; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "out"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['iplen'] = "0-100"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_Outbound DNS Query"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 0; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "out"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['port'] = 53; - $config['shaper']['rule'][$rulei]['protocol'] = "udp"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_AH Upload"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 0; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "out"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['protocol'] = "ah"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_ESP Upload"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 0; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "out"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['protocol'] = "esp"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_GRE Upload"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 0; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "out"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['protocol'] = "gre"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_ICMP Upload"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 1; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "out"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['protocol'] = "icmp"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_Catch-All Upload"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 3; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "out"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_ICMP Download"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 7; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "in"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['protocol'] = "icmp"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_Small Pkt Download"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 7; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "in"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['iplen'] = "0-100"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_AH Download"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 7; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "in"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['protocol'] = "ah"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_ESP Download"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 7; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "in"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['protocol'] = "esp"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_GRE Download"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 7; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "in"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['protocol'] = "gre"; - $rulei++; - $config['shaper']['rule'][$rulei]['descr'] = "m_Catch-All Download"; - $config['shaper']['rule'][$rulei]['targetqueue'] = 5; - $config['shaper']['rule'][$rulei]['interface'] = "wan"; - $config['shaper']['rule'][$rulei]['direction'] = "in"; - $config['shaper']['rule'][$rulei]['source']['any'] = TRUE; - $config['shaper']['rule'][$rulei]['destination']['any'] = TRUE; - $rulei++; -} - -if (!is_array($config['shaper']['rule'])) { - $config['shaper']['rule'] = array(); -} -if (!is_array($config['shaper']['pipe'])) { - $config['shaper']['pipe'] = array(); -} -if (!is_array($config['shaper']['queue'])) { - $config['shaper']['queue'] = array(); -} - -$a_shaper = &$config['shaper']['rule']; -$a_queues = &$config['shaper']['queue']; -$a_pipes = &$config['shaper']['pipe']; - -$pconfig['p2plow'] = isset($config['shaper']['magic']['p2plow']); -$pconfig['maskq'] = isset($config['shaper']['magic']['maskq']); -$pconfig['maxup'] = $config['shaper']['magic']['maxup']; -$pconfig['maxdown'] = $config['shaper']['magic']['maxdown']; - -if ($_POST) { - - if ($_POST['install']) { - unset($input_errors); - $pconfig = $_POST; - $reqdfields = explode(" ", "maxup maxdown"); - $reqdfieldsn = explode(",", "Max. Upload,Max.Download"); - do_input_validation($_POST,$reqdfields, $reqdfieldsn, &$input_errors); - if (($_POST['maxup'] && !is_int($_POST['maxup']))) { - //$input_errors[] = "The max upload bandwidth must be an integer."; - } - if (($_POST['maxdown'] && !is_int($_POST['maxdown']))) { - //$input_errors[] = "The max download bandwidth must be an integer."; - } - if (!$input_errors) { - if ($_POST['install']) { - unset ($config['shaper']); - create_magic($_POST['maxup'],$_POST['maxdown'],$_POST['p2plow']?TRUE:FALSE,$_POST['maskq']?TRUE:FALSE); - touch($d_shaperconfdirty_path); - } - $config['shaper']['magic']['p2plow'] = $_POST['p2plow'] ? TRUE : FALSE; - $config['shaper']['magic']['maskq'] = $_POST['maskq'] ? TRUE : FALSE; - $config['shaper']['magic']['maxup'] = $_POST['maxup']; - $config['shaper']['magic']['maxdown'] = $_POST['maxdown']; - write_config(); - } - } - if ($_POST['remove']) { - wipe_magic(); - $note = '

Note: The traffic shaper has been disabled.
All of your user-defined rules/pipes/queues are still intact.

'; - touch($d_shaperconfdirty_path); - write_config(); - } - if ($_POST['apply']) { - $retval = 0; - if (!file_exists($d_sysrebootreqd_path)) { - config_lock(); - require_once("m0n0/shaper.inc"); - $retval = shaper_configure(); - config_unlock(); - } - $savemsg = get_std_save_message($retval); - if ($retval == 0) { - if (file_exists($d_shaperconfdirty_path)) - unlink($d_shaperconfdirty_path); - } - } -} - -$pgtitle = "Firewall: Traffic Shaper: Magic Shaper Wizard"; -include("head.inc"); - -?> -"> - -

-
- -

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

- - - - - - -
- -
- - - - - - - - - - - - - - - - - - - - - -
  - > - Set P2P traffic to lowest priority
  - > - Share bandwidth evenly on LAN
Downstream
- speed
- - kbps
- Enter the speed of your WAN downstream link here.
Upstream
- speed
- kbps
- Enter the speed of your WAN upstream link here.
  - -   - -

- All existing traffic shaper rules/pipes/queues will be deleted once "Install/Update" has been pressed! Backup your configuration before proceeding!

- Note:
-
By entering your maximum upload and download values and pressing the "Install/Update" button, the magic shaper will do its best to create the optimum shaping rules, queues, and pipes for you. These rules will help ensure that interactive traffic remains acceptable while the upstream bandwidth is being consumed by heavy traffic.
-
-
- - - diff --git a/usr/local/www/m0n0/firewall_shaper_pipes.php b/usr/local/www/m0n0/firewall_shaper_pipes.php deleted file mode 100755 index aefc307a48..0000000000 --- a/usr/local/www/m0n0/firewall_shaper_pipes.php +++ /dev/null @@ -1,175 +0,0 @@ -#!/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. -*/ - -$pgtitle = array("Firewall", "Traffic shaper"); -require("guiconfig.inc"); - -if (!is_array($config['shaper']['pipe'])) { - $config['shaper']['pipe'] = array(); -} -if (!is_array($config['shaper']['queue'])) { - $config['shaper']['queue'] = array(); -} -$a_pipes = &$config['shaper']['pipe']; - -if ($_GET['act'] == "del") { - if ($a_pipes[$_GET['id']]) { - /* check that no rule references this pipe */ - if (is_array($config['shaper']['rule'])) { - foreach ($config['shaper']['rule'] as $rule) { - if (isset($rule['targetpipe']) && ($rule['targetpipe'] == $_GET['id'])) { - $input_errors[] = "This pipe cannot be deleted because it is still referenced by a rule."; - break; - } - } - } - - /* check that no queue references this pipe */ - if (is_array($config['shaper']['queue'])) { - foreach ($config['shaper']['queue'] as $queue) { - if ($queue['targetpipe'] == $_GET['id']) { - $input_errors[] = "This pipe cannot be deleted because it is still referenced by a queue."; - break; - } - } - } - - if (!$input_errors) { - unset($a_pipes[$_GET['id']]); - - /* renumber all rules and queues */ - if (is_array($config['shaper']['rule'])) { - for ($i = 0; isset($config['shaper']['rule'][$i]); $i++) { - $currule = &$config['shaper']['rule'][$i]; - if (isset($currule['targetpipe']) && ($currule['targetpipe'] > $_GET['id'])) - $currule['targetpipe']--; - } - } - if (is_array($config['shaper']['queue'])) { - for ($i = 0; isset($config['shaper']['queue'][$i]); $i++) { - $curqueue = &$config['shaper']['queue'][$i]; - if ($curqueue['targetpipe'] > $_GET['id']) - $curqueue['targetpipe']--; - } - } - - write_config(); - touch($d_shaperconfdirty_path); - header("Location: firewall_shaper_pipes.php"); - exit; - } - } -} -$pgtitle = "Firewall: Traffic Shaper - Pipes"; -include("head.inc"); - -?> -"> - -

-
- - -

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

- - - - - - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
No.BandwidthDelayPLRQueueMaskDescription
- - - Kbit/s - - - ms - -   - - - -   - - - -   - - - -   - - -   -  

- Note: a pipe can - only be deleted if it is not referenced by any rules or queues.
-
- - - diff --git a/usr/local/www/m0n0/firewall_shaper_pipes_edit.php b/usr/local/www/m0n0/firewall_shaper_pipes_edit.php deleted file mode 100755 index d9cf01f6e3..0000000000 --- a/usr/local/www/m0n0/firewall_shaper_pipes_edit.php +++ /dev/null @@ -1,168 +0,0 @@ -#!/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. -*/ - -$pgtitle = array("Firewall", "Traffic shaper", "Edit pipe"); -require("guiconfig.inc"); - -$a_pipes = &$config['shaper']['pipe']; - -$id = $_GET['id']; -if (isset($_POST['id'])) - $id = $_POST['id']; - -if (isset($id) && $a_pipes[$id]) { - $pconfig['bandwidth'] = $a_pipes[$id]['bandwidth']; - $pconfig['delay'] = $a_pipes[$id]['delay']; - $pconfig['plr'] = $a_pipes[$id]['plr']; - $pconfig['qsize'] = $a_pipes[$id]['qsize']; - $pconfig['mask'] = $a_pipes[$id]['mask']; - $pconfig['descr'] = $a_pipes[$id]['descr']; -} - -if ($_POST) { - - unset($input_errors); - $pconfig = $_POST; - - /* input validation */ - $reqdfields = explode(" ", "bandwidth"); - $reqdfieldsn = explode(",", "Bandwidth"); - - do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - - if (($_POST['bandwidth'] && !is_int($_POST['bandwidth']))) { - $input_errors[] = "The bandwidth must be an integer."; - } - if (($_POST['delay'] && !is_int($_POST['delay']))) { - $input_errors[] = "The delay must be an integer."; - } - if ($_POST['plr'] && (!is_numeric($_POST['plr']) || $_POST['plr'] < 0 || $_POST['plr'] > 1)) { - $input_errors[] = "The packet loss rate must be a number between 0 and 1."; - } - if ($_POST['qsize'] && (!is_int($_POST['qsize']) || $_POST['qsize'] < 2 || $_POST['qsize'] > 100)) { - $input_errors[] = "The queue size must be an integer between 2 and 100."; - } - - if (!$input_errors) { - $pipe = array(); - - $pipe['bandwidth'] = $_POST['bandwidth']; - if ($_POST['delay']) - $pipe['delay'] = $_POST['delay']; - if ($_POST['plr']) - $pipe['plr'] = $_POST['plr']; - if ($_POST['qsize']) - $pipe['qsize'] = $_POST['qsize']; - if ($_POST['mask']) - $pipe['mask'] = $_POST['mask']; - $pipe['descr'] = $_POST['descr']; - - if (isset($id) && $a_pipes[$id]) - $a_pipes[$id] = $pipe; - else - $a_pipes[] = $pipe; - - write_config(); - touch($d_shaperconfdirty_path); - - header("Location: firewall_shaper_pipes.php"); - exit; - } -} - -$pgtitle = "Firewall: Traffic Shaper - Pipes Edit"; -include("head.inc"); -?> -"> - -

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Bandwidth -  Kbit/s
Delay -  ms
Hint: in most cases, you - should specify 0 here (or leave the field empty)
Packet loss rate -
Hint: in most cases, you - should specify 0 here (or leave the field empty). A value of 0.001 means one packet in 1000 gets dropped.
Queue size -  slots
- Hint: in most cases, you - should leave the field empty. All packets in this pipe are placed into a fixed-size queue first, - then they are delayed by value specified in the Delay field, and then they are delivered to their destination.
Mask
- If 'source' or 'destination' is chosen, - a dynamic pipe with the bandwidth, delay, packet loss and queue size given above will - be created for each source/destination IP address encountered, - respectively. This makes it possible to easily specify bandwidth - limits per host.
Description -
You may enter a description here - for your reference (not parsed).
  - - - -
- -
- - - - diff --git a/usr/local/www/m0n0/firewall_shaper_queues.php b/usr/local/www/m0n0/firewall_shaper_queues.php deleted file mode 100755 index 85f2525d2d..0000000000 --- a/usr/local/www/m0n0/firewall_shaper_queues.php +++ /dev/null @@ -1,149 +0,0 @@ -#!/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. -*/ - -$pgtitle = array("Firewall", "Traffic shaper"); -require("guiconfig.inc"); - -if (!is_array($config['shaper']['pipe'])) { - $config['shaper']['pipe'] = array(); -} -if (!is_array($config['shaper']['queue'])) { - $config['shaper']['queue'] = array(); -} -$a_queues = &$config['shaper']['queue']; -$a_pipe = &$config['shaper']['pipe']; - -if ($_GET['act'] == "del") { - if ($a_queues[$_GET['id']]) { - /* check that no rule references this queue */ - if (is_array($config['shaper']['rule'])) { - foreach ($config['shaper']['rule'] as $rule) { - if (isset($rule['targetqueue']) && ($rule['targetqueue'] == $_GET['id'])) { - $input_errors[] = "This queue cannot be deleted because it is still referenced by a rule."; - break; - } - } - } - - if (!$input_errors) { - unset($a_queues[$_GET['id']]); - - /* renumber all rules */ - if (is_array($config['shaper']['rule'])) { - for ($i = 0; isset($config['shaper']['rule'][$i]); $i++) { - $currule = &$config['shaper']['rule'][$i]; - if (isset($currule['targetqueue']) && ($currule['targetqueue'] > $_GET['id'])) - $currule['targetqueue']--; - } - } - - write_config(); - touch($d_shaperconfdirty_path); - header("Location: firewall_shaper_queues.php"); - exit; - } - } -} - -$pgtitle = "Firewall: Traffic Shaper - Queues"; -include("head.inc"); - -?> -"> - -

-
- - -

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

- - - - - - -
- -
- - - - - - - - - - - - - - - - - - - - - - - -
No.PipeWeightMaskDescription
- - - - - - - -   - - -   -  

- Note: a queue can - only be deleted if it is not referenced by any rules.
-
- - - diff --git a/usr/local/www/m0n0/firewall_shaper_queues_edit.php b/usr/local/www/m0n0/firewall_shaper_queues_edit.php deleted file mode 100755 index efa9ea401e..0000000000 --- a/usr/local/www/m0n0/firewall_shaper_queues_edit.php +++ /dev/null @@ -1,157 +0,0 @@ -#!/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. -*/ - -$pgtitle = array("Firewall", "Traffic shaper", "Edit queue"); -require("guiconfig.inc"); - -$a_queues = &$config['shaper']['queue']; - -$id = $_GET['id']; -if (isset($_POST['id'])) - $id = $_POST['id']; - -if (isset($id) && $a_queues[$id]) { - $pconfig['targetpipe'] = $a_queues[$id]['targetpipe']; - $pconfig['weight'] = $a_queues[$id]['weight']; - $pconfig['mask'] = $a_queues[$id]['mask']; - $pconfig['descr'] = $a_queues[$id]['descr']; -} - -if ($_POST) { - - unset($input_errors); - $pconfig = $_POST; - - /* input validation */ - $reqdfields = explode(" ", "weight"); - $reqdfieldsn = explode(",", "Weight"); - - do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - - if ($_POST['weight'] && (!is_int($_POST['weight']) - || ($_POST['weight'] < 1) || ($_POST['weight'] > 100))) { - $input_errors[] = "The weight must be an integer between 1 and 100."; - } - - if (!$input_errors) { - $queue = array(); - - $queue['targetpipe'] = $_POST['targetpipe']; - $queue['weight'] = $_POST['weight']; - if ($_POST['mask']) - $queue['mask'] = $_POST['mask']; - $queue['descr'] = $_POST['descr']; - - if (isset($id) && $a_queues[$id]) - $a_queues[$id] = $queue; - else - $a_queues[] = $queue; - - write_config(); - touch($d_shaperconfdirty_path); - - header("Location: firewall_shaper_queues.php"); - exit; - } -} -$pgtitle = "Firewall: Traffic Shaper: Queues Edit"; -include("head.inc"); - -?> -"> - -

- - 0)): ?> -
- - - - - - - - - - - - - - - - - - - - - -
Pipe
- Choose the pipe that this queue is linked - to.
Weight -
Valid range: 1..100.
- All backlogged (i.e., with packets queued) queues linked to - the same pipe share the pipe's bandwidth proportionally to - their weights (higher weight = higher share of bandwidth). - Note that weights are not priorities; a queue with a lower - weight is still guaranteed to get its fraction of the bandwidth - even if a queue with a higher weight is permanently backlogged.
Mask
If 'source' or 'destination' - is chosen, a dynamic queue associated with the pipe and with - the weight given above will be created for each source/destination - IP address encountered, respectively.
Description -
You may enter a description here - for your reference (not parsed).
  - - - -
- -

You need to create a pipe before you can add a new queue.

- -
- - - -