2005-09-25 08:23:03 +02:00
< ? php
/*
2013-03-22 16:47:53 +01:00
Copyright ( C ) 2008 Ermal Luçi
2009-11-03 18:12:29 +01:00
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 .
pfSense_BUILDER_BINARIES : / bin / kill / sbin / kldload / bin / rm / bin / ps
pfSense_MODULE : shaper
2005-09-25 08:23:03 +02:00
*/
2009-11-03 18:12:29 +01:00
/* XXX: needs some reducing on include. */
/* include all configuration functions. */
2012-01-19 20:01:16 +01:00
require_once ( " globals.inc " );
2005-09-25 08:23:03 +02:00
require_once ( " functions.inc " );
2011-01-24 18:24:28 +01:00
require_once ( " util.inc " );
require_once ( " notices.inc " );
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
/*
* I admit : ) this is derived from xmplparse . inc StartElement ()
*/
2014-02-24 13:10:11 +01:00
function & get_reference_to_me_in_config ( & $mypath )
2008-07-16 21:34:17 +02:00
{
2008-01-11 22:07:25 +01:00
global $config ;
2014-02-24 13:10:11 +01:00
$ptr =& $config [ 'shaper' ];
2008-01-11 22:07:25 +01:00
foreach ( $mypath as $indeks ) {
2009-11-03 18:12:29 +01:00
$ptr =& $ptr [ 'queue' ][ $indeks ];
}
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
return $ptr ;
2005-09-25 08:23:03 +02:00
}
2008-07-16 21:34:17 +02:00
2014-02-24 13:10:11 +01:00
function unset_object_by_reference ( & $mypath )
2008-07-16 21:34:17 +02:00
{
2008-01-11 22:07:25 +01:00
global $config ;
2005-09-25 08:23:03 +02:00
2009-11-03 18:12:29 +01:00
$ptr =& $config [ 'shaper' ];
for ( $i = 0 ; $i < count ( $mypath ) - 1 ; $i ++ ) {
$ptr =& $ptr [ 'queue' ][ $mypath [ $i ]];
}
2008-01-11 22:07:25 +01:00
unset ( $ptr [ 'queue' ][ $mypath [ $i ]]);
}
2008-07-16 21:34:17 +02:00
2014-02-24 13:10:11 +01:00
function & get_dn_reference_to_me_in_config ( & $mypath )
2008-07-16 21:34:17 +02:00
{
2008-07-14 23:50:10 +02:00
global $config ;
2009-11-03 18:12:29 +01:00
$ptr =& $config [ 'dnshaper' ];
2008-07-14 23:50:10 +02:00
foreach ( $mypath as $indeks ) {
2009-11-03 18:12:29 +01:00
$ptr =& $ptr [ 'queue' ][ $indeks ];
}
2008-07-14 23:50:10 +02:00
return $ptr ;
}
2008-07-16 21:34:17 +02:00
2014-02-24 13:10:11 +01:00
function unset_dn_object_by_reference ( & $mypath )
2008-07-16 21:34:17 +02:00
{
2008-07-14 23:50:10 +02:00
global $config ;
2009-11-03 18:12:29 +01:00
$ptr =& $config [ 'dnshaper' ];
for ( $i = 0 ; $i < count ( $mypath ) - 1 ; $i ++ ) {
$ptr =& $ptr [ 'queue' ][ $mypath [ $i ]];
}
2008-07-14 23:50:10 +02:00
unset ( $ptr [ 'queue' ][ $mypath [ $i ]]);
}
2014-02-24 13:10:11 +01:00
function clean_child_queues ( $type , $mypath )
2008-07-16 21:34:17 +02:00
{
2008-01-11 22:07:25 +01:00
$ref = & get_reference_to_me_in_config ( $mypath );
switch ( $type ) {
case 'HFSC' :
2014-02-24 13:10:11 +01:00
if ( isset ( $ref [ 'borrow' ])) unset ( $ref [ 'borrow' ]);
2008-04-22 00:47:15 +02:00
if ( isset ( $ref [ 'hogs' ])) unset ( $ref [ 'hogs' ]);
if ( isset ( $ref [ 'buckets' ])) unset ( $ref [ 'buckets' ]);
2008-01-11 22:07:25 +01:00
break ;
case 'PRIQ' :
2014-02-24 13:10:11 +01:00
if ( isset ( $ref [ 'borrow' ])) unset ( $ref [ 'borrow' ]);
2008-01-11 22:07:25 +01:00
if ( isset ( $ref [ 'bandwidth' ])) unset ( $ref [ 'bandwidth' ]);
if ( isset ( $ref [ 'bandwidthtype' ])) unset ( $ref [ 'bandwidthtype' ]);
/* fall through */
2008-04-22 00:47:15 +02:00
case 'FAIRQ' :
2014-02-24 13:10:11 +01:00
if ( isset ( $ref [ 'borrow' ])) unset ( $ref [ 'borrow' ]);
2008-04-22 00:47:15 +02:00
/* fall through */
2008-01-11 22:07:25 +01:00
case 'CBQ' :
2014-02-24 13:10:11 +01:00
if ( isset ( $ref [ 'realtime' ])) unset ( $ref [ 'realtime' ]);
2008-01-11 22:07:25 +01:00
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' ]);
2008-04-22 00:47:15 +02:00
if ( isset ( $ref [ 'upperlimit1' ])) unset ( $ref [ 'upperlimit1' ]);
if ( isset ( $ref [ 'upperlimit2' ])) unset ( $ref [ 'upperlimit2' ]);
if ( isset ( $ref [ 'upperlimit3' ])) unset ( $ref [ 'upperlimit3' ]);
2008-01-11 22:07:25 +01:00
if ( isset ( $ref [ 'linkshare' ])) unset ( $ref [ 'linkshare' ]);
2008-04-22 00:47:15 +02:00
if ( isset ( $ref [ 'linkshare1' ])) unset ( $ref [ 'linkshare1' ]);
if ( isset ( $ref [ 'linkshare2' ])) unset ( $ref [ 'linkshare2' ]);
2014-02-24 13:10:11 +01:00
if ( isset ( $ref [ 'linkshare3' ])) unset ( $ref [ 'linkshare3' ]);
2008-04-22 00:47:15 +02:00
if ( isset ( $ref [ 'hogs' ])) unset ( $ref [ 'hogs' ]);
if ( isset ( $ref [ 'buckets' ])) unset ( $ref [ 'buckets' ]);
2008-01-11 22:07:25 +01:00
break ;
}
}
2005-09-25 08:23:03 +02:00
2014-02-24 13:10:11 +01:00
function get_bandwidthtype_scale ( $type )
2008-07-16 21:34:17 +02:00
{
2014-02-24 13:10:11 +01:00
switch ( $type ) {
case " Gb " :
$factor = 1024 * 1024 * 1024 ;
break ;
case " Mb " :
$factor = 1024 * 1024 ;
break ;
case " Kb " :
$factor = 1024 ;
break ;
case " b " :
default :
$factor = 1 ;
break ;
}
return intval ( $factor );
2008-01-22 23:07:35 +01:00
}
2014-02-24 13:10:11 +01:00
function get_hfsc_bandwidth ( $object , $bw )
2008-07-16 21:34:17 +02:00
{
2008-01-22 23:07:35 +01:00
$pattern = " /[0-9]+/ " ;
2014-02-24 13:10:11 +01:00
if ( preg_match ( $pattern , $bw , $match ))
$bw_1 = $match [ 1 ];
else
return 0 ;
$pattern = " /(b|Kb|Mb|Gb|%)/ " ;
if ( preg_match ( $pattern , $bw , $match )) {
switch ( $match [ 1 ]) {
case '%' :
$bw_1 = $bw_1 / 100 * get_interface_bandwidth ( $object );
break ;
default :
$bw_1 = $bw_1 * get_bandwidthtype_scale ( $match [ 0 ]);
break ;
}
2008-03-04 19:29:38 +01:00
return floatval ( $bw_1 );
2014-02-24 13:10:11 +01:00
} else
return 0 ;
2008-01-22 23:07:35 +01:00
}
2014-02-24 13:10:11 +01:00
function get_interface_bandwidth ( $object )
2008-07-16 21:34:17 +02:00
{
2008-01-22 23:07:35 +01:00
global $altq_list_queues ;
2014-02-24 13:10:11 +01:00
$int = $object -> GetInterface ();
$altq =& $altq_list_queues [ $int ];
if ( $altq ) {
$bw_3 = $altq -> GetBandwidth ();
$bw_3 = $bw_3 * get_bandwidthtype_scale ( $altq -> GetBwscale ());
2008-03-04 19:29:38 +01:00
return floatval ( $bw_3 );
2014-02-24 13:10:11 +01:00
} else
2009-11-03 18:12:29 +01:00
return 0 ;
2008-01-22 23:07:35 +01:00
}
/*
* This is duplicated here since we cannot include guiconfig . inc .
* Including it makes all stuff break .
*/
2014-02-24 13:10:11 +01:00
function shaper_do_input_validation ( $postdata , $reqdfields , $reqdfieldsn , $input_errors )
2008-07-16 21:34:17 +02:00
{
2008-01-22 23:07:35 +01:00
2014-02-24 13:10:11 +01:00
/* check for bad control characters */
foreach ( $postdata as $pn => $pd ) {
if ( is_string ( $pd ) && preg_match ( " /[ \\ x00- \\ x08 \\ x0b \\ x0c \\ x0e- \\ x1f]/ " , $pd )) {
$input_errors [] = sprintf ( gettext ( " The field '%s' contains invalid characters. " ), $pn );
}
}
for ( $i = 0 ; $i < count ( $reqdfields ); $i ++ ) {
if ( $postdata [ $reqdfields [ $i ]] == " " ) {
$input_errors [] = sprintf ( gettext ( " The field '%s' is required. " ), $reqdfieldsn [ $i ]);
}
}
2008-01-22 23:07:35 +01:00
}
2014-02-24 13:10:11 +01:00
function cleanup_queue_from_rules ( $queue )
2008-07-16 21:34:17 +02:00
{
2008-01-11 22:07:25 +01:00
global $config ;
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
foreach ( $config [ 'filter' ][ 'rule' ] as $rule ) {
if ( $rule [ 'defaultqueue' ] == $queue )
unset ( $rule [ 'defaultqueue' ]);
if ( $rule [ 'ackqueue' ] == $queue )
unset ( $rule [ 'ackqueue' ]);
}
2005-09-25 08:23:03 +02:00
}
2014-02-24 13:10:11 +01:00
function cleanup_dnqueue_from_rules ( $queue )
2008-07-16 21:34:17 +02:00
{
2008-07-14 23:50:10 +02:00
global $config ;
foreach ( $config [ 'filter' ][ 'rule' ] as $rule ) {
if ( $rule [ 'dnpipe' ] == $queue )
unset ( $rule [ 'dnpipe' ]);
if ( $rule [ 'pdnpipe' ] == $queue )
unset ( $rule [ 'pdnpipe' ]);
}
}
2008-01-11 22:07:25 +01:00
class altq_root_queue {
2009-11-03 18:12:29 +01:00
var $interface ;
var $tbrconfig ;
var $bandwidth ;
var $bandwidthtype ; /* b, Kb, Mb */
var $scheduler ;
var $qlimit ;
var $queues = array ();
var $qenabled = false ;
var $link ;
var $available_bw ; /* in b/s */
/* Accesor functions */
2008-01-16 23:52:27 +01:00
function GetAvailableBandwidth () {
return $this -> available_bw ;
}
function SetAvailableBandwidth ( $bw ) {
$this -> available_bw = $bw ;
}
2008-01-11 22:07:25 +01:00
function GetDefaultQueuePresent () {
2011-08-11 23:39:22 +02:00
if ( ! empty ( $this -> queues )) {
foreach ( $this -> queues as $q ) {
if ( $q -> GetDefault ())
return true ;
}
}
return false ;
2008-01-11 22:07:25 +01:00
}
function SetLink ( $link ) {
$this -> link = $link ;
}
function GetLink () {
return $this -> link ;
2014-02-24 13:10:11 +01:00
}
2008-01-11 22:07:25 +01:00
function GetEnabled () {
return $this -> qenabled ;
}
2008-01-16 23:52:27 +01:00
function SetEnabled ( $value ) {
2008-01-11 22:07:25 +01:00
$this -> qenabled = $value ;
}
2009-08-28 01:29:47 +02:00
function CanHaveChildren () {
2013-05-06 20:09:24 +02:00
if ( $this -> GetScheduler () == " CODELQ " )
return false ;
else
return true ;
2008-01-11 22:07:25 +01:00
}
function CanBeDeleted () {
return false ;
}
function GetQname () {
return $this -> interface ;
}
function SetQname ( $name ) {
$this -> interface = trim ( $name );
}
2008-01-16 23:52:27 +01:00
function GetInterface () {
2009-11-03 18:12:29 +01:00
return $this -> interface ;
2008-01-16 23:52:27 +01:00
}
function SetInterface ( $name ) {
2009-11-03 18:12:29 +01:00
$this -> interface = trim ( $name );
2008-01-16 23:52:27 +01:00
}
function GetTbrConfig () {
2009-11-03 18:12:29 +01:00
return $this -> tbrconfig ;
2008-01-16 23:52:27 +01:00
}
function SetTbrConfig ( $tbrconfig ) {
2009-11-03 18:12:29 +01:00
$this -> tbrconfig = $tbrconfig ;
2008-01-16 23:52:27 +01:00
}
function GetBandwidth () {
2009-11-03 18:12:29 +01:00
return $this -> bandwidth ;
2008-01-16 23:52:27 +01:00
}
function SetBandwidth ( $bw ) {
2009-11-03 18:12:29 +01:00
$this -> bandwidth = $bw ;
2008-01-16 23:52:27 +01:00
}
function GetBwscale () {
2009-11-03 18:12:29 +01:00
return $this -> bandwidthtype ;
2008-01-16 23:52:27 +01:00
}
function SetBwscale ( $bwscale ) {
2009-11-03 18:12:29 +01:00
$this -> bandwidthtype = $bwscale ;
2008-01-16 23:52:27 +01:00
}
function GetScheduler () {
2009-11-03 18:12:29 +01:00
return $this -> scheduler ;
2008-01-16 23:52:27 +01:00
}
function SetScheduler ( $scheduler ) {
2009-11-03 18:12:29 +01:00
$this -> scheduler = trim ( $scheduler );
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
function GetQlimit () {
return $this -> qlimit ;
}
function SetQlimit ( $limit ) {
$this -> qlimit = $limit ;
}
2009-11-03 18:12:29 +01:00
2008-01-11 22:07:25 +01:00
function validate_input ( $data , & $input_errors ) {
2013-03-29 20:25:14 +01:00
2009-04-20 00:04:48 +02:00
$reqdfields [] = " bandwidth " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Bandwidth " );
2009-04-20 00:04:48 +02:00
$reqdfields [] = " bandwidthtype " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Bandwidthtype " );
2013-03-29 20:25:14 +01:00
2008-01-22 23:07:35 +01:00
shaper_do_input_validation ( $data , $reqdfields , $reqdfieldsn , $input_errors );
2013-03-29 20:25:14 +01:00
2014-02-24 13:10:11 +01:00
if ( $data [ 'bandwidth' ] && ( ! is_numeric ( $data [ 'bandwidth' ])))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Bandwidth must be an integer. " );
2014-02-24 13:10:11 +01:00
if ( $data [ 'bandwidth' ] < 0 )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Bandwidth cannot be negative. " );
2014-02-24 13:10:11 +01:00
if ( $data [ 'qlimit' ] && ( ! is_numeric ( $data [ 'qlimit' ])))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Qlimit must be an integer. " );
2014-02-24 13:10:11 +01:00
if ( $data [ 'qlimit' ] < 0 )
2013-09-03 13:45:03 +02:00
$input_errors [] = gettext ( " Qlimit must be positive. " );
2014-02-24 13:10:11 +01:00
if ( $data [ 'tbrconfig' ] && ( ! is_numeric ( $data [ 'tbrconfig' ])))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Tbrsize must be an integer. " );
2014-02-24 13:10:11 +01:00
if ( $data [ 'tbrconfig' ] < 0 )
2013-09-03 13:45:03 +02:00
$input_errors [] = gettext ( " Tbrsize must be positive. " );
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
/* Implement this to shorten some code on the frontend page */
2009-11-03 18:12:29 +01:00
function ReadConfig ( & $conf ) {
if ( isset ( $conf [ 'tbrconfig' ]))
$this -> SetTbrConfig ( $conf [ 'tbrconfig' ]);
2010-08-05 22:59:45 +02:00
else
$this -> SetTbrConfig ( $conf [ 'tbrconfig' ]);
2010-07-22 20:59:02 +02:00
$this -> SetBandwidth ( $conf [ 'bandwidth' ]);
if ( $conf [ 'bandwidthtype' ] <> " " )
$this -> SetBwscale ( $conf [ 'bandwidthtype' ]);
2008-01-11 22:07:25 +01:00
if ( isset ( $conf [ 'scheduler' ])) {
2009-11-03 18:12:29 +01:00
if ( $this -> GetScheduler () != $conf [ 'scheduler' ]) {
foreach ( $this -> queues as $q ) {
clean_child_queues ( $conf [ 'scheduler' ], $this -> GetLink ());
$q -> clean_queue ( $conf [ 'scheduler' ]);
2005-09-25 08:23:03 +02:00
}
}
2009-11-03 18:12:29 +01:00
$this -> SetScheduler ( $conf [ 'scheduler' ]);
}
2008-01-16 23:52:27 +01:00
if ( isset ( $conf [ 'qlimit' ]) && $conf [ 'qlimit' ] <> " " )
2008-01-11 22:07:25 +01:00
$this -> SetQlimit ( $conf [ 'qlimit' ]);
2010-08-05 22:59:45 +02:00
else
$this -> SetQlimit ( " " );
2008-01-11 22:07:25 +01:00
if ( isset ( $conf [ 'name' ]))
2014-02-24 13:10:11 +01:00
$this -> SetQname ( $conf [ 'name' ]);
2009-11-03 18:27:49 +01:00
if ( ! empty ( $conf [ 'enabled' ]))
2009-11-03 18:12:29 +01:00
$this -> SetEnabled ( $conf [ 'enabled' ]);
2009-12-30 17:43:48 +01:00
else
$this -> SetEnabled ( " " );
2008-01-11 22:07:25 +01:00
}
2009-11-03 18:12:29 +01:00
2008-03-27 18:08:16 +01:00
function copy_queue ( $interface , & $cflink ) {
2014-02-24 13:10:11 +01:00
$cflink [ 'interface' ] = $interface ;
$cflink [ 'name' ] = $interface ;
$cflink [ 'scheduler' ] = $this -> GetScheduler ();
$cflink [ 'bandwidth' ] = $this -> GetBandwidth ();
$cflink [ 'bandwidthtype' ] = $this -> GetBwscale ();
$cflink [ 'qlimit' ] = $this -> GetQlimit ();
$cflink [ 'tbrconfig' ] = $this -> GetTbrConfig ();
$cflink [ 'enabled' ] = $this -> GetEnabled ();
2008-03-27 18:08:16 +01:00
if ( is_array ( $this -> queues )) {
$cflink [ 'queue' ] = array ();
foreach ( $this -> queues as $q ) {
$cflink [ 'queue' ][ $q -> GetQname ()] = array ();
2013-01-17 19:57:32 +01:00
$q -> copy_queue ( $interface , $cflink [ 'queue' ][ $q -> GetQname ()]);
2008-03-27 18:08:16 +01:00
}
2008-01-16 23:52:27 +01:00
}
2005-09-25 08:23:03 +02:00
}
2013-09-12 16:29:21 +02:00
function & get_queue_list ( & $q = null ) {
2009-11-03 18:12:29 +01:00
$qlist = array ();
2005-10-17 18:11:07 +02:00
2011-06-28 22:09:29 +02:00
//$qlist[$this->GetQname()] = & $this;
2009-11-03 18:12:29 +01:00
if ( is_array ( $this -> queues )) {
foreach ( $this -> queues as $queue )
2013-09-12 16:29:21 +02:00
$queue -> get_queue_list ( $qlist );
2008-02-21 20:23:55 +01:00
}
2009-11-03 18:12:29 +01:00
return $qlist ;
}
2008-02-21 20:23:55 +01:00
2009-11-03 18:12:29 +01:00
function & add_queue ( $interface , & $queue , & $path , & $input_errors ) {
2008-01-16 23:52:27 +01:00
2009-11-03 18:12:29 +01:00
if ( ! is_array ( $this -> queues ))
$this -> queues = array ();
switch ( $this -> GetScheduler ()) {
case " PRIQ " :
2010-03-09 08:30:51 +01:00
$q =& new priq_queue ();
2009-11-03 18:12:29 +01:00
break ;
case " HFSC " :
2010-03-09 08:30:51 +01:00
$q =& new hfsc_queue ();
2009-11-03 18:12:29 +01:00
break ;
case " CBQ " :
2010-03-09 08:30:51 +01:00
$q =& new cbq_queue ();
2009-11-03 18:12:29 +01:00
break ;
case " FAIRQ " :
2010-03-09 08:30:51 +01:00
$q =& new fairq_queue ();
2009-11-03 18:12:29 +01:00
break ;
default :
2014-02-24 13:10:11 +01:00
/* XXX: but should not happen anyway */
2009-11-03 18:12:29 +01:00
return ;
break ;
}
$q -> SetLink ( $path );
$q -> SetInterface ( $this -> GetInterface ());
$q -> SetEnabled ( " on " );
2013-09-12 16:29:21 +02:00
$q -> SetParent ( $this );
2009-11-03 18:12:29 +01:00
$q -> ReadConfig ( $queue );
$q -> validate_input ( $queue , $input_errors );
if ( count ( $input_errors )) {
2011-01-24 18:04:14 +01:00
log_error ( " SHAPER: could not create queue " . $q -> GetQname () . " on interface { $interface } because: " . print_r ( $input_errors , true ));
2008-01-16 23:52:27 +01:00
return $q ;
2008-01-11 22:07:25 +01:00
}
2009-11-03 18:12:29 +01:00
if ( isset ( $queue [ 'bandwidth' ])) {
switch ( $queue [ 'bandwidthtype' ]) {
case " % " :
$myBw = $this -> GetAvailableBandwidth () * $queue [ 'bandwidth' ] / 100 ;
break ;
default :
$myBw = $queue [ 'bandwidth' ] * get_bandwidthtype_scale ( $queue [ 'bandwdithtype' ]);
break ;
2008-01-16 23:52:27 +01:00
}
}
2009-11-03 18:12:29 +01:00
$q -> SetAvailableBandwidth ( $myBw );
$this -> SetAvailableBandwidth ( $this -> GetAvailableBandwidth () - $myBw );
2014-02-24 13:10:11 +01:00
$this -> queues [ $q -> GetQname ()] = & $q ;
2009-11-03 18:12:29 +01:00
ref_on_altq_queue_list ( $this -> GetQname (), $q -> GetQname ());
if ( is_array ( $queue [ 'queue' ])) {
foreach ( $queue [ 'queue' ] as $key1 => $que ) {
array_push ( $path , $key1 );
2013-09-12 16:29:21 +02:00
$q -> add_queue ( $q -> GetInterface (), $que , $path , $input_errors );
2009-11-03 18:12:29 +01:00
array_pop ( $path );
}
}
return $q ;
}
/* interface here might be optional */
function & find_queue ( $interface , $qname ) {
if ( $qname == $this -> GetQname ()) {
return $this ;
2014-02-24 13:10:11 +01:00
}
2009-11-03 18:12:29 +01:00
foreach ( $this -> queues as $q ) {
$result =& $q -> find_queue ( " " , $qname );
if ( $result )
return $result ;
}
}
2008-01-11 22:07:25 +01:00
function & find_parentqueue ( $interface , $qname ) {
if ( $qname == $interface ) {
$result = NULL ;
2014-02-24 13:10:11 +01:00
} else if ( $this -> queues [ $qname ]) {
2008-01-11 22:07:25 +01:00
$result = $this ;
} else if ( $this -> GetScheduler () <> " PRIQ " ) {
foreach ( $this -> queues as $q ) {
$result = $q -> find_parentqueue ( " " , $qname );
if ( $result )
return $result ;
2005-10-17 18:11:07 +02:00
}
2005-09-25 08:23:03 +02:00
}
}
2008-01-11 22:07:25 +01:00
function build_tree () {
2008-11-16 18:49:21 +01:00
global $shaperIFlist ;
2014-02-24 13:10:11 +01:00
$tree = " <li><a href= \" firewall_shaper.php?interface= " . $this -> GetInterface () . " &queue= " . $this -> GetInterface () . " &action=show " ;
2008-11-16 18:49:21 +01:00
$tree .= " \" > " . $shaperIFlist [ $this -> GetInterface ()] . " </a> " ;
2008-01-11 22:07:25 +01:00
if ( is_array ( $this -> queues )) {
$tree .= " <ul> " ;
foreach ( $this -> queues as $q ) {
$tree .= $q -> build_tree ();
}
$tree .= " </ul> " ;
}
$tree .= " </li> " ;
return $tree ;
}
2013-03-29 20:25:14 +01:00
2014-02-24 13:10:11 +01:00
function delete_queue () {
2008-02-21 19:22:00 +01:00
foreach ( $this -> queues as $q ) {
2008-02-18 21:40:49 +01:00
$this -> SetAvailableBandwidth ( $this -> GetAvailableBandwidth () + $q -> GetAvailableBandwidth ());
2014-02-24 13:10:11 +01:00
$q -> delete_queue ();
2008-02-21 19:22:00 +01:00
}
2008-01-11 22:07:25 +01:00
unset_object_by_reference ( $this -> GetLink ());
2014-02-24 13:10:11 +01:00
}
2008-01-16 23:52:27 +01:00
2008-01-21 23:41:49 +01:00
function delete_all () {
2014-02-24 13:10:11 +01:00
if ( count ( $this -> queues )) {
foreach ( $this -> queues as $q ) {
$q -> delete_all ();
unset_object_by_reference ( $q -> GetLink ());
unset ( $q );
}
unset ( $this -> queues );
}
}
2008-01-21 23:41:49 +01:00
2008-01-16 23:52:27 +01:00
/*
* First it spits :
* altq on $interface ..............
* then it goes like
* foreach ( $queues as $qkey => $queue )
* this -> queues [ $qkey ] -> build_rule ();
*/
2011-01-28 15:39:48 +01:00
function build_rules ( & $default = false ) {
2010-05-04 18:10:18 +02:00
if ( count ( $this -> queues ) > 0 && $this -> GetEnabled () == " on " ) {
2011-01-24 18:18:46 +01:00
$default = false ;
2008-10-23 23:51:53 +02:00
$rules = " altq on " . get_real_interface ( $this -> GetInterface ());
2008-01-16 23:52:27 +01:00
if ( $this -> GetScheduler ())
2009-11-03 18:12:29 +01:00
$rules .= " " . strtolower ( $this -> GetScheduler ());
2014-07-08 13:46:45 +02:00
if ( $this -> GetQlimit () > 0 )
2014-07-09 07:07:36 +02:00
$rules .= " qlimit " . $this -> GetQlimit () . " " ;
2010-07-22 20:59:02 +02:00
if ( $this -> GetBandwidth ()) {
2009-11-03 18:12:29 +01:00
$rules .= " bandwidth " . trim ( $this -> GetBandwidth ());
2010-07-22 20:59:02 +02:00
if ( $this -> GetBwscale ())
$rules .= $this -> GetBwscale ();
}
2008-01-16 23:52:27 +01:00
if ( $this -> GetTbrConfig ())
2009-11-03 18:12:29 +01:00
$rules .= " tbrsize " . $this -> GetTbrConfig ();
2008-01-16 23:52:27 +01:00
if ( count ( $this -> queues )) {
2009-11-03 18:12:29 +01:00
$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 ) {
2011-01-28 15:39:48 +01:00
$rules .= $q -> build_rules ( $default );
2009-11-03 18:12:29 +01:00
}
2008-01-16 23:52:27 +01:00
}
2013-05-06 20:09:24 +02:00
2011-01-24 18:18:46 +01:00
if ( $default == false ) {
2011-01-24 18:24:28 +01:00
$error = " SHAPER: no default queue specified for interface " . $this -> GetInterface () . " . The interface queue will be enforced as default. " ;
file_notice ( " Shaper " , $error , " Error occurred " , " " );
unset ( $error );
2011-01-24 18:18:46 +01:00
return " \n " ;
2014-02-24 13:10:11 +01:00
}
2011-01-24 18:18:46 +01:00
$frule .= $rules ;
2013-05-06 20:09:24 +02:00
} else if ( $this -> GetEnabled () == " on " && $this -> GetScheduler () == " CODELQ " ) {
$rules = " altq on " . get_real_interface ( $this -> GetInterface ());
if ( $this -> GetScheduler ())
$rules .= " " . strtolower ( $this -> GetScheduler ());
if ( $this -> GetQlimit () > 0 )
$rules .= " ( qlimit " . $this -> GetQlimit () . " ) " ;
if ( $this -> GetBandwidth ()) {
$rules .= " bandwidth " . trim ( $this -> GetBandwidth ());
if ( $this -> GetBwscale ())
$rules .= $this -> GetBwscale ();
}
if ( $this -> GetTbrConfig ())
$rules .= " tbrsize " . $this -> GetTbrConfig ();
$rules .= " queue " ;
2008-01-11 22:07:25 +01:00
}
2013-05-06 20:09:24 +02:00
2008-01-11 22:07:25 +01:00
$rules .= " \n " ;
2008-01-16 23:52:27 +01:00
return $rules ;
}
2008-01-11 22:07:25 +01:00
function build_javascript () {
2009-11-03 18:12:29 +01:00
$javascript = " <script type= \" text/javascript \" > " ;
2013-04-07 10:52:05 +02:00
$javascript .= " //<![CDATA[ \n " ;
2009-11-03 18:12:29 +01:00
$javascript .= " function mySuspend() { " ;
2011-03-08 23:14:58 +01:00
$javascript .= " if (document.layers && document.layers['shaperarea'] != null) " ;
$javascript .= " document.layers['shaperarea'].visibility = 'hidden'; " ;
2009-11-03 18:12:29 +01:00
$javascript .= " else if (document.all) " ;
$javascript .= " document.all['shaperarea'].style.visibility = 'hidden'; " ;
$javascript .= " } " ;
$javascript .= " function myResume() { " ;
2011-03-08 23:14:58 +01:00
$javascript .= " if (document.layers && document.layers['shaperarea'] != null) " ;
2009-11-03 18:12:29 +01:00
$javascript .= " document.layers['shaperarea'].visibility = 'visible'; " ;
2011-03-08 23:14:58 +01:00
$javascript .= " else if (document.all) " ;
2009-11-03 18:12:29 +01:00
$javascript .= " document.all['shaperarea'].style.visibility = 'visible'; " ;
$javascript .= " } " ;
2013-03-22 16:47:53 +01:00
$javascript .= " //]]> " ;
2009-11-03 18:12:29 +01:00
$javascript .= " </script> " ;
return $javascript ;
2008-01-16 23:52:27 +01:00
}
2013-03-29 20:25:14 +01:00
2008-01-16 23:52:27 +01:00
function build_shortform () {
2009-11-03 18:12:29 +01:00
global $g ;
$altq =& $this ;
if ( $altq )
$scheduler = " : " . $altq -> GetScheduler ();
$form = " <tr><td width= \" 20% \" class= \" vtable \" > " ;
2013-03-23 22:12:13 +01:00
$form .= " <a href= \" firewall_shaper.php?interface= " . $this -> GetInterface () . " &queue= " . $this -> GetInterface () . " &action=show \" > " . $shaperIFlist [ $this -> GetInterface ()] . " : " . $scheduler . " </a> " ;
2009-11-03 18:12:29 +01:00
$form .= " </td></tr> " ;
$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 \" > " ;
$form .= " <a href= \" firewall_shaper_queues.php?interface= " ;
2013-03-23 22:12:13 +01:00
$form .= $this -> GetInterface () . " &queue= " ;
$form .= $this -> GetQname () . " &action=delete \" > " ;
2009-11-03 18:12:29 +01:00
$form .= " <img src= \" " ;
$form .= " ./themes/ " . $g [ 'theme' ] . " /images/icons/icon_x.gif \" " ;
2013-03-25 22:46:22 +01:00
$form .= " width= \" 17 \" height= \" 17 \" border= \" 0 \" title= \" Disable shaper on interface \" alt= \" disable \" /> " ;
2009-11-03 18:12:29 +01:00
$form .= " <span>Disable shaper on interface</span></a></td></tr> " ;
return $form ;
2008-01-16 23:52:27 +01:00
}
2009-11-03 18:12:29 +01:00
/*
2013-03-29 20:25:14 +01:00
* For requesting the parameters of the root queues
2009-11-03 18:12:29 +01:00
* to the user like the traffic wizard does .
*/
2014-02-24 13:10:11 +01:00
function build_form () {
2014-03-14 21:24:03 +01:00
$form = " <tr><td valign= \" middle \" class= \" vncellreq \" ><br /> " ;
2010-08-18 15:36:29 +02:00
$form .= gettext ( " Enable/Disable " );
2014-03-14 21:24:03 +01:00
$form .= " <br /></td><td class= \" vncellreq \" > " ;
2010-05-04 18:10:18 +02:00
$form .= " <input type= \" checkbox \" id= \" enabled \" name= \" enabled \" value= \" on \" " ;
2014-02-24 13:10:11 +01:00
if ( $this -> GetEnabled () == " on " )
$form .= " checked= \" checked \" " ;
2013-03-25 22:46:22 +01:00
$form .= " /><span class= \" vexpl \" > " . gettext ( " Enable/disable discipline and its children " ) . " </span> " ;
2010-05-04 18:10:18 +02:00
$form .= " </td></tr> " ;
2014-03-14 21:24:03 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" ><br /><span class= \" vexpl \" > " . gettext ( " Name " ) . " </span></td> " ;
2008-01-11 22:07:25 +01:00
$form .= " <td class= \" vncellreq \" > " ;
$form .= " <strong> " . $this -> GetQname () . " </strong> " ;
$form .= " </td></tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Scheduler Type " );
2008-01-11 22:07:25 +01:00
$form .= " </td> " ;
$form .= " <td class= \" vncellreq \" > " ;
$form .= " <select id= \" scheduler \" name= \" scheduler \" class= \" formselect \" > " ;
2008-04-22 18:14:25 +02:00
$form .= " <option value= \" HFSC \" " ;
2008-01-11 22:07:25 +01:00
if ( $this -> GetScheduler () == " HFSC " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2008-01-11 22:07:25 +01:00
$form .= " >HFSC</option> " ;
2008-04-22 18:14:25 +02:00
$form .= " <option value= \" CBQ \" " ;
2008-01-11 22:07:25 +01:00
if ( $this -> GetScheduler () == " CBQ " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2008-01-11 22:07:25 +01:00
$form .= " >CBQ</option> " ;
2008-04-22 18:14:25 +02:00
$form .= " <option value= \" FAIRQ \" " ;
2014-02-24 13:10:11 +01:00
if ( $this -> GetScheduler () == " FAIRQ " )
$form .= " selected= \" selected \" " ;
$form .= " >FAIRQ</option> " ;
2013-05-06 20:09:24 +02:00
$form .= " <option value= \" CODELQ \" " ;
2014-02-24 13:10:11 +01:00
if ( $this -> GetScheduler () == " CODELQ " )
$form .= " selected= \" selected \" " ;
$form .= " >CODELQ</option> " ;
2008-04-22 18:14:25 +02:00
$form .= " <option value= \" PRIQ \" " ;
2008-01-11 22:07:25 +01:00
if ( $this -> GetScheduler () == " PRIQ " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2008-01-11 22:07:25 +01:00
$form .= " >PRIQ</option> " ;
2008-04-22 18:14:25 +02:00
$form .= " </select> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> <span class= \" vexpl \" > " ;
2010-08-18 15:36:29 +02:00
$form .= gettext ( " NOTE: Changing this changes all child queues! " );
$form .= gettext ( " Beware you can lose information. " );
2008-01-11 22:07:25 +01:00
$form .= " </span> " ;
$form .= " </td></tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Bandwidth " );
2008-01-11 22:07:25 +01:00
$form .= " </td><td class= \" vncellreq \" > " ;
$form .= " <input type= \" text \" id= \" bandwidth \" name= \" bandwidth \" value= \" " ;
2014-02-24 13:10:11 +01:00
$form .= $this -> GetBandwidth () . " \" /> " ;
2008-01-16 23:52:27 +01:00
$form .= " <select id= \" bandwidthtype \" name= \" bandwidthtype \" class= \" formselect \" > " ;
$form .= " <option value= \" Kb \" " ;
2008-01-11 22:07:25 +01:00
if ( $this -> GetBwscale () == " Kb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2008-01-11 22:07:25 +01:00
$form .= " >Kbit/s</option> " ;
2008-01-16 23:52:27 +01:00
$form .= " <option value= \" Mb \" " ;
2008-01-11 22:07:25 +01:00
if ( $this -> GetBwscale () == " Mb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2008-01-16 23:52:27 +01:00
$form .= " >Mbit/s</option> " ;
$form .= " <option value= \" Gb \" " ;
if ( $this -> GetBwscale () == " Gb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2014-02-24 13:10:11 +01:00
$form .= " >Gbit/s</option> " ;
2012-03-22 16:20:41 +01:00
$form .= " <option value= \" b \" " ;
2008-01-16 23:52:27 +01:00
if ( $this -> GetBwscale () == " b " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2008-01-16 23:52:27 +01:00
$form .= " >Bit/s</option> " ;
$form .= " </select> " ;
$form .= " </td></tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" >Queue Limit</td> " ;
2008-01-16 23:52:27 +01:00
$form .= " <td class= \" vncellreq \" > " ;
$form .= " <input type= \" text \" id= \" qlimit \" name= \" qlimit \" value= \" " ;
$form .= $this -> GetQlimit ();
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2008-01-11 22:07:25 +01:00
$form .= " </td></tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" >TBR Size</td> " ;
2008-01-11 22:07:25 +01:00
$form .= " <td class= \" vncellreq \" > " ;
2010-07-21 20:19:11 +02:00
$form .= " <br /><input type= \" text \" id= \" tbrconfig \" name= \" tbrconfig \" value= \" " ;
2008-01-11 22:07:25 +01:00
$form .= $this -> GetTbrConfig ();
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> <span class= \" vexpl \" > " ;
2010-08-18 15:36:29 +02:00
$form .= gettext ( " Adjusts the size, in bytes, of the token bucket regulator. "
. " If not specified, heuristics based on the interface "
. " bandwidth are used to determine the size. " );
2009-11-03 18:12:29 +01:00
$form .= " </span></td></tr> " ;
2008-01-11 22:07:25 +01:00
$form .= " <input type= \" hidden \" id= \" interface \" name= \" interface \" " ;
2013-03-25 22:46:22 +01:00
$form .= " value= \" " . $this -> GetInterface () . " \" /> " ;
$form .= " <input type= \" hidden \" id= \" name \" name= \" name \" value= \" " . $this -> GetQname () . " \" /> " ;
2008-01-11 22:07:25 +01:00
return $form ;
}
2005-09-25 08:23:03 +02:00
2014-02-24 13:10:11 +01:00
function update_altq_queue_data ( & $data ) {
2008-01-11 22:07:25 +01:00
$this -> ReadConfig ( $data );
2005-09-25 08:23:03 +02:00
}
2013-03-29 20:25:14 +01:00
2008-01-16 23:52:27 +01:00
/*
* Should call on each of it queues and subqueues
* the same function much like build_rules ();
*/
2014-02-24 13:10:11 +01:00
function wconfig () {
2008-01-16 23:52:27 +01:00
$cflink = & get_reference_to_me_in_config ( $this -> GetLink ());
if ( ! is_array ( $cflink ))
$cflink = array ();
2014-02-24 13:10:11 +01:00
$cflink [ 'interface' ] = $this -> GetInterface ();
2008-01-16 23:52:27 +01:00
$cflink [ 'name' ] = $this -> GetQname ();
$cflink [ 'scheduler' ] = $this -> GetScheduler ();
$cflink [ 'bandwidth' ] = $this -> GetBandwidth ();
$cflink [ 'bandwidthtype' ] = $this -> GetBwscale ();
2009-11-03 18:12:29 +01:00
$cflink [ 'qlimit' ] = trim ( $this -> GetQlimit ());
if ( empty ( $cflink [ 'qlimit' ]))
unset ( $cflink [ 'qlimit' ]);
$cflink [ 'tbrconfig' ] = trim ( $this -> GetTbrConfig ());
if ( empty ( $cflink [ 'tbrconfig' ]))
unset ( $cflink [ 'tbrconfig' ]);
2008-01-16 23:52:27 +01:00
$cflink [ 'enabled' ] = $this -> GetEnabled ();
2009-11-03 18:12:29 +01:00
if ( empty ( $cflink [ 'enabled' ]))
unset ( $cflink [ 'enabled' ]);
2008-01-16 23:52:27 +01:00
}
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
}
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
class priq_queue {
2008-01-16 23:52:27 +01:00
var $qname ;
2014-02-24 13:10:11 +01:00
var $qinterface ;
2008-01-16 23:52:27 +01:00
var $qlimit ;
var $qpriority ;
var $description ;
var $isparent ;
2008-01-11 22:07:25 +01:00
var $qbandwidth ;
var $qbandwidthtype ;
2009-11-03 18:12:29 +01:00
var $qdefault = " " ;
var $qrio = " " ;
var $qred = " " ;
2013-05-06 20:09:24 +02:00
var $qcodel = " " ;
2009-11-03 18:12:29 +01:00
var $qecn = " " ;
2008-01-11 22:07:25 +01:00
var $qack ;
2009-11-03 18:12:29 +01:00
var $qenabled = " " ;
2008-01-11 22:07:25 +01:00
var $qparent ;
var $link ;
2008-01-16 23:52:27 +01:00
var $available_bw ; /* in b/s */
2009-08-28 01:29:47 +02:00
/* This is here to help with form building and building rules/lists */
2011-03-31 19:45:37 +02:00
var $subqueues = array ();
2008-01-16 23:52:27 +01:00
/* Accesor functions */
function GetAvailableBandwidth () {
return $this -> available_bw ;
}
function SetAvailableBandwidth ( $bw ) {
$this -> available_bw = $bw ;
}
function SetLink ( $link ) {
2009-11-03 18:12:29 +01:00
$this -> link = $link ;
2008-01-16 23:52:27 +01:00
}
function GetLink () {
2009-11-03 18:12:29 +01:00
return $this -> link ;
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
function & GetParent () {
return $this -> qparent ;
}
function SetParent ( & $parent ) {
$this -> qparent = & $parent ;
}
2008-01-16 23:52:27 +01:00
function GetEnabled () {
2009-11-03 18:12:29 +01:00
return $this -> qenabled ;
2008-01-16 23:52:27 +01:00
}
function SetEnabled ( $value ) {
2009-11-03 18:12:29 +01:00
$this -> qenabled = $value ;
2008-01-16 23:52:27 +01:00
}
2009-08-28 01:29:47 +02:00
function CanHaveChildren () {
2009-11-03 18:12:29 +01:00
return false ;
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
function CanBeDeleted () {
2009-11-03 18:12:29 +01:00
return true ;
2008-01-16 23:52:27 +01:00
}
function GetQname () {
2009-11-03 18:12:29 +01:00
return $this -> qname ;
2008-01-16 23:52:27 +01:00
}
function SetQname ( $name ) {
2009-11-03 18:12:29 +01:00
$this -> qname = trim ( $name );
2008-01-16 23:52:27 +01:00
}
function GetBandwidth () {
2009-11-03 18:12:29 +01:00
return $this -> qbandwidth ;
2008-01-16 23:52:27 +01:00
}
function SetBandwidth ( $bandwidth ) {
2009-11-03 18:12:29 +01:00
$this -> qbandwidth = $bandwidth ;
2008-01-16 23:52:27 +01:00
}
function GetInterface () {
2009-11-03 18:12:29 +01:00
return $this -> qinterface ;
2008-01-16 23:52:27 +01:00
}
function SetInterface ( $name ) {
2009-11-03 18:12:29 +01:00
$this -> qinterface = trim ( $name );
2008-01-16 23:52:27 +01:00
}
function GetQlimit () {
2009-11-03 18:12:29 +01:00
return $this -> qlimit ;
2008-01-16 23:52:27 +01:00
}
function SetQlimit ( $limit ) {
2009-11-03 18:12:29 +01:00
$this -> qlimit = $limit ;
2008-01-16 23:52:27 +01:00
}
function GetQpriority () {
2009-11-03 18:12:29 +01:00
return $this -> qpriority ;
2008-01-16 23:52:27 +01:00
}
function SetQpriority ( $priority ) {
2009-11-03 18:12:29 +01:00
$this -> qpriority = $priority ;
2008-01-16 23:52:27 +01:00
}
function GetDescription () {
2009-11-03 18:12:29 +01:00
return $this -> description ;
2008-01-16 23:52:27 +01:00
}
function SetDescription ( $str ) {
2009-11-03 18:12:29 +01:00
$this -> description = trim ( $str );
2008-01-16 23:52:27 +01:00
}
function GetFirstime () {
2009-11-03 18:12:29 +01:00
return $this -> firsttime ;
2008-01-16 23:52:27 +01:00
}
function SetFirsttime ( $number ) {
2009-11-03 18:12:29 +01:00
$this -> firsttime = $number ;
2008-01-16 23:52:27 +01:00
}
function GetBwscale () {
2009-11-03 18:12:29 +01:00
return $this -> qbandwidthtype ;
2008-01-16 23:52:27 +01:00
}
function SetBwscale ( $scale ) {
2009-11-03 18:12:29 +01:00
$this -> qbandwidthtype = $scale ;
2008-01-16 23:52:27 +01:00
}
2011-08-11 23:39:22 +02:00
function GetDefaultQueuePresent () {
if ( $this -> GetDefault ())
return true ;
if ( ! empty ( $this -> subqueues )) {
foreach ( $this -> subqueues as $q ) {
if ( $q -> GetDefault ())
return true ;
}
}
return false ;
}
2008-01-11 22:07:25 +01:00
function GetDefault () {
2009-11-03 18:12:29 +01:00
return $this -> qdefault ;
2008-01-16 23:52:27 +01:00
}
function SetDefault ( $value = false ) {
2009-11-03 18:12:29 +01:00
$this -> qdefault = $value ;
2008-01-16 23:52:27 +01:00
}
2013-05-06 20:09:24 +02:00
function GetCodel () {
return $this -> codel ;
}
function SetCodel ( $codel = false ) {
$this -> codel = $codel ;
}
2008-01-11 22:07:25 +01:00
function GetRed () {
2009-11-03 18:12:29 +01:00
return $this -> qred ;
2008-01-16 23:52:27 +01:00
}
function SetRed ( $red = false ) {
2009-11-03 18:12:29 +01:00
$this -> qred = $red ;
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
function GetRio () {
2009-11-03 18:12:29 +01:00
return $this -> qrio ;
2008-01-16 23:52:27 +01:00
}
function SetRio ( $rio = false ) {
2009-11-03 18:12:29 +01:00
$this -> qrio = $rio ;
2008-01-16 23:52:27 +01:00
}
2009-11-03 18:12:29 +01:00
function GetEcn () {
return $this -> qecn ;
2008-01-16 23:52:27 +01:00
}
function SetEcn ( $ecn = false ) {
2009-11-03 18:12:29 +01:00
$this -> qecn = $ecn ;
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
function GetAck () {
2009-11-03 18:12:29 +01:00
return $this -> qack ;
2008-01-16 23:52:27 +01:00
}
function SetAck ( $ack = false ) {
2009-11-03 18:12:29 +01:00
$this -> qack = $ack ;
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
function build_javascript () {
$javascript = " <script type= \" text/javascript \" > " ;
2013-04-07 10:52:05 +02:00
$javascript .= " //<![CDATA[ \n " ;
2008-01-11 22:07:25 +01:00
$javascript .= " function mySuspend() { \n " ;
2011-03-08 23:14:58 +01:00
$javascript .= " if (document.layers && document.layers['shaperarea'] != null) \n " ;
2008-01-16 23:52:27 +01:00
$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 " ;
2013-03-22 16:47:53 +01:00
$javascript .= " //]]> " ;
2008-01-16 23:52:27 +01:00
$javascript .= " </script> " ;
2013-03-29 20:25:14 +01:00
2008-01-11 22:07:25 +01:00
return $javascript ;
}
2013-03-29 20:25:14 +01:00
2008-11-16 17:56:06 +01:00
function & add_queue ( $interface , & $qname , & $path , & $input_errors ) { return ; }
2014-02-24 13:10:11 +01:00
/*
* Currently this will not be called unless we decide to clone a whole
2008-01-11 22:07:25 +01:00
* queue tree on the 'By Queues' view or support drag & drop on the tree / list
*/
2014-02-24 13:10:11 +01:00
function copy_queue ( $interface , & $cflink ) {
$cflink [ 'name' ] = $this -> GetQname ();
$cflink [ 'interface' ] = $interface ;
$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 [ 'codel' ] = $this -> GetCodel ();
$cflink [ 'rio' ] = $this -> GetRio ();
$cflink [ 'ecn' ] = $this -> GetEcn ();
if ( is_array ( $this -> subqueues )) {
$cflinkp [ 'queue' ] = array ();
foreach ( $this -> subqueues as $q ) {
$cflink [ 'queue' ][ $q -> GetQname ()] = array ();
$q -> copy_queue ( $interface , $cflink [ 'queue' ][ $q -> GetQname ()]);
2008-03-27 18:08:16 +01:00
}
2014-02-24 13:10:11 +01:00
}
2008-01-11 22:07:25 +01:00
2014-02-24 13:10:11 +01:00
}
2008-01-11 22:07:25 +01:00
function clean_queue ( $sched ) {
2008-01-16 23:52:27 +01:00
clean_child_queues ( $sched , $this -> GetLink ());
if ( is_array ( $this -> subqueues )) {
2009-11-03 18:12:29 +01:00
foreach ( $this -> subqueues as $q )
$q -> clean_queue ( $sched );
2008-01-16 23:52:27 +01:00
}
2009-11-03 18:12:29 +01:00
}
2008-01-11 22:07:25 +01:00
2014-02-24 13:10:11 +01:00
function & get_queue_list ( & $qlist ) {
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
$qlist [ $this -> GetQname ()] = & $this ;
if ( is_array ( $this -> subqueues )) {
foreach ( $this -> subqueues as $queue )
$queue -> get_queue_list ( $qlist );
}
}
2008-02-21 20:23:55 +01:00
2008-01-11 22:07:25 +01:00
function delete_queue () {
2008-01-16 23:52:27 +01:00
unref_on_altq_queue_list ( $this -> GetQname ());
cleanup_queue_from_rules ( $this -> GetQname ());
unset_object_by_reference ( $this -> GetLink ());
}
2013-03-29 20:25:14 +01:00
2008-01-21 23:41:49 +01:00
function delete_all () {
2014-02-24 13:10:11 +01:00
if ( count ( $this -> subqueues )) {
foreach ( $this -> subqueues as $q ) {
$q -> delete_all ();
unset_object_by_reference ( $q -> GetLink ());
unset ( $q );
}
unset ( $this -> subqueues );
}
}
function & find_queue ( $interface , $qname ) {
2008-01-11 22:07:25 +01:00
if ( $qname == $this -> GetQname ())
2014-02-24 13:10:11 +01:00
return $this ;
2008-01-11 22:07:25 +01:00
}
2013-03-29 20:25:14 +01:00
2010-03-09 08:30:51 +01:00
function find_parentqueue ( $interface , $qname ) { return ; }
2013-03-29 20:25:14 +01:00
2008-01-16 23:52:27 +01:00
function validate_input ( $data , & $input_errors ) {
2013-03-29 20:25:14 +01:00
2009-04-20 00:04:48 +02:00
$reqdfields [] = " name " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Name " );
2008-01-22 23:07:35 +01:00
shaper_do_input_validation ( $data , $reqdfields , $reqdfieldsn , $input_errors );
2008-01-11 22:07:25 +01:00
2013-09-03 13:45:03 +02:00
if ( $data [ 'bandwidth' ] && ( ! is_numeric ( $data [ 'bandwidth' ])))
2011-03-31 19:39:01 +02:00
$input_errors [] = " Bandwidth must be an integer. " ;
2013-09-03 13:45:03 +02:00
if ( $data [ 'bandwidth' ] < 0 )
2011-03-31 19:39:01 +02:00
$input_errors [] = " Bandwidth cannot be negative. " ;
2008-01-11 22:07:25 +01:00
if ( $data [ 'priority' ] && ( ! is_numeric ( $data [ 'priority' ])
2011-03-31 19:39:01 +02:00
|| ( $data [ 'priority' ] < 1 ) || ( $data [ 'priority' ] > 15 ))) {
2011-04-04 15:42:48 +02:00
$input_errors [] = gettext ( " The priority must be an integer between 1 and 15. " );
2008-01-16 23:52:27 +01:00
}
2014-02-24 13:10:11 +01:00
if ( $data [ 'qlimit' ] && ( ! is_numeric ( $data [ 'qlimit' ])))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Queue limit must be an integer " );
2008-01-16 23:52:27 +01:00
if ( $data [ 'qlimit' ] < 0 )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Queue limit must be positive " );
2011-03-22 20:10:21 +01:00
if ( ! empty ( $data [ 'newname' ]) && ! preg_match ( " /^[a-zA-Z0-9_-]* $ / " , $data [ 'newname' ]))
2014-02-24 13:10:11 +01:00
$input_errors [] = gettext ( " Queue names must be alphanumeric and _ or - only. " );
2011-03-22 20:10:21 +01:00
if ( ! empty ( $data [ 'name' ]) && ! preg_match ( " /^[a-zA-Z0-9_-]* $ / " , $data [ 'name' ]))
2014-02-24 13:10:11 +01:00
$input_errors [] = gettext ( " Queue names must be alphanumeric and _ or - only. " );
2013-01-21 12:45:13 +01:00
$default = $this -> GetDefault ();
if ( ! empty ( $data [ 'default' ]) && altq_get_default_queue ( $data [ 'interface' ]) && empty ( $default ))
2011-08-11 23:39:22 +02:00
$input_errors [] = gettext ( " Only one default queue per interface is allowed. " );
2005-09-25 08:23:03 +02:00
}
2008-01-16 23:52:27 +01:00
function ReadConfig ( & $q ) {
2011-02-09 23:06:19 +01:00
if ( ! empty ( $q [ 'name' ]) && ! empty ( $q [ 'newname' ]) && $q [ 'name' ] != $q [ 'newname' ]) {
$this -> SetQname ( $q [ 'newname' ]);
} else if ( ! empty ( $q [ 'newname' ])) {
$this -> SetQname ( $q [ 'newname' ]);
} else if ( isset ( $q [ 'name' ]))
$this -> SetQname ( $q [ 'name' ]);
2008-01-16 23:52:27 +01:00
if ( isset ( $q [ 'interface' ]))
2011-08-11 23:39:22 +02:00
$this -> SetInterface ( $q [ 'interface' ]);
2010-07-22 21:03:28 +02:00
$this -> SetBandwidth ( $q [ 'bandwidth' ]);
if ( $q [ 'bandwidthtype' ] <> " " )
$this -> SetBwscale ( $q [ 'bandwidthtype' ]);
2009-11-03 18:12:29 +01:00
if ( ! empty ( $q [ 'qlimit' ]))
$this -> SetQlimit ( $q [ 'qlimit' ]);
2009-12-30 17:43:48 +01:00
else
$this -> SetQlimit ( " " ); // Default
2009-11-03 18:12:29 +01:00
if ( ! empty ( $q [ 'priority' ]))
$this -> SetQPriority ( $q [ 'priority' ]);
2009-12-30 17:43:48 +01:00
else
$this -> SetQpriority ( " " );
2009-11-03 18:12:29 +01:00
if ( ! empty ( $q [ 'description' ]))
$this -> SetDescription ( $q [ 'description' ]);
2009-12-30 17:43:48 +01:00
else
2010-01-05 08:54:23 +01:00
$this -> SetDescription ( " " );
2009-11-03 18:27:49 +01:00
if ( ! empty ( $q [ 'red' ]))
2009-11-03 18:12:29 +01:00
$this -> SetRed ( $q [ 'red' ]);
2009-12-30 17:43:48 +01:00
else
$this -> SetRed ();
2013-05-06 20:09:24 +02:00
if ( ! empty ( $q [ 'codel' ]))
$this -> SetCodel ( $q [ 'codel' ]);
else
$this -> SetCodel ();
2009-11-03 18:27:49 +01:00
if ( ! empty ( $q [ 'rio' ]))
2009-11-03 18:12:29 +01:00
$this -> SetRio ( $q [ 'rio' ]);
2009-12-30 17:43:48 +01:00
else
$this -> SetRio ();
2009-11-03 18:27:49 +01:00
if ( ! empty ( $q [ 'ecn' ]))
2009-11-03 18:12:29 +01:00
$this -> SetEcn ( $q [ 'ecn' ]);
2009-12-30 17:43:48 +01:00
else
$this -> SetEcn ();
2009-11-03 18:27:49 +01:00
if ( ! empty ( $q [ 'default' ]))
2009-11-03 18:12:29 +01:00
$this -> SetDefault ( $q [ 'default' ]);
2009-12-30 17:43:48 +01:00
else
$this -> SetDefault ();
2009-11-03 18:27:49 +01:00
if ( ! empty ( $q [ 'enabled' ]))
2009-11-03 18:12:29 +01:00
$this -> SetEnabled ( $q [ 'enabled' ]);
2009-12-30 17:43:48 +01:00
else
$this -> SetEnabled ( " " );
2008-01-11 22:07:25 +01:00
2009-11-03 18:12:29 +01:00
}
2008-01-11 22:07:25 +01:00
function build_tree () {
2014-02-24 13:10:11 +01:00
$tree = " <li><a href= \" firewall_shaper.php?interface= " . $this -> GetInterface () . " &queue= " . $this -> GetQname () . " &action=show " ;
2009-11-03 18:12:29 +01:00
$tree .= " \" " ;
$tmpvalue = $this -> GetDefault ();
if ( ! empty ( $tmpvalue ))
$tree .= " class= \" navlnk \" " ;
$tree .= " > " . $this -> GetQname () . " </a> " ;
2014-02-24 13:10:11 +01:00
/*
2009-11-03 18:12:29 +01:00
* Not needed here !
* if ( is_array ( $queues ) {
* $tree .= " <ul> " ;
2014-02-24 13:10:11 +01:00
* foreach ( $q as $queues )
2009-11-03 18:12:29 +01:00
* $tree .= $queues [ '$q->GetName()' ] -> build_tree ();
2014-02-24 13:10:11 +01:00
* endforeach
2009-11-03 18:12:29 +01:00
* $tree .= " </ul> " ;
* }
2008-01-16 23:52:27 +01:00
*/
2009-11-03 18:12:29 +01:00
2014-02-24 13:10:11 +01:00
$tree .= " </li> " ;
2009-11-03 18:12:29 +01:00
return $tree ;
}
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
/* Should return something like :
* queue $qname on $qinterface bandwidth ....
*/
2011-01-28 15:39:48 +01:00
function build_rules ( & $default = false ) {
2009-11-03 18:12:29 +01:00
$pfq_rule = " queue " . $this -> qname ;
if ( $this -> GetInterface ())
$pfq_rule .= " on " . get_real_interface ( $this -> GetInterface ());
$tmpvalue = $this -> GetQpriority ();
if ( ! empty ( $tmpvalue ))
$pfq_rule .= " priority " . $this -> GetQpriority ();
$tmpvalue = $this -> GetQlimit ();
if ( ! empty ( $tmpvalue ))
$pfq_rule .= " qlimit " . $this -> GetQlimit ();
2013-05-06 20:09:24 +02:00
if ( $this -> GetRed () || $this -> GetRio () || $this -> GetEcn () || $this -> GetDefault () || $this -> GetCodel ()) {
2009-11-03 18:12:29 +01:00
$pfq_rule .= " priq ( " ;
$tmpvalue = $this -> GetRed ();
if ( ! empty ( $tmpvalue )) {
$comma = 1 ;
$pfq_rule .= " red " ;
}
$tmpvalue = $this -> GetRio ();
if ( ! empty ( $tmpvalue )) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2009-11-03 18:12:29 +01:00
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " rio " ;
}
$tmpvalue = $this -> GetEcn ();
if ( ! empty ( $tmpvalue )) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2009-11-03 18:12:29 +01:00
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " ecn " ;
}
2013-05-06 20:09:24 +02:00
$tmpvalue = $this -> GetCodel ();
if ( ! empty ( $tmpvalue )) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2013-05-06 20:09:24 +02:00
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " codel " ;
}
2009-11-03 18:12:29 +01:00
$tmpvalue = $this -> GetDefault ();
if ( ! empty ( $tmpvalue )) {
if ( $comma )
$pfq_rule .= " , " ;
$pfq_rule .= " default " ;
2011-01-24 18:18:46 +01:00
$default = true ;
2009-11-03 18:12:29 +01:00
}
$pfq_rule .= " ) " ;
2008-01-16 23:52:27 +01:00
}
2009-11-03 18:12:29 +01:00
$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 () {
2014-03-14 21:24:03 +01:00
$form = " <tr><td valign= \" middle \" class= \" vncellreq \" ><br /> " ;
2014-02-24 13:10:11 +01:00
$form .= gettext ( " Enable/Disable " );
2014-03-14 21:24:03 +01:00
$form .= " <br /></td><td class= \" vncellreq \" > " ;
2014-02-24 13:10:11 +01:00
$form .= " <input type= \" checkbox \" id= \" enabled \" name= \" enabled \" value= \" on \" " ;
if ( $this -> GetEnabled () == " on " )
$form .= " checked= \" checked \" " ;
$form .= " /><span class= \" vexpl \" > " . gettext ( " Enable/Disable queue and its children " ) . " </span> " ;
$form .= " </td></tr> " ;
2009-11-03 18:12:29 +01:00
$form .= " <tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <td width= \" 22% \" valign= \" middle \" class= \" vncellreq \" > " ;
2010-08-20 14:41:26 +02:00
$form .= gettext ( " Queue Name " ) . " </td><td width= \" 78% \" class= \" vtable \" > " ;
2011-02-09 23:06:19 +01:00
$form .= " <input name= \" newname \" type= \" text \" id= \" newname \" class= \" formfld unknown \" size= \" 15 \" maxlength= \" 15 \" value= \" " ;
$form .= htmlspecialchars ( $this -> GetQname ());
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2011-02-09 23:06:19 +01:00
$form .= " <input name= \" name \" type= \" hidden \" id= \" name \" class= \" formfld unknown \" size= \" 15 \" maxlength= \" 15 \" value= \" " ;
2008-01-11 22:07:25 +01:00
$form .= htmlspecialchars ( $this -> GetQname ());
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2010-08-18 15:36:29 +02:00
$form .= " <br /> <span class= \" vexpl \" > " . gettext ( " Enter the name of the queue here. Do not use spaces and limit the size to 15 characters. " );
2010-07-21 20:19:11 +02:00
$form .= " </span><br /></td> " ;
2008-01-11 22:07:25 +01:00
$form .= " </tr><tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <td width= \" 22% \" valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Priority " ) . " </td> " ;
2009-11-03 18:12:29 +01:00
$form .= " <td width= \" 78% \" class= \" vtable \" > <input name= \" priority \" type= \" text \" id= \" priority \" size= \" 5 \" value= \" " ;
$form .= htmlspecialchars ( $this -> GetQpriority ());
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> <span class= \" vexpl \" > " . gettext ( " 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> " ;
2009-11-03 18:12:29 +01:00
$form .= " </tr> " ;
2010-07-21 20:19:11 +02:00
$form .= " <tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <td width= \" 22% \" valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Queue limit " ) . " </td> " ;
2010-07-21 20:19:11 +02:00
$form .= " <td width= \" 78% \" class= \" vtable \" > <input name= \" qlimit \" type= \" text \" id= \" qlimit \" size= \" 8 \" value= \" " ;
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetQlimit ());
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> <span class= \" vexpl \" > " . gettext ( " Queue limit in packets. " );
2013-04-03 18:08:59 +02:00
$form .= " </span></td></tr> " ;
2009-11-03 18:12:29 +01:00
$form .= " <tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <td width= \" 22% \" valign= \" middle \" class= \" vncell \" > " . gettext ( " Scheduler options " ) . " </td> " ;
2009-11-03 18:12:29 +01:00
$form .= " <td width= \" 78% \" class= \" vtable \" > " ;
2011-03-31 19:52:01 +02:00
if ( empty ( $this -> subqueues )) {
2014-02-24 13:10:11 +01:00
if ( $this -> GetDefault ()) {
2013-03-29 20:25:14 +01:00
$form .= " <input type= \" checkbox \" id= \" default \" checked= \" checked \" name= \" default \" value= \" default \" " ;
2014-03-14 21:24:03 +01:00
$form .= " /> " . gettext ( " Default queue " ) . " <br /> " ;
2011-08-11 23:39:22 +02:00
} else {
$form .= " <input type= \" checkbox \" id= \" default \" name= \" default \" value= \" default \" " ;
2014-03-14 21:24:03 +01:00
$form .= " /> " . gettext ( " Default queue " ) . " <br /> " ;
2011-03-31 19:45:37 +02:00
}
2008-01-11 22:07:25 +01:00
}
2009-11-03 18:12:29 +01:00
$form .= " <input type= \" checkbox \" id= \" red \" name= \" red \" value= \" red \" " ;
$tmpvalue = $this -> GetRed ();
2014-02-24 13:10:11 +01:00
if ( ! empty ( $tmpvalue ))
2013-03-29 20:25:14 +01:00
$form .= " checked= \" checked \" " ;
2014-03-14 21:24:03 +01:00
$form .= " /> <a target= \" _new \" href= \" http://www.openbsd.org/faq/pf/queueing.html#red \" > " . gettext ( " Random Early Detection " ) . " </a><br /> " ;
2009-11-03 18:12:29 +01:00
$form .= " <input type= \" checkbox \" id= \" rio \" name= \" rio \" value= \" rio \" " ;
$tmpvalue = $this -> GetRio ();
2014-02-24 13:10:11 +01:00
if ( ! empty ( $tmpvalue ))
2013-03-29 20:25:14 +01:00
$form .= " checked= \" checked \" " ;
2014-03-14 21:24:03 +01:00
$form .= " /> <a target= \" _new \" href= \" http://www.openbsd.org/faq/pf/queueing.html#rio \" > " . gettext ( " Random Early Detection In and Out " ) . " </a><br /> " ;
2009-11-03 18:12:29 +01:00
$form .= " <input type= \" checkbox \" id= \" ecn \" name= \" ecn \" value= \" ecn \" " ;
$tmpvalue = $this -> GetEcn ();
2014-02-24 13:10:11 +01:00
if ( ! empty ( $tmpvalue ))
2013-03-29 20:25:14 +01:00
$form .= " checked= \" checked \" " ;
2014-03-14 21:24:03 +01:00
$form .= " /> <a target= \" _new \" href= \" http://www.openbsd.org/faq/pf/queueing.html#ecn \" > " . gettext ( " Explicit Congestion Notification " ) . " </a><br /> " ;
2013-05-06 20:09:24 +02:00
$form .= " <input type= \" checkbox \" id= \" codel \" name= \" codel \" value= \" codel \" " ;
$tmpvalue = $this -> GetCodel ();
2014-02-24 13:10:11 +01:00
if ( ! empty ( $tmpvalue ))
2013-05-06 20:09:24 +02:00
$form .= " checked= \" checked \" " ;
2014-03-14 21:24:03 +01:00
$form .= " /> <a target= \" _new \" href= \" http://www.bufferbloat.net/projects/codel/wiki \" > " . gettext ( " Codel Active Queue " ) . " </a><br /> " ;
$form .= " <span class= \" vexpl \" ><br /> " . gettext ( " Select options for this queue " );
2013-04-03 18:08:59 +02:00
$form .= " </span></td></tr><tr> " ;
2010-08-18 15:36:29 +02:00
$form .= " <td width= \" 22% \" class= \" vncellreq \" > " . gettext ( " Description " ) . " </td> " ;
2008-01-11 22:07:25 +01:00
$form .= " <td width= \" 78% \" class= \" vtable \" > " ;
2013-04-03 18:08:59 +02:00
$form .= " <input type= \" text \" name= \" description \" size= \" 40 \" class= \" formfld unknown \" value= \" " . $this -> GetDescription () . " \" /> " ;
2008-01-11 22:07:25 +01:00
$form .= " </td></tr> " ;
$form .= " <input type= \" hidden \" name= \" interface \" id= \" interface \" " ;
2013-03-25 22:46:22 +01:00
$form .= " value= \" " . $this -> GetInterface () . " \" /> " ;
2008-01-11 22:07:25 +01:00
return $form ;
2009-11-03 18:12:29 +01:00
}
2008-01-11 22:07:25 +01:00
function build_shortform () {
/* XXX: Hacks in site. Mostly layer violations! */
global $g , $altq_list_queues ;
2011-12-06 22:51:11 +01:00
global $shaperIFlist ;
2013-03-29 20:25:14 +01:00
2008-01-11 22:07:25 +01:00
$altq =& $altq_list_queues [ $this -> GetInterface ()];
if ( $altq )
$scheduler = " : " . $altq -> GetScheduler ();
2009-11-03 18:12:29 +01:00
$form = " <tr><td width= \" 20% \" class= \" vtable \" > " ;
2013-03-23 22:12:13 +01:00
$form .= " <a href= \" firewall_shaper.php?interface= " . $this -> GetInterface () . " &queue= " . $this -> GetQname () . " &action=show \" > " . $shaperIFlist [ $this -> GetInterface ()] . $scheduler . " </a> " ;
2008-01-16 23:52:27 +01:00
$form .= " </td></tr> " ;
2014-02-24 13:10:11 +01:00
/*
2008-01-11 22:07:25 +01:00
* XXX : Hack in sight maybe fix with a class that wraps all
2008-01-16 23:52:27 +01:00
* of this layer violations
2008-01-11 22:07:25 +01:00
*/
$form .= " <tr> " ;
$form .= " <td width= \" 50% \" class= \" vncellreq \" > " ;
2010-08-18 15:36:29 +02:00
$form .= gettext ( " Bandwidth: " ) . " " . $this -> GetBandwidth () . $this -> GetBwscale ();
2008-01-11 22:07:25 +01:00
$form .= " </td><td width= \" 50% \" ></td></tr> " ;
2009-11-03 18:12:29 +01:00
$tmpvalue = $this -> GetQpriority ();
if ( ! empty ( $tmpvalue ))
2013-04-03 18:08:59 +02:00
$form .= " <tr><td width= \" 20% \" class= \" vncellreq \" > " . gettext ( " Priority: on " ) . " </td></tr> " ;
2009-11-03 18:12:29 +01:00
$tmpvalue = $this -> GetDefault ();
if ( ! empty ( $tmpvalue ))
2010-08-18 15:36:29 +02:00
$form .= " <tr><td class= \" vncellreq \" > " . gettext ( " Default: on " ) . " </td></tr> " ;
2008-01-11 22:07:25 +01:00
$form .= " <tr><td width= \" 20% \" class= \" vncellreq \" > " ;
$form .= " <a href= \" firewall_shaper_queues.php?interface= " ;
2013-03-23 22:12:13 +01:00
$form .= $this -> GetInterface () . " &queue= " ;
$form .= $this -> GetQname () . " &action=delete \" > " ;
2009-11-03 18:12:29 +01:00
$form .= " <img src= \" " ;
$form .= " ./themes/ " . $g [ 'theme' ] . " /images/icons/icon_x.gif \" " ;
2013-03-25 22:46:22 +01:00
$form .= " width= \" 17 \" height= \" 17 \" border= \" 0 \" title= \" " . gettext ( " Delete queue from interface " ) . " \" alt= \" delete \" /> " ;
2010-08-18 15:36:29 +02:00
$form .= " <span> " . gettext ( " Delete queue from interface " ) . " </span></a></td></tr> " ;
2013-03-29 20:25:14 +01:00
2008-01-11 22:07:25 +01:00
return $form ;
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
}
2005-09-25 08:23:03 +02:00
2014-02-24 13:10:11 +01:00
function update_altq_queue_data ( & $q ) {
2008-01-11 22:07:25 +01:00
$this -> ReadConfig ( $q );
}
2005-09-25 08:23:03 +02:00
2009-11-03 18:12:29 +01:00
function wconfig () {
$cflink =& get_reference_to_me_in_config ( $this -> GetLink ());
2008-01-11 22:07:25 +01:00
if ( ! is_array ( $cflink ))
$cflink = array ();
$cflink [ 'name' ] = $this -> GetQname ();
2009-11-03 18:12:29 +01:00
$cflink [ 'interface' ] = $this -> GetInterface ();
$cflink [ 'qlimit' ] = trim ( $this -> GetQlimit ());
if ( empty ( $cflink [ 'qlimit' ]))
unset ( $cflink [ 'qlimit' ]);
$cflink [ 'priority' ] = trim ( $this -> GetQpriority ());
if ( empty ( $cflink [ 'priority' ]))
unset ( $cflink [ 'priority' ]);
$cflink [ 'description' ] = trim ( $this -> GetDescription ());
if ( empty ( $cflink [ 'description' ]))
unset ( $cflink [ 'description' ]);
$cflink [ 'enabled' ] = trim ( $this -> GetEnabled ());
if ( empty ( $cflink [ 'enabled' ]))
unset ( $cflink [ 'enabled' ]);
$cflink [ 'default' ] = trim ( $this -> GetDefault ());
if ( empty ( $cflink [ 'default' ]))
unset ( $cflink [ 'default' ]);
$cflink [ 'red' ] = trim ( $this -> GetRed ());
if ( empty ( $cflink [ 'red' ]))
unset ( $cflink [ 'red' ]);
2013-05-06 20:09:24 +02:00
$cflink [ 'codel' ] = trim ( $this -> GetCodel ());
if ( empty ( $cflink [ 'codel' ]))
unset ( $cflink [ 'codel' ]);
2009-11-03 18:12:29 +01:00
$cflink [ 'rio' ] = trim ( $this -> GetRio ());
if ( empty ( $cflink [ 'rio' ]))
unset ( $cflink [ 'rio' ]);
$cflink [ 'ecn' ] = trim ( $this -> GetEcn ());
if ( empty ( $cflink [ 'ecn' ]))
unset ( $cflink [ 'ecn' ]);
2005-09-25 08:23:03 +02:00
}
}
2008-01-11 22:07:25 +01:00
class hfsc_queue extends priq_queue {
2009-11-03 18:12:29 +01:00
/* realtime */
2008-01-11 22:07:25 +01:00
var $realtime ;
2009-11-03 18:12:29 +01:00
var $r_m1 ;
var $r_d ;
var $r_m2 ;
/* linkshare */
2008-01-11 22:07:25 +01:00
var $linkshare ;
2009-11-03 18:12:29 +01:00
var $l_m1 ;
var $l_d ;
var $l_m2 ;
/* upperlimit */
2008-01-11 22:07:25 +01:00
var $upperlimit ;
2009-11-03 18:12:29 +01:00
var $u_m1 ;
var $u_d ;
var $u_m2 ;
2008-01-11 22:07:25 +01:00
2009-11-03 18:12:29 +01:00
/*
* HFSC can have nested queues .
*/
2009-08-28 01:29:47 +02:00
function CanHaveChildren () {
2009-11-03 18:12:29 +01:00
return true ;
}
2008-01-11 22:07:25 +01:00
function GetRealtime () {
2014-02-24 13:10:11 +01:00
return $this -> realtime ;
2009-11-03 18:12:29 +01:00
}
function GetR_m1 () {
return $this -> r_m1 ;
}
function GetR_d () {
return $this -> r_d ;
}
function GetR_m2 () {
return $this -> r_m2 ;
}
function SetRealtime () {
$this -> realtime = " on " ;
}
function DisableRealtime () {
$this -> realtime = " " ;
}
function SetR_m1 ( $value ) {
$this -> r_m1 = $value ;
}
function SetR_d ( $value ) {
$this -> r_d = $value ;
}
function SetR_m2 ( $value ) {
$this -> r_m2 = $value ;
}
function GetLinkshare () {
return $this -> linkshare ;
}
function DisableLinkshare () {
$this -> linkshare = " " ;
}
function GetL_m1 () {
return $this -> l_m1 ;
}
function GetL_d () {
return $this -> l_d ;
}
function GetL_m2 () {
return $this -> l_m2 ;
}
function SetLinkshare () {
$this -> linkshare = " on " ;
}
function SetL_m1 ( $value ) {
$this -> l_m1 = $value ;
}
function SetL_d ( $value ) {
$this -> l_d = $value ;
}
function SetL_m2 ( $value ) {
$this -> l_m2 = $value ;
}
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 ;
}
function SetUpperlimit () {
$this -> upperlimit = " on " ;
}
function DisableUpperlimit () {
$this -> upperlimit = " " ;
}
function SetU_m1 ( $value ) {
$this -> u_m1 = $value ;
}
function SetU_d ( $value ) {
$this -> u_d = $value ;
}
function SetU_m2 ( $value ) {
$this -> u_m2 = $value ;
}
function & add_queue ( $interface , & $qname , & $path , & $input_errors ) {
if ( ! is_array ( $this -> subqueues ))
$this -> subqueues = array ();
2010-03-09 08:30:51 +01:00
$q =& new hfsc_queue ();
2009-11-03 18:12:29 +01:00
$q -> SetInterface ( $this -> GetInterface ());
2013-09-12 16:29:21 +02:00
$q -> SetParent ( $this );
2009-11-03 18:12:29 +01:00
$q -> ReadConfig ( $qname );
$q -> validate_input ( $qname , $input_errors );
if ( count ( $input_errors )) {
2011-01-24 18:04:14 +01:00
log_error ( " SHAPER: could not create queue " . $q -> GetQname () . " on interface { $interface } because: " . print_r ( $input_errors , true ));
2008-01-16 23:52:27 +01:00
return $q ;
}
2008-01-11 22:07:25 +01:00
2009-11-03 18:12:29 +01:00
$q -> SetEnabled ( " on " );
$q -> SetLink ( $path );
switch ( $q -> GetBwscale ()) {
case " % " :
$myBw = $this -> GetAvailableBandwidth () * $qname [ 'bandwidth' ] / 100 ;
break ;
default :
$myBw = $qname [ 'bandwidth' ] * get_bandwidthtype_scale ( $q -> GetBwscale ());
break ;
}
$q -> SetAvailableBandwidth ( $myBw );
$this -> SetAvailableBandwidth ( $this -> GetAvailableBandwidth () - $myBw );
$this -> subqueues [ $q -> GetQname ()] =& $q ; //new hfsc_queue()
ref_on_altq_queue_list ( $this -> GetQname (), $q -> GetQname ());
if ( is_array ( $qname [ 'queue' ])) {
foreach ( $qname [ 'queue' ] as $key1 => $que ) {
array_push ( $path , $key1 );
2013-09-12 16:29:21 +02:00
$q -> add_queue ( $q -> GetInterface (), $que , $path , $input_errors );
2009-11-03 18:12:29 +01:00
array_pop ( $path );
}
}
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
return $q ;
}
2008-03-27 18:08:16 +01:00
2014-02-24 13:10:11 +01:00
function copy_queue ( $interface , & $cflink ) {
2008-03-27 18:08:16 +01:00
2009-11-03 18:12:29 +01:00
$cflink [ 'name' ] = $this -> GetQname ();
$cflink [ 'interface' ] = $interface ;
$cflink [ 'qlimit' ] = trim ( $this -> GetQlimit ());
if ( empty ( $cflink [ 'qlimit' ]))
unset ( $cflink [ 'qlimit' ]);
$cflink [ 'priority' ] = trim ( $this -> GetQpriority ());
if ( empty ( $cflink [ 'priority' ]))
unset ( $cflink [ 'priority' ]);
$cflink [ 'description' ] = trim ( $this -> GetDescription ());
if ( empty ( $cflink [ 'description' ]))
unset ( $cflink [ 'description' ]);
$cflink [ 'bandwidth' ] = $this -> GetBandwidth ();
$cflink [ 'bandwidthtype' ] = $this -> GetBwscale ();
$cflink [ 'enabled' ] = trim ( $this -> GetEnabled ());
if ( empty ( $cflink [ 'enabled' ]))
unset ( $cflink [ 'enabled' ]);
$cflink [ 'default' ] = trim ( $this -> GetDefault ());
if ( empty ( $cflink [ 'default' ]))
unset ( $cflink [ 'default' ]);
$cflink [ 'red' ] = trim ( $this -> GetRed ());
if ( empty ( $cflink [ 'red' ]))
unset ( $cflink [ 'red' ]);
$cflink [ 'rio' ] = trim ( $this -> GetRio ());
if ( empty ( $cflink [ 'rio' ]))
unset ( $cflink [ 'rio' ]);
$cflink [ 'ecn' ] = trim ( $this -> GetEcn ());
if ( empty ( $cflink [ 'ecn' ]))
unset ( $cflink [ 'ecn' ]);
if ( $this -> GetLinkshare () <> " " ) {
if ( $this -> GetL_m1 () <> " " ) {
$cflink [ 'linkshare1' ] = $this -> GetL_m1 ();
$cflink [ 'linkshare2' ] = $this -> GetL_d ();
$cflink [ 'linkshare' ] = " on " ;
} else {
unset ( $cflink [ 'linkshare1' ]);
unset ( $cflink [ 'linkshare2' ]);
unset ( $cflink [ 'linkshare' ]);
2008-02-21 19:22:00 +01:00
}
2009-11-03 18:12:29 +01:00
if ( $this -> GetL_m2 () <> " " ) {
$cflink [ 'linkshare3' ] = $this -> GetL_m2 ();
$cflink [ 'linkshare' ] = " on " ;
} else {
unset ( $cflink [ 'linkshare3' ]);
unset ( $cflink [ 'linkshare' ]);
2008-01-16 23:52:27 +01:00
}
2009-11-03 18:12:29 +01:00
}
if ( $this -> GetRealtime () <> " " ) {
if ( $this -> GetR_m1 () <> " " ) {
$cflink [ 'realtime1' ] = $this -> GetR_m1 ();
$cflink [ 'realtime2' ] = $this -> GetR_d ();
$cflink [ 'realtime' ] = " on " ;
} else {
unset ( $cflink [ 'realtime1' ]);
2014-02-24 13:10:11 +01:00
unset ( $cflink [ 'realtime2' ]);
unset ( $cflink [ 'realtime' ]);
2009-11-03 18:12:29 +01:00
}
if ( $this -> GetR_m2 () <> " " ) {
$cflink [ 'realtime3' ] = $this -> GetR_m2 ();
$cflink [ 'realtime' ] = " on " ;
} else {
unset ( $cflink [ 'realtime3' ]);
unset ( $cflink [ 'realtime' ]);
2008-01-16 23:52:27 +01:00
}
2005-10-17 18:11:07 +02:00
}
2009-11-03 18:12:29 +01:00
if ( $this -> GetUpperlimit () <> " " ) {
if ( $this -> GetU_m1 () <> " " ) {
$cflink [ 'upperlimit1' ] = $this -> GetU_m1 ();
$cflink [ 'upperlimit2' ] = $this -> GetU_d ();
$cflink [ 'upperlimit' ] = " on " ;
} else {
unset ( $cflink [ 'upperlimit' ]);
unset ( $cflink [ 'upperlimit1' ]);
unset ( $cflink [ 'upperlimit2' ]);
}
if ( $this -> GetU_m2 () <> " " ) {
$cflink [ 'upperlimit3' ] = $this -> GetU_m2 ();
$cflink [ 'upperlimit' ] = " on " ;
} else {
unset ( $cflink [ 'upperlimit3' ]);
unset ( $cflink [ 'upperlimit' ]);
}
2008-01-16 23:52:27 +01:00
}
2008-01-22 23:07:35 +01:00
2009-11-03 18:12:29 +01:00
if ( is_array ( $this -> subqueues )) {
$cflinkp [ 'queue' ] = array ();
foreach ( $this -> subqueues as $q ) {
$cflink [ 'queue' ][ $q -> GetQname ()] = array ();
2013-09-12 16:29:21 +02:00
$q -> copy_queue ( $interface , $cflink [ 'queue' ][ $q -> GetQname ()]);
2009-11-03 18:12:29 +01:00
}
}
}
2014-02-24 13:10:11 +01:00
function delete_queue () {
2009-11-03 18:12:29 +01:00
unref_on_altq_queue_list ( $this -> GetQname ());
cleanup_queue_from_rules ( $this -> GetQname ());
$parent =& $this -> GetParent ();
foreach ( $this -> subqueues as $q ) {
$this -> SetAvailableBandwidth ( $this -> GetAvailableBandwidth () + $q -> GetAvailableBandwidth ());
$q -> delete_queue ();
}
unset_object_by_reference ( $this -> GetLink ());
}
/*
* Should search even its children
*/
function & find_queue ( $interface , $qname ) {
2014-02-24 13:10:11 +01:00
if ( $qname == $this -> GetQname ())
2009-11-03 18:12:29 +01:00
return $this ;
foreach ( $this -> subqueues as $q ) {
$result =& $q -> find_queue ( " " , $qname );
if ( $result )
return $result ;
}
}
function & find_parentqueue ( $interface , $qname ) {
2014-02-24 13:10:11 +01:00
if ( $this -> subqueues [ $qname ])
2009-11-03 18:12:29 +01:00
return $this ;
foreach ( $this -> subqueues as $q ) {
$result = $q -> find_parentqueue ( " " , $qname );
if ( $result )
return $result ;
}
}
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
function validate_input ( $data , & $input_errors ) {
parent :: validate_input ( $data , $input_errors );
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
$reqdfields [] = " bandwidth " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Bandwidth " );
2009-11-03 18:12:29 +01:00
$reqdfields [] = " bandwidthtype " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Bandwidthtype " );
2009-11-03 18:12:29 +01:00
shaper_do_input_validation ( $data , $reqdfields , $reqdfieldsn , $input_errors );
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
if ( isset ( $data [ 'linkshare3' ]) && $data [ 'linkshare3' ] <> " " ) {
if ( $data [ 'bandwidth' ] && ( ! is_numeric ( $data [ 'bandwidth' ])))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Bandwidth must be an integer. " );
2009-11-03 18:12:29 +01:00
2010-08-18 15:36:29 +02:00
if ( $data [ 'bandwidth' ] < 0 )
$input_errors [] = gettext ( " Bandwidth cannot be negative. " );
2009-11-03 18:12:29 +01:00
if ( $data [ 'bandwidthtype' ] == " % " ) {
if ( $data [ 'bandwidth' ] > 100 || $data [ 'bandwidth' ] < 0 )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Bandwidth in percentage should be between 1 and 100 bounds. " );
2009-11-03 18:12:29 +01:00
}
/*
$parent =& $this -> GetParent ();
switch ( $data [ 'bandwidthtype' ]) {
case " % " :
$myBw = $parent -> GetAvailableBandwidth () * floatval ( $data [ 'bandwidth' ]) / 100 ;
default :
$mybw = floatval ( $data [ 'bandwidth' ]) * get_bandwidthtype_scale ( $data [ 'bandwidthtype' ]);
break ;
}
if ( $parent -> GetAvailableBandwidth () < $myBw )
$input_errors [] = " The sum of children bandwidth exceeds that of the parent. " ;
*/
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
if ( $data [ 'upperlimit1' ] <> " " && $data [ 'upperlimit2' ] == " " )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " upperlimit service curve defined but missing (d) value " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'upperlimit2' ] <> " " && $data [ 'upperlimit1' ] == " " )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " upperlimit service curve defined but missing initial bandwidth (m1) value " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'upperlimit1' ] <> " " && ! is_valid_shaperbw ( $data [ 'upperlimit1' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " upperlimit m1 value needs to be Kb, Mb, Gb, or % " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'upperlimit2' ] <> " " && ! is_numeric ( $data [ 'upperlimit2' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " upperlimit d value needs to be numeric " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'upperlimit3' ] <> " " && ! is_valid_shaperbw ( $data [ 'upperlimit3' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " upperlimit m2 value needs to be Kb, Mb, Gb, or % " );
2008-03-27 18:08:16 +01:00
2009-11-03 18:12:29 +01:00
/*
2008-01-22 23:07:35 +01:00
if ( isset ( $data [ 'upperlimit' ]) && $data [ 'upperlimit3' ] <> " " && $data [ 'upperlimit1' ] <> " " ) {
2009-11-03 18:12:29 +01:00
$bw_1 = get_hfsc_bandwidth ( $this , $data [ 'upperlimit1' ]);
$bw_2 = get_hfsc_bandwidth ( $this , $data [ 'upperlimit3' ]);
2014-02-24 13:10:11 +01:00
if ( floatval ( $bw_1 ) < floatval ( $bw_2 ))
2009-11-03 18:12:29 +01:00
$input_errors [] = ( " upperlimit m1 cannot be smaller than m2 " );
2008-01-22 23:07:35 +01:00
2009-11-03 18:12:29 +01:00
if ( get_interface_bandwidth ( $this ) < ( 0.8 * ( floatval ( $bw_1 ) + floatval ( $bw_2 ))))
2013-09-03 13:45:03 +02:00
$input_errors [] = ( " upperlimit specification exceeds 80% of allowable allocation. " );
2008-01-22 23:07:35 +01:00
}
2009-11-03 18:12:29 +01:00
*/
2008-01-22 23:07:35 +01:00
if ( $data [ 'linkshare1' ] <> " " && $data [ 'linkshare2' ] == " " )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " linkshare service curve defined but missing (d) value " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'linkshare2' ] <> " " && $data [ 'linkshare1' ] == " " )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " linkshare service curve defined but missing initial bandwidth (m1) value " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'linkshare1' ] <> " " && ! is_valid_shaperbw ( $data [ 'linkshare1' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " linkshare m1 value needs to be Kb, Mb, Gb, or % " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'linkshare2' ] <> " " && ! is_numeric ( $data [ 'linkshare2' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " linkshare d value needs to be numeric " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'linkshare3' ] <> " " && ! is_valid_shaperbw ( $data [ 'linkshare3' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " linkshare m2 value needs to be Kb, Mb, Gb, or % " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'realtime1' ] <> " " && $data [ 'realtime2' ] == " " )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " realtime service curve defined but missing (d) value " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'realtime2' ] <> " " && $data [ 'realtime1' ] == " " )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " realtime service curve defined but missing initial bandwidth (m1) value " );
2008-01-22 23:07:35 +01:00
2009-11-03 18:12:29 +01:00
/*
2008-03-27 18:08:16 +01:00
if ( isset ( $data [ 'linkshare' ]) && $data [ 'linkshare3' ] <> " " && $data [ 'linkshare1' ] <> " " && 0 ) {
2009-11-03 18:12:29 +01:00
$bw_1 = get_hfsc_bandwidth ( $this , $data [ 'linkshare1' ]);
2014-02-24 13:10:11 +01:00
$bw_2 = get_hfsc_bandwidth ( $this , $data [ 'linkshare3' ]);
if ( floatval ( $bw_1 ) < floatval ( $bw_2 ))
$input_errors [] = ( " linkshare m1 cannot be smaller than m2 " );
2008-01-22 23:07:35 +01:00
2009-11-03 18:12:29 +01:00
if ( get_interface_bandwidth ( $this ) < ( 0.8 * ( floatval ( $bw_1 ) + floatval ( $bw_2 ))))
2014-02-24 13:10:11 +01:00
$input_errors [] = ( " linkshare specification exceeds 80% of allowable allocation. " );
2008-01-22 23:07:35 +01:00
}
2009-11-03 18:12:29 +01:00
*/
2008-03-20 22:41:29 +01:00
2008-01-22 23:07:35 +01:00
if ( $data [ 'realtime1' ] <> " " && ! is_valid_shaperbw ( $data [ 'realtime1' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " realtime m1 value needs to be Kb, Mb, Gb, or % " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'realtime2' ] <> " " && ! is_numeric ( $data [ 'realtime2' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " realtime d value needs to be numeric " );
2008-01-22 23:07:35 +01:00
if ( $data [ 'realtime3' ] <> " " && ! is_valid_shaperbw ( $data [ 'realtime3' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " realtime m2 value needs to be Kb, Mb, Gb, or % " );
2008-01-22 23:07:35 +01:00
2009-11-03 18:12:29 +01:00
/*
2008-03-27 18:08:16 +01:00
if ( isset ( $data [ 'realtime' ]) && $data [ 'realtime3' ] <> " " && $data [ 'realtime1' ] <> " " && 0 ) {
2009-11-03 18:12:29 +01:00
$bw_1 = get_hfsc_bandwidth ( $this , $data [ 'realtime1' ]);
2014-02-24 13:10:11 +01:00
$bw_2 = get_hfsc_bandwidth ( $this , $data [ 'realtime3' ]);
if ( floatval ( $bw_1 ) < floatval ( $bw_2 ))
$input_errors [] = ( " realtime m1 cannot be smaller than m2 " );
2008-01-22 23:07:35 +01:00
2009-11-03 18:12:29 +01:00
if ( get_interface_bandwidth ( $this ) < ( 0.8 * ( floatval ( $bw_1 ) + floatval ( $bw_2 ))))
2013-09-03 13:45:03 +02:00
$input_errors [] = ( " realtime specification exceeds 80% of allowable allocation. " );
2008-01-22 23:07:35 +01:00
}
2009-11-03 18:12:29 +01:00
*/
2005-09-25 08:23:03 +02:00
}
2009-11-03 18:12:29 +01:00
function ReadConfig ( & $cflink ) {
if ( ! empty ( $cflink [ 'linkshare' ])) {
if ( ! empty ( $cflink [ 'linkshare1' ])) {
2008-01-16 23:52:27 +01:00
$this -> SetL_m1 ( $cflink [ 'linkshare1' ]);
2014-02-24 13:10:11 +01:00
$this -> SetL_d ( $cflink [ 'linkshare2' ]);
2008-01-16 23:52:27 +01:00
$this -> SetLinkshare ();
2010-08-03 20:12:40 +02:00
} else {
$this -> SetL_m1 ( " " );
2014-02-24 13:10:11 +01:00
$this -> SetL_d ( " " );
2010-08-03 20:12:40 +02:00
$this -> DisableLinkshare ();
2008-01-16 23:52:27 +01:00
}
2009-11-03 18:12:29 +01:00
if ( ! empty ( $cflink [ 'linkshare3' ])) {
2014-02-24 13:10:11 +01:00
$this -> SetL_m2 ( $cflink [ 'linkshare3' ]);
2008-01-16 23:52:27 +01:00
$this -> SetLinkshare ();
}
2009-11-03 18:12:29 +01:00
} else
$this -> DisableLinkshare ();
if ( ! empty ( $cflink [ 'realtime' ])) {
2014-02-24 13:10:11 +01:00
if ( ! empty ( $cflink [ 'realtime1' ])) {
$this -> SetR_m1 ( $cflink [ 'realtime1' ]);
$this -> SetR_d ( $cflink [ 'realtime2' ]);
2008-01-16 23:52:27 +01:00
$this -> SetRealtime ();
2010-08-03 20:12:40 +02:00
} else {
2014-02-24 13:10:11 +01:00
$this -> SetR_m1 ( " " );
$this -> SetR_d ( " " );
2010-08-03 20:12:40 +02:00
$this -> DisableRealtime ();
2008-01-16 23:52:27 +01:00
}
2014-02-24 13:10:11 +01:00
if ( ! empty ( $cflink [ 'realtime3' ])) {
$this -> SetR_m2 ( $cflink [ 'realtime3' ]);
2008-01-16 23:52:27 +01:00
$this -> SetRealtime ();
}
2009-11-03 18:12:29 +01:00
} else
2014-02-24 13:10:11 +01:00
$this -> DisableRealtime ();
2009-11-03 18:12:29 +01:00
if ( ! empty ( $cflink [ 'upperlimit' ])) {
2014-02-24 13:10:11 +01:00
if ( ! empty ( $cflink [ 'upperlimit1' ])) {
$this -> SetU_m1 ( $cflink [ 'upperlimit1' ]);
$this -> SetU_d ( $cflink [ 'upperlimit2' ]);
2008-01-16 23:52:27 +01:00
$this -> SetUpperlimit ();
2010-08-03 20:12:40 +02:00
} else {
2014-02-24 13:10:11 +01:00
$this -> SetU_m1 ( " " );
$this -> SetU_d ( " " );
2010-08-03 20:12:40 +02:00
$this -> DisableUpperlimit ();
2008-01-16 23:52:27 +01:00
}
2014-02-24 13:10:11 +01:00
if ( ! empty ( $cflink [ 'upperlimit3' ])) {
$this -> SetU_m2 ( $cflink [ 'upperlimit3' ]);
2008-01-16 23:52:27 +01:00
$this -> SetUpperlimit ();
}
2009-11-03 18:12:29 +01:00
} else
$this -> DisableUpperlimit ();
2008-01-16 23:52:27 +01:00
parent :: ReadConfig ( $cflink );
2009-11-03 18:12:29 +01:00
}
2008-01-11 22:07:25 +01:00
function build_tree () {
2014-02-24 13:10:11 +01:00
$tree = " <li><a href= \" firewall_shaper.php?interface= " . $this -> GetInterface () . " &queue= " . $this -> GetQname () . " &action=show " ;
2008-01-11 22:07:25 +01:00
$tree .= " \" " ;
2009-11-03 18:12:29 +01:00
$tmpvalue = $this -> GetDefault ();
if ( ! empty ( $tmpvalue ))
$tree .= " class= \" navlnk \" " ;
2008-01-11 22:07:25 +01:00
$tree .= " > " . $this -> GetQname () . " </a> " ;
if ( is_array ( $this -> subqueues )) {
$tree .= " <ul> " ;
foreach ( $this -> subqueues as $q ) {
$tree .= $q -> build_tree ();
2014-02-24 13:10:11 +01:00
}
2008-01-11 22:07:25 +01:00
$tree .= " </ul> " ;
}
$tree .= " </li> " ;
return $tree ;
2005-09-25 08:23:03 +02:00
}
2009-11-03 18:12:29 +01:00
/* Even this should take children into consideration */
2011-01-28 15:39:48 +01:00
function build_rules ( & $default = false ) {
2008-01-11 22:07:25 +01:00
2009-11-03 18:12:29 +01:00
$pfq_rule = " queue " . $this -> qname ;
if ( $this -> GetInterface ())
$pfq_rule .= " on " . get_real_interface ( $this -> GetInterface ());
2008-01-11 22:07:25 +01:00
if ( $this -> GetBandwidth () && $this -> GetBwscale ())
2009-11-03 18:12:29 +01:00
$pfq_rule .= " bandwidth " . trim ( $this -> GetBandwidth ()) . $this -> GetBwscale ();
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
$tmpvalue = $this -> GetQlimit ();
if ( ! empty ( $tmpvalue ))
$pfq_rule .= " qlimit " . $this -> GetQlimit ();
2013-05-06 20:09:24 +02:00
if ( $this -> GetDefault () || $this -> GetRed () || $this -> GetRio () || $this -> GetEcn () || $this -> GetCodel () || $this -> GetRealtime () <> " " || $this -> GetLinkshare () <> " " || $this -> GetUpperlimit () <> " " ) {
2009-11-03 18:12:29 +01:00
$pfq_rule .= " hfsc ( " ;
$tmpvalue = $this -> GetRed ();
if ( ! empty ( $tmpvalue )) {
$comma = 1 ;
$pfq_rule .= " red " ;
}
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
$tmpvalue = $this -> GetRio ();
if ( ! empty ( $tmpvalue )) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2009-11-03 18:12:29 +01:00
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " rio " ;
}
$tmpvalue = $this -> GetEcn ();
if ( ! empty ( $tmpvalue )) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2009-11-03 18:12:29 +01:00
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " ecn " ;
}
2013-05-06 20:09:24 +02:00
$tmpvalue = $this -> GetCodel ();
if ( ! empty ( $tmpvalue )) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2013-05-06 20:09:24 +02:00
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " codel " ;
}
2009-11-03 18:12:29 +01:00
$tmpvalue = $this -> GetDefault ();
if ( ! empty ( $tmpvalue )) {
if ( $comma )
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " default " ;
2011-01-24 18:18:46 +01:00
$default = true ;
2009-11-03 18:12:29 +01:00
}
if ( $this -> GetRealtime () <> " " ) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2009-11-03 18:12:29 +01:00
$pfq_rule .= " , " ;
2008-01-16 23:52:27 +01:00
if ( $this -> GetR_m1 () <> " " && $this -> GetR_d () <> " " && $this -> GetR_m2 () <> " " )
2009-11-03 18:12:29 +01:00
$pfq_rule .= " realtime ( " . $this -> GetR_m1 () . " , " . $this -> GetR_d () . " , " . $this -> GetR_m2 () . " ) " ;
2008-01-16 23:52:27 +01:00
else if ( $this -> GetR_m2 () <> " " )
$pfq_rule .= " realtime " . $this -> GetR_m2 ();
2008-01-11 22:07:25 +01:00
$comma = 1 ;
}
2009-11-03 18:12:29 +01:00
if ( $this -> GetLinkshare () <> " " ) {
if ( $comma )
2008-01-11 22:07:25 +01:00
$pfq_rule .= " , " ;
2008-01-16 23:52:27 +01:00
if ( $this -> GetL_m1 () <> " " && $this -> GetL_d () <> " " && $this -> GetL_m2 () <> " " )
2009-11-03 18:12:29 +01:00
$pfq_rule .= " linkshare ( " . $this -> GetL_m1 () . " , " . $this -> GetL_d () . " , " . $this -> GetL_m2 () . " ) " ;
2008-01-16 23:52:27 +01:00
else if ( $this -> GetL_m2 () <> " " )
$pfq_rule .= " linkshare " . $this -> GetL_m2 () . " " ;
2008-01-11 22:07:25 +01:00
$comma = 1 ;
}
2009-11-03 18:12:29 +01:00
if ( $this -> GetUpperlimit () <> " " ) {
2008-01-11 22:07:25 +01:00
if ( $comma )
$pfq_rule .= " , " ;
2008-01-16 23:52:27 +01:00
if ( $this -> GetU_m1 () <> " " && $this -> GetU_d () <> " " && $this -> GetU_m2 () <> " " )
$pfq_rule .= " upperlimit ( " . $this -> GetU_m1 () . " , " . $this -> GetU_d () . " , " . $this -> GetU_m2 () . " ) " ;
else if ( $this -> GetU_m2 () <> " " )
$pfq_rule .= " upperlimit " . $this -> GetU_m2 () . " " ;
2008-01-11 22:07:25 +01:00
}
2009-11-03 18:12:29 +01:00
$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 )
2013-09-12 16:29:21 +02:00
$pfq_rule .= $q -> build_rules ( $default );
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
2014-02-24 13:10:11 +01:00
$pfq_rule .= " \n " ;
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
return $pfq_rule ;
}
2008-01-11 22:07:25 +01:00
function build_javascript () {
$javascript = parent :: build_javascript ();
$javascript .= " <script type= \" text/javascript \" > " ;
2013-04-07 10:52:05 +02:00
$javascript .= " //<![CDATA[ \n " ;
2008-01-11 22:07:25 +01:00
$javascript .= " function enable_realtime(enable_over) { \n " ;
2008-01-16 23:52:27 +01:00
$javascript .= " if (document.iform.realtime.checked || enable_over) { \n " ;
$javascript .= " document.iform.realtime1.disabled = 0; \n " ;
$javascript .= " document.iform.realtime2.disabled = 0; \n " ;
$javascript .= " document.iform.realtime3.disabled = 0; \n " ;
$javascript .= " } else { \n " ;
$javascript .= " document.iform.realtime1.disabled = 1; \n " ;
$javascript .= " document.iform.realtime2.disabled = 1; \n " ;
$javascript .= " document.iform.realtime3.disabled = 1; \n " ;
$javascript .= " } \n " ;
2008-01-11 22:07:25 +01:00
$javascript .= " } \n " ;
$javascript .= " function enable_linkshare(enable_over) { \n " ;
2008-01-16 23:52:27 +01:00
$javascript .= " if (document.iform.linkshare.checked || enable_over) { \n " ;
$javascript .= " document.iform.linkshare1.disabled = 0; \n " ;
$javascript .= " document.iform.linkshare2.disabled = 0; \n " ;
$javascript .= " document.iform.linkshare3.disabled = 0; \n " ;
$javascript .= " } else { \n " ;
$javascript .= " document.iform.linkshare1.disabled = 1; \n " ;
$javascript .= " document.iform.linkshare2.disabled = 1; \n " ;
$javascript .= " document.iform.linkshare3.disabled = 1; \n " ;
$javascript .= " } \n " ;
2008-01-11 22:07:25 +01:00
$javascript .= " } \n " ;
$javascript .= " function enable_upperlimit(enable_over) { \n " ;
2008-01-16 23:52:27 +01:00
$javascript .= " if (document.iform.upperlimit.checked || enable_over) { \n " ;
$javascript .= " document.iform.upperlimit1.disabled = 0; \n " ;
$javascript .= " document.iform.upperlimit2.disabled = 0; \n " ;
$javascript .= " document.iform.upperlimit3.disabled = 0; \n " ;
$javascript .= " } else { \n " ;
$javascript .= " document.iform.upperlimit1.disabled = 1; \n " ;
$javascript .= " document.iform.upperlimit2.disabled = 1; \n " ;
$javascript .= " document.iform.upperlimit3.disabled = 1; \n " ;
$javascript .= " } \n " ;
2013-03-29 20:25:14 +01:00
2008-01-16 23:52:27 +01:00
$javascript .= " } \n " ;
2013-03-22 16:47:53 +01:00
$javascript .= " //]]> " ;
2008-01-11 22:07:25 +01:00
$javascript .= " </script> " ;
2008-01-16 23:52:27 +01:00
2008-01-11 22:07:25 +01:00
return $javascript ;
}
2005-09-25 08:23:03 +02:00
2009-11-03 18:12:29 +01:00
function build_form () {
2010-07-20 22:28:19 +02:00
$form = parent :: build_form ();
$form .= " <tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Bandwidth " ) . " </td> " ;
2009-11-03 18:12:29 +01:00
$form .= " <td class= \" vtable \" > <input name= \" bandwidth \" id= \" bandwidth \" class= \" formfld unknown \" value= \" " ;
$form .= htmlspecialchars ( $this -> GetBandwidth ());
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2009-11-03 18:12:29 +01:00
$form .= " <select name= \" bandwidthtype \" id= \" bandwidthtype \" class= \" formselect \" > " ;
$form .= " <option value= \" Gb \" " ;
if ( $this -> GetBwscale () == " Gb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Gbit/s " ) . " </option> " ;
2009-11-03 18:12:29 +01:00
$form .= " <option value= \" Mb \" " ;
if ( $this -> GetBwscale () == " Mb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Mbit/s " ) . " </option> " ;
2009-11-03 18:12:29 +01:00
$form .= " <option value= \" Kb \" " ;
if ( $this -> GetBwscale () == " Kb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Kbit/s " ) . " </option> " ;
2012-03-22 16:20:41 +01:00
$form .= " <option value= \" b \" " ;
2009-11-03 18:12:29 +01:00
if ( $this -> GetBwscale () == " b " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Bit/s " ) . " </option> " ;
2009-11-03 18:12:29 +01:00
$form .= " <option value= \" % \" " ;
if ( $this -> GetBwscale () == " % " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2009-11-03 18:12:29 +01:00
$form .= " >%</option> " ;
2014-03-14 21:24:03 +01:00
$form .= " </select> <br /> " ;
2010-08-18 15:36:29 +02:00
$form .= " <span class= \" vexpl \" > " . gettext ( " Choose the amount of bandwidth for this queue " );
2010-07-20 22:28:19 +02:00
$form .= " </span></td></tr> " ;
2009-11-03 18:12:29 +01:00
$form .= " <tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <td width= \" 22% \" valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Service Curve (sc) " ) . " </td> " ;
2009-11-03 18:12:29 +01:00
$form .= " <td width= \" 78% \" class= \" vtable \" > " ;
$form .= " <table> " ;
$form .= " <tr><td> </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 \" " ;
2014-02-24 13:10:11 +01:00
if ( $this -> GetUpperlimit () <> " " )
2013-03-29 20:25:14 +01:00
$form .= " checked= \" checked \" " ;
2013-03-25 22:46:22 +01:00
$form .= " onchange= \" enable_upperlimit() \" /> " . gettext ( " Upperlimit: " ) . " </td><td><input size= \" 6 \" value= \" " ;
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetU_m1 ());
$form .= " \" id= \" upperlimit1 \" name= \" upperlimit1 \" " ;
if ( $this -> GetUpperlimit () == " " )
2013-03-29 20:25:14 +01:00
$form .= " disabled= \" disabled \" " ;
2013-03-25 22:46:22 +01:00
$form .= " /></td><td><input size= \" 6 \" value= \" " ;
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetU_d ());
$form .= " \" id= \" upperlimi2 \" name= \" upperlimit2 \" " ;
if ( $this -> GetUpperlimit () == " " )
2013-03-29 20:25:14 +01:00
$form .= " disabled= \" disabled \" " ;
2013-03-25 22:46:22 +01:00
$form .= " /></td><td><input size= \" 6 \" value= \" " ;
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetU_m2 ());
$form .= " \" id= \" upperlimit3 \" name= \" upperlimit3 \" " ;
if ( $this -> GetUpperlimit () == " " )
2013-03-29 20:25:14 +01:00
$form .= " disabled= \" disabled \" " ;
2013-03-25 22:46:22 +01:00
$form .= " /></td><td> " . gettext ( " The maximum allowed bandwidth for the queue. " ) . " </td></tr> " ;
2009-11-03 18:12:29 +01:00
$form .= " <tr><td><input type= \" checkbox \" id= \" realtime \" name= \" realtime \" " ;
2014-02-24 13:10:11 +01:00
if ( $this -> GetRealtime () <> " " )
2013-03-29 20:25:14 +01:00
$form .= " checked= \" checked \" " ;
2013-03-25 22:46:22 +01:00
$form .= " onchange= \" enable_realtime() \" /> " . gettext ( " Real time: " ) . " </td><td><input size= \" 6 \" value= \" " ;
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetR_m1 ());
$form .= " \" id= \" realtime1 \" name= \" realtime1 \" " ;
if ( $this -> GetRealtime () == " " )
2013-03-29 20:25:14 +01:00
$form .= " disabled= \" disabled \" " ;
2013-03-25 22:46:22 +01:00
$form .= " /></td><td><input size= \" 6 \" value= \" " ;
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetR_d ());
$form .= " \" id= \" realtime2 \" name= \" realtime2 \" " ;
if ( $this -> GetRealtime () == " " )
2013-03-29 20:25:14 +01:00
$form .= " disabled= \" disabled \" " ;
2013-03-25 22:46:22 +01:00
$form .= " /></td><td><input size= \" 6 \" value= \" " ;
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetR_m2 ());
$form .= " \" id= \" realtime3 \" name= \" realtime3 \" " ;
if ( $this -> GetRealtime () == " " )
2013-03-29 20:25:14 +01:00
$form .= " disabled= \" disabled \" " ;
2013-03-25 22:46:22 +01:00
$form .= " /></td><td> " . gettext ( " The minimum required bandwidth for the queue. " ) . " </td></tr> " ;
2013-04-03 18:08:59 +02:00
$form .= " <tr><td><input type= \" checkbox \" id= \" linkshare \" name= \" linkshare \" " ;
2014-02-24 13:10:11 +01:00
if ( $this -> GetLinkshare () <> " " )
2013-03-29 20:25:14 +01:00
$form .= " checked= \" checked \" " ;
2013-03-25 22:46:22 +01:00
$form .= " onchange= \" enable_linkshare() \" /> " . gettext ( " Link share: " ) . " </td><td><input size= \" 6 \" value= \" " ;
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetL_m1 ());
$form .= " \" id= \" linkshare1 \" name= \" linkshare1 \" " ;
if ( $this -> GetLinkshare () == " " )
2013-03-29 20:25:14 +01:00
$form .= " disabled= \" disabled \" " ;
2013-03-25 22:46:22 +01:00
$form .= " /></td><td><input size= \" 6 \" value= \" " ;
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetL_d ());
$form .= " \" id= \" linkshare2 \" name= \" linkshare2 \" " ;
if ( $this -> GetLinkshare () == " " )
2013-03-29 20:25:14 +01:00
$form .= " disabled= \" disabled \" " ;
2013-03-25 22:46:22 +01:00
$form .= " /></td><td><input size= \" 6 \" value= \" " ;
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetL_m2 ());
$form .= " \" id= \" linkshare3 \" name= \" linkshare3 \" " ;
if ( $this -> GetLinkshare () == " " )
2013-03-29 20:25:14 +01:00
$form .= " disabled= \" disabled \" " ;
2013-03-25 22:46:22 +01:00
$form .= " /></td><td> " . gettext ( " The bandwidth share of a backlogged queue - this overrides priority. " ) . " </td></tr> " ;
2014-03-14 21:24:03 +01:00
$form .= " </table><br /> " ;
2010-08-18 15:36:29 +02:00
$form .= gettext ( " The format for service curve specifications is (m1, d, m2). m2 controls "
. " the bandwidth assigned to the queue. m1 and d are optional and can be "
. " used to control the initial bandwidth assignment. For the first d milliseconds the queue gets the bandwidth given as m1, afterwards the value "
. " given in m2. " );
2013-04-03 18:08:59 +02:00
$form .= " </td> " ;
2009-11-03 18:12:29 +01:00
$form .= " </tr> " ;
return $form ;
}
2008-01-11 22:07:25 +01:00
2014-02-24 13:10:11 +01:00
function update_altq_queue_data ( & $data ) {
2008-01-11 22:07:25 +01:00
$this -> ReadConfig ( $data );
2005-09-25 08:23:03 +02:00
}
2008-01-16 23:52:27 +01:00
function wconfig () {
2008-01-11 22:07:25 +01:00
$cflink =& get_reference_to_me_in_config ( $this -> GetLink ());
2008-01-16 23:52:27 +01:00
if ( ! is_array ( $cflink ))
$cflink = array ();
2009-11-03 18:12:29 +01:00
$cflink [ 'name' ] = $this -> GetQname ();
$cflink [ 'interface' ] = $this -> GetInterface ();
$cflink [ 'qlimit' ] = trim ( $this -> GetQlimit ());
if ( empty ( $cflink [ 'qlimit' ]))
unset ( $cflink [ 'qlimit' ]);
$cflink [ 'priority' ] = $this -> GetQpriority ();
if ( empty ( $cflink [ 'priority' ]))
unset ( $cflink [ 'priority' ]);
$cflink [ 'description' ] = $this -> GetDescription ();
if ( empty ( $cflink [ 'description' ]))
unset ( $cflink [ 'description' ]);
$cflink [ 'bandwidth' ] = $this -> GetBandwidth ();
$cflink [ 'bandwidthtype' ] = $this -> GetBwscale ();
$cflink [ 'enabled' ] = $this -> GetEnabled ();
if ( empty ( $cflink [ 'enabled' ]))
unset ( $cflink [ 'enabled' ]);
$cflink [ 'default' ] = $this -> GetDefault ();
if ( empty ( $cflink [ 'default' ]))
unset ( $cflink [ 'default' ]);
$cflink [ 'red' ] = trim ( $this -> GetRed ());
if ( empty ( $cflink [ 'red' ]))
unset ( $cflink [ 'red' ]);
$cflink [ 'rio' ] = $this -> GetRio ();
if ( empty ( $cflink [ 'rio' ]))
unset ( $cflink [ 'rio' ]);
$cflink [ 'ecn' ] = trim ( $this -> GetEcn ());
if ( empty ( $cflink [ 'ecn' ]))
unset ( $cflink [ 'ecn' ]);
2013-09-28 14:12:35 +02:00
$cflink [ 'codel' ] = trim ( $this -> GetCodel ());
if ( empty ( $cflink [ 'codel' ]))
unset ( $cflink [ 'codel' ]);
2009-11-03 18:12:29 +01:00
if ( $this -> GetLinkshare () <> " " ) {
if ( $this -> GetL_m1 () <> " " ) {
$cflink [ 'linkshare1' ] = $this -> GetL_m1 ();
$cflink [ 'linkshare2' ] = $this -> GetL_d ();
$cflink [ 'linkshare' ] = " on " ;
} else {
unset ( $cflink [ 'linkshare' ]);
unset ( $cflink [ 'linkshare1' ]);
unset ( $cflink [ 'linkshare2' ]);
}
if ( $this -> GetL_m2 () <> " " ) {
$cflink [ 'linkshare3' ] = $this -> GetL_m2 ();
$cflink [ 'linkshare' ] = " on " ;
} else {
unset ( $cflink [ 'linkshare' ]);
unset ( $cflink [ 'linkshare3' ]);
}
} else {
unset ( $cflink [ 'linkshare' ]);
unset ( $cflink [ 'linkshare1' ]);
unset ( $cflink [ 'linkshare2' ]);
unset ( $cflink [ 'linkshare3' ]);
}
if ( $this -> GetRealtime () <> " " ) {
if ( $this -> GetR_m1 () <> " " ) {
$cflink [ 'realtime1' ] = $this -> GetR_m1 ();
$cflink [ 'realtime2' ] = $this -> GetR_d ();
$cflink [ 'realtime' ] = " on " ;
} else {
unset ( $cflink [ 'realtime' ]);
unset ( $cflink [ 'realtime1' ]);
unset ( $cflink [ 'realtime2' ]);
}
if ( $this -> GetR_m2 () <> " " ) {
$cflink [ 'realtime3' ] = $this -> GetR_m2 ();
$cflink [ 'realtime' ] = " on " ;
} else {
unset ( $cflink [ 'realtime' ]);
unset ( $cflink [ 'realtime3' ]);
}
} else {
unset ( $cflink [ 'realtime' ]);
unset ( $cflink [ 'realtime1' ]);
unset ( $cflink [ 'realtime2' ]);
unset ( $cflink [ 'realtime3' ]);
}
if ( $this -> GetUpperlimit () <> " " ) {
if ( $this -> GetU_m1 () <> " " ) {
$cflink [ 'upperlimit1' ] = $this -> GetU_m1 ();
$cflink [ 'upperlimit2' ] = $this -> GetU_d ();
$cflink [ 'upperlimit' ] = " on " ;
} else {
unset ( $cflink [ 'upperlimit' ]);
unset ( $cflink [ 'upperlimit1' ]);
unset ( $cflink [ 'upperlimit2' ]);
}
if ( $this -> GetU_m2 () <> " " ) {
$cflink [ 'upperlimit3' ] = $this -> GetU_m2 ();
$cflink [ 'upperlimit' ] = " on " ;
} else {
unset ( $cflink [ 'upperlimit' ]);
unset ( $cflink [ 'upperlimit3' ]);
}
} else {
unset ( $cflink [ 'upperlimit' ]);
unset ( $cflink [ 'upperlimit1' ]);
unset ( $cflink [ 'upperlimit2' ]);
unset ( $cflink [ 'upperlimit3' ]);
2008-01-11 22:07:25 +01:00
}
}
2009-11-03 18:12:29 +01:00
}
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
class cbq_queue extends priq_queue {
2009-11-03 18:12:29 +01:00
var $qborrow = " " ;
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
function GetBorrow () {
return $this -> qborrow ;
2005-09-25 08:23:03 +02:00
}
2008-01-11 22:07:25 +01:00
function SetBorrow ( $borrow ) {
$this -> qborrow = $borrow ;
}
2009-08-28 01:29:47 +02:00
function CanHaveChildren () {
2009-11-03 18:12:29 +01:00
return true ;
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
2008-01-16 23:52:27 +01:00
function & add_queue ( $interface , & $qname , & $path , & $input_errors ) {
2008-01-11 22:07:25 +01:00
if ( ! is_array ( $this -> subqueues ))
2009-11-03 18:12:29 +01:00
$this -> subqueues = array ();
2010-03-09 08:30:51 +01:00
$q =& new cbq_queue ();
2008-01-11 22:07:25 +01:00
$q -> SetInterface ( $this -> GetInterface ());
2013-09-12 16:29:21 +02:00
$q -> SetParent ( $this );
2008-01-16 23:52:27 +01:00
$q -> ReadConfig ( $qname );
2014-02-24 13:10:11 +01:00
$q -> validate_input ( $qname , $input_errors );
if ( count ( $input_errors )) {
2011-01-24 18:04:14 +01:00
log_error ( " SHAPER: could not create queue " . $q -> GetQname () . " on interface { $interface } because: " . print_r ( $input_errors , true ));
2014-02-24 13:10:11 +01:00
return $q ;
}
switch ( $q -> GetBwscale ()) {
case " % " :
$myBw = $this -> GetAvailableBandwidth () * $qname [ 'bandwidth' ] / 100 ;
break ;
default :
$myBw = $qname [ 'bandwidth' ] * get_bandwidthtype_scale ( $q -> GetBwscale ());
break ;
}
$q -> SetAvailableBandwidth ( $myBw );
$this -> SetAvailableBandwidth ( $this -> GetAvailableBandwidth () - $myBw );
2008-01-22 23:07:35 +01:00
2008-01-11 22:07:25 +01:00
$q -> SetEnabled ( " on " );
2008-01-16 23:52:27 +01:00
$q -> SetLink ( $path );
$this -> subqueues [ $q -> GetQName ()] = & $q ;
2008-01-11 22:07:25 +01:00
ref_on_altq_queue_list ( $this -> GetQname (), $q -> GetQname ());
if ( is_array ( $qname [ 'queue' ])) {
2009-11-03 18:12:29 +01:00
foreach ( $qname [ 'queue' ] as $key1 => $que ) {
array_push ( $path , $key1 );
2013-09-12 16:29:21 +02:00
$q -> add_queue ( $q -> GetInterface (), $que , $path , $input_errors );
2009-11-03 18:12:29 +01:00
array_pop ( $path );
}
2008-01-16 23:52:27 +01:00
}
2008-01-11 22:07:25 +01:00
return $q ;
2009-11-03 18:12:29 +01:00
}
2008-03-27 18:08:16 +01:00
2009-11-03 18:12:29 +01:00
function copy_queue ( $interface , & $cflink ) {
2008-03-27 18:08:16 +01:00
2009-11-03 18:12:29 +01:00
$cflink [ 'interface' ] = $interface ;
$cflink [ 'qlimit' ] = trim ( $this -> GetQlimit ());
if ( empty ( $clink [ 'qlimit' ]))
unset ( $cflink [ 'qlimit' ]);
$cflink [ 'priority' ] = trim ( $this -> GetQpriority ());
if ( empty ( $cflink [ 'priority' ]))
unset ( $cflink [ 'priority' ]);
$cflink [ 'name' ] = $this -> GetQname ();
$cflink [ 'description' ] = trim ( $this -> GetDescription ());
if ( empty ( $cflink [ 'description' ]))
unset ( $cflink [ 'description' ]);
$cflink [ 'bandwidth' ] = $this -> GetBandwidth ();
$cflink [ 'bandwidthtype' ] = $this -> GetBwscale ();
$cflink [ 'enabled' ] = trim ( $this -> GetEnabled ());
if ( empty ( $cflink [ 'enabled' ]))
unset ( $cflink [ 'enabled' ]);
$cflink [ 'default' ] = trim ( $this -> GetDefault ());
if ( empty ( $cflink [ 'default' ]))
unset ( $cflink [ 'default' ]);
$cflink [ 'red' ] = trim ( $this -> GetRed ());
if ( empty ( $cflink [ 'red' ]))
unset ( $cflink [ 'red' ]);
$cflink [ 'rio' ] = trim ( $this -> GetRio ());
if ( empty ( $cflink [ 'rio' ]))
unset ( $cflink [ 'rio' ]);
$cflink [ 'ecn' ] = trim ( $this -> GetEcn ());
if ( empty ( $cflink [ 'ecn' ]))
unset ( $cflink [ 'ecn' ]);
$cflink [ 'borrow' ] = trim ( $this -> GetBorrow ());
if ( empty ( $cflink [ 'borrow' ]))
unset ( $cflink [ 'borrow' ]);
if ( is_array ( $this -> queues )) {
$cflinkp [ 'queue' ] = array ();
foreach ( $this -> subqueues as $q ) {
$cflink [ 'queue' ][ $q -> GetQname ()] = array ();
2013-09-12 16:29:21 +02:00
$q -> copy_queue ( $interface , $cflink [ 'queue' ][ $q -> GetQname ()]);
2009-11-03 18:12:29 +01:00
}
2008-03-27 18:08:16 +01:00
}
2009-11-03 18:12:29 +01:00
}
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
/*
* Should search even its children
*/
function & find_queue ( $interface , $qname ) {
if ( $qname == $this -> GetQname ())
return $this ;
foreach ( $this -> subqueues as $q ) {
$result =& $q -> find_queue ( " " , $qname );
2008-01-11 22:07:25 +01:00
if ( $result )
2009-11-03 18:12:29 +01:00
return $result ;
2008-01-16 23:52:27 +01:00
}
2009-11-03 18:12:29 +01:00
}
2008-01-11 22:07:25 +01:00
function & find_parentqueue ( $interface , $qname ) {
2009-11-03 18:12:29 +01:00
if ( $this -> subqueues [ $qname ])
return $this ;
foreach ( $this -> subqueues as $q ) {
$result = $q -> find_parentqueue ( " " , $qname );
2008-01-11 22:07:25 +01:00
if ( $result )
return $result ;
}
2009-11-03 18:12:29 +01:00
}
2008-01-11 22:07:25 +01:00
2009-11-03 18:12:29 +01:00
function delete_queue () {
unref_on_altq_queue_list ( $this -> GetQname ());
cleanup_queue_from_rules ( $this -> GetQname ());
foreach ( $this -> subqueues as $q ) {
$this -> SetAvailableBandwidth ( $this -> GetAvailableBandwidth () + $q -> GetAvailableBandwidth ());
$q -> delete_queue ();
2008-01-16 23:52:27 +01:00
}
2009-11-03 18:12:29 +01:00
unset_object_by_reference ( $this -> GetLink ());
}
2013-03-29 20:25:14 +01:00
2008-01-11 22:07:25 +01:00
function validate_input ( $data , & $input_errors ) {
parent :: validate_input ( $data , $input_errors );
2013-03-29 20:25:14 +01:00
2008-01-11 22:07:25 +01:00
if ( $data [ 'priority' ] > 7 )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Priority must be an integer between 1 and 7. " );
2009-04-20 00:04:48 +02:00
$reqdfields [] = " bandwidth " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Bandwidth " );
2009-04-20 00:04:48 +02:00
$reqdfields [] = " bandwidthtype " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Bandwidthtype " );
2005-09-25 08:23:03 +02:00
2008-01-22 23:07:35 +01:00
shaper_do_input_validation ( $data , $reqdfields , $reqdfieldsn , $input_errors );
2013-03-29 20:25:14 +01:00
2008-01-22 23:07:35 +01:00
if ( $data [ 'bandwidth' ] && ! is_numeric ( $data [ 'bandwidth' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Bandwidth must be an integer. " );
2008-01-16 23:52:27 +01:00
2008-01-22 23:07:35 +01:00
2009-11-03 18:12:29 +01:00
if ( $data [ 'bandwidth' ] < 0 )
2014-02-24 13:10:11 +01:00
$input_errors [] = gettext ( " Bandwidth cannot be negative. " );
2008-01-22 23:07:35 +01:00
2009-11-03 18:12:29 +01:00
if ( $data [ 'bandwidthtype' ] == " % " ) {
if ( $data [ 'bandwidth' ] > 100 || $data [ 'bandwidth' ] < 0 )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Bandwidth in percentage should be between 1 and 100 bounds. " );
2009-11-03 18:12:29 +01:00
}
2008-01-22 23:07:35 +01:00
2008-03-20 22:41:29 +01:00
/*
2011-08-11 23:39:22 +02:00
$parent =& $this -> GetParent ();
switch ( $data [ 'bandwidthtype' ]) {
case " % " :
$myBw = $parent -> GetAvailableBandwidth () * floatval ( $data [ 'bandwidth' ]) / 100 ;
break ;
default :
$mybw = floatval ( $data [ 'bandwidth' ]) * get_bandwidthtype_scale ( $data [ 'bandwidthtype' ]);
break ;
}
2014-02-24 13:10:11 +01:00
if ( $parent -> GetAvailableBandwidth () < floatval ( $myBw ))
$input_errors [] = " The sum of the children bandwidth exceeds that of the parent. " ;
*/
2008-01-16 23:52:27 +01:00
}
2009-11-03 18:12:29 +01:00
function ReadConfig ( & $q ) {
parent :: ReadConfig ( $q );
if ( ! empty ( $q [ 'borrow' ]))
2008-01-11 22:07:25 +01:00
$this -> SetBorrow ( " on " );
2010-08-03 20:12:40 +02:00
else
$this -> SetBorrow ( " " );
2009-11-03 18:12:29 +01:00
}
2013-03-29 20:25:14 +01:00
2008-01-11 22:07:25 +01:00
function build_javascript () {
return parent :: build_javascript ();
}
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
function build_tree () {
2014-02-24 13:10:11 +01:00
$tree = " <li><a href= \" firewall_shaper.php?interface= " . $this -> GetInterface () . " &queue= " . $this -> GetQname () . " &action=show " ;
2009-11-03 18:12:29 +01:00
$tree .= " \" " ;
$tmpvalue = trim ( $this -> GetDefault ());
if ( ! empty ( $tmpvalue ))
$tree .= " class= \" navlnk \" " ;
$tree .= " > " . $this -> GetQname () . " </a> " ;
if ( is_array ( $this -> subqueues )) {
$tree .= " <ul> " ;
foreach ( $this -> subqueues as $q ) {
$tree .= $q -> build_tree ();
2014-02-24 13:10:11 +01:00
}
2009-11-03 18:12:29 +01:00
$tree .= " </ul> " ;
}
$tree .= " </li> " ;
return $tree ;
2008-01-11 22:07:25 +01:00
}
2013-03-29 20:25:14 +01:00
2009-08-28 01:29:47 +02:00
/* Even this should take children into consideration */
2011-01-28 15:39:48 +01:00
function build_rules ( & $default = false ) {
2009-11-03 18:12:29 +01:00
$pfq_rule = " queue " . $this -> qname ;
if ( $this -> GetInterface ())
$pfq_rule .= " on " . get_real_interface ( $this -> GetInterface ());
if ( $this -> GetBandwidth () && $this -> GetBwscale ())
$pfq_rule .= " bandwidth " . trim ( $this -> GetBandwidth ()) . $this -> GetBwscale ();
$tmpvalue = $this -> GetQpriority ();
if ( ! empty ( $tmpvalue ))
$pfq_rule .= " priority " . $this -> GetQpriority ();
$tmpvalue = trim ( $this -> GetQlimit ());
if ( ! empty ( $tmpvalue ))
$pfq_rule .= " qlimit " . $this -> GetQlimit ();
2013-05-06 20:09:24 +02:00
if ( $this -> GetDefault () || $this -> GetRed () || $this -> GetRio () || $this -> GetEcn () || $this -> GetBorrow () || $this -> GetCodel ()) {
2009-11-03 18:12:29 +01:00
$pfq_rule .= " cbq ( " ;
$tmpvalue = trim ( $this -> GetRed ());
if ( ! empty ( $tmpvalue )) {
$comma = 1 ;
$pfq_rule .= " red " ;
}
2013-05-06 20:09:24 +02:00
$tmpvalue = trim ( $this -> GetCodel ());
if ( ! empty ( $tmpvalue )) {
$comma = 1 ;
$pfq_rule .= " codel " ;
}
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetRio ());
if ( ! empty ( $tmpvalue )) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2009-11-03 18:12:29 +01:00
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " rio " ;
}
$tmpvalue = trim ( $this -> GetEcn ());
if ( ! empty ( $tmpvalue )) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2009-11-03 18:12:29 +01:00
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " ecn " ;
}
$tmpvalue = trim ( $this -> GetDefault ());
if ( ! empty ( $tmpvalue )) {
if ( $comma )
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " default " ;
2011-01-24 18:18:46 +01:00
$default = true ;
2009-11-03 18:12:29 +01:00
}
$tmpvalue = trim ( $this -> GetBorrow ());
if ( ! empty ( $tmpvalue )) {
if ( $comma )
$pfq_rule .= " , " ;
$pfq_rule .= " borrow " ;
2008-01-16 23:52:27 +01:00
}
2009-11-03 18:12:29 +01:00
$pfq_rule .= " ) " ;
2014-02-24 13:10:11 +01:00
}
2009-11-03 18:12:29 +01:00
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 )
2011-01-28 15:39:48 +01:00
$pfq_rule .= $q -> build_rules ( $default );
2009-11-03 18:12:29 +01:00
}
2008-01-16 23:52:27 +01:00
2009-11-03 18:12:29 +01:00
$pfq_rule .= " \n " ;
return $pfq_rule ;
2008-01-16 23:52:27 +01:00
}
function build_form () {
2010-07-21 20:19:11 +02:00
$form = parent :: build_form ();
$form .= " <tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Bandwidth " ) . " </td> " ;
2008-01-16 23:52:27 +01:00
$form .= " <td class= \" vtable \" > <input name= \" bandwidth \" id= \" bandwidth \" class= \" formfld unknown \" value= \" " ;
if ( $this -> GetBandwidth () > 0 )
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetBandwidth ());
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2008-01-11 22:07:25 +01:00
$form .= " <select name= \" bandwidthtype \" id= \" bandwidthtype \" class= \" formselect \" > " ;
2008-01-16 23:52:27 +01:00
$form .= " <option value= \" Gb \" " ;
if ( $this -> GetBwscale () == " Gb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Gbit/s " ) . " </option> " ;
2008-01-16 23:52:27 +01:00
$form .= " <option value= \" Mb \" " ;
if ( $this -> GetBwscale () == " Mb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Mbit/s " ) . " </option> " ;
2008-01-16 23:52:27 +01:00
$form .= " <option value= \" Kb \" " ;
if ( $this -> GetBwscale () == " Kb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Kbit/s " ) . " </option> " ;
2012-03-22 16:20:41 +01:00
$form .= " <option value= \" b \" " ;
2008-01-16 23:52:27 +01:00
if ( $this -> GetBwscale () == " b " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Bit/s " ) . " </option> " ;
2008-01-16 23:52:27 +01:00
$form .= " <option value= \" % \" " ;
if ( $this -> GetBwscale () == " % " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2008-01-16 23:52:27 +01:00
$form .= " >%</option> " ;
2014-03-14 21:24:03 +01:00
$form .= " </select> <br /> " ;
2010-08-18 15:36:29 +02:00
$form .= " <span class= \" vexpl \" > " . gettext ( " Choose the amount of bandwidth for this queue " );
2008-01-16 23:52:27 +01:00
$form .= " </span></td></tr> " ;
2010-08-18 15:36:29 +02:00
$form .= " <tr><td class= \" vncellreq \" > " . gettext ( " Scheduler specific options " ) . " </td> " ;
2008-01-11 22:07:25 +01:00
$form .= " <td class= \" vtable \" ><input type= \" checkbox \" id= \" borrow \" name= \" borrow \" " ;
2014-02-24 13:10:11 +01:00
if ( $this -> GetBorrow () == " on " )
2013-03-29 20:25:14 +01:00
$form .= " checked= \" checked \" " ;
2014-03-14 21:24:03 +01:00
$form .= " /> " . gettext ( " Borrow from other queues when available " ) . " <br /></td></tr> " ;
2008-01-11 22:07:25 +01:00
2008-01-16 23:52:27 +01:00
return $form ;
}
2008-01-11 22:07:25 +01:00
2014-02-24 13:10:11 +01:00
function update_altq_queue_data ( & $data ) {
2008-01-11 22:07:25 +01:00
$this -> ReadConfig ( $data );
}
2005-09-25 08:23:03 +02:00
2008-01-16 23:52:27 +01:00
function wconfig () {
2008-01-11 22:07:25 +01:00
$cflink =& get_reference_to_me_in_config ( $this -> GetLink ());
2009-11-03 18:12:29 +01:00
if ( ! is_array ( $cflink ))
$cflink = array ();
$cflink [ 'interface' ] = $this -> GetInterface ();
$cflink [ 'qlimit' ] = trim ( $this -> GetQlimit ());
if ( empty ( $cflink [ 'qlimit' ]))
unset ( $cflink [ 'qlimit' ]);
$cflink [ 'priority' ] = $this -> GetQpriority ();
if ( empty ( $cflink [ 'priority' ]))
unset ( $cflink [ 'priority' ]);
$cflink [ 'name' ] = $this -> GetQname ();
$cflink [ 'description' ] = $this -> GetDescription ();
if ( empty ( $cflink [ 'description' ]))
unset ( $cflink [ 'description' ]);
$cflink [ 'bandwidth' ] = $this -> GetBandwidth ();
$cflink [ 'bandwidthtype' ] = $this -> GetBwscale ();
$cflink [ 'enabled' ] = trim ( $this -> GetEnabled ());
if ( empty ( $cflink [ 'enabled' ]))
unset ( $cflink [ 'enabled' ]);
$cflink [ 'default' ] = trim ( $this -> GetDefault ());
if ( empty ( $cflink [ 'default' ]))
unset ( $cflink [ 'default' ]);
$cflink [ 'red' ] = trim ( $this -> GetRed ());
if ( empty ( $cflink [ 'red' ]))
unset ( $cflink [ 'red' ]);
$cflink [ 'rio' ] = trim ( $this -> GetRio ());
if ( empty ( $cflink [ 'rio' ]))
unset ( $cflink [ 'rio' ]);
$cflink [ 'ecn' ] = trim ( $this -> GetEcn ());
if ( empty ( $cflink [ 'ecn' ]))
unset ( $cflink [ 'ecn' ]);
2013-09-28 14:12:35 +02:00
$cflink [ 'codel' ] = trim ( $this -> GetCodel ());
if ( empty ( $cflink [ 'codel' ]))
unset ( $cflink [ 'codel' ]);
2009-11-03 18:12:29 +01:00
$cflink [ 'borrow' ] = trim ( $this -> GetBorrow ());
if ( empty ( $cflink [ 'borrow' ]))
unset ( $cflink [ 'borrow' ]);
}
2008-01-11 22:07:25 +01:00
}
2005-09-25 08:23:03 +02:00
2008-04-22 00:47:15 +02:00
class fairq_queue extends priq_queue {
2009-11-03 18:12:29 +01:00
var $hogs ;
var $buckets ;
2008-04-22 00:47:15 +02:00
function GetBuckets () {
return $this -> buckets ;
}
function SetBuckets ( $buckets ) {
2008-04-22 22:09:56 +02:00
$this -> buckets = $buckets ;
2008-04-22 00:47:15 +02:00
}
function GetHogs () {
return $this -> hogs ;
}
function SetHogs ( $hogs ) {
2008-04-22 22:09:56 +02:00
$this -> hogs = $hogs ;
2008-04-22 00:47:15 +02:00
}
2009-08-28 01:29:47 +02:00
function CanHaveChildren () {
2008-04-22 00:47:15 +02:00
return false ;
}
function copy_queue ( $interface , & $cflink ) {
2014-02-24 13:10:11 +01:00
$cflink [ 'interface' ] = $interface ;
$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 [ 'buckets' ] = $this -> GetBuckets ();
2008-04-22 00:52:11 +02:00
$cflink [ 'hogs' ] = $this -> GetHogs ();
2008-04-22 00:47:15 +02:00
}
2013-03-29 20:25:14 +01:00
2008-04-22 00:47:15 +02:00
/*
2009-08-28 01:29:47 +02:00
* Should search even its children
2008-04-22 00:47:15 +02:00
*/
function & find_queue ( $interface , $qname ) {
if ( $qname == $this -> GetQname ())
return $this ;
}
2010-03-09 08:30:51 +01:00
function find_parentqueue ( $interface , $qname ) { return ; }
2008-04-22 00:47:15 +02:00
function delete_queue () {
unref_on_altq_queue_list ( $this -> GetQname ());
cleanup_queue_from_rules ( $this -> GetQname ());
unset_object_by_reference ( $this -> GetLink ());
}
2013-03-29 20:25:14 +01:00
2008-04-22 00:47:15 +02:00
function validate_input ( $data , & $input_errors ) {
parent :: validate_input ( $data , $input_errors );
2013-03-29 20:25:14 +01:00
2008-04-22 00:47:15 +02:00
if ( $data [ 'priority' ] > 255 )
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Priority must be an integer between 1 and 255. " );
2009-04-20 00:04:48 +02:00
$reqdfields [] = " bandwidth " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Bandwidth " );
2009-04-20 00:04:48 +02:00
$reqdfields [] = " bandwidthtype " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Bandwidthtype " );
2008-04-22 00:47:15 +02:00
shaper_do_input_validation ( $data , $reqdfields , $reqdfieldsn , $input_errors );
2013-03-29 20:25:14 +01:00
2008-04-22 00:47:15 +02:00
if ( $data [ 'bandwidth' ] && ! is_numeric ( $data [ 'bandwidth' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Bandwidth must be an integer. " );
2008-04-22 00:47:15 +02:00
2010-08-18 15:36:29 +02:00
if ( $data [ 'bandwidth' ] < 0 )
$input_errors [] = gettext ( " Bandwidth cannot be negative. " );
2008-04-22 00:47:15 +02:00
2010-08-18 15:36:29 +02:00
if ( $data [ 'bandwidthtype' ] == " % " ) {
if ( $data [ 'bandwidth' ] > 100 || $data [ 'bandwidth' ] < 0 )
$input_errors [] = gettext ( " Bandwidth in percentage should be between 1 and 100 bounds. " );
}
2008-04-22 00:47:15 +02:00
/*
2014-02-24 13:10:11 +01:00
$parent =& $this -> GetParent ();
switch ( $data [ 'bandwidthtype' ]) {
case " % " :
$myBw = $parent -> GetAvailableBandwidth () * floatval ( $data [ 'bandwidth' ]) / 100 ;
default :
$mybw = floatval ( $data [ 'bandwidth' ]) * get_bandwidthtype_scale ( $data [ 'bandwidthtype' ]);
break ;
}
if ( $parent -> GetAvailableBandwidth () < floatval ( $myBw ))
$input_errors [] = " The sum of children bandwidth exceeds that of the parent. " ;
2008-04-22 00:47:15 +02:00
*/
}
2013-03-29 20:25:14 +01:00
2008-04-22 00:47:15 +02:00
function ReadConfig ( & $q ) {
parent :: ReadConfig ( $q );
2009-11-03 18:12:29 +01:00
if ( ! empty ( $q [ 'buckets' ]))
2008-04-22 00:47:15 +02:00
$this -> SetBuckets ( $q [ 'buckets' ]);
2010-08-03 20:12:40 +02:00
else
$this -> SetBuckets ( " " );
2009-11-03 18:12:29 +01:00
if ( ! empty ( $q [ 'hogs' ]) && is_valid_shaperbw ( $q [ 'hogs' ]))
2008-04-22 00:47:15 +02:00
$this -> SetHogs ( $q [ 'hogs' ]);
2010-08-03 20:12:40 +02:00
else
$this -> SetHogs ( " " );
2008-04-22 00:47:15 +02:00
}
2013-03-29 20:25:14 +01:00
2008-04-22 00:47:15 +02:00
function build_javascript () {
return parent :: build_javascript ();
}
function build_tree () {
2014-02-24 13:10:11 +01:00
$tree = " <li><a href= \" firewall_shaper.php?interface= " .
$this -> GetInterface () . " &queue= " . $this -> GetQname () . " &action=show " ;
2009-11-03 18:12:29 +01:00
$tree .= " \" " ;
$tmpvalue = trim ( $this -> GetDefault ());
if ( ! empty ( $tmpvalue ))
$tree .= " class= \" navlnk \" " ;
$tree .= " > " . $this -> GetQname () . " </a> " ;
$tree .= " </li> " ;
return $tree ;
2008-04-22 00:47:15 +02:00
}
2013-03-29 20:25:14 +01:00
2009-08-28 01:29:47 +02:00
/* Even this should take children into consideration */
2011-01-28 15:39:48 +01:00
function build_rules ( & $default = false ) {
2008-04-22 00:47:15 +02:00
$pfq_rule = " queue " . $this -> qname ;
if ( $this -> GetInterface ())
2008-10-23 23:51:53 +02:00
$pfq_rule .= " on " . get_real_interface ( $this -> GetInterface ());
2008-04-22 00:47:15 +02:00
if ( $this -> GetBandwidth () && $this -> GetBwscale ())
$pfq_rule .= " bandwidth " . trim ( $this -> GetBandwidth ()) . $this -> GetBwscale ();
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetQpriority ());
if ( ! empty ( $tmpvalue ))
2008-04-22 00:47:15 +02:00
$pfq_rule .= " priority " . $this -> GetQpriority ();
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetQlimit ());
if ( ! empty ( $tmpvalue ))
2008-04-22 00:47:15 +02:00
$pfq_rule .= " qlimit " . $this -> GetQlimit ();
2014-02-24 13:10:11 +01:00
if ( $this -> GetDefault () || $this -> GetRed () || $this -> GetRio ()
2013-05-06 20:09:24 +02:00
|| $this -> GetEcn () || $this -> GetBuckets () || $this -> GetHogs () || $this -> GetCodel ()) {
2008-04-22 22:09:56 +02:00
$pfq_rule .= " fairq ( " ;
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetRed ());
if ( ! empty ( $tmpvalue )) {
2008-04-22 00:47:15 +02:00
$comma = 1 ;
$pfq_rule .= " red " ;
}
2013-05-06 20:09:24 +02:00
$tmpvalue = trim ( $this -> GetCodel ());
if ( ! empty ( $tmpvalue )) {
$comma = 1 ;
$pfq_rule .= " codel " ;
}
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetRio ());
if ( ! empty ( $tmpvalue )) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2008-04-22 00:47:15 +02:00
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " rio " ;
}
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetEcn ());
if ( ! empty ( $tmpvalue )) {
2014-02-24 13:10:11 +01:00
if ( $comma )
2008-04-22 00:47:15 +02:00
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " ecn " ;
}
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetDefault ());
if ( ! empty ( $tmpvalue )) {
2008-04-22 00:47:15 +02:00
if ( $comma )
$pfq_rule .= " , " ;
$comma = 1 ;
$pfq_rule .= " default " ;
2011-01-24 18:18:46 +01:00
$default = true ;
2008-04-22 00:47:15 +02:00
}
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetBuckets ());
if ( ! empty ( $tmpvalue )) {
2008-04-22 00:47:15 +02:00
if ( $comma )
$pfq_rule .= " , " ;
$pfq_rule .= " buckets " . $this -> GetBuckets () . " " ;
}
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetHogs ());
if ( ! empty ( $tmpvalue )) {
2008-04-22 00:47:15 +02:00
if ( $comma )
$pfq_rule .= " , " ;
$pfq_rule .= " hogs " . $this -> GetHogs () . " " ;
}
$pfq_rule .= " ) " ;
2014-02-24 13:10:11 +01:00
}
2008-04-22 00:47:15 +02:00
$pfq_rule .= " \n " ;
return $pfq_rule ;
}
function build_form () {
2010-07-21 20:19:11 +02:00
$form = parent :: build_form ();
$form .= " <tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Bandwidth " ) . " </td> " ;
2008-04-22 00:47:15 +02:00
$form .= " <td class= \" vtable \" > <input name= \" bandwidth \" id= \" bandwidth \" class= \" formfld unknown \" value= \" " ;
if ( $this -> GetBandwidth () > 0 )
2009-11-03 18:12:29 +01:00
$form .= htmlspecialchars ( $this -> GetBandwidth ());
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2008-04-22 00:47:15 +02:00
$form .= " <select name= \" bandwidthtype \" id= \" bandwidthtype \" class= \" formselect \" > " ;
$form .= " <option value= \" Gb \" " ;
if ( $this -> GetBwscale () == " Gb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Gbit/s " ) . " </option> " ;
2008-04-22 00:47:15 +02:00
$form .= " <option value= \" Mb \" " ;
if ( $this -> GetBwscale () == " Mb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Mbit/s " ) . " </option> " ;
2008-04-22 00:47:15 +02:00
$form .= " <option value= \" Kb \" " ;
if ( $this -> GetBwscale () == " Kb " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Kbit/s " ) . " </option> " ;
2012-03-22 16:20:41 +01:00
$form .= " <option value= \" b \" " ;
2008-04-22 00:47:15 +02:00
if ( $this -> GetBwscale () == " b " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-20 14:41:26 +02:00
$form .= " > " . gettext ( " Bit/s " ) . " </option> " ;
2008-04-22 00:47:15 +02:00
$form .= " <option value= \" % \" " ;
if ( $this -> GetBwscale () == " % " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2008-04-22 00:47:15 +02:00
$form .= " >%</option> " ;
2014-03-14 21:24:03 +01:00
$form .= " </select> <br /> " ;
2010-08-18 15:36:29 +02:00
$form .= " <span class= \" vexpl \" > " . gettext ( " Choose the amount of bandwidth for this queue " );
2008-04-22 00:47:15 +02:00
$form .= " </span></td></tr> " ;
2010-08-18 15:36:29 +02:00
$form .= " <tr><td class= \" vncellreq \" > " . gettext ( " Scheduler specific options " ) . " </td> " ;
2008-04-22 22:09:56 +02:00
$form .= " <td class= \" vtable \" ><table><tr><td> " ;
$form .= " <input id= \" buckets \" name= \" buckets \" value= \" " ;
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetBuckets ());
2014-02-24 13:10:11 +01:00
if ( ! empty ( $tmpvalue ))
2009-11-03 18:12:29 +01:00
$form .= $this -> GetBuckets ();
2014-03-14 21:24:03 +01:00
$form .= " \" /> " . gettext ( " Number of buckets available. " ) . " <br /></td></tr> " ;
2008-04-22 22:09:56 +02:00
$form .= " <tr><td class= \" vtable \" ><input id= \" hogs \" name= \" hogs \" value= \" " ;
2009-11-03 18:12:29 +01:00
$tmpvalue = trim ( $this -> GetHogs ());
2014-02-24 13:10:11 +01:00
if ( ! empty ( $tmpvalue ))
2009-11-03 18:12:29 +01:00
$form .= $this -> GetHogs ();
2014-03-14 21:24:03 +01:00
$form .= " \" /> " . gettext ( " Bandwidth limit for hosts to not saturate link. " ) . " <br /></td></tr> " ;
2008-04-22 22:09:56 +02:00
$form .= " </table></td></tr> " ;
2008-04-22 00:47:15 +02:00
return $form ;
}
2014-02-24 13:10:11 +01:00
function update_altq_queue_data ( & $data ) {
2008-04-22 00:47:15 +02:00
$this -> ReadConfig ( $data );
}
function wconfig () {
$cflink =& get_reference_to_me_in_config ( $this -> GetLink ());
if ( ! is_array ( $cflink ))
$cflink = array ();
$cflink [ 'interface' ] = $this -> GetInterface ();
2009-11-03 18:12:29 +01:00
$cflink [ 'qlimit' ] = trim ( $this -> GetQlimit ());
if ( empty ( $cflink [ 'qlimit' ]))
unset ( $cflink [ 'qlimit' ]);
$cflink [ 'priority' ] = trim ( $this -> GetQpriority ());
if ( empty ( $cflink [ 'priority' ]))
unset ( $cflink [ 'priority' ]);
2008-04-22 00:47:15 +02:00
$cflink [ 'name' ] = $this -> GetQname ();
2009-11-03 18:12:29 +01:00
$cflink [ 'description' ] = trim ( $this -> GetDescription ());
if ( empty ( $cflink [ 'description' ]))
unset ( $cflink [ 'description' ]);
2008-04-22 00:47:15 +02:00
$cflink [ 'bandwidth' ] = $this -> GetBandwidth ();
$cflink [ 'bandwidthtype' ] = $this -> GetBwscale ();
$cflink [ 'enabled' ] = $this -> GetEnabled ();
2009-11-03 18:12:29 +01:00
if ( empty ( $cflink [ 'enabled' ]))
unset ( $cflink [ 'enabled' ]);
$cflink [ 'default' ] = trim ( $this -> GetDefault ());
if ( empty ( $cflink [ 'default' ]))
unset ( $cflink [ 'default' ]);
$cflink [ 'red' ] = trim ( $this -> GetRed ());
if ( empty ( $cflink [ 'red' ]))
unset ( $cflink [ 'red' ]);
$cflink [ 'rio' ] = trim ( $this -> GetRio ());
if ( empty ( $cflink [ 'rio' ]))
unset ( $cflink [ 'rio' ]);
$cflink [ 'ecn' ] = trim ( $this -> GetEcn ());
if ( empty ( $cflink [ 'ecn' ]))
unset ( $cflink [ 'ecn' ]);
2013-09-28 14:12:35 +02:00
$cflink [ 'codel' ] = trim ( $this -> GetCodel ());
if ( empty ( $cflink [ 'codel' ]))
unset ( $cflink [ 'codel' ]);
2009-11-03 18:12:29 +01:00
$cflink [ 'buckets' ] = trim ( $this -> GetBuckets ());
if ( empty ( $cflink [ 'buckets' ]))
unset ( $cflink [ 'buckets' ]);
$cflink [ 'hogs' ] = trim ( $this -> GetHogs ());
if ( empty ( $cflink [ 'hogs' ]))
unset ( $cflink [ 'hogs' ]);
2008-04-22 00:47:15 +02:00
}
}
2005-09-25 08:23:03 +02:00
2008-07-14 23:50:10 +02:00
/*
2010-06-15 19:16:56 +02:00
* dummynet ( 4 ) wrappers .
2008-07-14 23:50:10 +02:00
*/
/*
* List of respective objects !
*/
2008-07-16 21:34:17 +02:00
$dummynet_pipe_list = array ();
2008-07-14 23:50:10 +02:00
class dummynet_class {
2014-02-24 13:10:11 +01:00
var $qname ;
2009-11-03 18:12:29 +01:00
var $qnumber ; /* dummynet(4) uses numbers instead of names; maybe integrate with pf the same as altq does?! */
2014-02-24 13:10:11 +01:00
var $qlimit ;
var $description ;
2009-11-03 18:12:29 +01:00
var $qenabled ;
var $link ;
var $qparent ; /* link to upper class so we do things easily on WF2Q+ rule creation */
2014-02-24 13:10:11 +01:00
var $plr ;
var $buckets ;
/* mask parameters */
var $mask ;
var $noerror ;
/* Accessor functions */
function SetLink ( $link ) {
$this -> link = $link ;
}
function GetLink () {
return $this -> link ;
}
2013-05-11 07:26:10 +02:00
function GetMask () {
2013-05-14 04:42:41 +02:00
if ( ! isset ( $this -> mask [ " type " ]))
$this -> mask [ " type " ] = " none " ;
2009-11-03 18:12:29 +01:00
return $this -> mask ;
}
function SetMask ( $mask ) {
$this -> mask = $mask ;
}
function & GetParent () {
return $this -> qparent ;
}
function SetParent ( & $parent ) {
$this -> qparent = & $parent ;
}
2014-02-24 13:10:11 +01:00
function GetEnabled () {
return $this -> qenabled ;
}
function SetEnabled ( $value ) {
$this -> qenabled = $value ;
}
2009-11-03 18:12:29 +01:00
function CanHaveChildren () {
return false ;
2014-02-24 13:10:11 +01:00
}
2009-11-03 18:12:29 +01:00
function CanBeDeleted () {
2014-02-24 13:10:11 +01:00
return true ;
}
function GetQname () {
return $this -> qname ;
}
function SetQname ( $name ) {
$this -> qname = trim ( $name );
}
function GetQlimit () {
return $this -> qlimit ;
}
function SetQlimit ( $limit ) {
$this -> qlimit = $limit ;
}
function GetDescription () {
return $this -> description ;
}
function SetDescription ( $str ) {
$this -> description = trim ( $str );
}
function GetFirstime () {
return $this -> firsttime ;
}
function SetFirsttime ( $number ) {
$this -> firsttime = $number ;
}
function GetBuckets () {
return $this -> buckets ;
}
function SetBuckets ( $buckets ) {
$this -> buckets = $buckets ;
}
2009-11-03 18:12:29 +01:00
function SetNumber ( $number ) {
$this -> qnumber = $number ;
}
function GetNumber () {
return $this -> qnumber ;
}
2014-02-24 13:10:11 +01:00
function GetPlr () {
return $this -> plr ;
}
function SetPlr ( $plr ) {
$this -> plr = $plr ;
}
2008-07-14 23:50:10 +02:00
2013-05-14 04:42:41 +02:00
function build_javascript () {
2013-05-22 00:53:48 +02:00
$javascript .= " <script type= \" text/javascript \" > \n " ;
2013-05-14 04:42:41 +02:00
$javascript .= " //<![CDATA[ \n " ;
2013-05-22 00:53:48 +02:00
$javascript .= " function enable_maskbits(enable_over) { \n " ;
$javascript .= " var e = document.getElementById( \" mask \" ); \n " ;
$javascript .= " if ((e.options[e.selectedIndex].text == \" none \" ) || enable_over) { \n " ;
2013-05-14 04:42:41 +02:00
$javascript .= " document.iform.maskbits.disabled = 1; \n " ;
$javascript .= " document.iform.maskbits.value = \" \" ; \n " ;
2013-05-28 22:34:39 +02:00
$javascript .= " document.iform.maskbitsv6.disabled = 1; \n " ;
$javascript .= " document.iform.maskbitsv6.value = \" \" ; \n " ;
2013-05-22 00:53:48 +02:00
$javascript .= " } else { \n " ;
2013-05-14 04:42:41 +02:00
$javascript .= " document.iform.maskbits.disabled = 0; \n " ;
2014-02-24 13:10:11 +01:00
$javascript .= " document.iform.maskbitsv6.disabled = 0; \n " ;
2013-05-22 00:53:48 +02:00
$javascript .= " }} \n " ;
2013-05-14 04:42:41 +02:00
$javascript .= " //]]> \n " ;
2013-05-22 00:53:48 +02:00
$javascript .= " </script> \n " ;
2013-05-14 04:42:41 +02:00
return $javascript ;
}
2008-07-16 21:34:17 +02:00
2009-11-03 18:12:29 +01:00
function validate_input ( $data , & $input_errors ) {
$reqdfields [] = " bandwidth " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Bandwidth " );
2014-10-29 21:39:15 +01:00
/* $reqdfields [] = " burst " ;
$reqdfieldsn [] = gettext ( " Burst " ); */
2009-11-03 18:12:29 +01:00
$reqdfields [] = " bandwidthtype " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Bandwidthtype " );
2011-03-22 19:19:49 +01:00
$reqdfields [] = " newname " ;
2010-08-18 15:36:29 +02:00
$reqdfieldsn [] = gettext ( " Name " );
2013-03-29 20:25:14 +01:00
2009-11-03 18:12:29 +01:00
shaper_do_input_validation ( $data , $reqdfields , $reqdfieldsn , $input_errors );
2013-10-11 13:25:12 +02:00
if ( $data [ 'plr' ] && ( ! is_numeric ( $data [ 'plr' ]) ||
2014-02-24 13:10:11 +01:00
( $data [ 'plr' ] < 0 ) || ( $data [ 'plr' ] > 1 )))
2013-06-19 10:42:15 +02:00
$input_errors [] = gettext ( " Plr must be a value between 0 and 1. " );
2013-10-11 13:25:12 +02:00
if ( $data [ 'buckets' ] && ( ! is_numeric ( $data [ 'buckets' ]) ||
( $data [ 'buckets' ] < 16 ) || ( $data [ 'buckets' ] > 65535 )))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Buckets must be an integer between 16 and 65535. " );
2014-02-24 13:10:11 +01:00
if ( $data [ 'qlimit' ] && ( ! is_numeric ( $data [ 'qlimit' ])))
$input_errors [] = gettext ( " Queue limit must be an integer " );
if ( ! empty ( $data [ 'newname' ]) && ! preg_match ( " /^[a-zA-Z0-9_-]+ $ / " , $data [ 'newname' ]))
2011-03-25 12:59:29 +01:00
$input_errors [] = gettext ( " Queue names must be alphanumeric and _ or - only. " );
2014-02-24 13:10:11 +01:00
if ( ! empty ( $data [ 'name' ]) && ! preg_match ( " /^[a-zA-Z0-9_-]+ $ / " , $data [ 'name' ]))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Queue names must be alphanumeric and _ or - only. " );
2014-02-24 13:10:11 +01:00
if ( isset ( $data [ 'maskbits' ]) && ( $data [ 'maskbits' ] <> " " ))
2013-05-11 07:26:10 +02:00
if (( ! is_numeric ( $data [ 'maskbits' ])) || ( $data [ 'maskbits' ] <= 0 ) || ( $data [ 'maskbits' ] > 32 ))
2013-05-22 00:53:48 +02:00
$input_errors [] = gettext ( " IPV4 bit mask must be blank or numeric value between 1 and 32. " );
2013-05-28 22:34:39 +02:00
if ( isset ( $data [ 'maskbitsv6' ]) && ( $data [ 'maskbitsv6' ] <> " " ))
if (( ! is_numeric ( $data [ 'maskbitsv6' ])) || ( $data [ 'maskbitsv6' ] <= 0 ) || ( $data [ 'maskbitsv6' ] > 128 ))
$input_errors [] = gettext ( " IPV6 bit mask must be blank or numeric value between 1 and 128. " );
2013-05-22 00:53:48 +02:00
}
2014-02-24 13:10:11 +01:00
2013-05-22 00:53:48 +02:00
function build_mask_rules ( & $pfq_rule ) {
$mask = $this -> GetMask ();
if ( ! empty ( $mask [ 'type' ])) {
if ( $mask [ 'type' ] <> 'none' )
$pfq_rule .= " mask " ;
switch ( $mask [ 'type' ]) {
case 'srcaddress' :
2013-05-28 22:34:39 +02:00
if ( ! empty ( $mask [ 'bitsv6' ]) && ( $mask [ 'bitsv6' ] <> " " ))
$pfq_rule .= " src-ip6 / " . $mask [ 'bitsv6' ];
else
$pfq_rule .= " src-ip6 /128 " ;
2014-02-24 13:10:11 +01:00
if ( ! empty ( $mask [ 'bits' ]) && ( $mask [ 'bits' ] <> " " ))
$pfq_rule .= sprintf ( " src-ip 0x%x " , gen_subnet_mask_long ( $mask [ 'bits' ]));
else
2013-05-22 00:53:48 +02:00
$pfq_rule .= " src-ip 0xffffffff " ;
break ;
case 'dstaddress' :
2013-05-28 22:34:39 +02:00
if ( ! empty ( $mask [ 'bitsv6' ]) && ( $mask [ 'bitsv6' ] <> " " ))
$pfq_rule .= " dst-ip6 / " . $mask [ 'bitsv6' ];
else
$pfq_rule .= " dst-ip6 /128 " ;
2014-02-24 13:10:11 +01:00
if ( ! empty ( $mask [ 'bits' ]) && ( $mask [ 'bits' ] <> " " ))
$pfq_rule .= sprintf ( " dst-ip 0x%x " , gen_subnet_mask_long ( $mask [ 'bits' ]));
else
2013-05-22 00:53:48 +02:00
$pfq_rule .= " dst-ip 0xffffffff " ;
break ;
default :
break ;
}
2014-02-24 13:10:11 +01:00
}
2009-11-03 18:12:29 +01:00
}
2014-02-24 13:10:11 +01:00
2008-07-14 23:50:10 +02:00
}
class dnpipe_class extends dummynet_class {
2014-02-24 13:10:11 +01:00
var $delay ;
2012-10-09 19:44:49 +02:00
var $qbandwidth = array ();
2008-07-16 21:34:17 +02:00
var $qbandwidthtype ;
2008-07-14 23:50:10 +02:00
/* This is here to help on form building and building rules/lists */
2014-02-24 13:10:11 +01:00
var $subqueues = array ();
2008-07-14 23:50:10 +02:00
2009-08-28 01:29:47 +02:00
function CanHaveChildren () {
2014-02-24 13:10:11 +01:00
return true ;
}
2008-07-16 21:34:17 +02:00
function SetDelay ( $delay ) {
$this -> delay = $delay ;
}
function GetDelay () {
return $this -> delay ;
}
function delete_queue () {
cleanup_dnqueue_from_rules ( $this -> GetQname ());
foreach ( $this -> subqueues as $q )
$q -> delete_queue ();
unset_dn_object_by_reference ( $this -> GetLink ());
2014-04-28 14:36:36 +02:00
@ pfSense_pipe_action ( " pipe delete " . $this -> GetNumber ());
2014-02-24 13:10:11 +01:00
}
function GetBandwidth () {
return $this -> qbandwidth ;
}
function SetBandwidth ( $bandwidth ) {
$this -> qbandwidth = $bandwidth ;
}
2013-06-17 15:25:43 +02:00
function GetBurst () {
return $this -> qburst ;
}
function SetBurst ( $burst ) {
$this -> qburst = $burst ;
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function & add_queue ( $interface , & $queue , & $path , & $input_errors ) {
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
if ( ! is_array ( $this -> subqueues ))
$this -> subqueues = array ();
2013-03-29 20:25:14 +01:00
2010-03-09 08:30:51 +01:00
$q =& new dnqueue_class ();
2008-07-16 21:34:17 +02:00
$q -> SetLink ( $path );
$q -> SetEnabled ( " on " );
$q -> SetPipe ( $this -> GetQname ());
2013-09-12 16:29:21 +02:00
$q -> SetParent ( $this );
2008-07-16 21:34:17 +02:00
$q -> ReadConfig ( $queue );
$q -> validate_input ( $queue , $input_errors );
2011-01-24 18:04:14 +01:00
if ( count ( $input_errors )) {
log_error ( " SHAPER: could not create queue " . $q -> GetQname () . " on interface { $interface } because: " . print_r ( $input_errors , true ));
2008-07-16 21:34:17 +02:00
return $q ;
2011-01-24 18:04:14 +01:00
}
2012-06-01 21:51:18 +02:00
$number = dnqueue_find_nextnumber ();
$q -> SetNumber ( $number );
2008-07-16 21:34:17 +02:00
$this -> subqueues [ $q -> GetQname ()] = & $q ;
2014-02-24 13:10:11 +01:00
2008-07-16 21:34:17 +02:00
return $q ;
}
2008-07-14 23:50:10 +02:00
2013-09-12 16:29:21 +02:00
function & get_queue_list ( & $q = null ) {
2008-07-16 21:34:17 +02:00
$qlist = array ();
2008-07-14 23:50:10 +02:00
2008-07-16 22:41:27 +02:00
$qlist [ $this -> GetQname ()] = $this -> GetNumber ();
2008-07-16 21:34:17 +02:00
if ( is_array ( $this -> subqueues )) {
foreach ( $this -> subqueues as $queue )
2013-09-12 16:29:21 +02:00
$queue -> get_queue_list ( $qlist );
2008-07-14 23:50:10 +02:00
}
2008-07-16 21:34:17 +02:00
return $qlist ;
}
2013-03-29 20:25:14 +01:00
2014-02-24 13:10:11 +01:00
/*
* Should search even its children
*/
function & find_queue ( $pipe , $qname ) {
if ( $qname == $this -> GetQname ())
return $this ;
foreach ( $this -> subqueues as $q ) {
$result =& $q -> find_queue ( " " , $qname );
if ( $result )
return $result ;
}
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function & find_parentqueue ( $pipe , $qname ) {
return NULL ;
2014-02-24 13:10:11 +01:00
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function validate_input ( $data , & $input_errors ) {
parent :: validate_input ( $data , $input_errors );
2008-07-14 23:50:10 +02:00
2012-10-09 19:44:49 +02:00
$schedule = 0 ;
$schedulenone = 0 ;
$entries = 0 ;
2014-10-15 00:36:27 +02:00
/* XXX: Really no better way? */
for ( $i = 0 ; $i < 2900 ; $i ++ ) {
2012-10-09 19:44:49 +02:00
if ( ! empty ( $data [ " bwsched { $i } " ])) {
if ( $data [ " bwsched { $i } " ] != " none " )
$schedule ++ ;
else
$schedulenone ++ ;
}
if ( ! empty ( $data [ " bandwidth { $i } " ])) {
if ( ! is_numeric ( $data [ " bandwidth { $i } " ]))
$input_errors [] = sprintf ( gettext ( " Bandwidth for schedule %s must be an integer. " ), $data [ " bwsched { $i } " ]);
2013-09-03 13:45:03 +02:00
else if (( $data [ " burst { $i } " ] != " " ) && ( ! is_numeric ( $data [ " burst { $i } " ])))
$input_errors [] = sprintf ( gettext ( " Burst for schedule %s must be an integer. " ), $data [ " bwsched { $i } " ]);
2012-10-09 19:44:49 +02:00
else
$entries ++ ;
}
}
if ( $schedule == 0 && $entries > 1 )
$input_errors [] = gettext ( " You need to specify a schedule for every additional entry " );
if ( $schedulenone > 0 && $entries > 1 )
$input_errors [] = gettext ( " If more than one bandwidth configured all schedules need to be selected " );
if ( $entries == 0 )
$input_errors [] = gettext ( " At least one bw specification is necessary " );
2008-07-16 21:34:17 +02:00
if ( $data [ 'delay' ] && ( ! is_numeric ( $data [ 'delay' ])))
2010-08-18 15:36:29 +02:00
$input_errors [] = gettext ( " Delay must be an integer. " );
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function ReadConfig ( & $q ) {
2011-02-09 22:40:00 +01:00
if ( ! empty ( $q [ 'name' ]) && ! empty ( $q [ 'newname' ]) && $q [ 'name' ] != $q [ 'newname' ]) {
$this -> SetQname ( $q [ 'newname' ]);
} else if ( ! empty ( $q [ 'newname' ])) {
$this -> SetQname ( $q [ 'newname' ]);
} else {
$this -> SetQname ( $q [ 'name' ]);
}
2008-07-16 21:34:17 +02:00
$this -> SetNumber ( $q [ 'number' ]);
2012-10-09 19:44:49 +02:00
if ( ! empty ( $_POST )) {
$bandwidth = array ();
2014-10-15 00:36:27 +02:00
/* XXX: Really no better way? */
for ( $i = 0 ; $i < 2900 ; $i ++ ) {
2014-02-24 13:10:11 +01:00
if ( isset ( $q [ " bandwidth { $i } " ]) && $q [ " bandwidth { $i } " ] <> " " ) {
2012-10-09 19:44:49 +02:00
$bw = array ();
$bw [ 'bw' ] = $q [ " bandwidth { $i } " ];
2013-06-17 15:25:43 +02:00
$bw [ 'burst' ] = $q [ " burst { $i } " ];
2012-10-09 19:44:49 +02:00
if ( isset ( $q [ " bwtype { $i } " ]) && $q [ " bwtype { $i } " ])
$bw [ 'bwscale' ] = $q [ " bwtype { $i } " ];
if ( isset ( $q [ " bwsched { $i } " ]) && $q [ " bwsched { $i } " ])
$bw [ 'bwsched' ] = $q [ " bwsched { $i } " ];
$bandwidth [] = $bw ;
}
}
$this -> SetBandwidth ( $bandwidth );
2008-07-16 21:34:17 +02:00
}
2014-02-24 13:10:11 +01:00
2013-06-17 15:25:43 +02:00
if ( is_array ( $q [ 'bandwidth' ]) && is_array ( $q [ 'bandwidth' ][ 'item' ])) {
2012-10-09 19:44:49 +02:00
$this -> SetBandwidth ( $q [ 'bandwidth' ][ 'item' ]);
2013-06-17 15:25:43 +02:00
$this -> SetBurst ( $q [ 'burst' ][ 'item' ]);
}
2014-02-24 13:10:11 +01:00
2008-07-16 21:34:17 +02:00
if ( isset ( $q [ 'qlimit' ]) && $q [ 'qlimit' ] <> " " )
2014-02-24 13:10:11 +01:00
$this -> SetQlimit ( $q [ 'qlimit' ]);
2011-01-19 22:20:50 +01:00
else
2014-02-24 13:10:11 +01:00
$this -> SetQlimit ( " " );
2008-07-16 21:34:17 +02:00
if ( isset ( $q [ 'mask' ]) && $q [ 'mask' ] <> " " )
2013-05-11 07:26:10 +02:00
$masktype = $q [ 'mask' ];
else
$masktype = " " ;
if ( isset ( $q [ 'maskbits' ]) && $q [ 'maskbits' ] <> " " )
$maskbits = $q [ 'maskbits' ];
2011-01-19 22:20:50 +01:00
else
2013-05-11 07:26:10 +02:00
$maskbits = " " ;
2013-05-22 00:53:48 +02:00
if ( isset ( $q [ 'maskbitsv6' ]) && $q [ 'maskbitsv6' ] <> " " )
$maskbitsv6 = $q [ 'maskbitsv6' ];
else
$maskbitsv6 = " " ;
$this -> SetMask ( array ( " type " => $masktype , " bits " => $maskbits , " bitsv6 " => $maskbitsv6 ));
2008-07-16 21:34:17 +02:00
if ( isset ( $q [ 'buckets' ]) && $q [ 'buckets' ] <> " " )
2014-02-24 13:10:11 +01:00
$this -> SetBuckets ( $q [ 'buckets' ]);
2011-01-19 22:20:50 +01:00
else
2014-02-24 13:10:11 +01:00
$this -> SetBuckets ( " " );
if ( isset ( $q [ 'plr' ]) && $q [ 'plr' ] <> " " )
$this -> SetPlr ( $q [ 'plr' ]);
2011-01-19 22:20:50 +01:00
else
2014-02-24 13:10:11 +01:00
$this -> SetPlr ( " " );
2008-07-16 21:34:17 +02:00
if ( isset ( $q [ 'delay' ]) && $q [ 'delay' ] <> " " )
2014-02-24 13:10:11 +01:00
$this -> SetDelay ( $q [ 'delay' ]);
2011-01-19 22:20:50 +01:00
else
$this -> SetDelay ( 0 );
2014-02-24 13:10:11 +01:00
if ( isset ( $q [ 'description' ]) && $q [ 'description' ] <> " " )
2008-07-16 21:34:17 +02:00
$this -> SetDescription ( $q [ 'description' ]);
2011-01-19 22:20:50 +01:00
else
$this -> SetDescription ( " " );
2008-07-16 21:34:17 +02:00
$this -> SetEnabled ( $q [ 'enabled' ]);
2008-07-14 23:50:10 +02:00
2014-02-24 13:10:11 +01:00
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function build_tree () {
2014-02-24 13:10:11 +01:00
$tree = " <li><a href= \" firewall_shaper_vinterface.php?pipe= " . $this -> GetQname () . " &queue= " . $this -> GetQname () . " &action=show \" > " ;
2008-07-16 21:34:17 +02:00
$tree .= $this -> GetQname () . " </a> " ;
if ( is_array ( $this -> subqueues )) {
$tree .= " <ul> " ;
foreach ( $this -> subqueues as $q ) {
$tree .= $q -> build_tree ();
2014-02-24 13:10:11 +01:00
}
2008-07-16 21:34:17 +02:00
$tree .= " </ul> " ;
2008-07-14 23:50:10 +02:00
}
2008-07-16 21:34:17 +02:00
$tree .= " </li> " ;
2013-03-29 20:25:14 +01:00
2008-07-16 21:34:17 +02:00
return $tree ;
}
2008-07-14 23:50:10 +02:00
2014-02-24 13:10:11 +01:00
function build_rules () {
2012-10-09 19:44:49 +02:00
global $config , $time_based_rules ;
2008-07-18 18:46:43 +02:00
if ( $this -> GetEnabled () == " " )
return ;
2012-10-15 14:41:36 +02:00
$pfq_rule = " \n pipe " . $this -> GetNumber () . " config " ;
2012-10-29 09:22:17 +01:00
$found = false ;
2012-10-09 19:44:49 +02:00
$bandwidth = $this -> GetBandwidth ();
if ( is_array ( $bandwidth )) {
foreach ( $bandwidth as $bw ) {
2012-10-23 22:56:19 +02:00
if ( $bw [ 'bwsched' ] != " none " ) {
2012-10-09 19:44:49 +02:00
$time_based_rules = true ;
2012-10-18 11:04:22 +02:00
if ( is_array ( $config [ 'schedules' ]) && is_array ( $config [ 'schedules' ][ 'schedule' ])) {
2012-10-18 11:03:53 +02:00
foreach ( $config [ 'schedules' ][ 'schedule' ] as $schedule ) {
if ( $bw [ 'bwsched' ] == $schedule [ 'name' ]) {
if ( filter_get_time_based_rule_status ( $schedule )) {
$pfq_rule .= " bw " . trim ( $bw [ 'bw' ]) . $bw [ 'bwscale' ];
2013-09-02 08:55:09 +02:00
if ( is_numeric ( $bw [ 'burst' ]) && ( $bw [ 'burst' ] > 0 ))
2014-05-06 21:57:57 +02:00
$pfq_rule .= " burst " . trim ( $bw [ 'burst' ]);
2012-10-29 09:22:17 +01:00
$found = true ;
2012-10-18 11:03:53 +02:00
break ;
}
2012-10-09 19:44:49 +02:00
}
}
2012-11-08 22:39:03 +01:00
} else {
2012-10-29 09:22:17 +01:00
$pfq_rule .= " bw 0 " ;
2012-11-09 10:42:27 +01:00
$found = true ;
2012-11-08 22:39:03 +01:00
break ;
}
2012-11-07 16:19:30 +01:00
} else {
2012-10-09 19:44:49 +02:00
$pfq_rule .= " bw " . trim ( $bw [ 'bw' ]) . $bw [ 'bwscale' ];
2013-09-02 08:55:09 +02:00
if ( is_numeric ( $bw [ 'burst' ]) && ( $bw [ 'burst' ] > 0 ))
2014-05-06 21:57:57 +02:00
$pfq_rule .= " burst " . trim ( $bw [ 'burst' ]);
2012-11-09 10:42:27 +01:00
$found = true ;
2012-11-07 16:19:30 +01:00
break ;
}
2012-10-09 19:44:49 +02:00
}
2012-10-29 09:22:17 +01:00
if ( $found == false )
$pfq_rule .= " bw 0 " ;
2012-11-07 16:19:30 +01:00
} else
$pfq_rule .= " bw 0 " ;
2012-10-09 19:44:49 +02:00
2008-07-16 21:34:17 +02:00
if ( $this -> GetQlimit ())
2013-06-17 15:25:43 +02:00
$pfq_rule .= " queue " . $this -> GetQlimit ();
2008-07-16 21:34:17 +02:00
if ( $this -> GetPlr ())
$pfq_rule .= " plr " . $this -> GetPlr ();
if ( $this -> GetBuckets ())
$pfq_rule .= " buckets " . $this -> GetBuckets ();
if ( $this -> GetDelay ())
$pfq_rule .= " delay " . $this -> GetDelay ();
2013-05-22 00:53:48 +02:00
$this -> build_mask_rules ( $pfq_rule );
2008-07-16 21:34:17 +02:00
2012-03-23 22:10:42 +01:00
$pfq_rule .= " \n " ;
2012-03-23 22:01:06 +01:00
if ( ! empty ( $this -> subqueues ) && count ( $this -> subqueues ) > 0 ) {
foreach ( $this -> subqueues as $q )
$pfq_rule .= $q -> build_rules ();
}
2008-07-16 21:34:17 +02:00
$pfq_rule .= " \n " ;
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
return $pfq_rule ;
2014-02-24 13:10:11 +01:00
}
2008-07-14 23:50:10 +02:00
2014-02-24 13:10:11 +01:00
function update_dn_data ( & $data ) {
2008-07-16 21:34:17 +02:00
$this -> ReadConfig ( $data );
}
2008-07-14 23:50:10 +02:00
2012-10-09 19:44:49 +02:00
function build_javascript () {
global $g , $config ;
2013-05-14 04:42:41 +02:00
$javasr = parent :: build_javascript ();
2014-02-24 13:10:11 +01:00
2012-10-09 19:44:49 +02:00
//build list of schedules
$schedules = " <option value='none'>none</option> " ;
if ( is_array ( $config [ 'schedules' ]) && is_array ( $config [ 'schedules' ][ 'schedule' ])) {
foreach ( $config [ 'schedules' ][ 'schedule' ] as $schedule ) {
if ( $schedule [ 'name' ] <> " " )
$schedules .= " <option value=' { $schedule [ 'name' ] } '> { $schedule [ 'name' ] } </option> " ;
}
}
$bwopt = " " ;
foreach ( array ( " Kb " => " Kbit/s " , " Mb " => " Mbit/s " , " Gb " => " Gbit/s " , " b " => " Bit/s " ) as $bwidx => $bw )
$bwopt .= " <option value=' { $bwidx } '> { $bw } </option> " ;
2013-05-14 04:42:41 +02:00
$javasr .= <<< EOD
2013-03-23 22:12:13 +01:00
< script type = 'text/javascript' >
2013-03-22 16:47:53 +01:00
//<![CDATA[
2012-10-09 19:44:49 +02:00
var addBwRowTo = ( function () {
return ( function ( tableId ) {
var d , tbody , tr , td ;
d = document ;
tbody = d . getElementById ( tableId ) . getElementsByTagName ( " tbody " ) . item ( 0 );
tr = d . createElement ( " tr " );
td = d . createElement ( " td " );
2013-03-25 22:46:22 +01:00
td . innerHTML = " <input type='hidden' value=' " + totalrows + " ' name='bandwidth_row- " + totalrows + " ' /><input size='10' type='text' class='formfld unknown' name='bandwidth " + totalrows + " ' id='bandwidth " + totalrows + " ' /> " ;
2012-10-09 19:44:49 +02:00
tr . appendChild ( td );
2014-10-29 21:39:15 +01:00
//td = d.createElement("td");
//td.innerHTML="<input type='hidden' value='" + totalrows +"' name='burst_row-" + totalrows + "' /><input size='10' type='text' class='formfld unknown' name='burst" + totalrows + "' id='burst" + totalrows + "' />";
//tr.appendChild(td);
2013-06-17 15:25:43 +02:00
td = d . createElement ( " td " );
2013-03-25 22:46:22 +01:00
td . innerHTML = " <input type='hidden' value=' " + totalrows + " ' name='bwtype_row- " + totalrows + " ' /><select class='formselect' name='bwtype " + totalrows + " '> { $bwopt } </select> " ;
2012-10-09 19:44:49 +02:00
tr . appendChild ( td );
td = d . createElement ( " td " );
2013-03-25 22:46:22 +01:00
td . innerHTML = " <input type='hidden' value=' " + totalrows + " ' name='bwsched_row- " + totalrows + " ' /><select class='formselect' name='bwsched " + totalrows + " '> { $schedules } </select> " ;
2012-10-09 19:44:49 +02:00
tr . appendChild ( td );
td = d . createElement ( " td " );
td . rowSpan = " 1 " ;
2013-03-25 22:46:22 +01:00
td . innerHTML = '<a onclick="removeBwRow(this); return false;" href="#"><img border="0" src="/themes/{$g[' theme ']}/images/icons/icon_x.gif" alt="remove" /></a>' ;
2012-10-09 19:44:49 +02:00
tr . appendChild ( td );
tbody . appendChild ( tr );
totalrows ++ ;
});
})();
function removeBwRow ( el ) {
var cel ;
while ( el && el . nodeName . toLowerCase () != " tr " )
2014-02-24 13:10:11 +01:00
el = el . parentNode ;
2012-10-09 19:44:49 +02:00
if ( el && el . parentNode ) {
cel = el . getElementsByTagName ( " td " ) . item ( 0 );
el . parentNode . removeChild ( el );
}
}
2013-03-22 16:47:53 +01:00
//]]>
2012-10-09 19:44:49 +02:00
</ script >
EOD ;
2014-02-24 13:10:11 +01:00
return $javasr ;
2012-10-09 19:44:49 +02:00
}
2014-02-24 13:10:11 +01:00
function build_form () {
2012-10-09 19:44:49 +02:00
global $g , $config ;
//build list of schedules
$schedules = array ();
$schedules [] = " none " ; //leave none to leave rule enabled all the time
if ( is_array ( $config [ 'schedules' ]) && is_array ( $config [ 'schedules' ][ 'schedule' ])) {
foreach ( $config [ 'schedules' ][ 'schedule' ] as $schedule ) {
if ( $schedule [ 'name' ] <> " " )
$schedules [] = $schedule [ 'name' ];
}
}
2014-03-14 21:24:03 +01:00
$form = " <tr><td valign= \" middle \" class= \" vncellreq \" ><br /> " ;
2014-02-24 13:10:11 +01:00
$form .= gettext ( " Enable " );
$form .= " </td><td class= \" vncellreq \" > " ;
$form .= " <input type= \" checkbox \" id= \" enabled \" name= \" enabled \" value= \" on \" " ;
if ( $this -> GetEnabled () == " on " )
$form .= " checked= \" checked \" " ;
$form .= " /><span class= \" vexpl \" > " . gettext ( " Enable limiter and its children " ) . " </span> " ;
$form .= " </td></tr> " ;
2014-03-14 21:24:03 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" ><br /><span class= \" vexpl \" > " . gettext ( " Name " ) . " </span></td> " ;
2008-07-14 23:50:10 +02:00
$form .= " <td class= \" vncellreq \" > " ;
2011-02-09 22:40:00 +01:00
$form .= " <input type= \" text \" id= \" newname \" name= \" newname \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetQname () . " \" /> " ;
2011-02-09 22:40:00 +01:00
$form .= " <input type= \" hidden \" id= \" name \" name= \" name \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetQname () . " \" /> " ;
2012-06-01 21:51:18 +02:00
if ( $this -> GetNumber () > 0 ) {
$form .= " <input type= \" hidden \" id= \" number \" name= \" number \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetNumber () . " \" /> " ;
2012-06-01 21:51:18 +02:00
}
2008-07-14 23:50:10 +02:00
$form .= " </td></tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Bandwidth " );
2012-10-09 19:44:49 +02:00
$bandwidth = $this -> GetBandwidth ();
2008-07-14 23:50:10 +02:00
$form .= " </td><td class= \" vncellreq \" > " ;
2012-10-09 19:44:49 +02:00
$form .= " <table id='maintable'> " ;
$form .= " <tbody><tr> " ;
2013-06-17 15:25:43 +02:00
$form .= " <td width='35%'><div id='onecolumn'>Bandwidth</div></td> " ;
2014-10-29 21:39:15 +01:00
//$form .= "<td width='35%'><div id='fifthcolumn'>Burst</div></td>";
2012-10-09 19:44:49 +02:00
$form .= " <td width='20%'><div id='twocolumn'>Bw type</div></td> " ;
$form .= " <td width='35%' ><div id='thirdcolumn'>Schedule</div></td> " ;
$form .= " <td width='5%'><div id='fourthcolumn'></div></td> " ;
$form .= " </tr> " ;
if ( is_array ( $bandwidth )) {
foreach ( $bandwidth as $bwidx => $bw ) {
$form .= " \n <tr><td width='40%'> " ;
2013-03-25 22:46:22 +01:00
$form .= " <input class='formfld unknown' size='10' type= \" text \" id= \" bandwidth { $bwidx } \" name= \" bandwidth { $bwidx } \" value= \" { $bw [ 'bw' ] } \" /> " ;
2014-10-29 21:39:15 +01:00
//$form .= "</td><td width='20%'>";
//$form .= "<input class='formfld unknown' size='10' type=\"text\" id=\"burst{$bwidx}\" name=\"burst{$bwidx}\" value=\"{$bw['burst']}\" />";
2013-06-17 15:25:43 +02:00
$form .= " </td><td width='20%'> " ;
2012-10-09 19:44:49 +02:00
$form .= " <select id= \" bwtype { $bwidx } \" name= \" bwtype { $bwidx } \" class= \" formselect \" > " ;
foreach ( array ( " Kb " => " Kbit/s " , " Mb " => " Mbit/s " , " Gb " => " Gbit/s " , " b " => " Bit/s " ) as $bwsidx => $bwscale ) {
$form .= " <option value= \" { $bwsidx } \" " ;
if ( $bw [ 'bwscale' ] == $bwsidx )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2012-10-09 19:44:49 +02:00
$form .= " > { $bwscale } </option> " ;
}
$form .= " </select> " ;
$form .= " </td><td width='35%' > " ;
$form .= " <select id= \" bwsched { $bwidx } \" name= \" bwsched { $bwidx } \" class= \" formselect \" > " ;
foreach ( $schedules as $schd ) {
$selected = " " ;
if ( $bw [ 'bwsched' ] == $schd )
2013-03-29 20:25:14 +01:00
$selected = " selected= \" selected \" " ;
2012-10-09 19:44:49 +02:00
$form .= " <option value=' { $schd } ' { $selected } > { $schd } </option> " ;
}
$form .= " </select> " ;
$form .= " </td><td width='5%' > " ;
2013-03-25 22:46:22 +01:00
$form .= " <a onclick= \" removeBwRow(this); return false; \" href='#'><img border='0' src='/themes/ { $g [ 'theme' ] } /images/icons/icon_x.gif' alt='remove' /></a> " ;
2012-10-09 19:44:49 +02:00
$form .= " </td></tr> " ;
}
}
$form .= " </tbody></table> " ;
$form .= " <a onclick= \" javascript:addBwRowTo('maintable'); return false; \" href='#'> " ;
2013-03-25 22:46:22 +01:00
$form .= " <img border='0' src='/themes/ { $g [ 'theme' ] } /images/icons/icon_plus.gif' alt='add' title=' " . gettext ( " add another schedule " ) . " ' /></a> " ;
2014-10-29 21:39:15 +01:00
//$form .= "<br /><span class=\"vexpl\">" . gettext("Bandwidth is a rate (e.g. Mbit/s), burst is a total amount of data that will be transferred at full speed after an idle period.") . "</span><br />";
$form .= " <br /><span class= \" vexpl \" > " . gettext ( " Bandwidth is the rate (e.g. Mbit/s) to which traffic in this limiter will be restricted. " ) . " </span><br /> " ;
2008-07-14 23:50:10 +02:00
$form .= " </td></tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Mask " ) . " </td> " ;
2008-07-17 00:52:52 +02:00
$form .= " <td class= \" vncellreq \" > " ;
2013-05-14 04:42:41 +02:00
$form .= " <select name= \" mask \" id= \" mask \" class= \" formselect \" onchange= \" enable_maskbits(); \" > " ;
2008-07-17 00:52:52 +02:00
$form .= " <option value= \" none \" " ;
2013-05-11 07:26:10 +02:00
$mask = $this -> GetMask ();
if ( $mask [ 'type' ] == " none " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2008-07-17 00:52:52 +02:00
$form .= " >none</option> " ;
$form .= " <option value= \" srcaddress \" " ;
2013-05-11 07:26:10 +02:00
if ( $mask [ 'type' ] == " srcaddress " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-18 15:36:29 +02:00
$form .= " > " . gettext ( " Source addresses " ) . " </option> " ;
2008-07-17 00:52:52 +02:00
$form .= " <option value= \" dstaddress \" " ;
2013-05-11 07:26:10 +02:00
if ( $mask [ 'type' ] == " dstaddress " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-18 15:36:29 +02:00
$form .= " > " . gettext ( " Destination addresses " ) . " </option> " ;
2008-07-17 00:52:52 +02:00
$form .= " </select> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> " ;
2013-05-11 07:26:10 +02:00
$form .= " <span class= \" vexpl \" > " . gettext ( " If 'source' or 'destination' slots is chosen, \n "
2010-08-18 15:36:29 +02:00
. " a dynamic pipe with the bandwidth, delay, packet loss and queue size given above will \n "
. " be created for each source/destination IP address encountered, \n "
. " respectively. This makes it possible to easily specify bandwidth \n "
2013-05-11 07:26:10 +02:00
. " limits per host. " ) . " </span><br /> " ;
$form .= " 255.255.255.255/ <input type= \" text \" class= \" formfld unknown \" size= \" 2 \" id= \" maskbits \" name= \" maskbits \" value= \" " ;
2013-05-14 04:42:41 +02:00
if ( $mask [ 'type' ] <> " none " )
2013-05-11 07:26:10 +02:00
$form .= $mask [ 'bits' ];
2013-05-14 04:42:41 +02:00
$form .= " \" " ;
if ( $mask [ 'type' ] == " none " )
$form .= " disabled " ;
$form .= " /> " ;
2014-03-14 21:24:03 +01:00
$form .= " IPV4 mask bits (1-32)<br /> " ;
2013-05-28 22:34:39 +02:00
$form .= " ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/ <input type= \" text \" class= \" formfld unknown \" size= \" 2 \" id= \" maskbitsv6 \" name= \" maskbitsv6 \" value= \" " ;
if ( $mask [ 'type' ] <> " none " )
$form .= $mask [ 'bitsv6' ];
$form .= " \" " ;
if ( $mask [ 'type' ] == " none " )
$form .= " disabled " ;
$form .= " /> " ;
2014-03-14 21:24:03 +01:00
$form .= " IPV6 mask bits (1-128)<br /> " ;
2013-05-11 07:26:10 +02:00
$form .= " <span class= \" vexpl \" > " . gettext ( " If 'source' or 'destination' slots is chosen, \n "
. " leaving the mask bits blank will create one pipe per host. Otherwise specify \n "
. " the number of 'one' bits in the subnet mask used to group multiple hosts \n "
. " per pipe. " ) . " </span> " ;
2008-07-17 00:52:52 +02:00
$form .= " </td></tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Description " ) . " </td> " ;
2008-07-17 00:52:52 +02:00
$form .= " <td class= \" vncellreq \" > " ;
2013-04-03 18:08:59 +02:00
$form .= " <input type= \" text \" class= \" formfld unknown \" size= \" 40 \" id= \" description \" name= \" description \" value= \" " ;
2008-07-17 00:52:52 +02:00
$form .= $this -> GetDescription ();
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> <span class= \" vexpl \" > " ;
2010-08-18 15:36:29 +02:00
$form .= gettext ( " You may enter a description here for your reference (not parsed). " ) . " </span> " ;
2008-07-17 00:52:52 +02:00
$form .= " </td></tr> " ;
2014-02-24 13:10:11 +01:00
$form .= " <tr id= \" sprtable4 \" > " ;
2008-07-17 00:52:52 +02:00
$form .= " <td></td> " ;
2014-02-24 13:10:11 +01:00
$form .= " <td><div id= \" showadvancedboxspr \" > " ;
$form .= " <p><input type= \" button \" onclick= \" show_source_port_range() \" " ;
2013-03-25 22:46:22 +01:00
$form .= " value= \" " . gettext ( " Show advanced options " ) . " \" /> " ;
2014-02-24 13:10:11 +01:00
$form .= " </p></div></td></tr> " ;
$form .= " <tr style= \" display:none \" id= \" sprtable \" > " ;
2008-07-17 00:31:26 +02:00
2013-03-23 22:12:13 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Delay " ) . " </td> " ;
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " ;
2008-07-14 23:50:10 +02:00
$form .= " <input name= \" delay \" type= \" text \" id= \" delay \" size= \" 5 \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetDelay () . " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " ms<br /> <span class= \" vexpl \" > " . gettext ( " Hint: in most cases, you "
. " should specify 0 here (or leave the field empty) " ) . " </span><br /> " ;
2013-04-03 18:08:59 +02:00
$form .= " </td></tr> " ;
2014-02-24 13:10:11 +01:00
$form .= " <tr style= \" display:none \" id= \" sprtable1 \" > " ;
2013-03-23 22:12:13 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Packet loss rate " ) . " </td> " ;
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " ;
2008-07-14 23:50:10 +02:00
$form .= " <input name= \" plr \" type= \" text \" id= \" plr \" size= \" 5 \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetPlr () . " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> <span class= \" vexpl \" > " . gettext ( " Hint: in most cases, you "
2014-02-24 13:10:11 +01:00
. " should specify 0 here (or leave the field empty). "
2010-08-18 15:36:29 +02:00
. " A value of 0.001 means one packet in 1000 gets dropped " ) . " </span> " ;
2008-07-14 23:50:10 +02:00
$form .= " </td></tr> " ;
2013-04-03 18:08:59 +02:00
$form .= " <tr style= \" display:none \" id= \" sprtable2 \" > " ;
2013-03-23 22:12:13 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Queue Size " ) . " </td> " ;
2008-07-14 23:50:10 +02:00
$form .= " <td class= \" vncellreq \" > " ;
$form .= " <input type= \" text \" id= \" qlimit \" name= \" qlimit \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetQlimit () . " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " slots<br /> " ;
2010-08-18 15:36:29 +02:00
$form .= " <span class= \" vexpl \" > " . gettext ( " Hint: in most cases, you "
. " should leave the field empty. All packets in this pipe are placed into a fixed-size queue first, "
2014-02-24 13:10:11 +01:00
. " then they are delayed by value specified in the Delay field, and then they "
2010-08-18 15:36:29 +02:00
. " are delivered to their destination. " ) . " </span> " ;
2008-07-17 00:40:56 +02:00
$form .= " </td></tr> " ;
2013-04-03 18:08:59 +02:00
$form .= " <tr style= \" display:none \" id= \" sprtable5 \" > " ;
2014-02-24 13:10:11 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Bucket Size " ) . " </td> " ;
$form .= " <td class= \" vncellreq \" > " ;
$form .= " <input type= \" text \" id= \" buckets \" name= \" buckets \" value= \" " ;
$form .= $this -> GetBuckets () . " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " slots<br /> " ;
2014-02-24 13:10:11 +01:00
$form .= " <span class= \" vexpl \" > " . gettext ( " Hint: in most cases, you "
. " should leave the field empty. It increases the hash size set. " );
$form .= " </span></td></tr> " ;
2008-07-14 23:50:10 +02:00
return $form ;
2013-03-29 20:25:14 +01:00
2008-07-14 23:50:10 +02:00
}
2008-07-16 21:34:17 +02:00
function wconfig () {
$cflink =& get_dn_reference_to_me_in_config ( $this -> GetLink ());
2014-02-24 13:10:11 +01:00
if ( ! is_array ( $cflink ))
$cflink = array ();
2008-07-16 21:34:17 +02:00
$cflink [ 'name' ] = $this -> GetQname ();
$cflink [ 'number' ] = $this -> GetNumber ();
2014-02-24 13:10:11 +01:00
$cflink [ 'qlimit' ] = $this -> GetQlimit ();
$cflink [ 'plr' ] = $this -> GetPlr ();
$cflink [ 'description' ] = $this -> GetDescription ();
2012-10-09 19:44:49 +02:00
$bandwidth = $this -> GetBandwidth ();
if ( is_array ( $bandwidth )) {
$cflink [ 'bandwidth' ] = array ();
$cflink [ 'bandwidth' ][ 'item' ] = array ();
foreach ( $bandwidth as $bwidx => $bw )
$cflink [ 'bandwidth' ][ 'item' ][] = $bw ;
}
2008-07-16 21:34:17 +02:00
$cflink [ 'enabled' ] = $this -> GetEnabled ();
$cflink [ 'buckets' ] = $this -> GetBuckets ();
2013-05-11 07:26:10 +02:00
$mask = $this -> GetMask ();
$cflink [ 'mask' ] = $mask [ 'type' ];
$cflink [ 'maskbits' ] = $mask [ 'bits' ];
2014-02-24 13:10:11 +01:00
$cflink [ 'maskbitsv6' ] = $mask [ 'bitsv6' ];
2008-07-16 21:34:17 +02:00
$cflink [ 'delay' ] = $this -> GetDelay ();
}
2008-07-14 23:50:10 +02:00
}
class dnqueue_class extends dummynet_class {
2014-02-24 13:10:11 +01:00
var $pipeparent ;
var $weight ;
function GetWeight () {
return $this -> weight ;
}
function SetWeight ( $weight ) {
$this -> weight = $weight ;
}
2008-07-16 21:34:17 +02:00
function GetPipe () {
return $this -> pipeparent ;
}
function SetPipe ( $pipe ) {
$this -> pipeparent = $pipe ;
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
/* Just a stub in case we ever try to call this from the frontend. */
function & add_queue ( $interface , & $queue , & $path , & $input_errors ) { return ; }
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function delete_queue () {
cleanup_dnqueue_from_rules ( $this -> GetQname ());
unset_dn_object_by_reference ( $this -> GetLink ());
2014-04-28 14:36:36 +02:00
@ pfSense_pipe_action ( " queue delete " . $this -> GetNumber ());
2014-02-24 13:10:11 +01:00
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function validate_input ( $data , & $input_errors ) {
parent :: validate_input ( $data , $input_errors );
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
if ( $data [ 'weight' ] && (( ! is_numeric ( $data [ 'weight' ])) ||
2014-02-24 13:10:11 +01:00
( $data [ 'weight' ] < 1 && $data [ 'weight' ] > 100 )))
$input_errors [] = gettext ( " Weight must be an integer between 1 and 100. " );
2008-07-16 21:34:17 +02:00
}
2008-07-14 23:50:10 +02:00
2014-02-24 13:10:11 +01:00
/*
* Should search even its children
*/
function & find_queue ( $pipe , $qname ) {
if ( $qname == $this -> GetQname ())
return $this ;
2008-07-16 21:34:17 +02:00
else
return NULL ;
2014-02-24 13:10:11 +01:00
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function & find_parentqueue ( $pipe , $qname ) {
return $this -> qparent ;
2014-02-24 13:10:11 +01:00
}
2008-07-14 23:50:10 +02:00
2014-02-24 13:10:11 +01:00
function & get_queue_list ( & $qlist ) {
2010-10-25 20:06:05 +02:00
if ( $this -> GetEnabled () == " " )
return ;
2014-02-24 13:10:11 +01:00
$qlist [ $this -> GetQname ()] = " ? " . $this -> GetNumber ();
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function ReadConfig ( & $q ) {
2011-02-09 22:40:00 +01:00
if ( ! empty ( $q [ 'name' ]) && ! empty ( $q [ 'newname' ]) && $q [ 'name' ] != $q [ 'newname' ]) {
$this -> SetQname ( $q [ 'newname' ]);
} else if ( ! empty ( $q [ 'newname' ])) {
$this -> SetQname ( $q [ 'newname' ]);
} else {
$this -> SetQname ( $q [ 'name' ]);
}
2008-07-16 21:34:17 +02:00
$this -> SetNumber ( $q [ 'number' ]);
if ( isset ( $q [ 'qlimit' ]) && $q [ 'qlimit' ] <> " " )
2014-02-24 13:10:11 +01:00
$this -> SetQlimit ( $q [ 'qlimit' ]);
2011-01-19 22:23:27 +01:00
else
2014-02-24 13:10:11 +01:00
$this -> SetQlimit ( " " );
2008-07-16 21:34:17 +02:00
if ( isset ( $q [ 'mask' ]) && $q [ 'mask' ] <> " " )
2013-05-11 07:26:10 +02:00
$masktype = $q [ 'mask' ];
2011-01-19 22:23:27 +01:00
else
2013-05-11 07:26:10 +02:00
$masktype = " " ;
if ( isset ( $q [ 'maskbits' ]) && $q [ 'maskbits' ] <> " " )
$maskbits = $q [ 'maskbits' ];
else
$maskbits = " " ;
2013-05-22 00:53:48 +02:00
if ( isset ( $q [ 'maskbitsv6' ]) && $q [ 'maskbitsv6' ] <> " " )
$maskbitsv6 = $q [ 'maskbitsv6' ];
else
$maskbitsv6 = " " ;
$this -> SetMask ( array ( " type " => $masktype , " bits " => $maskbits , " bitsv6 " => $maskbitsv6 ));
2013-10-21 14:59:02 +02:00
if ( isset ( $q [ 'buckets' ]) && $q [ 'buckets' ] <> " " )
$this -> SetBuckets ( $q [ 'buckets' ]);
else
$this -> SetBuckets ( " " );
if ( isset ( $q [ 'plr' ]) && $q [ 'plr' ] <> " " )
$this -> SetPlr ( $q [ 'plr' ]);
else
$this -> SetPlr ( " " );
2014-02-24 13:10:11 +01:00
if ( isset ( $q [ 'weight' ]) && $q [ 'weight' ] <> " " )
$this -> SetWeight ( $q [ 'weight' ]);
2011-01-19 22:23:27 +01:00
else
2014-02-24 13:10:11 +01:00
$this -> SetWeight ( " " );
if ( isset ( $q [ 'description' ]) && $q [ 'description' ] <> " " )
2008-07-16 21:34:17 +02:00
$this -> SetDescription ( $q [ 'description' ]);
2011-01-19 22:23:27 +01:00
else
$this -> SetDescription ( " " );
2008-07-16 21:34:17 +02:00
$this -> SetEnabled ( $q [ 'enabled' ]);
2014-02-24 13:10:11 +01:00
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function build_tree () {
$parent =& $this -> GetParent ();
2014-02-24 13:10:11 +01:00
$tree = " <li><a href= \" firewall_shaper_vinterface.php?pipe= " . $parent -> GetQname () . " &queue= " . $this -> GetQname () . " &action=show \" > " ;
2008-07-16 21:34:17 +02:00
$tree .= $this -> GetQname () . " </a> " ;
$tree .= " </li> " ;
2013-03-29 20:25:14 +01:00
2008-07-16 21:34:17 +02:00
return $tree ;
}
2008-07-14 23:50:10 +02:00
2014-02-24 13:10:11 +01:00
function build_rules () {
2008-07-18 18:46:43 +02:00
if ( $this -> GetEnabled () == " " )
2014-02-24 13:10:11 +01:00
return ;
2008-07-18 18:46:43 +02:00
2008-07-16 21:34:17 +02:00
$parent =& $this -> GetParent ();
2014-02-24 13:10:11 +01:00
$pfq_rule = " queue " . $this -> GetNumber () . " config pipe " . $parent -> GetNumber ();
2008-07-16 21:34:17 +02:00
if ( $this -> GetQlimit ())
2014-02-24 13:10:11 +01:00
$pfq_rule .= " queue " . $this -> GetQlimit ();
2008-07-16 21:34:17 +02:00
if ( $this -> GetWeight ())
$pfq_rule .= " weight " . $this -> GetWeight ();
if ( $this -> GetBuckets ())
$pfq_rule .= " buckets " . $this -> GetBuckets ();
2013-05-22 00:53:48 +02:00
$this -> build_mask_rules ( $pfq_rule );
2012-12-18 00:59:28 +01:00
$pfq_rule .= " \n " ;
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
return $pfq_rule ;
}
2014-02-24 13:10:11 +01:00
function build_javascript () {
2013-05-14 04:42:41 +02:00
return parent :: build_javascript ();
}
2014-02-24 13:10:11 +01:00
function build_form () {
2014-03-14 21:24:03 +01:00
$form = " <tr><td valign= \" middle \" class= \" vncellreq \" ><br /> " ;
2014-02-24 13:10:11 +01:00
$form .= gettext ( " Enable/Disable " );
$form .= " </td><td class= \" vncellreq \" > " ;
$form .= " <input type= \" checkbox \" id= \" enabled \" name= \" enabled \" value= \" on \" " ;
if ( $this -> GetEnabled () == " on " )
$form .= " checked= \" checked \" " ;
$form .= " /><span class= \" vexpl \" > " . gettext ( " Enable/Disable queue " ) . " </span> " ;
$form .= " </td></tr> " ;
2014-03-14 21:24:03 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" ><br /><span class= \" vexpl \" > " . gettext ( " Name " ) . " </span></td> " ;
2008-07-14 23:50:10 +02:00
$form .= " <td class= \" vncellreq \" > " ;
2011-02-09 22:40:00 +01:00
$form .= " <input type= \" text \" id= \" newname \" name= \" newname \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetQname () . " \" /> " ;
2011-02-09 22:40:00 +01:00
$form .= " <input type= \" hidden \" id= \" name \" name= \" name \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetQname () . " \" /> " ;
2012-06-01 21:51:18 +02:00
if ( $this -> GetNumber () > 0 ) {
$form .= " <input type= \" hidden \" id= \" number \" name= \" number \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetNumber () . " \" /> " ;
2012-06-01 21:51:18 +02:00
}
2008-07-14 23:50:10 +02:00
$form .= " </td></tr> " ;
2013-03-23 22:12:13 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Mask " ) . " </td> " ;
2008-07-14 23:50:10 +02:00
$form .= " <td class= \" vncellreq \" > " ;
2013-05-14 04:42:41 +02:00
$form .= " <select name= \" mask \" id= \" mask \" class= \" formselect \" onchange= \" enable_maskbits(); \" > " ;
2008-07-14 23:50:10 +02:00
$form .= " <option value= \" none \" " ;
2013-05-11 07:26:10 +02:00
$mask = $this -> GetMask ();
if ( $mask [ 'type' ] == " none " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-18 15:36:29 +02:00
$form .= " > " . gettext ( " none " ) . " </option> " ;
2008-07-16 21:34:17 +02:00
$form .= " <option value= \" srcaddress \" " ;
2013-05-11 07:26:10 +02:00
if ( $mask [ 'type' ] == " srcaddress " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-18 15:36:29 +02:00
$form .= " > " . gettext ( " Source addresses " ) . " </option> " ;
2008-07-16 21:34:17 +02:00
$form .= " <option value= \" dstaddress \" " ;
2013-05-11 07:26:10 +02:00
if ( $mask [ 'type' ] == " dstaddress " )
2013-03-29 20:25:14 +01:00
$form .= " selected= \" selected \" " ;
2010-08-18 15:36:29 +02:00
$form .= " > " . gettext ( " Destination addresses " ) . " </option> " ;
2008-07-14 23:50:10 +02:00
$form .= " </select> " ;
2014-03-14 21:24:03 +01:00
$form .= " slots<br /> " ;
2013-05-11 07:26:10 +02:00
$form .= " <span class= \" vexpl \" > " . gettext ( " If 'source' or 'destination' slots is chosen, \n "
2014-02-24 13:10:11 +01:00
. " a dynamic pipe with the bandwidth, delay, packet loss and queue size given above will \n "
. " be created for each source/destination IP address encountered, \n "
. " respectively. This makes it possible to easily specify bandwidth \n "
2014-03-14 21:24:03 +01:00
. " limits per host. " ) . " </span><br /> " ;
2013-05-11 07:26:10 +02:00
$form .= " 255.255.255.255/ <input type= \" text \" class= \" formfld unknown \" size= \" 2 \" id= \" maskbits \" name= \" maskbits \" value= \" " ;
2013-05-14 04:42:41 +02:00
if ( $mask [ 'type' ] <> " none " )
2014-02-24 13:10:11 +01:00
$form .= $mask [ 'bits' ];
2013-05-14 04:42:41 +02:00
$form .= " \" " ;
if ( $mask [ 'type' ] == " none " )
$form .= " disabled " ;
$form .= " /> " ;
2014-03-14 21:24:03 +01:00
$form .= " IPV4 mask bits (1-32)<br /> " ;
2013-05-28 22:34:39 +02:00
$form .= " ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/ <input type= \" text \" class= \" formfld unknown \" size= \" 2 \" id= \" maskbitsv6 \" name= \" maskbitsv6 \" value= \" " ;
if ( $mask [ 'type' ] <> " none " )
2014-02-24 13:10:11 +01:00
$form .= $mask [ 'bitsv6' ];
2013-05-28 22:34:39 +02:00
$form .= " \" " ;
if ( $mask [ 'type' ] == " none " )
$form .= " disabled " ;
$form .= " /> " ;
2014-03-14 21:24:03 +01:00
$form .= " IPV6 mask bits (1-128)<br /> " ;
2013-05-11 07:26:10 +02:00
$form .= " <span class= \" vexpl \" > " . gettext ( " If 'source' or 'destination' slots is chosen, \n "
2014-02-24 13:10:11 +01:00
. " leaving the mask bits blank will create one pipe per host. Otherwise specify \n "
. " the number of 'one' bits in the subnet mask used to group multiple hosts \n "
. " per queue. " ) . " </span> " ;
2008-07-14 23:50:10 +02:00
$form .= " </td></tr> " ;
2013-04-03 18:08:59 +02:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Description " ) . " </td> " ;
2008-07-14 23:50:10 +02:00
$form .= " <td class= \" vncellreq \" > " ;
2013-04-03 18:08:59 +02:00
$form .= " <input type= \" text \" id= \" description \" class= \" formfld unknown \" size= \" 40 \" name= \" description \" value= \" " ;
2008-07-14 23:50:10 +02:00
$form .= $this -> GetDescription ();
2013-03-25 22:46:22 +01:00
$form .= " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> <span class= \" vexpl \" > " ;
2010-08-18 15:36:29 +02:00
$form .= gettext ( " You may enter a description here for your reference (not parsed). " ) . " </span> " ;
2008-07-14 23:50:10 +02:00
$form .= " </td></tr> " ;
2013-04-03 18:08:59 +02:00
$form .= " <tr id= \" sprtable4 \" > " ;
2008-07-17 00:57:22 +02:00
$form .= " <td></td> " ;
2014-02-24 13:10:11 +01:00
$form .= " <td><div id= \" showadvancedboxspr \" > " ;
$form .= " <p><input type= \" button \" onclick= \" show_source_port_range() \" " ;
2013-03-25 22:46:22 +01:00
$form .= " value= \" " . gettext ( " Show advanced options " ) . " \" /> " ;
2014-02-24 13:10:11 +01:00
$form .= " </p></div></td></tr> " ;
2013-04-03 18:08:59 +02:00
$form .= " <tr style= \" display:none \" id= \" sprtable \" > " ;
2013-03-23 22:12:13 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Weight " ) . " </td> " ;
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " ;
2008-07-17 00:57:22 +02:00
$form .= " <input name= \" weight \" type= \" text \" id= \" weight \" size= \" 5 \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetWeight () . " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> <span class= \" vexpl \" > " . gettext ( " Hint: For queues under the same parent "
2014-02-24 13:10:11 +01:00
. " this specifies the share that a queue gets(values range from 1 to 100, you can leave it blank otherwise) " ) . " </span> " ;
2008-07-17 00:57:22 +02:00
$form .= " </td></tr> " ;
2013-04-03 18:08:59 +02:00
$form .= " <tr style= \" display:none \" id= \" sprtable1 \" > " ;
2013-03-23 22:12:13 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Packet loss rate " ) . " </td> " ;
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " ;
2008-07-17 00:57:22 +02:00
$form .= " <input name= \" plr \" type= \" text \" id= \" plr \" size= \" 5 \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetPlr () . " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> <span class= \" vexpl \" > " . gettext ( " Hint: in most cases, you "
2014-02-24 13:10:11 +01:00
. " should specify 0 here (or leave the field empty). "
. " A value of 0.001 means one packet in 1000 gets dropped " ) . " </span> " ;
2008-07-17 00:57:22 +02:00
$form .= " </td></tr> " ;
2013-04-03 18:08:59 +02:00
$form .= " <tr style= \" display:none \" id= \" sprtable2 \" > " ;
2013-03-23 22:12:13 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Queue Size " ) . " </td> " ;
2008-07-17 00:57:22 +02:00
$form .= " <td class= \" vncellreq \" > " ;
$form .= " <input type= \" text \" id= \" qlimit \" name= \" qlimit \" value= \" " ;
2013-03-25 22:46:22 +01:00
$form .= $this -> GetQlimit () . " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " slots<br /> " ;
2010-08-18 15:36:29 +02:00
$form .= " <span class= \" vexpl \" > " . gettext ( " Hint: in most cases, you "
2014-02-24 13:10:11 +01:00
. " should leave the field empty. All packets in this pipe are placed into a fixed-size queue first, "
. " then they are delayed by value specified in the Delay field, and then they "
. " are delivered to their destination. " ) . " </span> " ;
2008-07-17 00:57:22 +02:00
$form .= " </td></tr> " ;
2013-04-03 18:08:59 +02:00
$form .= " <tr style= \" display:none \" id= \" sprtable5 \" > " ;
2014-02-24 13:10:11 +01:00
$form .= " <td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Bucket Size " ) . " </td> " ;
$form .= " <td class= \" vncellreq \" > " ;
$form .= " <input type= \" text \" id= \" buckets \" name= \" buckets \" value= \" " ;
$form .= $this -> GetBuckets () . " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " " . gettext ( " slots " ) . " <br /> " ;
2014-02-24 13:10:11 +01:00
$form .= " <span class= \" vexpl \" > " . gettext ( " Hint: in most cases, you "
. " should leave the field empty. It increases the hash size set. " );
$form .= " </span></td></tr> " ;
2008-07-17 18:24:14 +02:00
2008-07-14 23:50:10 +02:00
$form .= " <input type= \" hidden \" id= \" pipe \" name= \" pipe \" " ;
2013-03-25 22:46:22 +01:00
$form .= " value= \" " . $this -> GetPipe () . " \" /> " ;
2008-07-14 23:50:10 +02:00
return $form ;
2013-03-29 20:25:14 +01:00
2008-07-16 21:34:17 +02:00
}
2008-07-14 23:50:10 +02:00
2014-02-24 13:10:11 +01:00
function update_dn_data ( & $data ) {
2008-07-16 21:34:17 +02:00
$this -> ReadConfig ( $data );
}
2008-07-14 23:50:10 +02:00
2008-07-16 21:34:17 +02:00
function wconfig () {
$cflink =& get_dn_reference_to_me_in_config ( $this -> GetLink ());
2014-02-24 13:10:11 +01:00
if ( ! is_array ( $cflink ))
$cflink = array ();
2008-07-16 21:34:17 +02:00
$cflink [ 'name' ] = $this -> GetQname ();
$cflink [ 'number' ] = $this -> GetNumber ();
2014-02-24 13:10:11 +01:00
$cflink [ 'qlimit' ] = $this -> GetQlimit ();
$cflink [ 'description' ] = $this -> GetDescription ();
2008-07-16 21:34:17 +02:00
$cflink [ 'weight' ] = $this -> GetWeight ();
$cflink [ 'enabled' ] = $this -> GetEnabled ();
$cflink [ 'buckets' ] = $this -> GetBuckets ();
2013-05-11 07:26:10 +02:00
$mask = $this -> GetMask ();
$cflink [ 'mask' ] = $mask [ 'type' ];
$cflink [ 'maskbits' ] = $mask [ 'bits' ];
2014-02-24 13:10:11 +01:00
$cflink [ 'maskbitsv6' ] = $mask [ 'bitsv6' ];
2008-07-16 21:34:17 +02:00
}
2008-07-14 23:50:10 +02:00
}
2008-12-21 00:57:09 +01:00
// List of layer7 objects
$layer7_rules_list = array ();
class layer7 {
2013-03-29 20:25:14 +01:00
2014-02-24 13:10:11 +01:00
var $rname ; //alias
var $rdescription ; //alias description
var $rport ; //divert port
var $renabled ; //rule enabled
var $rsets = array (); //array of l7 associations
2013-03-29 20:25:14 +01:00
2014-02-24 13:10:11 +01:00
// Auxiliary functions
2013-03-29 20:25:14 +01:00
2014-02-24 13:10:11 +01:00
function GetRName () {
return $this -> rname ;
}
function SetRName ( $rname ) {
$this -> rname = $rname ;
}
function GetRDescription () {
return $this -> rdescription ;
}
function SetRDescription ( $rdescription ) {
$this -> rdescription = $rdescription ;
}
function GetRPort () {
return $this -> rport ;
}
function SetRPort ( $rport ) {
$this -> rport = $rport ;
}
function GetREnabled () {
return $this -> renabled ;
}
function SetREnabled ( $value ) {
$this -> renabled = $value ;
}
function GetRl7 () {
return $this -> rsets ;
}
function SetRl7 ( $rsets ) {
$this -> rsets = $rsets ;
}
//Add a tuple (rule,sctructure,element) to the $rsets
function add_rule ( $l7set ) {
$this -> rsets [] = $l7set ;
}
// Build the layer7 rules
function build_l7_rules () {
if ( $this -> GetREnabled () == " " ) {
return ;
}
//$l7rules = "#" . $this->rdescription . "\n";
foreach ( $this -> rsets as $rl7 ) {
$l7rules .= $rl7 -> build_rules ();
}
return $l7rules ;
}
// Read the config from array
function ReadConfig ( & $qname , & $q ) {
$this -> SetRName ( $qname );
$this -> SetREnabled ( $q [ 'enabled' ]);
$this -> SetRPort ( $q [ 'divert_port' ]);
if ( isset ( $q [ 'description' ]) && $q [ 'description' ] <> " " )
$this -> SetRDescription ( $q [ 'description' ]);
$rsets = $q [ 'l7rules' ];
//Put individual rules in the array
if ( is_array ( $rsets )) {
$this -> rsets = array (); // XXX: ugly hack
foreach ( $rsets as $l7r ) {
$l7obj = new l7rule ();
$l7obj -> SetRProtocol ( $l7r [ 'protocol' ]);
$l7obj -> SetRStructure ( $l7r [ 'structure' ]);
$l7obj -> SetRBehaviour ( $l7r [ 'behaviour' ]);
$this -> add_rule ( $l7obj );
}
}
}
//Generate a random port for the divert socket
function gen_divert_port () {
$dports = get_divert_ports (); //array of used ports
$divert_port = 1 ; // Initialize
while (( $divert_port % 2 ) != 0 || in_array ( $divert_port , $dports )) {
$divert_port = rand ( 40000 , 60000 );
}
return $divert_port ;
}
//Helps building the left tree
function build_tree () {
$tree = " <li><a href= \" firewall_shaper_layer7.php?container= " . $this -> GetRName () . " &action=show \" > " ;
$tree .= $this -> GetRName () . " </a> " ;
$tree .= " </li> " ;
return $tree ;
}
function build_form () {
2014-03-14 21:24:03 +01:00
$form = " <tr><td valign= \" middle \" class= \" vncellreq \" ><br /> " ;
2014-02-24 13:10:11 +01:00
$form .= gettext ( " Enable/Disable " );
$form .= " </td><td class= \" vncellreq \" > " ;
$form .= " <input type= \" checkbox \" id= \" enabled \" name= \" enabled \" value= \" on \" " ;
if ( $this -> GetREnabled () == " on " ) {
$form .= " checked= \" checked \" " ;
}
$form .= " /><span class= \" vexpl \" > " . gettext ( " Enable/Disable layer7 Container " ) . " </span> " ;
$form .= " </td></tr> " ;
2014-03-14 21:24:03 +01:00
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" ><br /><span class= \" vexpl \" > " . gettext ( " Name " ) . " </span></td> " ;
2014-02-24 13:10:11 +01:00
$form .= " <td class= \" vncellreq \" > " ;
$form .= " <input type= \" text \" id= \" container \" name= \" container \" value= \" " ;
$form .= $this -> GetRName () . " \" /> " ;
$form .= " </td></tr> " ;
$form .= " <tr><td valign= \" middle \" class= \" vncellreq \" > " . gettext ( " Description " ) . " </td> " ;
$form .= " <td class= \" vncellreq \" > " ;
$form .= " <input type= \" text \" class= \" formfld unknown \" size= \" 40 \" id= \" description \" name= \" description \" value= \" " ;
$form .= $this -> GetRDescription ();
$form .= " \" /> " ;
2014-03-14 21:24:03 +01:00
$form .= " <br /> <span class= \" vexpl \" > " ;
2014-02-24 13:10:11 +01:00
$form .= gettext ( " You may enter a description here for your reference (not parsed). " ) . " </span> " ;
$form .= " </td></tr> " ;
return $form ;
}
//Write the setting to the $config array
function wconfig () {
global $config ;
if ( ! is_array ( $config [ 'l7shaper' ][ 'container' ])) {
$config [ 'l7shaper' ][ 'container' ] = array ();
}
//
$cflink =& get_l7c_reference_to_me_in_config ( $this -> GetRName ());
// Test if this rule does exists already
if ( ! $cflink ) {
$cflink =& $config [ 'l7shaper' ][ 'container' ][];
}
$cflink [ 'name' ] = $this -> GetRName ();
$cflink [ 'enabled' ] = $this -> GetREnabled ();
$cflink [ 'description' ] = $this -> GetRDescription ();
$cflink [ 'divert_port' ] = $this -> GetRPort ();
//Destroy previously existent rules
if ( is_array ( $cflink [ 'rules' ])) {
unset ( $cflink [ 'l7rules' ]);
}
$cflink [ 'l7rules' ] = array ();
$i = 0 ;
foreach ( $this -> rsets as $rulel7 ) {
$cflink [ 'l7rules' ][ $i ][ 'protocol' ] = $rulel7 -> GetRProtocol ();
$cflink [ 'l7rules' ][ $i ][ 'structure' ] = $rulel7 -> GetRStructure ();
$cflink [ 'l7rules' ][ $i ][ 'behaviour' ] = $rulel7 -> GetRBehaviour ();
$i ++ ;
}
}
//This function is necessary to help producing the overload options for keep state
function get_unique_structures () {
$unique_structures = array ( " action " => false , " dummynet " => false , " altq " => false );
foreach ( $this -> rsets as $l7rule ) {
if ( $l7rule -> GetRStructure () == " action " )
$unique_structures [ 'action' ] = true ;
else if ( $l7rule -> GetRStructure () == " limiter " )
$unique_structures [ 'dummynet' ] = true ;
else
$unique_structures [ 'altq' ] = true ;
}
//Delete non used structures so we don't have to check this in filter.inc
foreach ( $unique_structures as $key => $value )
if ( ! $value )
unset ( $unique_structures [ $key ]);
return $unique_structures ;
}
function validate_input ( $data , & $input_errors ) {
$reqdfields [] = " container " ;
$reqdfieldsn [] = gettext ( " Name " );
shaper_do_input_validation ( $data , $reqdfields , $reqdfieldsn , $input_errors );
if ( ! preg_match ( " /^[a-zA-Z0-9_-]+ $ / " , $data [ 'container' ]))
$input_errors [] = gettext ( " Queue names must be alphanumeric and _ or - only. " );
}
function delete_l7c () {
mwexec ( " /bin/pkill -f 'ipfw-classifyd .* -p " . $this -> GetRPort () . " ' " , true );
unset_l7_object_by_reference ( $this -> GetRName ());
cleanup_l7_from_rules ( $this -> GetRName ());
}
2008-12-21 00:57:09 +01:00
}
class l7rule {
2014-02-24 13:10:11 +01:00
var $rprotocol ; //protocol
var $rstructure ; //action, limiter, queue
var $rbehaviour ; //allow, block, queue_name, pipe_number ...
//Auxiliary Functions
function GetRProtocol () {
return $this -> rprotocol ;
}
function SetRProtocol ( $rprotocol ) {
$this -> rprotocol = $rprotocol ;
}
function GetRStructure () {
return $this -> rstructure ;
}
function SetRStructure ( $rstructure ) {
$this -> rstructure = $rstructure ;
}
function GetRBehaviour () {
return $this -> rbehaviour ;
}
function SetRBehaviour ( $rbehaviour ) {
$this -> rbehaviour = $rbehaviour ;
}
//XXX Do we need to test any particularity for AltQ queues?
function build_rules () {
global $dummynet_pipe_list ;
switch ( $this -> GetRStructure ()) {
2008-12-21 00:57:09 +01:00
case " limiter " :
read_dummynet_config ();
$dn_list =& get_unique_dnqueue_list ();
$found = false ;
if ( is_array ( $dn_list )) {
foreach ( $dn_list as $key => $value ) {
if ( $key == $this -> GetRBehaviour ()) {
if ( $value [ 0 ] == " ? " )
$l7rule = $this -> GetRProtocol () . " = dnqueue " . substr ( $value , 1 ) . " \n " ;
else
$l7rule = $this -> GetRProtocol () . " = dnpipe " . $value . " \n " ;
$found = true ;
}
if ( $found )
break ;
}
}
break ;
default : //This is for action and for altq
$l7rule = $this -> GetRProtocol () . " = " . $this -> GetRStructure () . " " . $this -> GetRBehaviour () . " \n " ;
break ;
2014-02-24 13:10:11 +01:00
}
return $l7rule ;
2008-12-21 00:57:09 +01:00
}
}
/*
* This function allows to return an array with all the used divert socket ports
*/
function get_divert_ports () {
2014-02-24 13:10:11 +01:00
global $layer7_rules_list ;
$dports = array ();
foreach ( $layer7_rules_list as $l7r )
$dports [] = $l7r -> GetRPort ();
return $dports ;
2008-12-21 00:57:09 +01:00
}
function & get_l7c_reference_to_me_in_config ( & $name ) {
global $config ;
2013-03-29 20:25:14 +01:00
2008-12-21 00:57:09 +01:00
$ptr = NULL ;
2013-03-29 20:25:14 +01:00
2008-12-21 00:57:09 +01:00
if ( is_array ( $config [ 'l7shaper' ][ 'container' ])) {
foreach ( $config [ 'l7shaper' ][ 'container' ] as $key => $value ) {
if ( $value [ 'name' ] == $name )
$ptr =& $config [ 'l7shaper' ][ 'container' ][ $key ];
}
2014-02-24 13:10:11 +01:00
}
2008-12-21 00:57:09 +01:00
return $ptr ;
2014-02-24 13:10:11 +01:00
// $ptr can be null. has to be checked later
2008-12-21 00:57:09 +01:00
}
function unset_l7_object_by_reference ( & $name ) {
global $config ;
2014-02-24 13:10:11 +01:00
2008-12-21 00:57:09 +01:00
if ( is_array ( $config [ 'l7shaper' ][ 'container' ])) {
foreach ( $config [ 'l7shaper' ][ 'container' ] as $key => $value ) {
if ( $value [ 'name' ] == $name ) {
unset ( $config [ 'l7shaper' ][ 'container' ][ $key ][ 'l7rules' ]);
unset ( $config [ 'l7shaper' ][ 'container' ][ $key ]);
break ;
}
}
}
}
function read_layer7_config () {
2014-02-24 13:10:11 +01:00
global $layer7_rules_list , $config ;
2014-04-14 15:48:39 +02:00
if ( ! is_array ( $config [ 'l7shaper' ][ 'container' ]) || ! count ( $config [ 'l7shaper' ][ 'container' ])) {
$layer7_rules_list = array ();
2014-02-24 15:12:30 +01:00
return ;
2014-04-14 15:48:39 +02:00
}
2014-02-24 15:12:30 +01:00
2014-02-24 13:10:11 +01:00
$l7cs = & $config [ 'l7shaper' ][ 'container' ];
$layer7_rules_list = array ();
foreach ( $l7cs as $conf ) {
if ( empty ( $conf [ 'name' ]))
continue ; /* XXX: grrrrrr at php */
$root =& new layer7 ();
$root -> ReadConfig ( $conf [ 'name' ], $conf );
$layer7_rules_list [ $root -> GetRName ()] = & $root ;
}
2008-12-21 00:57:09 +01:00
}
2014-02-24 16:24:52 +01:00
function update_layer7_custom_patterns () {
global $config ;
if ( ! is_array ( $config [ 'l7shaper' ][ 'custom_pat' ]))
return ;
foreach ( $config [ 'l7shaper' ][ 'custom_pat' ] as $filename => $filecontent )
if ( ! file_exists ( " /usr/local/share/protocols/ " . $filename ))
@ file_put_contents ( " /usr/local/share/protocols/ " . $filename , base64_decode ( $filecontent ));
}
2008-12-21 00:57:09 +01:00
function generate_layer7_files () {
2014-02-24 13:10:11 +01:00
global $layer7_rules_list , $g ;
read_layer7_config ();
if ( ! empty ( $layer7_rules_list )) {
if ( ! is_module_loaded ( " ipdivert.ko " ))
mwexec ( " /sbin/kldload ipdivert.ko " );
array_map ( 'unlink' , glob ( " { $g [ 'tmp_path' ] } /*.l7 " ));
}
2014-02-24 16:24:52 +01:00
update_layer7_custom_patterns ();
2014-02-24 13:10:11 +01:00
foreach ( $layer7_rules_list as $l7rules ) {
if ( $l7rules -> GetREnabled ()) {
$filename = $l7rules -> GetRName () . " .l7 " ;
$path = " { $g [ 'tmp_path' ] } / " . $filename ;
$rules = $l7rules -> build_l7_rules ();
$fp = fopen ( $path , 'w' );
fwrite ( $fp , $rules );
fclose ( $fp );
}
}
2009-02-14 07:24:51 +01:00
}
function layer7_start_l7daemon () {
2014-02-24 13:10:11 +01:00
global $layer7_rules_list , $g ;
/*
* XXX : ermal - Needed ? !
* read_layer7_config ();
*/
foreach ( $layer7_rules_list as $l7rules ) {
if ( $l7rules -> GetREnabled ()) {
$filename = $l7rules -> GetRName () . " .l7 " ;
$path = " { $g [ 'tmp_path' ] } / " . $filename ;
unset ( $l7pid );
/* Only reread the configuration rather than restart to avoid losing information. */
exec ( " /bin/pgrep -f 'ipfw-classifyd .* -p " . $l7rules -> GetRPort () . " ' " , $l7pid );
if ( count ( $l7pid ) > 0 ) {
log_error ( sprintf ( gettext ( " Sending HUP signal to %s " ), $l7pid [ 0 ]));
mwexec ( " /bin/kill -HUP { $l7pid [ 0 ] } " );
} else {
// XXX: Hardcoded number of packets to garbage collect and queue length..
$ipfw_classifyd_init = " /usr/local/sbin/ipfw-classifyd -n 8 -q 700 -c { $path } -p " . $l7rules -> GetRPort () . " -P /usr/local/share/protocols " ;
mwexec_bg ( $ipfw_classifyd_init );
}
}
}
2008-12-21 00:57:09 +01:00
}
// This function uses /usr/local/share/protocols as a default directory for searching .pat files
function generate_protocols_array () {
2014-02-24 16:24:52 +01:00
update_layer7_custom_patterns ();
2008-12-21 00:57:09 +01:00
$protocols = return_dir_as_array ( " /usr/local/share/protocols " );
2009-11-28 19:42:10 +01:00
$protocols_new = array ();
2008-12-21 00:57:09 +01:00
if ( is_array ( $protocols )) {
2009-11-25 17:33:46 +01:00
foreach ( $protocols as $key => $proto ) {
2009-11-28 03:24:15 +01:00
if ( strstr ( $proto , " .pat " ))
2009-11-28 19:42:10 +01:00
$protocols_new [ $key ] =& str_replace ( " .pat " , " " , $proto );
2009-11-25 17:33:46 +01:00
}
2009-11-28 19:42:10 +01:00
sort ( $protocols_new );
2014-02-24 13:10:11 +01:00
}
2009-11-28 19:42:10 +01:00
return $protocols_new ;
2008-12-21 00:57:09 +01:00
}
function get_l7_unique_list () {
global $layer7_rules_list ;
2013-03-29 20:25:14 +01:00
2008-12-21 00:57:09 +01:00
$l7list = array ();
2014-02-24 13:10:11 +01:00
if ( is_array ( $layer7_rules_list ))
2008-12-21 00:57:09 +01:00
foreach ( $layer7_rules_list as $l7c )
if ( $l7c -> GetREnabled ())
$l7list [] = $l7c -> GetRName ();
2013-03-29 20:25:14 +01:00
2008-12-21 00:57:09 +01:00
return $l7list ;
}
// Disable a removed l7 container from the filter
function cleanup_l7_from_rules ( & $name ) {
global $config ;
2008-12-21 23:45:23 +01:00
if ( is_array ( $config [ 'filter' ][ 'rule' ]))
foreach ( $config [ 'filter' ][ 'rule' ] as $key => $rule ) {
if ( $rule [ 'l7container' ] == $name )
unset ( $config [ 'filter' ][ 'rule' ][ $key ][ 'l7container' ]);
}
}
function get_dummynet_name_list () {
2013-03-29 20:25:14 +01:00
2008-12-21 23:45:23 +01:00
$dn_name_list =& get_unique_dnqueue_list ();
$dn_name = array ();
if ( is_array ( $dn_name_list ))
foreach ( $dn_name_list as $key => $value )
$dn_name [] = $key ;
2013-03-29 20:25:14 +01:00
2008-12-21 23:45:23 +01:00
return $dn_name ;
2013-03-29 20:25:14 +01:00
2008-12-21 23:45:23 +01:00
}
function get_altq_name_list () {
$altq_name_list =& get_unique_queue_list ();
$altq_name = array ();
if ( is_array ( $altq_name_list ))
foreach ( $altq_name_list as $key => $aqobj )
$altq_name [] = $key ;
2013-03-29 20:25:14 +01:00
2008-12-21 23:45:23 +01:00
return $altq_name ;
2008-12-21 00:57:09 +01:00
}
2008-07-14 23:50:10 +02:00
2008-01-11 22:07:25 +01:00
/*
* XXX : TODO Make a class shaper to hide all these function
* from the global namespace .
*/
2014-02-24 13:10:11 +01:00
/*
* This is a layer violation but for now there is no way
2008-01-11 22:07:25 +01:00
* i can find to properly do this with PHP .
*/
function altq_get_default_queue ( $interface ) {
global $altq_list_queues ;
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
$altq_tmp = $altq_list_queues [ $interface ];
2011-07-15 22:02:39 +02:00
if ( $altq_tmp )
2014-02-24 13:10:11 +01:00
return $altq_tmp -> GetDefaultQueuePresent ();
2011-07-15 22:02:39 +02:00
else
return false ;
2008-01-11 22:07:25 +01:00
}
2005-09-25 08:23:03 +02:00
2008-02-23 03:22:30 +01:00
function altq_check_default_queues () {
global $altq_list_queues ;
$count = 0 ;
if ( is_array ( $altq_list_queues )) {
foreach ( $altq_list_queues as $altq ) {
if ( $altq -> GetDefaultQueuePresent ())
$count ++ ;
}
}
2014-03-19 23:38:56 +01:00
else $count ++ ;
2013-03-29 20:25:14 +01:00
2008-02-23 03:22:30 +01:00
return 0 ;
}
function & get_unique_queue_list () {
global $altq_list_queues ;
2013-03-29 20:25:14 +01:00
2008-02-23 03:22:30 +01:00
$qlist = array ();
if ( is_array ( $altq_list_queues )) {
foreach ( $altq_list_queues as $altq ) {
2010-11-09 21:10:47 +01:00
if ( $altq -> GetEnabled () == " " )
2010-10-25 20:06:05 +02:00
continue ;
2008-02-23 03:22:30 +01:00
$tmplist =& $altq -> get_queue_list ();
2010-10-25 20:06:05 +02:00
foreach ( $tmplist as $qname => $link ) {
if ( $link -> GetEnabled () <> " " )
2014-02-24 13:10:11 +01:00
$qlist [ $qname ] = $link ;
2010-10-25 20:06:05 +02:00
}
2008-02-23 03:22:30 +01:00
}
}
return $qlist ;
}
2008-07-16 21:53:24 +02:00
function & get_unique_dnqueue_list () {
2008-07-14 23:50:10 +02:00
global $dummynet_pipe_list ;
2013-03-29 20:25:14 +01:00
2008-07-14 23:50:10 +02:00
$qlist = array ();
if ( is_array ( $dummynet_pipe_list )) {
foreach ( $dummynet_pipe_list as $dn ) {
2010-10-25 20:06:05 +02:00
if ( $dn -> GetEnabled () == " " )
continue ;
2008-07-14 23:50:10 +02:00
$tmplist =& $dn -> get_queue_list ();
2010-10-25 20:06:05 +02:00
foreach ( $tmplist as $qname => $link ) {
2014-02-24 13:10:11 +01:00
$qlist [ $qname ] = $link ;
2010-10-25 20:06:05 +02:00
}
2008-07-14 23:50:10 +02:00
}
}
return $qlist ;
}
2008-01-11 22:07:25 +01:00
function ref_on_altq_queue_list ( $parent , $qname ) {
if ( isset ( $GLOBALS [ 'queue_list' ][ $qname ]))
$GLOBALS [ 'queue_list' ][ $qname ] ++ ;
else
$GLOBALS [ 'queue_list' ][ $qname ] = 1 ;
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
unref_on_altq_queue_list ( $parent );
}
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
function unref_on_altq_queue_list ( $qname ) {
$GLOBALS [ 'queue_list' ][ $qname ] -- ;
if ( $GLOBALS [ 'queue_list' ][ $qname ] <= 1 )
2014-02-24 13:10:11 +01:00
unset ( $GLOBALS [ 'queue_list' ][ $qname ]);
2008-01-11 22:07:25 +01:00
}
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
function read_altq_config () {
global $altq_list_queues , $config ;
$path = array ();
2013-03-29 20:25:14 +01:00
2009-07-24 23:18:31 +02:00
if ( ! is_array ( $config [ 'shaper' ]))
$config [ 'shaper' ] = array ();
if ( ! is_array ( $config [ 'shaper' ][ 'queue' ]))
$config [ 'shaper' ][ 'queue' ] = array ();
2008-01-11 22:07:25 +01:00
$a_int = & $config [ 'shaper' ][ 'queue' ];
$altq_list_queues = array ();
2013-03-29 20:25:14 +01:00
2008-01-11 22:07:25 +01:00
if ( ! is_array ( $config [ 'shaper' ][ 'queue' ]))
return ;
foreach ( $a_int as $key => $conf ) {
2010-10-25 19:42:57 +02:00
$int = $conf [ 'interface' ];
$root =& new altq_root_queue ();
$root -> SetInterface ( $int );
$altq_list_queues [ $root -> GetInterface ()] = & $root ;
$root -> ReadConfig ( $conf );
2008-01-11 22:07:25 +01:00
array_push ( $path , $key );
$root -> SetLink ( $path );
if ( is_array ( $conf [ 'queue' ])) {
foreach ( $conf [ 'queue' ] as $key1 => $q ) {
array_push ( $path , $key1 );
2014-02-24 13:10:11 +01:00
/*
* XXX : we completely ignore errors here but anyway we must have
2008-01-16 23:52:27 +01:00
* checked them before so no harm should be come from this .
*/
2013-09-12 16:29:21 +02:00
$root -> add_queue ( $root -> GetInterface (), $q , $path , $input_errors );
2008-01-11 22:07:25 +01:00
array_pop ( $path );
2014-02-24 13:10:11 +01:00
}
2010-10-25 19:42:57 +02:00
}
2008-01-11 22:07:25 +01:00
array_pop ( $path );
}
}
2006-09-17 18:45:47 +02:00
2008-07-14 23:50:10 +02:00
function read_dummynet_config () {
global $dummynet_pipe_list , $config ;
$path = array ();
2008-07-16 21:34:17 +02:00
2009-07-26 23:12:49 +02:00
if ( ! is_array ( $config [ 'dnshaper' ]))
$config [ 'dnshaper' ] = array ();
if ( ! is_array ( $config [ 'dnshaper' ][ 'queue' ]))
$config [ 'dnshaper' ][ 'queue' ] = array ();
2008-07-14 23:50:10 +02:00
$a_int = & $config [ 'dnshaper' ][ 'queue' ];
2006-03-17 23:08:25 +01:00
2008-07-14 23:50:10 +02:00
$dummynet_pipe_list = array ();
2013-03-29 20:25:14 +01:00
2008-07-17 18:37:17 +02:00
if ( ! is_array ( $config [ 'dnshaper' ][ 'queue' ])
|| ! count ( $config [ 'dnshaper' ][ 'queue' ]))
2008-07-14 23:50:10 +02:00
return ;
foreach ( $a_int as $key => $conf ) {
2008-07-17 18:37:17 +02:00
if ( empty ( $conf [ 'name' ]))
2014-02-24 13:10:11 +01:00
continue ; /* XXX: grrrrrr at php */
2010-03-09 08:30:51 +01:00
$root =& new dnpipe_class ();
2008-07-16 21:34:17 +02:00
$root -> ReadConfig ( $conf );
$dummynet_pipe_list [ $root -> GetQname ()] = & $root ;
array_push ( $path , $key );
$root -> SetLink ( $path );
if ( is_array ( $conf [ 'queue' ])) {
foreach ( $conf [ 'queue' ] as $key1 => $q ) {
array_push ( $path , $key1 );
2014-02-24 13:10:11 +01:00
/*
* XXX : we completely ignore errors here but anyway we must have
2008-07-16 21:34:17 +02:00
* checked them before so no harm should be come from this .
2014-02-24 13:10:11 +01:00
*/
2013-09-12 16:29:21 +02:00
$root -> add_queue ( $root -> GetQname (), $q , $path , $input_errors );
2008-07-14 23:50:10 +02:00
array_pop ( $path );
2014-02-24 13:10:11 +01:00
}
2008-07-16 21:34:17 +02:00
}
array_pop ( $path );
2008-07-14 23:50:10 +02:00
}
}
2006-09-17 18:45:47 +02:00
2008-01-11 22:07:25 +01:00
function get_interface_list_to_show () {
global $altq_list_queues , $config ;
2008-11-16 18:49:21 +01:00
global $shaperIFlist ;
2008-01-11 22:07:25 +01:00
$tree = " " ;
2008-11-16 18:49:21 +01:00
foreach ( $shaperIFlist as $shif => $shDescr ) {
if ( $altq_list_queues [ $shif ]) {
2008-01-11 22:07:25 +01:00
continue ;
2008-03-27 18:08:16 +01:00
} else {
2008-11-16 18:49:21 +01:00
if ( ! is_altq_capable ( get_real_interface ( $shif )))
2008-03-30 11:21:54 +02:00
continue ;
2013-03-23 22:12:13 +01:00
$tree .= " <li><a href= \" firewall_shaper.php?interface= " . $shif . " &action=add \" > " . $shDescr . " </a></li> " ;
2008-01-11 22:07:25 +01:00
}
}
2013-03-29 20:25:14 +01:00
2008-01-11 22:07:25 +01:00
return $tree ;
}
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
function filter_generate_altq_queues () {
global $altq_list_queues ;
2013-03-29 20:25:14 +01:00
2008-01-11 22:07:25 +01:00
read_altq_config ();
2005-09-25 08:23:03 +02:00
2008-01-11 22:07:25 +01:00
$altq_rules = " " ;
2014-02-24 13:10:11 +01:00
foreach ( $altq_list_queues as $altq )
2008-01-11 22:07:25 +01:00
$altq_rules .= $altq -> build_rules ();
2006-03-10 23:52:26 +01:00
2008-01-11 22:07:25 +01:00
return $altq_rules ;
}
2006-03-10 23:52:26 +01:00
2012-06-01 21:51:18 +02:00
function dnqueue_find_nextnumber () {
global $dummynet_pipe_list ;
$dnused = array ();
if ( is_array ( $dummynet_pipe_list )) {
foreach ( $dummynet_pipe_list as $dn ) {
$tmplist =& $dn -> get_queue_list ();
foreach ( $tmplist as $qname => $link ) {
if ( $link [ 0 ] == " ? " )
$dnused [ $qname ] = substr ( $link , 1 );
}
}
}
sort ( $dnused , SORT_NUMERIC );
$dnnumber = 0 ;
$found = false ;
foreach ( $dnused as $dnnum ) {
if (( $dnnum - $dnnumber ) > 1 ) {
2014-11-13 13:09:41 +01:00
$dnnumber = $dnnum - 1 ;
2012-06-01 21:51:18 +02:00
$found = true ;
break ;
} else
$dnnumber = $dnnum ;
}
if ( $found == false )
$dnnumber ++ ;
unset ( $dnused , $dnnum , $found );
return $dnnumber ;
}
function dnpipe_find_nextnumber () {
global $dummynet_pipe_list ;
$dnused = array ();
foreach ( $dummynet_pipe_list as $dn )
$dnused [] = $dn -> GetNumber ();
sort ( $dnused , SORT_NUMERIC );
$dnnumber = 0 ;
$found = false ;
foreach ( $dnused as $dnnum ) {
if (( $dnnum - $dnnumber ) > 1 ) {
2014-11-13 13:09:41 +01:00
$dnnumber = $dnnum - 1 ;
2012-06-01 21:51:18 +02:00
$found = true ;
break ;
} else
$dnnumber = $dnnum ;
}
if ( $found == false )
$dnnumber ++ ;
unset ( $dnused , $dnnum , $found );
return $dnnumber ;
}
2008-07-16 21:34:17 +02:00
function filter_generate_dummynet_rules () {
2010-04-02 03:23:16 +02:00
global $g , $dummynet_pipe_list ;
2013-03-29 20:25:14 +01:00
2008-07-14 23:50:10 +02:00
read_dummynet_config ();
2013-03-29 20:25:14 +01:00
2008-07-14 23:50:10 +02:00
$dn_rules = " " ;
2014-02-24 13:10:11 +01:00
foreach ( $dummynet_pipe_list as $dn )
2008-07-14 23:50:10 +02:00
$dn_rules .= $dn -> build_rules ();
2010-04-22 13:54:57 +02:00
if ( ! empty ( $dn_rules )) {
2014-04-28 14:37:41 +02:00
if ( ! is_module_loaded ( " dummynet.ko " )) {
mwexec ( " /sbin/kldload dummynet " );
2014-07-08 01:06:37 +02:00
set_sysctl ( array (
" net.inet.ip.dummynet.io_fast " => " 1 " ,
" net.inet.ip.dummynet.hash_size " => " 256 "
));
2014-04-28 14:37:41 +02:00
}
2010-04-02 03:23:16 +02:00
file_put_contents ( " { $g [ 'tmp_path' ] } /rules.limiter " , $dn_rules );
mwexec ( " /sbin/ipfw { $g [ 'tmp_path' ] } /rules.limiter " );
}
2008-07-14 23:50:10 +02:00
}
2006-09-17 18:45:47 +02:00
2008-01-11 22:07:25 +01:00
function build_iface_without_this_queue ( $iface , $qname ) {
global $g , $altq_list_queues ;
2011-12-06 22:51:11 +01:00
global $shaperIFlist ;
2006-09-17 18:45:47 +02:00
2008-01-11 22:07:25 +01:00
$altq =& $altq_list_queues [ $iface ];
2011-03-31 22:26:58 +02:00
if ( $altq )
$scheduler = " : " . $altq -> GetScheduler ();
2008-01-11 22:07:25 +01:00
$form = " <tr><td width= \" 20% \" > " ;
2013-03-23 22:12:13 +01:00
$form .= " <a href= \" firewall_shaper.php?interface= " . $iface . " &queue= " . $iface . " &action=show \" > " . $shaperIFlist [ $iface ] . $scheduler . " </a> " ;
2010-08-18 15:36:29 +02:00
$form .= " </td></tr> " ;
$form .= " <tr><td width= \" 100% \" class= \" vncellreq \" > " ;
$form .= " <a href= \" firewall_shaper_queues.php?interface= " ;
2013-03-23 22:12:13 +01:00
$form .= $iface . " &queue= " . $qname . " &action=add \" > " ;
2010-08-18 15:36:29 +02:00
$form .= " <img src= \" " ;
$form .= " ./themes/ " . $g [ 'theme' ] . " /images/icons/icon_plus.gif \" " ;
2013-03-25 22:46:22 +01:00
$form .= " width= \" 17 \" height= \" 17 \" border= \" 0 \" title= \" Clone shaper/queue on this interface \" alt= \" clone \" /> " ;
2010-08-18 15:36:29 +02:00
$form .= gettext ( " Clone shaper/queue on this interface " ) . " </a></td></tr> " ;
2008-01-16 23:52:27 +01:00
2010-08-18 15:36:29 +02:00
return $form ;
2006-09-17 18:45:47 +02:00
2008-01-11 22:07:25 +01:00
}
2006-09-17 18:45:47 +02:00
2005-09-25 08:23:03 +02:00
2013-04-03 18:08:59 +02:00
$default_shaper_msg = " <tr><td align= \" center \" width= \" 80% \" > " ;
$default_shaper_msg .= " <span class= \" vexpl \" ><strong><b> " . sprintf ( gettext ( " Welcome to the %s Traffic Shaper. " ), $g [ 'product_name' ]) . " </b><br /> " ;
2010-08-18 15:36:29 +02:00
$default_shaper_msg .= gettext ( " The tree on the left helps you navigate through the queues <br /> "
2014-02-24 13:10:11 +01:00
. " buttons at the bottom represent queue actions and are activated accordingly. " );
2013-04-03 18:08:59 +02:00
$default_shaper_msg .= " </strong></span> " ;
2008-01-11 22:07:25 +01:00
$default_shaper_msg .= " </td></tr> " ;
2005-09-25 08:23:03 +02:00
2013-04-03 18:08:59 +02:00
$dn_default_shaper_msg = " <tr><td align= \" center \" width= \" 80% \" > " ;
$dn_default_shaper_msg .= " <span class= \" vexpl \" ><strong><b> " . sprintf ( gettext ( " Welcome to the %s Traffic Shaper. " ), $g [ 'product_name' ]) . " </b><br /> " ;
2010-08-18 15:36:29 +02:00
$dn_default_shaper_msg .= gettext ( " The tree on the left helps you navigate through the queues <br /> "
2014-02-24 13:10:11 +01:00
. " buttons at the bottom represent queue actions and are activated accordingly. " );
2013-04-03 18:08:59 +02:00
$dn_default_shaper_msg .= " </strong></span> " ;
2008-07-16 21:34:17 +02:00
$dn_default_shaper_msg .= " </td></tr> " ;
2009-12-28 10:41:47 +01:00
?>