summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErmal Luçi <eri@pfsense.org>2008-01-11 21:07:25 +0000
committerErmal Luçi <eri@pfsense.org>2008-01-11 21:07:25 +0000
commit197bfe966c677a4ffca27610cdf1dc2a22a6a289 (patch)
treeecf9230a6fc3d92822c1b7ba974a9fbc72a091d0
parent9daeb964853d3251c3304cb6dfbc05bda843987a (diff)
downloadpfsense-197bfe966c677a4ffca27610cdf1dc2a22a6a289.zip
pfsense-197bfe966c677a4ffca27610cdf1dc2a22a6a289.tar.gz
Bring in the new traffic shaper.
It is capable of multi interface shaping. Also bring the wizard up-to-date. Now it is capable of doing multi interface too.
-rw-r--r--etc/inc/config.inc33
-rw-r--r--etc/inc/filter.inc131
-rw-r--r--etc/inc/pfsense-utils.inc26
-rw-r--r--etc/inc/shaper.inc2331
-rwxr-xr-xusr/local/www/firewall_rules.php25
-rwxr-xr-xusr/local/www/firewall_rules_edit.php57
-rwxr-xr-xusr/local/www/firewall_shaper.php562
-rwxr-xr-xusr/local/www/firewall_shaper_queues.php286
-rwxr-xr-xusr/local/www/status_queues.php6
-rw-r--r--usr/local/www/wizards/traffic_shaper_wizard.inc1865
-rw-r--r--usr/local/www/wizards/traffic_shaper_wizard.xml182
11 files changed, 3097 insertions, 2407 deletions
diff --git a/etc/inc/config.inc b/etc/inc/config.inc
index 61361dd..032157d 100644
--- a/etc/inc/config.inc
+++ b/etc/inc/config.inc
@@ -217,7 +217,6 @@ function parse_config($parse = false) {
die("Config.xml is corrupted and is 0 bytes. Could not restore a previous backup.");
}
}
-
if($g['booting']) echo ".";
config_lock();
if(!$parse) {
@@ -369,7 +368,6 @@ function parse_config_bootup() {
}
}
}
-
if(filesize("{$g['conf_path']}/config.xml") == 0) {
$last_backup = discover_last_backup();
if($last_backup) {
@@ -380,7 +378,6 @@ function parse_config_bootup() {
die("Config.xml is corrupted and is 0 bytes. Could not restore a previous backup.");
}
}
-
parse_config(true);
if ((float)$config['version'] > (float)$g['latest_config']) {
@@ -498,7 +495,6 @@ function convert_config() {
}
}
}
-
if ($config['version'] == $g['latest_config'])
return; /* already at latest version */
@@ -1144,9 +1140,17 @@ function convert_config() {
$config['version'] = "4.1";
}
-
}
+ /* Convert 4.1 -> 4.2 */
+ if ($config['version'] <= 4.0) {
+ if (isset($config['shaper']))
+ unset($config['shaper']);
+ if (isset($config['ezshaper']))
+ unset($config['ezshaper']);
+
+ $config['version'] = "4.2";
+ }
if ($prev_version != $config['version'])
write_config("Upgraded config version level from {$prev_version} to {$config['version']}");
}
@@ -1608,7 +1612,6 @@ EOD;
EOD;
fclose($fp);
-
if($g['booting'])
return;
@@ -1730,16 +1733,6 @@ function system_start_ftp_helpers() {
/* loop through all interfaces and handle ftp-proxy */
$interface_counter = 0;
- if(isset($config['shaper']['enable'])) {
- if(isset($config['ezshaper']['step5']['p2pcatchall'])) {
- $shaper_queue = "-q qP2PDown";
- } else {
- $downq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['inside_int']);
- $shaper_queue = "-q {$downq}def";
- }
- } else {
- $shaper_queue = "";
- }
foreach ($iflist as $ifent => $ifname) {
/* if the ftp proxy is disabled for this interface then kill ftp-proxy
* instance and continue. note that the helpers for port forwards are
@@ -1750,6 +1743,11 @@ function system_start_ftp_helpers() {
if(stristr($ifname, "opt") <> false)
if(!isset($config['interfaces'][strtolower($ifname)]['enable']))
continue;
+
+ /* Get the ftp queue for this interface */
+ if (isset($config['shaper'][$ifname]['ftpqueue']))
+ $shaper_queue = $config['interfaces'][$ifname]['ftpqueue'];
+
$port = 8021 + $interface_counter;
if(isset($config['interfaces'][$ifname]['disableftpproxy'])) {
/* item is disabled. lets ++ the interface counter and
@@ -1837,6 +1835,7 @@ function cleanup_backupcache($revisions = 30) {
if($newxml == "-1") {
log_error("The backup cache file $backup is corrupted. Unlinking.");
unlink($backup);
+ log_error("The backup cache file $backup is corrupted. Unlinking.");
continue;
}
if($newxml['revision']['description'] == "")
@@ -1990,4 +1989,4 @@ function set_device_perms() {
if($g['booting']) echo ".";
$config = parse_config();
-?> \ No newline at end of file
+?>
diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc
index 114c25d..9c910e7 100644
--- a/etc/inc/filter.inc
+++ b/etc/inc/filter.inc
@@ -5,6 +5,7 @@
Copyright (C) 2004-2006 Scott Ullrich
Copyright (C) 2005 Bill Marquette
Copyright (C) 2006 Peter Allgeyer
+ Copyright (C) 2008 Ermal Lu\xe7i
All rights reserved.
originally part of m0n0wall (http://m0n0.ch/wall)
@@ -38,9 +39,7 @@
require_once("functions.inc");
require_once("pkg-utils.inc");
require_once("notices.inc");
-
-if($config['system']['shapertype'] <> "m0n0")
- require_once ("shaper.inc");
+require_once ("shaper.inc");
/* holds the items that will be executed *AFTER* the filter is fully loaded */
$after_filter_configure_run = array();
@@ -133,26 +132,10 @@ function filter_configure_sync() {
if($g['booting'] == true) echo ".";
update_filter_reload_status("Generating filter rules");
$pfrules = filter_rules_generate();
-
- if (isset($config['shaper']['enable']) and $config['system']['shapertype'] <> "m0n0") {
- /* generate altq interface setup parms */
- if($g['booting'] == true) echo ".";
- update_filter_reload_status("Generating ALTQ interfaces");
- $altq_ints = filter_setup_altq_interfaces();
- /* generate altq queues */
- if($g['booting'] == true) echo ".";
- update_filter_reload_status("Generating ALTQ queues");
- $altq_queues = filter_generate_altq_queues($altq_ints);
- /* generate altq rules */
- if($g['booting'] == true) echo ".";
- /* Setup a default rule that tags ALL packets as unshaped
- * we'll match only unshaped packets in the shaper code later
- * this allows the shaper to be first match
- */
- $pf_altq_rules = "block in all tag unshaped label \"SHAPER: first match rule\"\n";
- update_filter_reload_status("Generating ALTQ rules");
- $pf_altq_rules .= filter_generate_pf_altq_rules();
- }
+ /* generate altq */
+ if($g['booting'] == true) echo ".";
+ update_filter_reload_status("Generating ALTQ queues");
+ $altq_queues = filter_generate_altq_queues();
update_filter_reload_status("Loading filter rules");
@@ -212,13 +195,8 @@ function filter_configure_sync() {
$rules .= "scrub {$mssclamp}\n"; // reassemble all directions
}
- if($config['system']['shapertype'] <> "m0n0") {
- $rules.= "{$altq_ints}\n";
- $rules.= "{$altq_queues}\n";
- }
+ $rules.= "{$altq_queues}\n";
$rules.= "{$natrules}\n";
- if($config['system']['shapertype'] <> "m0n0")
- $rules.= "{$pf_altq_rules}\n";
$rules.= "{$pfrules}\n";
fwrite($fd, $rules);
fclose($fd);
@@ -1018,7 +996,6 @@ function filter_nat_rules_generate() {
if(file_exists("/var/etc/inetd.conf"))
mwexec("rm /var/etc/inetd.conf");
-
touch("/var/etc/inetd.conf");
if (isset($config['nat']['rule'])) {
@@ -1110,17 +1087,11 @@ function filter_nat_rules_generate() {
* routines because if this is the first bootup the filter is not completely configured
* and thus pf is not fully running. otherwise we end up with: ftp-proxy: pf is disabled
*/
- if(isset($config['shaper']['enable'])) {
- if(isset($config['ezshaper']['step5']['p2pcatchall'])) {
- $shaper_queue = "-q qP2PUp ";
- } else {
- $upq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['outside_int']);
- $shaper_queue = "-q {$upq}def ";
- }
- } else {
- $shaper_queue = "";
- }
- $after_filter_configure_run[] = "/usr/local/sbin/ftp-proxy {$shaper_queue}-R {$target} -b {$external_address} -p 21 -P 21";
+ /* Get the ftp queue for this interface */
+ if (isset($config['interfaces'][$rule['interface']]['ftpqueue']))
+ $shaper_queue = $config['interfaces'][$rule['interface']]['ftpqueue'];
+ /* else default queue configured on shaper will get this */
+ $after_filter_configure_run[] = "/usr/local/sbin/pftpx {$shaper_queue} -f {$target} -b {$external_address} -c 21 -g 21";
}
$dontinstallrdr = true;
}
@@ -1375,7 +1346,6 @@ EOD;
require_once('clamav.inc');
$natrules .= clamav_generate_rules('nat');
}
-
if (is_package_installed('frickin') && file_exists('/usr/local/pkg/frickin.inc')) {
require_once ('frickin.inc');
$natrules .= frickin_generate_rules('nat');
@@ -1422,7 +1392,6 @@ function generate_user_filter_rule_arr($rule, $ngcounter) {
$ret['descr'] = "label \"USER_RULE: " . str_replace('"', '', $rule['descr']) . "\"";
else
$ret['descr'] = "label \"USER_RULE\"";
- $ret['ackq'] = get_ack_queue($rule['interface']);
return $ret;
}
@@ -2093,6 +2062,15 @@ function generate_user_filter_rule($rule, $ngcounter) {
/* special reject packet */
$aline['flags'] .= "flags S/SA ";
}
+
+ if ($type == "pass") {
+ if (isset($rule['defaultqueue'])) {
+ $aline['queue'] = " queue (".$rule['defaultqueue'];
+ if (isset($rule['ackqueue']))
+ $aline['queue'] .= ",".$rule['ackqueue'];
+ $aline['queue'] .= ") ";
+ }
+ }
}
/* cache entries */
@@ -2155,7 +2133,7 @@ function generate_user_filter_rule($rule, $ngcounter) {
/* piece together the actual user rule */
$line .= $aline['type'] . $aline['direction'] . $aline['log'] . $aline['quick'] . $aline['interface'] . $aline['reply'] .
$aline['route'] . $aline['prot'] . $aline['src'] . $aline['srcport'] . $aline['os'] . $aline['dst'] .
- $aline['dstport'] . $aline['icmp-type'] . $aline['flags'];
+ $aline['dstport'] . $aline['icmp-type'] . $aline['flags'] . $aline['queue'];
/* is a time based rule schedule attached? */
if($rule['sched']) {
@@ -2628,7 +2606,6 @@ EOD;
if ($oc['ip'] && !(($oc['bridge'] || $isbridged) && isset($config['bridge']['filteringbridge'])))
$ipfrules .= filter_rules_spoofcheck_generate($on, $oc['if'], $oc['sa'], $oc['sn'], $log);
}
-
$ipfrules .= "\nanchor \"spoofing\"\n";
/* block private networks on WAN? */
@@ -2675,7 +2652,7 @@ block in $log quick on \$wan from <bogons> to any label "block bogon networks fr
EOD;
}
-if (!isset($config['shaper']['enable']) && !is_array($config['shaper']['queue']) and $config['system']['shapertype'] <> "m0n0") {
+if (!is_array($config['shaper']['queue']) && count($config['shaper']['queue']) > 0) {
$ipfrules .= <<<EOD
@@ -2822,33 +2799,6 @@ EOD;
$ipfrules .= $table;
}
- /* Shaper rules */
- if (isset($config['shaper']['enable']) && is_array($config['shaper']['queue']) && isset($config['filter']['rule']) and $config['system']['shapertype'] <> "m0n0") {
-
- $ipfrules .= "\n# Anchors for rules that might be matched by queues\n";
-
- /* This is ugly, but we generate one anchor per queue */
- foreach ($config['shaper']['queue'] as $queue) {
- update_filter_reload_status("Creating filter anchor for {$queue['name']} ...");
- /* Add anchor to rules */
- $ipfrules .= "anchor {$queue['name']} tagged {$queue['name']}\n";
- $ipfrules .= "load anchor {$queue['name']} from \"{$g['tmp_path']}/{$queue['name']}.rules\"\n";
- /* Create rules for anchors */
- $fd = fopen("{$g['tmp_path']}/{$queue['name']}.rules", "w");
- /* aliases don't recurse to anchors */
- $line = filter_generate_aliases();
- fwrite($fd, $line);
- foreach($rule_arr as $rule) {
- if($rule['ackq'] != "")
- $line = "{$rule['rule']} queue ({$queue['name']}, {$rule['ackq']}) {$rule['descr']}\n";
- else
- $line = "{$rule['rule']} queue {$queue['name']} {$rule['descr']}\n";
- fwrite($fd, $line);
- }
- fclose($fd);
- }
- }
-
$ipfrules .= "\n# User-defined rules follow\n";
/* Generate user rule lines */
foreach($rule_arr as $rule) {
@@ -2856,13 +2806,6 @@ EOD;
if (!isset($rule['disabled'])) {
$line = $rule['rule'];
if($line <> "") {
- /* Add default queue if we're using the shaper */
- if (isset($config['shaper']['enable']) && is_array($config['shaper']['queue']) and $config['system']['shapertype'] <> "m0n0") {
- $defq = find_default_queue($rule['interface']);
- $ackq = $rule['ackq'];
- if (($defq != "") and ($ackq != ""))
- $line .= " queue ({$defq}, {$ackq}) ";
- }
/* label */
$line .= " {$rule['descr']}";
}
@@ -3069,32 +3012,8 @@ function create_firewall_outgoing_rules_to_itself() {
/* if the interface is pppoe, set the ng0 interface */
update_filter_reload_status("Creating IPsec tunnel items {$tunnel['descr']}...");
$ip = find_interface_ip($int);
- if ($config['interfaces'][$ifname]['ipaddr'] == "pppoe")
+ if ($config['interfaces'][$ifname]['ipaddr'] == "pppoe") {
$int = " { " . filter_translate_type_to_real_interface($ifname) . " ng0 } ";
- if (isset($config['shaper']['enable']) && is_array($config['shaper']['queue']) and $config['system']['shapertype'] <> "m0n0") {
- $ackq = get_ack_queue($ifname);
- $defq = find_default_queue($ifname);
- /* Handle all tagged packets */
- foreach ($config['shaper']['queue'] as $queue) {
- if(!filter_is_queue_being_used_on_interface($queue['name'], $ifname, 'out'))
- continue;
- if ($ackq == "" || $defq == "") {
- /* Shaper must not be enabled on this interface */
- $q = "";
- } else {
- $q = "queue ({$queue['name']}, {$ackq})";
- }
- $rule .="pass out quick on {$int} all keep state tagged {$queue['name']} {$q} label \"let out anything from firewall host itself\"\n";
- }
- /* Handle untagged packets */
- if ($ackq == "" || $defq == "") {
- /* Shaper must not be enabled on this interface */
- $q = "";
- } else {
- $q = "queue ({$defq}, {$ackq})";
- }
- $rule .="pass out quick on {$int} all keep state {$q} label \"let out anything from firewall host itself\"\n";
- } else {
/* first add a rule for the real interface, then for ng0 */
$rule .="pass out quick on {$int} all keep state label \"let out anything from firewall host itself\"\n";
}
@@ -3407,4 +3326,4 @@ function return_vpn_subnet($adr) {
}
-?> \ No newline at end of file
+?>
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index 2b64b80..a06b79e 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -3228,21 +3228,18 @@ function enable_rrd_graphing() {
if ("$ifname" == "wan") {
/* QUEUES, set up the queues databases */
- if (!is_array($config['shaper']['queue'])) {
- $config['shaper']['queue'] = array ();
- }
- $a_queues = & $config['shaper']['queue'];
+ if (!is_array($GLOBALS['allqueue_list']))
+ read_altq_config();
- if (isset ($config['shaper']['enable'])) {
+ if (is_array($config['shaper']['queue'])) {
if (!file_exists("$rrddbpath$ifname$queues")) {
/* create rrd file if it does not exist */
log_error("Create RRD database $rrddbpath$ifname$queues");
$rrdcreate = "$rrdtool create $rrddbpath$ifname$queues --step $rrdqueuesinterval ";
/* loop list of shaper queues */
$q = 0;
- foreach ($a_queues as $queue) {
- $name = $queue['name'];
- $rrdcreate .= "DS:$name:COUNTER:$queuesvalid:0:$downstream ";
+ foreach ($GLOBALS['allqueue_list'] as $qname) {
+ $rrdcreate .= "DS:$qname:COUNTER:$queuesvalid:0:$downstream ";
}
$rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
@@ -3264,9 +3261,8 @@ function enable_rrd_graphing() {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$queuesdrop --step $rrdqueuesdropinterval ";
/* loop list of shaper queues */
$q = 0;
- foreach ($a_queues as $queue) {
- $name = $queue['name'];
- $rrdcreate .= "DS:$name:COUNTER:$queuesdropvalid:0:$downstream ";
+ foreach ($GLOBALS['allqueue_list'] as $queue) {
+ $rrdcreate .= "DS:$queue:COUNTER:$queuesdropvalid:0:$downstream ";
}
$rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
@@ -3285,11 +3281,11 @@ function enable_rrd_graphing() {
$rrdqcommand = "-t ";
$rrducommand = "N";
$q = 0;
- foreach ($a_queues as $queue) {
+ foreach ($GLOBALS['allqueue_list'] as $queue) {
if($q == 0) {
- $rrdqcommand .= "{$queue['name']}";
+ $rrdqcommand .= "{$queue}";
} else {
- $rrdqcommand .= ":{$queue['name']}";
+ $rrdqcommand .= ":{$queue}";
}
$q++;
$rrducommand .= ":U";
@@ -3938,4 +3934,4 @@ function lookup_gateway_interface_by_name($name) {
}
}
-?> \ No newline at end of file
+?>
diff --git a/etc/inc/shaper.inc b/etc/inc/shaper.inc
index 991778f..3169375 100644
--- a/etc/inc/shaper.inc
+++ b/etc/inc/shaper.inc
@@ -1,32 +1,29 @@
<?php
-/* $Id$ */
/*
- shaper.inc
- Copyright (C) 2004-2006 Scott Ullrich
- Copyright (C) 2005-2006 Bill Marquette
- 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.
-
+ Copyright (C) 2004, 2005 Scott Ullrich
+ Copyright (C) 2008 Ermal Lu\xe7i
+ 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 */
@@ -34,647 +31,1817 @@ require_once("functions.inc");
require_once("pkg-utils.inc");
require_once("notices.inc");
-function find_default_queue($interface) {
- global $config, $queue_cache;
- $qconfig = $config;
-
- /* quick return if we've already seen the default queue for this interface */
- if (isset($queue_cache['defq'][$interface]))
- return $queue_cache['defq'][$interface];
-
- if (is_array($qconfig['shaper']['queue'])) {
- foreach ($qconfig['shaper']['queue'] as $queue) {
- if(isset($queue['defaultqueue']) and ($queue['defaultqueue'] <> "")) {
- /* If this is a child queue */
- if(isset($queue['attachtoqueue'])) {
- if(is_subqueue_used_on_interface($queue['attachtoqueue'], $interface)) {
- $queue_cache['defq'][$interface] = $queue['name'];
- return $queue['name'];
- }
- } else {
- $queue_cache['defq'][$interface] = $queue['name'];
- return $queue['name'];
- }
- }
- }
- }
+/*
+ * I admit :) this is derived from xmplparse.inc StartElement()
+ */
+function &get_reference_to_me_in_config(&$mypath) {
+ global $config;
+
+ $ptr =& $config['shaper'];
+ foreach ($mypath as $indeks) {
+ $ptr =& $ptr['queue'][$indeks];
+ }
- /* unreachable */
- return null;
+ return $ptr;
}
+function unset_object_by_reference(&$mypath) {
+ global $config;
-function get_ack_queue($interface) {
- global $config, $queue_cache;
+ $ptr =& $config['shaper'];
+ for ($i = 0; $i < count($mypath) - 1; $i++) {
+ $ptr =& $ptr['queue'][$mypath[$i]];
+ }
+ unset($ptr['queue'][$mypath[$i]]);
+}
- /* quick return if we've already seen the ack queue for this interface */
- if (isset($queue_cache['ackq'][$interface]))
- return $queue_cache['ackq'][$interface];
+function clean_child_queues($type, $mypath) {
+ $ref = &get_reference_to_me_in_config($mypath);
+
+ switch ($type) {
+ case 'HFSC':
+ /* Nothing to do */
+ break;
+ case 'PRIQ':
+ if (isset($ref['borrow'])) unset($ref['borrow']);
+ if (isset($ref['bandwidth'])) unset($ref['bandwidth']);
+ if (isset($ref['bandwidthtype'])) unset($ref['bandwidthtype']);
+ /* fall through */
+ case 'CBQ':
+ if (isset($ref['realtime'])) unset($ref['realtime']);
+ if (isset($ref['realtime1'])) unset($ref['realtime1']);
+ if (isset($ref['realtime2'])) unset($ref['realtime2']);
+ if (isset($ref['realtime3'])) unset($ref['realtime3']);
+ if (isset($ref['upperlimit'])) unset($ref['upperlimit']);
+ if (isset($ref['upperlimit1'])) unset($ref['upperlimit1']);
+ if (isset($ref['upperlimit2'])) unset($ref['upperlimit2']);
+ if (isset($ref['upperlimit3'])) unset($ref['upperlimit3']);
+ if (isset($ref['linkshare'])) unset($ref['linkshare']);
+ if (isset($ref['linkshare1'])) unset($ref['linkshare1']);
+ if (isset($ref['linkshare2'])) unset($ref['linkshare2']);
+ if (isset($ref['linkshare3'])) unset($ref['linkshare3']);
+ break;
+ }
+}
- $qconfig = $config;
+function cleanup_queue_from_rules($queue) {
+ global $config;
- if (is_array($qconfig['shaper']['queue'])) {
- foreach ($qconfig['shaper']['queue'] as $queue) {
- if(isset($queue['ack']))
- if(isset($queue['attachtoqueue']))
- if(is_subqueue_used_on_interface($queue['attachtoqueue'], $interface)) {
- /* Add to cache */
- $queue_cache['ackq'][$interface] = $queue['name'];
- return $queue['name'];
+ foreach ($config['filter']['rule'] as $rule) {
+ if ($rule['defaultqueue'] == $queue)
+ unset($rule['defaultqueue']);
+ if ($rule['ackqueue'] == $queue)
+ unset($rule['ackqueue']);
+ }
+ foreach ($config['interfaces'] as $if => $ifdata) {
+ if ($ifdata['ftpqueue'] == $queue) {
+ unset($config['interfaces'][$if]['ftpqueue']);
+ break;
}
- }
}
- /* unreachable */
- return null;
}
-function filter_generate_altq_queues($altq_ints) {
- global $config;
- $altq_rules = "";
- if (is_array($config['shaper']['queue'])) {
- foreach ($config['shaper']['queue'] as $rule) {
- update_filter_reload_status("Generating ALTQ queue {$rule['descr']}...");
- $options = "";
- // check to make sure we're actually using this queue.
- //if(stristr($altq_ints, $rule['name']) !== FALSE) {
- $altq_rules .= "queue {$rule['name']} ";
- if (isset($rule['bandwidth']) and $rule['bandwidth'] <> "")
- $altq_rules .= "bandwidth {$rule['bandwidth']}{$rule['bandwidthtype']} ";
- if (isset($rule['priority']) and $rule['priority'] <> "")
- $altq_rules .= "priority {$rule['priority']} ";
- if (isset($rule['qlimit']) and $rule['qlimit'] <> "")
- $altq_rules .= "qlimit {$rule['qlimit']} ";
- if(isset($rule['red']) and $rule['red'] <> "")
- $options .= " red";
- if(isset($rule['borrow']) and $rule['borrow'] <> "")
- $options .= " borrow";
- if(isset($rule['ecn']) and $rule['ecn'] <> "")
- $options .= " ecn";
- if(isset($rule['rio']) and $rule['rio'] <> "")
- $options .= " rio";
- if(isset($rule['defaultqueue']) and $rule['defaultqueue'] <> "")
- $options .= " default";
- if(isset($rule['upperlimit']) and $rule['upperlimit'] <> "") {
- if ($rule['upperlimit1'] <> "")
- $options .= " upperlimit({$rule['upperlimit1']} {$rule['upperlimit2']} {$rule['upperlimit3']})";
- else
- $options .= " upperlimit {$rule['upperlimit3']}";
- }
- if(isset($rule['linkshare']) and $rule['linkshare'] <> "") {
- if ($rule['linkshare1'] <> "")
- $options .= " linkshare({$rule['linkshare1']} {$rule['linkshare2']} {$rule['linkshare3']})";
- else
- $options .= " linkshare {$rule['linkshare3']}";
- }
- if(isset($rule['realtime']) and $rule['realtime'] <> "") {
- if ($rule['realtime1'] <> "")
- $options .= " realtime({$rule['realtime1']} {$rule['realtime2']} {$rule['realtime3']})";
- else
- $options .= " realtime {$rule['realtime3']}";
- }
- $scheduler_type = $config['shaper']['schedulertype'];
- $altq_rules .= "{$scheduler_type} ";
- if($options)
- $altq_rules .= "( {$options} )";
- $fsq="";
- foreach($config['shaper']['queue'] as $q) {
- if($q['attachtoqueue'] == $rule['name']) {
- if($fsq == "") {
- $altq_rules .= "{ ";
- }
- else if($fsq == "1") {
- $altq_rules .= ", ";
+class altq_root_queue {
+ var $interface;
+ var $tbrconfig ;
+ var $bandwidth;
+ var $bandwidthtype; /* b, Kb, Mb */
+ var $scheduler;
+ var $qlimit;
+ var $queues = array();
+ var $qenabled;
+ var $link;
+ var $default_present; /* if we have a default queue set */
+
+ /* Accesor functions */
+ function SetDefaultQueuePresent($value) {
+ $this->default_present = $value;
+ }
+ function GetDefaultQueuePresent() {
+ return trim($this->default_present);
+ }
+ function SetLink($link) {
+ $this->link = $link;
+ }
+ function GetLink() {
+ return $this->link;
+ }
+ function GetEnabled() {
+ return $this->qenabled;
+ }
+ function SetEnabled($value = false) {
+ $this->qenabled = $value;
+ }
+ function CanHaveChilds() {
+ return true;
+ }
+ function CanBeDeleted() {
+ return false;
+ }
+ function GetQname() {
+ return $this->interface;
+ }
+ function SetQname($name) {
+ $this->interface = trim($name);
+ }
+ function GetInterface() {
+ return $this->interface;
+ }
+ function SetInterface($name) {
+ $this->interface = trim($name);
+ }
+ function GetTbrConfig() {
+ return $this->tbrconfig;
+ }
+ function SetTbrConfig($tbrconfig) {
+ $this->tbrconfig = $tbrconfig;
+ }
+ function GetBandwidth() {
+ return $this->bandwidth;
+ }
+ function SetBandwidth($bw) {
+ $this->bandwidth = trim($bw);
+ }
+ function GetBwscale() {
+ return $this->bandwidthtype;
+ }
+ function SetBwscale($bwscale) {
+ $this->bandwidthtype = $bwscale;
+ }
+ function GetScheduler() {
+ return $this->scheduler;
+ }
+ function SetScheduler($scheduler) {
+ $this->scheduler = trim($scheduler);
+ }
+ function GetQlimit() {
+ return $this->qlimit;
+ }
+ function SetQlimit($limit) {
+ $this->qlimit = $limit;
+ }
+
+ function validate_input($data, &$input_errors) {
+
+ do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
+
+ if ($data['qlimit'] && (!is_numeric($data['qlimit'])))
+ $input_errors[] = "Qlimit must be an integer.";
+ if ($data['tbrconfig'] && (!is_numeric($data['tbrconfig'])))
+ $input_errors[] = "Qlimit must be an integer.";
+
+ }
+
+
+ /* Implement this to shorten some code on the frontend page */
+ function ReadConfig(&$conf) {
+ if (isset($conf['tbrconfig']))
+ $this->SetTbrConfig($conf['tbrconfig']);
+ if ($conf['bandwidth']) {
+ $this->SetBandwidth($conf['bandwidth']);
+ if ($conf['bandwidthtype'])
+ $this->SetBwscale($conf['bandwidthtype']);
+ }
+ if (isset($conf['scheduler'])) {
+ if ($this->GetScheduler() != $conf['scheduler']) {
+ foreach ($this->queues as $q) {
+ clean_child_queues($conf['scheduler'], $this->GetLink());
+ $q->clean_queue($conf['scheduler']);
}
- $altq_rules .= $q['name'];
- $fsq = "1";
}
+ $this->SetScheduler($conf['scheduler']);
}
- if($fsq == "1")
- $altq_rules .= " }";
- $altq_rules .= "\n";
- //}
- }
+ if (isset($conf['qlimit']))
+ $this->SetQlimit($conf['qlimit']);
+ if (isset($conf['name']))
+ $this->SetQname($conf['name']);
+ $this->SetEnabled($conf['enabled']);
+
+ }
+
+ function copy_queue($interface, &$queue) {
+ global $config;
+
+ $mylink = &get_reference_to_me_in_config($this->GetLink());
+ $link = &get_reference_to_me_in_config($queue->GetLink());
+
+ if ($link && $mylink) {
+ if (!is_array($mylink['queue'][$queue->GetQname()]))
+ $mylink['queue'][$queue->GetQname()] = array();
+
+ foreach ($link as $key => $value)
+ $mylink['queue'][$queue->GetQname()][$key] = $value;
+ }
}
- return $altq_rules;
-}
-/* Find a queue that's attached to this one and see if that queue is used on this interface */
-function is_subqueue_used_on_interface($queuename, $interface) {
- global $config;
- $qconfig = $config;
- if (!is_array($qconfig['shaper']['queue'])) return 0;
-
- foreach ($qconfig['shaper']['queue'] as $queue) {
- if($queue['attachtoqueue'] == $queuename) {
- /* recurse if we're a parent queue */
- if ($queue['parentqueue'] == "on") {
- return is_subqueue_used_on_interface($queue['name'], $interface);
- }
- /* If we're not a parent check to see if the queue is used on this interface */
- $subqueue_interface = filter_is_queue_being_used_on_interface($queue['name'], $interface);
- if ($subqueue_interface != ""){
- return 1;
+ function &add_queue($interface, &$queue, &$path) {
+
+ if (!is_array($this->queues))
+ $this->queues = array();
+
+ switch ($this->GetScheduler()) {
+ case "PRIQ":
+ $q =& new priq_queue();
+ break;
+ case "HFSC":
+ $q =& new hfsc_queue();
+ break;
+ case "CBQ":
+ $q =& new cbq_queue();
+ break;
+ default:
+ /* XXX: but should not happen anyway */
+ return;
+ break;
+ }
+ $q->ReadConfig($queue);
+ $q->SetLink($path);
+ $q->SetInterface($this->GetInterface());
+ $q->SetEnabled("on");
+ $q->SetParent(&$this);
+ $this->queues[$q->GetQname()] = &$q;
+ $GLOBALS['allqueue_list'][] = $q->GetQname();
+ ref_on_altq_queue_list($this->GetQname(), $q->GetQname());
+ if (is_array($queue['queue'])) {
+ foreach ($queue['queue'] as $key1 => $que) {
+ array_push($path, $key1);
+ $q->add_queue($q->GetInterface(), &$que, &$path);
+ array_pop($path);
+ }
+ }
+
+ return $q;
+ }
+
+ /* interface here might be optional */
+ function &find_queue($interface, $qname) {
+ if ($qname == $this->GetQname()) {
+ return $this;
+ }
+ foreach ($this->queues as $q) {
+ $result =& $q->find_queue("", $qname);
+ if ($result)
+ return $result;
+ }
+ }
+
+ function &find_parentqueue($interface, $qname) {
+ if ($qname == $interface) {
+ $result = NULL;
+ } else if ($this->queues[$qname]) {
+ $result = $this;
+ } else if ($this->GetScheduler() <> "PRIQ") {
+ foreach ($this->queues as $q) {
+ $result = $q->find_parentqueue("", $qname);
+ if ($result)
+ return $result;
}
}
}
- return 0;
-}
-function filter_is_queue_being_used_on_interface($queuename, $interface, $direction = 'in') {
- global $config;
- $lconfig = $config;
+ function build_tree() {
+ $tree = " <li><a href=\"firewall_shaper.php?interface=".$this->GetInterface()."&queue=". $this->GetInterface()."&action=show";
+ $tree .= "\">" . $this->GetInterface() . "</a>";
+ if (is_array($this->queues)) {
+ $tree .= "<ul>";
+ foreach ($this->queues as $q) {
+ $tree .= $q->build_tree();
+ }
+ $tree .= "</ul>";
+ }
+ $tree .= "</li>";
+ return $tree;
+ }
+
+ function delete_queue() {
+ foreach ($this->queues as $q)
+ $q->delete_queue();
+ unset_object_by_reference($this->GetLink());
+ }
+
+ /*
+ * First it spits:
+ * altq on $interface ..............
+ * then it goes like
+ * foreach ($queues as $qkey => $queue)
+ * this->queues[$qkey]->build_rule();
+ */
+ function build_rules() {
+ if (count($this->queues) > 0 && $this->GetEnabled()) {
+ $rules = " altq on " . convert_friendly_interface_to_real_interface_name($this->GetInterface());
+ if ($this->GetScheduler())
+ $rules .= " ".strtolower($this->GetScheduler());
+ if ($this->GetBandwidth())
+ $rules .= " bandwidth ".trim($this->GetBandwidth());
+ if ($this->GetBwscale())
+ $rules .= $this->GetBwscale();
+ if ($this->GetTbrConfig())
+ $rules .= " tbrsize ".$this->GetTbrConfig();
+ if (count($this->queues)) {
+ $i = count($this->queues);
+ $rules .= " queue { ";
+ foreach ($this->queues as $qkey => $qnone) {
+ if ($i > 1) {
+ $i--;
+ $rules .= " {$qkey}, ";
+ } else
+ $rules .= " {$qkey} ";
+ }
+ $rules .= " } \n";
+ foreach ($this->queues as $q) {
+ $rules .= $q->build_rules();
+ }
+ }
+ }
+ $rules .= " \n";
+ return $rules;
+ }
+
+ function build_javascript() {
+ $javascript = "<script type=\"text/javascript\">";
+ $javascript .= "function mySuspend() {";
+ $javascript .= "if (document.layers && document.layers['shaperarea'] != null);";
+ $javascript .= "document.layers['shaperarea'].visibility = 'hidden';";
+ $javascript .= "else if (document.all)";
+ $javascript .= "document.all['shaperarea'].style.visibility = 'hidden';";
+ $javascript .= "}";
+
+ $javascript .= "function myResume() {";
+ $javascript .= "if (document.layers && document.layers['shaperarea'] != null)";
+ $javascript .= "document.layers['shaperarea'].visibility = 'visible';";
+ $javascript .= "else if (document.all)";
+ $javascript .= "document.all['shaperarea'].style.visibility = 'visible';";
+ $javascript .= "}";
+ $javascript .= "</script>";
+
+ return $javascript;
+ }
+
+ /*
+ * For requesting the parameters of the root queue
+ * to the user like the traffic wizard does.
+ */
+ function build_form() {
+ $form = "<tr><td valign=\"top\" class=\"vncellreq\"><br><span class=\"vexpl\">Name</span></td>";
+ $form .= "<td class=\"vncellreq\">";
+ $form .= "<strong>".$this->GetQname()."</strong>";
+ $form .= "</td></tr>";
+ $form .= "<tr><td valign=\"top\" class=\"vncellreq\">Scheduler Type ";
+ $form .= "</td>";
+ $form .= "<td class=\"vncellreq\">";
+ $form .= "<select id=\"scheduler\" name=\"scheduler\" class=\"formselect\">";
+ $form .= "<option value=\"HFSC\"";
+ if ($this->GetScheduler() == "HFSC")
+ $form .= " selected=\"yes\"";
+ $form .= ">HFSC</option>";
+ $form .= "<option value=\"CBQ\"";
+ if ($this->GetScheduler() == "CBQ")
+ $form .= " selected=\"yes\"";
+ $form .= ">CBQ</option>";
+ $form .= "<option value=\"PRIQ\"";
+ if ($this->GetScheduler() == "PRIQ")
+ $form .= " selected=\"yes\"";
+ $form .= ">PRIQ</option>";
+ $form .= "</select>";
+ $form .= "<br> <span class=\"vexpl\">";
+ $form .= "NOTE: changing this changes all queues underneath!";
+ $form .= " Beaware you can loose information.";
+ $form .= "</span>";
+ $form .= "</td></tr>";
+ $form .= "<tr><td valign=\"top\" class=\"vncellreq\">Bandwidth";
+ $form .= "</td><td class=\"vncellreq\">";
+ $form .= "<input type=\"text\" id=\"bandwidth\" name=\"bandwidth\" value=\"";
+ $form .= $this->GetBandwidth() . "\">";
+ $form .= "<select id=\"bandwidthtype\" name=\"bandwidthtype\" class=\"formselect\">";
+ $form .= "<option value=\"Kb\"";
+ if ($this->GetBwscale() == "Kb")
+ $form .= "selected=\"yes\"";
+ $form .= ">Kbit/s</option>";
+ $form .= "<option value=\"Mb\"";
+ if ($this->GetBwscale() == "Mb")
+ $form .= "selected=\"yes\"";
+ $form .= ">Mbit/s</option>";
+ $form .= "<option value=\"\"";
+ if ($this->GetBwscale() == "b")
+ $form .= "selected=\"yes\"";
+ $form .= ">Bit/s</option>";
+ $form .= "<option value=\"\"";
+ if ($this->GetBwscale() == "%")
+ $form .= "selected=\"yes\"";
+ $form .= ">%</option>";
+ $form .= "</select>";
+ $form .= "</td></tr>";
+ $form .= "<tr><td valign=\"top\" class=\"vncellreq\">Queue Limit</td>";
+ $form .= "<td class=\"vncellreq\">";
+ $form .= "<input type=\"text\" id=\"qlimit\" name=\"qlimit\" value=\"";
+ $form .= $this->GetQlimit();
+ $form .= "\">";
+ $form .= "</td></tr>";
+ $form .= "<tr><td valign=\"top\" class=\"vncellreq\">Tbr Size</td>";
+ $form .= "<td class=\"vncellreq\">";
+ $form .= "<input type=\"text\" id=\"tbrconfig\" name=\"tbrconfig\" value=\"";
+ $form .= $this->GetTbrConfig();
+ $form .= "\">";
+ $form .= "<br> <span class=\"vexpl\">";
+ $form .= "Adjusts the size, in bytes, of the token bucket regulator.";
+ $form .= "If not specified, heuristics based on the interface ";
+ $form .= "bandwidth are used to determine the size.";
+ $form .= "</span></td></tr>";
+ $form .= "<input type=\"hidden\" id=\"interface\" name=\"interface\"";
+ $form .= " value=\"" . $this->GetInterface() . "\">";
+ $form .= "<input type=\"hidden\" id=\"name\" name=\"name\" value=\"".$this->GetQname()."\" >";
+
+
+ return $form;
+ }
- if(!is_array($lconfig['shaper']['rule'])) return null;
- foreach($lconfig['shaper']['rule'] as $rule) {
- $q = $direction . 'queue';
- $if = $direction . '-interface';
- if(($rule[$q] == $queuename && $rule[$if] == $interface))
- return $interface;
+ function update_altq_queue_data(&$data) {
+ $this->ReadConfig($data);
}
- return null;
-}
+
+ /*
+ * Should call on each of it queues and subqueues
+ * the same function much like build_rules();
+ */
+ function wconfig() {
+ $cflink = &get_reference_to_me_in_config($this->GetLink());
+ if (!is_array($cflink))
+ $cflink = array();
+ $cflink['interface'] = $this->GetInterface();
+ $cflink['name'] = $this->GetQname();
+ $cflink['scheduler'] = $this->GetScheduler();
+ $cflink['bandwidth'] = $this->GetBandwidth();
+ $cflink['bandwidthtype'] = $this->GetBwscale();
+ $cflink['qlimit'] = $this->GetQlimit();
+ $cflink['tbrconfig'] = $this->GetTbrConfig();
+ $cflink['enabled'] = $this->GetEnabled();
+ }
-function filter_setup_altq_interfaces() {
- global $config;
- $altq_rules = "";
- $queue_names = "";
- $is_first = "";
+}
- if(!is_array($config['shaper']['queue'])) return null;
+class priq_queue {
+ var $qname;
+ var $qinterface;
+ var $qlimit;
+ var $qpriority;
+ var $description;
+ var $isparent;
+ var $qbandwidth;
+ var $qbandwidthtype;
+ var $qdefault;
+ var $qrio;
+ var $qred;
+ var $qecn;
+ var $qack;
+ var $qenabled;
+ var $qparent;
+ var $link;
+
+ /* This is here to help on form building and building rules/lists */
+ var $subqueues = array();
+
+ /* Accesor functions */
+ function SetLink($link) {
+ $this->link = $link;
+ }
+ function GetLink() {
+ return $this->link;
+ }
+ function &GetParent() {
+ return $this->qparent;
+ }
+ function SetParent(&$parent) {
+ $this->qparent = &$parent;
+ }
+ function GetEnabled() {
+ return $this->qenabled;
+ }
+ function SetEnabled($value) {
+ $this->qenabled = $value;
+ }
+ function CanHaveChilds() {
+ return false;
+ }
+ function CanBeDeleted() {
+ return true;
+ }
+ function GetQname() {
+ return $this->qname;
+ }
+ function SetQname($name) {
+ $this->qname = trim($name);
+ }
+ function GetBandwidth() {
+ return $this->qbandwidth;
+ }
+ function SetBandwidth($bandwidth) {
+ $this->qbandwidth = $bandwidth;
+ }
+ function GetInterface() {
+ return $this->qinterface;
+ }
+ function SetInterface($name) {
+ $this->qinterface = trim($name);
+ }
+ function GetQlimit() {
+ return $this->qlimit;
+ }
+ function SetQlimit($limit) {
+ $this->qlimit = $limit;
+ }
+ function GetQpriority() {
+ return $this->qpriority;
+ }
+ function SetQpriority($priority) {
+ $this->qpriority = $priority;
+ }
+ function GetDescription() {
+ return $this->description;
+ }
+ function SetDescription($str) {
+ $this->descritpion = trim($str);
+ }
+ function GetFirstime() {
+ return $this->firsttime;
+ }
+ function SetFirsttime($number) {
+ $this->firsttime = $number;
+ }
+ function GetBwscale() {
+ return $this->qbandwidthtype;
+ }
+ function SetBwscale($scale) {
+ $this->qbandwidthtype = $scale;
+ }
+ function GetDefault() {
+ return $this->qdefault;
+ }
+ function SetDefault($value = false) {
+ $this->qdefault = $value;
+ altq_set_default_queue($this->GetInterface(), "true");
+ }
+ function GetRed() {
+ return $this->qred;
+ }
+ function SetRed($red = false) {
+ $this->qred = $red;
+ }
+ function GetRio() {
+ return $this->qrio;
+ }
+ function SetRio($rio = false) {
+ $this->qrio = $rio;
+ }
+ function GetEcn() {
+ return $this->qecn;
+ }
+ function SetEcn($ecn = false) {
+ $this->qecn = $ecn;
+ }
+ function GetAck() {
+ return $this->qack;
+ }
+ function SetAck($ack = false) {
+ $this->qack = $ack;
+ }
+
+ function build_javascript() {
+ $javascript = "<script type=\"text/javascript\">";
+ $javascript .= "function mySuspend() { \n";
+ $javascript .= "if (document.layers && document.layers['shaperarea'] != null);\n";
+ $javascript .= "document.layers['shaperarea'].visibility = 'hidden';\n";
+ $javascript .= "else if (document.all)\n";
+ $javascript .= "document.all['shaperarea'].style.visibility = 'hidden';\n";
+ $javascript .= "}\n";
+
+ $javascript .= "function myResume() {\n";
+ $javascript .= "if (document.layers && document.layers['shaperarea'] != null)\n";
+ $javascript .= "document.layers['shaperarea'].visibility = 'visible';\n";
+ $javascript .= "else if (document.all)\n";
+ $javascript .= "document.all['shaperarea'].style.visibility = 'visible';\n";
+ $javascript .= "}\n";
+ $javascript .= "</script>";
+
+ return $javascript;
+ }
+
+ /*
+ * Currently this will not be called unless we decide to clonce whole
+ * queue tree on the 'By Queues' view or support drag&drop on the tree/list
+ */
+ function copy_queue($interface, &$queue) {
+ global $config;
+
+ $mylink = &get_reference_to_me_in_config($this->GetLink());
+ $copylink = &get_reference_to_me_in_config($queue->GetLink());
+
+ if ($link && $mylink) {
+ if (!is_array($mylink['queue'][$queue->GetQname()]))
+ $mylink['queue'][$queue->GetQname()] = array();
+
+ foreach ($link as $key => $value)
+ $mylink['queue'][$queue->GetQname()][$key] = $value;
+ }
+ }
+
+ function clean_queue($sched) {
+ clean_child_queues($sched, $this->GetLink());
+ if (is_array($this->subqueues)) {
+ foreach ($this->subqueues as $q)
+ $q->clean_queue($sched);
+ }
+ }
+
+
+
+ function delete_queue() {
+ unref_on_altq_queue_list($this->GetQname());
+ if ($this->GetDefault())
+ altq_set_default_queue($this->GetInterface(), "false");
+ cleanup_queue_from_rules($this->GetQname());
+ unset_object_by_reference($this->GetLink());
+ }
+
+ function &find_queue($interface, $qname) {
+ if ($qname == $this->GetQname())
+ return $this;
+ }
+ function find_parentqueue($interface, $qname) { return; }
+
+ function validate_input($data, &$input_errors) {
+ do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
+
+ if ($data['priority'] && (!is_numeric($data['priority'])
+ || ($data['priority'] < 1) || ($data['priority'] > 15))) {
+ $input_errors[] = "The priority must be an integer between 1 and 15.";
+ }
+ if ($data['qlimit'] && (!is_numeric($data['qlimit'])))
+ $input_errors[] = "Queue limit must be an integer";
+ if ($data['bandwidth'] && (!is_numeric($data['bandwidth'])))
+ $input_errors[] = "Bandwidth must be an integer.";
+ if (!preg_match("/^[a-zA-Z0-9_-]*$/", $data['name']))
+ $input_errors[] = "Queue names must be alphanumeric and _ or - only.";
+
+
+
- $ifdescrs = array('wan', 'lan');
- for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
- $ifdescrs[] = "opt" . $j;
}
- foreach ($ifdescrs as $ifdescr => $ifname) {
- $queue_names = "";
- $is_first = "";
+ function ReadConfig(&$q) {
+ if (isset($q['name']))
+ $this->SetQname($q['name']);
+ if (isset($q['interface']))
+ $this->SetInterface($q['interface']);
+ if ($q['bandwidth']) {
+ $this->SetBandwidth($q['bandwidth']);
+ if ($q['bandwidthtype'])
+ $this->SetBwscale($q['bandwidthtype']);
+ }
+ if (isset($q['qlimit']))
+ $this->SetQlimit($q['qlimit']);
+ if (isset($q['priority']))
+ $this->SetQPriority($q['priority']);
+ if (isset($q['descritption']))
+ $this->SetDescription($q['description']);
+ if ($q['ftpqueue'] == "on")
+ set_is_ftp_queue($this->GetInterface(), $this->GetQname());
+ $this->SetRed($q['red']);
+ $this->SetRio($q['rio']);
+ $this->SetEcn($q['ecn']);
+ $this->SetDefault($q['default']);
+ $this->SetEnabled($conf['enabled']);
+
+ }
+
+ function build_tree() {
+ $tree = " <li><a href=\"firewall_shaper.php?interface=". $this->GetInterface()."&queue=". $this->GetQname()."&action=show";
+ $tree .= "\" ";
+ if ($this->GetDefault())
+ $tree .= " class=\"navlnk\"";
+ $tree .= " >" . $this->GetQname() . "</a>";
+ /*
+ * Not needed here!
+ * if (is_array($queues) {
+ * $tree .= "<ul>";
+ * foreach ($q as $queues)
+ * $tree .= $queues['$q->GetName()']->build_tree();
+ * endforeach
+ * $tree .= "</ul>";
+ * }
+ */
+
+ $tree .= "</li>";
+
+ return $tree;
+ }
+
+ /* Should return something like:
+ * queue $qname on $qinterface bandwidth ....
+ */
+ function build_rules() {
+ $pfq_rule = " queue ". $this->qname;
+ if ($this->GetInterface())
+ $pfq_rule .= " on ".convert_friendly_interface_to_real_interface_name($this->GetInterface());
+ if ($this->GetQpriority())
+ $pfq_rule .= " priority ".$this->GetQpriority();
+ if ($this->GetQlimit())
+ $pfq_rule .= " qlimit " . $this->GetQlimit();
+ if ($this->GetRed() || $this->GetRio() || $this->GetEcn() || $this->GetDefault()) {
+ $pfq_rule .= " priq ( ";
+ if ($this->GetRed()) {
+ $comma = 1;
+ $pfq_rule .= " red ";
+ }
+ if ($this->GetRio()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $comma = 1;
+ $pfq_rule .= " rio ";
+ }
+ if ($this->GetEcn()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $comma = 1;
+ $pfq_rule .= " ecn ";
+ }
+ if ($this->GetDefault()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $pfq_rule .= " default ";
+ }
+ $pfq_rule .= " ) ";
+ }
+
+ $pfq_rule .= " \n";
+
+ return $pfq_rule;
+ }
+
+ /*
+ * To return the html form to show to user
+ * for getting the parameters.
+ * Should do even for first time when the
+ * object is created and later when we may
+ * need to update it.
+ */
+ function build_form() {
+ $form .= "<tr>";
+ $form .= "<td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
+ $form .= "Queue Name</td><td width=\"78%\" class=\"vtable\">";
+ $form .= "<input name=\"name\" type=\"text\" id=\"name\" class=\"formfld unknown\" size=\"15\" value=\"";
+ $form .= htmlspecialchars($this->GetQname());
+ $form .= "\">";
+ $form .= "<br> <span class=\"vexpl\">Enter the name of the queue here. Do not use spaces and limit the size to 15 characters.";
+ $form .= "</span></td>";
+ $form .= "</tr><tr>";
+ $form .= "<td width=\"22%\" valign=\"top\" class=\"vncellreq\">Priority</td>";
+ $form .= "<td width=\"78%\" class=\"vtable\"> <input name=\"priority\" type=\"text\" id=\"priority\" size=\"5\" value=\"";
+ $form .= htmlspecialchars($this->GetQpriority());
+ $form .= "\">";
+ $form .= "<br> <span class=\"vexpl\">For hfsc, the range is 0 to 7. The default is 1. Hfsc queues with a higher priority are preferred in the case of overload.</span></td>";
+ $form .= "</tr>";
+ $form .= "</tr>";
+ $form .= "<td width=\"22%\" valign=\"top\" class=\"vncellreq\">Queue limit</td>";
+ $form .= "<td width=\"78%\" class=\"vtable\"> <input name=\"qlimit\" type=\"text\" id=\"qlimit\" size=\"5\" value=\"";
+ $form .= htmlspecialchars($this->GetQlimit());
+ $form .= "\">";
+ $form .= "<br> <span class=\"vexpl\">Queue limit in packet per second.";
+ $form .= "</span></td>";
+ $form .= "<tr>";
+ $form .= "<td width=\"22%\" valign=\"top\" class=\"vncell\">Scheduler options</td>";
+ $form .= "<td width=\"78%\" class=\"vtable\">";
+ if ($this->GetDefault()) {
+ $form .= "<input type=\"checkbox\" id=\"default\" CHECKED name=\"default\"";
+ $form .= "> Default queue<br>";
+ } else if (count($this->subqueues) < 1) {
+ $form .= "<input type=\"checkbox\" id=\"default\" name=\"default\"";
+ $form .= "> Default queue<br>";
+ }
+ /* XXX: TODO Add check to disable this if it has been set on another queue on this interface. */
+ $form .= "<input type=\"checkbox\" id=\"ftpqueue\" name=\"ftpqueue\" ";
+ if (get_is_ftp_queue($this->GetInterface(), $this->GetQname()))
+ $form .= " CHECKED";
+ $form .= ">Use this queue for the ftp proxy<br>";
+ /* XXX: TODO */
+ $form .= "<input type=\"checkbox\" id=\"red\" name=\"red\"";
+ if($this->GetRed())
+ $form .= " CHECKED";
+ $form .= "> <a target=\"_new\" href=\"http://www.openbsd.org/faq/pf/queueing.html#red\">Random Early Detection</a><br>";
+ $form .= "<input type=\"checkbox\" id=\"rio\" name=\"rio\"";
+ if($this->GetRio())
+ $form .= " CHECKED";
+ $form .= "> <a target=\"_new\" href=\"http://www.openbsd.org/faq/pf/queueing.html#rio\">Random Early Detection In and Out</a><br>";
+ $form .= "<input type=\"checkbox\" id=\"ecn\" name=\"ecn\"";
+ if($this->GetEcn())
+ $form .= " CHECKED";
+ $form .= "> <a target=\"_new\" href=\"http://www.openbsd.org/faq/pf/queueing.html#ecn\">Explicit Congestion Notification</a><br>";
+ $form .= "<span class=\"vexpl\"><br>Select options for this queue";
+ $form .= "</tr><tr>";
+ $form .= "<td width=\"22%\" class=\"vncellreq\">Description</td>";
+ $form .= "<td width=\"78%\" class=\"vtable\">";
+ $form .= "<input type=\"text\" name=\"description\" size=\"50%\" class=\"formfld unknown\" value=\"" . $this->GetDescription() . "\" >";
+ $form .= "</td></tr>";
+ $form .= "<input type=\"hidden\" name=\"interface\" id=\"interface\"";
+ $form .= " value=\"".$this->GetInterface()."\">";
+
+ return $form;
+ }
+
+ function build_shortform() {
+ /* XXX: Hacks in site. Mostly layer violations! */
+ global $g, $altq_list_queues;
+
+ $altq =& $altq_list_queues[$this->GetInterface()];
+ if ($altq)
+ $scheduler = ": " . $altq->GetScheduler();
+ $form = "<tr><td width=\"20%\" class=\"vtable\">";
+ $form .= "<a href=\"firewall_shaper.php?interface" . $this->GetInterface() . "&queue=" . $this->GetInterface()."&action=show\">".$this->GetInterface().": ".$scheduler."</a>";
+ $form .= "</td></tr>";
+ /*
+ * XXX: Hack in sight maybe fix with a class that wraps all
+ * of this layer violations
+ */
+ $form .= "<tr>";
+ $form .= "<td width=\"50%\" class=\"vncellreq\">";
+ $form .= "Bandwidth: " . $this->GetBandwidth().$this->GetBwscale();
+ $form .= "</td><td width=\"50%\"></td></tr>";
+ $form .= "<tr><td width=\"20%\" class=\"vncellreq\">";
+ if ($this->GetQpriority())
+ $form .= "Priority: on </td></tr>";
+ if ($this->GetDefault())
+ $form .= "<tr><td class=\"vncellreq\">Default: on </td></tr>";
+ $form .= "<tr><td width=\"20%\" class=\"vncellreq\">";
+ $form .= "<a href=\"firewall_shaper_queues.php?interface=";
+ $form .= $this->GetInterface() . "&queue=";
+ $form .= $this->GetQname() . "&action=delete\">";
+ $form .= "<img src=\"";
+ $form .= "./themes/".$g['theme']."/images/icons/icon_minus.gif\"";
+ $form .= " width=\"17\" height=\"17\" border=\"0\" title=\"Delete queue from interface\">";
+ $form .= "<span>Delete queue from interface</span></a></td></tr>";
+
+ return $form;
- $queue_names = find_root_queue($ifname);
+ }
- if($queue_names <> ""){
- $altq_rules .= "altq on {$config['interfaces'][$ifname]['if']} ";
- $bandwidth_arr = get_queue_bandwidth($queue_names);
- $bandwidth = "bandwidth {$bandwidth_arr['bandwidth']}{$bandwidth_arr['bandwidthtype']}";
- $altq_rules .= "{$config['shaper']['schedulertype']} {$bandwidth} ";
- $altq_rules .= "queue { {$queue_names} }";
- }
- $altq_rules .= "\n";
+ function update_altq_queue_data(&$q) {
+ $this->ReadConfig($q);
+ }
+ function wconfig() {
+ $cflink =& get_reference_to_me_in_config($this->GetLink());
+ if (!is_array($cflink))
+ $cflink = array();
+ $cflink['name'] = $this->GetQname();
+ $cflink['interface'] = $this->GetInterface();
+ $cflink['qlimit'] = $this->GetQlimit();
+ $cflink['priority'] = $this->GetQpriority();
+ $cflink['description'] = $this->GetDescription();
+ $cflink['enabled'] = $this->GetEnabled();
+ $cflink['default'] = $this->GetDefault();
+ $cflink['red'] = $this->GetRed();
+ $cflink['rio'] = $this->GetRio();
+ $cflink['ecn'] = $this->GetEcn();
}
- return $altq_rules;
}
+class hfsc_queue extends priq_queue {
+ /* realtime */
+ var $realtime;
+ var $r_m1;
+ var $r_d;
+ var $r_m2;
+ /* linkshare */
+ var $linkshare;
+ var $l_m1;
+ var $l_d;
+ var $l_m2;
+ /* upperlimit */
+ var $upperlimit;
+ var $u_m1;
+ var $u_d;
+ var $u_m2;
+
+ /*
+ * HFSC can have nested queues.
+ */
+
+ function CanHaveChilds() {
+ return true;
+ }
+ function SetRealtime($r_m1, $r_d, $r_m2) {
+ $this->r_m1 = $r_m1;
+ $this->r_d = $r_d;
+ $this->r_m2 = $r_m2;
+ $this->realtime = "on";
+ }
+ function SetLinkshare($l_m1, $l_d, $l_m2) {
+ $this->l_m1 = $l_m1;
+ $this->l_d = $l_d;
+ $this->l_m2 = $l_m2;
+ $this->linkshare = "on";
+ }
+ function SetUpperlimit($u_m1, $u_d, $u_m2) {
+ $this->u_m1 = $u_m1;
+ $this->u_d = $u_d;
+ $this->u_m2 = $u_m2;
+ $this->upperlimit = "on";
+ }
+ function GetRealtime() {
+ return $this->realtime;
+ }
+ function GetR_m1() {
+ return $this->r_m1;
+ }
+ function GetR_d() {
+ return $this->r_d;
+ }
+ function GetR_m2() {
+ return $this->r_m2;
+ }
+ function GetLinkshare() {
+ return $this->linkshare;
+ }
+ function GetL_m1() {
+ return $this->l_m1;
+ }
+ function GetL_d() {
+ return $this->l_d;
+ }
+ function GetL_m2() {
+ return $this->l_m2;
+ }
+ function GetUpperlimit() {
+ return $this->upperlimit;
+ }
+ function GetU_m1() {
+ return $this->u_m1;
+ }
+ function GetU_d() {
+ return $this->u_d;
+ }
+ function GetU_m2() {
+ return $this->u_m2;
+ }
-/* Find the root queue for an interface */
-function find_root_queue($ifname) {
- global $config;
- $queue_names = "";
- foreach ($config['shaper']['queue'] as $queue) {
- $rule_interface = "";
- $q = $queue;
- /* if we're a parentqueue and aren't attached to another queue we're probably a root */
- if ((isset($q['parentqueue']) && $q['parentqueue'] <> "") && (!isset($q['attachtoqueue']) || $q['attachtoqueue'] == "")) {
- /* Confirm that this is a valid queue for this interface */
- $rule_interface = is_subqueue_used_on_interface($q['name'], $ifname);
- if ($rule_interface == 1) {
- if (strlen($queue_names) > 0)
- $queue_names .= " ";
- $queue_names .= $q['name'];
+ function &add_queue($interface, &$qname, &$path) {
+
+ if (!is_array($this->subqueues))
+ $this->subqueues = array();
+ $q =& new hfsc_queue();
+ $q->ReadConfig($qname);
+ $this->subqueues[$q->GetQname()] =& $q; //new hfsc_queue();
+ $q->SetInterface($this->GetInterface());
+ $q->SetParent(&$this);
+ $q->SetEnabled("on");
+ $q->SetLink($path);
+ $this->subqueues[$q->GetQName()] = $q;
+ $GLOBALS['allqueue_list'][] = $q->GetQname();
+ ref_on_altq_queue_list($this->GetQname(), $q->GetQname());
+ if (is_array($qname['queue'])) {
+ foreach ($qname['queue'] as $key1 => $que) {
+ array_push($path, $key1);
+ $q->add_queue($q->GetInterface(), &$que, &$path);
+ array_pop($path);
}
+ }
+
+ return $q;
+ }
+
+ function delete_queue() {
+ unref_on_altq_queue_list($this->GetQname());
+ if ($this->GetDefault())
+ altq_set_default_queue($this->GetInterface(), "false");
+ cleanup_queue_from_rules($this->GetQname());
+ foreach ($this->subqueues as $q)
+ $q->delete_queue();
+ unset_object_by_reference($this->GetLink());
+ }
+
+ /*
+ * Should search even its childs
+ */
+ function &find_queue($interface, $qname) {
+ if ($qname == $this->GetQname())
+ return $this;
+
+ foreach ($this->subqueues as $q) {
+ $result =& $q->find_queue("", $qname);
+ if ($result)
+ return $result;
+ }
+ }
+
+ function &find_parentqueue($interface, $qname) {
+ if ($this->subqueues[$qname])
+ return $this;
+ foreach ($this->subqueues as $q) {
+ $result = $q->find_parentqueue("", $qname);
+ if ($result)
+ return $result;
}
- }
- return $queue_names;
-}
-
-function get_queue_bandwidth($name) {
- global $config;
- foreach ($config['shaper']['queue'] as $queue) {
- if ($queue['name'] == $name) {
- return array(
- 'bandwidth' => $queue['bandwidth'],
- 'bandwidthtype' => $queue['bandwidthtype']
- );
- }
- }
-}
+ }
+
+ function validate_input($data, &$input_errors) {
+ parent::validate_input($data, $input_errors);
+
+ if ($data['priority'] > 7)
+ $input_errors[] = "Priority must be an integer between 1 and 7.";
+ if ($data['upperlimit1'] <> "" && $data['upperlimit2'] == "")
+ $input_errors[] = ("upperlimit service curve defined but missing burst (d) value");
+ if ($data['upperlimit2'] <> "" && $data['upperlimit1'] == "")
+ $input_errors[] = ("upperlimit service curve defined but missing initial bandwidth (m1) value");
+ if ($data['upperlimit1'] <> "" && !is_valid_shaperbw($data['upperlimit1']))
+ $input_errors[] = ("upperlimit m1 value needs to be Kb, Mb, Gb, or %");
+ if ($data['upperlimit2'] <> "" && !is_numeric($data['upperlimit2']))
+ $input_errors[] = ("upperlimit d value needs to be numeric");
+ if ($data['upperlimit3'] <> "" && !is_valid_shaperbw($data['upperlimit3']))
+ $input_errors[] = ("upperlimit m2 value needs to be Kb, Mb, Gb, or %");
+ if ($data['linkshare1'] <> "" && $data['linkshare2'] == "")
+ $input_errors[] = ("linkshare service curve defined but missing burst (d) value");
+ if ($data['linkshare2'] <> "" && $data['linkshare1'] == "")
+ $input_errors[] = ("linkshare service curve defined but missing initial bandwidth (m1) value");
+ if ($data['linkshare1'] <> "" && !is_valid_shaperbw($data['linkshare1']))
+ $input_errors[] = ("linkshare m1 value needs to be Kb, Mb, Gb, or %");
+ if ($data['linkshare2'] <> "" && !is_numeric($data['linkshare2']))
+ $input_errors[] = ("linkshare d value needs to be numeric");
+ if ($data['linkshare3'] <> "" && !is_valid_shaperbw($data['linkshare3']))
+ $input_errors[] = ("linkshare m2 value needs to be Kb, Mb, Gb, or %");
+ if ($data['realtime1'] <> "" && $data['realtime2'] == "")
+ $input_errors[] = ("realtime service curve defined but missing burst (d) value");
+ if ($data['realtime2'] <> "" && $data['realtime1'] == "")
+ $input_errors[] = ("realtime service curve defined but missing initial bandwidth (m1) value");
+ if ($data['realtime1'] <> "" && !is_valid_shaperbw($data['realtime1']))
+ $input_errors[] = ("realtime m1 value needs to be Kb, Mb, Gb, or %");
+ if ($data['realtime2'] <> "" && !is_numeric($data['realtime2']))
+ $input_errors[] = ("realtime d value needs to be numeric");
+ if ($data['realtime3'] <> "" && !is_valid_shaperbw($data['realtime3']))
+ $input_errors[] = ("realtime m2 value needs to be Kb, Mb, Gb, or %");
-function is_queue_attached_children($name) {
- global $config;
- if (!is_array($config['shaper']['queue'])) return 0;
- foreach ($config['shaper']['queue'] as $queue) {
- if($queue['attachtoqueue'] == $name) return 1;
}
- return 0;
-}
-function queue_interface_recursive($queuename) {
- global $config;
- foreach($config['shaper']['queue'] as $queue) {
- if($queue['attachtoqueue'] == $queuename) {
- $status = queue_interface_recursive($queue['name']);
- if($status <> "") return $status;
+ function ReadConfig(&$cflink) {
+ parent::ReadConfig($cflink);
+ if (isset($cflink['linkshare'])) {
+ $this->SetLinkshare($cflink['linkshare1'], $cflink['linkshare2'], $cflink['linkshare3']);
}
- foreach($config['shaper']['rule'] as $rule) {
- if($rule['inqueue'] == $queuename)
- return $rule['in-interface'];
+ if (isset($cflink['realtime'])) {
+ $this->SetRealtime($cflink['realtime1'], $cflink['realtime2'], $cflink['realtime3']);
}
+ if (isset($cflink['upperlimit'])) {
+ $this->SetUpperlimit($cflink['upperlimit1'], $cflink['upperlimit2'], $cflink['upperlimit3']);
+ }
+ }
+
+ function build_tree() {
+ $tree = " <li><a href=\"firewall_shaper.php?interface=" . $this->GetInterface() ."&queue=" . $this->GetQname()."&action=show";
+ $tree .= "\" ";
+ if ($this->GetDefault())
+ $tree .= " class=\"navlnk\"";
+ $tree .= " >" . $this->GetQname() . "</a>";
+ if (is_array($this->subqueues)) {
+ $tree .= "<ul>";
+ foreach ($this->subqueues as $q) {
+ $tree .= $q->build_tree();
+ }
+ $tree .= "</ul>";
+ }
+ $tree .= "</li>";
+ return $tree;
}
- /* unreachable */
- return null;
-}
+ /* Even this should take childs in consideration */
+ function build_rules() {
+
+ $pfq_rule = " queue ". $this->qname;
+ if ($this->GetInterface())
+ $pfq_rule .= " on ".convert_friendly_interface_to_real_interface_name($this->GetInterface());
+ if ($this->GetBandwidth() && $this->GetBwscale())
+ $pfq_rule .= " bandwidth ".trim($this->GetBandwidth()).$this->GetBwscale();
+
+ if ($this->GetQpriority())
+ $pfq_rule .= " priority " . $this->GetQpriority();
+ if ($this->GetQlimit())
+ $pfq_rule .= " qlimit " . $this->GetQlimit();
+ if ($this->GetDefault() || $this->GetRed() || $this->GetRio() || $this->GetEcn() || $this->GetRealtime() || $this->GetLinkshare() || $this->GetUpperlimit()) {
+ $pfq_rule .= " hfsc ( ";
+ if ($this->GetRed()) {
+ $comma = 1;
+ $pfq_rule .= " red ";
+ }
+ if ($this->GetRio()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $comma = 1;
+ $pfq_rule .= " rio ";
+ }
+ if ($this->GetEcn()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $comma = 1;
+ $pfq_rule .= " ecn ";
+ }
+ if ($this->GetDefault()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $comma = 1;
+ $pfq_rule .= " default ";
+ }
+
+ if ($this->GetRealtime() ) {
+ if ($comma)
+ $pfq_rule .= " , ";
+ $pfq_rule .= "realtime ".$this->GetR_m1() . " " . $this->GetR_d()." ". $this->GetR_m2() ." ";
+ $comma = 1;
+ }
+ if ($this->GetLinkshare()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $pfq_rule .= " linkshare ".$this->GetL_m1(). " ". $this->GetL_d(). " ". $this->GetL_m2(). " ";
+ $comma = 1;
+ }
+ if ($this->GetUpperlimit()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $pfq_rule .= " upperlimit ".$this->GetU_m1()." ". $this->GetU_d()." ". $this->GetU_m2(). " ";
+ }
+ $pfq_rule .= " )\n ";
+ }
+ if (count($this->subqueues)) {
+ $i = count($this->subqueues);
+ $pfq_rule .= " { ";
+ foreach ($this->subqueues as $qkey => $qnone) {
+ if ($i > 1) {
+ $i--;
+ $pfq_rule .= " {$qkey}, ";
+ } else
+ $pfq_rule .= " {$qkey} ";
+ $pfq_rule .= " } \n";
+ foreach ($this->subqueues as $q)
+ $pfq_rule .= $q->build_rules();
+ }
+ }
+
+ $pfq_rule .= " \n";
+
+ return $pfq_rule;
+ }
+
+ function build_javascript() {
+ $javascript = parent::build_javascript();
+ $javascript .= "<script type=\"text/javascript\">";
+ $javascript .= "function enable_realtime(enable_over) { \n";
+ $javascript .= "if (document.form.realtime.checked || enable_over) { \n";
+ $javascript .= "document.form.realtime1.disabled = 0;\n";
+ $javascript .= "document.form.realtime2.disabled = 0;\n";
+ $javascript .= "document.form.realtime3.disabled = 0;\n";
+ $javascript .= " } else { \n";
+ $javascript .= "document.form.realtime1.disabled = 1;\n";
+ $javascript .= "document.form.realtime2.disabled = 1;\n";
+ $javascript .= "document.form.realtime3.disabled = 1;\n";
+ $javascript .= " } \n";
+ $javascript .= " } \n";
+ $javascript .= "function enable_linkshare(enable_over) { \n";
+ $javascript .= "if (document.form.linkshare.checked || enable_over) { \n";
+ $javascript .= "document.form.linkshare1.disabled = 0;\n";
+ $javascript .= "document.form.linkshare2.disabled = 0;\n";
+ $javascript .= "document.form.linkshare3.disabled = 0;\n";
+ $javascript .= " } else { \n";
+ $javascript .= "document.form.linkshare1.disabled = 1;\n";
+ $javascript .= "document.form.linkshare2.disabled = 1;\n";
+ $javascript .= "document.form.linkshare3.disabled = 1;\n";
+ $javascript .= " } \n";
+ $javascript .= " } \n";
+ $javascript .= "function enable_upperlimit(enable_over) { \n";
+ $javascript .= "if (document.form.upperlimit.checked || enable_over) { \n";
+ $javascript .= "document.form.upperlimit1.disabled = 0;\n";
+ $javascript .= "document.form.upperlimit2.disabled = 0;\n";
+ $javascript .= "document.form.upperlimit3.disabled = 0;\n";
+ $javascript .= " } else { \n";
+ $javascript .= "document.form.upperlimit1.disabled = 1;\n";
+ $javascript .= "document.form.upperlimit2.disabled = 1;\n";
+ $javascript .= "document.form.upperlimit3.disabled = 1;\n";
+ $javascript .= " } \n";
+
+ $javascript .= "} \n";
+ $javascript .= "</script>";
+ return $javascript;
+ }
-function is_subqueue($name) {
- global $config;
- $queues = $config['shaper']['queue']; /* must assign to keep from corrupting in memory $config */
- if (!is_array($queues)) return 0;
- foreach ($queues as $queue) {
- if($queue['attachtoqueue'] == $name) return 1;
+ function build_form() {
+ $form = "<tr>";
+ $form .= "<td valign=\"top\" class=\"vncellreq\">Bandwidth</td>";
+ $form .= "<td class=\"vtable\"> <input name=\"bandwidth\" id=\"bandwidth\" class=\"formfld unknown\" value=\"";
+ $form .= htmlspecialchars($this->GetBandwidth());
+ $form .= "\">";
+ $form .= "<select name=\"bandwidthtype\" id=\"bandwidthtype\" class=\"formselect\">";
+ $form .= "<option value=\"Mb\"";
+ if (stristr($this->GetBwscale(),"Mb"))
+ $form .= " selected=\"yes\"";
+ $form .= ">Mbit/s</option>";
+ $form .= "<option value=\"Kb\"";
+ if (stristr($this->GetBwscale(),"Kb"))
+ $form .= " selected=\"yes\"";
+ $form .= ">Kbit/s</option>";
+ $form .= "<option value=\"\"";
+ if (stristr($this->GetBwscale(),"b"))
+ $form .= " selected=\"yes\"";
+ $form .= ">Bit/s</option>";
+ $form .= "<option value=\"\"";
+ if (stristr($this->GetBwscale(),"%"))
+ $form .= " selected=\"yes\"";
+ $form .= ">%</option>";
+ $form .= "</select> <br>";
+ $form .= "<span class=\"vexpl\">Choose the amount of bandwidth for this queue";
+ $form .= "</span></td>";
+ $form .= parent::build_form();
+ $form .= "<tr>";
+ $form .= "<td width=\"22%\" valign=\"top\" class=\"vncellreq\">Service Curve (sc)</td>";
+ $form .= "<td width=\"78%\" class=\"vtable\">";
+ $form .= "<table>";
+ $form .= "<tr><td>&nbsp;</td><td><center>m1</center></td><td><center>d</center></td><td><center><b>m2</b></center></td></tr>";
+ $form .= "<tr><td><input type=\"checkbox\" id=\"upperlimit\" name=\"upperlimit\"";
+ if($this->GetUpperlimit())
+ $form .= " CHECKED ";
+ $form .= "onChange=\"enable_upperlimit()\"> Upperlimit:</td><td><input size=\"6\" value=\"";
+ $form .= htmlspecialchars($this->GetU_m1());
+ $form .= "\" id=\"upperlimit1\" name=\"upperlimit1\" ";
+ if (!$this->GetUpperlimit()) $form .= " disabled";
+ $form .= "></td><td><input size=\"6\" value=\"";
+ $form .= htmlspecialchars($this->GetU_d());
+ $form .= "\" id=\"upperlimi2\" name=\"upperlimit2\" ";
+ if (!$this->GetUpperlimit()) $form .= " disabled";
+ $form .= "></td><td><input size=\"6\" value=\"";
+ $form .= htmlspecialchars($this->GetU_m2());
+ $form .= "\" id=\"upperlimit3\" name=\"upperlimit3\" ";
+ if (!$this->GetUpperlimit()) $form .= " disabled";
+ $form .= "></td><td>The maximum allowed bandwidth for the queue.</td></tr>";
+ $form .= "<tr><td><input type=\"checkbox\" id=\"realtime\" name=\"realtime\"";
+ if($this->GetRealtime())
+ $form .= " CHECKED ";
+ $form .= "onChange=\"enable_realtime()\"> Real time:</td><td><input size=\"6\" value=\"";
+ $form .= htmlspecialchars($this->GetR_m1());
+ $form .= "\" id=\"realtime1\" name=\"realtime1\" ";
+ if (!$this->GetRealtime()) $form .= " disabled";
+ $form .= "></td><td><input size=\"6\" value=\"";
+ $form .= htmlspecialchars($this->GetR_d());
+ $form .= "\" id=\"realtime2\" name=\"realtime2\" ";
+ if (!$this->GetRealtime()) $form .= " disabled";
+ $form .= "></td><td><input size=\"6\" value=\"";
+ $form .= htmlspecialchars($this->GetR_m2());
+ $form .= "\" id=\"realtime3\" name=\"realtime3\" ";
+ if (!$this->GetRealtime()) $form .= " disabled";
+ $form .= "></td><td>The minimum required bandwidth for the queue.</td></tr>";
+ $form .= "<tr><td><input type=\"checkbox\" id=\"linkshare\" id=\"linkshare\" name=\"linkshare\"";
+ if($this->GetLinkshare())
+ $form .= " CHECKED ";
+ $form .= "onChange=\"enable_linkshare()\"> Link share:</td><td><input size=\"6\" value=\"";
+ $form .= htmlspecialchars($this->GetL_m1());
+ $form .= "\" id=\"linkshare1\" name=\"linkshare1\" ";
+ if (!$this->GetLinkshare()) $form .= " disabled";
+ $form .= "></td><td><input size=\"6\" value=\"";
+ $form .= htmlspecialchars($this->GetL_d());
+ $form .= "\" id=\"linkshare2\" name=\"linkshare2\" ";
+ if (!$this->GetLinkshare()) $form .= " disabled";
+ $form .= "></td><td><input size=\"6\" value=\"";
+ $form .= htmlspecialchars($this->GetL_m2());
+ $form .= "\" id=\"linkshare3\" name=\"linkshare3\" ";
+ if (!$this->GetLinkshare()) $form .= " disabled";
+ $form .= "></td><td>The bandwidth share of a backlogged queue - this overrides priority.</td></tr>";
+ $form .= "</table><br>";
+ $form .= "The format for service curve specifications is (m1, d, m2). m2 controls";
+ $form .= "the bandwidth assigned to the queue. m1 and d are optional and can be";
+ $form .= "used to control the initial bandwidth assignment. For the first d milliseconds the queue gets the bandwidth given as m1, afterwards the value";
+ $form .= "given in m2.";
+ $form .= "</span></td>";
+ $form .= "</tr>";
+
+ return $form;
+ }
+
+ function update_altq_queue_data(&$data) {
+ $this->ReadConfig($data);
}
- return 0;
-}
-function filter_altq_get_queuename($queuenum) {
- global $config;
- $x=0;
- foreach($config['shaper']['queue'] as $rule) {
- if($x == $queuenum)
- return $rule['name'];
- $x++;
- }
- /* unreachable */
- return null;
+ function wconfig() {
+ $cflink =& get_reference_to_me_in_config($this->GetLink());
+ if (!is_array($cflink))
+ $cflink = array();
+ $cflink['name'] = $this->GetQname();
+ $cflink['interface'] = $this->GetInterface();
+ $cflink['qlimit'] = $this->GetQlimit();
+ $cflink['priority'] = $this->GetQpriority();
+ $cflink['description'] = $this->GetDescription();
+ $cflink['bandwidth'] = $this->GetBandwidth();
+ $cflink['bandwidthtype'] = $this->GetBwscale();
+ $cflink['enabled'] = $this->GetEnabled();
+ $cflink['default'] = $this->GetDefault();
+ $cflink['red'] = $this->GetRed();
+ $cflink['rio'] = $this->GetRio();
+ $cflink['ecn'] = $this->GetEcn();
+ if ($this->GetLinkshare()) {
+ $cflink['linkshare'] = "on";
+ $cflink['linkshare3'] = $this->GetL_m2();
+ $cflink['linkshare2'] = $this->GetL_d();
+ $cflink['linkshare1'] = $this->GetL_m1();
+ }
+ if ($this->GetRealtime()) {
+ $cflink['realtime'] = "on";
+ $cflink['realtime3'] = $this->GetR_m2();
+ $cflink['realtime2'] = $this->GetR_d();
+ $cflink['realtime1'] = $this->GetR_m1();
+ }
+ if ($this->GetUpperlimit()) {
+ $cflink['upperlimit'] = "on";
+ $cflink['upperlimit3'] = $this->GetU_m2();
+ $cflink['upperlimit2'] = $this->GetU_d();
+ $cflink['upperlimit1'] = $this->GetU_m1();
+ }
+ }
}
-function filter_generate_pf_altq_rules() {
- /* I don't think we're in IPFW anymore Toto */
- $i = 0;
-
- global $config, $g, $tcpflags;
-
- $lancfg = $config['interfaces']['lan'];
- $pptpdcfg = $config['pptpd'];
- $pppoecfg = $config['pppoe'];
-
- $lanif = $lancfg['if'];
- $wanif = get_real_wan_interface();
-
- $lansa = gen_subnet($lancfg['ipaddr'], $lancfg['subnet']);
- $lansn = $lancfg['subnet'];
-
- /* optional interfaces */
- $optcfg = array();
- generate_optcfg_array($optcfg);
+class cbq_queue extends priq_queue {
+ var $qborrow;
- if ($pptpdcfg['mode'] == "server") {
- $pptpsa = $pptpdcfg['remoteip'];
- $pptpsn = $g['pptp_subnet'];
- if($config['pptp']['pptp_subnet'] <> "")
- $pptpsn = $config['pptp']['pptp_subnet'];
+ function GetBorrow() {
+ return $this->qborrow;
}
-
- if ($pppoecfg['mode'] == "server") {
- $pppoesa = $pppoecfg['remoteip'];
- $pppoesn = $g['pppoe_subnet'];
- if($config['pppoe']['pppoe_subnet'] <> "")
- $pppoesn = $config['pppoe']['pppoe_subnet'];
+ function SetBorrow($borrow) {
+ $this->qborrow = $borrow;
+ }
+ function CanHaveChilds() {
+ return true;
+ }
+
+ function &add_queue($interface, &$qname, &$path) {
+
+ if (!is_array($this->subqueues))
+ $this->subqueues = array();
+ $q =& new cbq_queue();
+ $q->ReadConfig($qname);
+ $q->SetInterface($this->GetInterface());
+ $q->SetParent(&$this);
+ $q->SetEnabled("on");
+ $q->SetLink($path);
+ $this->subqueues[$q->GetQName()] = &$q;
+ $GLOBALS['allqueue_list'][] = $q->GetQname();
+ ref_on_altq_queue_list($this->GetQname(), $q->GetQname());
+ if (is_array($qname['queue'])) {
+ foreach ($qname['queue'] as $key1 => $que) {
+ array_push($path, $key1);
+ $q->add_queue($q->GetInterface(), &$que, &$path);
+ array_pop($path);
+ }
+ }
+
+ return $q;
+ }
+
+ /*
+ * Should search even its childs
+ */
+ function &find_queue($interface, $qname) {
+ if ($qname == $this->GetQname())
+ return $this;
+ foreach ($this->subqueues as $q) {
+ $result =& $q->find_queue("", $qname);
+ if ($result)
+ return $result;
+ }
+ }
+
+ function &find_parentqueue($interface, $qname) {
+ if ($this->subqueues[$qname])
+ return $this;
+ foreach ($this->subqueues as $q) {
+ $result = $q->find_parentqueue("", $qname);
+ if ($result)
+ return $result;
+ }
+ }
+
+ function delete_all() {
+ if (count($this->subqueues)) {
+ foreach ($this->subqueues as $q) {
+ $q->delete_all();
+ unset_object_by_reference($q->GetLink());
+ unset($q);
+ }
+ unset($subqueues);
+ }
+ }
+
+ function delete_queue() {
+ unref_on_altq_queue_list($this->GetQname());
+ if ($this->GetDefault())
+ altq_set_default_queue($this->GetInterface(), "false");
+ cleanup_queue_from_rules($this->GetQname());
+ foreach ($this->subqueues as $q)
+ $q->delete_queue();
+ unset_object_by_reference($this->subqueues[$qname]->GetLink());
+ }
+
+ function validate_input($data, &$input_errors) {
+ parent::validate_input($data, $input_errors);
+ if ($data['priority'] > 7)
+ $input_errors[] = "Priority must be an integer between 1 and 7.
+";
}
- /* generate rules */
- if (isset($config['shaper']['rule']))
- foreach ($config['shaper']['rule'] as $rule) {
+ function ReadConfig(&$q) {
+ parent::ReadConfig($q);
+ if ($q['borrow'])
+ $this->SetBorrow("on");
+ }
+
+ function build_javascript() {
+ return parent::build_javascript();
+ }
- /* don't include disabled rules */
- if (isset($rule['disabled'])) {
- $i++;
- continue;
- }
+ function build_tree() {
+ $tree = " <li><a href=\"firewall_shaper.php?interface=" . $this->GetInterface()."&queue=" . $this->GetQname()."&action=show";
+ $tree .= "\" ";
+ if ($this->GetDefault())
+ $tree .= " class=\"navlnk\"";
+ $tree .= " >" . $this->GetQname() . "</a>";
+ if (is_array($this->subqueues)) {
+ $tree .= "<ul>";
+ foreach ($this->subqueues as $q) {
+ $tree .= $q->build_tree();
+ }
+ $tree .= "</ul>";
+ }
+ $tree .= "</li>";
+ return $tree;
+ }
+
+ /* Even this should take childs in consideration */
+ function build_rules() {
+
+ $pfq_rule = "queue ". $this->qname;
+ if ($this->GetInterface())
+ $pfq_rule .= " on ".convert_friendly_interface_to_real_interface_name($this->GetInterface());
+ if ($this->GetBandwidth() && $this->GetBwscale())
+ $pfq_rule .= " bandwidth ".trim($this->GetBandwidth()).$this->GetBwscale();
+ if ($this->GetQpriority())
+ $pfq_rule .= " priority " . $this->GetQpriority();
+ if ($this->GetQlimit())
+ $pfq_rule .= " qlimit " . $this->GetQlimit();
+ if ($this->GetDefault() || $this->GetRed() || $this->GetRio() || $this->GetEcn() || $this->GetBorrow()) {
+ $pfq_rule .= " cbq ( ";
+ if ($this->GetRed()) {
+ $comma = 1;
+ $pfq_rule .= " red ";
+ }
+ if ($this->GetRio()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $comma = 1;
+ $pfq_rule .= " rio ";
+ }
+ if ($this->GetEcn()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $comma = 1;
+ $pfq_rule .= " ecn ";
+ }
+ if ($this->GetDefault()) {
+ if ($comma)
+ $pfq_rule .= " ,";
+ $comma = 1;
+ $pfq_rule .= " default ";
+ }
+ if ($this->GetBorrow()) {
+ if ($comma)
+ $pfq_rule .= ", ";
+ $pfq_rule .= " borrow ";
+ }
+ $pfq_rule .= " ) ";
+ }
+ if (count($this->subqueues)) {
+ $i = count($this->subqueues);
+ $pfq_rule .= " { ";
+ foreach ($this->subqueues as $qkey => $qnone) {
+ if ($i > 1) {
+ $i--;
+ $pfq_rule .= " {$qkey}, ";
+ } else
+ $pfq_rule .= " {$qkey} ";
+ }
+ $pfq_rule .= " } \n";
+ foreach ($this->subqueues as $q)
+ $pfq_rule .= $q->build_rules();
+ }
+ //}
+ $pfq_rule .= " \n";
+ return $pfq_rule;
+ }
+
+ function build_form() {
+ $form = "<tr>";
+ $form .= "<td valign=\"top\" class=\"vncellreq\">Bandwidth</td>";
+ $form .= "<td class=\"vtable\"> <input name=\"bandwidth\" id=\"bandwidth\" class=\"formfld unknown\" value=\"";
+ if ($this->GetBandwidth() > 0)
+ $form .= htmlspecialchars($this->GetBandwidth());
+ $form .= "\">";
+ $form .= "<select name=\"bandwidthtype\" id=\"bandwidthtype\" class=\"formselect\">";
+ $form .= "<option value=\"Mb\"";
+ if (stristr($this->GetBwscale(),"Mb"))
+ $form .= " selected=\"yes\"";
+ $form .= ">Mbit/s</option>";
+ $form .= "<option value=\"Kb\"";
+ if (stristr($this->GetBwscale(),"Kb"))
+ $form .= " selected=\"yes\"";
+ $form .= ">Kbit/s</option>";
+ $form .= "<option value=\"\"";
+ if (stristr($this->GetBwscale(),"b"))
+ $form .= " selected=\"yes\"";
+ $form .= ">Bit/s</option>";
+ $form .= "<option value=\"\"";
+ if (stristr($this->GetBwscale(),"%"))
+ $form .= " selected=\"yes\"";
+ $form .= ">%</option>";
+ $form .= "</select> <br>";
+ $form .= "<span class=\"vexpl\">Choose the amount of bandwidth for this
+ queue";
+ $form .= "</span></td></tr>";
+ $form .= parent::build_form();
+ $form .= "<tr><td class=\"vncellreq\">Scheduler specific options</td>";
+ $form .= "<td class=\"vtable\"><input type=\"checkbox\" id=\"borrow\" name=\"borrow\"";
+ if($this->GetBorrow() == "on")
+ $form .= " CHECKED ";
+ $form .= "> Borrow from other queues when available<br></td></tr>";
+
+ return $form;
+ }
+
+ function update_altq_queue_data(&$data) {
+ $this->ReadConfig($data);
+ }
- update_filter_reload_status("Generating ALTQ rule {$rule['descr']}...");
+ function wconfig() {
+ $cflink =& get_reference_to_me_in_config($this->GetLink());
+ if (!is_array($cflink))
+ $cflink = array();
+ $cflink['interface'] = $this->GetInterface();
+ $cflink['qlimit'] = $this->GetQlimit();
+ $cflink['priority'] = $this->GetQpriority();
+ $cflink['name'] = $this->GetQname();
+ $cflink['description'] = $this->GetDescription();
+ $cflink['bandwidth'] = $this->GetBandwidth();
+ $cflink['bandwidthtype'] = $this->GetBwscale();
+ $cflink['enabled'] = $this->GetEnabled();
+ $cflink['default'] = $this->GetDefault();
+ $cflink['red'] = $this->GetRed();
+ $cflink['rio'] = $this->GetRio();
+ $cflink['ecn'] = $this->GetEcn();
+ $cflink['borrow'] = $this->GetBorrow();
+ }
+}
- switch($rule['in-interface']) {
- case "pptp": /* does the rule deal with a PPTP interface? */
- if ($pptpdcfg['mode'] != "server") {
- if (($rule['source']['network'] == "pptp") ||
- ($rule['destination']['network'] == "pptp")) {
- $i++;
- continue;
- }
- }
+/*
+ * XXX: TODO Link dummynet(4) in the system.
+ */
- $nif = $g['n_pptp_units'];
- if($config['pptp']['n_pptp_units'] <> "")
- $nif = $config['pptp']['n_pptp_units'];
- $ispptp = true;
- break;
+/*
+ * List of respective objects!
+ */
+$g_pipes_list = array();
+$g_queue_list = array();
+
+class dummynet_class {
+ var $buckets;
+ /* mask parameters */
+ var $dstip;
+ var $srcip;
+ var $dstport;
+ var $srcport;
+ var $dstip6;
+ var $srcip6;
+ var $flowid;
+ /* all masks */
+ var $dnall;
+
+ var $noerror;
+ var $plr;
+ var $queue;
+ var $queue_scale; /* b, Kb */
+ var $red; /* red or gred */
+ /* red parameters */
+ var $w_q;
+ var $min_th;
+ var $max_th;
+ var $max_p;
+
+ function GetBuckets() {
+ return $this->buckets;
+ }
+ function SetBuckets($buckets) {
+ $this->buckets = $buckets;
+ }
+ function GetPlr() {
+ return $this->plr;
+ }
+ function SetPlr($plr) {
+ $this->plr = $plr;
+ }
+ /* function GetBuckets() {
+ return $this->buckets;
+ }
+ function SetBuckets($buckets) {
+ $this->buckets = $buckets;
+ }
+ */
+ /* Can be used or not */
+ function build_rules() { return; }
+ function build_form() { return; }
+ function update_config() { return; }
+ function wconfig() { return; }
+}
- case "pppoe": /* does the rule deal with a PPPOE interface? */
- if ($pppoecfg['mode'] != "server") {
- if (($rule['source']['network'] == "pppoe") ||
- ($rule['destination']['network'] == "pppoe")) {
- $i++;
- continue;
- }
- }
+class dnpipe_class extends dummynet_class {
+ var $pipe_nr;
+ var $bandwidth;
+ var $delay;
- $nif = $g['n_pppoe_units'];
- if($config['pppoe']['n_pppoe_units'] <> "")
- $nif = $config['pppoe']['n_pppoe_units'];
+ function delete_pipe() { return; }
+ function build_rules() { return; }
+ function build_form() { return; }
+ function update_pipe() { return; }
+ function wconfig() { return; }
+}
- $ispppoe = true;
- break;
- default:
- if (strstr($rule['in-interface'], "opt")) {
- if (!array_key_exists($rule['in-interface'], $optcfg)) {
- $i++;
- continue;
- }
- }
- $nif = 1;
- $ispptp = false;
- $ispppoe = false;
- }
+class dnqueue_class extends dummynet_class {
+ var $queue_nr;
+ var $pipe_parent;
+ var $weight;
- 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;
- }
- }
+ function delete_queue() { return; }
+ function build_rules() { return; }
+ function build_form() { return; }
+ function update_queue() { return; }
+ function wconfig() { return; }
+}
- /* check for unresolvable aliases */
- if ($rule['source']['address'] && !alias_expand($rule['source']['address'])) {
- $i++;
- continue;
+/*
+ * XXX: TODO Make a class shaper to hide all these function
+ * from the global namespace.
+ */
+
+/*
+ * This is a layer violation but for now there is no way
+ * i can find to properly do this with PHP.
+ */
+function altq_set_default_queue($interface, $value) {
+ global $altq_list_queues;
+
+ $altq_tmp =& $altq_list_queues[$interface];
+ if ($altq_tmp) {
+ if ($value) {
+ $altq_tmp->SetDefaultQueuePresent("true");
}
- if ($rule['destination']['address'] && !alias_expand($rule['destination']['address'])) {
- $i++;
- continue;
+ else {
+ $altq_tmp->SetDefaultQueuePresent("false");
}
+ }
+}
- $lanip = find_interface_ip($config['interfaces']['lan']['if']);
- $wanip = find_interface_ip(get_real_wan_interface());
-
- for ($iif = 0; $iif < $nif; $iif++) {
- $direction = 'in';
- $line = "pass {$direction} on ";
-
- if ($ispptp) {
- $line .= " ng" . ($iif+1);
- }
- else if($ispppoe) {
- $line .= " ng" . ($iif+1);
- }
- else {
- $friendly_desc = convert_friendly_interface_to_friendly_descr($rule['in-interface']);
- $line .= " \${$friendly_desc} ";
- }
-
- /* get protocol */
- $proto = $rule['protocol'];
- if (isset($proto)) {
- $line .= "proto {$proto} ";
- }
+function altq_get_default_queue($interface) {
+ global $altq_list_queues;
- /* get source address */
- if (isset($rule['source']['any'])) {
- $src = "any";
- } else if ($rule['source']['network']) {
- if (stristr($rule['source']['network'], "opt") == true) {
- $src = $optcfg[$rule['source']['network']]['sa'] . "/" .
- $optcfg[$rule['source']['network']]['sn'];
- } else {
- switch ($rule['source']['network']) {
- case 'wanip':
- $src = $wanip;
- break;
- case 'lanip':
- $src = $lanip;
- break;
- case 'lan':
- $src = "$lansa/$lansn";
- break;
- case 'pptp':
- $src = "$pptpsa/$pptpsn";
- break;
- case 'pppoe':
- $src = "$pppoesa/$pppoesn";
- break;
- }
- }
- } else if ($rule['source']['address']) {
- $src = alias_expand($rule['source']['address']);
- if(!$src)
- $src = $rule['source']['address'];
- }
+ $altq_tmp = $altq_list_queues[$interface];
+ if ($altq_tmp)
+ return $altq_tmp->GetDefaultQueuePresent();
+}
- if (!$src) {
- printf("No source address found in rule $i\n");
- break;
- }
+function get_is_ftp_queue($interface, $qname) {
+ global $config;
- if (isset($rule['source']['not'])) {
+ if (isset($config['interfaces'][$interface]['ftpqueue']) &&
+ $config['interfaces'][$interface]['ftpqueue'] == $qname)
+ return true;
+ return false;
+}
- /*pf is not really happy with this sexy ($src = "!{$src}";) approach of
- * negating a list or macro. So we have to write out a ! on each entry.
- */
+function set_is_ftp_queue($interface, $qname) {
+ global $config;
- /* not very happy with this! but it beats copying this section to
- * several places.
- */
- $alias = alias_expand(substr($src, 1));
+ if (!is_array($config['interfaces'][$interface]['ftpqueue']))
+ $config['interfaces'][$interface]['ftpqueue'] = array();
+ $config['interfaces'][$interface]['ftpqueue'] = $qname;
+}
- if(isset($alias) && stristr($alias, "$")) {
- $alias = alias_expand_value(substr($src, 1));
- $src = "{";
- foreach(preg_split("/[\s]+/", $alias) as $item) {
- if($item != "") {
- $src .= " !{$item}";
- }
- }
- $src .= " }";
- }
- else {
- $src = "!{$src}";
- }
- }
- $line .= "from {$src} ";
-
- /* get source port */
- if (!isset($rule['protocol']) || in_array($rule['protocol'], array("tcp","udp"))) {
- if ($rule['source']['port']) {
- /*
- * Check to see if port is a alias. If so grab it and
- * enclose it in { } to pass to pf.
- *
- * Otherwise combine the portrange into one if its only
- * one item.
- */
- $src = alias_expand($rule['source']['port']);
- if($src <> "") {
- $line .= "port {$src}";
- } else {
- $srcport = explode("-", $rule['source']['port']);
- if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
- $line .= "port {$srcport[0]} ";
- } else {
- $line .= "port {$srcport[0]}:{$srcport[1]} ";
- }
- }
- }
- }
+function ref_on_altq_queue_list($parent, $qname) {
+ if (isset($GLOBALS['queue_list'][$qname]))
+ $GLOBALS['queue_list'][$qname]++;
+ else
+ $GLOBALS['queue_list'][$qname] = 1;
- /* destination address */
- if (isset($rule['destination']['any'])) {
- $dst = "any";
- } else if ($rule['destination']['network']) {
- if (stristr($rule['destination']['network'], "opt") == true) {
- $dst = $optcfg[$rule['destination']['network']]['sa'] . "/" .
- $optcfg[$rule['destination']['network']]['sn'];
- } else {
- switch ($rule['destination']['network']) {
- case 'wanip':
- $dst = $wanip;
- break;
- case 'lanip':
- $dst = $lanip;
- break;
- case 'lan':
- $dst = "$lansa/$lansn";
- break;
- case 'pptp':
- $dst = "$pptpsa/$pptpsn";
- break;
- case 'pppoe':
- $dst = "$pppoesa/$pppoesn";
- break;
- }
- }
- } else if ($rule['destination']['address']) {
- $dst = alias_expand($rule['destination']['address']);
- if(!$dst)
- $dst = $rule['destination']['address'];
- }
+ unref_on_altq_queue_list($parent);
+}
- if (!$dst) {
- printf("No destination address found in rule {$i}. \n");
- print_r($rule['destination']['network']);
- break;
- }
+function unref_on_altq_queue_list($qname) {
+ $GLOBALS['queue_list'][$qname]--;
+ if ($GLOBALS['queue_list'][$qname] <= 1)
+ unset($GLOBALS['queue_list'][$qname]);
+}
- if (isset($rule['destination']['not'])) {
+function read_altq_config() {
+ global $altq_list_queues, $config;
+ $path = array();
+
+ $a_int = &$config['shaper']['queue'];
+
+ $altq_list_queues = array();
+
+ $GLOBALS['allqueue_list'] = array();
+
+ if (!is_array($config['shaper']['queue']))
+ return;
+
+ foreach ($a_int as $key => $conf) {
+ $int = $conf['interface'];
+ $root =& new altq_root_queue();
+ $root->SetInterface($int);
+ $altq_list_queues[$root->GetInterface()] = &$root;
+ $root->ReadConfig($conf);
+ array_push($path, $key);
+ $root->SetLink($path);
+ $GLOBALS['allqueue_list'][] = $root->GetQname();
+ if (is_array($conf['queue'])) {
+ foreach ($conf['queue'] as $key1 => $q) {
+ array_push($path, $key1);
+ $root->add_queue($root->GetInterface(), $q, &$path);
+ array_pop($path);
+ }
+ }
+ array_pop($path);
+ }
+}
- /*pf is not really happy with this sexy ($dst = "!{$dst}";) approach of
- * negating a list or macro. So we have to write out a ! on each entry.
- */
- /* not very happy with this! but it beats copying this section to
- * several places.
- */
- $alias = alias_expand(substr($dst, 1));
- if(isset($alias) && stristr($alias, "$")) {
- $alias = alias_expand_value(substr($dst, 1));
- $dst = "{";
- foreach(preg_split("/[\s]+/", $alias) as $item) {
- if($item != "") {
- $dst .= " !{$item}";
- }
- }
- $dst .= " }";
- }
- else {
- $dst = "!{$dst}";
- }
- }
- $line .= " to {$dst} ";
-
- if (!isset($rule['protocol']) || in_array($rule['protocol'], array("tcp","udp"))) {
- if ($rule['destination']['port']) {
- $dstport = alias_expand($rule['destination']['port']);
- /*
- * Check to see if port is a alias. If so grab it and
- * enclose it in { } to pass to pf.
- *
- * Otherwise combine the portrange into one if its only
- * one item.
- */
- if($dstport <> "") {
- $line .= "port {$dstport}";
- } else {
- $dstport = explode("-", $rule['destination']['port']);
- if ((!$dstport[1]) || ($dstport[0] == $dstport[1])) {
- $dstport = $dstport[0];
- $line .= "port {$dstport} ";
- } else {
- $dstport = "{$dstport[0]}:{$dstport[1]}";
- $line .= "port {$dstport} ";
- }
- }
- }
- }
+function get_interface_list_to_show() {
+ global $altq_list_queues, $config;
+
+ $tree = "";
+ foreach ($config['interfaces'] as $if => $ifdesc) {
+ if ($altq_list_queues[$if])
+ continue;
+ else {
+ if (!is_altq_capable($ifdesc['if']))
+ continue;
+ if (!isset($ifdesc['enable']) && $if != "lan" && $if != "wan")
+ continue;
+ $tree .= " <li><a href=\"firewall_shaper.php?interface=".$if."&action=add\">".$if."</a></li>";
+ }
+ }
+
+ return $tree;
+}
- if ($rule['iptos'])
- $line .= "tos {$rule['iptos']} ";
+function filter_generate_altq_queues() {
+ global $altq_list_queues;
+
+ read_altq_config();
- $inflags = explode(",", $rule['tcpflags']);
- $flags = " flags ";
- foreach ($tcpflags as $tcpflag) {
- if (array_search($tcpflag, $inflags) !== false) {
- $flags .= strtoupper(substr($tcpflag, 0, 1));
- }
- }
- if($flags <> " flags ")
- $line .= "{$flags}/SAFRPU ";
+ $altq_rules = "";
+ foreach ($altq_list_queues as $altq)
+ $altq_rules .= $altq->build_rules();
- $qtag = "{$direction}queue";
- $line .= " keep state tagged unshaped tag {$rule[$qtag]} ";
+ return $altq_rules;
+}
- $line .= "\n";
- $shaperrules .= $line;
- /* setup the outbound queue on the other interface */
- $direction = 'out';
- $qouttag = "{$direction}queue";
+function build_iface_without_this_queue($iface, $qname) {
+ global $g, $altq_list_queues;
- $friendly_desc = convert_friendly_interface_to_friendly_descr($rule['out-interface']);
- $shaperrules .= "pass out on \${$friendly_desc}";
+ $altq =& $altq_list_queues[$iface];
+ if ($altq)
+ $scheduler = ": " . $altq->GetScheduler();
+ $form = "<tr><td width=\"20%\" >";
+ $form .= "<a href=\"firewall_shaper.php?interface" . $iface . "&queue=" . $iface."&action=show\">".$iface.": ".$scheduler."</a>";
+ $form .= "</td></tr>";
+ $form .= "<tr><td width=\"100%\" class=\"vncellreq\">";
+ $form .= "<a href=\"firewall_shaper_queues.php?interface=";
+ $form .= $iface . "&queue=". $qname . "&action=add\">";
+ $form .= "<img src=\"";
+ $form .= "./themes/".$g['theme']."/images/icons/icon_plus.gif\"";
+ $form .= " width=\"17\" height=\"17\" border=\"0\" title=\"Activate queue on this interface\">";
+ $form .= " Activate queue on this interface</a></td></tr>";
- if(isset($proto) && $proto != "") {
- $shaperrules .= " proto {$proto}";
- }
- $shaperrules .= " from any to {$dst}";
- if(isset($dstport) && $dstport != "") {
- $shaperrules .= " port {$dstport}";
- }
- if ($rule['iptos']) {
- $shaperrules .= " tos {$rule['iptos']}";
- }
- if($flags <> " flags ") {
- $shaperrules .= "{$flags}/SAFRPU";
- }
+ return $form;
- $shaperrules .= " keep state tagged {$rule[$qtag]} tag {$rule[$qouttag]}\n";
+}
- unset($src);
- unset($dst);
- unset($srcport);
- unset($dstport);
- }
- $i++;
- }
- return $shaperrules;
-}
+$default_shaper_msg = "<tr><td width=\"80%\" >";
+$default_shaper_msg .= "<strong>Welcome to the pfSense Traffic Shaper.";
+$default_shaper_msg .= "The tree on the left helps you navigate through the";
+$default_shaper_msg .= "queues while the buttons at the bottom, which show actions, are activated accordingly";
+$default_shaper_ms .= " as allowed</strong>";
+$default_shaper_msg .= "</td></tr>";
-?> \ No newline at end of file
+?>
diff --git a/usr/local/www/firewall_rules.php b/usr/local/www/firewall_rules.php
index 51fd476..461b97e 100755
--- a/usr/local/www/firewall_rules.php
+++ b/usr/local/www/firewall_rules.php
@@ -242,13 +242,14 @@ echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript
<tr id="frheader">
<td width="3%" class="list">&nbsp;</td>
<td width="5%" class="list">&nbsp;</td>
- <td width="10%" class="listhdrr">Proto</td>
+ <td width="6%" class="listhdrr">Proto</td>
<td width="15%" class="listhdrr">Source</td>
- <td width="10%" class="listhdrr">Port</td>
+ <td width="7%" class="listhdrr">Port</td>
<td width="15%" class="listhdrr">Destination</td>
- <td width="10%" class="listhdrr">Port</td>
- <td width="5%" class="listhdrr">Gateway</td>
- <td width="5%" class="listhdrr">Schedule</td>
+ <td width="7%" class="listhdrr">Port</td>
+ <td width="5%" class="listhdrr">Gateway</td>
+ <td width="10%" class="listhdrr">Queue</td>
+ <td width="5%" class="listhdrr">Schedule</td>
<td width="22%" class="listhdr">Description</td>
<td width="10%" class="list">
<table border="0" cellspacing="0" cellpadding="1">
@@ -282,6 +283,7 @@ echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript
<td class="listr" style="background-color: #e0e0e0">*</td>
<td class="listr" style="background-color: #e0e0e0">*</td>
<td class="listr" style="background-color: #e0e0e0">*</td>
+ <td class="listr" style="background-color: #e0e0e0">Default</td>
<td class="listr" style="background-color: #e0e0e0">*</td>
<td class="listbg" style="background-color: #990000"><font color="white">Block private networks</td>
<td valign="middle" nowrap class="list">
@@ -576,6 +578,19 @@ echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript
<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
<?=$textss;?><?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])) echo htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']); else echo htmlspecialchars(pprint_port($filterent['gateway'])); ?><?=$textse;?>
</td>
+<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"><?=$textss;?>
+ <?php
+ if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
+ $desc = $filterent['ackqueue'] ;
+ echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&action=show\">{$desc}</a>";
+ $desc = $filterent['defaultqueue'];
+ echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&action=show\">{$desc}</a>";
+ } else if (isset($filterent['defaultqueue'])) {
+ $desc = $filterent['defaultqueue'];
+ echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&action=show\">{$desc}</a>"; }
+ else echo "none";
+ ?><?=$textse;?>
+ </td>
<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"><font color="black">
<?php if ($printicon) { ?><img src="./themes/<?= $g['theme']; ?>/images/icons/<?php echo $image; ?>.gif" title="<?php echo $alttext;?>" border="0"><?php } ?>&nbsp;<?=$textss;?><?php echo $schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?><?php echo $schedule_span_end; ?><?=$textse;?>
</td>
diff --git a/usr/local/www/firewall_rules_edit.php b/usr/local/www/firewall_rules_edit.php
index 290b9dc..2733d52 100755
--- a/usr/local/www/firewall_rules_edit.php
+++ b/usr/local/www/firewall_rules_edit.php
@@ -115,6 +115,10 @@ if (isset($id) && $a_filter[$id]) {
/* Multi-WAN next-hop support */
$pconfig['gateway'] = $a_filter[$id]['gateway'];
+ /* Shaper support */
+ $pconfig['defaultqueue'] = $a_filter[$id]['defaultqueue'];
+ $pconfig['ackqueue'] = $a_filter[$id]['ackqueue'];
+
//schedule support
$pconfig['sched'] = $a_filter[$id]['sched'];
@@ -288,6 +292,13 @@ if ($_POST) {
if( $_POST['proto'] != "tcp" )
$input_errors[] = "OS detection is only valid with protocol tcp.";
+ if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
+ if ($_POST['defaultqueue'] == "none" )
+ $input_errors[] = "You have to select a queue when you select an acknowledge queue too.";
+ else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
+ $input_errors[] = "Acknokledge queue and Queue cannot be the same.";
+ }
+
if (!$input_errors) {
$filterent = array();
$filterent['type'] = $_POST['type'];
@@ -346,6 +357,12 @@ if ($_POST) {
if ($_POST['gateway'] != "") {
$filterent['gateway'] = $_POST['gateway'];
}
+
+ if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
+ $filterent['defaultqueue'] = $_POST['defaultqueue'];
+ if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
+ $filterent['ackqueue'] = $_POST['ackqueue'];
+ }
if ($_POST['sched'] != "") {
$filterent['sched'] = $_POST['sched'];
@@ -883,6 +900,46 @@ include("head.inc");
</td>
</tr>
<tr>
+ <td width="22%" valign="top" class="vncell">Ackqueue/Queue</td>
+ <td width="78%" class="vtable">
+ <select name="ackqueue">
+<?php
+ if (!is_array($altq_list_queues))
+ read_altq_config(); /* XXX: */
+ foreach ($GLOBALS['allqueue_list'] as $q) {
+ echo "<option value=\"$q\"";
+ if ($q == $pconfig['ackqueue']) {
+ $qselected = 1;
+ echo " SELECTED";
+ }
+ echo ">{$q}</option>";
+ }
+ echo "<option value=\"none\"";
+ if (!$qselected) echo " SELECTED";
+ echo " >none</option>";
+?>
+ </select> /
+ <select name="defaultqueue">
+<?php
+ $qselected = 0;
+ foreach ($GLOBALS['allqueue_list'] as $q) {
+ echo "<option value=\"$q\"";
+ if ($q == $pconfig['defaultqueue']) {
+ $qselected = 1;
+ echo " SELECTED";
+ }
+ echo ">{$q}</option>";
+ }
+ echo "<option value=\"none\"";
+ if (!$qselected) echo " SELECTED";
+ echo " >none</option>";
+?>
+ </select>
+ <br />
+ <span class="vexpl">Choose the Acknowledge Queue only if you have selected Queue.</span>
+ </td>
+ </tr>
+ <tr>
<td width="22%" valign="top" class="vncell">Description</td>
<td width="78%" class="vtable">
<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
diff --git a/usr/local/www/firewall_shaper.php b/usr/local/www/firewall_shaper.php
index a035cf2..a82a683 100755
--- a/usr/local/www/firewall_shaper.php
+++ b/usr/local/www/firewall_shaper.php
@@ -1,202 +1,311 @@
<?php
/* $Id$ */
/*
- firewall_shaper.php
- Copyright (C) 2004, 2005 Scott Ullrich
- All rights reserved.
+ firewall_shaper.php
+ Copyright (C) 2004, 2005 Scott Ullrich
+ Copyright (C) 2008 Ermal Luçi
+ All rights reserved.
- Originally part of m0n0wall (http://m0n0.ch/wall)
- Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
- All rights reserved.
+ Originally part of m0n0wall (http://m0n0.ch/wall)
+ Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
+ All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
+ 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.
+ 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.
+ 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.
+ 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'];
+read_altq_config();
+
+$tree = "<ul class=\"tree\" >";
+if (is_array($altq_list_queues)) {
+ foreach ($altq_list_queues as $altq) {
+ $tree .= $altq->build_tree();
+ }
+$tree .= get_interface_list_to_show();
+}
+$tree .= "</ul>";
-function wipe_magic () {
- global $config;
+/*
+ * The whole logic in these code maybe can be specified.
+ * If you find a better way contact me :).
+ */
- /* wipe previous */
- unset($config['shaper']['queue']);
- unset($config['shaper']['rule']);
- $config['shaper']['enable'] = FALSE;
+if ($_GET) {
+ if ($_GET['queue'])
+ $qname = trim($_GET['queue']);
+ if ($_GET['interface'])
+ $interface = trim($_GET['interface']);
+ if ($_GET['action'])
+ $action = $_GET['action'];
+}
+if ($_POST) {
+ if ($_POST['name'])
+ $qname = trim($_POST['name']);
+ if ($_POST['interface'])
+ $interface = trim($_POST['interface']);
+ if ($_POST['parentqueue'])
+ $parentqueue = trim($_POST['parentqueue']);
}
-if ($_POST['remove'] or $_GET['remove']) {
- wipe_magic();
- $savemsg = '<p><span class="red"><strong>Note: The traffic shaper has been disabled.</strong></span><strong><br>';
- touch($d_shaperconfdirty_path);
- unset($config['shaper']['enable']);
- write_config();
- filter_configure();
- Header("Location: index.php");
- exit;
+if ($interface) {
+ $altq = $altq_list_queues[$interface];
+ if ($altq) {
+ $queue =& $altq->find_queue($interface, $qname);
+ if ($queue) {
+ if ($queue->GetEnabled())
+ $can_enable = true;
+ else
+ $can_enable = false;
+ if ($queue->CanHaveChilds() && $can_enable)
+ $can_add = true;
+ else
+ $can_add = false;
+ }
+ } else $addnewaltq = true;
}
-if ($_POST) {
+$output = "<div id=\"shaperarea\" style=\"position:relative\">";
+if ($queue) {
+$output .= "<tr><td valign=\"top\" class=\"vncellreq\"><br>";
+$output .= "Enable/Disable";
+$output .= "</td><td class=\"vncellreq\">";
+$output .= " <input type=\"checkbox\" id=\"enabled\" name=\"enabled\"";
+if ($can_enable)
+ $output .= " CHECKED";
+$output .= " ><span class=\"vexpl\"> Enable/Disable queue and its childs</span>";
+$output .= "</td></tr>";
+}
+$dontshow = false;
+$newqueue = false;
- if ($_POST['submit']) {
- $pconfig = $_POST;
- $config['shaper']['enable'] = $_POST['enable'] ? true : false;
- write_config();
+if ($_GET) {
+ switch ($action) {
+ case "delete":
+ if ($queue) {
+ $queue->delete_queue();
+ write_config();
+ touch($d_shaperconfdirty_path);
+ }
+ header("Location: firewall_shaper.php");
+ exit;
+ break;
+ case "add":
+ /* XXX: Find better way because we shouldn't know about this */
+ if ($altq) {
+ switch ($altq->GetScheduler()) {
+ case "PRIQ":
+ $q = new priq_queue();
+ break;
+ case "HFSC":
+ $q = new hfsc_queue();
+ break;
+ case "CBQ":
+ $q = new cbq_queue();
+ break;
+ default:
+ /* XXX: Happens when sched==NONE?! */
+ $q = new altq_root_queue();
+ break;
+ }
+ } else if ($addnewaltq) {
+ $q = new altq_root_queue();
+ } else
+ $input_errors[] = "Could not create new queue/discipline!";
+
+ if ($q) {
+ $q->SetInterface($interface);
+ $output .= $q->build_form();
+ $output .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
+ $output .= " value=\"".$qname."\">";
+ unset($q);
+ $newqueue = true;
+ }
+ break;
+ case "show":
+ if ($queue)
+ $output .= $queue->build_form();
+ else
+ $input_errors[] = "Queue not found!";
+ break;
+ case "enable":
+ if ($queue) {
+ $queue->SetEnabled("on");
+ $output .= $queue->build_form();
+ write_config();
+ touch($d_shaperconfdirty_path);
+ } else
+ $input_errors[] = "Queue not found!";
+ break;
+ case "disable":
+ if ($queue) {
+ $queue->SetEnabled("");
+ $output .= $queue->build_form();
+ write_config();
+ touch($d_shaperconfdirty_path);
+ } else
+ $input_errors[] = "Queue not found!";
+ break;
+ default:
+ $output .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
+ $dontshow = true;
+ break;
}
+} else if ($_POST) {
+ unset($input_errors);
- 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 ($addnewaltq) {
+ $altq =& new altq_root_queue();
+ $altq->SetInterface($interface);
+ $altq->ReadConfig($_POST);
+ unset($tmppath);
+ $tmppath[] = $altq->GetInterface();
+ $altq->SetLink(&$tmppath);
+ $altq->wconfig();
+ $output .= $altq->build_form();
+ write_config();
+ touch($d_shaperconfdirty_path);
+ } else if ($parentqueue) { /* Add a new queue */
+ $qtmp =& $altq->find_queue($interface, $parentqueue);
+ if ($qtmp) {
+ $tmppath =& $qtmp->GetLink();
+ array_push($tmppath, $qname);
+ $tmp =& $qtmp->add_queue($interface, $_POST, &$tmppath);
+ array_pop($tmppath);
+ $output .= $tmp->build_form();
+ $tmp->wconfig();
+ $can_enable = true;
+ if ($tmp->CanHaveChilds() && $can_enable)
+ $can_add = true;
+ else
+ $can_add = false;
+ write_config();
+ touch($d_shaperconfdirty_path);
+ } else
+ $input_errors[] = "Could not add new queue.";
+ } else if ($_POST['apply']) {
+ write_config();
- if(file_exists($d_shaperconfdirty_path))
- unlink($d_shaperconfdirty_path);
- }
-}
+ $retval = 0;
+ $savemsg = get_std_save_message($retval);
+ /* Setup pf rules since the user may have changed the optimizat
+ion value */
+ config_lock();
+ $retval = filter_configure();
+ config_unlock();
+ if (stristr($retval, "error") <> true)
+ $savemsg = get_std_save_message($retval);
+ else
+ $savemsg = $retval;
-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;
- }
-}
+ enable_rrd_graphing();
+ unlink($d_shaperconfdirty_path);
+ if ($queue)
+ $output .= $queue->build_form();
+ else
+ $output .= $default_shaper_message;
-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;
- }
+ $dontshow = true;
+// header("Location: firewall_shaper.php");
+ // exit;
+ } else if ($queue) {
+ $queue->validate_input($_POST, &$input_errors);
+ if (!$input_errors) {
+ $queue->update_altq_queue_data($_POST);
+ $queue->wconfig();
+ $output .= $queue->build_form();
+ write_config();
+ touch($d_shaperconfdirty_path);
+ } else
+ $input_errors[] = "Could not complete the request.";
+ } else
+ $input_errors[] = "Ummmm nothing to do?!";
} 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();
+ $output .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
+ $dontshow = true;
- /* 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];
+if (!$dontshow || $newqueue) {
- /* 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];
- }
+$output .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
+$output .= "Queue Actions";
+$output .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
- $a_shaper = $a_shaper_new;
- write_config();
- touch($d_shaperconfdirty_path);
- header("Location: firewall_shaper.php");
- exit;
- }
+$output .= "<input type=\"image\" src=\"";
+$output .= "./themes/".$g['theme']."/images/icons/icon_up.gif\"";
+$output .= " width=\"17\" height=\"17\" border=\"0\" title=\"Submit\" >";
+
+if ($can_add || $addnewaltq) {
+ $output .= "<a href=\"firewall_shaper.php?interface=";
+ $output .= $altq->GetInterface() . "&queue=";
+ $output .= $queue->GetQname() . "&action=add\">";
+ $output .= "<img src=\"";
+ $output .= "./themes/".$g['theme']."/images/icons/icon_plus.gif\"";
+ $output .= " width=\"17\" height=\"17\" border=\"0\" title=\"Add queue\">";
+ $output .= "</a>";
+ $output .= "<a href=\"firewall_shaper.php?interface=";
+ $output .= $altq->GetInterface() . "&queue=";
+ $output .= $queue->GetQname() . "&action=delete\">";
+ $output .= "<img src=\"";
+ $output .= "./themes/".$g['theme']."/images/icons/icon_minus.gif\"";
+ $output .= " width=\"17\" height=\"17\" border=\"0\" title=\"Delete a queue\">";
+ $output .= "</a>";
}
+$output .= "</td></tr>";
+$output .= "</div>";
+}
+else
+ $output .= "</div>";
-$pgtitle = array("Firewall","Shaper","Rules");
-include("head.inc");
+$pgtitle = "Firewall: Shaper: By Interface View";
+include("head.inc");
+if ($queue) {
+ echo "<script type=\"text/javascript\">";
+ echo $queue->build_javascript();
+ echo "</script>";
+}
?>
+<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
+<script type="text/javascript" src="./tree/tree.js"></script>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
-<form action="firewall_shaper.php" method="post" name="iform">
-<script type="text/javascript" language="javascript" src="row_toggle.js">
-</script>
+<p class="pgtitle"><?=$pgtitle?></p>
+<div id="inputerrors"></div>
+<?php if ($input_errors) print_input_errors($input_errors); ?>
+
+<form action="firewall_shaper.php" method="post" name="form" id="form">
+
+<script type="text/javascript" language="javascript" src="row_toggle.js"></script>
<?php if ($savemsg) print_info_box($savemsg); ?>
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
<?php print_info_box_np("The traffic shaper configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
@@ -205,133 +314,42 @@ include("head.inc");
<tr><td>
<?php
$tab_array = array();
- $tab_array[0] = array("Rules", true, "firewall_shaper.php");
- $tab_array[1] = array("Queues", false, "firewall_shaper_queues.php");
- $tab_array[2] = array("EZ Shaper wizard", false, "wizard.php?xml=traffic_shaper_wizard.xml");
+ $tab_array[0] = array("Shaper", true, "firewall_shaper.php");
+ //$tab_array[1] = array("Level 2", false, "");
+ $tab_array[1] = array("EZ Shaper wizard", false, "wizard.php?xml=traffic_shaper_wizard.xml");
display_top_tabs($tab_array);
-?>
+?>
</td></tr>
<tr>
<td>
<div id="mainarea">
- <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
- <tr>
- <td class="vtable"><p>
- <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?>>
- <strong>Enable traffic shaper<br>
- </strong></p></td>
- </tr>
- <tr>
- <td>
- <input name="submit" type="submit" class="formbtn" value="Save">
- <input name="remove" type="submit" class="formbtn" id="remove" value="Remove Wizard">
- </td>
-
- </tr>
- </table>
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
- <tr id="frheader">
- <td width="3%" class="list">&nbsp;</td>
- <td width="3%" class="list">&nbsp;</td>
- <td width="5%" class="listhdrrns">If</td>
- <td width="5%" class="listhdrrns">Proto</td>
- <td width="20%" class="listhdrr">Source</td>
- <td width="20%" class="listhdrr">Destination</td>
- <td width="15%" class="listhdrrns">Target</td>
- <td width="25%" class="listhdr">Description</td>
- <td width="10%" class="list"></td>
- </tr>
- <?php $nrules = $i = 0; foreach ($a_shaper as $shaperent): ?>
- <tr valign="top" id="fr<?=$nrules;?>">
- <td class="listt"><input type="checkbox" id="frc<?=$nrules;?>" name="rule[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$nrules;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;"></td>
- <td class="listt" align="center"></td>
- <td class="listlr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';">
- <?php
- $dis = "";
- if (isset($shaperent['disabled'])) {
- $dis = "_d";
- $textss = "<span class=\"gray\">";
- $textse = "</span>";
- } 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['in-interface']]) . "->" . htmlspecialchars($iflabels[$shaperent['out-interface']]);
+ <tr>
+ <td width="25%" valign="top" algin="left">
+ <? $tab_ar = array();
+ $tab_ar[0] = array("Interfaces", true, "firewall_shaper.php");
+ $tab_ar[1] = array("Queues", false, "firewall_shaper_queues.php");
+ display_top_tabs($tab_ar);
+ // customize later display_top_bar($tab_ar, "#A0000F", "#578100"); ?>
+ <?php
+ echo $tree;
+ ?>
+ </td>
+ <td width="75%" valign="top" align="center">
+ <table>
+ <?
+ echo $output;
+ ?>
+ </table>
- echo "<br>";
- echo "<a href=\"?act=toggle&id={$i}\">";
- if ($shaperent['direction'] == "in")
- echo "<img src=\"./themes/".$g['theme']."/images/icons/icon_in{$dis}.gif\" width=\"11\" height=\"11\" border=\"0\" style=\"margin-top: 5px\" title=\"click to toggle enabled/disabled status\">";
- if ($shaperent['direction'] == "out")
- echo "<img src=\"./themes/".$g['theme']."/images/icons/icon_out{$dis}.gif\" width=\"11\" height=\"11\" border=\"0\" style=\"margin-top: 5px\" title=\"click to toggle enabled/disabled status\">";
-
- echo "</a>" . $textse;;
- ?>
- </td>
- <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';">
- <?=$textss;?><?php if (isset($shaperent['protocol'])) echo strtoupper($shaperent['protocol']); else echo "*"; ?><?=$textse;?>
- </td>
- <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';"><?=$textss;?><?php echo htmlspecialchars(pprint_address($shaperent['source'])); ?>
- <?php if ($shaperent['source']['port']): ?><br>
- Port: <?=htmlspecialchars(pprint_port($shaperent['source']['port'])); ?>
- <?php endif; ?><?=$textse;?>
- </td>
- <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';"><?=$textss;?><?php echo htmlspecialchars(pprint_address($shaperent['destination'])); ?>
- <?php if ($shaperent['destination']['port']): ?><br>
- Port: <?=htmlspecialchars(pprint_port($shaperent['destination']['port'])); ?>
- <?php endif; ?><?=$textse;?>
- </td>
- <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';"><?=$textss;?>
- <?php
- if (isset($shaperent['outqueue']) && isset($shaperent['inqueue'])) {
- $desc = htmlspecialchars($shaperent['outqueue']);
- echo "<a href=\"firewall_shaper_queues_edit.php?id={$shaperent['outqueue']}\">{$desc}</a>";
- $desc = htmlspecialchars($shaperent['inqueue']);
- echo "/<a href=\"firewall_shaper_queues_edit.php?id={$shaperent['inqueue']}\">{$desc}</a>";
- }
- ?><?=$textse;?>
- </td>
- <td class="listbg" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';"><font color="white">
- <?=$textss;?><?=htmlspecialchars($shaperent['descr']);?><?=$textse;?>
- &nbsp; </td>
- <td valign="middle" nowrap class="list"> <a href="firewall_shaper_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit rule" width="17" height="17" border="0"></a>
- <?php if ($i > 0): ?>
- <a href="firewall_shaper.php?act=up&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_up.gif" title="move up" width="17" height="17" border="0"></a>
- <?php else: ?>
- <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_up_d.gif" width="17" height="17" border="0">
- <?php endif; ?>
- <input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="move selected rules before this rule" onMouseOver="fr_insline(<?=$nrules;?>, true)" onMouseOut="fr_insline(<?=$nrules;?>, false)"><br>
-
- <input name="del" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" title="delete selected mappings" onclick="return confirm('Do you really want to delete the selected mappings?')">
-
- <?php if (isset($a_shaper[$i+1])): ?>
- <a href="firewall_shaper.php?act=down&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_down.gif" title="move down" width="17" height="17" border="0"></a>
- <?php else: ?>
- <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_down_d.gif" width="17" height="17" border="0">
- <?php endif; ?>
- <a href="firewall_shaper_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add a new rule based on this one" width="17" height="17" border="0"></a>
- </td>
- </tr>
- <?php $nrules++; $i++; endforeach; ?>
- <tr>
- <td class="list" colspan="8"></td>
- <td class="list"> <a href="firewall_shaper_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
- </tr>
- <tr>
- <td colspan="8"><p><span class="red"><strong>Note:</strong></span><strong><br>
- </strong>The first rule that matches a packet will be executed.<br>
- The following match patterns are not shown in the list above:
- IP packet length, TCP flags.<br>
- You can check the results of your queues at <a href="status_queues.php">Status:Queues</a>.</td>
- </tr>
+ </td></tr>
</table>
</div>
</td>
</tr>
</table>
</form>
-<?php include("fend.inc"); ?>
+<?php include("fend.inc");
+?>
</body>
</html>
diff --git a/usr/local/www/firewall_shaper_queues.php b/usr/local/www/firewall_shaper_queues.php
index ca42947..c08d00f 100755
--- a/usr/local/www/firewall_shaper_queues.php
+++ b/usr/local/www/firewall_shaper_queues.php
@@ -3,6 +3,7 @@
/*
firewall_shaper_queues.php
Copyright (C) 2004, 2005 Scott Ullrich
+ Copyright (C) 2008 Ermal Luçi
All rights reserved.
Originally part of m0n0wall (http://m0n0.ch/wall)
@@ -41,130 +42,114 @@ if($_GET['reset'] <> "") {
if (!is_array($config['shaper']['queue'])) {
$config['shaper']['queue'] = array();
}
-$a_queues = &$config['shaper']['queue'];
-/* 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");
+/* on HEAD it has to use vc_* api on variable_cache.inc */
+if (!is_array($GLOBALS['allqueue_list'])) {
+ $GLOBALS['allqueue_list'] = array();
}
-$iflist = array("lan" => "LAN", "wan" => "WAN");
+/* XXX: NOTE: When dummynet is implemented these will be moved from here */
+read_altq_config();
-for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
- $iflist['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
-}
-
-if ($_POST['apply'] || $_POST['submit']) {
- $config['shaper']['enable'] = true;
- 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);
+$tree = "<ul class=\"tree\" >";
+if (is_array($altq_list_queues)) {
+ foreach ($GLOBALS['allqueue_list'] as $queue) {
+ $tree .= "<li><a href=\"firewall_shaper_queues.php?queue={$queue}&action=show\" >{$queue}</a></li>";
+ }
}
-
-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;
- }
+$tree .= "</ul>";
+
+if ($_GET) {
+ if ($_GET['queue'])
+ $qname = trim($_GET['queue']);
+ if ($_GET['interface'])
+ $interface = trim($_GET['interface']);
+ if ($_GET['action'])
+ $action = $_GET['action'];
+
+ switch ($action) {
+ case "delete":
+ $altq =& $altq_list_queues[$interface];
+ $qtmp =& $altq->find_queue("", $qname);
+ if ($qtmp) {
+ $qtmp->delete_queue();
+ write_config();
+ touch($d_shaperconfdirty_path);
}
- }
-
- 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']--;
+ header("Location: firewall_shaper_queues.php");
+ exit;
+ break;
+ case "add":
+ /*
+ * XXX: WARNING: This returns the first it finds.
+ * Maybe the user expects something else?!
+ */
+ foreach ($altq_list_queues as $altq) {
+ $qtmp =& $altq->find_queue("", $qname);
+ if ($qtmp) {
+ $aq =& $altq_list_queues[$interface];
+ if ($aq) {
+ //$link =& get_reference_to_me_in_config(&$link);
+ $aq->copy_queue($interface, &$qtmp);
+ write_config();
+ touch($d_shaperconfdirty_path);
+ break;
+ }
}
}
-
- write_config();
- touch($d_shaperconfdirty_path);
- header("Location: firewall_shaper_queues.php");
+ header("Location: firewall_shaper_queues.php?queue=".$qname."&action=show");
exit;
- }
+ break;
+ case "show":
+ $iflist = get_interface_list();
+ foreach ($iflist as $if) {
+ $altq = $altq_list_queues[$if['friendly']];
+ if ($altq) {
+ $qtmp =& $altq->find_queue("", $qname);
+ if ($qtmp)
+ $output .= $qtmp->build_shortform();
+ else
+ $output .= build_iface_without_this_queue($if['friendly'], $qname);
+ } else
+ $output .= build_iface_without_this_queue($if['friendly'], $qname);
+ }
+ break;
}
}
-if ($_POST) {
- /* 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['queue']) && count($_POST['queue'])) {
- $a_queue_new = array();
-
- /* copy all rules < $movebtn and not selected */
- for ($i = 0; $i < $movebtn; $i++) {
- if (!in_array($i, $_POST['queue']))
- $a_queue_new[] = $a_queues[$i];
- }
+if ($_POST['apply']) {
+ write_config();
- /* copy all selected rules */
- for ($i = 0; $i < count($a_queues); $i++) {
- if ($i == $movebtn)
- continue;
- if (in_array($i, $_POST['queue']))
- $a_queue_new[] = $a_queues[$i];
- }
+ $retval = 0;
+ $savemsg = get_std_save_message($retval);
+ /* Setup pf rules since the user may have changed the optimization value */
- /* copy $movebtn rule */
- if ($movebtn < count($a_queues))
- $a_queue_new[] = $a_queues[$movebtn];
+ config_lock();
+ $retval = filter_configure();
+ config_unlock();
+ if (stristr($retval, "error") <> true)
+ $savemsg = get_std_save_message($retval);
+ else
+ $savemsg = $retval;
- /* copy all rules > $movebtn and not selected */
- for ($i = $movebtn+1; $i < count($a_queues); $i++) {
- if (!in_array($i, $_POST['queue']))
- $a_queue_new[] = $a_queues[$i];
- }
+ enable_rrd_graphing();
- $a_queues = $a_queue_new;
- write_config();
- touch($d_shaperconfdirty_path);
- header("Location: firewall_shaper_queues.php");
- exit;
- }
+ unlink($d_shaperconfdirty_path);
}
+$pgtitle = "Firewall: Shaper: By Queues View";
-$pgtitle = array("Firewall","Shaper","Queues");
include("head.inc");
-
?>
+<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
+<script type="text/javascript" src="./tree/tree.js"></script>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
-<form action="firewall_shaper_queues.php" method="post">
-<script type="text/javascript" language="javascript" src="row_toggle.js"></script>
+<p class="pgtitle"><?=$pgtitle?></p>
+<div id="inputerrors"></div>
<?php if ($input_errors) print_input_errors($input_errors); ?>
+<form action="firewall_shaper_queues.php" method="post" name="iform" id="iform">
<?php if ($savemsg) print_info_box($savemsg); ?>
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
<?php print_info_box_np("The traffic shaper configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
@@ -173,9 +158,9 @@ include("head.inc");
<tr><td>
<?php
$tab_array = array();
- $tab_array[0] = array("Rules", false, "firewall_shaper.php");
- $tab_array[1] = array("Queues", true, "firewall_shaper_queues.php");
- $tab_array[2] = array("EZ Shaper wizard", false, "wizard.php?xml=traffic_shaper_wizard.xml");
+ $tab_array[0] = array("Shaper", false, "firewall_shaper.php");
+ //$tab_array[1] = array("Level 2", true, "");
+ $tab_array[1] = array("EZ Shaper wizard", false, "wizard.php?xml=traffic_shaper_wizard.xml");
display_top_tabs($tab_array);
?>
</td></tr>
@@ -183,77 +168,29 @@ include("head.inc");
<td>
<div id="mainarea">
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
- <tr id="frheader">
- <td width="3%" class="list">&nbsp;</td>
- <td width="0%" class="list">&nbsp;</td>
- <td width="5%" class="listhdrr">Flags</td>
- <td width="5%" class="listhdrr">Priority</td>
- <td width="5%" class="listhdr">Default</td>
- <td width="5%" class="listhdr">Bandwidth</td>
- <td width="65%" class="listhdr">Name</td>
- <td width="10%" class="list">&nbsp;</td>
- </tr>
- <?php $i = 0; foreach ($a_queues as $queue): ?>
- <tr valign="top" id="fr<?=$i;?>">
-<td class="listt"><input type="checkbox" id="frc<?=$i;?>" name="queue[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$i;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;"></td>
- <td class="listt" onClick="fr_toggle(<?=$i;?>)" id="frc<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">&nbsp;</td>
- <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
-<?php
- if($queue['red'] <> "") echo " RED";
- if($queue['rio'] <> "") echo " RIO";
- if($queue['ecn'] <> "") echo " ECN";
- if($queue['borrow'] <> "") echo " Borrow";
- if(isset($queue['ack'])) echo "ACK"
-?>
- &nbsp;
- </td>
- <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
- <?=$queue['priority'];?>&nbsp;
- </td>
- <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
- <?php
- if($queue['defaultqueue'] <> "") {
- echo "Yes";
- } else {
- echo "No";
- }
- ?>
- </td>
- <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
- <?=htmlspecialchars($queue['bandwidth']);?> <?=htmlspecialchars($queue['bandwidthtype']);?>
- &nbsp;
- </td>
- <td class="listbg" onClick="fr_toggle(<?=$i;?>)" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
- <font color="#FFFFFF"><?=htmlspecialchars($queue['name']);?>
- &nbsp;
- </td>
- <td valign="middle" nowrap class="list">
- <table border="0" cellspacing="0" cellpadding="1">
- <tr>
- <td><input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="move selected queue before this rule" onMouseOver="fr_insline(<?=$i;?>, true)" onMouseOut="fr_insline(<?=$i;?>, false)"></td>
- <td valign="middle"><a href="firewall_shaper_queues_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
- <td valign="middle"><a href="firewall_shaper_queues.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this queue?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
- </tr>
- </table>
- </td>
- </tr>
- <?php $i++; endforeach; $total_queues = $i; ?>
- <tr>
- <td class="list" colspan="7"></td>
- <td class="list">
- <table border="0" cellspacing="0" cellpadding="1">
- <tr>
- <td valign="middle"><a href="firewall_shaper_queues_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
- </tr>
- </table>
- </td>
- </tr>
- <tr><td colspan="7">
- <p>
- <strong><span class="red">Note:</span></strong><strong><br></strong>
- A queue can only be deleted if it is not referenced by any rules.<br>
- You can check the results of your queues at <a href="status_queues.php">Status:Queues</a>.
- </p>
+ <tr>
+ <td width="30%" valign="top" algin="left">
+ <? $tab_ar = array();
+ $tab_ar[0] = array("By Interface", false, "firewall_shaper.php");
+ $tab_ar[1] = array("By Queues", true, "firewall_shaper_queues.php");
+ display_top_tabs($tab_ar);
+ echo $tree;
+ ?>
+ </td></tr>
+ </table>
+ <td width="70%" valign="top" align="center">
+ <table class=\"tabcont\" width=\"80%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
+ <tr><td>
+ <?
+ if ($qname)
+ echo "<pr class=\"pgtitle\">" . $qname . "</pr><br />";
+ echo "<table align=\"top\" class=\"tabcont\" width=\"80%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">";
+ echo $output;
+ echo "</table>";
+ ?>
+ </td></tr>
+ </table>
+
</td></tr>
</table>
</div>
@@ -261,6 +198,7 @@ include("head.inc");
</tr>
</table>
</form>
-<?php include("fend.inc"); ?>
+<?php include("fend.inc");
+?>
</body>
</html>
diff --git a/usr/local/www/status_queues.php b/usr/local/www/status_queues.php
index 2a5963f..73ef55d 100755
--- a/usr/local/www/status_queues.php
+++ b/usr/local/www/status_queues.php
@@ -59,7 +59,7 @@ include("head.inc");
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<?php
-if(!isset($config['shaper']['enable'])) {
+if(!is_array($config['shaper']['queue'])) {
echo "Traffic shaping is currently disabled.";
include("fend.inc");
exit;
@@ -76,7 +76,7 @@ if(!isset($config['shaper']['enable'])) {
<tr><td bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
<tr valign="top">
<td bgcolor="#DDDDDD">
- <font color="#000000">&nbsp;&nbsp;&nbsp;<?echo "<a href=\"firewall_shaper_queues_edit.php?id={$queue}\">" . htmlspecialchars($queue) . "</a>";?>&nbsp;&nbsp;&nbsp;</td>
+ <font color="#000000">&nbsp;&nbsp;&nbsp;<?echo "<a href=\"firewall_shaper.php?id={$queue}\">" . htmlspecialchars($queue) . "</a>";?>&nbsp;&nbsp;&nbsp;</td>
<td bgcolor="#DDDDDD">
<nobr>
<?php
@@ -181,4 +181,4 @@ While(!Connection_Aborted()) {
mwexec("/usr/bin/killall pfctl");
mwexec("/usr/bin/killall pfctl");
-?> \ No newline at end of file
+?>
diff --git a/usr/local/www/wizards/traffic_shaper_wizard.inc b/usr/local/www/wizards/traffic_shaper_wizard.inc
index 9626c43..bf3565e 100644
--- a/usr/local/www/wizards/traffic_shaper_wizard.inc
+++ b/usr/local/www/wizards/traffic_shaper_wizard.inc
@@ -1,5 +1,4 @@
<?php
-
/* $Id$ */
/*
traffic_shaper_wizard.inc
@@ -7,6 +6,7 @@
Copyright (C) 2006 Bill Marquette - bill.marquette@gmail.com.
Copyright (C) 2006 Scott Ullrich - sullrich@pfsense.com.
+ Copyright (C) 2008 Ermal Lu\xe7i
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -31,301 +31,123 @@
POSSIBILITY OF SUCH DAMAGE.
*/
+
+
+function step1_stepbeforeformdisplay() {
+ global $g, $config;
+
+ $pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/traffic_shaper_wizard.xml", "pfsensewizard");
+ unset($pkg['step'][1]['fields']);
+ $fields =& $pkg['step'][1]['fields']['field'];
+
+ $fields = array();
+ $field = array();
+ $field['name'] = "Setup network speeds";
+ $field['type'] = "listtopic";
+ $fields[] = $field;
+
+ foreach ($config['interfaces'] as $if => $ifdesc) {
+ if (!is_altq_capable($ifdesc['if']))
+ continue;
+ if (!isset($ifdesc['enable']) && $if != "lan" && $if != "wan")
+ continue;
+ $field = array();
+ $field['name'] = "{$if}scheduler";
+ $field['type'] = "select";
+ $field['typehint'] = "Queueing discipline to apply on this interface";
+ $field['options']['option'] = array();
+ $opts = array();
+ $opts['name'] = "HFSC";
+ $opts['value'] = "HFSC";
+ $field['options']['option'][] = $opts;
+ $opts = array();
+ $opts['name'] = "CBQ";
+ $opts['value'] = "CBQ";
+ $field['options']['option'][] = $opts;
+ $opts = array();
+ $opts['name'] = "PRIQ";
+ $opts['value'] = "PRIQ";
+ $field['options']['option'][] = $opts;
+ $field['bindstofield'] = "ezshaper->step2->{$if}->scheduler";
+ $fields[] = $field;
+
+ $field = array();
+ $field['name'] = $if;
+ $field['type'] = "input";
+ $field['typehint'] = "Bandwidth in Kbit/sec on this interface";
+ $field['validate'] = "^[0-9]*$";
+ $field['bindstofield'] = "ezshaper->step2->{$if}->bandwidth";
+ $fields[] = $field;
+ }
+ $field = array();
+ $field['name'] = "Next";
+ $field['type'] = "submit";
+ $fields[] = $field;
+
+ conf_mount_rw();
+
+ $xmlcf = dump_xml_config_pkg($pkg, "pfsensewizard");
+ /* write new configuration */
+ $fd = fopen("{$g['www_path']}/wizards/traffic_shaper_wizard.xml", "w");
+ if (!$fd)
+ die("Unable to open {$g['www_path']}/wizards/traffic_shaper_wizard.xml for writing in write_config()\n");
+ fwrite($fd, $xmlcf);
+ fclose($fd);
+
+ conf_mount_ro();
+
+}
function step1_stepsubmitphpaction() {
global $g, $config;
/* wipe previous */
- unset($config['shaper']['queue']);
- unset($config['shaper']['rule']);
- $config['shaper']['enable'] = FALSE;
- $config['shaper']['itemsshaped'] = "0";
+ if(isset($config['shaper']['queue']))
+ unset($config['shaper']['queue']);
+ if(isset($config['shaper']['rule']))
+ unset($config['shaper']['rule']);
+ foreach ($config['filter']['rule'] as $key => $rule)
+ if ($rule['wizard'] == "yes")
+ unset($config['filter']['rule'][$key]);
+ write_config();
}
function step2_stepsubmitphpaction() {
- global $g, $config;
- if(!is_numeric($_POST['upload']) or !is_numeric($_POST['download'])) {
- $message="Upload and download speeds must be a number only! Values should be Kbits/second.";
- header("Location: /wizard.php?xml=traffic_shaper_wizard.xml&stepid=1&message={$message}");
- exit;
- }
- if ($config['ezshaper']['step2']['inside_int'] == $config['ezshaper']['step2']['outside_int']) {
- $message="Inside and Outside interfaces cannot be the same. Please select a unique interface for both.";
- header("Location: /wizard.php?xml=traffic_shaper_wizard.xml&stepid=1&message={$message}");
- exit;
- }
- $downq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['inside_int']);
- $upq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['outside_int']);
-
- /* Magic shaper scheduler */
- $config['shaper']['schedulertype'] = "hfsc";
-
- /* Create queues */
- /* WAN root queue */
- $queue = array();
- $queue['name'] = "{$upq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 0;
- $queue['parentqueue'] = "on";
- /* $queue['bandwidth'] = (int)$_POST['upload'] * .8; */
- $queue['bandwidth'] = (int)$_POST['upload'];
- $queue['bandwidthtype'] = "Kb";
- $config['shaper']['queue'][] = $queue;
-
- /* LAN root queue */
- $queue = array();
- $queue['name'] = "{$downq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 0;
- $queue['parentqueue'] = "on";
- /* $queue['bandwidth'] = (int)$_POST['download'] * .8; */
- $queue['bandwidth'] = (int)$_POST['download'];
- $queue['bandwidthtype'] = "Kb";
- $config['shaper']['queue'][] = $queue;
-
- /* WAN default queue */
- $queue = array();
- $queue['name'] = "{$upq}def";
- $queue['attachtoqueue'] = "{$upq}Root";
- $queue['associatedrule'] = 0;
- $queue['defaultqueue'] = 'true';
- $queue['priority'] = 1;
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "1%";
- $queue['bandwidth'] = 1;
- $queue['bandwidthtype'] = '%';
- $queue['qlimit'] = 500;
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
-
- /* LAN default queue */
- $queue = array();
- $queue['name'] = "{$downq}def";
- $queue['priority'] = 1;
- $queue['attachtoqueue'] = "{$downq}Root";
- $queue['associatedrule'] = 0;
- $queue['defaultqueue'] = 'true';
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "1%";
- $queue['bandwidth'] = 1;
- $queue['bandwidthtype'] = '%';
- $queue['qlimit'] = 500;
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- /* WAN ack queue */
- $queue = array();
- $queue['name'] = "{$upq}acks";
- $queue['ack'] = TRUE;
- $queue['attachtoqueue'] = "{$upq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 7;
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "10%";
- $queue['bandwidth'] = 25;
- $queue['bandwidthtype'] = '%';
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
- $queue = array();
-
- /* LAN ack queue */
- $queue['name'] = "{$downq}acks";
- $queue['ack'] = TRUE;
- $queue['attachtoqueue'] = "{$downq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 7;
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "10%";
- $queue['bandwidth'] = 25;
- $queue['bandwidthtype'] = '%';
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
+ global $config;
+ foreach ($config['interfaces'] as $if => $ifdesc) {
+ if (!is_altq_capable($ifdesc['if']))
+ continue;
+ if (!isset($ifdesc['enable']) && $if != "lan" && $if != "wan")
+ continue;
+ if (isset($_POST['bandwidth']) && $_POST['bandwidth'] < 128) {
+ $message=gettext("We do not support Bandwidths smaller than 128Kbit/s. Please correct this value to continue.");
+ header("Location: /wizard.php?xml=traffic_shaper_wizard.xml&stepid=2&message={$message}");
+ }
+ }
}
function step3_stepsubmitphpaction() {
- global $g, $config;
+
if($_POST['address']) {
if(!is_ipaddr($_POST['address'])) {
if(!is_alias($_POST['address'])) {
/* item is not an ip or alias. error out */
- $message="Address must be a valid IP address or Firewall Alias. Please correct this value to continue.";
+ $message=gettext("Address must be a valid IP address or Firewall Alias. Please correct this value to continue.");
header("Location: /wizard.php?xml=traffic_shaper_wizard.xml&stepid=3&message={$message}");
- exit;
- }
- }
- }
-
- if ( $_POST['enable'] ) {
- $downq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['inside_int']);
- $upq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['outside_int']);
- $downint = strtolower($config['ezshaper']['step2']['inside_int']);
- $upint = strtolower($config['ezshaper']['step2']['outside_int']);
-
- /* create qVOIPUp */
- $queue = array();
- $queue['name'] = "qVOIPUp";
- $queue['attachtoqueue'] = "{$upq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 7;
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = $_POST['bandwidth'] . "Kb";
- $queue['bandwidth'] = 25;
- $queue['bandwidthtype'] = '%';
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['bandwidth'] = $_POST['bandwidth'];
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- /* create qVOIPDown */
- $queue = array();
- $queue['name'] = "qVOIPDown";
- $queue['attachtoqueue'] = "{$downq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 7;
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = $_POST['bandwidth'] . "Kb";
- $queue['bandwidth'] = 25;
- $queue['bandwidthtype'] = '%';
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['bandwidth'] = $_POST['bandwidth'];
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- $config['shaper']['itemsshaped']++;
-
- /* If user specifies an IP, we don't bother with providers */
- if( is_ipaddr($_POST['address']) or is_alias($_POST['address'])) {
- /* create VOIP rules */
- $rule = array();
- $rule['descr'] = "VOIP Adapter";
- $rule['inqueue'] = "qVOIPDown";
- $rule['outqueue'] = "qVOIPUp";
- $rule['in-interface'] = $downint;
- $rule['out-interface'] = $upint;
- /* $rule['source']['network'] = $downint; */
- $rule['source']['address'] = $_POST['address'];
- $rule['destination']['any'] = TRUE;
- $config['shaper']['rule'][] = $rule;
-
- $rule = array();
- $rule['descr'] = "VOIP Adapter";
- $rule['inqueue'] = "qVOIPUp";
- $rule['outqueue'] = "qVOIPDown";
- $rule['in-interface'] = $upint;
- $rule['out-interface'] = $downint;
- $rule['source']['any'] = TRUE;
- $rule['destination']['address'] = $_POST['address'];
- $config['shaper']['rule'][] = $rule;
- } elseif( $_POST['provider'] == "Generic" ) {
- /* create VOIP rules */
- $rule = array();
- $rule['descr'] = "DiffServ/Lowdelay/Upload";
- $rule['inqueue'] = "qVOIPDown";
- $rule['outqueue'] = "qVOIPUp";
- $rule['in-interface'] = $downint;
- $rule['out-interface'] = $upint;
- $rule['source']['network'] = $downint;
- $rule['destination']['any'] = TRUE;
- $rule['iptos'] = "lowdelay";
- $config['shaper']['rule'][] = $rule;
-
- $rule = array();
- $rule['descr'] = "DiffServ/Lowdelay/Download";
- $rule['inqueue'] = "qVOIPUp";
- $rule['outqueue'] = "qVOIPDown";
- $rule['in-interface'] = $upint;
- $rule['out-interface'] = $downint;
- $rule['source']['any'] = TRUE;
- $rule['destination']['network'] = $downint;
- $rule['iptos'] = "lowdelay";
- $config['shaper']['rule'][] = $rule;
- } else {
-
- $voiplist = array();
-
- /* asterisk server / same as vonage */
- if(($_POST['provider'] == "Asterisk") || ($_POST['provider'] == "Vonage")) {
- $voiplist[] = array('Asterisk', 'udp', '5060', '5069', 'both');
- $voiplist[] = array('Asterisk', 'udp', '10000', '20000', 'both');
- }
- /* VoicePulse server */
- if( $_POST['provider'] == "VoicePulse") {
- $voiplist[] = array('VoicePulse', 'udp', '16384', '16482', 'both');
- $voiplist[] = array('VoicePulse', 'udp', '4569', '4569', 'both');
- }
-
- /* Panasonic Hybrid PBX */
- if( $_POST['provider'] == "Panasonic") {
- $voiplist[] = array('Panasonic1', 'udp', '8000', '8063', 'both');
- $voiplist[] = array('Panasonic2', 'udp', '9300', '9301', 'both');
- $voiplist[] = array('Panasonic3', 'udp', '2747', '2747', 'both');
- }
-
- /* Set up/down VOIP as higher weight */
- /* loop through voiplist[] */
- foreach ($voiplist as $voip) {
- foreach (array('source', 'destination') as $srcdest) {
- $rule = array();
- if ($srcdest == 'source') {
- $destsrc = 'destination';
- $rule['inqueue'] = 'qVOIPDown';
- $rule['outqueue'] = 'qVOIPUp';
- $rule['in-interface'] = $downint;
- $rule['out-interface'] = $upint;
- $rule['source']['network'] = $downint;
- $rule['destination']['any'] = TRUE;
- $rule['descr'] = "m_voip {$voip[0]} outbound";
- } else {
- $destsrc = 'source';
- $rule['inqueue'] = 'qVOIPUp';
- $rule['outqueue'] = 'qVOIPDown';
- $rule['in-interface'] = $upint;
- $rule['out-interface'] = $downint;
- $rule['source']['any'] = TRUE;
- $rule['destination']['network'] = $downint;
- $rule['descr'] = "m_voip {$voip[0]} inbound";
- }
-
- $rule['destination']['port'] = $voip[2]."-".$voip[3];
- if($voip[1] != '')
- $rule['protocol'] = $voip[1];
-
- $config['shaper']['rule'][] = $rule;
}
- }
}
}
}
function step4_stepsubmitphpaction() {
- global $g, $config;
+
if ( $_POST['enable'] ) {
- if(!is_numeric($_POST['bandwidthup']) or !is_numeric($_POST['bandwidthdown'])) {
- $message="Upload and download speeds must be a number only! Values should be Kbits/second.";
+ if(!is_numeric($_POST['bandwidth'])) {
+ $message="Speed must be a number only! Values should be in percentage.";
+ header("Location: /wizard.php?xml=traffic_shaper_wizard.xml&stepid=4&message={$message}");
+ exit;
+ }
+ if(!$_POST['bandwidth']) {
+ $message="You need to specify a value for bandwidth! Values should be in percentage.";
header("Location: /wizard.php?xml=traffic_shaper_wizard.xml&stepid=4&message={$message}");
exit;
}
@@ -339,901 +161,802 @@ function step4_stepsubmitphpaction() {
}
}
- if ( $_POST['enable'] ) {
- $downq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['inside_int']);
- $upq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['outside_int']);
- $downint = strtolower($config['ezshaper']['step2']['inside_int']);
- $upint = strtolower($config['ezshaper']['step2']['outside_int']);
-
- /* create qPenaltyUp queue */
- $queue = array();
- $queue['name'] = "qPenaltyUp";
- $queue['attachtoqueue'] = "{$upq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 2;
- $queue['red'] = "on";
- $queue['ecn'] = "on";
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['upperlimit'] = "on";
- $queue['upperlimit3'] = $_POST['bandwidthup'] . "Kb";
- $queue['bandwidth'] = 1;
- $queue['bandwidthtype'] = '%';
- $queue['qlimit'] = 500;
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "off";
- $queue['bandwidth'] = $_POST['bandwidthup'];
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- /* create qPenaltyDown queue */
- $queue = array();
- $queue['name'] = "qPenaltyDown";
- $queue['attachtoqueue'] = "{$downq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 2;
- $queue['red'] = "on";
- $queue['ecn'] = "on";
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['upperlimit'] = "on";
- $queue['upperlimit3'] = $_POST['bandwidthdown'] . "Kb";
- $queue['bandwidth'] = 1;
- $queue['bandwidthtype'] = '%';
- $queue['qlimit'] = 500;
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "off";
- $queue['bandwidth'] = $_POST['bandwidthdown'];
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- $config['shaper']['itemsshaped']++;
-
- /* If user specifies an IP, we don't bother with providers */
- if( is_ipaddr($_POST['address']) or is_alias($_POST['address'])) {
- /* create Penalty rules */
- $rule = array();
- $rule['descr'] = gettext("Penalty IP");
- $rule['inqueue'] = "qPenaltyDown";
- $rule['outqueue'] = "qPenaltyUp";
- $rule['in-interface'] = $downint;
- $rule['out-interface'] = $upint;
- /* $rule['source']['network'] = $downint; */
- $rule['source']['address'] = $_POST['address'];
- $rule['destination']['any'] = TRUE;
- $config['shaper']['rule'][] = $rule;
-
- $rule = array();
- $rule['descr'] = gettext("Penalty IP");
- $rule['inqueue'] = "qPenaltyUp";
- $rule['outqueue'] = "qPenaltyDown";
- $rule['in-interface'] = $upint;
- $rule['out-interface'] = $downint;
- $rule['source']['any'] = TRUE;
- $rule['destination']['address'] = $_POST['address'];
- $config['shaper']['rule'][] = $rule;
- }
- }
}
function step5_stepsubmitphpaction() {
- global $g, $config;
if ( $_POST['enable'] ) {
- if (( $_POST['bandwidthup'] ) || ($_POST['bandwidthdown'])) {
- if(!is_numeric($_POST['bandwidthup']) or !is_numeric($_POST['bandwidthdown'])) {
- $message="Upload and download speeds must be a number only! Values should be Kbits/second.";
+ if (( $_POST['bandwidth'] )) {
+ if(!is_numeric($_POST['bandwidth'])) {
+ $message="Speed must be a number only! Values should be in percentage.";
header("Location: /wizard.php?xml=traffic_shaper_wizard.xml&stepid=4&message={$message}");
exit;
}
}
}
- /* XXX - billm - needs to actually honor what the user selects still */
- if ( $_POST['enable'] ) {
- $downq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['inside_int']);
- $upq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['outside_int']);
- $downint = strtolower($config['ezshaper']['step2']['inside_int']);
- $upint = strtolower($config['ezshaper']['step2']['outside_int']);
- if($_POST['p2pcatchall'] != "")
- $config['shaper']['itemsshaped']++;
+}
- $p2plist = array();
+function step8_stepsubmitphpaction() {
+ global $g, $config, $d_shaperconfdirty_path;
- /* To add p2p clients, push Descr,Protocol,Start,End,src/dest/both onto p2plist */
- if($_POST['aimster'] != "")
- $p2plist[] = array('Aimster', 'tcp', '7668', '7668', 'both');
- if($_POST['bittorrent'] != "") {
- $p2plist[] = array('BitTorrent', 'tcp', '6881', '6999', 'both');
- $p2plist[] = array('BitTorrent', 'udp', '6881', '6999', 'both');
- }
- if($_POST['buddyshare'] != "")
- $p2plist[] = array('BuddyShare', 'tcp', '7788', '7788', 'both');
- if($_POST['cutemx'] != "")
- $p2plist[] = array('CuteMX', 'tcp', '2340', '2340', 'both');
- if($_POST['dc++'] != "")
- $p2plist[] = array('DC++', 'tcp', '1412', '1412', 'both');
- if($_POST['dcc'] != "")
- $p2plist[] = array('dcc', 'tcp', '6666', '6668', 'both');
- if($_POST['directconnect'] != "")
- $p2plist[] = array('DirectConnect', 'tcp', '412', '412', 'both');
- if($_POST['directfileexpress'] != "")
- $p2plist[] = array('DirectFileExpress', 'tcp', '1044', '1045', 'both');
- if($_POST['edonkey2000'] != "")
- $p2plist[] = array('EDonkey2000', 'tcp', '4661', '4665', 'both');
- if($_POST['fastTrack'] != "")
- $p2plist[] = array('FastTrack', 'tcp', '1214', '1214', 'both');
- if($_POST['gnutella'] != "") {
- $p2plist[] = array('Gnutella-TCP', 'tcp', '6346', '6346', 'both');
- $p2plist[] = array('Gnutella-UDP', 'udp', '6346', '6346', 'both');
- }
- if($_POST['grouper'] != "")
- $p2plist[] = array('grouper', 'tcp', '8038', '8039', 'both');
- if($_POST['hotcomm'] != "")
- $p2plist[] = array('hotComm', 'tcp', '28864', '28865', 'both');
- if($_POST['hotlineconnect'] != "")
- $p2plist[] = array('HotlineConnect', 'tcp', '5500', '5503', 'both');
- if($_POST['imesh'] != "")
- $p2plist[] = array('iMesh', 'tcp', '4329', '4329', 'both');
- if($_POST['napster'] != "")
- $p2plist[] = array('Napster', 'tcp', '6699', '6701', 'both');
- if($_POST['opennap'] != "")
- $p2plist[] = array('OpenNap', 'tcp', '8888', '8889', 'both');
- if($_POST['scour'] != "")
- $p2plist[] = array('Scour', 'tcp', '8311', '8311', 'both');
- if($_POST['shareaza'] != "")
- $p2plist[] = array('Shareaza', 'tcp', '6346', '6346', 'both');
- if($_POST['songspy'] != "")
- $p2plist[] = array('SongSpy', 'tcp', '5190', '5190', 'both');
- if($_POST['winmx'] != "")
- $p2plist[] = array('WinMX', 'tcp', '6699', '6699', 'both');
-
- /* Set up/down p2p as lowest weight */
- /* loop through p2plist[] */
- foreach ($p2plist as $p2pclient) {
- foreach (array('source', 'destination') as $srcdest) {
- $rule = array();
- $config['shaper']['itemsshaped']++;
- if ($srcdest == 'source') {
- $destsrc = 'destination';
- $rule['inqueue'] = 'qP2PDown';
- $rule['outqueue'] = 'qP2PUp';
- $rule['in-interface'] = $downint;
- $rule['out-interface'] = $upint;
- $rule['interface'] = $downint;
- $rule['source']['network'] = $downint;
- $rule['destination']['any'] = TRUE;
- $rule['descr'] = "m_P2P {$p2pclient[0]} outbound";
- } else {
- $destsrc = 'source';
- $rule['inqueue'] = 'qP2PUp';
- $rule['outqueue'] = 'qP2PDown';
- $rule['in-interface'] = $upint;
- $rule['out-interface'] = $downint;
- $rule['source']['any'] = TRUE;
- $rule['destination']['network'] = $downint;
- $rule['descr'] = "m_P2P {$p2pclient[0]} inbound";
- }
+ /* Prepare for next ezshaper wizard run */
+ unset($config['shaper']['itemsshaped']);
+
+ /* create configuration */
+ apply_all_choosen_items();
+ /* reset rrd queues */
+ system("rm -f /var/db/rrd/wan-queuesdrop.rrd");
+ system("rm -f /var/db/rrd/wan-queues.rrd");
+ enable_rrd_graphing();
- $rule['destination']['port'] = $p2pclient[2]."-".$p2pclient[3];
- if($p2pclient[1] != '')
- $rule['protocol'] = $p2pclient[1];
+ /* Create new rules */
+ filter_configure();
- $config['shaper']['rule'][] = $rule;
- }
- }
+ /* And we're no longer dirty! */
+ unlink_if_exists($d_shaperconfdirty_path);
- /* create qP2PUp */
- $queue = array();
- $queue['name'] = "qP2PUp";
- $queue['attachtoqueue'] = "{$upq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 1;
- $queue['red'] = "on";
- $queue['ecn'] = "on";
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "1Kb";
- if($_POST['bandwidthup'] <> "") {
- $queue['upperlimit'] = "on";
- $queue['upperlimit3'] = $_POST['bandwidthup'] . "Kb";
- }
- $queue['bandwidth'] = 1;
- $queue['bandwidthtype'] = '%';
- $queue['qlimit'] = 500;
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- /* create qP2PDown */
- $queue = array();
- $queue['name'] = "qP2PDown";
- $queue['attachtoqueue'] = "{$downq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 1;
- $queue['red'] = "on";
- $queue['ecn'] = "on";
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "1Kb";
- if($_POST['bandwidthdown'] <> "") {
- $queue['upperlimit'] = "on";
- $queue['upperlimit3'] = $_POST['bandwidthdown'] . "Kb";
- }
- $queue['bandwidth'] = 1;
- $queue['bandwidthtype'] = '%';
- $queue['qlimit'] = 500;
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
- }
+ update_filter_reload_status("Initializing");
+
+ /* Head over and check out the groovy queue stats */
+ header("Location: status_filter_reload.php");
}
-function step6_stepsubmitphpaction() {
+function step9_stepsubmitphpaction() {
global $g, $config;
- /* XXX - billm - needs to actually honor what the user selects still */
- if ( $_POST['enable'] ) {
- $downq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['inside_int']);
- $upq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['outside_int']);
- $downint = strtolower($config['ezshaper']['step2']['inside_int']);
- $upint = strtolower($config['ezshaper']['step2']['outside_int']);
-
- /* create qGamesUp queue */
- $queue = array();
- $queue['name'] = "qGamesUp";
- $queue['attachtoqueue'] = "{$upq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 5;
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "1Kb";
- $queue['bandwidth'] = 15;
- $queue['bandwidthtype'] = '%';
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- /* create qGamesDown queue */
- $queue = array();
- $queue['name'] = "qGamesDown";
- $queue['attachtoqueue'] = "{$downq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 5;
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "1Kb";
- $queue['bandwidth'] = 15;
- $queue['bandwidthtype'] = '%';
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- $gamesplist = array();
-
- if($_POST['battlefield2'] != "") {
- /* Battlefield 2 */
- $gamesplist[] = array('BF2-1500-4999', 'udp', '1500', '4999', 'both');
- $gamesplist[] = array('BF2-4711', 'tcp', '4711', '4711', 'both');
- $gamesplist[] = array('BF2-16567', 'udp', '16567', '16567', 'both');
- $gamesplist[] = array('BF2-27900', 'udp', '27900', '27900', 'both');
- $gamesplist[] = array('BF2-28910', 'tcp', '28910', '28910', 'both');
- $gamesplist[] = array('BF2-29900-29901-UDP', 'udp', '29900', '29901', 'both');
- $gamesplist[] = array('BF2-29900-29901-TCP', 'tcp', '29900', '29901', 'both');
- $gamesplist[] = array('BF2-27900', 'udp', '27900', '27900', 'both');
- $gamesplist[] = array('BF2-55123-55125', 'udp', '55123', '55125', 'both');
- }
+ header("Location: status_filter_reload.php");
+}
- if($_POST['counterstrike'] != "") {
- /* counter strike */
- $gamesplist[] = array('Titan', 'udp', '6003', '6003', 'both');
- $gamesplist[] = array('Authentication', 'udp', '7002', '7002', 'both');
- $gamesplist[] = array('Client', 'udp', '6003', '6003', 'both');
- $gamesplist[] = array('Masterserver', 'udp', '27010', '27010', 'both');
- $gamesplist[] = array('Mod-Server', 'udp', '27011', '27011', 'both');
- $gamesplist[] = array('Chat', 'udp', '27012', '27012', 'both');
- $gamesplist[] = array('HL-Serverport1', 'udp', '27013', '27013', 'both');
- $gamesplist[] = array('HL-Serverport2', 'udp', '27014', '27014', 'both');
- $gamesplist[] = array('HL-Serverport', 'udp', '27015', '27015', 'both');
- }
+function apply_all_choosen_items() {
+ global $pkg, $config, $g, $altq_list_queues;
+
+$gamesplist = array();
- if($_POST['deltaforce'] != "") {
+$gamesplist['battlefield2'] = array();
+ /* Battlefield 2 */
+ $gamesplist['battlefield2'][] = array('BF2-1500-4999', 'udp', '1500', '4999', 'both');
+ $gamesplist['battlefield2'][] = array('BF2-4711', 'tcp', '4711', '4711', 'both');
+ $gamesplist['battlefield2'][] = array('BF2-16567', 'udp', '16567', '16567', 'both');
+ $gamesplist['battlefield2'][] = array('BF2-27900', 'udp', '27900', '27900', 'both');
+ $gamesplist['battlefield2'][] = array('BF2-28910', 'tcp', '28910', '28910', 'both');
+ $gamesplist['battlefield2'][] = array('BF2-29900-29901-UDP', 'udp', '29900', '29901', 'both');
+ $gamesplist['battlefield2'][] = array('BF2-29900-29901-TCP', 'tcp', '29900', '29901', 'both');
+ $gamesplist['battlefield2'][] = array('BF2-27900', 'udp', '27900', '27900', 'both');
+ $gamesplist['battlefield2'][] = array('BF2-55123-55125', 'udp', '55123', '55125', 'both');
+
+$gamesplist['counterstrike'] = array();
+ /* counter strike */
+ $gamesplist['counterstrike'][] = array('Titan', 'udp', '6003', '6003', 'both');
+ $gamesplist['counterstrike'][] = array('Authentication', 'udp', '7002', '7002', 'both');
+ $gamesplist['counterstrike'][] = array('Client', 'udp', '6003', '6003', 'both');
+ $gamesplist['counterstrike'][] = array('Masterserver', 'udp', '27010', '27010', 'both');
+ $gamesplist['counterstrike'][] = array('Mod-Server', 'udp', '27011', '27011', 'both');
+ $gamesplist['counterstrike'][] = array('Chat', 'udp', '27012', '27012', 'both');
+ $gamesplist['counterstrike'][] = array('HL-Serverport1', 'udp', '27013', '27013', 'both');
+ $gamesplist['counterstrike'][] = array('HL-Serverport2', 'udp', '27014', '27014', 'both');
+ $gamesplist['counterstrike'][] = array('HL-Serverport', 'udp', '27015', '27015', 'both');
+
+$gamesplist['deltaforce'] = array();
/* delta force */
- $gamesplist[] = array('Delta1', 'udp', '17478', '17488', 'both');
- }
+ $gamesplist['deltaforce'][] = array('Delta1', 'udp', '17478', '17488', 'both');
- if($_POST['quakeiii'] != "") {
+
+$gamesplist['quakeiii'] = array();
/* quake3 */
- $gamesplist[] = array('quakeiii', 'udp', '27910', '27919', 'both');
- }
+ $gamesplist['quakeiii'][] = array('quakeiii', 'udp', '27910', '27919', 'both');
- if($_POST['tigerwoods2004ps2'] != "") {
+
+$gamesplist['tigerwoods2004ps2'] = array();
/* tiger woods 2004 ps2 */
- $gamesplist[] = array('Outbound2Player', 'udp', '3658', '3658', 'both');
- $gamesplist[] = array('Outbound2Player2', 'udp', '6000', '6000', 'both');
- $gamesplist[] = array('Outbound2EA', 'tcp', '10300', '10301', 'both');
- }
+ $gamesplist['tigerwoods2004ps2'][] = array('Outbound2Player', 'udp', '3658', '3658', 'both');
+ $gamesplist['tigerwoods2004ps2'][] = array('Outbound2Player2', 'udp', '6000', '6000', 'both');
+ $gamesplist['tigerwoods2004ps2'][] = array('Outbound2EA', 'tcp', '10300', '10301', 'both');
+
+
+$gamesplist['callofduty'] = array();
+ $gamesplist['callofduty'][] = array('CallOfDuty1', 'tcp', '28960', '28960', 'both');
+ $gamesplist['callofduty'][] = array('CallOfDuty2', 'udp', '28960', '28960', 'both');
- if($_POST['callofduty'] != "") {
- $gamesplist[] = array('CallOfDuty1', 'tcp', '28960', '28960', 'both');
- $gamesplist[] = array('CallOfDuty2', 'udp', '28960', '28960', 'both');
- }
- if($_POST['planetside'] != "") {
+$gamesplist['planetside'] = array();
/* PlanetSide */
- $gamesplist[] = array('PlanetSide', 'tcp', '7000', '7000', 'both');
- $gamesplist[] = array('PlanetSide', 'tcp', '7080', '7080', 'both');
- $gamesplist[] = array('PlanetSide2', 'udp', '3016', '3021', 'both');
- $gamesplist[] = array('PlanetSide2', 'udp', '45000', '45010', 'both');
- $gamesplist[] = array('PlanetSide2', 'udp', '30000', '30500', 'both');
- }
+ $gamesplist['planetside'][] = array('PlanetSide', 'tcp', '7000', '7000', 'both');
+ $gamesplist['planetside'][] = array('PlanetSide', 'tcp', '7080', '7080', 'both');
+ $gamesplist['planetside'][] = array('PlanetSide2', 'udp', '3016', '3021', 'both');
+ $gamesplist['planetside'][] = array('PlanetSide2', 'udp', '45000', '45010', 'both');
+ $gamesplist['planetside'][] = array('PlanetSide2', 'udp', '30000', '30500', 'both');
+
- if($_POST['halo2'] != "") {
+$gamesplist['halo2'] = array();
/* Halo2 + XBOX Live */
- $gamesplist[] = array('Halo2-1', 'udp', '88', '88', 'both');
- $gamesplist[] = array('Halo2-2', 'udp', '3074', '3074', 'both');
- $gamesplist[] = array('Halo2-3', 'tcp', '3074', '3074', 'both');
- }
+ $gamesplist['halo2'][] = array('Halo2-1', 'udp', '88', '88', 'both');
+ $gamesplist['halo2'][] = array('Halo2-2', 'udp', '3074', '3074', 'both');
+ $gamesplist['halo2'][] = array('Halo2-3', 'tcp', '3074', '3074', 'both');
+
- if($_POST['unrealtournament'] != "") {
+$gamesplist['unrealtournament'] = array();
/* Unreal Tournament */
- $gamesplist[] = array('ur1', 'udp', '7777', '7787', 'both');
- $gamesplist[] = array('ur2', 'tcp', '7777', '7787', 'both');
- }
+ $gamesplist['unrealtournament'][] = array('ur1', 'udp', '7777', '7787', 'both');
+ $gamesplist['unrealtournament'][] = array('ur2', 'tcp', '7777', '7787', 'both');
- if($_POST['doom3'] != "") {
+
+$gamesplist['doom3'] = array();
/* doom3 */
- $gamesplist[] = array('DOOM3-1', 'udp', '27650', '27650', 'both');
- $gamesplist[] = array('DOOM3-2', 'udp', '27666', '27666', 'both');
- }
+ $gamesplist['doom3'][] = array('DOOM3-1', 'udp', '27650', '27650', 'both');
+ $gamesplist['doom3'][] = array('DOOM3-2', 'udp', '27666', '27666', 'both');
- if($_POST['empireearth'] != "") {
+
+$gamesplist['empireearth'] = array();
/* empire earth */
- $gamesplist[] = array('EmpireEarth-1', 'tcp', '33335', '33336', 'both');
- $gamesplist[] = array('EmpireEarth-2', 'udp', '33334', '33334', 'both');
- }
+ $gamesplist['empireearth'][] = array('EmpireEarth-1', 'tcp', '33335', '33336', 'both');
+ $gamesplist['empireearth'][] = array('EmpireEarth-2', 'udp', '33334', '33334', 'both');
+
- if($_POST['everquest'] != "") {
+$gamesplist['everquest'] = array();
/* everquest */
- $gamesplist[] = array('Everquest-1', 'tcp', '1024', '6000', 'both');
- $gamesplist[] = array('Everquest-2', 'tcp', '7000', '7000', 'both');
- $gamesplist[] = array('Everquest-3', 'udp', '1024', '6000', 'both');
- $gamesplist[] = array('Everquest-4', 'udp', '7000', '7000', 'both');
- }
+ $gamesplist['everquest'][] = array('Everquest-1', 'tcp', '1024', '6000', 'both');
+ $gamesplist['everquest'][] = array('Everquest-2', 'tcp', '7000', '7000', 'both');
+ $gamesplist['everquest'][] = array('Everquest-3', 'udp', '1024', '6000', 'both');
+ $gamesplist['everquest'][] = array('Everquest-4', 'udp', '7000', '7000', 'both');
+
- if($_POST['everquest2'] != "") {
+$gamesplist['everquest2'] = array();
/* everquest2 */
- $gamesplist[] = array('Everquest2-1', 'tcp', '7000', '7000', 'both');
- $gamesplist[] = array('Everquest2-2', 'udp', '3016', '3021', 'both');
- $gamesplist[] = array('Everquest2-3', 'udp', '9100', '9100', 'both');
- $gamesplist[] = array('Everquest2-4', 'udp', '9700', '9703', 'both');
- $gamesplist[] = array('Everquest2-5', 'udp', '32800', '33000', 'both');
- }
-
- if($_POST['farcry'] != "") {
+ $gamesplist['everquest2'][] = array('Everquest2-1', 'tcp', '7000', '7000', 'both');
+ $gamesplist['everquest2'][] = array('Everquest2-2', 'udp', '3016', '3021', 'both');
+ $gamesplist['everquest2'][] = array('Everquest2-3', 'udp', '9100', '9100', 'both');
+ $gamesplist['everquest2'][] = array('Everquest2-4', 'udp', '9700', '9703', 'both');
+ $gamesplist['everquest2'][] = array('Everquest2-5', 'udp', '32800', '33000', 'both');
+
+
+$gamesplist['farcry'] = array();
/* far cry */
- $gamesplist[] = array('FarCry-1', 'tcp', '49001', '49002', 'both');
- $gamesplist[] = array('FarCry-2', 'udp', '49001', '49002', 'both');
- }
+ $gamesplist['farcry'][] = array('FarCry-1', 'tcp', '49001', '49002', 'both');
+ $gamesplist['farcry'][] = array('FarCry-2', 'udp', '49001', '49002', 'both');
+
- if($_POST['halflife2'] != "") {
+$gamesplist['halflife2'] = array();
/* halflife 2 */
- $gamesplist[] = array('HL2-1', 'tcp', '27020', '27050', 'both');
- $gamesplist[] = array('HL2-2', 'udp', '1200', '1200', 'both');
- $gamesplist[] = array('HL2-3', 'udp', '27000', '27015', 'both');
- }
+ $gamesplist['halflife2'][] = array('HL2-1', 'tcp', '27020', '27050', 'both');
+ $gamesplist['halflife2'][] = array('HL2-2', 'udp', '1200', '1200', 'both');
+ $gamesplist['halflife2'][] = array('HL2-3', 'udp', '27000', '27015', 'both');
+
- if($_POST['halflife'] != "") {
+$gamesplist['halflife'] = array();
/* halflife */
- $gamesplist[] = array('HL-1', 'tcp', '27015', '27015', 'both');
- $gamesplist[] = array('HL-2', 'udp', '27650', '27650', 'both');
- $gamesplist[] = array('HL-3', 'udp', '27666', '27666', 'both');
- }
+ $gamesplist['halflife'][] = array('HL-1', 'tcp', '27015', '27015', 'both');
+ $gamesplist['halflife'][] = array('HL-2', 'udp', '27650', '27650', 'both');
+ $gamesplist['halflife'][] = array('HL-3', 'udp', '27666', '27666', 'both');
- if($_POST['wolfet'] != "") {
+
+$gamesplist['wolfet'] = array();
/* wolfenstein enemy territory */
- $gamesplist[] = array('WolfET-1', 'tcp', '27960', '27960', 'both');
- }
+ $gamesplist['wolfet'][] = array('WolfET-1', 'tcp', '27960', '27960', 'both');
- if($_POST['lineage2'] != "") {
- /* Lineage II */
- $gamesplist[] = array('Lineage2-2009', 'tcp', '2009', '2009', 'both');
- $gamesplist[] = array('Lineage2-2106', 'tcp', '2106', '2106', 'both');
- $gamesplist[] = array('Lineage2-7777', 'tcp', '7777', '7777', 'both');
- }
- if($_POST['battlenet'] != "") {
+$gamesplist['lineage2'] = array();
+ /* Lineage II */
+ $gamesplist['lineage2'][] = array('Lineage2-2009', 'tcp', '2009', '2009', 'both');
+ $gamesplist['lineage2'][] = array('Lineage2-2106', 'tcp', '2106', '2106', 'both');
+ $gamesplist['lineage2'][] = array('Lineage2-7777', 'tcp', '7777', '7777', 'both');
+$gamesplist['battlenet'] = array();
/* Blizzard Publishing games */
- $gamesplist[] = array('Battle.NET', 'tcp', '6112', '6119', 'both');
- }
- if($_POST['worldofwarcraft'] != "") {
- /* World of WarCract */
- if ($_POST['battlenet'] == "") {
- /* Add battle.net only if WoW is selected and battle.net isn't */
- $gamesplist[] = array('Battle.NET', 'tcp', '6112', '6119', 'both');
- }
- $gamesplist[] = array('WoW', 'tcp', '3724', '3724', 'both');
- }
-
- if($_POST['archlord'] != "") {
- /* ArchLord */
- $gamesplist[] = array('AL-1', 'tcp', '11000', '11000', 'both');
- $gamesplist[] = array('AL-2', 'tcp', '11002', '11002', 'both');
- $gamesplist[] = array('AL-3', 'tcp', '11008', '11008', 'both');
- }
-
- if($_POST['gunzonline'] != "") {
- /* GunZ Online */
- $gamesplist[] = array('GunZOnline', 'udp', '7700', '7700', 'both');
- }
+ $gamesplist['battlenet'][] = array('Battle.NET', 'tcp', '6112', '6119', 'both');
+/* World of WarCract */
+$gamesplist['worldofwarcraft'] = array();
+ $gamesplist[] = array('WoW', 'tcp', '3724', '3724', 'both');
- if($_POST['xbox360'] != "") {
- /* XBox360 */
- $gamesplist[] = array('xbox360-1', 'udp', '88', '88', 'both');
- $gamesplist[] = array('xbox360-2', 'udp', '3074', '3074', 'both');
- $gamesplist[] = array('xbox360-3', 'tcp', '3074', '3074', 'both');
- }
+/* Add battle.net only if WoW is selected and battle.net isn't */
+$gamesplist['battlenet'] = array();
+ $gamesplist[] = array('Battle.NET', 'tcp', '6112', '6119', 'both');
- if($_POST['xbox360'] != "") {
- /* XBox360 */
- $gamesplist[] = array('xbox360-1', 'udp', '88', '88', 'both');
- $gamesplist[] = array('xbox360-2', 'udp', '3074', '3074', 'both');
- $gamesplist[] = array('xbox360-3', 'tcp', '3074', '3074', 'both');
- }
+/* ArchLord */
+$gamesplist['archlord'] = array();
+ $gamesplist[] = array('AL-1', 'tcp', '11000', '11000', 'both');
+ $gamesplist[] = array('AL-2', 'tcp', '11002', '11002', 'both');
+ $gamesplist[] = array('AL-3', 'tcp', '11008', '11008', 'both');
- /* XXX: add some more games before this line!! */
+/* GunZ Online */
+$gamesplist['gunzonline'] = array();
+ $gamesplist['gunzonline'][] = array('GunZOnline', 'udp', '7700', '7700', 'both');
- /* Set up/down games as higher weight */
- /* loop through p2plist[] */
- foreach ($gamesplist as $Gameclient) {
- foreach (array('source', 'destination') as $srcdest) {
- $rule = array();
- $config['shaper']['itemsshaped']++;
- if ($srcdest == 'source') {
- $destsrc = 'destination';
- $rule['inqueue'] = 'qGamesDown';
- $rule['outqueue'] = 'qGamesUp';
- $rule['in-interface'] = $downint;
- $rule['out-interface'] = $upint;
- $rule['source']['network'] = $downint;
- $rule['destination']['any'] = TRUE;
- $rule['descr'] = "m_Game {$Gameclient[0]} outbound";
- } else {
- $destsrc = 'source';
- $rule['inqueue'] = 'qGamesUp';
- $rule['outqueue'] = 'qGamesDown';
- $rule['in-interface'] = $upint;
- $rule['out-interface'] = $downint;
- $rule['source']['any'] = TRUE;
- $rule['destination']['network'] = $downint;
- $rule['descr'] = "m_Game {$Gameclient[0]} inbound";
- }
+/* XBox360 */
+$gamesplist['xbox360'] = array();
+ $gamesplist['xbox360'][] = array('xbox360-1', 'udp', '88', '88', 'both');
+ $gamesplist['xbox360'][] = array('xbox360-2', 'udp', '3074', '3074', 'both');
+ $gamesplist['xbox360'][] = array('xbox360-3', 'tcp', '3074', '3074', 'both');
- $rule['destination']['port'] = $Gameclient[2]."-".$Gameclient[3];
- if($Gameclient[1] != '')
- $rule['protocol'] = $Gameclient[1];
+$voiplist = array();
+
+ /* asterisk server / same as vonage */
+$voiplist['Asterisk'] = array();
+ $voiplist['Asterisk'][] = array($_POST['provider'], 'udp', '5060', '5069', 'both');
+ $voiplist['Asterisk'][] = array($_POST['provider'], 'udp', '10000', '20000', 'both');
+
+ /* VoicePulse server */
+$voiplist['VoicePulse'] = array();
+ $voiplist['VoicePulse'][] = array('VoicePulse', 'udp', '16384', '16482', 'both');
+ $voiplist['VoicePulse'][] = array('VoicePulse', 'udp', '4569', '4569', 'both');
+
+ /* Panasonic Hybrid PBX */
+$voiplist['Panasonic'] = array();
+ $voiplist['Panasonic'][] = array('Panasonic1', 'udp', '8000', '8063', 'both');
+ $voiplist['Panasonic'][] = array('Panasonic2', 'udp', '9300', '9301', 'both');
+ $voiplist['Panasonic'][] = array('Panasonic3', 'udp', '2747', '2747', 'both');
- $config['shaper']['rule'][] = $rule;
- }
- }
- }
-}
-function step7_stepsubmitphpaction() {
- global $g, $config;
- if ( $_POST['enable'] ) {
- $downq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['inside_int']);
- $upq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['outside_int']);
- $downint = strtolower($config['ezshaper']['step2']['inside_int']);
- $upint = strtolower($config['ezshaper']['step2']['outside_int']);
- /* create qOthersUp queue */
- $queue = array();
- $queue['name'] = "qOthersUpH";
- $queue['attachtoqueue'] = "{$upq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 4;
- $queue['red'] = "on";
- $queue['ecn'] = "on";
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "1Kb";
- $queue['bandwidth'] = 25;
- $queue['bandwidthtype'] = '%';
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- /* create qOthersDown queue */
- $queue = array();
- $queue['name'] = "qOthersDownH";
- $queue['attachtoqueue'] = "{$downq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 4;
- $queue['red'] = "on";
- $queue['ecn'] = "on";
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "1Kb";
- $queue['bandwidth'] = 25;
- $queue['bandwidthtype'] = '%';
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
-
- /* create qOthersUp queue */
- $queue = array();
- $queue['name'] = "qOthersUpL";
- $queue['attachtoqueue'] = "{$upq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 2;
- $queue['red'] = "on";
- $queue['ecn'] = "on";
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "1Kb";
- $queue['bandwidth'] = 1;
- $queue['bandwidthtype'] = '%';
- $queue['qlimit'] = 500;
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- /* create qOthersDown queue */
- $queue = array();
- $queue['name'] = "qOthersDownL";
- $queue['attachtoqueue'] = "{$downq}Root";
- $queue['associatedrule'] = 0;
- $queue['priority'] = 2;
- $queue['red'] = "on";
- $queue['ecn'] = "on";
- if ($config['shaper']['schedulertype'] == "hfsc") {
- $queue['realtime'] = "on";
- $queue['realtime3'] = "1Kb";
- $queue['bandwidth'] = 1;
- $queue['bandwidthtype'] = '%';
- $queue['qlimit'] = 500;
- } elseif ($config['shaper']['schedulertype'] == "cbq") {
- $queue['borrow'] = "on";
- $queue['bandwidth'] = 6;
- $queue['bandwidthtype'] = 'Kb';
- }
- $config['shaper']['queue'][] = $queue;
-
- $othersplist = array();
+$p2plist = array();
+ /* To add p2p clients, push Descr,Protocol,Start,End,src/dest/both onto p2plist */
+ $p2plist['aimster'] = array();
+ $p2plist['aimster'][] = array('Aimster', 'tcp', '7668', '7668', 'both');
+ $p2plist['bittorrent'] = array();
+ $p2plist['bittorrent'][] = array('BitTorrent', 'tcp', '6881', '6999', 'both');
+ $p2plist['bittorrent'][] = array('BitTorrent', 'udp', '6881', '6999', 'both');
+ $p2plist['buddyshare'] = array();
+ $p2plist['buddyshare'][] = array('BuddyShare', 'tcp', '7788', '7788', 'both');
+ $p2plist['cutemx'] = array();
+ $p2plist['cutemx'][] = array('CuteMX', 'tcp', '2340', '2340', 'both');
+ $p2plist['dc++'] = array();
+ $p2plist['dc++'][] = array('DC++', 'tcp', '1412', '1412', 'both');
+ $p2plist['dcc'] = array();
+ $p2plist['dcc'][] = array('dcc', 'tcp', '6666', '6668', 'both');
+ $p2plist['directconnect'] = array();
+ $p2plist['directconnect'][] = array('DirectConnect', 'tcp', '412', '412', 'both');
+ $p2plist['directfileexpress'] = array();
+ $p2plist['directfileexpress'][] = array('DirectFileExpress', 'tcp', '1044', '1045', 'both');
+ $p2plist['edonkey2000'] = array();
+ $p2plist['edonkey2000'][] = array('EDonkey2000', 'tcp', '4661', '4665', 'both');
+ $p2plist['fastTrack'] = array();
+ $p2plist['fastTrack'][] = array('FastTrack', 'tcp', '1214', '1214', 'both');
+ $p2plist['gnutella'] = array();
+ $p2plist['gnutella'][] = array('Gnutella-TCP', 'tcp', '6346', '6346', 'both');
+ $p2plist['gnutella'][] = array('Gnutella-UDP', 'udp', '6346', '6346', 'both');
+ $p2plist['grouper'] = array();
+ $p2plist['grouper'][] = array('grouper', 'tcp', '8038', '8039', 'both');
+ $p2plist['hotcomm'] = array();
+ $p2plist['hotcomm'][] = array('hotComm', 'tcp', '28864', '28865', 'both');
+ $p2plist['hotlineconnect'] = array();
+ $p2plist['hotlineconnect'][] = array('HotlineConnect', 'tcp', '5500', '5503', 'both');
+ $p2plist['imesh'] = array();
+ $p2plist['imesh'][] = array('iMesh', 'tcp', '4329', '4329', 'both');
+ $p2plist['napster'] = array();
+ $p2plist['napster'][] = array('Napster', 'tcp', '6699', '6701', 'both');
+ $p2plist['opennap'] = array();
+ $p2plist['opennap'][] = array('OpenNap', 'tcp', '8888', '8889', 'both');
+ $p2plist['scour'] = array();
+ $p2plist['scour'][] = array('Scour', 'tcp', '8311', '8311', 'both');
+ $p2plist['shareaza'] = array();
+ $p2plist['shareaza'][] = array('Shareaza', 'tcp', '6346', '6346', 'both');
+ $p2plist['songspy'] = array();
+ $p2plist['songspy'][] = array('SongSpy', 'tcp', '5190', '5190', 'both');
+ $p2plist['winmx'] = array();
+ $p2plist['winmx'][] = array('WinMX', 'tcp', '6699', '6699', 'both');
+
+
+
+$othersplist = array();
/* Unlike other areas we are posting the queue H or L or BLANK */
- if($_POST['msrdp'] != "") {
+ $othersplist['msrdp'] = array();
/* MSRDP */
- $othersplist[] = array('MSRDP', 'tcp', '3389', '3389', 'both', $_POST['msrdp']);
- }
-
- if($_POST['pptp'] != "") {
+ $othersplist['msrdp'][] = array('MSRDP', 'tcp', '3389', '3389', 'both');
+ $othersplist['pptp'] = array();
/* PPTP */
- $othersplist[] = array('PPTP', 'tcp', '1723', '1723', 'both', $_POST['pptp']);
- $othersplist[] = array('PPTPGRE', 'gre', '', '', 'both', $_POST['pptp']);
- }
-
- if($_POST['ipsec'] != "") {
- /* IPsec */
- $othersplist[] = array('IPsec', 'udp', '500', '500', 'both', $_POST['ipsec']);
- $othersplist[] = array('IPsec', 'ah', '', '', 'both', $_POST['ipsec']);
- $othersplist[] = array('IPsec', 'esp', '', '', 'both', $_POST['ipsec']);
- }
-
- if($_POST['streamingmp3'] != "") {
+ $othersplist['pptp'][] = array('PPTP', 'tcp', '1723', '1723', 'both');
+ $othersplist['pptp'][] = array('PPTPGRE', 'gre', '', '', 'both');
+ $othersplist['ipsec'] = array();
+ /* IPSEC */
+ $othersplist['ipsec'][] = array('IPSEC', 'udp', '500', '500', 'both');
+ $othersplist['ipsec'][] = array('IPSEC', 'ah', '', '', 'both');
+ $othersplist['ipsec'][] = array('IPSEC', 'esp', '', '', 'both');
+ $othersplist['streamingmp3'] = array();
/* streaming mp3 media aka shoutcast */
- $othersplist[] = array('STREAMINGMP3', 'tcp', '8000', '8100', 'both', $_POST['streamingmp3']);
- }
-
- if($_POST['irc'] != "") {
+ $othersplist['streamingmp3'][] = array('STREAMINGMP3', 'tcp', '8000', '8100', 'both');
+ $othersplist['irc'] = array();
/* internet relay chat */
- $othersplist[] = array('IRC', 'tcp', '6667', '6670', 'both', $_POST['irc']);
- }
-
- if($_POST['jabber'] != "") {
+ $othersplist['irc'][] = array('IRC', 'tcp', '6667', '6670', 'both');
+ $othersplist['jabber'] = array();
/* jabber */
- $othersplist[] = array('IRC', 'tcp', '5222', '5222', 'both', $_POST['jabber']);
- $othersplist[] = array('IRC', 'tcp', '5223', '5223', 'both', $_POST['jabber']);
- $othersplist[] = array('IRC', 'tcp', '5269', '5269', 'both', $_POST['jabber']);
- }
-
- if($_POST['dns'] != "") {
+ $othersplist['jabber'][] = array('IRC', 'tcp', '5222', '5222', 'both');
+ $othersplist['jabber'][] = array('IRC', 'tcp', '5223', '5223', 'both');
+ $othersplist['jabber'][] = array('IRC', 'tcp', '5269', '5269', 'both');
+ $othersplist['dns'] = array();
/* domain name system */
- $othersplist[] = array('DNS1', 'tcp', '53', '53', 'both', $_POST['dns']);
- $othersplist[] = array('DNS2', 'udp', '53', '53', 'both', $_POST['dns']);
- }
-
- if($_POST['http'] != "") {
+ $othersplist['dns'][] = array('DNS1', 'tcp', '53', '53', 'both');
+ $othersplist['dns'][] = array('DNS2', 'udp', '53', '53', 'both');
+ $othersplist['http'] = array();
/* HTTP aka Web Traffic */
- $othersplist[] = array('HTTP', 'tcp', '80', '80', 'both', $_POST['http']);
- $othersplist[] = array('HTTPS', 'tcp', '443', '443', 'both', $_POST['http']);
- }
-
- if($_POST['smtp'] != "") {
+ $othersplist['http'][] = array('HTTP', 'tcp', '80', '80', 'both');
+ $othersplist['http'][] = array('HTTPS', 'tcp', '443', '443', 'both');
+ $othersplist['smtp'] = array();
/* Secure shell traffic */
- $othersplist[] = array('SMTP', 'tcp', '25', '25', 'both', $_POST['smtp']);
- }
-
- if($_POST['pop3'] != "") {
+ $othersplist['smtp'][] = array('SMTP', 'tcp', '25', '25', 'both');
+ $othersplist['pop3'] = array();
/* Post Office Protocol - POP3 */
- $othersplist[] = array('POP3', 'tcp', '110', '110', 'both', $_POST['pop3']);
- }
-
- if($_POST['icmp'] != "") {
+ $othersplist['pop3'][] = array('POP3', 'tcp', '110', '110', 'both');
+ $othersplist['icmp'] = array();
/* ICMP */
- $othersplist[] = array('ICMP', 'icmp', '', '', 'both', $_POST['icmp']);
- }
-
- if($_POST['imap'] != "") {
+ $othersplist['icmp'][] = array('ICMP', 'icmp', '', '', 'both');
+ $othersplist['imap'] = array();
/* IMAP */
- $othersplist[] = array('IMAP', 'tcp', '143', '143', 'both', $_POST['imap']);
- }
-
- if($_POST['smb'] != "") {
+ $othersplist['imap'][] = array('IMAP', 'tcp', '143', '143', 'both');
+ $othersplist['smb'] = array();
/* Microsoft SMB and friends */
- $othersplist[] = array('SMB1', 'tcp', '445', '445', 'both', $_POST['smb']);
- $othersplist[] = array('SMB2', 'tcp', '137-139', '137-139', 'both', $_POST['smb']);
-
- if($_POST['rtsp'] != "") {
+ $othersplist['smb'][] = array('SMB1', 'tcp', '445', '445', 'both');
+ $othersplist['smb'][] = array('SMB2', 'tcp', '137-139', '137-139', 'both');
+ $othersplist['rtsp'] = array();
/* realtime streaming protocol */
- $othersplist[] = array('RTSP1', 'tcp', '554', '554', 'both', $_POST['rtsp']);
- } }
-
- if($_POST['snmp'] != "") {
+ $othersplist['rtsp'][] = array('RTSP1', 'tcp', '554', '554', 'both');
+ $othersplist['snmp'] = array();
/* Simple network management protocol */
- $othersplist[] = array('SNMP', 'tcp', '161', '161', 'both', $_POST['snmp']);
- $othersplist[] = array('SNMP2', 'udp', '161', '161', 'both', $_POST['snmp']);
- }
-
- if($_POST['vnc'] != "") {
+ $othersplist['snmp'][] = array('SNMP', 'tcp', '161', '161', 'both');
+ $othersplist['snmp'][] = array('SNMP2', 'udp', '161', '161', 'both');
+ $othersplist['vnc'] = array();
/* virtual network control */
- $othersplist[] = array('VNC', 'tcp', '5900', '5930', 'both', $_POST['vnc']);
- }
-
- if($_POST['appleremotedesktop'] != "") {
+ $othersplist['vnc'][] = array('VNC', 'tcp', '5900', '5930', 'both');
+ $othersplist['appleremotedesktop'] = array();
/* apple remote desktop */
- $othersplist[] = array('AppleRemoteDesktop1', 'tcp', '3283', '3283', 'both', $_POST['appleremotedesktop']);
- $othersplist[] = array('AppleRemoteDesktop2', 'tcp', '5900', '5900', 'both', $_POST['appleremotedesktop']);
- $othersplist[] = array('AppleRemoteDesktop3', 'udp', '3283', '3283', 'both', $_POST['appleremotedesktop']);
- $othersplist[] = array('AppleRemoteDesktop4', 'udp', '5900', '5900', 'both', $_POST['appleremotedesktop']);
- }
-
- if($_POST['icq'] != "") {
+ $othersplist['appleremotedesktop'][] = array('AppleRemoteDesktop1', 'tcp', '3283', '3283', 'both');
+ $othersplist['appleremotedesktop'][] = array('AppleRemoteDesktop2', 'tcp', '5900', '5900', 'both');
+ $othersplist['appleremotedesktop'][] = array('AppleRemoteDesktop3', 'udp', '3283', '3283', 'both');
+ $othersplist['appleremotedesktop'][] = array('AppleRemoteDesktop4', 'udp', '5900', '5900', 'both');
+ $othersplist['icq'] = array();
/* icq */
- $othersplist[] = array('ICQ1', 'tcp', '5190', '5190', 'both', $_POST['icq']);
- $othersplist[] = array('ICQ2', 'udp', '5190', '5190', 'both', $_POST['icq']);
- }
-
- if($_POST['lotusnotes'] != "") {
+ $othersplist['icq'][] = array('ICQ1', 'tcp', '5190', '5190', 'both');
+ $othersplist['icq'][] = array('ICQ2', 'udp', '5190', '5190', 'both');
+ $othersplist['lotusnotes'] = array();
/* lotus notes */
- $othersplist[] = array('LotusNotes1', 'tcp', '1352', '1352', 'both', $_POST['lotusnotes']);
- $othersplist[] = array('LotusNotes2', 'udp', '1352', '1352', 'both', $_POST['lotusnotes']);
- }
- if($_POST['aolinstantmessenger'] != "") {
+ $othersplist['lotusnotes'][] = array('LotusNotes1', 'tcp', '1352', '1352', 'both');
+ $othersplist['lotusnotes'][] = array('LotusNotes2', 'udp', '1352', '1352', 'both');
+ $othersplist['aolinstantmessenger'] = array();
/* AIM */
- $othersplist[] = array('AIM', 'tcp', '5190', '5190', 'both', $_POST['aolinstantmessenger']);
- }
-
- if($_POST['msnmessenger'] != "") {
+ $othersplist['aolinstantmessenger'][] = array('AIM', 'tcp', '5190', '5190', 'both');
+ $othersplist['msnmessenger'] = array();
/* msn messenger */
- $othersplist[] = array('MSN1', 'tcp', '1863', '1863', 'both', $_POST['msnmessenger']);
- $othersplist[] = array('MSN2', 'tcp', '6891', '6900', 'both', $_POST['msnmessenger']);
- $othersplist[] = array('MSN3', 'tcp', '6901', '6901', 'both', $_POST['msnmessenger']);
- $othersplist[] = array('MSN4', 'udp', '6901', '6901', 'both', $_POST['msnmessenger']);
- }
-
- if($_POST['mysqlserver'] != "") {
+ $othersplist['msnmessenger'][] = array('MSN1', 'tcp', '1863', '1863', 'both');
+ $othersplist['msnmessenger'][] = array('MSN2', 'tcp', '6891', '6900', 'both');
+ $othersplist['msnmessenger'][] = array('MSN3', 'tcp', '6901', '6901', 'both');
+ $othersplist['msnmessenger'][] = array('MSN4', 'udp', '6901', '6901', 'both');
+ $othersplist['mysqlserver'] = array();
/* mysql server */
- $othersplist[] = array('MySQL1', 'tcp', '3306', '3306', 'both', $_POST['mysqlserver']);
- }
-
- if($_POST['nntp'] != "") {
+ $othersplist['mysqlserver'][] = array('MySQL1', 'tcp', '3306', '3306', 'both');
+ $othersplist['nntp'] = array();
/* nntp */
- $othersplist[] = array('NNTP1', 'tcp', '119', '119', 'both', $_POST['mysqlserver']);
- $othersplist[] = array('NNTP2', 'udp', '119', '119', 'both', $_POST['mysqlserver']);
- }
-
- if($_POST['pcanywhere'] != "") {
+ $othersplist['nntp'][] = array('NNTP1', 'tcp', '119', '119', 'both');
+ $othersplist['nntp'][] = array('NNTP2', 'udp', '119', '119', 'both');
+ $othersplist['pcanywhere'] = array();
/* symantec pc anywhere */
- $othersplist[] = array('pcany1', 'tcp', '5631', '5631', 'both', $_POST['pcanywhere']);
- $othersplist[] = array('pcany2', 'udp', '5632', '5632', 'both', $_POST['pcanywhere']);
- }
-
- if($_POST['teamspeak'] != "") {
+ $othersplist['pcanywhere'][] = array('pcany1', 'tcp', '5631', '5631', 'both');
+ $othersplist['pcanywhere'][] = array('pcany2', 'udp', '5632', '5632', 'both');
+ $othersplist['teamspeak'] = array();
/* teamspeak */
- $othersplist[] = array('teamspeak1', 'tcp', '14534', '14534', 'both', $_POST['teamspeak']);
- $othersplist[] = array('teamspeak2', 'tcp', '51234', '51234', 'both', $_POST['teamspeak']);
- $othersplist[] = array('teamspeak3', 'udp', '8767', '8768', 'both', $_POST['teamspeak']);
- }
+ $othersplist['teamspeak'][] = array('teamspeak1', 'tcp', '14534', '14534', 'both');
+ $othersplist['teamspeak'][] = array('teamspeak2', 'tcp', '51234', '51234', 'both');
+ $othersplist['teamspeak'][] = array('teamspeak3', 'udp', '8767', '8768', 'both');
+ $othersplist['cvsup'] = array();
+ /* cvs */
+ $othersplist['cvsup'][] = array('cvsup', 'tcp', '5999', '5999', 'both');
+ $othersplist['hbci'] = array();
+ /* HBCI */
+ $othersplist['hbci'][] = array('HBCI', 'tcp', '3000', '3000', 'both');
+ $othersplist['p2pCatchAll'] = array();
+ $othersplist['p2pCatchAll'][] = array('p2pCatchAll', 'udp', '', '', 'both', '');
+ $othersplist['p2pCatchAll'][] = array('p2pCatchAll2', 'tcp', '', '', 'both', '');
+
+
+ unset($altq_list_queues);
+
+ $altq_list_queues = array();
+ $tmppath = array();
+
+ foreach ($config['ezshaper']['step2'] as $ifkey => $if) {
+
+ $altq =& new altq_root_queue();
+
+ $altq->SetInterface($ifkey);
+ $altq->SetScheduler($if['scheduler']);
+ $altq->SetBandwidth($if['bandwidth']);
+ $altq->SetBwscale("Kb");
+ $altq->SetEnabled("on");
+ $altq_list_queues[$altq->GetQname()] =& $altq;
+ array_push($tmppath, $ifkey);
+ $altq->SetLink($tmppath);
+ $altq->wconfig();
+
+
+ $sched = $if['scheduler'];
+ /* Values are in percent */
+ if ($sched == "CBQ" || $sched == "HFSC") {
+ if (isset($config['ezshaper']['step3']['bandwidth'])) {
+ $voip = TRUE;
+ $voipbw = $config['ezshaper']['step3']['bandwidth'];
+ } else {
+ $voip = FALSE;
+ $voipbw = 20;
+ }
+ if (isset($config['ezshaper']['step4']['enable'])) {
+ $penalty = TRUE;
+ $penaltybw = $config['ezshaper']['step4']['bandwidth'];
+ } else {
+ $penalty = FALSE;
+ $penaltybw = 0;
+ }
+ if (isset($config['ezshaper']['step5']['p2pcatchall'])) {
+ $p2pcatchall = TRUE;
+ $p2pcatchbw = $config['ezshaper']['step5']['bandwidth'];
+ } else {
+ $p2pcatchall = FALSE;
+ $p2pcatchbw = 0;
+ }
+
+
+ if ($voipbw + $penaltybw + $p2pcatchbw > 40) {
+ $message=gettext("Custom Bandwidths are greater than 70%. Please make them more reasonable to continue.");
+ header("Location: /wizard.php?xml=traffic_shaper_wizard.xml&stepid=2&message={$message}");
+ }
+ $remainbw = 100 - $voipbw - $penaltybw - $p2pcatchbw;
+ }
+
+ if ($sched == "PRIQ" || $sched == "CBQ" || $sched == "HFSC") {
+ if ($sched != "HFSC") {
+ if ($sched == "PRIQ")
+ $q =& new priq_queue();
+ else if ($sched == "CBQ")
+ $q =& new cbq_queue();
+ $tmpcf = array();
+ $tmpcf['name'] = "qACK";
+ $tmpcf['priority'] = 6;
+ $tmpcf['red'] = "on";
+ if ($sched == "CBQ") {
+ $tmpcf['borrow'] = "on";
+ $tmpcf['bandwidth'] = $remainbw * 30/100; /* 30% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ }
+ array_push($tmppath, "qACK");
+ $qtmp =& $altq->add_queue($q, &$tmpcf, &$tmppath);
+ array_pop($tmppath);
+ $qtmp->wconfig();
+ } else {
+ /* If you find out how to make qACK for HFSC work be my guest */
+ $remainbw = $remainbw + 30;
+ }
- if($_POST['cvsup'] != "") {
- /* cvsup */
- $othersplist[] = array('cvs', 'tcp', '5999', '5999', 'both', $_POST['cvsup']);
- }
- if($_POST['hbci'] != "") {
- /* HBCI */
- $othersplist[] = array('HBCI', 'tcp', '3000', '3000', 'both', $_POST['hbci']);
- }
+ if ($sched == "PRIQ")
+ $q =& new priq_queue();
+ else if ($sched == "CBQ")
+ $q =& new cbq_queue();
+ else if ($sched == "HFSC")
+ $q =& new hfsc_queue();
+ $tmpcf = array();
+ $tmpcf['name'] = "qDefault";
+ $tmpcf['priority'] = 3;
+ if (!$p2pcatchall)
+ $tmpcf['default'] = "on";
+ $tmpcf['red'] = "on";
+ if ($sched == "CBQ") {
+ $tmpcf['borrow'] = "on";
+ $tmpcf['bandwidth'] = $remainbw * 7/100; /* 7% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ } else if ($sched == "HFSC") {
+ $tmpcf['bandwidth'] = $remainbw * 7/100; /* 7% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ }
+ array_push($tmppath, "qDefault");
+ $qtmp =& $altq->add_queue($q, &$tmpcf, &$tmppath);
+ array_pop($tmppath);
+ $qtmp->wconfig();
+
+
+
+ if ($sched == "PRIQ")
+ $q =& new priq_queue();
+ else if ($sched == "CBQ")
+ $q =& new cbq_queue();
+ else if ($sched == "HFSC")
+ $q =& new hfsc_queue();
+ $tmpcf = array();
+ $tmpcf['name'] = "qP2P";
+ $tmpcf['priority'] = 1;
+ $tmpcf['red'] = "on";
+ if ($p2pcatchall) {
+ if ($sched == "CBQ") {
+ $tmpcf['borrow'] = "on";
+ $tmpcf['bandwidth'] = $p2pcatchbw;
+ $tmpcf['bandwidthtype'] = "%";
+ } else if ($sched == "HFSC") {
+ $tmpcf['bandwidth'] = $p2pcatchbw;
+ $tmpcf['bandwidthtype'] = "%";
+ }
+ $tmpcf['default'] = "on";
+ } else {
+ if ($sched == "CBQ") {
+ $tmpcf['borrow'] = "on";
+ $tmpcf['bandwidth'] = $remainbw * 5/100; /* 5% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ } else if ($sched == "HFSC") {
+ $tmpcf['bandwidth'] = $remainbw * 5/100; /* 5% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ }
+ }
+ array_push($tmppath, "qP2P");
+ $qtmp =& $altq->add_queue($q, &$tmpcf, &$tmppath);
+ array_pop($tmppath);
+ $qtmp->wconfig();
+
+ if ($sched == "PRIQ")
+ $q =& new priq_queue();
+ else if ($sched == "CBQ")
+ $q =& new cbq_queue();
+ else if ($sched == "HFSC")
+ $q =& new hfsc_queue();
+ $tmpcf = array();
+ $tmpcf['name'] = "qVoIP";
+ $tmpcf['priority'] = 7;
+ $tmpcf['red'] = "on";
+ if ($sched == "CBQ") {
+ $tmpcf['borrow'] = "on";
+ if ($voip)
+ $tmpcf['bandwidth'] = $voipbw;
+ else
+ $tmpcf['bandwidth'] = $remainbw * 20/100; /* 20% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ } else if ($sched == "HFSC") {
+ if ($voip) {
+ $tmpcf['realtime'] = "on";
+ $tmpcf['realtime1'] = "10%";
+ $tmpcf['realtime2'] = "50ms";
+ $tmpcf['realtime3'] = "{$voipbw}%";
+ } else {
+ $tmpcf['realtime'] = "on";
+ $tmpcf['realtime1'] = "10%";
+ $tmpcf['realtime2'] = "50ms";
+ $voipbw = ($remainbw * 20/100); /* 20% bandwidth */
+ $tmpcf['realtime3'] = "{$voipbw}%";
+ }
+ }
+ array_push($tmppath, "qVoIP");
+ $qtmp =& $altq->add_queue($q, &$tmpcf, &$tmppath);
+ array_pop($tmppath);
+ $qtmp->wconfig();
+
+ if ($sched == "PRIQ")
+ $q =& new priq_queue();
+ else if ($sched == "CBQ")
+ $q =& new cbq_queue();
+ else if ($sched == "HFSC")
+ $q =& new hfsc_queue();
+ $tmpcf = array();
+ $tmpcf['name'] = "qGames";
+ $tmpcf['priority'] = 5;
+ $tmpcf['red'] = "on";
+ if ($sched == "CBQ") {
+ $tmpcf['borrow'] = "on";
+ $tmpcf['bandwidth'] = $remainbw * 20/100; /* 20% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ } else if ($sched == "HFSC") {
+ $tmpcf['bandwidth'] = $remainbw * 20/100; /* 20% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ }
+ array_push($tmppath, "qGames");
+ $qtmp =& $altq->add_queue($q, &$tmpcf, &$tmppath);
+ array_pop($tmppath);
+ $qtmp->wconfig();
+
+ if ($sched == "PRIQ")
+ $q =& new priq_queue();
+ else if ($sched == "CBQ")
+ $q =& new cbq_queue();
+ else if ($sched == "HFSC")
+ $q =& new hfsc_queue();
+ $tmpcf = array();
+ $tmpcf['name'] = "qOthersHigh";
+ $tmpcf['priority'] = 4;
+ $tmpcf['red'] = "on";
+ if ($sched == "CBQ") {
+ $tmpcf['borrow'] = "on";
+ $tmpcf['bandwidth'] = $remainbw * 8/100; /* 8% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ } else if ($sched == "HFSC") {
+ $tmpcf['bandwidth'] = $remainbw * 8/100; /* 8% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ }
+ array_push($tmppath, "qOthersHigh");
+ $qtmp =& $altq->add_queue($q, &$tmpcf, &$tmppath);
+ array_pop($tmppath);
+ $qtmp->wconfig();
+
+ if ($sched == "PRIQ")
+ $q =& new priq_queue();
+ else if ($sched == "CBQ")
+ $q =& new cbq_queue();
+ else if ($sched == "HFSC")
+ $q =& new hfsc_queue();
+ $tmpcf = array();
+ $tmpcf['name'] = "qOthersLow";
+ $tmpcf['priority'] = 2;
+ $tmpcf['red'] = "on";
+ if ($sched == "CBQ") {
+ $tmpcf['borrow'] = "on";
+ if ($penalty)
+ $tmpcf['bandwidth'] = $penaltybw;
+ else
+ $tmpcf['bandwidth'] = $remainbw * 5/100; /* 5% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ } else if ($sched == "HFSC") {
+ if ($penalty)
+ $tmpcf['bandwidth'] = $penaltybw;
+ else
+ $tmpcf['bandwidth'] = $remainbw * 5/100; /* 5% bandwidth */
+ $tmpcf['bandwidthtype'] = "%";
+ }
+ array_push($tmppath, "qOthersLow");
+ $qtmp =& $altq->add_queue($q, &$tmpcf, &$tmppath);
+ array_pop($tmppath);
+ $qtmp->wconfig();
+
+ if (!is_array($config['filter']['rule']))
+ $config['filter']['rule'] = array();
+
+ }
+ array_pop($tmppath);
+
+ /* Rules */
+ if ($penalty) {
+ if( is_ipaddr($config['ezshaper']['step4']['address']) or is_alias($config['ezshaper']['step4']['address'])) {
+ $rule = array();
+ $rule['descr'] = gettext("Penalty Box");
+ $rule['interface'] = $altq->GetInterface();
+ $rule['source']['network'] = $altq->GetInterface();
+// $rule['source']['any'] = TRUE;
+ $rule['defaultqueue'] = "qOthersLow";
+ $rule['source']['address'] = $config['ezshaper']['step4']['address'];
+ $rule['destination']['any'] = TRUE;
+ $rule['wizard'] = "yes";
+ $config['filter']['rule'][] = $rule;
+
+ }
+ }
- /* XXX: add some more protocols here! */
+ /* If user specifies an IP, we don't bother with providers */
+ if( is_ipaddr($config['ezshaper']['step3']['address']) or is_alias($config['ezshaper']['step3']['address'])) {
+ /* create VOIP rules */
+ $rule = array();
+ $rule['descr'] = gettext("VOIP Adapter");
+ $rule['interface'] = $altq->GetInterface();
+ $rule['source']['network'] = $altq->GetInterface();
+// $rule['source']['any'] = TRUE;
+ $rule['defaultqueue'] = "qVoIP";
+ $rule['source']['address'] = $config['ezshaper']['step3']['address'];
+ $rule['destination']['any'] = TRUE;
+ $rule['wizard'] = "yes";
+ $config['filter']['rule'][] = $rule;
- /* Set up/down protocols as higher weight */
- /* loop through othersplist[] */
- foreach ($othersplist as $otherclient) {
- foreach (array('source', 'destination') as $srcdest) {
+ } elseif( $config['ezshaper']['step3']['provider'] == "Generic" ) {
+ /* create VOIP rules */
$rule = array();
- $config['shaper']['itemsshaped']++;
- if ($srcdest == 'source') {
- $destsrc = 'destination';
- switch ($otherclient[5]) {
- case "H":
- case "L":
- $rule['inqueue'] = 'qOthersDown' . $otherclient[5]; /* posted value H or L */
- $rule['outqueue'] = 'qOthersUp' . $otherclient[5]; /* posted value H or L */
- break;
- case "D":
- $rule['inqueue'] = "q${downint}def"; /* posted value H or L */
- $rule['outqueue'] = "q${upint}def"; /* posted value H or L */
- break;
- }
-
- $rule['in-interface'] = $downint;
- $rule['out-interface'] = $upint;
- $rule['source']['network'] = $downint;
- $rule['destination']['any'] = TRUE;
- $rule['descr'] = "m_Other {$otherclient[0]} outbound";
- } else {
- $destsrc = 'source';
- switch ($otherclient[5]) {
- case "H":
- case "L":
- $rule['inqueue'] = 'qOthersUp' . $otherclient[5]; /* posted value H or L */
- $rule['outqueue'] = 'qOthersDown' . $otherclient[5]; /* posted value H or L */
- break;
- case "D":
- $rule['inqueue'] = "q${upint}def"; /* posted value H or L */
- $rule['outqueue'] = "q${downint}def"; /* posted value H or L */
- break;
- }
- $rule['in-interface'] = $upint;
- $rule['out-interface'] = $downint;
- $rule['source']['any'] = TRUE;
- $rule['destination']['network'] = $downint;
- $rule['descr'] = "m_Other {$otherclient[0]} inbound";
- }
+ $rule['descr'] = "DiffServ/Lowdelay/Upload";
+ $rule['interface'] = $altq->GetInterface();
+ $rule['source']['network'] = $altq->GetInterface();
+// $rule['source']['any'] = TRUE;
+ $rule['defaultqueue'] = "qVoIP";
+ $rule['source']['network'] = $altq->GetInterface();
+ $rule['destination']['any'] = TRUE;
+ $rule['iptos'] = "lowdelay";
+ $rule['wizard'] = "yes";
+ $config['filter']['rule'][] = $rule;
- if($otherclient[2] or $otherclient[3]) {
- $rule['destination']['port'] = $otherclient[2]."-".$otherclient[3];
- }
- if($otherclient[1] != '')
- $rule['protocol'] = $otherclient[1];
+ } else {
+ /* loop through voiplist[] */
+ foreach ($voiplist[$config['ezshaper']['step3']['provider']] as $voip) {
+ $rule = array();
+ $rule['interface'] = $altq->GetInterface();
+ $rule['defaultqueue'] = 'qVoIP';
+ $rule['source']['network'] = $altq->GetInterface();
+// $rule['source']['any'] = TRUE;
+ $rule['destination']['any'] = TRUE;
+ $rule['descr'] = "m_voip {$voip[0]} outbound";
+ $rule['wizard'] = "yes";
+ $rule['destination']['port'] = $voip[2]."-".$voip[3];
+ if($voip[1] != '')
+ $rule['protocol'] = $voip[1];
+ $config['filter']['rule'][] = $rule;
+ }
+ }
+
- $config['shaper']['rule'][] = $rule;
- }
- }
- }
-}
-function step8_stepbeforeformdisplay() {
- global $g, $config;
- if($config['shaper']['itemsshaped'] == "0") {
- /* no shaper items have been selected
- * wipe previous
- */
- unset($config['shaper']['queue']);
- unset($config['shaper']['rule']);
- unset($config['shaper']);
- $config['shaper']['enable'] = FALSE;
- $message = "No items have been selected to shape. Exiting traffic shaper wizard.";
- write_config("No shaper items picked, unsetting shaper configuration");
- header("Location: /wizard.php?xml=traffic_shaper_wizard.xml&stepid=8&message={$message}");
- exit;
- }
-}
+ /* loop through p2plist[] */
+ foreach($config['ezshaper']['step5'] as $key => $val) {
+ if (!is_array($p2plist[$key]))
+ continue;
+ foreach ($p2plist[$key] as $p2pclient) {
+ $rule = array();
+ $rule['defaultqueue'] = 'qP2P';
+ $rule['interface'] = $altq->GetInterface();
+ $rule['source']['network'] = $altq->GetInterface();
+// $rule['source']['any'] = TRUE;
+ $rule['source']['network'] = $altq->GetInterface();
+ $rule['destination']['any'] = TRUE;
+ $rule['descr'] = "m_P2P {$p2pclient[0]} outbound";
+ $rule['wizard'] = "yes";
+ $rule['destination']['port'] = $p2pclient[2]."-".$p2pclient[3];
+ if($p2pclient[1] != '')
+ $rule['protocol'] = $p2pclient[1];
+ $config['filter']['rule'][] = $rule;
+ }
+ }
-function step8_stepsubmitphpaction() {
- global $g, $config, $d_shaperconfdirty_path;
- /* Sort rules by queue priority */
- sort_rule_by_queue_priority();
-
- $downq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['inside_int']);
- $upq = "q" . convert_friendly_interface_to_friendly_descr($config['ezshaper']['step2']['outside_int']);
- $downint = strtolower($config['ezshaper']['step2']['inside_int']);
- $upint = strtolower($config['ezshaper']['step2']['outside_int']);
-
- /* install default p2p catch all rule if user has enabled option (MUST BE LAST!) */
- if($config['ezshaper']['step5']['p2pcatchall'] == "on") {
- $othersplist = array();
- $othersplist[] = array('p2pCatchAll', 'tcp', '', '', 'both', '');
- $othersplist[] = array('p2pCatchAll2', 'udp', '', '', 'both', '');
- } else {
- $othersplist = array();
- }
+ /* loop through gamesplist[] */
+ foreach($config['ezshaper']['step6'] as $key => $val) {
+ if (!is_array($gamesplist[$key]))
+ continue;
+ foreach ($gamesplist[$key] as $Gameclient) {
+ $rule = array();
+ $rule['defaultqueue'] = 'qGames';
+ if ($sched != "HFSC")
+ $rule['ackqueue'] = 'qACK';
+ $rule['interface'] = $altq->GetInterface();
+ $rule['source']['network'] = $altq->GetInterface();
+// $rule['source']['any'] = TRUE;
+ $rule['destination']['any'] = TRUE;
+ $rule['wizard'] = "yes";
+ $rule['descr'] = "m_Game {$Gameclient[0]} outbound";
+ $rule['destination']['port'] = $Gameclient[2]."-".$Gameclient[3];
+ if($Gameclient[1] != '')
+ $rule['protocol'] = $Gameclient[1];
+ $config['filter']['rule'][] = $rule;
+ }
+ }
- /* Set up/down protocols as p2p weight */
- /* loop through othersplist[] */
- foreach ($othersplist as $otherclient) {
- foreach (array('source', 'destination') as $srcdest) {
+ /* loop through othersplist[] */
+ foreach($config['ezshaper']['step7'] as $key => $val) {
+ if (!is_array($othersplist[$key]))
+ continue;
+ foreach ($othersplist[$key] as $otherclient) {
$rule = array();
- $config['shaper']['itemsshaped']++;
- if ($srcdest == 'source') {
- $destsrc = 'destination';
- $rule['inqueue'] = 'qP2PDown' . $otherclient[5]; /* posted value H or L */
- $rule['outqueue'] = 'qP2PUp' . $otherclient[5]; /* posted value H or L */
- $rule['in-interface'] = $downint;
- $rule['out-interface'] = $upint;
- $rule['source']['network'] = $downint;
+ switch ($val) {
+ case "H":
+ $rule['defaultqueue'] = 'qOthersHigh'; /* posted value H or L */
+ if ($sched != "HFSC")
+ $rule['ackqueue'] = 'qACK';
+ $loop = 0;
+ break;
+ case "L":
+ $rule['defaultqueue'] = 'qOthersLow'; /* posted value H or L */
+ $loop = 0;
+ break;
+ case "D":
+ if ($p2pcatchall) {
+ $loop = 0;
+ $rule['defaultqueue'] = 'qDefault';
+ if ($sched != "HFSC")
+ $rule['ackqueue'] = 'qACK';
+ } else
+ $loop = 1; /* It automitaclly goes to default queue */
+ break;
+ default:
+ $loop = 1;
+ }
+ if (!$loop) {
+ $rule['interface'] = $altq->GetInterface();
+ $rule['source']['network'] = $altq->GetInterface();
+// $rule['source']['any'] = TRUE;
$rule['destination']['any'] = TRUE;
- $rule['descr'] = "p2pCatchAll outbound";
- } else {
- $destsrc = 'source';
- $rule['inqueue'] = 'qP2PUp' . $otherclient[5]; /* posted value H or L */
- $rule['outqueue'] = 'qP2PDown' . $otherclient[5]; /* posted value H or L */
- $rule['in-interface'] = $upint;
- $rule['out-interface'] = $downint;
- $rule['source']['any'] = TRUE;
- $rule['destination']['network'] = $downint;
- $rule['descr'] = "p2pCatchAll inbound";
- }
+ $rule['wizard'] = "yes";
+ $rule['descr'] = "m_Other {$otherclient[0]} outbound";
- if($otherclient[2] or $otherclient[3]) {
- $rule['destination']['port'] = $otherclient[2]."-".$otherclient[3];
+ if($otherclient[2] or $otherclient[3]) {
+ $rule['destination']['port'] = $otherclient[2]."-".$otherclient[3];
+ }
if($otherclient[1] != '')
- $rule['protocol'] = $otherclient[1];
- }
- if($rule['inqueue'] != "" and $rule['in-interface'] != "" and $rule['out-interface'] != "")
- $config['shaper']['rule'][] = $rule;
-
- }
- }
-
- /* Enable shaper */
- $config['shaper']['enable'] = TRUE;
-
- /* Prepare for next ezshaper wizard run */
- unset($config['shaper']['itemsshaped']);
-
- /* Create new rules */
- filter_configure();
-
- /* reset rrd queues */
- system("rm -f /var/db/rrd/wan-queues.rrd");
- enable_rrd_graphing();
-
- /* And we're no longer dirty! */
- unlink_if_exists($d_shaperconfdirty_path);
-
- update_filter_reload_status("Initializing");
+ $rule['protocol'] = $otherclient[1];
- /* Head over and check out the groovy queue stats */
- header("Location: status_filter_reload.php");
-}
-function step9_stepsubmitphpaction() {
- global $g, $config;
- header("Location: status_filter_reload.php");
+ $config['filter']['rule'][] = $rule;
+ }
+ }
+ }
+ }
+ write_config();
}
-
-
?>
diff --git a/usr/local/www/wizards/traffic_shaper_wizard.xml b/usr/local/www/wizards/traffic_shaper_wizard.xml
index e98bf3d..3335f53 100644
--- a/usr/local/www/wizards/traffic_shaper_wizard.xml
+++ b/usr/local/www/wizards/traffic_shaper_wizard.xml
@@ -41,15 +41,11 @@
<field>
<name>Next</name>
<type>submit</type>
- <warning>Going any further will wipe your existing shaper config! If you do not wish to continue, please click the pfSense logo at the top to return to the webConfigurator. Also note that currently the traffic shaper is not compatible with bridging.</warning>
+ <warning>Going any further will wipe your existing shaper config! If you do not wish to continue, please click the pfSense logo at the top to return to the webConfigurator.</warning>
</field>
</fields>
<stepbeforeformdisplay>
- /* Check to see if ALTQ can even be used */
- if(!is_altq_capable($config['interfaces']['wan']['if']) or !is_altq_capable($config['interfaces']['lan']['if'])) {
- $message="Either your LAN or WAN interface doesn't support ALTQ. The wizard cannot continue.";
- header("Location: /wizard.php?xml=traffic_shaper_wizard.xml&amp;stepid=7&amp;message={$message}");
- }
+ step1_stepbeforeformdisplay();
</stepbeforeformdisplay>
<stepsubmitphpaction>
step1_stepsubmitphpaction();
@@ -103,8 +99,8 @@
</field>
</fields>
<stepsubmitphpaction>
- step2_stepsubmitphpaction();
- </stepsubmitphpaction>
+ step2_stepsubmitphpaction();
+ </stepsubmitphpaction>
<includefile>/usr/local/www/wizards/traffic_shaper_wizard.inc</includefile>
</step>
<step>
@@ -142,11 +138,7 @@
<value>VoicePulse</value>
</option>
<option>
- <name>Vonage</name>
- <value>Vonage</value>
- </option>
- <option>
- <name>Asterisk</name>
+ <name>Asterisk/Vonage</name>
<value>Asterisk</value>
</option>
<option>
@@ -164,92 +156,9 @@
</field>
<field>
<name>Bandwidth</name>
- <type>select</type>
- <typehint>Total bandwidth guarantee for VOIP phone(s)</typehint>
- <default>128</default>
+ <type>input</type>
+ <typehint>Total bandwidth(in percentage %) guarantee for VOIP phone(s)</typehint>
<bindstofield>ezshaper->step3->bandwidth</bindstofield>
- <options>
- <option>
- <name>32Kbits/sec</name>
- <value>32</value>
- </option>
- <option>
- <name>64Kbits/sec</name>
- <value>64</value>
- </option>
- <option>
- <name>96Kbits/sec</name>
- <value>96</value>
- </option>
- <option>
- <name>128Kbits/sec</name>
- <value>128</value>
- </option>
- <option>
- <name>256Kbits/sec</name>
- <value>256</value>
- </option>
- <option>
- <name>384Kbits/sec</name>
- <value>384</value>
- </option>
- <option>
- <name>512Kbits/sec</name>
- <value>512</value>
- </option>
- <option>
- <name>768Kbits/sec</name>
- <value>768</value>
- </option>
- <option>
- <name>1024Kbits/sec</name>
- <value>1024</value>
- </option>
- <option>
- <name>1500Kbits/sec</name>
- <value>1500</value>
- </option>
- <option>
- <name>3000Kbits/sec</name>
- <value>3000</value>
- </option>
- <option>
- <name>4000Kbits/sec</name>
- <value>4000</value>
- </option>
- <option>
- <name>5000Kbits/sec</name>
- <value>5000</value>
- </option>
- <option>
- <name>6000Kbits/sec</name>
- <value>6000</value>
- </option>
- <option>
- <name>7000Kbits/sec</name>
- <value>7000</value>
- </option>
- <option>
- <name>8000Kbits/sec</name>
- <value>8000</value>
- </option>
- <option>
- <name>9000Kbits/sec</name>
- <value>9000</value>
- </option>
- <option>
- <name>10000Kbits/sec</name>
- <value>10000</value>
- </option>
- <option>
- <name>11000Kbits/sec</name>
- <value>11000</value>
- </option>
- <option>
- <name>12000Kbits/sec</name>
- <value>12000</value>
- </option>
- </options>
</field>
<field>
<name>Next</name>
@@ -273,7 +182,7 @@
<type>checkbox</type>
<typehint>Penalize IP or Alias</typehint>
<description>This will lower the priority of traffic from this IP or alias.</description>
- <enablefields>Address,BandwidthUp,BandwidthDown</enablefields>
+ <enablefields>Address,Bandwidth</enablefields>
<bindstofield>ezshaper->step4->enable</bindstofield>
</field>
<field>
@@ -292,20 +201,12 @@
<message>IP Address field is non-blank and doesn't look like an IP address.</message>
</field>
<field>
- <name>BandwidthUp</name>
- <description>The upload limit in Kbits/second.</description>
+ <name>Bandwidth</name>
+ <description>The limit in percentage.</description>
<type>input</type>
<validate>^[0-9]*$</validate>
<message>Upload speed must be numerical</message>
- <bindstofield>ezshaper->step4->bandwidthup</bindstofield>
- </field>
- <field>
- <name>BandwidthDown</name>
- <description>The download limit Kbits/second.</description>
- <type>input</type>
- <validate>^[0-9]*$</validate>
- <message>Download speed must be numerical</message>
- <bindstofield>ezshaper->step4->bandwidthdown</bindstofield>
+ <bindstofield>ezshaper->step4->bandwidth</bindstofield>
</field>
<field>
<name>Next</name>
@@ -329,7 +230,7 @@
<type>checkbox</type>
<typehint>Lower priority of Peer-to-Peer traffic</typehint>
<description>This will lower the priority of P2P traffic below all other traffic. Please check the items that you would like to prioritize lower than normal traffic.</description>
- <enablefields>p2pCatchAll,BandwidthUp,BandwidthDown,Aimster,BitTorrent,BuddyShare,CuteMX,DCplusplus,dcc,DirectConnect,DirectFileExpress,EDonkey2000,FastTrack,Gnutella,grouper,hotComm,HotlineConnect,iMesh,Napster,OpenNap,Scour,Shareaza,SongSpy,WinMX</enablefields>
+ <enablefields>p2pCatchAll,Bandwidth,Aimster,BitTorrent,BuddyShare,CuteMX,DCplusplus,dcc,DirectConnect,DirectFileExpress,EDonkey2000,FastTrack,Gnutella,grouper,hotComm,HotlineConnect,iMesh,Napster,OpenNap,Scour,Shareaza,SongSpy,WinMX</enablefields>
<bindstofield>ezshaper->step5->enable</bindstofield>
</field>
<field>
@@ -347,20 +248,12 @@
<bindstofield>ezshaper->step5->p2pcatchall</bindstofield>
</field>
<field>
- <name>BandwidthUp</name>
- <description>The upload limit in Kbits/second.</description>
+ <name>Bandwidth</name>
+ <description>The upload limit in percentage.</description>
<type>input</type>
<validate>^[0-9]*$</validate>
- <message>Upload speed must be numerical</message>
- <bindstofield>ezshaper->step5->bandwidthup</bindstofield>
- </field>
- <field>
- <name>BandwidthDown</name>
- <description>The download limit Kbits/second.</description>
- <type>input</type>
- <validate>^[0-9]*$</validate>
- <message>Download speed must be numerical</message>
- <bindstofield>ezshaper->step5->bandwidthdown</bindstofield>
+ <message>Speed must be numerical and in percentage of parent</message>
+ <bindstofield>ezshaper->step5->bandwidth</bindstofield>
</field>
<field>
<name>Enable/Disable specific P2P protocols</name>
@@ -513,7 +406,7 @@
<type>checkbox</type>
<typehint>Prioritize network gaming traffic</typehint>
<description>This will raise the priority of gaming traffic to higher than most traffic.</description>
- <enablefields>BattleNET,Battlefield2,CallOfDuty,Counterstrike,DeltaForce,DOOM3,EmpireEarth,Everquest,Everquest2,FarCry,GunZOnline,HalfLife,HalfLife2,Halo2,Lineage2,PlanetSide,QuakeIII,TigerWoods2004PS2,UnrealTournament,WolfensteinEnemyTerritory,WorldOfWarcraft,ArchLord,XBox360</enablefields>
+ <enablefields>BattleNET,Battlefield2,CallOfDuty,Counterstrike,DeltaForce,DOOM3,EmpireEarth,Everquest,Everquest2,FarCry,GunZOnline,HalfLife,HalfLife2,Halo2,Lineage2,PlanetSide,QuakeIII,TigerWoods2004PS2,UnrealTournament,WolfensteinEnemyTerritory,WorldOfWarcraft,XBox360</enablefields>
<donotdisable>true</donotdisable>
<bindstofield>ezshaper->step6->enable</bindstofield>
</field>
@@ -651,12 +544,6 @@
<typehint>World of Warcraft</typehint>
<bindstofield>ezshaper->step6->wow</bindstofield>
</field>
- <field>
- <name>ArchLord</name>
- <type>checkbox</type>
- <typehint>ArchLord</typehint>
- <bindstofield>ezshaper->step6->archlord</bindstofield>
- </field>
<field>
<name>Xbox360</name>
<type>checkbox</type>
@@ -668,9 +555,6 @@
<type>submit</type>
</field>
</fields>
- <stepsubmitphpaction>
- step6_stepsubmitphpaction();
- </stepsubmitphpaction>
<includefile>/usr/local/www/wizards/traffic_shaper_wizard.inc</includefile>
</step>
<step>
@@ -684,7 +568,7 @@
<type>checkbox</type>
<typehint>Other networking protocols</typehint>
<description>This will help raise or lower the priority of other protocols higher than most traffic.</description>
- <enablefields>AIM,AppleRemoteDesktop,DNS,HTTP,ICMP,ICQ,IMAP,IPsec,IRC,Jabber,LotusNotes,MSN,MSRDP,MySqlServer,PCAnywhere,POP3,PPTP,RTSP,SMB,SMTP,SNMP,StreamingMP3,TeamSpeak,VNC,NNTP,CVSUP,HBCI</enablefields>
+ <enablefields>AIM,AppleRemoteDesktop,DNS,HTTP,ICMP,ICQ,IMAP,IPSEC,IRC,Jabber,LotusNotes,MSN,MSRDP,MySqlServer,PCAnywhere,POP3,PPTP,RTSP,SMB,SMTP,SNMP,StreamingMP3,TeamSpeak,VNC,NNTP,CVSUP</enablefields>
<donotdisable>true</donotdisable>
<bindstofield>ezshaper->step7->enable</bindstofield>
</field>
@@ -925,7 +809,7 @@
<typehint>Microsoft Point to Point tunneling protocol</typehint>
</field>
<field>
- <name>IPsec</name>
+ <name>IPSEC</name>
<type>select</type>
<bindstofield>ezshaper->step7->ipsec</bindstofield>
<options>
@@ -942,7 +826,7 @@
<value>L</value>
</option>
</options>
- <typehint>IPsec VPN traffic</typehint>
+ <typehint>IPSEC VPN traffic</typehint>
</field>
<field>
<name>Multimedia/Streaming</name>
@@ -1241,33 +1125,10 @@
<typehint>CVSUP</typehint>
</field>
<field>
- <name>HBCI</name>
- <bindstofield>ezshaper->step7->hbci</bindstofield>
- <type>select</type>
- <options>
- <option>
- <name>Default priority</name>
- <value>D</value>
- </option>
- <option>
- <name>Higher priority</name>
- <value>H</value>
- </option>
- <option>
- <name>Lower priority</name>
- <value>L</value>
- </option>
- </options>
- <typehint>HBCI</typehint>
- </field>
- <field>
<name>Next</name>
<type>submit</type>
</field>
</fields>
- <stepsubmitphpaction>
- step7_stepsubmitphpaction();
- </stepsubmitphpaction>
<includefile>/usr/local/www/wizards/traffic_shaper_wizard.inc</includefile>
</step>
<step>
@@ -1289,9 +1150,6 @@
<type>submit</type>
</field>
</fields>
- <stepbeforeformdisplay>
- step8_stepbeforeformdisplay();
- </stepbeforeformdisplay>
<stepsubmitphpaction>
step8_stepsubmitphpaction();
</stepsubmitphpaction>
OpenPOWER on IntegriCloud