diff --git a/etc/inc/shaper.inc b/etc/inc/shaper.inc index 166b62e687..bf53963bdf 100644 --- a/etc/inc/shaper.inc +++ b/etc/inc/shaper.inc @@ -260,7 +260,6 @@ class altq_root_queue { } function validate_input($data, &$input_errors) { - global $config; /* XXX: how to get info about interfaces?! */ $reqfields[] = "bandwidth"; $reqdfieldsn[] = "Bandwidth"; @@ -269,7 +268,6 @@ class altq_root_queue { shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors); - if (isset($config['interface'][$this->GetQname()]['bandwidth'])) { switch($data['banwidthtype']) { case "%": $myBw = $this->GetAvailableBandwidth() * intval($data['bandwidth']) / 100; @@ -282,7 +280,7 @@ class altq_root_queue { if ($this->GetAvailableBandwidth() < $myBw) $input_errors[] = "Bandwidth cannot be set higher than that of interface."; - } + if ($data['bandwidth'] && (!is_numeric($data['bandwidth']))) $input_errors[] = "Bandwidth must be an integer."; @@ -375,15 +373,15 @@ class altq_root_queue { if (isset($q['bandwidth'])) { switch ($q['bandwidthtype']) { case "%": - $q->SetAvailableBandwidth($this->GetAvailableBandwidth() - - ($this->GetAvailableBandwidth() * $q['bandwidth'] / 100)); + $myBw = $this->GetAvailableBandwidth() * $q['bandwidth'] / 100; break; default: - $q->SetAvailableBandwidth($this->GetAvailableBandwidth() - - ($q['bandwidth'] * get_bandwidthtype_scale($q['bandwdithtype']))); + $myBw = $q['bandwidth'] * get_bandwidthtype_scale($q['bandwdithtype']); break; } - } + } + $q->SetAvailableBandwidth($myBw); + $this->SetAvailableBandwidth($this->GetAvailableBandwidth() - $myBw); $this->queues[$q->GetQname()] = &$q; $GLOBALS['allqueue_list'][] = $q->GetQname(); ref_on_altq_queue_list($this->GetQname(), $q->GetQname()); @@ -439,8 +437,10 @@ class altq_root_queue { } function delete_queue() { - foreach ($this->queues as $q) + foreach ($this->queues as $q) $q->delete_queue(); + + $this->SetAvailableBandwidth($this->GetAvailableBandwidth() + $q->GetAvailableBandwidth()); unset_object_by_reference($this->GetLink()); } @@ -994,7 +994,7 @@ function GetEcn() { if ($this->GetDefault()) { $form .= "subqueues) < 1) { + } else { $form .= "SetInterface($this->GetInterface()); $q->SetParent(&$this); - $this->CalculateRemainingBandwidth($qname['bandwidth'], $qname['bandwidthtype']); $q->ReadConfig($qname); $q->validate_input($qname, $input_errors); if (count($input_errors)) { return $q; } + $q->SetEnabled("on"); $q->SetLink($path); - switch($q->GetBwscale()) { - case "%": - $myBw = $this->GetAvailableBandwidth() * $qname['bandwidth'] / 100; - break; - default: - $myBw = $qname['bandwidth'] * get_bandwidthtype_scale($q->GetBwscale()); - break; - } + switch ($q->GetBwscale()) { + case "%": + $myBw = $this->GetAvailableBandwidth() * $qname['bandwidth'] / 100; + break; + default: + $myBw = $qname['bandwidth'] * get_bandwidthtype_scale($q->GetBwscale()); + break; + } $q->SetAvailableBandwidth($myBw); $this->SetAvailableBandwidth($this->GetAvailableBandwidth() - $myBw); @@ -1239,9 +1239,10 @@ class hfsc_queue extends priq_queue { altq_set_default_queue($this->GetInterface(), "false"); cleanup_queue_from_rules($this->GetQname()); $parent =& $this->GetParent(); - $parent->CalculateRemainingBandwidth($this->GetBandwidth(), $this->GetBwscale(), "delete"); foreach ($this->subqueues as $q) $q->delete_queue(); + $this->SetAvailableBandwidth($this->GetAvailableBandwidth() + $q->GetAvailableBandwidth()); + unset_object_by_reference($this->GetLink()); } @@ -1490,7 +1491,7 @@ class hfsc_queue extends priq_queue { else if ($this->GetU_m2() <> "") $pfq_rule .= " upperlimit " . $this->GetU_m2() . " "; } - $pfq_rule .= " )\n "; + $pfq_rule .= " ) "; } if (count($this->subqueues)) { $i = count($this->subqueues); @@ -1787,8 +1788,8 @@ class cbq_queue extends priq_queue { cleanup_queue_from_rules($this->GetQname()); foreach ($this->subqueues as $q) $q->delete_queue(); + $this->SetAvailableBandwidth($this->GetAvailableBandwidth() + $q->GetAvailableBandwidth()); $parent =& $this->GetParent(); - $parent->CalculateRemainingBandwidth($this->GetBandwidth(), $this->GetBwscale(), "delete"); unset_object_by_reference($this->subqueues[$qname]->GetLink()); } diff --git a/usr/local/www/firewall_shaper.php b/usr/local/www/firewall_shaper.php index f1bec5099e..04585d1fb7 100755 --- a/usr/local/www/firewall_shaper.php +++ b/usr/local/www/firewall_shaper.php @@ -243,7 +243,7 @@ if ($_GET) { if ($qtmp) { $tmppath =& $qtmp->GetLink(); array_push($tmppath, $qname); - $tmp =& $qtmp->add_queue($interface, $_POST, &$tmppath, &$input_errors); + $tmp =& $qtmp->add_queue($interface, $_POST, $tmppath, &$input_errors); if (!$input_errors) { array_pop($tmppath); $tmp->wconfig(); diff --git a/usr/local/www/firewall_shaper_queues_edit.php b/usr/local/www/firewall_shaper_queues_edit.php deleted file mode 100755 index cb7309f8c8..0000000000 --- a/usr/local/www/firewall_shaper_queues_edit.php +++ /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. -*/ - -require("guiconfig.inc"); - -$a_queues = &$config['shaper']['queue']; - -function gettext($text) { - return $text; -} - -/* 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"); -} - -$id = $_GET['id']; -if (isset($_POST['id'])) - $id = $_POST['id']; - -$pconfig['schedulertype'] = $config['shaper']['schedulertype']; -$schedulertype = $config['shaper']['schedulertype']; - -if (isset($id)) { - if (!is_numeric($id)) { - $i = 0; - foreach($config['shaper']['queue'] as $queue) { - if ($queue['name'] == $id) { - $id = $i; - break; - } else - $i++; - } - } - if ($a_queues[$id]) { - $pconfig['priority'] = $a_queues[$id]['priority']; - $pconfig['mask'] = $a_queues[$id]['mask']; - $pconfig['name'] = $a_queues[$id]['name']; - $pconfig = $a_queues[$id]; - $pconfig['ack'] = $a_queues[$id]['ack']; - $pconfig['red'] = $a_queues[$id]['red']; - $pconfig['ecn'] = $a_queues[$id]['ecn']; - $pconfig['rio'] = $a_queues[$id]['rio']; - $pconfig['borrow'] = $a_queues[$id]['borrow']; - $pconfig['defaultqueue'] = $a_queues[$id]['defaultqueue']; - $pconfig['parentqueue'] = $a_queues[$id]['parentqueue']; - $pconfig['upperlimit1'] = $a_queues[$id]['upperlimit1']; - $pconfig['upperlimit2'] = $a_queues[$id]['upperlimit2']; - $pconfig['upperlimit3'] = $a_queues[$id]['upperlimit3']; - $pconfig['realtime1'] = $a_queues[$id]['realtime1']; - $pconfig['realtime2'] = $a_queues[$id]['realtime2']; - $pconfig['realtime3'] = $a_queues[$id]['realtime3']; - $pconfig['linkshare1'] = $a_queues[$id]['linkshare1']; - $pconfig['linkshare2'] = $a_queues[$id]['linkshare2']; - $pconfig['linkshare3'] = $a_queues[$id]['linkshare3']; - $pconfig['bandwidth'] = $a_queues[$id]['bandwidth']; - $pconfig['bandwidthtype'] = $a_queues[$id]['bandwidthtype']; - $pconfig['associatedrule'] = $a_queues[$id]['associatedrule']; - $pconfig['attachtoqueue'] = $a_queues[$id]['attachtoqueue']; - } -} - -if ($_POST) { - - unset($input_errors); - $pconfig = $_POST; - - $needs_rrd_reload = false; - if($rule['descr'] <> $pconfig['descr']) - $needs_rrd_reload = true; - - /* input validation */ - //$reqdfields = explode(" ", "priority"); - //$reqdfieldsn = explode(",", "Priority"); - - do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - - if ($_POST['priority'] && (!is_numericint($_POST['priority']) - || ($_POST['priority'] < 1) || ($_POST['priority'] > 100))) { - $input_errors[] = "The priority must be an integer between 1 and 100."; - } - if (!preg_match("/^[a-zA-Z0-9_-]*$/", $_POST['name'])) - $input_errors[] = gettext("Queue names must be alphanumeric and _ or - only."); - - switch($config['shaper']['schedulertype']) { - case 'hfsc': - /* HFSC validation */ - if ($_POST['upperlimit1'] <> "" && $_POST['upperlimit2'] == "") - $input_errors[] = "upperlimit service curve defined but missing burst (d) value"; - if ($_POST['upperlimit2'] <> "" && $_POST['upperlimit1'] == "") - $input_errors[] = "upperlimit service curve defined but missing initial bandwidth (m1) value"; - if ($_POST['upperlimit1'] <> "" && !is_valid_shaperbw($_POST['upperlimit1'])) - $input_errors[] = gettext("upperlimit m1 value needs to be Kb, Mb, Gb, or %"); - if ($_POST['upperlimit2'] <> "" && !is_numeric($_POST['upperlimit2'])) - $input_errors[] = gettext("upperlimit d value needs to be numeric"); - if ($_POST['upperlimit3'] <> "" && !is_valid_shaperbw($_POST['upperlimit3'])) - $input_errors[] = gettext("upperlimit m2 value needs to be Kb, Mb, Gb, or %"); - if ($_POST['linkshare1'] <> "" && $_POST['linkshare2'] == "") - $input_errors[] = "linkshare service curve defined but missing burst (d) value"; - if ($_POST['linkshare1'] <> "" && !is_valid_shaperbw($_POST['linkshare1'])) - $input_errors[] = gettext("linkshare m1 value needs to be Kb, Mb, Gb, or %"); - if ($_POST['linkshare2'] <> "" && !is_numeric($_POST['linkshare2'])) - $input_errors[] = gettext("linkshare d value needs to be numeric"); - if ($_POST['linkshare3'] <> "" && !is_valid_shaperbw($_POST['linkshare3'])) - $input_errors[] = gettext("linkshare m2 value needs to be Kb, Mb, Gb, or %"); - if ($_POST['linkshare2'] <> "" && $_POST['linkshare1'] == "") - $input_errors[] = "linkshare service curve defined but missing initial bandwidth (m1) value"; - if ($_POST['realtime1'] <> "" && $_POST['realtime2'] == "") - $input_errors[] = "realtime service curve defined but missing burst (d) value"; - if ($_POST['realtime1'] <> "" && !is_valid_shaperbw($_POST['realtime1'])) - $input_errors[] = gettext("realtime m1 value needs to be Kb, Mb, Gb, or %"); - if ($_POST['realtime2'] <> "" && !is_numeric($_POST['realtime2'])) - $input_errors[] = gettext("realtime d value needs to be numeric"); - if ($_POST['realtime3'] <> "" && !is_valid_shaperbw($_POST['realtime3'])) - $input_errors[] = gettext("realtime m2 value needs to be Kb, Mb, Gb, or %"); - if ($_POST['realtime2'] <> "" && $_POST['realtime1'] == "") - $input_errors[] = "realtime service curve defined but missing initial bandwidth (m1) value"; - break; - case 'cbq': - break; - case 'priq': - break; - } - - if (!$input_errors) { - $queue = array(); - $queue['schedulertype'] = $_POST['schedulertype']; - $queue['bandwidth'] = $_POST['bandwidth']; - $queue['bandwidthtype'] = $_POST['bandwidthtype']; - if($_POST['bandwidth'] == "") - unset($queue['bandwidthtype']); - if($_POST['bandwidthtype'] == "") - unset($queue['bandwidth']); - $queue['priority'] = $_POST['priority']; - $queue['name'] = substr(ereg_replace(" ", "", $_POST['name']), 0, 15); - $queue['borrow'] = $_POST['borrow']; - $queue['linkshare'] = $_POST['linkshare']; - $queue['linkshare3'] = $_POST['linkshare3']; - $queue['linkshare2'] = $_POST['linkshare2']; - $queue['linkshare1'] = $_POST['linkshare1']; - $queue['realtime'] = $_POST['realtime']; - $queue['realtime3'] = $_POST['realtime3']; - $queue['realtime2'] = $_POST['realtime2']; - $queue['realtime1'] = $_POST['realtime1']; - $queue['upperlimit'] = $_POST['upperlimit']; - $queue['upperlimit3'] = $_POST['upperlimit3']; - $queue['upperlimit2'] = $_POST['upperlimit2']; - $queue['upperlimit1'] = $_POST['upperlimit1']; - $queue['parentqueue'] = $_POST['parentqueue']; - $queue['attachtoqueue'] = $_POST['attachtoqueue']; - $queue['associatedrule'] = $_POST['associatedrule']; - $scheduleroptions=""; - if ($_POST['ack']) - $queue['ack'] = $_POST['ack']; - $queue['rio'] = $_POST['rio']; - $queue['red'] = $_POST['red']; - $queue['ecn'] = $_POST['ecn']; - $queue['defaultqueue'] = $_POST['defaultqueue']; - if (isset($id) && $a_queues[$id]) - $a_queues[$id] = $queue; - else - $a_queues[] = $queue; - - write_config(); - - foreach($config['filter']['rule'] as $rule) { - if($rule['descr'] == $_POST['associatedrule']) { - $rule['queue'] = $_POST['associatedrule']; - } - } - - write_config(); - - if($needs_rrd_reload) { - system("rm -f /var/db/rrd/wan-queues.rrd"); - enable_rrd_graphing(); - } - - touch($d_shaperconfdirty_path); - - header("Location: firewall_shaper_queues.php"); - exit; - } -} - - $ack = $pconfig["ack"]; - $red = $pconfig["red"]; - $ecn = $pconfig["ecn"]; - $rio = $pconfig["rio"]; - $borrow = $pconfig["borrow"]; - $upperlimit = $pconfig["upperlimit"]; - $upperlimit1 = $pconfig["upperlimit1"]; - $upperlimit2 = $pconfig["upperlimit2"]; - $upperlimit3 = $pconfig["upperlimit3"]; - $realtime = $pconfig["realtime"]; - $realtime1 = $pconfig["realtime1"]; - $realtime2 = $pconfig["realtime2"]; - $realtime3 = $pconfig["realtime3"]; - $linkshare = $pconfig["linkshare"]; - $linkshare1 = $pconfig["linkshare1"]; - $linkshare2 = $pconfig["linkshare2"]; - $linkshare3 = $pconfig["linkshare3"]; - $parentqueue = $pconfig["parentqueue"]; - $defaultqueue = $pconfig["defaultqueue"]; - $attachtoqueue = $pconfig['attachtoqueue']; - $parent = $pconfig["parent"]; - -$pgtitle = array("Firewall","Shaper","Queues","Edit"); -include("head.inc"); - -?> - - - -
- - - - - - -