summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2015-03-03 00:11:10 +0545
committerPhil Davis <phil.davis@inf.org>2015-03-03 00:11:10 +0545
commit61e047a50339da4a0b6a9202f163950573e8a578 (patch)
tree138a33434240f27f42e88483ed66cd1743cadf2a
parent8f5f40c9fca0bfb637589b4c86e53bfb80753c87 (diff)
downloadpfsense-61e047a50339da4a0b6a9202f163950573e8a578.zip
pfsense-61e047a50339da4a0b6a9202f163950573e8a578.tar.gz
Code style etc in r s
-rw-r--r--etc/inc/radius.inc136
-rw-r--r--etc/inc/rrd.inc112
-rw-r--r--etc/inc/sasl.inc4
-rw-r--r--etc/inc/service-utils.inc210
-rw-r--r--etc/inc/services.inc933
-rw-r--r--etc/inc/shaper.inc1734
-rw-r--r--etc/inc/smtp.inc2
-rw-r--r--etc/inc/system.inc754
8 files changed, 2343 insertions, 1542 deletions
diff --git a/etc/inc/radius.inc b/etc/inc/radius.inc
index bb8bf6c..709607f 100644
--- a/etc/inc/radius.inc
+++ b/etc/inc/radius.inc
@@ -6,30 +6,30 @@
Copyright (c) 2003, Michael Bretterklieber <michael@bretterklieber.com>
All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
+ 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
+ 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
+ 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.
- 3. The names of the authors may not be used to endorse or promote products
+ 3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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,
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- This code cannot simply be copied and put under the GNU Public License or
+ This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
This version of RADIUS.php has been modified by
@@ -73,7 +73,7 @@ PEAR::loadExtension('radius');
*
* Abstract base class for RADIUS
*
- * @package Auth_RADIUS
+ * @package Auth_RADIUS
*/
class Auth_RADIUS extends PEAR {
@@ -138,7 +138,7 @@ class Auth_RADIUS extends PEAR {
*
* @return void
*/
- function Auth_RADIUS()
+ function Auth_RADIUS()
{
$this->PEAR();
}
@@ -146,8 +146,8 @@ class Auth_RADIUS extends PEAR {
/**
* Adds a RADIUS server to the list of servers for requests.
*
- * At most 10 servers may be specified. When multiple servers
- * are given, they are tried in round-robin fashion until a
+ * At most 10 servers may be specified. When multiple servers
+ * are given, they are tried in round-robin fashion until a
* valid response is received
*
* @access public
@@ -158,7 +158,7 @@ class Auth_RADIUS extends PEAR {
* @param integer $maxtries Max. retries for each request
* @return void
*/
- function addServer($servername = 'localhost', $port = 0, $sharedSecret = 'testing123', $timeout = 3, $maxtries = 2)
+ function addServer($servername = 'localhost', $port = 0, $sharedSecret = 'testing123', $timeout = 3, $maxtries = 2)
{
$this->_servers[] = array($servername, $port, $sharedSecret, $timeout, $maxtries);
}
@@ -169,7 +169,7 @@ class Auth_RADIUS extends PEAR {
* @access public
* @return string
*/
- function getError()
+ function getError()
{
return radius_strerror($this->res);
}
@@ -181,7 +181,7 @@ class Auth_RADIUS extends PEAR {
* @param string $file Path to the configuration file
* @return void
*/
- function setConfigfile($file)
+ function setConfigfile($file)
{
$this->_configfile = $file;
}
@@ -195,7 +195,7 @@ class Auth_RADIUS extends PEAR {
* @param type $type Attribute-type
* @return bool true on success, false on error
*/
- function putAttribute($attrib, $value, $type = null)
+ function putAttribute($attrib, $value, $type = null)
{
if ($type == null) {
$type = gettype($value);
@@ -225,8 +225,8 @@ class Auth_RADIUS extends PEAR {
* @param mixed $port Attribute-value
* @param type $type Attribute-type
* @return bool true on success, false on error
- */
- function putVendorAttribute($vendor, $attrib, $value, $type = null)
+ */
+ function putVendorAttribute($vendor, $attrib, $value, $type = null)
{
if ($type == null) {
@@ -270,11 +270,11 @@ class Auth_RADIUS extends PEAR {
}
/**
- * Overwrite this.
+ * Overwrite this.
*
* @access public
*/
- function open()
+ function open()
{
}
@@ -339,7 +339,7 @@ class Auth_RADIUS extends PEAR {
* @return bool true on success, false on error
* @see addServer()
*/
- function putServer($servername, $port = 0, $sharedsecret = 'testing123', $timeout = 3, $maxtries = 3)
+ function putServer($servername, $port = 0, $sharedsecret = 'testing123', $timeout = 3, $maxtries = 3)
{
if (!radius_add_server($this->res, $servername, $port, $sharedsecret, $timeout, $maxtries)) {
return false;
@@ -354,7 +354,7 @@ class Auth_RADIUS extends PEAR {
* @param string $servername Servername or IP-Address
* @return bool true on success, false on error
*/
- function putConfigfile($file)
+ function putConfigfile($file)
{
if (!radius_config($this->res, $file)) {
return false;
@@ -363,11 +363,11 @@ class Auth_RADIUS extends PEAR {
}
/**
- * Initiates a RADIUS request.
+ * Initiates a RADIUS request.
*
* @access public
- * @return bool true on success, false on errors
- */
+ * @return bool true on success, false on errors
+ */
function start()
{
if (!$this->open()) {
@@ -447,7 +447,7 @@ class Auth_RADIUS extends PEAR {
if (!is_array($attrib)) {
return false;
- }
+ }
$attr = $attrib['attr'];
$data = $attrib['data'];
@@ -592,7 +592,7 @@ class Auth_RADIUS extends PEAR {
$this->attributes['url_logoff'] = radius_cvt_string($datav);
break;
}
- }
+ }
elseif ($vendor == 14122) { /* RADIUS_VENDOR_WISPr Wi-Fi Alliance */
@@ -719,9 +719,9 @@ class Auth_RADIUS extends PEAR {
*
* Class for authenticating using PAP (Plaintext)
*
- * @package Auth_RADIUS
+ * @package Auth_RADIUS
*/
-class Auth_RADIUS_PAP extends Auth_RADIUS
+class Auth_RADIUS_PAP extends Auth_RADIUS
{
/**
@@ -746,7 +746,7 @@ class Auth_RADIUS_PAP extends Auth_RADIUS
*
* @return bool true on success, false on error
*/
- function open()
+ function open()
{
$this->res = radius_auth_open();
if (!$this->res) {
@@ -756,7 +756,7 @@ class Auth_RADIUS_PAP extends Auth_RADIUS
}
/**
- * Creates an authentication request
+ * Creates an authentication request
*
* Creates an authentication request.
* You MUST call this method before you can put any attribute
@@ -772,7 +772,7 @@ class Auth_RADIUS_PAP extends Auth_RADIUS
}
/**
- * Put authentication specific attributes
+ * Put authentication specific attributes
*
* @return void
*/
@@ -792,10 +792,10 @@ class Auth_RADIUS_PAP extends Auth_RADIUS
* class Auth_RADIUS_CHAP_MD5
*
* Class for authenticating using CHAP-MD5 see RFC1994.
- * Instead og the plaintext password the challenge and
+ * Instead og the plaintext password the challenge and
* the response are needed.
*
- * @package Auth_RADIUS
+ * @package Auth_RADIUS
*/
class Auth_RADIUS_CHAP_MD5 extends Auth_RADIUS_PAP
{
@@ -836,7 +836,7 @@ class Auth_RADIUS_CHAP_MD5 extends Auth_RADIUS_PAP
/**
* Put CHAP-MD5 specific attributes
*
- * For authenticating using CHAP-MD5 via RADIUS you have to put the challenge
+ * For authenticating using CHAP-MD5 via RADIUS you have to put the challenge
* and the response. The chapid is inserted in the first byte of the response.
*
* @return void
@@ -844,7 +844,7 @@ class Auth_RADIUS_CHAP_MD5 extends Auth_RADIUS_PAP
function putAuthAttributes()
{
if (isset($this->username)) {
- $this->putAttribute(RADIUS_USER_NAME, $this->username);
+ $this->putAttribute(RADIUS_USER_NAME, $this->username);
}
if (isset($this->response)) {
$response = pack('C', $this->chapid) . $this->response;
@@ -877,9 +877,9 @@ class Auth_RADIUS_CHAP_MD5 extends Auth_RADIUS_PAP
*
* Class for authenticating using MS-CHAPv1 see RFC2433
*
- * @package Auth_RADIUS
+ * @package Auth_RADIUS
*/
-class Auth_RADIUS_MSCHAPv1 extends Auth_RADIUS_CHAP_MD5
+class Auth_RADIUS_MSCHAPv1 extends Auth_RADIUS_CHAP_MD5
{
/**
* LAN-Manager-Response
@@ -895,9 +895,9 @@ class Auth_RADIUS_MSCHAPv1 extends Auth_RADIUS_CHAP_MD5
var $flags = 1;
/**
- * Put MS-CHAPv1 specific attributes
+ * Put MS-CHAPv1 specific attributes
*
- * For authenticating using MS-CHAPv1 via RADIUS you have to put the challenge
+ * For authenticating using MS-CHAPv1 via RADIUS you have to put the challenge
* and the response. The response has this structure:
* struct rad_mschapvalue {
* u_char ident;
@@ -930,9 +930,9 @@ class Auth_RADIUS_MSCHAPv1 extends Auth_RADIUS_CHAP_MD5
*
* Class for authenticating using MS-CHAPv2 see RFC2759
*
- * @package Auth_RADIUS
+ * @package Auth_RADIUS
*/
-class Auth_RADIUS_MSCHAPv2 extends Auth_RADIUS_MSCHAPv1
+class Auth_RADIUS_MSCHAPv2 extends Auth_RADIUS_MSCHAPv1
{
/**
* 16 Bytes binary challenge
@@ -947,9 +947,9 @@ class Auth_RADIUS_MSCHAPv2 extends Auth_RADIUS_MSCHAPv1
var $peerChallenge = null;
/**
- * Put MS-CHAPv2 specific attributes
+ * Put MS-CHAPv2 specific attributes
*
- * For authenticating using MS-CHAPv1 via RADIUS you have to put the challenge
+ * For authenticating using MS-CHAPv1 via RADIUS you have to put the challenge
* and the response. The response has this structure:
* struct rad_mschapv2value {
* u_char ident;
@@ -964,11 +964,11 @@ class Auth_RADIUS_MSCHAPv2 extends Auth_RADIUS_MSCHAPv1
function putAuthAttributes()
{
if (isset($this->username)) {
- $this->putAttribute(RADIUS_USER_NAME, $this->username);
+ $this->putAttribute(RADIUS_USER_NAME, $this->username);
}
if (isset($this->response) && isset($this->peerChallenge)) {
- // Response: chapid, flags (1 = use NT Response), Peer challenge, reserved, Response
- $resp = pack('CCa16a8a24',$this->chapid , 1, $this->peerChallenge, str_repeat("\0", 8), $this->response);
+ // Response: chapid, flags (1 = use NT Response), Peer challenge, reserved, Response
+ $resp = pack('CCa16a8a24',$this->chapid , 1, $this->peerChallenge, str_repeat("\0", 8), $this->response);
$this->putVendorAttribute(RADIUS_VENDOR_MICROSOFT, RADIUS_MICROSOFT_MS_CHAP2_RESPONSE, $resp);
}
if (isset($this->challenge)) {
@@ -983,7 +983,7 @@ class Auth_RADIUS_MSCHAPv2 extends Auth_RADIUS_MSCHAPv1
* attributes are filled with Nullbytes to leave nothing in the mem.
*
* @access public
- */
+ */
function close()
{
Auth_RADIUS_MSCHAPv1::close();
@@ -995,10 +995,10 @@ class Auth_RADIUS_MSCHAPv2 extends Auth_RADIUS_MSCHAPv1
* class Auth_RADIUS_Acct
*
* Class for RADIUS accounting
- *
- * @package Auth_RADIUS
+ *
+ * @package Auth_RADIUS
*/
-class Auth_RADIUS_Acct extends Auth_RADIUS
+class Auth_RADIUS_Acct extends Auth_RADIUS
{
/**
* Defines where the Authentication was made, possible values are:
@@ -1011,19 +1011,19 @@ class Auth_RADIUS_Acct extends Auth_RADIUS
* Defines the type of the accounting request, on of:
* RADIUS_START, RADIUS_STOP, RADIUS_ACCOUNTING_ON, RADIUS_ACCOUNTING_OFF
* @var integer
- */
+ */
var $status_type = null;
/**
* The time the user was logged in in seconds
* @var integer
- */
+ */
var $session_time = null;
/**
* A uniq identifier for the session of the user, maybe the PHP-Session-Id
* @var string
- */
+ */
var $session_id = null;
/**
@@ -1066,7 +1066,7 @@ class Auth_RADIUS_Acct extends Auth_RADIUS
*
* @return bool true on success, false on error
*/
- function open()
+ function open()
{
$this->res = radius_acct_open();
if (!$this->res) {
@@ -1076,7 +1076,7 @@ class Auth_RADIUS_Acct extends Auth_RADIUS
}
/**
- * Creates an accounting request
+ * Creates an accounting request
*
* Creates an accounting request.
* You MUST call this method before you can put any attribute.
@@ -1094,10 +1094,10 @@ class Auth_RADIUS_Acct extends Auth_RADIUS
/**
* Put attributes for accounting.
*
- * Here we put some accounting values. There many more attributes for accounting,
+ * Here we put some accounting values. There many more attributes for accounting,
* but for web-applications only certain attributes make sense.
* @return void
- */
+ */
function putAuthAttributes()
{
if (isset($this->username)) {
@@ -1121,10 +1121,10 @@ class Auth_RADIUS_Acct extends Auth_RADIUS
* class Auth_RADIUS_Acct_Start
*
* Class for RADIUS accounting. Its usualy used, after the user has logged in.
- *
+ *
* @package Auth_RADIUS
*/
-class Auth_RADIUS_Acct_Start extends Auth_RADIUS_Acct
+class Auth_RADIUS_Acct_Start extends Auth_RADIUS_Acct
{
/**
* Defines the type of the accounting request.
diff --git a/etc/inc/rrd.inc b/etc/inc/rrd.inc
index c620419..5aaff68 100644
--- a/etc/inc/rrd.inc
+++ b/etc/inc/rrd.inc
@@ -61,14 +61,15 @@ function restore_rrd() {
}
unset($rrdrestore);
$_gb = exec("cd /;LANG=C /usr/bin/tar -tf {$g['cf_conf_path']}/rrd.tgz", $rrdrestore, $rrdreturn);
- if($rrdreturn != 0) {
+ if ($rrdreturn != 0) {
log_error("RRD restore failed exited with $rrdreturn, the error is: $rrdrestore\n");
return;
}
foreach ($rrdrestore as $xml_file) {
$rrd_file = '/' . substr($xml_file, 0, -4) . '.rrd';
- if (file_exists("{$rrd_file}"))
+ if (file_exists("{$rrd_file}")) {
@unlink($rrd_file);
+ }
file_put_contents("{$g['tmp_path']}/rrd_restore", $xml_file);
$_gb = exec("cd /;LANG=C /usr/bin/tar -xf {$g['cf_conf_path']}/rrd.tgz -T {$g['tmp_path']}/rrd_restore");
if (!file_exists("/{$xml_file}")) {
@@ -107,7 +108,7 @@ function create_new_rrd($rrdcreatecmd) {
}
function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
- if(!file_exists("/tmp/rrd_notice_sent.txt")) {
+ if (!file_exists("/tmp/rrd_notice_sent.txt")) {
$_gb = exec("echo 'Converting RRD configuration to new format. This might take a bit...' | wall");
@touch("/tmp/rrd_notice_sent.txt");
}
@@ -119,8 +120,8 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
/* add data sources not found in the old array from the new array */
$i = 0;
- foreach($rrdnewxml['ds'] as $ds) {
- if(!is_array($rrdoldxml['ds'][$i])) {
+ foreach ($rrdnewxml['ds'] as $ds) {
+ if (!is_array($rrdoldxml['ds'][$i])) {
$rrdoldxml['ds'][$i] = $rrdnewxml['ds'][$i];
/* set unknown values to 0 */
$rrdoldxml['ds'][$i]['last_ds'] = " 0.0000000000e+00 ";
@@ -134,16 +135,16 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
$rracountold = count($rrdoldxml['rra']);
$rracountnew = count($rrdnewxml['rra']);
/* process each RRA, which contain a database */
- foreach($rrdnewxml['rra'] as $rra) {
- if(!is_array($rrdoldxml['rra'][$i])) {
+ foreach ($rrdnewxml['rra'] as $rra) {
+ if (!is_array($rrdoldxml['rra'][$i])) {
$rrdoldxml['rra'][$i] = $rrdnewxml['rra'][$i];
}
$d = 0;
/* process cdp_prep */
$cdp_prep = $rra['cdp_prep'];
- foreach($cdp_prep['ds'] as $ds) {
- if(!is_array($rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d])) {
+ foreach ($cdp_prep['ds'] as $ds) {
+ if (!is_array($rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d])) {
$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d] = $rrdnewxml['rra'][$i]['cdp_prep']['ds'][$d];
$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['primary_value'] = " 0.0000000000e+00 ";
$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['secondary_value'] = " 0.0000000000e+00 ";
@@ -163,28 +164,28 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
$rowsdata = $rows;
$rowsempty = array();
$r = 0;
- while($r < $rowcountdiff) {
+ while ($r < $rowcountdiff) {
$rowsempty[] = $rrdnewxml['rra'][$i]['database']['row'][$r];
$r++;
}
$rows = $rowsempty + $rowsdata;
/* now foreach the rows in the database */
- foreach($rows['row'] as $row) {
- if(!is_array($rrdoldxml['rra'][$i]['database']['row'][$k])) {
+ foreach ($rows['row'] as $row) {
+ if (!is_array($rrdoldxml['rra'][$i]['database']['row'][$k])) {
$rrdoldxml['rra'][$i]['database']['row'][$k] = $rrdnewxml['rra'][$i]['database']['row'][$k];
}
$m = 0;
$vcountold = count($rrdoldxml['rra'][$i]['database']['row'][$k]['v']);
$vcountnew = count($rrdnewxml['rra'][$i]['database']['row'][$k]['v']);
- foreach($row['v'] as $value) {
- if(empty($rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m])) {
- if(isset($valid)) {
+ foreach ($row['v'] as $value) {
+ if (empty($rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m])) {
+ if (isset($valid)) {
$rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m] = "0.0000000000e+00 ";
} else {
$rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m] = $rrdnewxml['rra'][$i]['database']['row'][$k]['v'][$m];
}
} else {
- if($value <> " NaN ") {
+ if ($value <> " NaN ") {
$valid = true;
} else {
$valid = false;
@@ -206,8 +207,9 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
function enable_rrd_graphing() {
global $config, $g, $altq_list_queues;
- if(platform_booting())
+ if (platform_booting()) {
echo gettext("Generating RRD graphs...");
+ }
$rrddbpath = "/var/db/rrd/";
$rrdgraphpath = "/usr/local/www/rrd";
@@ -309,16 +311,17 @@ function enable_rrd_graphing() {
/* IPsec counters */
$ifdescrs['ipsec'] = "IPsec";
/* OpenVPN server counters */
- if(is_array($config['openvpn']['openvpn-server'])) {
- foreach($config['openvpn']['openvpn-server'] as $server) {
+ if (is_array($config['openvpn']['openvpn-server'])) {
+ foreach ($config['openvpn']['openvpn-server'] as $server) {
$serverid = "ovpns" . $server['vpnid'];
$ifdescrs[$serverid] = "{$server['description']}";
}
}
if (platform_booting()) {
- if (!is_dir("{$g['vardb_path']}/rrd"))
+ if (!is_dir("{$g['vardb_path']}/rrd")) {
mkdir("{$g['vardb_path']}/rrd", 0775);
+ }
@chown("{$g['vardb_path']}/rrd", "nobody");
}
@@ -326,7 +329,7 @@ function enable_rrd_graphing() {
/* process all real and pseudo interfaces */
foreach ($ifdescrs as $ifname => $ifdescr) {
$temp = get_real_interface($ifname);
- if($temp <> "") {
+ if ($temp <> "") {
$realif = $temp;
}
@@ -351,7 +354,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$traffic N:U:U:U:U:U:U:U:U");
}
@@ -384,7 +387,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$packets N:U:U:U:U:U:U:U:U");
}
@@ -397,7 +400,7 @@ function enable_rrd_graphing() {
$rrdupdatesh .= "END {print b4pi \":\" b4po \":\" b4bi \":\" b4bo \":\" b6pi \":\" b6po \":\" b6bi \":\" b6bo};'`\n";
/* WIRELESS, set up the rrd file */
- if($config['interfaces'][$ifname]['wireless']['mode'] == "bss") {
+ if ($config['interfaces'][$ifname]['wireless']['mode'] == "bss") {
if (!file_exists("$rrddbpath$ifname$wireless")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$wireless --step $rrdwirelessinterval ";
$rrdcreate .= "DS:snr:GAUGE:$wirelessvalid:0:1000 ";
@@ -413,7 +416,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$wireless N:U:U:U");
}
@@ -424,7 +427,7 @@ function enable_rrd_graphing() {
}
/* OpenVPN, set up the rrd file */
- if(stristr($ifname, "ovpns")) {
+ if (stristr($ifname, "ovpns")) {
if (!file_exists("$rrddbpath$ifname$vpnusers")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$vpnusers --step $rrdvpninterval ";
$rrdcreate .= "DS:users:GAUGE:$vpnvalid:0:10000 ";
@@ -438,13 +441,13 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$vpnusers N:U");
}
- if(is_array($config['openvpn']['openvpn-server'])) {
- foreach($config['openvpn']['openvpn-server'] as $server) {
- if("ovpns{$server['vpnid']}" == $ifname) {
+ if (is_array($config['openvpn']['openvpn-server'])) {
+ foreach ($config['openvpn']['openvpn-server'] as $server) {
+ if ("ovpns{$server['vpnid']}" == $ifname) {
$port = $server['local_port'];
$vpnid = $server['vpnid'];
}
@@ -520,12 +523,12 @@ function enable_rrd_graphing() {
unset($rrdcreate);
}
- if(platform_booting()) {
+ if (platform_booting()) {
$rrdqcommand = "-t ";
$rrducommand = "N";
$qi = 0;
foreach ($qlist as $qname => $q) {
- if($qi == 0) {
+ if ($qi == 0) {
$rrdqcommand .= "{$qname}";
} else {
$rrdqcommand .= ":{$qname}";
@@ -573,7 +576,7 @@ function enable_rrd_graphing() {
}
/* 3G interfaces */
- if(preg_match("/ppp[0-9]+/i", $realif)) {
+ if (preg_match("/ppp[0-9]+/i", $realif)) {
if (!file_exists("$rrddbpath$ifname$cellular")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$cellular --step $rrdcellularinterval ";
$rrdcreate .= "DS:rssi:GAUGE:$cellularvalid:0:100 ";
@@ -588,7 +591,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$cellular N:U:U:U");
}
@@ -605,7 +608,7 @@ function enable_rrd_graphing() {
$ifname = "system";
/* STATES, create pf states database */
- if(! file_exists("$rrddbpath$ifname$states")) {
+ if (!file_exists("$rrddbpath$ifname$states")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$states --step $rrdstatesinterval ";
$rrdcreate .= "DS:pfrate:GAUGE:$statesvalid:0:10000000 ";
$rrdcreate .= "DS:pfstates:GAUGE:$statesvalid:0:10000000 ";
@@ -622,7 +625,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$states N:U:U:U:U:U");
}
@@ -640,7 +643,7 @@ function enable_rrd_graphing() {
/* End pf states statistics */
/* CPU, create CPU statistics database */
- if(! file_exists("$rrddbpath$ifname$proc")) {
+ if (!file_exists("$rrddbpath$ifname$proc")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$proc --step $rrdprocinterval ";
$rrdcreate .= "DS:user:GAUGE:$procvalid:0:10000000 ";
$rrdcreate .= "DS:nice:GAUGE:$procvalid:0:10000000 ";
@@ -657,7 +660,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$proc N:U:U:U:U:U");
}
@@ -670,7 +673,7 @@ function enable_rrd_graphing() {
/* End CPU statistics */
/* Memory, create Memory statistics database */
- if(! file_exists("$rrddbpath$ifname$mem")) {
+ if (!file_exists("$rrddbpath$ifname$mem")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$mem --step $rrdmeminterval ";
$rrdcreate .= "DS:active:GAUGE:$memvalid:0:10000000 ";
$rrdcreate .= "DS:inactive:GAUGE:$memvalid:0:10000000 ";
@@ -695,7 +698,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$mem N:U:U:U:U:U");
}
@@ -708,7 +711,7 @@ function enable_rrd_graphing() {
/* End Memory statistics */
/* mbuf, create mbuf statistics database */
- if(! file_exists("$rrddbpath$ifname$mbuf")) {
+ if (!file_exists("$rrddbpath$ifname$mbuf")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$mbuf --step $rrdmbufinterval ";
$rrdcreate .= "DS:current:GAUGE:$mbufvalid:0:10000000 ";
$rrdcreate .= "DS:cache:GAUGE:$mbufvalid:0:10000000 ";
@@ -732,7 +735,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$mbuf N:U:U:U:U");
}
@@ -745,7 +748,7 @@ function enable_rrd_graphing() {
/* SPAMD, set up the spamd rrd file */
if (isset($config['installedpackages']['spamdsettings']) &&
- $config['installedpackages']['spamdsettings']['config'][0]['enablerrd']) {
+ $config['installedpackages']['spamdsettings']['config'][0]['enablerrd']) {
/* set up the spamd rrd file */
if (!file_exists("$rrddbpath$ifname$spamd")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$spamd --step $rrdspamdinterval ";
@@ -777,10 +780,11 @@ function enable_rrd_graphing() {
/* End System statistics */
/* Captive Portal statistics, set up the rrd file */
- if(is_array($config['captiveportal'])) {
+ if (is_array($config['captiveportal'])) {
foreach ($config['captiveportal'] as $cpkey => $cp) {
- if (!isset($cp['enable']))
+ if (!isset($cp['enable'])) {
continue;
+ }
$ifname= "captiveportal";
$concurrent_filename = $rrddbpath . $ifname . '-' . $cpkey . $captiveportalconcurrent;
@@ -809,7 +813,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $concurrent_filename N:U");
}
@@ -845,7 +849,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $loggedin_filename N:U");
}
@@ -888,8 +892,8 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
- mwexec("$rrdtool update $rrddbpath$ntpd N:U:U:U:U:U:U");
+ if (platform_booting()) {
+ mwexec("$rrdtool update $rrddbpath$ntpd N:U:U:U:U:U:U");
}
/* the ntp stats gathering function. */
@@ -931,12 +935,13 @@ function enable_rrd_graphing() {
}
$databases = glob("{$rrddbpath}/*.rrd");
- foreach($databases as $database) {
+ foreach ($databases as $database) {
chown($database, "nobody");
}
- if(platform_booting())
+ if (platform_booting()) {
echo gettext("done.") . "\n";
+ }
}
@@ -963,9 +968,10 @@ function create_gateway_quality_rrd($rrd_file) {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
- if (!is_dir("{$g['vardb_path']}/rrd"))
+ if (platform_booting()) {
+ if (!is_dir("{$g['vardb_path']}/rrd")) {
mkdir("{$g['vardb_path']}/rrd", 0775);
+ }
@chown("{$g['vardb_path']}/rrd", "nobody");
diff --git a/etc/inc/sasl.inc b/etc/inc/sasl.inc
index f6a8d0b..a9582da 100644
--- a/etc/inc/sasl.inc
+++ b/etc/inc/sasl.inc
@@ -178,7 +178,7 @@ class sasl_client_class
<purpose>Retrieve the values of one or more credentials to be used by
the authentication mechanism classes.</purpose>
<usage>This is meant to be used by authentication mechanism driver
- classes to retrieve the credentials that may be neede.</usage>
+ classes to retrieve the credentials that may be needed.</usage>
<returnvalue>The function may return <tt>SASL_CONTINUE</tt> if it
succeeded, or <tt>SASL_NOMECH</tt> if it was not possible to
retrieve one of the requested credentials.</returnvalue>
@@ -359,7 +359,7 @@ class sasl_client_class
<type>INTEGER</type>
<documentation>
<purpose>Process the authentication steps after the initial step,
- until the authetication iteration dialog is complete.</purpose>
+ until the authentication iteration dialog is complete.</purpose>
<usage>Call this function iteratively after a successful initial
step calling the <functionlink>Start</functionlink> function.</usage>
<returnvalue>The function returns <tt>SASL_CONTINUE</tt> if step was
diff --git a/etc/inc/service-utils.inc b/etc/inc/service-utils.inc
index a78446e..8323924 100644
--- a/etc/inc/service-utils.inc
+++ b/etc/inc/service-utils.inc
@@ -1,36 +1,35 @@
<?php
/****h* pfSense/service-utils
- * NAME
- * service-utils.inc - Service facility
- * DESCRIPTION
- * This file contains various functions used by the pfSense service facility.
- * HISTORY
- * $Id$
- ******
- *
- * Copyright (C) 2005-2006 Colin Smith (ethethlay@gmail.com)
- * 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)
- * RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
+ NAME
+ service-utils.inc - Service facility
+ DESCRIPTION
+ This file contains various functions used by the pfSense service facility.
+ HISTORY
+ $Id$
+
+ Copyright (C) 2005-2006 Colin Smith (ethethlay@gmail.com)
+ 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)
+ RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
*/
/*
@@ -51,11 +50,13 @@ function write_rcfile($params) {
safe_mkdir(RCFILEPREFIX);
$rcfile_fullname = RCFILEPREFIX . $params['file'];
- if (!file_exists($rcfile_fullname) && !is_link($rcfile_fullname) && !touch($rcfile_fullname))
+ if (!file_exists($rcfile_fullname) && !is_link($rcfile_fullname) && !touch($rcfile_fullname)) {
return false;
+ }
- if (!is_writable($rcfile_fullname) || empty($params['start']))
+ if (!is_writable($rcfile_fullname) || empty($params['start'])) {
return false;
+ }
$towrite = "#!/bin/sh\n";
$towrite .= "# This file was automatically generated\n# by the {$g['product_name']} service handler.\n\n";
@@ -64,9 +65,9 @@ function write_rcfile($params) {
$towrite .= "rc_start() {\n";
$towrite .= "\t{$params['start']}\n";
$towrite .= "}\n\n";
- if(!empty($params['stop'])) {
+ if (!empty($params['stop'])) {
$tokill =& $params['stop'];
- } else if(!empty($params['executable'])) {
+ } else if (!empty($params['executable'])) {
/* just nuke the executable */
$tokill = "/usr/bin/killall " . escapeshellarg($params['executable']);
} else {
@@ -90,23 +91,25 @@ function write_rcfile($params) {
function start_service($name) {
global $config;
- if (empty($name))
+ if (empty($name)) {
return;
+ }
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
- foreach($config['installedpackages']['service'] as $service) {
- if(strtolower($service['name']) == strtolower($name)) {
- if($service['rcfile']) {
+ foreach ($config['installedpackages']['service'] as $service) {
+ if (strtolower($service['name']) == strtolower($name)) {
+ if ($service['rcfile']) {
$prefix = RCFILEPREFIX;
if (!empty($service['prefix'])) {
$prefix =& $service['prefix'];
}
- if(file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
+ if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
mwexec_bg("{$prefix}{$service['rcfile']} start");
}
}
- if (!empty($service['startcmd']))
+ if (!empty($service['startcmd'])) {
eval($service['startcmd']);
+ }
break;
}
}
@@ -116,24 +119,26 @@ function start_service($name) {
function stop_service($name) {
global $config;
- if (empty($name))
+ if (empty($name)) {
return;
+ }
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
- foreach($config['installedpackages']['service'] as $service) {
- if(strtolower($service['name']) == strtolower($name)) {
- if($service['rcfile']) {
+ foreach ($config['installedpackages']['service'] as $service) {
+ if (strtolower($service['name']) == strtolower($name)) {
+ if ($service['rcfile']) {
$prefix = RCFILEPREFIX;
- if(!empty($service['prefix'])) {
+ if (!empty($service['prefix'])) {
$prefix =& $service['prefix'];
}
- if(file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
+ if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
mwexec("{$prefix}{$service['rcfile']} stop");
}
return;
}
- if (!empty($service['stopcmd']))
+ if (!empty($service['stopcmd'])) {
eval($service['stopcmd']);
+ }
break;
}
@@ -144,16 +149,17 @@ function stop_service($name) {
function restart_service($name) {
global $config;
- if (empty($name))
+ if (empty($name)) {
return;
+ }
stop_service($name);
start_service($name);
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
- foreach($config['installedpackages']['service'] as $service) {
- if(strtolower($service['name']) == strtolower($name)) {
- if($service['restartcmd']) {
+ foreach ($config['installedpackages']['service'] as $service) {
+ if (strtolower($service['name']) == strtolower($name)) {
+ if ($service['restartcmd']) {
eval($service['restartcmd']);
}
break;
@@ -163,34 +169,38 @@ function restart_service($name) {
}
function is_pid_running($pidfile) {
- if (!file_exists($pidfile))
+ if (!file_exists($pidfile)) {
return false;
+ }
return (isvalidpid($pidfile));
}
function is_dhcp_running($interface) {
$status = find_dhclient_process($interface);
- if($status != 0)
+ if ($status != 0) {
return true;
+ }
return false;
}
function restart_service_if_running($service) {
global $config;
- if(is_service_running($service))
+ if (is_service_running($service)) {
restart_service($service);
+ }
return;
}
function is_service_enabled($service_name) {
global $config;
- if ($service_name == "")
+ if ($service_name == "") {
return false;
+ }
if (is_array($config['installedpackages'])) {
if (isset($config['installedpackages'][$service_name]['config'][0]['enable']) &&
- ((empty($config['installedpackages'][$service_name]['config'][0]['enable'])) ||
- ($config['installedpackages'][$service_name]['config'][0]['enable'] === 'off'))) {
+ ((empty($config['installedpackages'][$service_name]['config'][0]['enable'])) ||
+ ($config['installedpackages'][$service_name]['config'][0]['enable'] === 'off'))) {
return false;
}
}
@@ -200,38 +210,42 @@ function is_service_enabled($service_name) {
function is_service_running($service, $ps = "") {
global $config;
- if(is_array($config['installedpackages']['service'])) {
- foreach($config['installedpackages']['service'] as $aservice) {
- if(strtolower($service) == strtolower($aservice['name'])) {
+ if (is_array($config['installedpackages']['service'])) {
+ foreach ($config['installedpackages']['service'] as $aservice) {
+ if (strtolower($service) == strtolower($aservice['name'])) {
if ($aservice['custom_php_service_status_command'] <> "") {
eval("\$rc={$aservice['custom_php_service_status_command']};");
return $rc;
}
- if(empty($aservice['executable']))
+ if (empty($aservice['executable'])) {
return false;
- if (is_process_running($aservice['executable']))
+ }
+ if (is_process_running($aservice['executable'])) {
return true;
+ }
return false;
}
}
}
- if (is_process_running($service))
+ if (is_process_running($service)) {
return true;
+ }
return false;
}
function get_services() {
global $config;
- if (is_array($config['installedpackages']['service']))
+ if (is_array($config['installedpackages']['service'])) {
$services = $config['installedpackages']['service'];
- else
+ } else {
$services = array();
+ }
- /* Add services that are in the base.
- *
+ /*
+ * Add services that are in the base.
*/
if (is_radvd_enabled()) {
$pconfig = array();
@@ -275,8 +289,9 @@ function get_services() {
$ifdescrs = get_configured_interface_list();
foreach ($ifdescrs as $if) {
$oc = $config['interfaces'][$if];
- if ($oc['if'] && (!link_interface_to_bridge($if)))
+ if ($oc['if'] && (!link_interface_to_bridge($if))) {
$iflist[$if] = $if;
+ }
}
if (isset($config['dhcrelay']['enable'])) {
@@ -377,40 +392,48 @@ function get_services() {
function find_service_by_name($name) {
$services = get_services();
- foreach ($services as $service)
- if ($service["name"] == $name)
+ foreach ($services as $service) {
+ if ($service["name"] == $name) {
return $service;
+ }
+ }
return array();
}
function find_service_by_openvpn_vpnid($vpnid) {
$services = get_services();
- foreach ($services as $service)
- if (($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid))
+ foreach ($services as $service) {
+ if (($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid)) {
return $service;
+ }
+ }
return array();
}
function find_service_by_cp_zone($zone) {
$services = get_services();
- foreach ($services as $service)
- if (($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone))
+ foreach ($services as $service) {
+ if (($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone)) {
return $service;
+ }
+ }
return array();
}
function service_name_compare($a, $b) {
- if (strtolower($a['name']) == strtolower($b['name']))
+ if (strtolower($a['name']) == strtolower($b['name'])) {
return 0;
+ }
return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
}
function get_pkg_descr($package_name) {
global $config;
if (is_array($config['installedpackages']['package'])) {
- foreach($config['installedpackages']['package'] as $pkg) {
- if($pkg['name'] == $package_name)
+ foreach ($config['installedpackages']['package'] as $pkg) {
+ if ($pkg['name'] == $package_name) {
return $pkg['descr'];
+ }
}
}
return gettext("Not available.");
@@ -424,8 +447,9 @@ function get_service_status($service) {
break;
case "captiveportal":
$running = is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal.pid");
- if (isset($config['captiveportal'][$service['zone']]['httpslogin']))
+ if (isset($config['captiveportal'][$service['zone']]['httpslogin'])) {
$running = $running && is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal-SSL.pid");
+ }
break;
case "vhosts-http":
$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid");
@@ -445,21 +469,23 @@ function get_service_status($service) {
function get_service_status_icon($service, $withtext = true, $smallicon = false) {
global $g;
$output = "";
- if(get_service_status($service)) {
+ if (get_service_status($service)) {
$statustext = gettext("Running");
$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"),$service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
$output .= ($smallicon) ? "icon_pass.gif" : "icon_service_running.gif";
$output .= "\" alt=\"status\" />&nbsp;";
- if ($withtext)
+ if ($withtext) {
$output .= "&nbsp;" . $statustext;
+ }
} else {
$service_enabled = is_service_enabled($service['name']);
$statustext = ($service_enabled) ? gettext("Stopped") : gettext("Disabled");
$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"),$service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
$output .= ($smallicon) ? "icon_block.gif" : "icon_service_stopped.gif";
$output .= "\" alt=\"status\" />&nbsp;";
- if ($withtext)
+ if ($withtext) {
$output .= "&nbsp;<font color=\"white\">{$statustext}</font>";
+ }
}
return $output;
}
@@ -468,7 +494,7 @@ function get_service_control_links($service, $addname = false) {
global $g;
$output = "";
$stitle = ($addname) ? $service['name'] . " " : "";
- if(get_service_status($service)) {
+ if (get_service_status($service)) {
switch ($service['name']) {
case "openvpn":
$output .= "<a href='status_services.php?mode=restartservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}'>";
@@ -502,18 +528,20 @@ function get_service_control_links($service, $addname = false) {
$output .= "<a href='status_services.php?mode=startservice&amp;service={$service['name']}&amp;zone={$service['zone']}'>";
break;
default:
- if ($service_enabled)
+ if ($service_enabled) {
$output .= "<a href='status_services.php?mode=startservice&amp;service={$service['name']}'>";
+ }
}
- if ($service_enabled)
+ if ($service_enabled) {
$output .= "<img style=\"vertical-align:middle\" title='" . sprintf(gettext("Start %sService"),$stitle) . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif' alt='start' /></a>\n";
+ }
}
return $output;
}
function service_control_start($name, $extras) {
global $g;
- switch($name) {
+ switch ($name) {
case 'radvd':
services_radvd_configure();
break;
@@ -563,8 +591,9 @@ function service_control_start($name, $extras) {
if (($vpnmode == "server") || ($vpnmode == "client")) {
$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($extras['id']);
$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
- if (file_exists($configfile))
+ if (file_exists($configfile)) {
openvpn_restart_by_vpnid($vpnmode, $id);
+ }
}
break;
case 'relayd':
@@ -578,7 +607,7 @@ function service_control_start($name, $extras) {
}
function service_control_stop($name, $extras) {
global $g;
- switch($name) {
+ switch ($name) {
case 'radvd':
killbypid("{$g['varrun_path']}/radvd.pid");
break;
@@ -649,7 +678,7 @@ function service_control_stop($name, $extras) {
function service_control_restart($name, $extras) {
global $g;
- switch($name) {
+ switch ($name) {
case 'radvd':
services_radvd_configure();
break;
@@ -702,8 +731,9 @@ function service_control_restart($name, $extras) {
if ($vpnmode == "server" || $vpnmode == "client") {
$id = htmlspecialchars($extras['id']);
$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
- if (file_exists($configfile))
+ if (file_exists($configfile)) {
openvpn_restart_by_vpnid($vpnmode, $id);
+ }
}
break;
case 'relayd':
diff --git a/etc/inc/services.inc b/etc/inc/services.inc
index 1f5283a..7fee002 100644
--- a/etc/inc/services.inc
+++ b/etc/inc/services.inc
@@ -44,17 +44,19 @@ define('DYNDNS_PROVIDER_DESCRIPTIONS', 'City Network,CloudFlare,Custom,Custom (v
/* implement ipv6 route advertising daemon */
function services_radvd_configure($blacklist = array()) {
global $config, $g;
-
- if ($g['platform'] == 'jail')
+
+ if ($g['platform'] == 'jail') {
return;
+ }
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "services_radvd_configure() being called $mt\n";
}
- if (!is_array($config['dhcpdv6']))
+ if (!is_array($config['dhcpdv6'])) {
$config['dhcpdv6'] = array();
+ }
$Iflist = get_configured_interface_list();
$Iflist = array_merge($Iflist, get_configured_pppoe_server_interfaces());
@@ -67,23 +69,29 @@ function services_radvd_configure($blacklist = array()) {
/* handle manually configured DHCP6 server settings first */
foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
- if (!is_array($config['interfaces'][$dhcpv6if]))
+ if (!is_array($config['interfaces'][$dhcpv6if])) {
continue;
- if (!isset($config['interfaces'][$dhcpv6if]['enable']))
+ }
+ if (!isset($config['interfaces'][$dhcpv6if]['enable'])) {
continue;
+ }
/* Do not put in the config an interface which is down */
- if (isset($blacklist[$dhcpv6if]))
+ if (isset($blacklist[$dhcpv6if])) {
continue;
- if (!isset($dhcpv6ifconf['ramode']))
+ }
+ if (!isset($dhcpv6ifconf['ramode'])) {
$dhcpv6ifconf['ramode'] = $dhcpv6ifconf['mode'];
+ }
/* are router advertisements enabled? */
- if ($dhcpv6ifconf['ramode'] == "disabled")
+ if ($dhcpv6ifconf['ramode'] == "disabled") {
continue;
+ }
- if (!isset($dhcpv6ifconf['rapriority']))
+ if (!isset($dhcpv6ifconf['rapriority'])) {
$dhcpv6ifconf['rapriority'] = "medium";
+ }
/* always start with the real parent, we override with the carp if later */
$carpif = false;
@@ -97,20 +105,23 @@ function services_radvd_configure($blacklist = array()) {
if (strstr($dhcpv6if, "_vip")) {
// CARP IP, check if it's enabled and find parent
- if (!get_carp_status() || get_carp_interface_status($dhcpv6if) != "MASTER")
+ if (!get_carp_status() || get_carp_interface_status($dhcpv6if) != "MASTER") {
continue;
+ }
$ifparent = link_carp_interface_to_parent($dhcpv6if);
$realif = convert_friendly_interface_to_real_interface_name($ifparent);
} else {
$realif = get_real_interface($dhcpv6if, "inet6");
}
-
- if (isset($radvdifs[$realif]))
+
+ if (isset($radvdifs[$realif])) {
continue;
+ }
$ifcfgipv6 = get_interface_ipv6($dhcpv6if);
- if (!is_ipaddrv6($ifcfgipv6))
+ if (!is_ipaddrv6($ifcfgipv6)) {
continue;
+ }
$ifcfgsnv6 = get_interface_subnetv6($dhcpv6if);
$subnetv6 = gen_subnetv6($ifcfgipv6, $ifcfgsnv6);
@@ -122,12 +133,13 @@ function services_radvd_configure($blacklist = array()) {
$radvdconf .= "\tMinRtrAdvInterval 5;\n";
$radvdconf .= "\tMaxRtrAdvInterval 20;\n";
$mtu = get_interface_mtu($realif);
- if (is_numeric($mtu))
+ if (is_numeric($mtu)) {
$radvdconf .= "\tAdvLinkMTU {$mtu};\n";
- else
+ } else {
$radvdconf .= "\tAdvLinkMTU 1280;\n";
+ }
// $radvdconf .= "\tDeprecatePrefix on;\n";
- switch($dhcpv6ifconf['rapriority']) {
+ switch ($dhcpv6ifconf['rapriority']) {
case "low":
$radvdconf .= "\tAdvDefaultPreference low;\n";
break;
@@ -138,7 +150,7 @@ function services_radvd_configure($blacklist = array()) {
$radvdconf .= "\tAdvDefaultPreference medium;\n";
break;
}
- switch($dhcpv6ifconf['ramode']) {
+ switch ($dhcpv6ifconf['ramode']) {
case "managed":
case "assist":
$radvdconf .= "\tAdvManagedFlag on;\n";
@@ -146,12 +158,12 @@ function services_radvd_configure($blacklist = array()) {
break;
}
$radvdconf .= "\tprefix {$subnetv6}/{$ifcfgsnv6} {\n";
- if($carpif == true) {
+ if ($carpif == true) {
$radvdconf .= "\t\tDeprecatePrefix off;\n";
} else {
$radvdconf .= "\t\tDeprecatePrefix on;\n";
}
- switch($dhcpv6ifconf['ramode']) {
+ switch ($dhcpv6ifconf['ramode']) {
case "managed":
$radvdconf .= "\t\tAdvOnLink on;\n";
$radvdconf .= "\t\tAdvAutonomous off;\n";
@@ -171,11 +183,11 @@ function services_radvd_configure($blacklist = array()) {
$radvdconf .= "\t\tAdvOnLink on;\n";
$radvdconf .= "\t\tAdvAutonomous on;\n";
$radvdconf .= "\t\tAdvRouterAddr on;\n";
- break;
+ break;
}
$radvdconf .= "\t};\n";
- if($carpif === true) {
+ if ($carpif === true) {
$radvdconf .= "\troute ::/0 {\n";
$radvdconf .= "\t\tRemoveRoute off;\n";
$radvdconf .= "\t};\n";
@@ -188,25 +200,31 @@ function services_radvd_configure($blacklist = array()) {
/* add DNS servers */
$dnslist = array();
if (isset($dhcpv6ifconf['rasamednsasdhcp6']) && is_array($dhcpv6ifconf['dnsserver']) && !empty($dhcpv6ifconf['dnsserver'])) {
- foreach($dhcpv6ifconf['dnsserver'] as $server)
- if (is_ipaddrv6($server))
+ foreach ($dhcpv6ifconf['dnsserver'] as $server) {
+ if (is_ipaddrv6($server)) {
$dnslist[] = $server;
+ }
+ }
} elseif (!isset($dhcpv6ifconf['rasamednsasdhcp6']) && isset($dhcpv6ifconf['radnsserver']) && is_array($dhcpv6ifconf['radnsserver'])) {
- foreach($dhcpv6ifconf['radnsserver'] as $server)
- if (is_ipaddrv6($server))
+ foreach ($dhcpv6ifconf['radnsserver'] as $server) {
+ if (is_ipaddrv6($server)) {
$dnslist[] = $server;
+ }
+ }
} elseif (isset($config['dnsmasq']['enable']) || isset($config['unbound']['enable'])) {
$dnslist[] = get_interface_ipv6($realif);
} elseif (is_array($config['system']['dnsserver']) && !empty($config['system']['dnsserver'])) {
- foreach($config['system']['dnsserver'] as $server) {
- if (is_ipaddrv6($server))
+ foreach ($config['system']['dnsserver'] as $server) {
+ if (is_ipaddrv6($server)) {
$dnslist[] = $server;
+ }
}
}
if (count($dnslist) > 0) {
$dnsstring = implode(" ", $dnslist);
- if ($dnsstring <> "")
+ if ($dnsstring <> "") {
$radvdconf .= "\tRDNSS {$dnsstring} { };\n";
+ }
}
if (!empty($dhcpv6ifconf['domain'])) {
$radvdconf .= "\tDNSSL {$dhcpv6ifconf['domain']} { };\n";
@@ -218,16 +236,20 @@ function services_radvd_configure($blacklist = array()) {
/* handle DHCP-PD prefixes and 6RD dynamic interfaces */
foreach ($Iflist as $if => $ifdescr) {
- if(!isset($config['interfaces'][$if]['track6-interface']))
+ if (!isset($config['interfaces'][$if]['track6-interface'])) {
continue;
- if(!isset($config['interfaces'][$if]['enable']))
+ }
+ if (!isset($config['interfaces'][$if]['enable'])) {
continue;
+ }
/* Do not put in the config an interface which is down */
- if (isset($blacklist[$if]))
+ if (isset($blacklist[$if])) {
continue;
+ }
$trackif = $config['interfaces'][$if]['track6-interface'];
- if (empty($config['interfaces'][$trackif]))
+ if (empty($config['interfaces'][$trackif])) {
continue;
+ }
if (strstr($if, "_vip")) {
// CARP IP, find parent
@@ -236,13 +258,14 @@ function services_radvd_configure($blacklist = array()) {
} else {
$realif = get_real_interface($if, "inet6");
}
-
+
/* prevent duplicate entries, manual overrides */
- if (isset($radvdifs[$realif]))
+ if (isset($radvdifs[$realif])) {
continue;
+ }
$ifcfgipv6 = get_interface_ipv6($if);
- if(!is_ipaddrv6($ifcfgipv6)) {
+ if (!is_ipaddrv6($ifcfgipv6)) {
$subnetv6 = "::";
$ifcfgsnv6 = "64";
} else {
@@ -252,9 +275,10 @@ function services_radvd_configure($blacklist = array()) {
$radvdifs[$realif] = $realif;
$autotype = $config['interfaces'][$trackif]['ipaddrv6'];
-
- if ($g['debug'])
+
+ if ($g['debug']) {
log_error("configuring RA on {$if} for type {$autotype} radvd subnet {$subnetv6}/{$ifcfgsnv6}");
+ }
$radvdconf .= "# Generated config for {$autotype} delegation from {$trackif} on {$if}\n";
$radvdconf .= "interface {$realif} {\n";
@@ -262,10 +286,11 @@ function services_radvd_configure($blacklist = array()) {
$radvdconf .= "\tMinRtrAdvInterval 3;\n";
$radvdconf .= "\tMaxRtrAdvInterval 10;\n";
$mtu = get_interface_mtu($realif);
- if (is_numeric($mtu))
+ if (is_numeric($mtu)) {
$radvdconf .= "\tAdvLinkMTU {$mtu};\n";
- else
+ } else {
$radvdconf .= "\tAdvLinkMTU 1280;\n";
+ }
$radvdconf .= "\tAdvOtherConfigFlag on;\n";
$radvdconf .= "\t\tprefix {$subnetv6}/{$ifcfgsnv6} {\n";
$radvdconf .= "\t\tAdvOnLink on;\n";
@@ -278,15 +303,17 @@ function services_radvd_configure($blacklist = array()) {
if (isset($config['dnsmasq']['enable']) || isset($config['unbound']['enable'])) {
$dnslist[] = $ifcfgipv6;
} elseif (is_array($config['system']['dnsserver']) && !empty($config['system']['dnsserver'])) {
- foreach($config['system']['dnsserver'] as $server) {
- if(is_ipaddrv6($server))
+ foreach ($config['system']['dnsserver'] as $server) {
+ if (is_ipaddrv6($server)) {
$dnslist[] = $server;
+ }
}
}
if (count($dnslist) > 0) {
$dnsstring = implode(" ", $dnslist);
- if (!empty($dnsstring))
+ if (!empty($dnsstring)) {
$radvdconf .= "\tRDNSS {$dnsstring} { };\n";
+ }
}
if (!empty($config['system']['domain'])) {
$radvdconf .= "\tDNSSL {$config['system']['domain']} { };\n";
@@ -297,16 +324,18 @@ function services_radvd_configure($blacklist = array()) {
/* write radvd.conf */
if (!@file_put_contents("{$g['varetc_path']}/radvd.conf", $radvdconf)) {
log_error("Error: cannot open radvd.conf in services_radvd_configure().\n");
- if (platform_booting())
+ if (platform_booting()) {
printf("Error: cannot open radvd.conf in services_radvd_configure().\n");
+ }
}
unset($radvdconf);
if (count($radvdifs) > 0) {
- if (isvalidpid("{$g['varrun_path']}/radvd.pid"))
+ if (isvalidpid("{$g['varrun_path']}/radvd.pid")) {
sigkillbypid("{$g['varrun_path']}/radvd.pid", "HUP");
- else
+ } else {
mwexec("/usr/local/sbin/radvd -p {$g['varrun_path']}/radvd.pid -C {$g['varetc_path']}/radvd.conf -m syslog");
+ }
} else {
/* we need to shut down the radvd cleanly, it will send out the prefix
* information with a lifetime of 0 to notify clients of a (possible) new prefix */
@@ -339,13 +368,15 @@ function services_dhcpd_configure($family = "all", $blacklist = array()) {
fwrite($fd, "/bin/chmod a+rx {$g['dhcpd_chroot_path']}/usr/local/sbin/dhcpd\n");
$status = `/sbin/mount | /usr/bin/grep -v grep | /usr/bin/grep "{$g['dhcpd_chroot_path']}/dev"`;
- if (!trim($status))
+ if (!trim($status)) {
fwrite($fd, "/sbin/mount -t devfs devfs {$g['dhcpd_chroot_path']}/dev\n");
+ }
fclose($fd);
mwexec("/bin/sh {$g['tmp_path']}/dhcpd.sh");
- if ($family == "all" || $family == "inet")
+ if ($family == "all" || $family == "inet") {
services_dhcpdv4_configure();
+ }
if ($family == "all" || $family == "inet6") {
services_dhcpdv6_configure($blacklist);
services_radvd_configure($blacklist);
@@ -357,31 +388,37 @@ function services_dhcpdv4_configure() {
$need_ddns_updates = false;
$ddns_zones = array();
- if($g['services_dhcp_server_enable'] == false)
+ if ($g['services_dhcp_server_enable'] == false) {
return;
+ }
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "services_dhcpdv4_configure($if) being called $mt\n";
}
/* kill any running dhcpd */
- if (isvalidpid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpd.pid"))
+ if (isvalidpid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpd.pid")) {
killbypid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpd.pid");
+ }
/* DHCP enabled on any interfaces? */
- if (!is_dhcp_server_enabled())
+ if (!is_dhcp_server_enabled()) {
return 0;
+ }
/* if OLSRD is enabled, allow WAN to house DHCP. */
- if (!function_exists('is_package_installed'))
+ if (!function_exists('is_package_installed')) {
require_once('pkg-utils.inc');
- if (is_package_installed('olsrd') && isset($config['installedpackages']['olsrd']))
- foreach($config['installedpackages']['olsrd']['config'] as $olsrd)
+ }
+ if (is_package_installed('olsrd') && isset($config['installedpackages']['olsrd'])) {
+ foreach ($config['installedpackages']['olsrd']['config'] as $olsrd) {
if (isset($olsrd['enable']) && $olsrd['enable'] == "on") {
$is_olsr_enabled = true;
break;
}
+ }
+ }
if (platform_booting()) {
/* restore the leases, if we have them */
@@ -390,7 +427,7 @@ function services_dhcpdv4_configure() {
$dhcpreturn = "";
exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/dhcpleases.tgz 2>&1", $dhcprestore, $dhcpreturn);
$dhcprestore = implode(" ", $dhcprestore);
- if($dhcpreturn <> 0) {
+ if ($dhcpreturn <> 0) {
log_error(sprintf(gettext('DHCP leases restore failed exited with %1$s, the error is: %2$s%3$s'), $dhcpreturn, $dhcprestore, "\n"));
}
}
@@ -401,34 +438,37 @@ function services_dhcpdv4_configure() {
}
$syscfg = $config['system'];
- if (!is_array($config['dhcpd']))
+ if (!is_array($config['dhcpd'])) {
$config['dhcpd'] = array();
+ }
$dhcpdcfg = $config['dhcpd'];
$Iflist = get_configured_interface_list();
/* Only consider DNS servers with IPv4 addresses for the IPv4 DHCP server. */
$dns_arrv4 = array();
if (is_array($syscfg['dnsserver'])) {
- foreach($syscfg['dnsserver'] as $dnsserver) {
+ foreach ($syscfg['dnsserver'] as $dnsserver) {
if (is_ipaddrv4($dnsserver)) {
$dns_arrv4[] = $dnsserver;
}
}
}
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Starting DHCP service...");
- else
+ } else {
sleep(1);
+ }
$custoptions = "";
foreach ($dhcpdcfg as $dhcpif => $dhcpifconf) {
- if(is_array($dhcpifconf['numberoptions']) && is_array($dhcpifconf['numberoptions']['item'])) {
- foreach($dhcpifconf['numberoptions']['item'] as $itemidx => $item) {
- if(!empty($item['type']))
+ if (is_array($dhcpifconf['numberoptions']) && is_array($dhcpifconf['numberoptions']['item'])) {
+ foreach ($dhcpifconf['numberoptions']['item'] as $itemidx => $item) {
+ if (!empty($item['type'])) {
$itemtype = $item['type'];
- else
+ } else {
$itemtype = "text";
+ }
$custoptions .= "option custom-{$dhcpif}-{$itemidx} code {$item['number']} = {$itemtype};\n";
}
}
@@ -451,19 +491,21 @@ update-conflict-detection false;
EOD;
- if(!isset($dhcpifconf['disableauthoritative']))
+ if (!isset($dhcpifconf['disableauthoritative'])) {
$dhcpdconf .= "authoritative;\n";
+ }
- if(isset($dhcpifconf['alwaysbroadcast']))
+ if (isset($dhcpifconf['alwaysbroadcast'])) {
$dhcpdconf .= "always-broadcast on\n";
+ }
$dhcpdifs = array();
$enable_add_routers = false;
$gateways_arr = return_gateways_array();
/* only add a routers line if the system has any IPv4 gateway at all */
/* a static route has a gateway, manually overriding this field always works */
- foreach($gateways_arr as $gwitem) {
- if($gwitem['ipprotocol'] == "inet") {
+ foreach ($gateways_arr as $gwitem) {
+ if ($gwitem['ipprotocol'] == "inet") {
$enable_add_routers = true;
break;
}
@@ -474,28 +516,30 @@ EOD;
*/
foreach ($dhcpdcfg as $dhcpif => $dhcpifconf) {
- if (!isset($config['interfaces'][$dhcpif]['enable']))
+ if (!isset($config['interfaces'][$dhcpif]['enable'])) {
continue;
+ }
interfaces_staticarp_configure($dhcpif);
- if (!isset($dhcpifconf['enable']))
+ if (!isset($dhcpifconf['enable'])) {
continue;
+ }
- if($dhcpifconf['failover_peerip'] <> "") {
+ if ($dhcpifconf['failover_peerip'] <> "") {
$intip = get_interface_ip($dhcpif);
/*
* yep, failover peer is defined.
* does it match up to a defined vip?
*/
$skew = 110;
- if(is_array($config['virtualip']['vip'])) {
+ if (is_array($config['virtualip']['vip'])) {
foreach ($config['virtualip']['vip'] as $vipent) {
- if($vipent['interface'] == $dhcpif) {
+ if ($vipent['interface'] == $dhcpif) {
$carp_nw = gen_subnet($vipent['subnet'], $vipent['subnet_bits']);
if (ip_in_subnet($dhcpifconf['failover_peerip'], "{$carp_nw}/{$vipent['subnet_bits']}")) {
/* this is the interface! */
- if(is_numeric($vipent['advskew']) && (intval($vipent['advskew']) < 20)) {
+ if (is_numeric($vipent['advskew']) && (intval($vipent['advskew']) < 20)) {
$skew = 0;
break;
}
@@ -505,7 +549,7 @@ EOD;
} else {
log_error(gettext("Warning! DHCP Failover setup and no CARP virtual IPs defined!"));
}
- if($skew > 10) {
+ if ($skew > 10) {
$type = "secondary";
$my_port = "520";
$peer_port = "519";
@@ -518,7 +562,7 @@ EOD;
}
if (is_ipaddrv4($intip)) {
- $dhcpdconf .= <<<EOPP
+ $dhcpdconf .= <<<EOPP
failover peer "dhcp_{$dhcpif}" {
{$type};
address {$intip};
@@ -541,19 +585,23 @@ EOPP;
$newzone = array();
$ifcfg = $config['interfaces'][$dhcpif];
- if (!isset($dhcpifconf['enable']) || !isset($Iflist[$dhcpif]))
+ if (!isset($dhcpifconf['enable']) || !isset($Iflist[$dhcpif])) {
continue;
+ }
$ifcfgip = get_interface_ip($dhcpif);
$ifcfgsn = get_interface_subnet($dhcpif);
$subnet = gen_subnet($ifcfgip, $ifcfgsn);
$subnetmask = gen_subnet_mask($ifcfgsn);
- if (!is_ipaddr($subnet))
+ if (!is_ipaddr($subnet)) {
continue;
+ }
- if($is_olsr_enabled == true)
- if($dhcpifconf['netmask'])
+ if ($is_olsr_enabled == true) {
+ if ($dhcpifconf['netmask']) {
$subnetmask = gen_subnet_mask($dhcpifconf['netmask']);
+ }
+ }
$all_pools = array();
$all_pools[] = $dhcpifconf;
@@ -567,14 +615,14 @@ EOPP;
$dnscfg .= " option domain-name \"{$dhcpifconf['domain']}\";\n";
}
- if($dhcpifconf['domainsearchlist'] <> "") {
+ if ($dhcpifconf['domainsearchlist'] <> "") {
$dnscfg .= " option domain-search \"" . join("\",\"", preg_split("/[ ;]+/", $dhcpifconf['domainsearchlist'])) . "\";\n";
}
if (isset($dhcpifconf['ddnsupdate'])) {
$need_ddns_updates = true;
$newzone = array();
- if($dhcpifconf['ddnsdomain'] <> "") {
+ if ($dhcpifconf['ddnsdomain'] <> "") {
$newzone['domain-name'] = $dhcpifconf['ddnsdomain'];
$dnscfg .= " ddns-domainname \"{$dhcpifconf['ddnsdomain']}\";\n";
} else {
@@ -583,8 +631,9 @@ EOPP;
$revsubnet = explode(".", $subnet);
$revsubnet = array_reverse($revsubnet);
foreach ($revsubnet as $octet) {
- if ($octet != "0")
+ if ($octet != "0") {
break;
+ }
array_shift($revsubnet);
}
$newzone['ptr-domain'] = implode(".", $revsubnet) . ".in-addr.arpa";
@@ -592,25 +641,28 @@ EOPP;
if (is_array($dhcpifconf['dnsserver']) && ($dhcpifconf['dnsserver'][0])) {
$dnscfg .= " option domain-name-servers " . join(",", $dhcpifconf['dnsserver']) . ";";
- if ($newzone['domain-name'])
+ if ($newzone['domain-name']) {
$newzone['dns-servers'] = $dhcpifconf['dnsserver'];
+ }
} else if (isset($config['dnsmasq']['enable'])) {
$dnscfg .= " option domain-name-servers {$ifcfgip};";
- if ($newzone['domain-name'] && is_array($syscfg['dnsserver']) && ($syscfg['dnsserver'][0]))
+ if ($newzone['domain-name'] && is_array($syscfg['dnsserver']) && ($syscfg['dnsserver'][0])) {
$newzone['dns-servers'] = $syscfg['dnsserver'];
+ }
} else if (isset($config['unbound']['enable'])) {
$dnscfg .= " option domain-name-servers {$ifcfgip};";
} else if (!empty($dns_arrv4)) {
$dnscfg .= " option domain-name-servers " . join(",", $dns_arrv4) . ";";
- if ($newzone['domain-name'])
+ if ($newzone['domain-name']) {
$newzone['dns-servers'] = $dns_arrv4;
+ }
}
- /* Create classes - These all contain comma separated lists. Join them into one
+ /* Create classes - These all contain comma separated lists. Join them into one
big comma separated string then split them all up. */
$all_mac_strings = array();
if (is_array($dhcpifconf['pool'])) {
- foreach($all_pools as $poolconf) {
+ foreach ($all_pools as $poolconf) {
$all_mac_strings[] = $poolconf['mac_allow'];
$all_mac_strings[] = $poolconf['mac_deny'];
}
@@ -619,8 +671,9 @@ EOPP;
$all_mac_strings[] = $dhcpifconf['mac_deny'];
$all_mac_list = array_unique(explode(',', implode(',', $all_mac_strings)));
foreach ($all_mac_list as $mac) {
- if (empty($mac))
+ if (empty($mac)) {
continue;
+ }
$dhcpdconf .= 'class "' . str_replace(':', '', $mac) . '" {' . "\n";
// Skip the first octet of the MAC address - for media type, typically Ethernet ("01") and match the rest.
$dhcpdconf .= ' match if substring (hardware, 1, ' . (substr_count($mac, ':') + 1) . ') = ' . $mac . ';' . "\n";
@@ -629,45 +682,53 @@ EOPP;
$dhcpdconf .= "subnet {$subnet} netmask {$subnetmask} {\n";
-// Setup pool options
- foreach($all_pools as $poolconf) {
+ // Setup pool options
+ foreach ($all_pools as $poolconf) {
$dhcpdconf .= " pool {\n";
/* is failover dns setup? */
if (is_array($poolconf['dnsserver']) && $poolconf['dnsserver'][0] <> "") {
$dhcpdconf .= " option domain-name-servers {$poolconf['dnsserver'][0]}";
- if($poolconf['dnsserver'][1] <> "")
+ if ($poolconf['dnsserver'][1] <> "") {
$dhcpdconf .= ",{$poolconf['dnsserver'][1]}";
- if($poolconf['dnsserver'][2] <> "")
+ }
+ if ($poolconf['dnsserver'][2] <> "") {
$dhcpdconf .= ",{$poolconf['dnsserver'][2]}";
- if($poolconf['dnsserver'][3] <> "")
+ }
+ if ($poolconf['dnsserver'][3] <> "") {
$dhcpdconf .= ",{$poolconf['dnsserver'][3]}";
+ }
$dhcpdconf .= ";\n";
}
/* allow/deny MACs */
$mac_allow_list = array_unique(explode(',', $poolconf['mac_allow']));
foreach ($mac_allow_list as $mac) {
- if (empty($mac))
+ if (empty($mac)) {
continue;
+ }
$dhcpdconf .= " allow members of \"" . str_replace(':', '', $mac) . "\";\n";
}
$mac_deny_list = array_unique(explode(',', $poolconf['mac_deny']));
foreach ($mac_deny_list as $mac) {
- if (empty($mac))
+ if (empty($mac)) {
continue;
+ }
$dhcpdconf .= " deny members of \"" . str_replace(':', '', $mac) . "\";\n";
}
- if($poolconf['failover_peerip'] <> "")
+ if ($poolconf['failover_peerip'] <> "") {
$dhcpdconf .= " deny dynamic bootp clients;\n";
+ }
- if (isset($poolconf['denyunknown']))
+ if (isset($poolconf['denyunknown'])) {
$dhcpdconf .= " deny unknown-clients;\n";
+ }
- if ($poolconf['gateway'] && $poolconf['gateway'] != "none" && ($poolconf['gateway'] != $dhcpifconf['gateway']))
+ if ($poolconf['gateway'] && $poolconf['gateway'] != "none" && ($poolconf['gateway'] != $dhcpifconf['gateway'])) {
$dhcpdconf .= " option routers {$poolconf['gateway']};\n";
+ }
- if($dhcpifconf['failover_peerip'] <> "") {
+ if ($dhcpifconf['failover_peerip'] <> "") {
$dhcpdconf .= " failover peer \"dhcp_{$dhcpif}\";\n";
}
@@ -677,13 +738,14 @@ EOPP;
$pdnscfg .= " option domain-name \"{$poolconf['domain']}\";\n";
}
- if(!empty($poolconf['domainsearchlist']) && ($poolconf['domainsearchlist'] != $dhcpifconf['domainsearchlist'])) {
+ if (!empty($poolconf['domainsearchlist']) && ($poolconf['domainsearchlist'] != $dhcpifconf['domainsearchlist'])) {
$pdnscfg .= " option domain-search \"" . join("\",\"", preg_split("/[ ;]+/", $poolconf['domainsearchlist'])) . "\";\n";
}
if (isset($poolconf['ddnsupdate'])) {
- if (($poolconf['ddnsdomain'] <> "") && ($poolconf['ddnsdomain'] != $dhcpifconf['ddnsdomain']))
+ if (($poolconf['ddnsdomain'] <> "") && ($poolconf['ddnsdomain'] != $dhcpifconf['ddnsdomain'])) {
$pdnscfg .= " ddns-domainname \"{$poolconf['ddnsdomain']}\";\n";
+ }
$pdnscfg .= " ddns-update-style interim;\n";
}
@@ -693,12 +755,14 @@ EOPP;
$dhcpdconf .= "{$pdnscfg}";
// default-lease-time
- if ($poolconf['defaultleasetime'] && ($poolconf['defaultleasetime'] != $dhcpifconf['defaultleasetime']))
+ if ($poolconf['defaultleasetime'] && ($poolconf['defaultleasetime'] != $dhcpifconf['defaultleasetime'])) {
$dhcpdconf .= " default-lease-time {$poolconf['defaultleasetime']};\n";
+ }
// max-lease-time
- if ($poolconf['maxleasetime'] && ($poolconf['maxleasetime'] != $dhcpifconf['maxleasetime']))
+ if ($poolconf['maxleasetime'] && ($poolconf['maxleasetime'] != $dhcpifconf['maxleasetime'])) {
$dhcpdconf .= " max-lease-time {$poolconf['maxleasetime']};\n";
+ }
// netbios-name*
if (is_array($poolconf['winsserver']) && $poolconf['winsserver'][0] && ($poolconf['winsserver'][0] != $dhcpifconf['winsserver'][0])) {
@@ -707,19 +771,22 @@ EOPP;
}
// ntp-servers
- if (is_array($poolconf['ntpserver']) && $poolconf['ntpserver'][0] && ($poolconf['ntpserver'][0] != $dhcpifconf['ntpserver'][0]))
+ if (is_array($poolconf['ntpserver']) && $poolconf['ntpserver'][0] && ($poolconf['ntpserver'][0] != $dhcpifconf['ntpserver'][0])) {
$dhcpdconf .= " option ntp-servers " . join(",", $poolconf['ntpserver']) . ";\n";
+ }
// tftp-server-name
- if (!empty($poolconf['tftp']) && ($poolconf['tftp'] != $dhcpifconf['tftp']))
+ if (!empty($poolconf['tftp']) && ($poolconf['tftp'] != $dhcpifconf['tftp'])) {
$dhcpdconf .= " option tftp-server-name \"{$poolconf['tftp']}\";\n";
+ }
// ldap-server
- if (!empty($poolconf['ldap']) && ($poolconf['ldap'] != $dhcpifconf['ldap']))
+ if (!empty($poolconf['ldap']) && ($poolconf['ldap'] != $dhcpifconf['ldap'])) {
$dhcpdconf .= " option ldap-server \"{$poolconf['ldap']}\";\n";
+ }
// net boot information
- if(isset($poolconf['netboot'])) {
+ if (isset($poolconf['netboot'])) {
if (!empty($poolconf['nextserver']) && ($poolconf['nextserver'] != $dhcpifconf['nextserver'])) {
$dhcpdconf .= " next-server {$poolconf['nextserver']};\n";
}
@@ -744,20 +811,23 @@ EOPP;
$add_routers = $enable_add_routers;
$routers = $ifcfgip;
}
- if($add_routers)
+ if ($add_routers) {
$dhcpdconf .= " option routers {$routers};\n";
+ }
$dhcpdconf .= <<<EOD
$dnscfg
EOD;
- // default-lease-time
- if ($dhcpifconf['defaultleasetime'])
+ // default-lease-time
+ if ($dhcpifconf['defaultleasetime']) {
$dhcpdconf .= " default-lease-time {$dhcpifconf['defaultleasetime']};\n";
+ }
// max-lease-time
- if ($dhcpifconf['maxleasetime'])
+ if ($dhcpifconf['maxleasetime']) {
$dhcpdconf .= " max-lease-time {$dhcpifconf['maxleasetime']};\n";
+ }
// netbios-name*
if (is_array($dhcpifconf['winsserver']) && $dhcpifconf['winsserver'][0]) {
@@ -766,30 +836,34 @@ EOD;
}
// ntp-servers
- if (is_array($dhcpifconf['ntpserver']) && $dhcpifconf['ntpserver'][0])
+ if (is_array($dhcpifconf['ntpserver']) && $dhcpifconf['ntpserver'][0]) {
$dhcpdconf .= " option ntp-servers " . join(",", $dhcpifconf['ntpserver']) . ";\n";
+ }
// tftp-server-name
- if ($dhcpifconf['tftp'] <> "")
+ if ($dhcpifconf['tftp'] <> "") {
$dhcpdconf .= " option tftp-server-name \"{$dhcpifconf['tftp']}\";\n";
+ }
// Handle option, number rowhelper values
$dhcpdconf .= "\n";
- if($dhcpifconf['numberoptions']['item']) {
- foreach($dhcpifconf['numberoptions']['item'] as $itemidx => $item) {
- if(empty($item['type']) || $item['type'] == "text")
+ if ($dhcpifconf['numberoptions']['item']) {
+ foreach ($dhcpifconf['numberoptions']['item'] as $itemidx => $item) {
+ if (empty($item['type']) || $item['type'] == "text") {
$dhcpdconf .= " option custom-{$dhcpif}-{$itemidx} \"{$item['value']}\";\n";
- else
+ } else {
$dhcpdconf .= " option custom-{$dhcpif}-{$itemidx} {$item['value']};\n";
+ }
}
}
// ldap-server
- if ($dhcpifconf['ldap'] <> "")
+ if ($dhcpifconf['ldap'] <> "") {
$dhcpdconf .= " option ldap-server \"{$dhcpifconf['ldap']}\";\n";
+ }
// net boot information
- if(isset($dhcpifconf['netboot'])) {
+ if (isset($dhcpifconf['netboot'])) {
if ($dhcpifconf['nextserver'] <> "") {
$dhcpdconf .= " next-server {$dhcpifconf['nextserver']};\n";
}
@@ -821,28 +895,34 @@ EOD;
foreach ($dhcpifconf['staticmap'] as $sm) {
$dhcpdconf .= "host s_{$dhcpif}_{$i} {\n";
- if ($sm['mac'])
- $dhcpdconf .= " hardware ethernet {$sm['mac']};\n";
+ if ($sm['mac']) {
+ $dhcpdconf .= " hardware ethernet {$sm['mac']};\n";
+ }
- if ($sm['cid'])
- $dhcpdconf .= " option dhcp-client-identifier \"{$sm['cid']}\";\n";
+ if ($sm['cid']) {
+ $dhcpdconf .= " option dhcp-client-identifier \"{$sm['cid']}\";\n";
+ }
- if ($sm['ipaddr'])
+ if ($sm['ipaddr']) {
$dhcpdconf .= " fixed-address {$sm['ipaddr']};\n";
+ }
if ($sm['hostname']) {
$dhhostname = str_replace(" ", "_", $sm['hostname']);
$dhhostname = str_replace(".", "_", $dhhostname);
$dhcpdconf .= " option host-name \"{$dhhostname}\";\n";
}
- if ($sm['filename'])
+ if ($sm['filename']) {
$dhcpdconf .= " filename \"{$sm['filename']}\";\n";
+ }
- if ($sm['rootpath'])
+ if ($sm['rootpath']) {
$dhcpdconf .= " option root-path \"{$sm['rootpath']}\";\n";
+ }
- if ($sm['gateway'] && ($sm['gateway'] != $dhcpifconf['gateway']))
+ if ($sm['gateway'] && ($sm['gateway'] != $dhcpifconf['gateway'])) {
$dhcpdconf .= " option routers {$sm['gateway']};\n";
+ }
$smdnscfg = "";
@@ -850,13 +930,14 @@ EOD;
$smdnscfg .= " option domain-name \"{$sm['domain']}\";\n";
}
- if(!empty($sm['domainsearchlist']) && ($sm['domainsearchlist'] != $dhcpifconf['domainsearchlist'])) {
+ if (!empty($sm['domainsearchlist']) && ($sm['domainsearchlist'] != $dhcpifconf['domainsearchlist'])) {
$smdnscfg .= " option domain-search \"" . join("\",\"", preg_split("/[ ;]+/", $sm['domainsearchlist'])) . "\";\n";
}
if (isset($sm['ddnsupdate'])) {
- if (($sm['ddnsdomain'] <> "") && ($sm['ddnsdomain'] != $dhcpifconf['ddnsdomain']))
+ if (($sm['ddnsdomain'] <> "") && ($sm['ddnsdomain'] != $dhcpifconf['ddnsdomain'])) {
$pdnscfg .= " ddns-domainname \"{$sm['ddnsdomain']}\";\n";
+ }
$pdnscfg .= " ddns-update-style interim;\n";
}
@@ -866,12 +947,14 @@ EOD;
$dhcpdconf .= "{$smdnscfg}";
// default-lease-time
- if ($sm['defaultleasetime'] && ($sm['defaultleasetime'] != $dhcpifconf['defaultleasetime']))
+ if ($sm['defaultleasetime'] && ($sm['defaultleasetime'] != $dhcpifconf['defaultleasetime'])) {
$dhcpdconf .= " default-lease-time {$sm['defaultleasetime']};\n";
+ }
// max-lease-time
- if ($sm['maxleasetime'] && ($sm['maxleasetime'] != $dhcpifconf['maxleasetime']))
+ if ($sm['maxleasetime'] && ($sm['maxleasetime'] != $dhcpifconf['maxleasetime'])) {
$dhcpdconf .= " max-lease-time {$sm['maxleasetime']};\n";
+ }
// netbios-name*
if (is_array($sm['winsserver']) && $sm['winsserver'][0] && ($sm['winsserver'][0] != $dhcpifconf['winsserver'][0])) {
@@ -880,12 +963,14 @@ EOD;
}
// ntp-servers
- if (is_array($sm['ntpserver']) && $sm['ntpserver'][0] && ($sm['ntpserver'][0] != $dhcpifconf['ntpserver'][0]))
+ if (is_array($sm['ntpserver']) && $sm['ntpserver'][0] && ($sm['ntpserver'][0] != $dhcpifconf['ntpserver'][0])) {
$dhcpdconf .= " option ntp-servers " . join(",", $sm['ntpserver']) . ";\n";
+ }
// tftp-server-name
- if (!empty($sm['tftp']) && ($sm['tftp'] != $dhcpifconf['tftp']))
+ if (!empty($sm['tftp']) && ($sm['tftp'] != $dhcpifconf['tftp'])) {
$dhcpdconf .= " option tftp-server-name \"{$sm['tftp']}\";\n";
+ }
$dhcpdconf .= "}\n";
$i++;
@@ -893,10 +978,8 @@ EOD;
}
$dhcpdifs[] = get_real_interface($dhcpif);
- if ($newzone['domain-name'])
- {
- if ($need_ddns_updates)
- {
+ if ($newzone['domain-name']) {
+ if ($need_ddns_updates) {
$newzone['dns-servers'] = array($dhcpifconf['ddnsdomainprimary']);
}
$ddns_zones[] = $newzone;
@@ -920,11 +1003,12 @@ EOD;
unset($dhcpdconf);
/* create an empty leases database */
- if (!file_exists("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases"))
+ if (!file_exists("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases")) {
@touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases");
+ }
/* make sure there isn't a stale dhcpd.pid file, which can make dhcpd fail to start. */
- /* if we get here, dhcpd has been killed and is not started yet */
+ /* if we get here, dhcpd has been killed and is not started yet */
unlink_if_exists("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpd.pid");
/* fire up dhcpd in a chroot */
@@ -933,8 +1017,9 @@ EOD;
join(" ", $dhcpdifs));
}
- if (platform_booting())
+ if (platform_booting()) {
print "done.\n";
+ }
return 0;
}
@@ -942,8 +1027,7 @@ EOD;
function dhcpdkey($dhcpifconf)
{
$dhcpdconf = "";
- if ($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "")
- {
+ if ($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "") {
$dhcpdconf .= "key {$dhcpifconf['ddnsdomainkeyname']} {\n";
$dhcpdconf .= " algorithm hmac-md5;\n";
$dhcpdconf .= " secret {$dhcpifconf['ddnsdomainkey']};\n";
@@ -960,8 +1044,9 @@ function dhcpdzones($ddns_zones, $dhcpifconf)
if (is_array($ddns_zones)) {
$added_zones = array();
foreach ($ddns_zones as $zone) {
- if (!is_array($zone) || empty($zone) || !is_array($zone['dns-servers']))
+ if (!is_array($zone) || empty($zone) || !is_array($zone['dns-servers'])) {
continue;
+ }
$primary = $zone['dns-servers'][0];
$secondary = empty($zone['dns-servers'][1]) ? "" : $zone['dns-servers'][1];
@@ -979,20 +1064,24 @@ function dhcpdzones($ddns_zones, $dhcpifconf)
if ($zone['domain-name'] && !in_array($zone['domain-name'], $added_zones)) {
$dhcpdconf .= "zone {$zone['domain-name']}. {\n";
$dhcpdconf .= " primary {$primary};\n";
- if (is_ipaddrv4($secondary))
+ if (is_ipaddrv4($secondary)) {
$dhcpdconf .= " secondary {$secondary};\n";
- if($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "")
- $dhcpdconf .= " key {$dhcpifconf['ddnsdomainkeyname']};\n";
+ }
+ if ($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "") {
+ $dhcpdconf .= " key {$dhcpifconf['ddnsdomainkeyname']};\n";
+ }
$dhcpdconf .= "}\n";
$added_zones[] = $zone['domain-name'];
}
if ($zone['ptr-domain'] && !in_array($zone['ptr-domain'], $added_zones)) {
$dhcpdconf .= "zone {$zone['ptr-domain']} {\n";
$dhcpdconf .= " primary {$primary};\n";
- if (is_ipaddrv4($secondary))
+ if (is_ipaddrv4($secondary)) {
$dhcpdconf .= " secondary {$secondary};\n";
- if($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "")
- $dhcpdconf .= " key {$dhcpifconf['ddnsdomainkeyname']};\n";
+ }
+ if ($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "") {
+ $dhcpdconf .= " key {$dhcpifconf['ddnsdomainkeyname']};\n";
+ }
$dhcpdconf .= "}\n";
$added_zones[] = $zone['ptr-domain'];
}
@@ -1005,23 +1094,27 @@ function dhcpdzones($ddns_zones, $dhcpifconf)
function services_dhcpdv6_configure($blacklist = array()) {
global $config, $g;
- if($g['services_dhcp_server_enable'] == false)
+ if ($g['services_dhcp_server_enable'] == false) {
return;
+ }
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "services_dhcpd_configure($if) being called $mt\n";
}
/* kill any running dhcpd */
- if (isvalidpid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid"))
+ if (isvalidpid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid")) {
killbypid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid");
- if (isvalidpid("{$g['varrun_path']}/dhcpleases6.pid"))
+ }
+ if (isvalidpid("{$g['varrun_path']}/dhcpleases6.pid")) {
killbypid("{$g['varrun_path']}/dhcpleases6.pid");
+ }
/* DHCP enabled on any interfaces? */
- if (!is_dhcpv6_server_enabled())
+ if (!is_dhcpv6_server_enabled()) {
return 0;
+ }
if (platform_booting()) {
if ($g['platform'] != "pfSense") {
@@ -1031,7 +1124,7 @@ function services_dhcpdv6_configure($blacklist = array()) {
$dhcpreturn = "";
exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/dhcp6leases.tgz 2>&1", $dhcprestore, $dhcpreturn);
$dhcprestore = implode(" ", $dhcprestore);
- if($dhcpreturn <> 0) {
+ if ($dhcpreturn <> 0) {
log_error("DHCP leases v6 restore failed exited with $dhcpreturn, the error is: $dhcprestore\n");
}
}
@@ -1039,28 +1132,32 @@ function services_dhcpdv6_configure($blacklist = array()) {
}
$syscfg = $config['system'];
- if (!is_array($config['dhcpdv6']))
+ if (!is_array($config['dhcpdv6'])) {
$config['dhcpdv6'] = array();
+ }
$dhcpdv6cfg = $config['dhcpdv6'];
$Iflist = get_configured_interface_list();
$Iflist = array_merge($Iflist, get_configured_pppoe_server_interfaces());
- if (platform_booting())
+ if (platform_booting()) {
echo "Starting DHCPv6 service...";
- else
+ } else {
sleep(1);
+ }
/* we add a fake entry for interfaces that are set to track6 another WAN */
foreach ($Iflist as $ifname) {
/* Do not put in the config an interface which is down */
- if (isset($blacklist[$ifname]))
+ if (isset($blacklist[$ifname])) {
continue;
+ }
if (!empty($config['interfaces'][$ifname]['track6-interface'])) {
$realif = get_real_interface($ifname, "inet6");
$ifcfgipv6 = get_interface_ipv6($ifname);
- if(!is_ipaddrv6($ifcfgipv6))
+ if (!is_ipaddrv6($ifcfgipv6)) {
continue;
+ }
$ifcfgipv6 = Net_IPv6::getNetmask($ifcfgipv6, 64);
$trackifname = $config['interfaces'][$ifname]['track6-interface'];
$trackcfg = $config['interfaces'][$trackifname];
@@ -1075,7 +1172,7 @@ function services_dhcpdv6_configure($blacklist = array()) {
$ifcfgipv6arr[7] = "2000";
$dhcpdv6cfg[$ifname]['range']['to'] = Net_IPv6::compress(implode(":", $ifcfgipv6arr));
/* prefix length > 0? We can add dhcp6 prefix delegation server */
- if($pdlen > 2) {
+ if ($pdlen > 2) {
$pdlenmax = $pdlen;
$pdlenhalf = $pdlenmax -1;
$pdlenmin = (64 - ceil($pdlenhalf / 4));
@@ -1099,15 +1196,16 @@ function services_dhcpdv6_configure($blacklist = array()) {
$custoptionsv6 = "";
foreach ($dhcpdv6cfg as $dhcpv6if => $dhcpv6ifconf) {
- if(is_array($dhcpv6ifconf['numberoptions']) && is_array($dhcpv6ifconf['numberoptions']['item'])) {
- foreach($dhcpv6ifconf['numberoptions']['item'] as $itemv6idx => $itemv6) {
+ if (is_array($dhcpv6ifconf['numberoptions']) && is_array($dhcpv6ifconf['numberoptions']['item'])) {
+ foreach ($dhcpv6ifconf['numberoptions']['item'] as $itemv6idx => $itemv6) {
$custoptionsv6 .= "option custom-{$dhcpv6if}-{$itemv6idx} code {$itemv6['number']} = text;\n";
}
}
}
- if(isset($dhcpv6ifconf['netboot']) && !empty($dhcpv6ifconf['bootfile_url']))
+ if (isset($dhcpv6ifconf['netboot']) && !empty($dhcpv6ifconf['bootfile_url'])) {
$custoptionsv6 .= "option dhcp6.bootfile-url code 59 = string;\n";
+ }
$dhcpdv6conf = <<<EOD
@@ -1125,11 +1223,13 @@ update-conflict-detection false;
EOD;
- if(!isset($dhcpv6ifconf['disableauthoritative']))
+ if (!isset($dhcpv6ifconf['disableauthoritative'])) {
$dhcpdv6conf .= "authoritative;\n";
+ }
- if(isset($dhcpv6ifconf['alwaysbroadcast']))
+ if (isset($dhcpv6ifconf['alwaysbroadcast'])) {
$dhcpdv6conf .= "always-broadcast on\n";
+ }
$dhcpdv6ifs = array();
@@ -1142,15 +1242,17 @@ EOD;
$ifcfgv6 = $config['interfaces'][$dhcpv6if];
- if (!isset($dhcpv6ifconf['enable']) || !isset($Iflist[$dhcpv6if]) || !isset($ifcfgv6['enable']))
+ if (!isset($dhcpv6ifconf['enable']) || !isset($Iflist[$dhcpv6if]) || !isset($ifcfgv6['enable'])) {
continue;
+ }
$ifcfgipv6 = get_interface_ipv6($dhcpv6if);
$ifcfgsnv6 = get_interface_subnetv6($dhcpv6if);
$subnetv6 = gen_subnetv6($ifcfgipv6, $ifcfgsnv6);
if ($is_olsr_enabled == true) {
- if($dhcpv6ifconf['netmask'])
+ if ($dhcpv6ifconf['netmask']) {
$subnetmask = gen_subnet_maskv6($dhcpv6ifconf['netmask']);
+ }
}
$dnscfgv6 = "";
@@ -1159,12 +1261,12 @@ EOD;
$dnscfgv6 .= " option domain-name \"{$dhcpv6ifconf['domain']}\";\n";
}
- if ($dhcpv6ifconf['domainsearchlist'] <> "") {
+ if ($dhcpv6ifconf['domainsearchlist'] <> "") {
$dnscfgv6 .= " option domain-search \"" . join("\",\"", preg_split("/[ ;]+/", $dhcpv6ifconf['domainsearchlist'])) . "\";\n";
- }
+ }
if (isset($dhcpv6ifconf['ddnsupdate'])) {
- if($dhcpv6ifconf['ddnsdomain'] <> "") {
+ if ($dhcpv6ifconf['ddnsdomain'] <> "") {
$dnscfgv6 .= " ddns-domainname \"{$dhcpv6ifconf['ddnsdomain']}\";\n";
}
$dnscfgv6 .= " ddns-update-style interim;\n";
@@ -1177,18 +1279,19 @@ EOD;
$dnscfgv6 .= " option dhcp6.name-servers {$ifcfgipv6};";
} else if (is_array($syscfg['dnsserver']) && ($syscfg['dnsserver'][0])) {
$dns_arrv6 = array();
- foreach($syscfg['dnsserver'] as $dnsserver) {
+ foreach ($syscfg['dnsserver'] as $dnsserver) {
if (is_ipaddrv6($dnsserver)) {
$dns_arrv6[] = $dnsserver;
}
}
- if(!empty($dns_arrv6))
+ if (!empty($dns_arrv6)) {
$dnscfgv6 .= " option dhcp6.name-servers " . join(",", $dns_arrv6) . ";";
+ }
}
if ($dhcpv6ifconf['domain']) {
$newzone = array();
- $newzone['domain-name'] = $dhcpv6ifconf['domain'];
+ $newzone['domain-name'] = $dhcpv6ifconf['domain'];
$newzone['dns-servers'][] = $dhcpv6ifconf['ddnsdomainprimary'];
$ddns_zones[] = $newzone;
}
@@ -1213,44 +1316,50 @@ EOD;
if (is_ipaddrv6($dhcpv6ifconf['dns6ip'])) {
$dhcpdv6conf .= " option dhcp6.name-servers {$dhcpv6ifconf['dns6ip']};\n";
}
- // default-lease-time
- if ($dhcpv6ifconf['defaultleasetime'])
+ // default-lease-time
+ if ($dhcpv6ifconf['defaultleasetime']) {
$dhcpdv6conf .= " default-lease-time {$dhcpv6ifconf['defaultleasetime']};\n";
+ }
// max-lease-time
- if ($dhcpv6ifconf['maxleasetime'])
+ if ($dhcpv6ifconf['maxleasetime']) {
$dhcpdv6conf .= " max-lease-time {$dhcpv6ifconf['maxleasetime']};\n";
+ }
// ntp-servers
if (is_array($dhcpv6ifconf['ntpserver']) && $dhcpv6ifconf['ntpserver'][0]) {
$ntpservers = array();
- foreach($dhcpv6ifconf['ntpserver'] as $ntpserver) {
- if(is_ipaddrv6($ntpserver))
+ foreach ($dhcpv6ifconf['ntpserver'] as $ntpserver) {
+ if (is_ipaddrv6($ntpserver)) {
$ntpservers[] = $ntpserver;
+ }
}
- if(count($ntpservers) > 0 )
+ if (count($ntpservers) > 0) {
$dhcpdv6conf .= " option dhcp6.sntp-servers " . join(",", $dhcpv6ifconf['ntpserver']) . ";\n";
+ }
}
// tftp-server-name
/* Needs ISC DHCPD support
- if ($dhcpv6ifconf['tftp'] <> "")
+ if ($dhcpv6ifconf['tftp'] <> "") {
$dhcpdv6conf .= " option tftp-server-name \"{$dhcpv6ifconf['tftp']}\";\n";
+ }
*/
// Handle option, number rowhelper values
$dhcpdv6conf .= "\n";
if ($dhcpv6ifconf['numberoptions']['item']) {
- foreach($dhcpv6ifconf['numberoptions']['item'] as $itemv6idx => $itemv6) {
+ foreach ($dhcpv6ifconf['numberoptions']['item'] as $itemv6idx => $itemv6) {
$dhcpdv6conf .= " option custom-{$dhcpv6if}-{$itemv6idx} \"{$itemv6['value']}\";\n";
}
}
// ldap-server
- if ($dhcpv6ifconf['ldap'] <> "")
+ if ($dhcpv6ifconf['ldap'] <> "") {
$dhcpdv6conf .= " option ldap-server \"{$dhcpv6ifconf['ldap']}\";\n";
+ }
// net boot information
- if(isset($dhcpv6ifconf['netboot'])) {
+ if (isset($dhcpv6ifconf['netboot'])) {
if (!empty($dhcpv6ifconf['bootfile_url'])) {
$dhcpdv6conf .= " option dhcp6.bootfile-url \"{$dhcpv6ifconf['bootfile_url']}\";\n";
}
@@ -1268,33 +1377,35 @@ host s_{$dhcpv6if}_{$i} {
host-identifier option dhcp6.client-id {$sm['duid']};
EOD;
- if ($sm['ipaddrv6'])
+ if ($sm['ipaddrv6']) {
$dhcpdv6conf .= " fixed-address6 {$sm['ipaddrv6']};\n";
+ }
if ($sm['hostname']) {
$dhhostname = str_replace(" ", "_", $sm['hostname']);
$dhhostname = str_replace(".", "_", $dhhostname);
$dhcpdv6conf .= " option host-name {$dhhostname};\n";
}
- if ($sm['filename'])
+ if ($sm['filename']) {
$dhcpdv6conf .= " filename \"{$sm['filename']}\";\n";
+ }
- if ($sm['rootpath'])
+ if ($sm['rootpath']) {
$dhcpdv6conf .= " option root-path \"{$sm['rootpath']}\";\n";
+ }
$dhcpdv6conf .= "}\n";
$i++;
}
}
- if ($dhcpv6ifconf['domain'])
- {
+ if ($dhcpv6ifconf['domain']) {
$dhcpdv6conf .= dhcpdkey($dhcpv6ifconf);
$dhcpdv6conf .= dhcpdzones($ddns_zones, $dhcpv6ifconf);
}
if ($config['dhcpdv6'][$dhcpv6if]['ramode'] <> "unmanaged" && isset($config['interfaces'][$dhcpv6if]['enable'])) {
- if(preg_match("/poes/si", $dhcpv6if)) {
+ if (preg_match("/poes/si", $dhcpv6if)) {
/* magic here */
$dhcpdv6ifs = array_merge($dhcpdv6ifs, get_pppoes_child_interfaces($dhcpv6if));
} else {
@@ -1311,32 +1422,31 @@ EOD;
}
}
- if ($nsupdate)
- {
+ if ($nsupdate) {
$dhcpdv6conf .= "ddns-update-style interim;\n";
- }
- else
- {
+ } else {
$dhcpdv6conf .= "ddns-update-style none;\n";
}
/* write dhcpdv6.conf */
if (!@file_put_contents("{$g['dhcpd_chroot_path']}/etc/dhcpdv6.conf", $dhcpdv6conf)) {
log_error("Error: cannot open {$g['dhcpd_chroot_path']}/etc/dhcpdv6.conf in services_dhcpdv6_configure().\n");
- if (platform_booting())
+ if (platform_booting()) {
printf("Error: cannot open {$g['dhcpd_chroot_path']}/etc/dhcpdv6.conf in services_dhcpdv6_configure().\n");
+ }
unset($dhcpdv6conf);
return 1;
}
unset($dhcpdv6conf);
/* create an empty leases v6 database */
- if (!file_exists("{$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases"))
+ if (!file_exists("{$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases")) {
@touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases");
+ }
- /* make sure there isn't a stale dhcpdv6.pid file, which may make dhcpdv6 fail to start. */
- /* if we get here, dhcpdv6 has been killed and is not started yet */
- unlink_if_exists("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid");
+ /* make sure there isn't a stale dhcpdv6.pid file, which may make dhcpdv6 fail to start. */
+ /* if we get here, dhcpdv6 has been killed and is not started yet */
+ unlink_if_exists("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid");
/* fire up dhcpd in a chroot */
if (count($dhcpdv6ifs) > 0) {
@@ -1344,24 +1454,26 @@ EOD;
join(" ", $dhcpdv6ifs));
mwexec("/usr/local/sbin/dhcpleases6 -c \"/usr/local/bin/php -f /usr/local/sbin/prefixes.php|/bin/sh\" -l {$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases");
}
- if (platform_booting())
+ if (platform_booting()) {
print gettext("done.") . "\n";
+ }
return 0;
}
function services_igmpproxy_configure() {
- global $config, $g;
+ global $config, $g;
- /* kill any running igmpproxy */
- killbyname("igmpproxy");
+ /* kill any running igmpproxy */
+ killbyname("igmpproxy");
- if (!is_array($config['igmpproxy']['igmpentry']) || (count($config['igmpproxy']['igmpentry']) == 0))
+ if (!is_array($config['igmpproxy']['igmpentry']) || (count($config['igmpproxy']['igmpentry']) == 0)) {
return 1;
+ }
- $iflist = get_configured_interface_list();
+ $iflist = get_configured_interface_list();
- $igmpconf = <<<EOD
+ $igmpconf = <<<EOD
##------------------------------------------------------
## Enable Quickleave mode (Sends Leave instantly)
@@ -1370,49 +1482,52 @@ quickleave
EOD;
- foreach ($config['igmpproxy']['igmpentry'] as $igmpcf) {
- unset($iflist[$igmpcf['ifname']]);
- $realif = get_real_interface($igmpcf['ifname']);
- if (empty($igmpcf['threshold']))
- $threshld = 1;
- else
- $threshld = $igmpcf['threshold'];
- $igmpconf .= "phyint {$realif} {$igmpcf['type']} ratelimit 0 threshold {$threshld}\n";
-
- if ($igmpcf['address'] <> "") {
- $item = explode(" ", $igmpcf['address']);
- foreach($item as $iww)
- $igmpconf .= "altnet {$iww}\n";
- }
- $igmpconf .= "\n";
- }
- foreach ($iflist as $ifn) {
- $realif = get_real_interface($ifn);
- $igmpconf .= "phyint {$realif} disabled\n";
- }
+ foreach ($config['igmpproxy']['igmpentry'] as $igmpcf) {
+ unset($iflist[$igmpcf['ifname']]);
+ $realif = get_real_interface($igmpcf['ifname']);
+ if (empty($igmpcf['threshold'])) {
+ $threshld = 1;
+ } else {
+ $threshld = $igmpcf['threshold'];
+ }
+ $igmpconf .= "phyint {$realif} {$igmpcf['type']} ratelimit 0 threshold {$threshld}\n";
+
+ if ($igmpcf['address'] <> "") {
+ $item = explode(" ", $igmpcf['address']);
+ foreach ($item as $iww) {
+ $igmpconf .= "altnet {$iww}\n";
+ }
+ }
+ $igmpconf .= "\n";
+ }
+ foreach ($iflist as $ifn) {
+ $realif = get_real_interface($ifn);
+ $igmpconf .= "phyint {$realif} disabled\n";
+ }
$igmpconf .= "\n";
- $igmpfl = fopen($g['tmp_path'] . "/igmpproxy.conf", "w");
- if (!$igmpfl) {
- log_error(gettext("Could not write Igmpproxy configuration file!"));
- return;
- }
- fwrite($igmpfl, $igmpconf);
- fclose($igmpfl);
+ $igmpfl = fopen($g['tmp_path'] . "/igmpproxy.conf", "w");
+ if (!$igmpfl) {
+ log_error(gettext("Could not write Igmpproxy configuration file!"));
+ return;
+ }
+ fwrite($igmpfl, $igmpconf);
+ fclose($igmpfl);
unset($igmpconf);
/* NOTE: -d4 means everything LOG_WARNING and smaller */
- mwexec("/usr/local/sbin/igmpproxy -d4 -c {$g['tmp_path']}/igmpproxy.conf");
- log_error(gettext("Started IGMP proxy service."));
+ mwexec("/usr/local/sbin/igmpproxy -d4 -c {$g['tmp_path']}/igmpproxy.conf");
+ log_error(gettext("Started IGMP proxy service."));
- return 0;
+ return 0;
}
function services_dhcrelay_configure() {
global $config, $g;
- if ($g['platform'] == 'jail')
+ if ($g['platform'] == 'jail') {
return;
- if(isset($config['system']['developerspew'])) {
+ }
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "services_dhcrelay_configure() being called $mt\n";
}
@@ -1423,24 +1538,28 @@ function services_dhcrelay_configure() {
$dhcrelaycfg =& $config['dhcrelay'];
/* DHCPRelay enabled on any interfaces? */
- if (!isset($dhcrelaycfg['enable']))
+ if (!isset($dhcrelaycfg['enable'])) {
return 0;
+ }
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Starting DHCP relay service...");
- else
+ } else {
sleep(1);
+ }
$iflist = get_configured_interface_list();
$dhcifaces = explode(",", $dhcrelaycfg['interface']);
foreach ($dhcifaces as $dhcrelayif) {
if (!isset($iflist[$dhcrelayif]) ||
- link_interface_to_bridge($dhcrelayif))
+ link_interface_to_bridge($dhcrelayif)) {
continue;
+ }
- if (is_ipaddr(get_interface_ip($dhcrelayif)))
+ if (is_ipaddr(get_interface_ip($dhcrelayif))) {
$dhcrelayifs[] = get_real_interface($dhcrelayif);
+ }
}
/*
@@ -1452,8 +1571,9 @@ function services_dhcrelay_configure() {
unset($destif);
foreach ($iflist as $ifname) {
$subnet = get_interface_ip($ifname);
- if (!is_ipaddr($subnet))
+ if (!is_ipaddr($subnet)) {
continue;
+ }
$subnet .= "/" . get_interface_subnet($ifname);
if (ip_in_subnet($srvip, $subnet)) {
$destif = get_real_interface($ifname);
@@ -1472,13 +1592,13 @@ function services_dhcrelay_configure() {
if (!isset($destif)) {
/* Create a array from the existing route table */
- exec("/usr/bin/netstat -rnWf inet", $route_str);
- array_shift($route_str);
- array_shift($route_str);
- array_shift($route_str);
- array_shift($route_str);
- $route_arr = array();
- foreach($route_str as $routeline) {
+ exec("/usr/bin/netstat -rnWf inet", $route_str);
+ array_shift($route_str);
+ array_shift($route_str);
+ array_shift($route_str);
+ array_shift($route_str);
+ $route_arr = array();
+ foreach ($route_str as $routeline) {
$items = preg_split("/[ ]+/i", $routeline);
if (is_subnetv4($items[0])) {
$subnet = $items[0];
@@ -1503,12 +1623,14 @@ function services_dhcrelay_configure() {
break;
}
}
- } else
+ } else {
$destif = get_real_interface("wan");
+ }
}
- if (!empty($destif))
+ if (!empty($destif)) {
$dhcrelayifs[] = $destif;
+ }
}
$dhcrelayifs = array_unique($dhcrelayifs);
@@ -1520,8 +1642,9 @@ function services_dhcrelay_configure() {
$cmd = "/usr/local/sbin/dhcrelay -i " . implode(" -i ", $dhcrelayifs);
- if (isset($dhcrelaycfg['agentoption']))
+ if (isset($dhcrelaycfg['agentoption'])) {
$cmd .= " -a -m replace";
+ }
$cmd .= " " . implode(" ", $srvips);
mwexec($cmd);
@@ -1532,9 +1655,10 @@ function services_dhcrelay_configure() {
function services_dhcrelay6_configure() {
global $config, $g;
- if ($g['platform'] == 'jail')
+ if ($g['platform'] == 'jail') {
return;
- if(isset($config['system']['developerspew'])) {
+ }
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "services_dhcrelay6_configure() being called $mt\n";
}
@@ -1545,24 +1669,27 @@ function services_dhcrelay6_configure() {
$dhcrelaycfg =& $config['dhcrelay6'];
/* DHCPv6 Relay enabled on any interfaces? */
- if (!isset($dhcrelaycfg['enable']))
+ if (!isset($dhcrelaycfg['enable'])) {
return 0;
+ }
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Starting DHCPv6 relay service...");
- else
+ } else {
sleep(1);
+ }
$iflist = get_configured_interface_list();
$dhcifaces = explode(",", $dhcrelaycfg['interface']);
foreach ($dhcifaces as $dhcrelayif) {
if (!isset($iflist[$dhcrelayif]) ||
- link_interface_to_bridge($dhcrelayif))
+ link_interface_to_bridge($dhcrelayif))
continue;
- if (is_ipaddrv6(get_interface_ipv6($dhcrelayif)))
+ if (is_ipaddrv6(get_interface_ipv6($dhcrelayif))) {
$dhcrelayifs[] = get_real_interface($dhcrelayif);
+ }
}
$dhcrelayifs = array_unique($dhcrelayifs);
@@ -1571,13 +1698,14 @@ function services_dhcrelay6_configure() {
* on the interface in which the destination server sits.
*/
$srvips = explode(",", $dhcrelaycfg['server']);
- $srvifaces = array();
+ $srvifaces = array();
foreach ($srvips as $srcidx => $srvip) {
unset($destif);
foreach ($iflist as $ifname) {
$subnet = get_interface_ipv6($ifname);
- if (!is_ipaddrv6($subnet))
+ if (!is_ipaddrv6($subnet)) {
continue;
+ }
$subnet .= "/" . get_interface_subnetv6($ifname);
if (ip_in_subnet($srvip, $subnet)) {
$destif = get_real_interface($ifname);
@@ -1598,19 +1726,19 @@ function services_dhcrelay6_configure() {
if (!isset($destif)) {
/* Create a array from the existing route table */
- exec("/usr/bin/netstat -rnWf inet6", $route_str);
- array_shift($route_str);
- array_shift($route_str);
- array_shift($route_str);
- array_shift($route_str);
- $route_arr = array();
- foreach($route_str as $routeline) {
- $items = preg_split("/[ ]+/i", $routeline);
+ exec("/usr/bin/netstat -rnWf inet6", $route_str);
+ array_shift($route_str);
+ array_shift($route_str);
+ array_shift($route_str);
+ array_shift($route_str);
+ $route_arr = array();
+ foreach ($route_str as $routeline) {
+ $items = preg_split("/[ ]+/i", $routeline);
if (ip_in_subnet($srvip, $items[0])) {
$destif = trim($items[6]);
break;
}
- }
+ }
}
if (!isset($destif)) {
@@ -1621,8 +1749,9 @@ function services_dhcrelay6_configure() {
break;
}
}
- } else
+ } else {
$destif = get_real_interface("wan");
+ }
}
if (!empty($destif)) {
@@ -1631,7 +1760,7 @@ function services_dhcrelay6_configure() {
}
/* fire up dhcrelay */
- if (empty($dhcrelayifs) || empty($srvifaces) ) {
+ if (empty($dhcrelayifs) || empty($srvifaces)) {
log_error("No suitable interface found for running dhcrelay -6!");
return; /* XXX */
}
@@ -1651,8 +1780,9 @@ function services_dhcrelay6_configure() {
function services_dyndns_configure_client($conf) {
- if (!isset($conf['enable']))
+ if (!isset($conf['enable'])) {
return;
+ }
/* load up the dyndns.class */
require_once("dyndns.class");
@@ -1681,7 +1811,7 @@ function services_dyndns_configure_client($conf) {
function services_dyndns_configure($int = "") {
global $config, $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "services_dyndns_configure() being called $mt\n";
}
@@ -1689,8 +1819,9 @@ function services_dyndns_configure($int = "") {
$dyndnscfg = $config['dyndnses']['dyndns'];
$gwgroups = return_gateway_groups_array();
if (is_array($dyndnscfg)) {
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Starting DynDNS clients...");
+ }
foreach ($dyndnscfg as $dyndns) {
if ((empty($int)) || ($int == $dyndns['interface']) || (is_array($gwgroups[$dyndns['interface']]))) {
@@ -1702,8 +1833,9 @@ function services_dyndns_configure($int = "") {
}
}
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("done.") . "\n";
+ }
}
return 0;
@@ -1716,8 +1848,9 @@ function dyndnsCheckIP($int) {
$gateways_status = return_gateways_status(true);
// If the gateway for this interface is down, then the external check cannot work.
// Avoid the long wait for the external check to timeout.
- if (stristr($gateways_status[$config['interfaces'][$int]['gateway']]['status'],"down"))
+ if (stristr($gateways_status[$config['interfaces'][$int]['gateway']]['status'], "down")) {
return "down";
+ }
$hosttocheck = "http://checkip.dyndns.org";
$ip_ch = curl_init($hosttocheck);
curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
@@ -1747,25 +1880,28 @@ function services_dnsmasq_configure() {
);
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "services_dnsmasq_configure() being called $mt\n";
}
/* kill any running dnsmasq */
- if (file_exists("{$g['varrun_path']}/dnsmasq.pid"))
+ if (file_exists("{$g['varrun_path']}/dnsmasq.pid")) {
sigkillbypid("{$g['varrun_path']}/dnsmasq.pid", "TERM");
+ }
if (isset($config['dnsmasq']['enable'])) {
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Starting DNS forwarder...");
- else
+ } else {
sleep(1);
+ }
- /* generate hosts file */
- if(system_hosts_generate()!=0)
- $return = 1;
+ /* generate hosts file */
+ if (system_hosts_generate()!=0) {
+ $return = 1;
+ }
$args = "";
@@ -1774,11 +1910,12 @@ function services_dnsmasq_configure() {
}
/* Setup listen port, if non-default */
- if (is_port($config['dnsmasq']['port']))
+ if (is_port($config['dnsmasq']['port'])) {
$args .= " --port={$config['dnsmasq']['port']} ";
+ }
$listen_addresses = "";
- if(isset($config['dnsmasq']['interface'])) {
+ if (isset($config['dnsmasq']['interface'])) {
$interfaces = explode(",", $config['dnsmasq']['interface']);
foreach ($interfaces as $interface) {
if (is_ipaddrv4($interface)) {
@@ -1791,18 +1928,21 @@ function services_dnsmasq_configure() {
if (is_linklocal($interface) && strstr($interface, "%")) {
$tmpaddrll6 = explode("%", $interface);
$listen_addresses .= " --listen-address={$tmpaddrll6[0]} ";
- } else
+ } else {
$listen_addresses .= " --listen-address={$interface} ";
+ }
} else if (strstr($interface, "_vip")) {
$laddr = get_configured_carp_interface_list($interface);
- if (is_ipaddr($laddr))
+ if (is_ipaddr($laddr)) {
$listen_addresses .= " --listen-address={$laddr} ";
+ }
} else {
$if = get_real_interface($interface);
if (does_interface_exist($if)) {
$laddr = get_interface_ip($interface);
- if (is_ipaddrv4($laddr))
+ if (is_ipaddrv4($laddr)) {
$listen_addresses .= " --listen-address={$laddr} ";
+ }
$laddr6 = get_interface_ipv6($interface);
if (is_ipaddrv6($laddr6) && !isset($config['dnsmasq']['strictbind'])) {
/*
@@ -1812,16 +1952,18 @@ function services_dnsmasq_configure() {
if (is_linklocal($laddr6) && strstr($laddr6, "%")) {
$tmpaddrll6 = explode("%", $laddr6);
$listen_addresses .= " --listen-address={$tmpaddrll6[0]} ";
- } else
+ } else {
$listen_addresses .= " --listen-address={$laddr6} ";
+ }
}
}
}
}
if (!empty($listen_addresses)) {
$args .= " {$listen_addresses} ";
- if (isset($config['dnsmasq']['strictbind']))
+ if (isset($config['dnsmasq']['strictbind'])) {
$args .= " --bind-interfaces ";
+ }
}
}
@@ -1843,14 +1985,15 @@ function services_dnsmasq_configure() {
// Build an array of the private reverse lookup domain names
$reverse_domain_a = array("10.in-addr.arpa", "168.192.in-addr.arpa");
// Unfortunately the 172.16.0.0/12 range does not map nicely to the in-addr.arpa scheme.
- for ($subnet_num = 16; $subnet_num < 32; $subnet_num++) {
+ for ($subnet_num = 16; $subnet_num < 32; $subnet_num++) {
$reverse_domain_a[] = "$subnet_num.172.in-addr.arpa";
}
// Set the --server parameter to nowhere for each reverse domain name that was not specifically specified in a domain override.
- foreach ($reverse_domain_a as $reverse_domain) {
- if (!isset($override_a[$reverse_domain]))
+ foreach ($reverse_domain_a as $reverse_domain) {
+ if (!isset($override_a[$reverse_domain])) {
$args .= " --server=/$reverse_domain/ ";
+ }
}
unset($override_a);
unset($reverse_domain_a);
@@ -1858,24 +2001,26 @@ function services_dnsmasq_configure() {
/* Setup forwarded domains */
if (isset($config['dnsmasq']['domainoverrides']) && is_array($config['dnsmasq']['domainoverrides'])) {
- foreach($config['dnsmasq']['domainoverrides'] as $override) {
- if ($override['ip'] == "!")
+ foreach ($config['dnsmasq']['domainoverrides'] as $override) {
+ if ($override['ip'] == "!") {
$override[ip] = "";
+ }
$args .= ' --server=/' . $override['domain'] . '/' . $override['ip'];
}
}
/* Allow DNS Rebind for forwarded domains */
if (isset($config['dnsmasq']['domainoverrides']) && is_array($config['dnsmasq']['domainoverrides'])) {
- if(!isset($config['system']['webgui']['nodnsrebindcheck'])) {
- foreach($config['dnsmasq']['domainoverrides'] as $override) {
+ if (!isset($config['system']['webgui']['nodnsrebindcheck'])) {
+ foreach ($config['dnsmasq']['domainoverrides'] as $override) {
$args .= ' --rebind-domain-ok=/' . $override['domain'] . '/ ';
}
}
}
- if(!isset($config['system']['webgui']['nodnsrebindcheck']))
+ if (!isset($config['system']['webgui']['nodnsrebindcheck'])) {
$dns_rebind = "--rebind-localhost-ok --stop-dns-rebind";
+ }
if (isset($config['dnsmasq']['strict_order'])) {
$args .= " --strict-order ";
@@ -1885,13 +2030,15 @@ function services_dnsmasq_configure() {
$args .= " --domain-needed ";
}
- if ($config['dnsmasq']['custom_options'])
+ if ($config['dnsmasq']['custom_options']) {
foreach (preg_split('/\s+/', $config['dnsmasq']['custom_options']) as $c) {
$args .= " " . escapeshellarg("--{$c}");
$p = explode('=', $c);
- if (array_key_exists($p[0], $standard_args))
+ if (array_key_exists($p[0], $standard_args)) {
unset($standard_args[$p[0]]);
+ }
}
+ }
$args .= ' ' . implode(' ', array_values($standard_args));
/* run dnsmasq */
@@ -1900,15 +2047,17 @@ function services_dnsmasq_configure() {
mwexec_bg($cmd);
unset($args);
- system_dhcpleases_configure();
+ system_dhcpleases_configure();
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("done.") . "\n";
+ }
}
if (!platform_booting()) {
- if(services_dhcpd_configure()!=0)
+ if (services_dhcpd_configure()!=0) {
$return = 1;
+ }
}
return $return;
@@ -1924,30 +2073,35 @@ function services_unbound_configure() {
}
// kill any running Unbound instance
- if (file_exists("{$g['varrun_path']}/unbound.pid"))
+ if (file_exists("{$g['varrun_path']}/unbound.pid")) {
sigkillbypid("{$g['varrun_path']}/unbound.pid", "TERM");
+ }
if (isset($config['unbound']['enable'])) {
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Starting DNS Resolver...");
- else
+ } else {
sleep(1);
+ }
/* generate hosts file */
- if(system_hosts_generate()!=0)
+ if (system_hosts_generate()!=0) {
$return = 1;
+ }
require_once('/etc/inc/unbound.inc');
sync_unbound_service();
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("done.") . "\n";
+ }
- system_dhcpleases_configure();
+ system_dhcpleases_configure();
}
if (!platform_booting()) {
- if (services_dhcpd_configure()!=0)
+ if (services_dhcpd_configure()!=0) {
$return = 1;
+ }
}
return $return;
@@ -1955,7 +2109,7 @@ function services_unbound_configure() {
function services_snmpd_configure() {
global $config, $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "services_snmpd_configure() being called $mt\n";
}
@@ -1963,13 +2117,15 @@ function services_snmpd_configure() {
/* kill any running snmpd */
sigkillbypid("{$g['varrun_path']}/snmpd.pid", "TERM");
sleep(2);
- if(is_process_running("bsnmpd"))
+ if (is_process_running("bsnmpd")) {
mwexec("/usr/bin/killall bsnmpd", true);
+ }
if (isset($config['snmpd']['enable'])) {
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Starting SNMP daemon... ");
+ }
/* generate snmpd.conf */
$fd = fopen("{$g['varetc_path']}/snmpd.conf", "w");
@@ -1987,8 +2143,8 @@ read := "{$config['snmpd']['rocommunity']}"
EOD;
/* No docs on what write strings do there for disable for now.
- if(isset($config['snmpd']['rwenable']) && preg_match('/^\S+$/', $config['snmpd']['rwcommunity'])){
- $snmpdconf .= <<<EOD
+ if (isset($config['snmpd']['rwenable']) && preg_match('/^\S+$/', $config['snmpd']['rwcommunity'])) {
+ $snmpdconf .= <<<EOD
# write string
write := "{$config['snmpd']['rwcommunity']}"
@@ -1997,8 +2153,8 @@ EOD;
*/
- if(isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])){
- $snmpdconf .= <<<EOD
+ if (isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])) {
+ $snmpdconf .= <<<EOD
# SNMP Trap support.
traphost := {$config['snmpd']['trapserver']}
trapport := {$config['snmpd']['trapserverport']}
@@ -2010,8 +2166,9 @@ EOD;
$version = trim(file_get_contents('/etc/version'));
$platform = trim(file_get_contents('/etc/platform'));
- if (($platform == "pfSense") && ($g['product_name'] != "pfSense"))
+ if (($platform == "pfSense") && ($g['product_name'] != "pfSense")) {
$platform = $g['product_name'];
+ }
$sysDescr = "{$g['product_name']} " . php_uname("n") .
" {$version} {$platform} " . php_uname("s") .
" " . php_uname("r") . " " . php_uname("m");
@@ -2027,8 +2184,8 @@ begemotSnmpdCommunityString.0.1 = $(read)
EOD;
/* No docs on what write strings do there for disable for now.
- if(isset($config['snmpd']['rwcommunity']) && preg_match('/^\S+$/', $config['snmpd']['rwcommunity'])){
- $snmpdconf .= <<<EOD
+ if (isset($config['snmpd']['rwcommunity']) && preg_match('/^\S+$/', $config['snmpd']['rwcommunity'])) {
+ $snmpdconf .= <<<EOD
begemotSnmpdCommunityString.0.2 = $(write)
EOD;
@@ -2036,8 +2193,8 @@ EOD;
*/
- if(isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])){
- $snmpdconf .= <<<EOD
+ if (isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])) {
+ $snmpdconf .= <<<EOD
begemotTrapSinkStatus.[$(traphost)].$(trapport) = 4
begemotTrapSinkVersion.[$(traphost)].$(trapport) = 2
begemotTrapSinkComm.[$(traphost)].$(trapport) = $(trap)
@@ -2056,18 +2213,19 @@ EOD;
unset($config['snmpd']['bindlan']);
}
$bind_to_ip = "0.0.0.0";
- if(isset($config['snmpd']['bindip'])) {
+ if (isset($config['snmpd']['bindip'])) {
if (is_ipaddr($config['snmpd']['bindip'])) {
$bind_to_ip = $config['snmpd']['bindip'];
} else {
$if = get_real_interface($config['snmpd']['bindip']);
- if (does_interface_exist($if))
+ if (does_interface_exist($if)) {
$bind_to_ip = get_interface_ip($config['snmpd']['bindip']);
+ }
}
}
- if(is_port( $config['snmpd']['pollport'] )) {
- $snmpdconf .= <<<EOD
+ if (is_port($config['snmpd']['pollport'])) {
+ $snmpdconf .= <<<EOD
begemotSnmpdPortStatus.{$bind_to_ip}.{$config['snmpd']['pollport']} = 1
EOD;
@@ -2087,50 +2245,50 @@ snmpEnableAuthenTraps = 2
EOD;
- if (is_array( $config['snmpd']['modules'] )) {
- if(isset($config['snmpd']['modules']['mibii'])) {
+ if (is_array($config['snmpd']['modules'])) {
+ if (isset($config['snmpd']['modules']['mibii'])) {
$snmpdconf .= <<<EOD
begemotSnmpdModulePath."mibII" = "/usr/lib/snmp_mibII.so"
EOD;
- }
+ }
- if(isset($config['snmpd']['modules']['netgraph'])) {
- $snmpdconf .= <<<EOD
+ if (isset($config['snmpd']['modules']['netgraph'])) {
+ $snmpdconf .= <<<EOD
begemotSnmpdModulePath."netgraph" = "/usr/lib/snmp_netgraph.so"
%netgraph
begemotNgControlNodeName = "snmpd"
EOD;
- }
+ }
- if(isset($config['snmpd']['modules']['pf'])) {
- $snmpdconf .= <<<EOD
+ if (isset($config['snmpd']['modules']['pf'])) {
+ $snmpdconf .= <<<EOD
begemotSnmpdModulePath."pf" = "/usr/lib/snmp_pf.so"
EOD;
- }
+ }
- if(isset($config['snmpd']['modules']['hostres'])) {
- $snmpdconf .= <<<EOD
+ if (isset($config['snmpd']['modules']['hostres'])) {
+ $snmpdconf .= <<<EOD
begemotSnmpdModulePath."hostres" = "/usr/lib/snmp_hostres.so"
EOD;
- }
- if(isset($config['snmpd']['modules']['bridge'])) {
- $snmpdconf .= <<<EOD
+ }
+ if (isset($config['snmpd']['modules']['bridge'])) {
+ $snmpdconf .= <<<EOD
begemotSnmpdModulePath."bridge" = "/usr/lib/snmp_bridge.so"
# config must end with blank line
EOD;
- }
- if(isset($config['snmpd']['modules']['ucd'])) {
+ }
+ if (isset($config['snmpd']['modules']['ucd'])) {
$snmpdconf .= <<<EOD
begemotSnmpdModulePath."ucd" = "/usr/local/lib/snmp_ucd.so"
EOD;
}
- if(isset($config['snmpd']['modules']['regex'])) {
+ if (isset($config['snmpd']['modules']['regex'])) {
$snmpdconf .= <<<EOD
begemotSnmpdModulePath."regex" = "/usr/local/lib/snmp_regex.so"
@@ -2150,8 +2308,9 @@ EOD;
mwexec("/usr/sbin/bsnmpd -c {$g['varetc_path']}/snmpd.conf" .
"{$bindlan} -p {$g['varrun_path']}/snmpd.pid");
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("done.") . "\n";
+ }
}
return 0;
@@ -2159,7 +2318,7 @@ EOD;
function services_dnsupdate_process($int = "", $updatehost = "", $forced = false) {
global $config, $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "services_dnsupdate_process() being called $mt\n";
}
@@ -2168,21 +2327,25 @@ function services_dnsupdate_process($int = "", $updatehost = "", $forced = false
if (is_array($config['dnsupdates']['dnsupdate'])) {
$notify_text = "";
foreach ($config['dnsupdates']['dnsupdate'] as $i => $dnsupdate) {
- if (!isset($dnsupdate['enable']))
+ if (!isset($dnsupdate['enable'])) {
continue;
- if (!empty($int) && $int != $dnsupdate['interface'])
+ }
+ if (!empty($int) && $int != $dnsupdate['interface']) {
continue;
- if (!empty($updatehost) && ($updatehost != $dnsupdate['host']))
+ }
+ if (!empty($updatehost) && ($updatehost != $dnsupdate['host'])) {
continue;
+ }
/* determine interface name */
$if = get_real_interface($dnsupdate['interface']);
-
- if (isset($dnsupdate['usepublicip']))
- $wanip = dyndnsCheckIP($dnsupdate['interface']);
- else
- $wanip = get_interface_ip($dnsupdate['interface']);
-
+
+ if (isset($dnsupdate['usepublicip'])) {
+ $wanip = dyndnsCheckIP($dnsupdate['interface']);
+ } else {
+ $wanip = get_interface_ip($dnsupdate['interface']);
+ }
+
$wanipv6 = get_interface_ipv6($dnsupdate['interface']);
$cacheFile = "{$g['conf_path']}/dyndns_{$dnsupdate['interface']}_rfc2136_" . escapeshellarg($dnsupdate['host']) . "_{$dnsupdate['server']}.cache";
$currentTime = time();
@@ -2190,13 +2353,15 @@ function services_dnsupdate_process($int = "", $updatehost = "", $forced = false
if ($wanip || $wanipv6) {
$keyname = $dnsupdate['keyname'];
/* trailing dot */
- if (substr($keyname, -1) != ".")
+ if (substr($keyname, -1) != ".") {
$keyname .= ".";
+ }
$hostname = $dnsupdate['host'];
/* trailing dot */
- if (substr($hostname, -1) != ".")
+ if (substr($hostname, -1) != ".") {
$hostname .= ".";
+ }
/* write private key file
this is dumb - public and private keys are the same for HMAC-MD5,
@@ -2229,8 +2394,9 @@ EOD;
/* generate update instructions */
$upinst = "";
- if (!empty($dnsupdate['server']))
+ if (!empty($dnsupdate['server'])) {
$upinst .= "server {$dnsupdate['server']}\n";
+ }
if (file_exists($cacheFile)) {
list($cachedipv4, $cacheTimev4) = explode("|", file_get_contents($cacheFile));
@@ -2256,8 +2422,9 @@ EOD;
} else {
log_error("phpDynDNS: Not updating {$dnsupdate['host']} A record because the IP address has not changed.");
}
- } else
+ } else {
@unlink($cacheFile);
+ }
/* Update IPv6 if we have it. */
if (is_ipaddrv6($wanipv6)) {
@@ -2271,8 +2438,9 @@ EOD;
} else {
log_error("phpDynDNS: Not updating {$dnsupdate['host']} AAAA record because the IPv6 address has not changed.");
}
- } else
+ } else {
@unlink("{$cacheFile}.ipv6");
+ }
conf_mount_ro();
$upinst .= "\n"; /* mind that trailing newline! */
@@ -2282,8 +2450,9 @@ EOD;
unset($upinst);
/* invoke nsupdate */
$cmd = "/usr/local/bin/nsupdate -k {$g['varetc_path']}/K{$i}{$keyname}+157+00000.key";
- if (isset($dnsupdate['usetcp']))
+ if (isset($dnsupdate['usetcp'])) {
$cmd .= " -v";
+ }
$cmd .= " {$g['varetc_path']}/nsupdatecmds{$i}";
mwexec_bg($cmd);
unset($cmd);
@@ -2319,13 +2488,14 @@ function configure_cron() {
if (is_array($config['cron']['item'])) {
$crontab_contents .= "#\n";
$crontab_contents .= "# " . gettext("pfSense specific crontab entries") . "\n";
- $crontab_contents .= "# " .gettext( "Created:") . " " . date("F j, Y, g:i a") . "\n";
+ $crontab_contents .= "# " .gettext("Created:") . " " . date("F j, Y, g:i a") . "\n";
$crontab_contents .= "#\n";
if (isset($config['system']['proxyurl']) && !empty($config['system']['proxyurl'])) {
$http_proxy = $config['system']['proxyurl'];
- if (isset($config['system']['proxyport']) && !empty($config['system']['proxyport']))
+ if (isset($config['system']['proxyport']) && !empty($config['system']['proxyport'])) {
$http_proxy .= ':' . $config['system']['proxyport'];
+ }
$crontab_contents .= "HTTP_PROXY={$http_proxy}";
}
@@ -2357,7 +2527,7 @@ function configure_cron() {
function upnp_action ($action) {
global $g, $config;
- switch($action) {
+ switch ($action) {
case "start":
if (file_exists('/var/etc/miniupnpd.conf')) {
@unlink("{$g['varrun_path']}/miniupnpd.pid");
@@ -2366,8 +2536,9 @@ function upnp_action ($action) {
break;
case "stop":
killbypid("{$g['varrun_path']}/miniupnpd.pid");
- while((int)exec("/bin/pgrep -a miniupnpd | wc -l") > 0)
+ while ((int)exec("/bin/pgrep -a miniupnpd | wc -l") > 0) {
mwexec('killall miniupnpd 2>/dev/null', true);
+ }
mwexec('/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null');
mwexec('/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null');
break;
@@ -2381,10 +2552,11 @@ function upnp_action ($action) {
function upnp_start() {
global $config;
- if(!isset($config['installedpackages']['miniupnpd']['config']))
+ if (!isset($config['installedpackages']['miniupnpd']['config'])) {
return;
+ }
- if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
+ if ($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
echo gettext("Starting UPnP service... ");
require_once('/usr/local/pkg/miniupnpd.inc');
sync_package_miniupnpd();
@@ -2398,21 +2570,23 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont
$is_installed = false;
$cron_changed = true;
- if (!is_array($config['cron']))
+ if (!is_array($config['cron'])) {
$config['cron'] = array();
- if (!is_array($config['cron']['item']))
+ }
+ if (!is_array($config['cron']['item'])) {
$config['cron']['item'] = array();
+ }
$x=0;
- foreach($config['cron']['item'] as $item) {
- if(strstr($item['command'], $command)) {
+ foreach ($config['cron']['item'] as $item) {
+ if (strstr($item['command'], $command)) {
$is_installed = true;
break;
}
$x++;
}
- if($active) {
+ if ($active) {
$cron_item = array();
$cron_item['minute'] = $minute;
$cron_item['hour'] = $hour;
@@ -2421,7 +2595,7 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont
$cron_item['wday'] = $weekday;
$cron_item['who'] = $who;
$cron_item['command'] = $command;
- if(!$is_installed) {
+ if (!$is_installed) {
$config['cron']['item'][] = $cron_item;
write_config(sprintf(gettext("Installed cron job for %s"), $command));
} else {
@@ -2434,14 +2608,15 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont
}
}
} else {
- if($is_installed == true) {
+ if ($is_installed == true) {
unset($config['cron']['item'][$x]);
write_config(sprintf(gettext("Removed cron job for %s"), $command));
}
}
- if ($cron_changed)
+ if ($cron_changed) {
configure_cron();
+ }
}
?>
diff --git a/etc/inc/shaper.inc b/etc/inc/shaper.inc
index d2f7bfc..92384e1 100644
--- a/etc/inc/shaper.inc
+++ b/etc/inc/shaper.inc
@@ -37,10 +37,9 @@ require_once("util.inc");
require_once("notices.inc");
/*
- * I admit :) this is derived from xmplparse.inc StartElement()
+ * I admit :) this is derived from xmlparse.inc StartElement()
*/
-function &get_reference_to_me_in_config(&$mypath)
-{
+function &get_reference_to_me_in_config(&$mypath) {
global $config;
$ptr =& $config['shaper'];
@@ -51,8 +50,7 @@ function &get_reference_to_me_in_config(&$mypath)
return $ptr;
}
-function unset_object_by_reference(&$mypath)
-{
+function unset_object_by_reference(&$mypath) {
global $config;
$ptr =& $config['shaper'];
@@ -62,8 +60,7 @@ function unset_object_by_reference(&$mypath)
unset($ptr['queue'][$mypath[$i]]);
}
-function &get_dn_reference_to_me_in_config(&$mypath)
-{
+function &get_dn_reference_to_me_in_config(&$mypath) {
global $config;
$ptr =& $config['dnshaper'];
@@ -74,8 +71,7 @@ function &get_dn_reference_to_me_in_config(&$mypath)
return $ptr;
}
-function unset_dn_object_by_reference(&$mypath)
-{
+function unset_dn_object_by_reference(&$mypath) {
global $config;
$ptr =& $config['dnshaper'];
@@ -85,87 +81,127 @@ function unset_dn_object_by_reference(&$mypath)
unset($ptr['queue'][$mypath[$i]]);
}
-function clean_child_queues($type, $mypath)
-{
+function clean_child_queues($type, $mypath) {
$ref = &get_reference_to_me_in_config($mypath);
switch ($type) {
- case 'HFSC':
- if (isset($ref['borrow'])) unset($ref['borrow']);
- if (isset($ref['hogs'])) unset($ref['hogs']);
- if (isset($ref['buckets'])) unset($ref['buckets']);
- break;
- case 'PRIQ':
- if (isset($ref['borrow'])) unset($ref['borrow']);
- if (isset($ref['bandwidth'])) unset($ref['bandwidth']);
- if (isset($ref['bandwidthtype'])) unset($ref['bandwidthtype']);
- /* fall through */
- case 'FAIRQ':
- if (isset($ref['borrow'])) unset($ref['borrow']);
- /* fall through */
- case 'CBQ':
- if (isset($ref['realtime'])) unset($ref['realtime']);
- if (isset($ref['realtime1'])) unset($ref['realtime1']);
- if (isset($ref['realtime2'])) unset($ref['realtime2']);
- if (isset($ref['realtime3'])) unset($ref['realtime3']);
- if (isset($ref['upperlimit'])) unset($ref['upperlimit']);
- if (isset($ref['upperlimit1'])) unset($ref['upperlimit1']);
- if (isset($ref['upperlimit2'])) unset($ref['upperlimit2']);
- if (isset($ref['upperlimit3'])) unset($ref['upperlimit3']);
- if (isset($ref['linkshare'])) unset($ref['linkshare']);
- if (isset($ref['linkshare1'])) unset($ref['linkshare1']);
- if (isset($ref['linkshare2'])) unset($ref['linkshare2']);
- if (isset($ref['linkshare3'])) unset($ref['linkshare3']);
- if (isset($ref['hogs'])) unset($ref['hogs']);
- if (isset($ref['buckets'])) unset($ref['buckets']);
- break;
+ case 'HFSC':
+ if (isset($ref['borrow'])) {
+ unset($ref['borrow']);
+ }
+ if (isset($ref['hogs'])) {
+ unset($ref['hogs']);
+ }
+ if (isset($ref['buckets'])) {
+ unset($ref['buckets']);
+ }
+ break;
+ case 'PRIQ':
+ if (isset($ref['borrow'])) {
+ unset($ref['borrow']);
+ }
+ if (isset($ref['bandwidth'])) {
+ unset($ref['bandwidth']);
+ }
+ if (isset($ref['bandwidthtype'])) {
+ unset($ref['bandwidthtype']);
+ }
+ /* fall through */
+ case 'FAIRQ':
+ if (isset($ref['borrow'])) {
+ unset($ref['borrow']);
+ }
+ /* fall through */
+ case 'CBQ':
+ if (isset($ref['realtime'])) {
+ unset($ref['realtime']);
+ }
+ if (isset($ref['realtime1'])) {
+ unset($ref['realtime1']);
+ }
+ if (isset($ref['realtime2'])) {
+ unset($ref['realtime2']);
+ }
+ if (isset($ref['realtime3'])) {
+ unset($ref['realtime3']);
+ }
+ if (isset($ref['upperlimit'])) {
+ unset($ref['upperlimit']);
+ }
+ if (isset($ref['upperlimit1'])) {
+ unset($ref['upperlimit1']);
+ }
+ if (isset($ref['upperlimit2'])) {
+ unset($ref['upperlimit2']);
+ }
+ if (isset($ref['upperlimit3'])) {
+ unset($ref['upperlimit3']);
+ }
+ if (isset($ref['linkshare'])) {
+ unset($ref['linkshare']);
+ }
+ if (isset($ref['linkshare1'])) {
+ unset($ref['linkshare1']);
+ }
+ if (isset($ref['linkshare2'])) {
+ unset($ref['linkshare2']);
+ }
+ if (isset($ref['linkshare3'])) {
+ unset($ref['linkshare3']);
+ }
+ if (isset($ref['hogs'])) {
+ unset($ref['hogs']);
+ }
+ if (isset($ref['buckets'])) {
+ unset($ref['buckets']);
+ }
+ break;
}
}
-function get_bandwidthtype_scale($type)
-{
+function get_bandwidthtype_scale($type) {
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;
+ 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);
}
-function get_hfsc_bandwidth($object, $bw)
-{
+function get_hfsc_bandwidth($object, $bw) {
$pattern= "/[0-9]+/";
- if (preg_match($pattern, $bw, $match))
+ if (preg_match($pattern, $bw, $match)) {
$bw_1 = $match[1];
- else
+ } 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;
+ case '%':
+ $bw_1 = $bw_1 / 100 * get_interface_bandwidth($object);
+ break;
+ default:
+ $bw_1 = $bw_1 * get_bandwidthtype_scale($match[0]);
+ break;
}
return floatval($bw_1);
- } else
+ } else {
return 0;
+ }
}
-function get_interface_bandwidth($object)
-{
+function get_interface_bandwidth($object) {
global $altq_list_queues;
$int = $object->GetInterface();
@@ -174,16 +210,16 @@ function get_interface_bandwidth($object)
$bw_3 = $altq->GetBandwidth();
$bw_3 = $bw_3 * get_bandwidthtype_scale($altq->GetBwscale());
return floatval($bw_3);
- } else
+ } else {
return 0;
+ }
}
/*
* This is duplicated here since we cannot include guiconfig.inc.
* Including it makes all stuff break.
*/
-function shaper_do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors)
-{
+function shaper_do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
/* check for bad control characters */
foreach ($postdata as $pn => $pd) {
@@ -199,27 +235,29 @@ function shaper_do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input
}
}
-function cleanup_queue_from_rules($queue)
-{
+function cleanup_queue_from_rules($queue) {
global $config;
foreach ($config['filter']['rule'] as $rule) {
- if ($rule['defaultqueue'] == $queue)
+ if ($rule['defaultqueue'] == $queue) {
unset($rule['defaultqueue']);
- if ($rule['ackqueue'] == $queue)
+ }
+ if ($rule['ackqueue'] == $queue) {
unset($rule['ackqueue']);
+ }
}
}
-function cleanup_dnqueue_from_rules($queue)
-{
+function cleanup_dnqueue_from_rules($queue) {
global $config;
foreach ($config['filter']['rule'] as $rule) {
- if ($rule['dnpipe'] == $queue)
+ if ($rule['dnpipe'] == $queue) {
unset($rule['dnpipe']);
- if ($rule['pdnpipe'] == $queue)
+ }
+ if ($rule['pdnpipe'] == $queue) {
unset($rule['pdnpipe']);
+ }
}
}
@@ -245,8 +283,9 @@ class altq_root_queue {
function GetDefaultQueuePresent() {
if (!empty($this->queues)) {
foreach ($this->queues as $q) {
- if ($q->GetDefault())
+ if ($q->GetDefault()) {
return true;
+ }
}
}
@@ -265,10 +304,11 @@ class altq_root_queue {
$this->qenabled = $value;
}
function CanHaveChildren() {
- if ($this->GetScheduler() == "CODELQ")
+ if ($this->GetScheduler() == "CODELQ") {
return false;
- else
+ } else {
return true;
+ }
}
function CanBeDeleted() {
return false;
@@ -325,29 +365,37 @@ class altq_root_queue {
shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
- if ($data['bandwidth'] && (!is_numeric($data['bandwidth'])))
+ if ($data['bandwidth'] && (!is_numeric($data['bandwidth']))) {
$input_errors[] = gettext("Bandwidth must be an integer.");
- if ($data['bandwidth'] < 0)
+ }
+ if ($data['bandwidth'] < 0) {
$input_errors[] = gettext("Bandwidth cannot be negative.");
- if ($data['qlimit'] && (!is_numeric($data['qlimit'])))
+ }
+ if ($data['qlimit'] && (!is_numeric($data['qlimit']))) {
$input_errors[] = gettext("Qlimit must be an integer.");
- if ($data['qlimit'] < 0)
+ }
+ if ($data['qlimit'] < 0) {
$input_errors[] = gettext("Qlimit must be positive.");
- if ($data['tbrconfig'] && (!is_numeric($data['tbrconfig'])))
+ }
+ if ($data['tbrconfig'] && (!is_numeric($data['tbrconfig']))) {
$input_errors[] = gettext("Tbrsize must be an integer.");
- if ($data['tbrconfig'] < 0)
+ }
+ if ($data['tbrconfig'] < 0) {
$input_errors[] = gettext("Tbrsize must be positive.");
+ }
}
/* Implement this to shorten some code on the frontend page */
function ReadConfig(&$conf) {
- if (isset($conf['tbrconfig']))
+ if (isset($conf['tbrconfig'])) {
$this->SetTbrConfig($conf['tbrconfig']);
- else
+ } else {
$this->SetTbrConfig($conf['tbrconfig']);
+ }
$this->SetBandwidth($conf['bandwidth']);
- if ($conf['bandwidthtype'] <> "")
+ if ($conf['bandwidthtype'] <> "") {
$this->SetBwscale($conf['bandwidthtype']);
+ }
if (isset($conf['scheduler'])) {
if ($this->GetScheduler() != $conf['scheduler']) {
foreach ($this->queues as $q) {
@@ -357,16 +405,19 @@ class altq_root_queue {
}
$this->SetScheduler($conf['scheduler']);
}
- if (isset($conf['qlimit']) && $conf['qlimit'] <> "")
+ if (isset($conf['qlimit']) && $conf['qlimit'] <> "") {
$this->SetQlimit($conf['qlimit']);
- else
+ } else {
$this->SetQlimit("");
- if (isset($conf['name']))
+ }
+ if (isset($conf['name'])) {
$this->SetQname($conf['name']);
- if (!empty($conf['enabled']))
+ }
+ if (!empty($conf['enabled'])) {
$this->SetEnabled($conf['enabled']);
- else
+ } else {
$this->SetEnabled("");
+ }
}
function copy_queue($interface, &$cflink) {
@@ -392,34 +443,36 @@ class altq_root_queue {
//$qlist[$this->GetQname()] = & $this;
if (is_array($this->queues)) {
- foreach ($this->queues as $queue)
+ foreach ($this->queues as $queue) {
$queue->get_queue_list($qlist);
+ }
}
return $qlist;
}
function &add_queue($interface, &$queue, &$path, &$input_errors) {
- if (!is_array($this->queues))
+ if (!is_array($this->queues)) {
$this->queues = array();
+ }
switch ($this->GetScheduler()) {
- case "PRIQ":
- $q =& new priq_queue();
- break;
- case "HFSC":
- $q =& new hfsc_queue();
- break;
- case "CBQ":
- $q =& new cbq_queue();
- break;
- case "FAIRQ":
- $q =& new fairq_queue();
- break;
- default:
- /* XXX: but should not happen anyway */
- return;
- break;
+ case "PRIQ":
+ $q =& new priq_queue();
+ break;
+ case "HFSC":
+ $q =& new hfsc_queue();
+ break;
+ case "CBQ":
+ $q =& new cbq_queue();
+ break;
+ case "FAIRQ":
+ $q =& new fairq_queue();
+ break;
+ default:
+ /* XXX: but should not happen anyway */
+ return;
+ break;
}
$q->SetLink($path);
$q->SetInterface($this->GetInterface());
@@ -434,12 +487,12 @@ class altq_root_queue {
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;
+ case "%":
+ $myBw = $this->GetAvailableBandwidth() * $queue['bandwidth'] / 100;
+ break;
+ default:
+ $myBw = $queue['bandwidth'] * get_bandwidthtype_scale($queue['bandwdithtype']);
+ break;
}
}
$q->SetAvailableBandwidth($myBw);
@@ -464,8 +517,9 @@ class altq_root_queue {
}
foreach ($this->queues as $q) {
$result =& $q->find_queue("", $qname);
- if ($result)
+ if ($result) {
return $result;
+ }
}
}
@@ -477,8 +531,9 @@ class altq_root_queue {
} else if ($this->GetScheduler() <> "PRIQ") {
foreach ($this->queues as $q) {
$result = $q->find_parentqueue("", $qname);
- if ($result)
+ if ($result) {
return $result;
+ }
}
}
}
@@ -493,7 +548,7 @@ class altq_root_queue {
foreach ($this->queues as $q) {
$tree .= $q->build_tree();
}
- $tree .= "</ul>";
+ $tree .= "</ul>";
}
$tree .= "</li>";
return $tree;
@@ -501,7 +556,7 @@ class altq_root_queue {
function delete_queue() {
foreach ($this->queues as $q) {
- $this->SetAvailableBandwidth($this->GetAvailableBandwidth() + $q->GetAvailableBandwidth());
+ $this->SetAvailableBandwidth($this->GetAvailableBandwidth() + $q->GetAvailableBandwidth());
$q->delete_queue();
}
unset_object_by_reference($this->GetLink());
@@ -522,24 +577,29 @@ class altq_root_queue {
* First it spits:
* altq on $interface ..............
* then it goes like
- * foreach ($queues as $qkey => $queue)
+ * foreach ($queues as $qkey => $queue) {
* this->queues[$qkey]->build_rule();
+ * }
*/
function build_rules(&$default = false) {
if (count($this->queues) > 0 && $this->GetEnabled() == "on") {
$default = false;
$rules = " altq on " . get_real_interface($this->GetInterface());
- if ($this->GetScheduler())
+ if ($this->GetScheduler()) {
$rules .= " ".strtolower($this->GetScheduler());
- if ($this->GetQlimit() > 0)
+ }
+ if ($this->GetQlimit() > 0) {
$rules .= " qlimit " . $this->GetQlimit() . " ";
+ }
if ($this->GetBandwidth()) {
$rules .= " bandwidth ".trim($this->GetBandwidth());
- if ($this->GetBwscale())
+ if ($this->GetBwscale()) {
$rules .= $this->GetBwscale();
+ }
}
- if ($this->GetTbrConfig())
+ if ($this->GetTbrConfig()) {
$rules .= " tbrsize ".$this->GetTbrConfig();
+ }
if (count($this->queues)) {
$i = count($this->queues);
$rules .= " queue { ";
@@ -547,8 +607,9 @@ class altq_root_queue {
if ($i > 1) {
$i--;
$rules .= " {$qkey}, ";
- } else
+ } else {
$rules .= " {$qkey} ";
+ }
}
$rules .= " } \n";
foreach ($this->queues as $q) {
@@ -565,17 +626,21 @@ class altq_root_queue {
$frule .= $rules;
} else if ($this->GetEnabled() == "on" && $this->GetScheduler() == "CODELQ") {
$rules = " altq on " . get_real_interface($this->GetInterface());
- if ($this->GetScheduler())
+ if ($this->GetScheduler()) {
$rules .= " ".strtolower($this->GetScheduler());
- if ($this->GetQlimit() > 0)
+ }
+ if ($this->GetQlimit() > 0) {
$rules .= " ( qlimit " . $this->GetQlimit() . " ) ";
+ }
if ($this->GetBandwidth()) {
$rules .= " bandwidth ".trim($this->GetBandwidth());
- if ($this->GetBwscale())
+ if ($this->GetBwscale()) {
$rules .= $this->GetBwscale();
+ }
}
- if ($this->GetTbrConfig())
+ if ($this->GetTbrConfig()) {
$rules .= " tbrsize ".$this->GetTbrConfig();
+ }
$rules .= " queue";
}
@@ -610,8 +675,9 @@ class altq_root_queue {
global $g;
$altq =& $this;
- if ($altq)
+ if ($altq) {
$scheduler = ": " . $altq->GetScheduler();
+ }
$form = "<tr><td width=\"20%\" class=\"vtable\">";
$form .= "<a href=\"firewall_shaper.php?interface=" . $this->GetInterface() . "&amp;queue=". $this->GetInterface()."&amp;action=show\">". $shaperIFlist[$this->GetInterface()] .": ".$scheduler."</a>";
$form .= "</td></tr>";
@@ -640,8 +706,9 @@ class altq_root_queue {
$form .= gettext("Enable/Disable");
$form .= "<br /></td><td class=\"vncellreq\">";
$form .= " <input type=\"checkbox\" id=\"enabled\" name=\"enabled\" value=\"on\"";
- if ($this->GetEnabled() == "on")
+ if ($this->GetEnabled() == "on") {
$form .= " checked=\"checked\"";
+ }
$form .= " /><span class=\"vexpl\"> " . gettext("Enable/disable discipline and its children") . "</span>";
$form .= "</td></tr>";
$form .= "<tr><td valign=\"middle\" class=\"vncellreq\"><br /><span class=\"vexpl\">" . gettext("Name") . "</span></td>";
@@ -653,24 +720,29 @@ class altq_root_queue {
$form .= "<td class=\"vncellreq\">";
$form .= "<select id=\"scheduler\" name=\"scheduler\" class=\"formselect\">";
$form .= "<option value=\"HFSC\"";
- if ($this->GetScheduler() == "HFSC")
+ if ($this->GetScheduler() == "HFSC") {
$form .= " selected=\"selected\"";
+ }
$form .= ">HFSC</option>";
$form .= "<option value=\"CBQ\"";
- if ($this->GetScheduler() == "CBQ")
+ if ($this->GetScheduler() == "CBQ") {
$form .= " selected=\"selected\"";
+ }
$form .= ">CBQ</option>";
$form .= "<option value=\"FAIRQ\"";
- if ($this->GetScheduler() == "FAIRQ")
+ if ($this->GetScheduler() == "FAIRQ") {
$form .= " selected=\"selected\"";
+ }
$form .= ">FAIRQ</option>";
$form .= "<option value=\"CODELQ\"";
- if ($this->GetScheduler() == "CODELQ")
+ if ($this->GetScheduler() == "CODELQ") {
$form .= " selected=\"selected\"";
+ }
$form .= ">CODELQ</option>";
$form .= "<option value=\"PRIQ\"";
- if ($this->GetScheduler() == "PRIQ")
+ if ($this->GetScheduler() == "PRIQ") {
$form .= " selected=\"selected\"";
+ }
$form .= ">PRIQ</option>";
$form .= "</select>";
$form .= "<br /> <span class=\"vexpl\">";
@@ -684,20 +756,24 @@ class altq_root_queue {
$form .= $this->GetBandwidth() . "\" />";
$form .= "<select id=\"bandwidthtype\" name=\"bandwidthtype\" class=\"formselect\">";
$form .= "<option value=\"Kb\"";
- if ($this->GetBwscale() == "Kb")
+ if ($this->GetBwscale() == "Kb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">Kbit/s</option>";
$form .= "<option value=\"Mb\"";
- if ($this->GetBwscale() == "Mb")
+ if ($this->GetBwscale() == "Mb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">Mbit/s</option>";
$form .= "<option value=\"Gb\"";
- if ($this->GetBwscale() == "Gb")
+ if ($this->GetBwscale() == "Gb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">Gbit/s</option>";
$form .= "<option value=\"b\"";
- if ($this->GetBwscale() == "b")
+ if ($this->GetBwscale() == "b") {
$form .= " selected=\"selected\"";
+ }
$form .= ">Bit/s</option>";
$form .= "</select>";
$form .= "</td></tr>";
@@ -714,14 +790,13 @@ class altq_root_queue {
$form .= "\" />";
$form .= "<br /> <span class=\"vexpl\">";
$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.");
+ . "If not specified, heuristics based on the interface "
+ . "bandwidth are used to determine the size.");
$form .= "</span></td></tr>";
$form .= "<input type=\"hidden\" id=\"interface\" name=\"interface\"";
$form .= " value=\"" . $this->GetInterface() . "\" />";
$form .= "<input type=\"hidden\" id=\"name\" name=\"name\" value=\"".$this->GetQname()."\" />";
-
return $form;
}
@@ -735,22 +810,26 @@ class altq_root_queue {
*/
function wconfig() {
$cflink = &get_reference_to_me_in_config($this->GetLink());
- if (!is_array($cflink))
+ if (!is_array($cflink)) {
$cflink = array();
+ }
$cflink['interface'] = $this->GetInterface();
$cflink['name'] = $this->GetQname();
$cflink['scheduler'] = $this->GetScheduler();
$cflink['bandwidth'] = $this->GetBandwidth();
$cflink['bandwidthtype'] = $this->GetBwscale();
$cflink['qlimit'] = trim($this->GetQlimit());
- if (empty($cflink['qlimit']))
+ if (empty($cflink['qlimit'])) {
unset($cflink['qlimit']);
+ }
$cflink['tbrconfig'] = trim($this->GetTbrConfig());
- if (empty($cflink['tbrconfig']))
+ if (empty($cflink['tbrconfig'])) {
unset($cflink['tbrconfig']);
+ }
$cflink['enabled'] = $this->GetEnabled();
- if (empty($cflink['enabled']))
+ if (empty($cflink['enabled'])) {
unset($cflink['enabled']);
+ }
}
}
@@ -858,12 +937,14 @@ class priq_queue {
$this->qbandwidthtype = $scale;
}
function GetDefaultQueuePresent() {
- if ($this->GetDefault())
+ if ($this->GetDefault()) {
return true;
+ }
if (!empty($this->subqueues)) {
foreach ($this->subqueues as $q) {
- if ($q->GetDefault())
+ if ($q->GetDefault()) {
return true;
+ }
}
}
@@ -955,14 +1036,14 @@ class priq_queue {
$q->copy_queue($interface, $cflink['queue'][$q->GetQname()]);
}
}
-
}
function clean_queue($sched) {
clean_child_queues($sched, $this->GetLink());
if (is_array($this->subqueues)) {
- foreach ($this->subqueues as $q)
+ foreach ($this->subqueues as $q) {
$q->clean_queue($sched);
+ }
}
}
@@ -970,8 +1051,9 @@ class priq_queue {
$qlist[$this->GetQname()] = & $this;
if (is_array($this->subqueues)) {
- foreach ($this->subqueues as $queue)
+ foreach ($this->subqueues as $queue) {
$queue->get_queue_list($qlist);
+ }
}
}
@@ -993,8 +1075,9 @@ class priq_queue {
}
function &find_queue($interface, $qname) {
- if ($qname == $this->GetQname())
+ if ($qname == $this->GetQname()) {
return $this;
+ }
}
function find_parentqueue($interface, $qname) { return; }
@@ -1005,25 +1088,32 @@ class priq_queue {
$reqdfieldsn[] = gettext("Name");
shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
- if ($data['bandwidth'] && (!is_numeric($data['bandwidth'])))
+ if ($data['bandwidth'] && (!is_numeric($data['bandwidth']))) {
$input_errors[] = "Bandwidth must be an integer.";
- if ($data['bandwidth'] < 0)
+ }
+ if ($data['bandwidth'] < 0) {
$input_errors[] = "Bandwidth cannot be negative.";
- if ($data['priority'] && (!is_numeric($data['priority'])
- || ($data['priority'] < 1) || ($data['priority'] > 15))) {
+ }
+ if ($data['priority'] && (!is_numeric($data['priority']) ||
+ ($data['priority'] < 1) || ($data['priority'] > 15))) {
$input_errors[] = gettext("The priority must be an integer between 1 and 15.");
}
- if ($data['qlimit'] && (!is_numeric($data['qlimit'])))
+ if ($data['qlimit'] && (!is_numeric($data['qlimit']))) {
$input_errors[] = gettext("Queue limit must be an integer");
- if ($data['qlimit'] < 0)
+ }
+ if ($data['qlimit'] < 0) {
$input_errors[] = gettext("Queue limit must be positive");
- if (!empty($data['newname']) && !preg_match("/^[a-zA-Z0-9_-]*$/", $data['newname']))
+ }
+ if (!empty($data['newname']) && !preg_match("/^[a-zA-Z0-9_-]*$/", $data['newname'])) {
$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only.");
- if (!empty($data['name']) && !preg_match("/^[a-zA-Z0-9_-]*$/", $data['name']))
+ }
+ if (!empty($data['name']) && !preg_match("/^[a-zA-Z0-9_-]*$/", $data['name'])) {
$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only.");
+ }
$default = $this->GetDefault();
- if (!empty($data['default']) && altq_get_default_queue($data['interface']) && empty($default))
+ if (!empty($data['default']) && altq_get_default_queue($data['interface']) && empty($default)) {
$input_errors[] = gettext("Only one default queue per interface is allowed.");
+ }
}
function ReadConfig(&$q) {
@@ -1031,58 +1121,70 @@ class priq_queue {
$this->SetQname($q['newname']);
} else if (!empty($q['newname'])) {
$this->SetQname($q['newname']);
- } else if (isset($q['name']))
+ } else if (isset($q['name'])) {
$this->SetQname($q['name']);
- if (isset($q['interface']))
+ }
+ if (isset($q['interface'])) {
$this->SetInterface($q['interface']);
+ }
$this->SetBandwidth($q['bandwidth']);
- if ($q['bandwidthtype'] <> "")
+ if ($q['bandwidthtype'] <> "") {
$this->SetBwscale($q['bandwidthtype']);
- if (!empty($q['qlimit']))
+ }
+ if (!empty($q['qlimit'])) {
$this->SetQlimit($q['qlimit']);
- else
+ } else {
$this->SetQlimit(""); // Default
- if (!empty($q['priority']))
+ }
+ if (!empty($q['priority'])) {
$this->SetQPriority($q['priority']);
- else
+ } else {
$this->SetQpriority("");
- if (!empty($q['description']))
+ }
+ if (!empty($q['description'])) {
$this->SetDescription($q['description']);
- else
+ } else {
$this->SetDescription("");
- if (!empty($q['red']))
+ }
+ if (!empty($q['red'])) {
$this->SetRed($q['red']);
- else
+ } else {
$this->SetRed();
- if (!empty($q['codel']))
+ }
+ if (!empty($q['codel'])) {
$this->SetCodel($q['codel']);
- else
+ } else {
$this->SetCodel();
- if (!empty($q['rio']))
+ }
+ if (!empty($q['rio'])) {
$this->SetRio($q['rio']);
- else
+ } else {
$this->SetRio();
- if (!empty($q['ecn']))
+ }
+ if (!empty($q['ecn'])) {
$this->SetEcn($q['ecn']);
- else
+ } else {
$this->SetEcn();
- if (!empty($q['default']))
+ }
+ if (!empty($q['default'])) {
$this->SetDefault($q['default']);
- else
+ } else {
$this->SetDefault();
- if (!empty($q['enabled']))
+ }
+ if (!empty($q['enabled'])) {
$this->SetEnabled($q['enabled']);
- else
+ } else {
$this->SetEnabled("");
-
+ }
}
function build_tree() {
$tree = " <li><a href=\"firewall_shaper.php?interface=". $this->GetInterface()."&amp;queue=". $this->GetQname()."&amp;action=show";
$tree .= "\" ";
$tmpvalue = $this->GetDefault();
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$tree .= " class=\"navlnk\"";
+ }
$tree .= " >" . $this->GetQname() . "</a>";
/*
* Not needed here!
@@ -1105,14 +1207,17 @@ class priq_queue {
*/
function build_rules(&$default = false) {
$pfq_rule = " queue ". $this->qname;
- if ($this->GetInterface())
+ if ($this->GetInterface()) {
$pfq_rule .= " on ".get_real_interface($this->GetInterface());
+ }
$tmpvalue = $this->GetQpriority();
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$pfq_rule .= " priority ".$this->GetQpriority();
+ }
$tmpvalue = $this->GetQlimit();
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$pfq_rule .= " qlimit " . $this->GetQlimit();
+ }
if ($this->GetRed() || $this->GetRio() || $this->GetEcn() || $this->GetDefault() || $this->GetCodel()) {
$pfq_rule .= " priq ( ";
$tmpvalue = $this->GetRed();
@@ -1122,29 +1227,33 @@ class priq_queue {
}
$tmpvalue = $this->GetRio();
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " rio ";
}
$tmpvalue = $this->GetEcn();
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " ecn ";
}
$tmpvalue = $this->GetCodel();
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " codel ";
}
$tmpvalue = $this->GetDefault();
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$pfq_rule .= " default ";
$default = true;
}
@@ -1168,8 +1277,9 @@ class priq_queue {
$form .= gettext("Enable/Disable");
$form .= "<br /></td><td class=\"vncellreq\">";
$form .= " <input type=\"checkbox\" id=\"enabled\" name=\"enabled\" value=\"on\"";
- if ($this->GetEnabled() == "on")
+ if ($this->GetEnabled() == "on") {
$form .= " checked=\"checked\"";
+ }
$form .= " /><span class=\"vexpl\"> " . gettext("Enable/Disable queue and its children") . "</span>";
$form .= "</td></tr>";
$form .= "<tr>";
@@ -1211,23 +1321,27 @@ class priq_queue {
}
$form .= "<input type=\"checkbox\" id=\"red\" name=\"red\" value=\"red\" ";
$tmpvalue = $this->GetRed();
- if(!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$form .= " checked=\"checked\"";
+ }
$form .= " /> <a target=\"_new\" href=\"http://www.openbsd.org/faq/pf/queueing.html#red\">" . gettext("Random Early Detection") . "</a><br />";
$form .= "<input type=\"checkbox\" id=\"rio\" name=\"rio\" value=\"rio\"";
$tmpvalue = $this->GetRio();
- if(!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$form .= " checked=\"checked\"";
+ }
$form .= " /> <a target=\"_new\" href=\"http://www.openbsd.org/faq/pf/queueing.html#rio\">" . gettext("Random Early Detection In and Out") . "</a><br />";
$form .= "<input type=\"checkbox\" id=\"ecn\" name=\"ecn\" value=\"ecn\"";
$tmpvalue = $this->GetEcn();
- if(!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$form .= " checked=\"checked\"";
+ }
$form .= " /> <a target=\"_new\" href=\"http://www.openbsd.org/faq/pf/queueing.html#ecn\">" . gettext("Explicit Congestion Notification") . "</a><br />";
$form .= "<input type=\"checkbox\" id=\"codel\" name=\"codel\" value=\"codel\"";
$tmpvalue = $this->GetCodel();
- if(!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$form .= " checked=\"checked\"";
+ }
$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");
$form .= "</span></td></tr><tr>";
@@ -1242,13 +1356,14 @@ class priq_queue {
}
function build_shortform() {
- /* XXX: Hacks in site. Mostly layer violations! */
+ /* XXX: Hacks in sight. Mostly layer violations! */
global $g, $altq_list_queues;
global $shaperIFlist;
$altq =& $altq_list_queues[$this->GetInterface()];
- if ($altq)
+ if ($altq) {
$scheduler = ": " . $altq->GetScheduler();
+ }
$form = "<tr><td width=\"20%\" class=\"vtable\">";
$form .= "<a href=\"firewall_shaper.php?interface=" . $this->GetInterface() . "&amp;queue=" . $this->GetQname()."&amp;action=show\">". $shaperIFlist[$this->GetInterface()] .$scheduler."</a>";
$form .= "</td></tr>";
@@ -1261,11 +1376,13 @@ class priq_queue {
$form .= gettext("Bandwidth:") . " " . $this->GetBandwidth().$this->GetBwscale();
$form .= "</td><td width=\"50%\"></td></tr>";
$tmpvalue = $this->GetQpriority();
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$form .= "<tr><td width=\"20%\" class=\"vncellreq\">" .gettext("Priority: on") . " </td></tr>";
+ }
$tmpvalue = $this->GetDefault();
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$form .= "<tr><td class=\"vncellreq\">" . gettext("Default: on") . " </td></tr>";
+ }
$form .= "<tr><td width=\"20%\" class=\"vncellreq\">";
$form .= "<a href=\"firewall_shaper_queues.php?interface=";
$form .= $this->GetInterface() . "&amp;queue=";
@@ -1279,43 +1396,53 @@ class priq_queue {
}
- function update_altq_queue_data(&$q) {
+ function update_altq_queue_data(&$q) {
$this->ReadConfig($q);
}
function wconfig() {
$cflink =& get_reference_to_me_in_config($this->GetLink());
- if (!is_array($cflink))
+ if (!is_array($cflink)) {
$cflink = array();
+ }
$cflink['name'] = $this->GetQname();
$cflink['interface'] = $this->GetInterface();
$cflink['qlimit'] = trim($this->GetQlimit());
- if (empty($cflink['qlimit']))
+ if (empty($cflink['qlimit'])) {
unset($cflink['qlimit']);
+ }
$cflink['priority'] = trim($this->GetQpriority());
- if (empty($cflink['priority']))
+ if (empty($cflink['priority'])) {
unset($cflink['priority']);
+ }
$cflink['description'] = trim($this->GetDescription());
- if (empty($cflink['description']))
+ if (empty($cflink['description'])) {
unset($cflink['description']);
+ }
$cflink['enabled'] = trim($this->GetEnabled());
- if (empty($cflink['enabled']))
+ if (empty($cflink['enabled'])) {
unset($cflink['enabled']);
+ }
$cflink['default'] = trim($this->GetDefault());
- if (empty($cflink['default']))
+ if (empty($cflink['default'])) {
unset($cflink['default']);
+ }
$cflink['red'] = trim($this->GetRed());
- if (empty($cflink['red']))
+ if (empty($cflink['red'])) {
unset($cflink['red']);
+ }
$cflink['codel'] = trim($this->GetCodel());
- if (empty($cflink['codel']))
+ if (empty($cflink['codel'])) {
unset($cflink['codel']);
+ }
$cflink['rio'] = trim($this->GetRio());
- if (empty($cflink['rio']))
+ if (empty($cflink['rio'])) {
unset($cflink['rio']);
+ }
$cflink['ecn'] = trim($this->GetEcn());
- if (empty($cflink['ecn']))
+ if (empty($cflink['ecn'])) {
unset($cflink['ecn']);
+ }
}
}
@@ -1426,8 +1553,9 @@ class hfsc_queue extends priq_queue {
function &add_queue($interface, &$qname, &$path, &$input_errors) {
- if (!is_array($this->subqueues))
+ if (!is_array($this->subqueues)) {
$this->subqueues = array();
+ }
$q =& new hfsc_queue();
$q->SetInterface($this->GetInterface());
$q->SetParent($this);
@@ -1441,12 +1569,12 @@ class hfsc_queue extends priq_queue {
$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;
+ 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);
@@ -1469,31 +1597,39 @@ class hfsc_queue extends priq_queue {
$cflink['name'] = $this->GetQname();
$cflink['interface'] = $interface;
$cflink['qlimit'] = trim($this->GetQlimit());
- if (empty($cflink['qlimit']))
+ if (empty($cflink['qlimit'])) {
unset($cflink['qlimit']);
+ }
$cflink['priority'] = trim($this->GetQpriority());
- if (empty($cflink['priority']))
+ if (empty($cflink['priority'])) {
unset($cflink['priority']);
+ }
$cflink['description'] = trim($this->GetDescription());
- if (empty($cflink['description']))
+ if (empty($cflink['description'])) {
unset($cflink['description']);
+ }
$cflink['bandwidth'] = $this->GetBandwidth();
$cflink['bandwidthtype'] = $this->GetBwscale();
$cflink['enabled'] = trim($this->GetEnabled());
- if (empty($cflink['enabled']))
+ if (empty($cflink['enabled'])) {
unset($cflink['enabled']);
+ }
$cflink['default'] = trim($this->GetDefault());
- if (empty($cflink['default']))
+ if (empty($cflink['default'])) {
unset($cflink['default']);
+ }
$cflink['red'] = trim($this->GetRed());
- if (empty($cflink['red']))
+ if (empty($cflink['red'])) {
unset($cflink['red']);
+ }
$cflink['rio'] = trim($this->GetRio());
- if (empty($cflink['rio']))
+ if (empty($cflink['rio'])) {
unset($cflink['rio']);
+ }
$cflink['ecn'] = trim($this->GetEcn());
- if (empty($cflink['ecn']))
+ if (empty($cflink['ecn'])) {
unset($cflink['ecn']);
+ }
if ($this->GetLinkshare() <> "") {
if ($this->GetL_m1() <> "") {
$cflink['linkshare1'] = $this->GetL_m1();
@@ -1563,8 +1699,8 @@ class hfsc_queue extends priq_queue {
cleanup_queue_from_rules($this->GetQname());
$parent =& $this->GetParent();
foreach ($this->subqueues as $q) {
- $this->SetAvailableBandwidth($this->GetAvailableBandwidth() + $q->GetAvailableBandwidth());
- $q->delete_queue();
+ $this->SetAvailableBandwidth($this->GetAvailableBandwidth() + $q->GetAvailableBandwidth());
+ $q->delete_queue();
}
unset_object_by_reference($this->GetLink());
}
@@ -1573,23 +1709,27 @@ class hfsc_queue extends priq_queue {
* Should search even its children
*/
function &find_queue($interface, $qname) {
- if ($qname == $this->GetQname())
+ if ($qname == $this->GetQname()) {
return $this;
+ }
foreach ($this->subqueues as $q) {
$result =& $q->find_queue("", $qname);
- if ($result)
+ if ($result) {
return $result;
+ }
}
}
function &find_parentqueue($interface, $qname) {
- if ($this->subqueues[$qname])
+ if ($this->subqueues[$qname]) {
return $this;
+ }
foreach ($this->subqueues as $q) {
$result = $q->find_parentqueue("", $qname);
- if ($result)
+ if ($result) {
return $result;
+ }
}
}
@@ -1604,15 +1744,18 @@ class hfsc_queue extends priq_queue {
shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
if (isset($data['linkshare3']) && $data['linkshare3'] <> "") {
- if ($data['bandwidth'] && (!is_numeric($data['bandwidth'])))
+ if ($data['bandwidth'] && (!is_numeric($data['bandwidth']))) {
$input_errors[] = gettext("Bandwidth must be an integer.");
+ }
- if ($data['bandwidth'] < 0)
+ if ($data['bandwidth'] < 0) {
$input_errors[] = gettext("Bandwidth cannot be negative.");
+ }
if ($data['bandwidthtype'] == "%") {
- if ($data['bandwidth'] > 100 || $data['bandwidth'] < 0)
+ if ($data['bandwidth'] > 100 || $data['bandwidth'] < 0) {
$input_errors[] = gettext("Bandwidth in percentage should be between 1 and 100 bounds.");
+ }
}
/*
$parent =& $this->GetParent();
@@ -1623,76 +1766,98 @@ class hfsc_queue extends priq_queue {
$mybw = floatval($data['bandwidth']) * get_bandwidthtype_scale($data['bandwidthtype']);
break;
}
- if ($parent->GetAvailableBandwidth() < $myBw)
+ if ($parent->GetAvailableBandwidth() < $myBw) {
$input_errors[] = "The sum of children bandwidth exceeds that of the parent.";
+ }
*/
}
- if ($data['upperlimit1'] <> "" && $data['upperlimit2'] == "")
+ if ($data['upperlimit1'] <> "" && $data['upperlimit2'] == "") {
$input_errors[] = gettext("upperlimit service curve defined but missing (d) value");
- if ($data['upperlimit2'] <> "" && $data['upperlimit1'] == "")
+ }
+ if ($data['upperlimit2'] <> "" && $data['upperlimit1'] == "") {
$input_errors[] = gettext("upperlimit service curve defined but missing initial bandwidth (m1) value");
- if ($data['upperlimit1'] <> "" && !is_valid_shaperbw($data['upperlimit1']))
+ }
+ if ($data['upperlimit1'] <> "" && !is_valid_shaperbw($data['upperlimit1'])) {
$input_errors[] = gettext("upperlimit m1 value needs to be Kb, Mb, Gb, or %");
- if ($data['upperlimit2'] <> "" && !is_numeric($data['upperlimit2']))
+ }
+ if ($data['upperlimit2'] <> "" && !is_numeric($data['upperlimit2'])) {
$input_errors[] = gettext("upperlimit d value needs to be numeric");
- if ($data['upperlimit3'] <> "" && !is_valid_shaperbw($data['upperlimit3']))
+ }
+ if ($data['upperlimit3'] <> "" && !is_valid_shaperbw($data['upperlimit3'])) {
$input_errors[] = gettext("upperlimit m2 value needs to be Kb, Mb, Gb, or %");
+ }
/*
if (isset($data['upperlimit']) && $data['upperlimit3'] <> "" && $data['upperlimit1'] <> "") {
$bw_1 = get_hfsc_bandwidth($this, $data['upperlimit1']);
$bw_2 = get_hfsc_bandwidth($this, $data['upperlimit3']);
- if (floatval($bw_1) < floatval($bw_2))
+ if (floatval($bw_1) < floatval($bw_2)) {
$input_errors[] = ("upperlimit m1 cannot be smaller than m2");
+ }
- if (get_interface_bandwidth($this) < (0.8 * (floatval($bw_1) + floatval($bw_2))))
+ if (get_interface_bandwidth($this) < (0.8 * (floatval($bw_1) + floatval($bw_2)))) {
$input_errors[] = ("upperlimit specification exceeds 80% of allowable allocation.");
+ }
}
*/
- if ($data['linkshare1'] <> "" && $data['linkshare2'] == "")
+ if ($data['linkshare1'] <> "" && $data['linkshare2'] == "") {
$input_errors[] = gettext("linkshare service curve defined but missing (d) value");
- if ($data['linkshare2'] <> "" && $data['linkshare1'] == "")
+ }
+ if ($data['linkshare2'] <> "" && $data['linkshare1'] == "") {
$input_errors[] = gettext("linkshare service curve defined but missing initial bandwidth (m1) value");
- if ($data['linkshare1'] <> "" && !is_valid_shaperbw($data['linkshare1']))
+ }
+ if ($data['linkshare1'] <> "" && !is_valid_shaperbw($data['linkshare1'])) {
$input_errors[] = gettext("linkshare m1 value needs to be Kb, Mb, Gb, or %");
- if ($data['linkshare2'] <> "" && !is_numeric($data['linkshare2']))
+ }
+ if ($data['linkshare2'] <> "" && !is_numeric($data['linkshare2'])) {
$input_errors[] = gettext("linkshare d value needs to be numeric");
- if ($data['linkshare3'] <> "" && !is_valid_shaperbw($data['linkshare3']))
+ }
+ if ($data['linkshare3'] <> "" && !is_valid_shaperbw($data['linkshare3'])) {
$input_errors[] = gettext("linkshare m2 value needs to be Kb, Mb, Gb, or %");
- if ($data['realtime1'] <> "" && $data['realtime2'] == "")
+ }
+ if ($data['realtime1'] <> "" && $data['realtime2'] == "") {
$input_errors[] = gettext("realtime service curve defined but missing (d) value");
- if ($data['realtime2'] <> "" && $data['realtime1'] == "")
+ }
+ if ($data['realtime2'] <> "" && $data['realtime1'] == "") {
$input_errors[] = gettext("realtime service curve defined but missing initial bandwidth (m1) value");
+ }
/*
if (isset($data['linkshare']) && $data['linkshare3'] <> "" && $data['linkshare1'] <> "" && 0) {
$bw_1 = get_hfsc_bandwidth($this, $data['linkshare1']);
$bw_2 = get_hfsc_bandwidth($this, $data['linkshare3']);
- if (floatval($bw_1) < floatval($bw_2))
+ if (floatval($bw_1) < floatval($bw_2)) {
$input_errors[] = ("linkshare m1 cannot be smaller than m2");
+ }
- if (get_interface_bandwidth($this) < (0.8 * (floatval($bw_1) + floatval($bw_2))))
+ if (get_interface_bandwidth($this) < (0.8 * (floatval($bw_1) + floatval($bw_2)))) {
$input_errors[] = ("linkshare specification exceeds 80% of allowable allocation.");
+ }
}
*/
- if ($data['realtime1'] <> "" && !is_valid_shaperbw($data['realtime1']))
+ if ($data['realtime1'] <> "" && !is_valid_shaperbw($data['realtime1'])) {
$input_errors[] = gettext("realtime m1 value needs to be Kb, Mb, Gb, or %");
- if ($data['realtime2'] <> "" && !is_numeric($data['realtime2']))
+ }
+ if ($data['realtime2'] <> "" && !is_numeric($data['realtime2'])) {
$input_errors[] = gettext("realtime d value needs to be numeric");
- if ($data['realtime3'] <> "" && !is_valid_shaperbw($data['realtime3']))
+ }
+ if ($data['realtime3'] <> "" && !is_valid_shaperbw($data['realtime3'])) {
$input_errors[] = gettext("realtime m2 value needs to be Kb, Mb, Gb, or %");
+ }
/*
if (isset($data['realtime']) && $data['realtime3'] <> "" && $data['realtime1'] <> "" && 0) {
$bw_1 = get_hfsc_bandwidth($this, $data['realtime1']);
$bw_2 = get_hfsc_bandwidth($this, $data['realtime3']);
- if (floatval($bw_1) < floatval($bw_2))
+ if (floatval($bw_1) < floatval($bw_2)) {
$input_errors[] = ("realtime m1 cannot be smaller than m2");
+ }
- if (get_interface_bandwidth($this) < (0.8 * (floatval($bw_1) + floatval($bw_2))))
+ if (get_interface_bandwidth($this) < (0.8 * (floatval($bw_1) + floatval($bw_2)))) {
$input_errors[] = ("realtime specification exceeds 80% of allowable allocation.");
+ }
}
*/
}
@@ -1712,8 +1877,9 @@ class hfsc_queue extends priq_queue {
$this->SetL_m2($cflink['linkshare3']);
$this->SetLinkshare();
}
- } else
+ } else {
$this->DisableLinkshare();
+ }
if (!empty($cflink['realtime'])) {
if (!empty($cflink['realtime1'])) {
$this->SetR_m1($cflink['realtime1']);
@@ -1728,8 +1894,9 @@ class hfsc_queue extends priq_queue {
$this->SetR_m2($cflink['realtime3']);
$this->SetRealtime();
}
- } else
+ } else {
$this->DisableRealtime();
+ }
if (!empty($cflink['upperlimit'])) {
if (!empty($cflink['upperlimit1'])) {
$this->SetU_m1($cflink['upperlimit1']);
@@ -1744,8 +1911,9 @@ class hfsc_queue extends priq_queue {
$this->SetU_m2($cflink['upperlimit3']);
$this->SetUpperlimit();
}
- } else
+ } else {
$this->DisableUpperlimit();
+ }
parent::ReadConfig($cflink);
}
@@ -1753,8 +1921,9 @@ class hfsc_queue extends priq_queue {
$tree = " <li><a href=\"firewall_shaper.php?interface=" . $this->GetInterface() ."&amp;queue=" . $this->GetQname()."&amp;action=show";
$tree .= "\" ";
$tmpvalue = $this->GetDefault();
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$tree .= " class=\"navlnk\"";
+ }
$tree .= " >" . $this->GetQname() . "</a>";
if (is_array($this->subqueues)) {
$tree .= "<ul>";
@@ -1771,14 +1940,17 @@ class hfsc_queue extends priq_queue {
function build_rules(&$default = false) {
$pfq_rule = " queue ". $this->qname;
- if ($this->GetInterface())
+ if ($this->GetInterface()) {
$pfq_rule .= " on ".get_real_interface($this->GetInterface());
- if ($this->GetBandwidth() && $this->GetBwscale())
+ }
+ if ($this->GetBandwidth() && $this->GetBwscale()) {
$pfq_rule .= " bandwidth ".trim($this->GetBandwidth()).$this->GetBwscale();
+ }
$tmpvalue = $this->GetQlimit();
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$pfq_rule .= " qlimit " . $this->GetQlimit();
+ }
if ($this->GetDefault() || $this->GetRed() || $this->GetRio() || $this->GetEcn() || $this->GetCodel() || $this->GetRealtime() <> "" || $this->GetLinkshare() <> "" || $this->GetUpperlimit() <> "") {
$pfq_rule .= " hfsc ( ";
$tmpvalue = $this->GetRed();
@@ -1789,59 +1961,69 @@ class hfsc_queue extends priq_queue {
$tmpvalue = $this->GetRio();
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " rio ";
}
$tmpvalue = $this->GetEcn();
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " ecn ";
}
$tmpvalue = $this->GetCodel();
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " codel ";
}
$tmpvalue = $this->GetDefault();
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " default ";
$default = true;
}
if ($this->GetRealtime() <> "") {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " , ";
- if ($this->GetR_m1() <> "" && $this->GetR_d() <> "" && $this->GetR_m2() <> "")
+ }
+ if ($this->GetR_m1() <> "" && $this->GetR_d() <> "" && $this->GetR_m2() <> "") {
$pfq_rule .= " realtime (".$this->GetR_m1() . ", " . $this->GetR_d().", ". $this->GetR_m2() .") ";
- else if ($this->GetR_m2() <> "")
+ } else if ($this->GetR_m2() <> "") {
$pfq_rule .= " realtime " . $this->GetR_m2();
+ }
$comma = 1;
}
if ($this->GetLinkshare() <> "") {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
- if ($this->GetL_m1() <> "" && $this->GetL_d() <> "" && $this->GetL_m2() <> "")
+ }
+ if ($this->GetL_m1() <> "" && $this->GetL_d() <> "" && $this->GetL_m2() <> "") {
$pfq_rule .= " linkshare (".$this->GetL_m1(). ", ". $this->GetL_d(). ", ". $this->GetL_m2(). ") ";
- else if ($this->GetL_m2() <> "")
+ } else if ($this->GetL_m2() <> "") {
$pfq_rule .= " linkshare " . $this->GetL_m2() . " ";
+ }
$comma = 1;
}
if ($this->GetUpperlimit() <> "") {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
- if ($this->GetU_m1() <> "" && $this->GetU_d() <> "" && $this->GetU_m2() <> "")
+ }
+ 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() <> "")
+ } else if ($this->GetU_m2() <> "") {
$pfq_rule .= " upperlimit " . $this->GetU_m2() . " ";
+ }
}
$pfq_rule .= " ) ";
}
@@ -1852,12 +2034,14 @@ class hfsc_queue extends priq_queue {
if ($i > 1) {
$i--;
$pfq_rule .= " {$qkey}, ";
- } else
+ } else {
$pfq_rule .= " {$qkey} ";
+ }
}
$pfq_rule .= " } \n";
- foreach ($this->subqueues as $q)
+ foreach ($this->subqueues as $q) {
$pfq_rule .= $q->build_rules($default);
+ }
}
$pfq_rule .= " \n";
@@ -1918,24 +2102,29 @@ class hfsc_queue extends priq_queue {
$form .= "\" />";
$form .= "<select name=\"bandwidthtype\" id=\"bandwidthtype\" class=\"formselect\">";
$form .= "<option value=\"Gb\"";
- if ($this->GetBwscale() == "Gb")
+ if ($this->GetBwscale() == "Gb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Gbit/s") . "</option>";
$form .= "<option value=\"Mb\"";
- if ($this->GetBwscale() == "Mb")
+ if ($this->GetBwscale() == "Mb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Mbit/s") . "</option>";
$form .= "<option value=\"Kb\"";
- if ($this->GetBwscale() == "Kb")
+ if ($this->GetBwscale() == "Kb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Kbit/s") . "</option>";
$form .= "<option value=\"b\"";
- if ($this->GetBwscale() == "b")
+ if ($this->GetBwscale() == "b") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Bit/s") . "</option>";
$form .= "<option value=\"%\"";
- if ($this->GetBwscale() == "%")
+ if ($this->GetBwscale() == "%") {
$form .= " selected=\"selected\"";
+ }
$form .= ">%</option>";
$form .= "</select> <br />";
$form .= "<span class=\"vexpl\">" . gettext("Choose the amount of bandwidth for this queue");
@@ -1946,67 +2135,79 @@ class hfsc_queue extends priq_queue {
$form .= "<table>";
$form .= "<tr><td>&nbsp;</td><td><center>m1</center></td><td><center>d</center></td><td><center><b>m2</b></center></td></tr>";
$form .= "<tr><td><input type=\"checkbox\" id=\"upperlimit\" name=\"upperlimit\"";
- if($this->GetUpperlimit()<> "")
+ if ($this->GetUpperlimit()<> "") {
$form .= " checked=\"checked\" ";
+ }
$form .= "onchange=\"enable_upperlimit()\" /> " . gettext("Upperlimit:") . "</td><td><input size=\"6\" value=\"";
$form .= htmlspecialchars($this->GetU_m1());
$form .= "\" id=\"upperlimit1\" name=\"upperlimit1\" ";
- if ($this->GetUpperlimit() == "")
+ if ($this->GetUpperlimit() == "") {
$form .= " disabled=\"disabled\"";
+ }
$form .= " /></td><td><input size=\"6\" value=\"";
$form .= htmlspecialchars($this->GetU_d());
$form .= "\" id=\"upperlimi2\" name=\"upperlimit2\" ";
- if ($this->GetUpperlimit() == "")
+ if ($this->GetUpperlimit() == "") {
$form .= " disabled=\"disabled\"";
+ }
$form .= " /></td><td><input size=\"6\" value=\"";
$form .= htmlspecialchars($this->GetU_m2());
$form .= "\" id=\"upperlimit3\" name=\"upperlimit3\" ";
- if ($this->GetUpperlimit() == "")
+ if ($this->GetUpperlimit() == "") {
$form .= " disabled=\"disabled\"";
+ }
$form .= " /></td><td>" . gettext("The maximum allowed bandwidth for the queue.") . "</td></tr>";
$form .= "<tr><td><input type=\"checkbox\" id=\"realtime\" name=\"realtime\"";
- if($this->GetRealtime() <> "")
+ if ($this->GetRealtime() <> "") {
$form .= " checked=\"checked\" ";
+ }
$form .= "onchange=\"enable_realtime()\" /> " . gettext("Real time:") . "</td><td><input size=\"6\" value=\"";
$form .= htmlspecialchars($this->GetR_m1());
$form .= "\" id=\"realtime1\" name=\"realtime1\" ";
- if ($this->GetRealtime() == "")
+ if ($this->GetRealtime() == "") {
$form .= " disabled=\"disabled\"";
+ }
$form .= " /></td><td><input size=\"6\" value=\"";
$form .= htmlspecialchars($this->GetR_d());
$form .= "\" id=\"realtime2\" name=\"realtime2\" ";
- if ($this->GetRealtime() == "")
+ if ($this->GetRealtime() == "") {
$form .= " disabled=\"disabled\"";
+ }
$form .= " /></td><td><input size=\"6\" value=\"";
$form .= htmlspecialchars($this->GetR_m2());
$form .= "\" id=\"realtime3\" name=\"realtime3\" ";
- if ($this->GetRealtime() == "")
+ if ($this->GetRealtime() == "") {
$form .= " disabled=\"disabled\"";
+ }
$form .= " /></td><td>" . gettext("The minimum required bandwidth for the queue.") . "</td></tr>";
$form .= "<tr><td><input type=\"checkbox\" id=\"linkshare\" name=\"linkshare\"";
- if($this->GetLinkshare() <> "")
+ if ($this->GetLinkshare() <> "") {
$form .= " checked=\"checked\" ";
+ }
$form .= "onchange=\"enable_linkshare()\" /> " . gettext("Link share:") . "</td><td><input size=\"6\" value=\"";
$form .= htmlspecialchars($this->GetL_m1());
$form .= "\" id=\"linkshare1\" name=\"linkshare1\" ";
- if ($this->GetLinkshare() == "")
+ if ($this->GetLinkshare() == "") {
$form .= " disabled=\"disabled\"";
+ }
$form .= " /></td><td><input size=\"6\" value=\"";
$form .= htmlspecialchars($this->GetL_d());
$form .= "\" id=\"linkshare2\" name=\"linkshare2\" ";
- if ($this->GetLinkshare() == "")
+ if ($this->GetLinkshare() == "") {
$form .= " disabled=\"disabled\"";
+ }
$form .= " /></td><td><input size=\"6\" value=\"";
$form .= htmlspecialchars($this->GetL_m2());
$form .= "\" id=\"linkshare3\" name=\"linkshare3\" ";
- if ($this->GetLinkshare() == "")
+ if ($this->GetLinkshare() == "") {
$form .= " disabled=\"disabled\"";
+ }
$form .= " /></td><td>" . gettext("The bandwidth share of a backlogged queue - this overrides priority.") . "</td></tr>";
$form .= "</table><br />";
$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.");
+ . "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.");
$form .= "</td>";
$form .= "</tr>";
@@ -2019,39 +2220,49 @@ class hfsc_queue extends priq_queue {
function wconfig() {
$cflink =& get_reference_to_me_in_config($this->GetLink());
- if (!is_array($cflink))
+ if (!is_array($cflink)) {
$cflink = array();
+ }
$cflink['name'] = $this->GetQname();
$cflink['interface'] = $this->GetInterface();
$cflink['qlimit'] = trim($this->GetQlimit());
- if (empty($cflink['qlimit']))
+ if (empty($cflink['qlimit'])) {
unset($cflink['qlimit']);
+ }
$cflink['priority'] = $this->GetQpriority();
- if (empty($cflink['priority']))
+ if (empty($cflink['priority'])) {
unset($cflink['priority']);
+ }
$cflink['description'] = $this->GetDescription();
- if (empty($cflink['description']))
+ if (empty($cflink['description'])) {
unset($cflink['description']);
+ }
$cflink['bandwidth'] = $this->GetBandwidth();
$cflink['bandwidthtype'] = $this->GetBwscale();
$cflink['enabled'] = $this->GetEnabled();
- if (empty($cflink['enabled']))
+ if (empty($cflink['enabled'])) {
unset($cflink['enabled']);
+ }
$cflink['default'] = $this->GetDefault();
- if (empty($cflink['default']))
+ if (empty($cflink['default'])) {
unset($cflink['default']);
+ }
$cflink['red'] = trim($this->GetRed());
- if (empty($cflink['red']))
+ if (empty($cflink['red'])) {
unset($cflink['red']);
+ }
$cflink['rio'] = $this->GetRio();
- if (empty($cflink['rio']))
+ if (empty($cflink['rio'])) {
unset($cflink['rio']);
+ }
$cflink['ecn'] = trim($this->GetEcn());
- if (empty($cflink['ecn']))
+ if (empty($cflink['ecn'])) {
unset($cflink['ecn']);
+ }
$cflink['codel'] = trim($this->GetCodel());
- if (empty($cflink['codel']))
+ if (empty($cflink['codel'])) {
unset($cflink['codel']);
+ }
if ($this->GetLinkshare() <> "") {
if ($this->GetL_m1() <> "") {
$cflink['linkshare1'] = $this->GetL_m1();
@@ -2139,8 +2350,9 @@ class cbq_queue extends priq_queue {
function &add_queue($interface, &$qname, &$path, &$input_errors) {
- if (!is_array($this->subqueues))
+ if (!is_array($this->subqueues)) {
$this->subqueues = array();
+ }
$q =& new cbq_queue();
$q->SetInterface($this->GetInterface());
$q->SetParent($this);
@@ -2151,12 +2363,12 @@ class cbq_queue extends priq_queue {
return $q;
}
switch ($q->GetBwscale()) {
- case "%":
- $myBw = $this->GetAvailableBandwidth() * $qname['bandwidth'] / 100;
- break;
- default:
- $myBw = $qname['bandwidth'] * get_bandwidthtype_scale($q->GetBwscale());
- break;
+ 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);
@@ -2180,35 +2392,44 @@ class cbq_queue extends priq_queue {
$cflink['interface'] = $interface;
$cflink['qlimit'] = trim($this->GetQlimit());
- if (empty($clink['qlimit']))
+ if (empty($clink['qlimit'])) {
unset($cflink['qlimit']);
+ }
$cflink['priority'] = trim($this->GetQpriority());
- if (empty($cflink['priority']))
+ if (empty($cflink['priority'])) {
unset($cflink['priority']);
+ }
$cflink['name'] = $this->GetQname();
$cflink['description'] = trim($this->GetDescription());
- if (empty($cflink['description']))
+ if (empty($cflink['description'])) {
unset($cflink['description']);
+ }
$cflink['bandwidth'] = $this->GetBandwidth();
$cflink['bandwidthtype'] = $this->GetBwscale();
$cflink['enabled'] = trim($this->GetEnabled());
- if (empty($cflink['enabled']))
+ if (empty($cflink['enabled'])) {
unset($cflink['enabled']);
+ }
$cflink['default'] = trim($this->GetDefault());
- if (empty($cflink['default']))
+ if (empty($cflink['default'])) {
unset($cflink['default']);
+ }
$cflink['red'] = trim($this->GetRed());
- if (empty($cflink['red']))
+ if (empty($cflink['red'])) {
unset($cflink['red']);
+ }
$cflink['rio'] = trim($this->GetRio());
- if (empty($cflink['rio']))
+ if (empty($cflink['rio'])) {
unset($cflink['rio']);
+ }
$cflink['ecn'] = trim($this->GetEcn());
- if (empty($cflink['ecn']))
+ if (empty($cflink['ecn'])) {
unset($cflink['ecn']);
+ }
$cflink['borrow'] = trim($this->GetBorrow());
- if (empty($cflink['borrow']))
+ if (empty($cflink['borrow'])) {
unset($cflink['borrow']);
+ }
if (is_array($this->queues)) {
$cflinkp['queue'] = array();
foreach ($this->subqueues as $q) {
@@ -2222,22 +2443,26 @@ class cbq_queue extends priq_queue {
* Should search even its children
*/
function &find_queue($interface, $qname) {
- if ($qname == $this->GetQname())
+ if ($qname == $this->GetQname()) {
return $this;
+ }
foreach ($this->subqueues as $q) {
$result =& $q->find_queue("", $qname);
- if ($result)
+ if ($result) {
return $result;
+ }
}
}
function &find_parentqueue($interface, $qname) {
- if ($this->subqueues[$qname])
+ if ($this->subqueues[$qname]) {
return $this;
+ }
foreach ($this->subqueues as $q) {
$result = $q->find_parentqueue("", $qname);
- if ($result)
+ if ($result) {
return $result;
+ }
}
}
@@ -2245,8 +2470,8 @@ class cbq_queue extends priq_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();
+ $this->SetAvailableBandwidth($this->GetAvailableBandwidth() + $q->GetAvailableBandwidth());
+ $q->delete_queue();
}
unset_object_by_reference($this->GetLink());
}
@@ -2254,8 +2479,9 @@ class cbq_queue extends priq_queue {
function validate_input($data, &$input_errors) {
parent::validate_input($data, $input_errors);
- if ($data['priority'] > 7)
+ if ($data['priority'] > 7) {
$input_errors[] = gettext("Priority must be an integer between 1 and 7.");
+ }
$reqdfields[] = "bandwidth";
$reqdfieldsn[] = gettext("Bandwidth");
$reqdfields[] = "bandwidthtype";
@@ -2263,16 +2489,19 @@ class cbq_queue extends priq_queue {
shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
- if ($data['bandwidth'] && !is_numeric($data['bandwidth']))
+ if ($data['bandwidth'] && !is_numeric($data['bandwidth'])) {
$input_errors[] = gettext("Bandwidth must be an integer.");
+ }
- if ($data['bandwidth'] < 0)
+ if ($data['bandwidth'] < 0) {
$input_errors[] = gettext("Bandwidth cannot be negative.");
+ }
if ($data['bandwidthtype'] == "%") {
- if ($data['bandwidth'] > 100 || $data['bandwidth'] < 0)
+ if ($data['bandwidth'] > 100 || $data['bandwidth'] < 0) {
$input_errors[] = gettext("Bandwidth in percentage should be between 1 and 100 bounds.");
+ }
}
/*
@@ -2285,17 +2514,19 @@ class cbq_queue extends priq_queue {
$mybw = floatval($data['bandwidth']) * get_bandwidthtype_scale($data['bandwidthtype']);
break;
}
- if ($parent->GetAvailableBandwidth() < floatval($myBw))
+ if ($parent->GetAvailableBandwidth() < floatval($myBw)) {
$input_errors[] = "The sum of the children bandwidth exceeds that of the parent.";
+ }
*/
}
function ReadConfig(&$q) {
parent::ReadConfig($q);
- if (!empty($q['borrow']))
+ if (!empty($q['borrow'])) {
$this->SetBorrow("on");
- else
+ } else {
$this->SetBorrow("");
+ }
}
function build_javascript() {
@@ -2306,8 +2537,9 @@ class cbq_queue extends priq_queue {
$tree = " <li><a href=\"firewall_shaper.php?interface=" . $this->GetInterface()."&amp;queue=" . $this->GetQname()."&amp;action=show";
$tree .= "\" ";
$tmpvalue = trim($this->GetDefault());
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$tree .= " class=\"navlnk\"";
+ }
$tree .= " >" . $this->GetQname() . "</a>";
if (is_array($this->subqueues)) {
$tree .= "<ul>";
@@ -2323,16 +2555,20 @@ class cbq_queue extends priq_queue {
/* Even this should take children into consideration */
function build_rules(&$default = false) {
$pfq_rule = "queue ". $this->qname;
- if ($this->GetInterface())
+ if ($this->GetInterface()) {
$pfq_rule .= " on ".get_real_interface($this->GetInterface());
- if ($this->GetBandwidth() && $this->GetBwscale())
+ }
+ if ($this->GetBandwidth() && $this->GetBwscale()) {
$pfq_rule .= " bandwidth ".trim($this->GetBandwidth()).$this->GetBwscale();
+ }
$tmpvalue = $this->GetQpriority();
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$pfq_rule .= " priority " . $this->GetQpriority();
+ }
$tmpvalue = trim($this->GetQlimit());
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$pfq_rule .= " qlimit " . $this->GetQlimit();
+ }
if ($this->GetDefault() || $this->GetRed() || $this->GetRio() || $this->GetEcn() || $this->GetBorrow() || $this->GetCodel()) {
$pfq_rule .= " cbq ( ";
$tmpvalue = trim($this->GetRed());
@@ -2347,30 +2583,34 @@ class cbq_queue extends priq_queue {
}
$tmpvalue = trim($this->GetRio());
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " rio ";
}
$tmpvalue = trim($this->GetEcn());
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " ecn ";
}
$tmpvalue = trim($this->GetDefault());
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " default ";
$default = true;
}
$tmpvalue = trim($this->GetBorrow());
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= ", ";
+ }
$pfq_rule .= " borrow ";
}
$pfq_rule .= " ) ";
@@ -2382,12 +2622,14 @@ class cbq_queue extends priq_queue {
if ($i > 1) {
$i--;
$pfq_rule .= " {$qkey}, ";
- } else
+ } else {
$pfq_rule .= " {$qkey} ";
+ }
}
$pfq_rule .= " } \n";
- foreach ($this->subqueues as $q)
+ foreach ($this->subqueues as $q) {
$pfq_rule .= $q->build_rules($default);
+ }
}
$pfq_rule .= " \n";
@@ -2399,37 +2641,44 @@ class cbq_queue extends priq_queue {
$form .= "<tr>";
$form .= "<td valign=\"middle\" class=\"vncellreq\">" . gettext("Bandwidth") . "</td>";
$form .= "<td class=\"vtable\"> <input name=\"bandwidth\" id=\"bandwidth\" class=\"formfld unknown\" value=\"";
- if ($this->GetBandwidth() > 0)
+ if ($this->GetBandwidth() > 0) {
$form .= htmlspecialchars($this->GetBandwidth());
+ }
$form .= "\" />";
$form .= "<select name=\"bandwidthtype\" id=\"bandwidthtype\" class=\"formselect\">";
$form .= "<option value=\"Gb\"";
- if ($this->GetBwscale() == "Gb")
+ if ($this->GetBwscale() == "Gb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Gbit/s") . "</option>";
$form .= "<option value=\"Mb\"";
- if ($this->GetBwscale() == "Mb")
+ if ($this->GetBwscale() == "Mb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Mbit/s") . "</option>";
$form .= "<option value=\"Kb\"";
- if ($this->GetBwscale() == "Kb")
+ if ($this->GetBwscale() == "Kb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Kbit/s") . "</option>";
$form .= "<option value=\"b\"";
- if ($this->GetBwscale() == "b")
+ if ($this->GetBwscale() == "b") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Bit/s") . "</option>";
$form .= "<option value=\"%\"";
- if ($this->GetBwscale() == "%")
+ if ($this->GetBwscale() == "%") {
$form .= " selected=\"selected\"";
+ }
$form .= ">%</option>";
$form .= "</select> <br />";
$form .= "<span class=\"vexpl\">" . gettext("Choose the amount of bandwidth for this queue");
$form .= "</span></td></tr>";
$form .= "<tr><td class=\"vncellreq\">" . gettext("Scheduler specific options") . "</td>";
$form .= "<td class=\"vtable\"><input type=\"checkbox\" id=\"borrow\" name=\"borrow\"";
- if($this->GetBorrow() == "on")
+ if ($this->GetBorrow() == "on") {
$form .= " checked=\"checked\" ";
+ }
$form .= " /> " . gettext("Borrow from other queues when available") . "<br /></td></tr>";
return $form;
@@ -2441,42 +2690,53 @@ class cbq_queue extends priq_queue {
function wconfig() {
$cflink =& get_reference_to_me_in_config($this->GetLink());
- if (!is_array($cflink))
+ if (!is_array($cflink)) {
$cflink = array();
+ }
$cflink['interface'] = $this->GetInterface();
$cflink['qlimit'] = trim($this->GetQlimit());
- if (empty($cflink['qlimit']))
+ if (empty($cflink['qlimit'])) {
unset($cflink['qlimit']);
+ }
$cflink['priority'] = $this->GetQpriority();
- if (empty($cflink['priority']))
+ if (empty($cflink['priority'])) {
unset($cflink['priority']);
+ }
$cflink['name'] = $this->GetQname();
$cflink['description'] = $this->GetDescription();
- if (empty($cflink['description']))
+ if (empty($cflink['description'])) {
unset($cflink['description']);
+ }
$cflink['bandwidth'] = $this->GetBandwidth();
$cflink['bandwidthtype'] = $this->GetBwscale();
$cflink['enabled'] = trim($this->GetEnabled());
- if (empty($cflink['enabled']))
+ if (empty($cflink['enabled'])) {
unset($cflink['enabled']);
+ }
$cflink['default'] = trim($this->GetDefault());
- if (empty($cflink['default']))
+ if (empty($cflink['default'])) {
unset($cflink['default']);
+ }
$cflink['red'] = trim($this->GetRed());
- if (empty($cflink['red']))
+ if (empty($cflink['red'])) {
unset($cflink['red']);
+ }
$cflink['rio'] = trim($this->GetRio());
- if (empty($cflink['rio']))
+ if (empty($cflink['rio'])) {
unset($cflink['rio']);
+ }
$cflink['ecn'] = trim($this->GetEcn());
- if (empty($cflink['ecn']))
+ if (empty($cflink['ecn'])) {
unset($cflink['ecn']);
+ }
$cflink['codel'] = trim($this->GetCodel());
- if (empty($cflink['codel']))
+ if (empty($cflink['codel'])) {
unset($cflink['codel']);
+ }
$cflink['borrow'] = trim($this->GetBorrow());
- if (empty($cflink['borrow']))
+ if (empty($cflink['borrow'])) {
unset($cflink['borrow']);
+ }
}
}
@@ -2522,8 +2782,9 @@ class fairq_queue extends priq_queue {
* Should search even its children
*/
function &find_queue($interface, $qname) {
- if ($qname == $this->GetQname())
+ if ($qname == $this->GetQname()) {
return $this;
+ }
}
function find_parentqueue($interface, $qname) { return; }
@@ -2537,8 +2798,9 @@ class fairq_queue extends priq_queue {
function validate_input($data, &$input_errors) {
parent::validate_input($data, $input_errors);
- if ($data['priority'] > 255)
+ if ($data['priority'] > 255) {
$input_errors[] = gettext("Priority must be an integer between 1 and 255.");
+ }
$reqdfields[] = "bandwidth";
$reqdfieldsn[] = gettext("Bandwidth");
$reqdfields[] = "bandwidthtype";
@@ -2546,17 +2808,20 @@ class fairq_queue extends priq_queue {
shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
- if ($data['bandwidth'] && !is_numeric($data['bandwidth']))
+ if ($data['bandwidth'] && !is_numeric($data['bandwidth'])) {
$input_errors[] = gettext("Bandwidth must be an integer.");
+ }
- if ($data['bandwidth'] < 0)
+ if ($data['bandwidth'] < 0) {
$input_errors[] = gettext("Bandwidth cannot be negative.");
+ }
if ($data['bandwidthtype'] == "%") {
- if ($data['bandwidth'] > 100 || $data['bandwidth'] < 0)
+ if ($data['bandwidth'] > 100 || $data['bandwidth'] < 0) {
$input_errors[] = gettext("Bandwidth in percentage should be between 1 and 100 bounds.");
+ }
}
/*
@@ -2568,21 +2833,24 @@ class fairq_queue extends priq_queue {
$mybw = floatval($data['bandwidth']) * get_bandwidthtype_scale($data['bandwidthtype']);
break;
}
- if ($parent->GetAvailableBandwidth() < floatval($myBw))
+ if ($parent->GetAvailableBandwidth() < floatval($myBw)) {
$input_errors[] = "The sum of children bandwidth exceeds that of the parent.";
+ }
*/
}
function ReadConfig(&$q) {
parent::ReadConfig($q);
- if (!empty($q['buckets']))
+ if (!empty($q['buckets'])) {
$this->SetBuckets($q['buckets']);
- else
+ } else {
$this->SetBuckets("");
- if (!empty($q['hogs']) && is_valid_shaperbw($q['hogs']))
+ }
+ if (!empty($q['hogs']) && is_valid_shaperbw($q['hogs'])) {
$this->SetHogs($q['hogs']);
- else
+ } else {
$this->SetHogs("");
+ }
}
function build_javascript() {
@@ -2594,8 +2862,9 @@ class fairq_queue extends priq_queue {
$this->GetInterface()."&amp;queue=" . $this->GetQname()."&amp;action=show";
$tree .= "\" ";
$tmpvalue = trim($this->GetDefault());
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$tree .= " class=\"navlnk\"";
+ }
$tree .= " >" . $this->GetQname() . "</a>";
$tree .= "</li>";
return $tree;
@@ -2604,18 +2873,22 @@ class fairq_queue extends priq_queue {
/* Even this should take children into consideration */
function build_rules(&$default = false) {
$pfq_rule = "queue ". $this->qname;
- if ($this->GetInterface())
+ if ($this->GetInterface()) {
$pfq_rule .= " on ".get_real_interface($this->GetInterface());
- if ($this->GetBandwidth() && $this->GetBwscale())
+ }
+ if ($this->GetBandwidth() && $this->GetBwscale()) {
$pfq_rule .= " bandwidth ".trim($this->GetBandwidth()).$this->GetBwscale();
+ }
$tmpvalue = trim($this->GetQpriority());
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$pfq_rule .= " priority " . $this->GetQpriority();
+ }
$tmpvalue = trim($this->GetQlimit());
- if (!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$pfq_rule .= " qlimit " . $this->GetQlimit();
- if ($this->GetDefault() || $this->GetRed() || $this->GetRio()
- || $this->GetEcn() || $this->GetBuckets() || $this->GetHogs() || $this->GetCodel()) {
+ }
+ if ($this->GetDefault() || $this->GetRed() || $this->GetRio() ||
+ $this->GetEcn() || $this->GetBuckets() || $this->GetHogs() || $this->GetCodel()) {
$pfq_rule .= " fairq ( ";
$tmpvalue = trim($this->GetRed());
if (!empty($tmpvalue)) {
@@ -2629,39 +2902,44 @@ class fairq_queue extends priq_queue {
}
$tmpvalue = trim($this->GetRio());
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " rio ";
}
$tmpvalue = trim($this->GetEcn());
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " ecn ";
}
$tmpvalue = trim($this->GetDefault());
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= " ,";
+ }
$comma = 1;
$pfq_rule .= " default ";
$default = true;
}
$tmpvalue = trim($this->GetBuckets());
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= ", ";
+ }
$pfq_rule .= " buckets " . $this->GetBuckets() . " ";
}
$tmpvalue = trim($this->GetHogs());
if (!empty($tmpvalue)) {
- if ($comma)
+ if ($comma) {
$pfq_rule .= ", ";
+ }
$pfq_rule .= " hogs " . $this->GetHogs() . " ";
}
- $pfq_rule .= " ) ";
+ $pfq_rule .= " ) ";
}
$pfq_rule .= " \n";
@@ -2673,29 +2951,35 @@ class fairq_queue extends priq_queue {
$form .= "<tr>";
$form .= "<td valign=\"middle\" class=\"vncellreq\">" . gettext("Bandwidth") . "</td>";
$form .= "<td class=\"vtable\"> <input name=\"bandwidth\" id=\"bandwidth\" class=\"formfld unknown\" value=\"";
- if ($this->GetBandwidth() > 0)
+ if ($this->GetBandwidth() > 0) {
$form .= htmlspecialchars($this->GetBandwidth());
+ }
$form .= "\" />";
$form .= "<select name=\"bandwidthtype\" id=\"bandwidthtype\" class=\"formselect\">";
$form .= "<option value=\"Gb\"";
- if ($this->GetBwscale() == "Gb")
+ if ($this->GetBwscale() == "Gb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Gbit/s") . "</option>";
$form .= "<option value=\"Mb\"";
- if ($this->GetBwscale() == "Mb")
+ if ($this->GetBwscale() == "Mb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Mbit/s") . "</option>";
$form .= "<option value=\"Kb\"";
- if ($this->GetBwscale() == "Kb")
+ if ($this->GetBwscale() == "Kb") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Kbit/s") . "</option>";
$form .= "<option value=\"b\"";
- if ($this->GetBwscale() == "b")
+ if ($this->GetBwscale() == "b") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Bit/s") . "</option>";
$form .= "<option value=\"%\"";
- if ($this->GetBwscale() == "%")
+ if ($this->GetBwscale() == "%") {
$form .= " selected=\"selected\"";
+ }
$form .= ">%</option>";
$form .= "</select> <br />";
$form .= "<span class=\"vexpl\">" . gettext("Choose the amount of bandwidth for this queue");
@@ -2704,13 +2988,15 @@ class fairq_queue extends priq_queue {
$form .= "<td class=\"vtable\"><table><tr><td>";
$form .= "<input id=\"buckets\" name=\"buckets\" value=\"";
$tmpvalue = trim($this->GetBuckets());
- if(!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$form .= $this->GetBuckets();
+ }
$form .= "\" /> " . gettext("Number of buckets available.") . "<br /></td></tr>";
$form .= "<tr><td class=\"vtable\"><input id=\"hogs\" name=\"hogs\" value=\"";
$tmpvalue = trim($this->GetHogs());
- if(!empty($tmpvalue))
+ if (!empty($tmpvalue)) {
$form .= $this->GetHogs();
+ }
$form .= "\" /> " . gettext("Bandwidth limit for hosts to not saturate link.") . "<br /></td></tr>";
$form .= "</table></td></tr>";
return $form;
@@ -2722,45 +3008,57 @@ class fairq_queue extends priq_queue {
function wconfig() {
$cflink =& get_reference_to_me_in_config($this->GetLink());
- if (!is_array($cflink))
+ if (!is_array($cflink)) {
$cflink = array();
+ }
$cflink['interface'] = $this->GetInterface();
$cflink['qlimit'] = trim($this->GetQlimit());
- if (empty($cflink['qlimit']))
+ if (empty($cflink['qlimit'])) {
unset($cflink['qlimit']);
+ }
$cflink['priority'] = trim($this->GetQpriority());
- if (empty($cflink['priority']))
+ if (empty($cflink['priority'])) {
unset($cflink['priority']);
+ }
$cflink['name'] = $this->GetQname();
$cflink['description'] = trim($this->GetDescription());
- if (empty($cflink['description']))
+ if (empty($cflink['description'])) {
unset($cflink['description']);
+ }
$cflink['bandwidth'] = $this->GetBandwidth();
$cflink['bandwidthtype'] = $this->GetBwscale();
$cflink['enabled'] = $this->GetEnabled();
- if (empty($cflink['enabled']))
+ if (empty($cflink['enabled'])) {
unset($cflink['enabled']);
+ }
$cflink['default'] = trim($this->GetDefault());
- if (empty($cflink['default']))
+ if (empty($cflink['default'])) {
unset($cflink['default']);
+ }
$cflink['red'] = trim($this->GetRed());
- if (empty($cflink['red']))
+ if (empty($cflink['red'])) {
unset($cflink['red']);
+ }
$cflink['rio'] = trim($this->GetRio());
- if (empty($cflink['rio']))
+ if (empty($cflink['rio'])) {
unset($cflink['rio']);
+ }
$cflink['ecn'] = trim($this->GetEcn());
- if (empty($cflink['ecn']))
+ if (empty($cflink['ecn'])) {
unset($cflink['ecn']);
+ }
$cflink['codel'] = trim($this->GetCodel());
- if (empty($cflink['codel']))
+ if (empty($cflink['codel'])) {
unset($cflink['codel']);
+ }
$cflink['buckets'] = trim($this->GetBuckets());
- if (empty($cflink['buckets']))
+ if (empty($cflink['buckets'])) {
unset($cflink['buckets']);
+ }
$cflink['hogs'] = trim($this->GetHogs());
- if (empty($cflink['hogs']))
+ if (empty($cflink['hogs'])) {
unset($cflink['hogs']);
+ }
}
}
@@ -2798,8 +3096,9 @@ class dummynet_class {
return $this->link;
}
function GetMask() {
- if (!isset($this->mask["type"]))
+ if (!isset($this->mask["type"])) {
$this->mask["type"] = "none";
+ }
return $this->mask;
}
function SetMask($mask) {
@@ -2898,53 +3197,67 @@ class dummynet_class {
shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
if ($data['plr'] && (!is_numeric($data['plr']) ||
- ($data['plr'] < 0) || ($data['plr'] > 1)))
+ ($data['plr'] < 0) || ($data['plr'] > 1))) {
$input_errors[] = gettext("Plr must be a value between 0 and 1.");
+ }
if ($data['buckets'] && (!is_numeric($data['buckets']) ||
- ($data['buckets'] < 16) || ($data['buckets'] > 65535)))
+ ($data['buckets'] < 16) || ($data['buckets'] > 65535))) {
$input_errors[] = gettext("Buckets must be an integer between 16 and 65535.");
- if ($data['qlimit'] && (!is_numeric($data['qlimit'])))
+ }
+ 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']))
+ }
+ if (!empty($data['newname']) && !preg_match("/^[a-zA-Z0-9_-]+$/", $data['newname'])) {
$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only.");
- if (!empty($data['name']) && !preg_match("/^[a-zA-Z0-9_-]+$/", $data['name']))
+ }
+ if (!empty($data['name']) && !preg_match("/^[a-zA-Z0-9_-]+$/", $data['name'])) {
$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only.");
- if (isset($data['maskbits']) && ($data['maskbits'] <> ""))
- if ((!is_numeric($data['maskbits'])) || ($data['maskbits'] <= 0) || ($data['maskbits'] > 32))
+ }
+ if (isset($data['maskbits']) && ($data['maskbits'] <> "")) {
+ if ((!is_numeric($data['maskbits'])) || ($data['maskbits'] <= 0) || ($data['maskbits'] > 32)) {
$input_errors[] = gettext("IPV4 bit mask must be blank or numeric value between 1 and 32.");
- if (isset($data['maskbitsv6']) && ($data['maskbitsv6'] <> ""))
- if ((!is_numeric($data['maskbitsv6'])) || ($data['maskbitsv6'] <= 0) || ($data['maskbitsv6'] > 128))
+ }
+ }
+ 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.");
+ }
+ }
}
function build_mask_rules(&$pfq_rule) {
$mask = $this->GetMask();
if (!empty($mask['type'])) {
- if ($mask['type'] <> 'none')
+ if ($mask['type'] <> 'none') {
$pfq_rule .= " mask";
+ }
switch ($mask['type']) {
- case 'srcaddress':
- if (!empty($mask['bitsv6']) && ($mask['bitsv6'] <> ""))
- $pfq_rule .= " src-ip6 /" . $mask['bitsv6'];
- else
- $pfq_rule .= " src-ip6 /128";
- if (!empty($mask['bits']) && ($mask['bits'] <> ""))
- $pfq_rule .= sprintf(" src-ip 0x%x", gen_subnet_mask_long($mask['bits']));
- else
- $pfq_rule .= " src-ip 0xffffffff";
- break;
- case 'dstaddress':
- if (!empty($mask['bitsv6']) && ($mask['bitsv6'] <> ""))
- $pfq_rule .= " dst-ip6 /" . $mask['bitsv6'];
- else
- $pfq_rule .= " dst-ip6 /128";
- if (!empty($mask['bits']) && ($mask['bits'] <> ""))
- $pfq_rule .= sprintf(" dst-ip 0x%x", gen_subnet_mask_long($mask['bits']));
- else
- $pfq_rule .= " dst-ip 0xffffffff";
- break;
- default:
- break;
+ case 'srcaddress':
+ if (!empty($mask['bitsv6']) && ($mask['bitsv6'] <> "")) {
+ $pfq_rule .= " src-ip6 /" . $mask['bitsv6'];
+ } else {
+ $pfq_rule .= " src-ip6 /128";
+ }
+ if (!empty($mask['bits']) && ($mask['bits'] <> "")) {
+ $pfq_rule .= sprintf(" src-ip 0x%x", gen_subnet_mask_long($mask['bits']));
+ } else {
+ $pfq_rule .= " src-ip 0xffffffff";
+ }
+ break;
+ case 'dstaddress':
+ if (!empty($mask['bitsv6']) && ($mask['bitsv6'] <> "")) {
+ $pfq_rule .= " dst-ip6 /" . $mask['bitsv6'];
+ } else {
+ $pfq_rule .= " dst-ip6 /128";
+ }
+ if (!empty($mask['bits']) && ($mask['bits'] <> "")) {
+ $pfq_rule .= sprintf(" dst-ip 0x%x", gen_subnet_mask_long($mask['bits']));
+ } else {
+ $pfq_rule .= " dst-ip 0xffffffff";
+ }
+ break;
+ default:
+ break;
}
}
}
@@ -2970,8 +3283,9 @@ class dnpipe_class extends dummynet_class {
}
function delete_queue() {
cleanup_dnqueue_from_rules($this->GetQname());
- foreach ($this->subqueues as $q)
+ foreach ($this->subqueues as $q) {
$q->delete_queue();
+ }
unset_dn_object_by_reference($this->GetLink());
@pfSense_pipe_action("pipe delete " . $this->GetNumber());
}
@@ -2981,17 +3295,18 @@ class dnpipe_class extends dummynet_class {
function SetBandwidth($bandwidth) {
$this->qbandwidth = $bandwidth;
}
- function GetBurst() {
- return $this->qburst;
- }
- function SetBurst($burst) {
- $this->qburst = $burst;
- }
+ function GetBurst() {
+ return $this->qburst;
+ }
+ function SetBurst($burst) {
+ $this->qburst = $burst;
+ }
function &add_queue($interface, &$queue, &$path, &$input_errors) {
- if (!is_array($this->subqueues))
+ if (!is_array($this->subqueues)) {
$this->subqueues = array();
+ }
$q =& new dnqueue_class();
$q->SetLink($path);
@@ -3016,8 +3331,9 @@ class dnpipe_class extends dummynet_class {
$qlist[$this->GetQname()] = $this->GetNumber();
if (is_array($this->subqueues)) {
- foreach ($this->subqueues as $queue)
+ foreach ($this->subqueues as $queue) {
$queue->get_queue_list($qlist);
+ }
}
return $qlist;
}
@@ -3026,12 +3342,14 @@ class dnpipe_class extends dummynet_class {
* Should search even its children
*/
function &find_queue($pipe, $qname) {
- if ($qname == $this->GetQname())
+ if ($qname == $this->GetQname()) {
return $this;
+ }
foreach ($this->subqueues as $q) {
$result =& $q->find_queue("", $qname);
- if ($result)
+ if ($result) {
return $result;
+ }
}
}
@@ -3048,28 +3366,34 @@ class dnpipe_class extends dummynet_class {
/* XXX: Really no better way? */
for ($i = 0; $i < 2900; $i++) {
if (!empty($data["bwsched{$i}"])) {
- if ($data["bwsched{$i}"] != "none")
+ if ($data["bwsched{$i}"] != "none") {
$schedule++;
- else
+ } else {
$schedulenone++;
+ }
}
if (!empty($data["bandwidth{$i}"])) {
- if (!is_numeric($data["bandwidth{$i}"]))
+ if (!is_numeric($data["bandwidth{$i}"])) {
$input_errors[] = sprintf(gettext("Bandwidth for schedule %s must be an integer."), $data["bwsched{$i}"]);
- else if (($data["burst{$i}"] != "") && (!is_numeric($data["burst{$i}"])))
+ } 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}"]);
- else
+ } else {
$entries++;
+ }
}
}
- if ($schedule == 0 && $entries > 1)
+ if ($schedule == 0 && $entries > 1) {
$input_errors[] = gettext("You need to specify a schedule for every additional entry");
- if ($schedulenone > 0 && $entries > 1)
+ }
+ if ($schedulenone > 0 && $entries > 1) {
$input_errors[] = gettext("If more than one bandwidth configured all schedules need to be selected");
- if ($entries == 0)
+ }
+ if ($entries == 0) {
$input_errors[] = gettext("At least one bw specification is necessary");
- if ($data['delay'] && (!is_numeric($data['delay'])))
+ }
+ if ($data['delay'] && (!is_numeric($data['delay']))) {
$input_errors[] = gettext("Delay must be an integer.");
+ }
}
function ReadConfig(&$q) {
@@ -3090,10 +3414,12 @@ class dnpipe_class extends dummynet_class {
$bw = array();
$bw['bw'] = $q["bandwidth{$i}"];
$bw['burst'] = $q["burst{$i}"];
- if (isset($q["bwtype{$i}"]) && $q["bwtype{$i}"])
+ if (isset($q["bwtype{$i}"]) && $q["bwtype{$i}"]) {
$bw['bwscale'] = $q["bwtype{$i}"];
- if (isset($q["bwsched{$i}"]) && $q["bwsched{$i}"])
+ }
+ if (isset($q["bwsched{$i}"]) && $q["bwsched{$i}"]) {
$bw['bwsched'] = $q["bwsched{$i}"];
+ }
$bandwidth[] = $bw;
}
}
@@ -3105,39 +3431,47 @@ class dnpipe_class extends dummynet_class {
$this->SetBurst($q['burst']['item']);
}
- if (isset($q['qlimit']) && $q['qlimit'] <> "")
+ if (isset($q['qlimit']) && $q['qlimit'] <> "") {
$this->SetQlimit($q['qlimit']);
- else
+ } else {
$this->SetQlimit("");
- if (isset($q['mask']) && $q['mask'] <> "")
+ }
+ if (isset($q['mask']) && $q['mask'] <> "") {
$masktype = $q['mask'];
- else
+ } else {
$masktype = "";
- if (isset($q['maskbits']) && $q['maskbits'] <> "")
+ }
+ if (isset($q['maskbits']) && $q['maskbits'] <> "") {
$maskbits = $q['maskbits'];
- else
+ } else {
$maskbits = "";
- if (isset($q['maskbitsv6']) && $q['maskbitsv6'] <> "")
+ }
+ if (isset($q['maskbitsv6']) && $q['maskbitsv6'] <> "") {
$maskbitsv6 = $q['maskbitsv6'];
- else
+ } else {
$maskbitsv6 = "";
+ }
$this->SetMask(array("type" => $masktype, "bits" => $maskbits, "bitsv6" => $maskbitsv6));
- if (isset($q['buckets']) && $q['buckets'] <> "")
+ if (isset($q['buckets']) && $q['buckets'] <> "") {
$this->SetBuckets($q['buckets']);
- else
+ } else {
$this->SetBuckets("");
- if (isset($q['plr']) && $q['plr'] <> "")
+ }
+ if (isset($q['plr']) && $q['plr'] <> "") {
$this->SetPlr($q['plr']);
- else
+ } else {
$this->SetPlr("");
- if (isset($q['delay']) && $q['delay'] <> "")
+ }
+ if (isset($q['delay']) && $q['delay'] <> "") {
$this->SetDelay($q['delay']);
- else
+ } else {
$this->SetDelay(0);
- if (isset($q['description']) && $q['description'] <> "")
+ }
+ if (isset($q['description']) && $q['description'] <> "") {
$this->SetDescription($q['description']);
- else
+ } else {
$this->SetDescription("");
+ }
$this->SetEnabled($q['enabled']);
}
@@ -3160,8 +3494,9 @@ class dnpipe_class extends dummynet_class {
function build_rules() {
global $config, $time_based_rules;
- if ($this->GetEnabled() == "")
+ if ($this->GetEnabled() == "") {
return;
+ }
$pfq_rule = "\npipe ". $this->GetNumber() . " config ";
$found = false;
@@ -3175,8 +3510,9 @@ class dnpipe_class extends dummynet_class {
if ($bw['bwsched'] == $schedule['name']) {
if (filter_get_time_based_rule_status($schedule)) {
$pfq_rule .= " bw ".trim($bw['bw']).$bw['bwscale'];
- if (is_numeric($bw['burst']) && ($bw['burst'] > 0))
+ if (is_numeric($bw['burst']) && ($bw['burst'] > 0)) {
$pfq_rule .= " burst ".trim($bw['burst']);
+ }
$found = true;
break;
}
@@ -3189,32 +3525,40 @@ class dnpipe_class extends dummynet_class {
}
} else {
$pfq_rule .= " bw ".trim($bw['bw']).$bw['bwscale'];
- if (is_numeric($bw['burst']) && ($bw['burst'] > 0))
+ if (is_numeric($bw['burst']) && ($bw['burst'] > 0)) {
$pfq_rule .= " burst ".trim($bw['burst']);
+ }
$found = true;
break;
}
}
- if ($found == false)
+ if ($found == false) {
$pfq_rule .= " bw 0";
- } else
+ }
+ } else {
$pfq_rule .= " bw 0";
+ }
- if ($this->GetQlimit())
+ if ($this->GetQlimit()) {
$pfq_rule .= " queue " . $this->GetQlimit();
- if ($this->GetPlr())
+ }
+ if ($this->GetPlr()) {
$pfq_rule .= " plr " . $this->GetPlr();
- if ($this->GetBuckets())
+ }
+ if ($this->GetBuckets()) {
$pfq_rule .= " buckets " . $this->GetBuckets();
- if ($this->GetDelay())
+ }
+ if ($this->GetDelay()) {
$pfq_rule .= " delay " . $this->GetDelay();
+ }
$this->build_mask_rules($pfq_rule);
$pfq_rule .= "\n";
if (!empty($this->subqueues) && count($this->subqueues) > 0) {
- foreach ($this->subqueues as $q)
- $pfq_rule .= $q->build_rules();
+ foreach ($this->subqueues as $q) {
+ $pfq_rule .= $q->build_rules();
+ }
}
$pfq_rule .= " \n";
@@ -3234,13 +3578,15 @@ class dnpipe_class extends dummynet_class {
$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'] <> "")
+ 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)
+ foreach (array("Kb" => "Kbit/s", "Mb" => "Mbit/s", "Gb" => "Gbit/s", "b" => "Bit/s") as $bwidx => $bw) {
$bwopt .= "<option value='{$bwidx}'>{$bw}</option>";
+ }
$javasr .= <<<EOD
<script type='text/javascript'>
@@ -3274,12 +3620,13 @@ var addBwRowTo = (function() {
function removeBwRow(el) {
var cel;
- while (el && el.nodeName.toLowerCase() != "tr")
+ while (el && el.nodeName.toLowerCase() != "tr") {
el = el.parentNode;
if (el && el.parentNode) {
cel = el.getElementsByTagName("td").item(0);
el.parentNode.removeChild(el);
}
+ }
}
//]]>
</script>
@@ -3297,8 +3644,9 @@ EOD;
$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'] <> "")
+ if ($schedule['name'] <> "") {
$schedules[] = $schedule['name'];
+ }
}
}
@@ -3306,8 +3654,9 @@ EOD;
$form .= gettext("Enable");
$form .= "</td><td class=\"vncellreq\">";
$form .= " <input type=\"checkbox\" id=\"enabled\" name=\"enabled\" value=\"on\"";
- if ($this->GetEnabled() == "on")
+ if ($this->GetEnabled() == "on") {
$form .= " checked=\"checked\"";
+ }
$form .= " /><span class=\"vexpl\"> " . gettext("Enable limiter and its children") . "</span>";
$form .= "</td></tr>";
$form .= "<tr><td valign=\"middle\" class=\"vncellreq\"><br /><span class=\"vexpl\">" . gettext("Name") . "</span></td>";
@@ -3342,8 +3691,9 @@ EOD;
$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)
+ if ($bw['bwscale'] == $bwsidx) {
$form .= " selected=\"selected\"";
+ }
$form .= ">{$bwscale}</option>";
}
$form .= "</select>";
@@ -3351,8 +3701,9 @@ EOD;
$form .= "<select id=\"bwsched{$bwidx}\" name=\"bwsched{$bwidx}\" class=\"formselect\">";
foreach ($schedules as $schd) {
$selected = "";
- if ($bw['bwsched'] == $schd)
+ if ($bw['bwsched'] == $schd) {
$selected = "selected=\"selected\"";
+ }
$form .= "<option value='{$schd}' {$selected}>{$schd}</option>";
}
$form .= "</select>";
@@ -3372,44 +3723,51 @@ EOD;
$form .= "<select name=\"mask\" id=\"mask\" class=\"formselect\" onchange=\"enable_maskbits();\" >";
$form .= "<option value=\"none\"";
$mask = $this->GetMask();
- if ($mask['type'] == "none")
+ if ($mask['type'] == "none") {
$form .= " selected=\"selected\"";
+ }
$form .= ">none</option>";
$form .= "<option value=\"srcaddress\"";
- if ($mask['type'] == "srcaddress")
+ if ($mask['type'] == "srcaddress") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Source addresses") . "</option>";
$form .= "<option value=\"dstaddress\"";
- if ($mask['type'] == "dstaddress")
+ if ($mask['type'] == "dstaddress") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Destination addresses") . "</option>";
$form .= "</select>";
$form .= "&nbsp;<br />";
$form .= "<span class=\"vexpl\">" . gettext("If 'source' or 'destination' slots is chosen, \n"
- . "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"
- . "limits per host.") . "</span><br />";
+ . "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"
+ . "limits per host.") . "</span><br />";
$form .= "255.255.255.255/&nbsp;<input type=\"text\" class=\"formfld unknown\" size=\"2\" id=\"maskbits\" name=\"maskbits\" value=\"";
- if ($mask['type'] <> "none")
- $form .= $mask['bits'];
+ if ($mask['type'] <> "none") {
+ $form .= $mask['bits'];
+ }
$form .= "\"";
- if ($mask['type'] == "none")
+ if ($mask['type'] == "none") {
$form .= " disabled";
+ }
$form .= " />";
$form .= "&nbsp; IPV4 mask bits (1-32)<br />";
$form .= "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/&nbsp;<input type=\"text\" class=\"formfld unknown\" size=\"2\" id=\"maskbitsv6\" name=\"maskbitsv6\" value=\"";
- if ($mask['type'] <> "none")
- $form .= $mask['bitsv6'];
+ if ($mask['type'] <> "none") {
+ $form .= $mask['bitsv6'];
+ }
$form .= "\"";
- if ($mask['type'] == "none")
+ if ($mask['type'] == "none") {
$form .= " disabled";
+ }
$form .= " />";
$form .= "&nbsp; IPV6 mask bits (1-128)<br />";
$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>";
+ . "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>";
$form .= "</td></tr>";
$form .= "<tr><td valign=\"middle\" class=\"vncellreq\">" . gettext("Description") . "</td>";
$form .= "<td class=\"vncellreq\">";
@@ -3432,7 +3790,7 @@ EOD;
$form .= "<input name=\"delay\" type=\"text\" id=\"delay\" size=\"5\" value=\"";
$form .= $this->GetDelay() . "\" />";
$form .= "&nbsp;ms<br /> <span class=\"vexpl\">" . gettext("Hint: in most cases, you "
- . "should specify 0 here (or leave the field empty)") . "</span><br />";
+ . "should specify 0 here (or leave the field empty)") . "</span><br />";
$form .= "</td></tr>";
$form .= "<tr style=\"display:none\" id=\"sprtable1\">";
$form .= "<td valign=\"middle\" class=\"vncellreq\">" . gettext("Packet loss rate") . "</td>";
@@ -3440,8 +3798,8 @@ EOD;
$form .= "<input name=\"plr\" type=\"text\" id=\"plr\" size=\"5\" value=\"";
$form .= $this->GetPlr() . "\" />";
$form .= "&nbsp;<br /> <span class=\"vexpl\">" . gettext("Hint: in most cases, you "
- . "should specify 0 here (or leave the field empty). "
- . "A value of 0.001 means one packet in 1000 gets dropped") . "</span>";
+ . "should specify 0 here (or leave the field empty). "
+ . "A value of 0.001 means one packet in 1000 gets dropped") . "</span>";
$form .= "</td></tr>";
$form .= "<tr style=\"display:none\" id=\"sprtable2\">";
$form .= "<td valign=\"middle\" class=\"vncellreq\">" . gettext("Queue Size") . "</td>";
@@ -3450,9 +3808,9 @@ EOD;
$form .= $this->GetQlimit() . "\" />";
$form .= "&nbsp;slots<br />";
$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, "
- . "then they are delayed by value specified in the Delay field, and then they "
- . "are delivered to their destination.") . "</span>";
+ . "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>";
$form .= "</td></tr>";
$form .= "<tr style=\"display:none\" id=\"sprtable5\">";
$form .= "<td valign=\"middle\" class=\"vncellreq\">" . gettext("Bucket Size") . "</td>";
@@ -3470,8 +3828,9 @@ EOD;
function wconfig() {
$cflink =& get_dn_reference_to_me_in_config($this->GetLink());
- if (!is_array($cflink))
+ if (!is_array($cflink)) {
$cflink = array();
+ }
$cflink['name'] = $this->GetQname();
$cflink['number'] = $this->GetNumber();
$cflink['qlimit'] = $this->GetQlimit();
@@ -3482,8 +3841,9 @@ EOD;
if (is_array($bandwidth)) {
$cflink['bandwidth'] = array();
$cflink['bandwidth']['item'] = array();
- foreach ($bandwidth as $bwidx => $bw)
+ foreach ($bandwidth as $bwidx => $bw) {
$cflink['bandwidth']['item'][] = $bw;
+ }
}
$cflink['enabled'] = $this->GetEnabled();
@@ -3515,7 +3875,9 @@ class dnqueue_class extends dummynet_class {
}
/* Just a stub in case we ever try to call this from the frontend. */
- function &add_queue($interface, &$queue, &$path, &$input_errors) { return; }
+ function &add_queue($interface, &$queue, &$path, &$input_errors) {
+ return;
+ }
function delete_queue() {
cleanup_dnqueue_from_rules($this->GetQname());
@@ -3527,18 +3889,20 @@ class dnqueue_class extends dummynet_class {
parent::validate_input($data, $input_errors);
if ($data['weight'] && ((!is_numeric($data['weight'])) ||
- ($data['weight'] < 1 && $data['weight'] > 100)))
+ ($data['weight'] < 1 && $data['weight'] > 100))) {
$input_errors[] = gettext("Weight must be an integer between 1 and 100.");
+ }
}
/*
* Should search even its children
*/
function &find_queue($pipe, $qname) {
- if ($qname == $this->GetQname())
+ if ($qname == $this->GetQname()) {
return $this;
- else
+ } else {
return NULL;
+ }
}
function &find_parentqueue($pipe, $qname) {
@@ -3546,8 +3910,9 @@ class dnqueue_class extends dummynet_class {
}
function &get_queue_list(&$qlist) {
- if ($this->GetEnabled() == "")
+ if ($this->GetEnabled() == "") {
return;
+ }
$qlist[$this->GetQname()] = "?" .$this->GetNumber();
}
@@ -3560,39 +3925,47 @@ class dnqueue_class extends dummynet_class {
$this->SetQname($q['name']);
}
$this->SetNumber($q['number']);
- if (isset($q['qlimit']) && $q['qlimit'] <> "")
+ if (isset($q['qlimit']) && $q['qlimit'] <> "") {
$this->SetQlimit($q['qlimit']);
- else
+ } else {
$this->SetQlimit("");
- if (isset($q['mask']) && $q['mask'] <> "")
+ }
+ if (isset($q['mask']) && $q['mask'] <> "") {
$masktype = $q['mask'];
- else
+ } else {
$masktype = "";
- if (isset($q['maskbits']) && $q['maskbits'] <> "")
+ }
+ if (isset($q['maskbits']) && $q['maskbits'] <> "") {
$maskbits = $q['maskbits'];
- else
+ } else {
$maskbits = "";
- if (isset($q['maskbitsv6']) && $q['maskbitsv6'] <> "")
+ }
+ if (isset($q['maskbitsv6']) && $q['maskbitsv6'] <> "") {
$maskbitsv6 = $q['maskbitsv6'];
- else
+ } else {
$maskbitsv6 = "";
+ }
$this->SetMask(array("type" => $masktype, "bits" => $maskbits, "bitsv6" => $maskbitsv6));
- if (isset($q['buckets']) && $q['buckets'] <> "")
+ if (isset($q['buckets']) && $q['buckets'] <> "") {
$this->SetBuckets($q['buckets']);
- else
+ } else {
$this->SetBuckets("");
- if (isset($q['plr']) && $q['plr'] <> "")
+ }
+ if (isset($q['plr']) && $q['plr'] <> "") {
$this->SetPlr($q['plr']);
- else
+ } else {
$this->SetPlr("");
- if (isset($q['weight']) && $q['weight'] <> "")
+ }
+ if (isset($q['weight']) && $q['weight'] <> "") {
$this->SetWeight($q['weight']);
- else
+ } else {
$this->SetWeight("");
- if (isset($q['description']) && $q['description'] <> "")
+ }
+ if (isset($q['description']) && $q['description'] <> "") {
$this->SetDescription($q['description']);
- else
+ } else {
$this->SetDescription("");
+ }
$this->SetEnabled($q['enabled']);
}
@@ -3606,17 +3979,21 @@ class dnqueue_class extends dummynet_class {
}
function build_rules() {
- if ($this->GetEnabled() == "")
+ if ($this->GetEnabled() == "") {
return;
+ }
$parent =& $this->GetParent();
$pfq_rule = "queue ". $this->GetNumber() . " config pipe " . $parent->GetNumber();
- if ($this->GetQlimit())
+ if ($this->GetQlimit()) {
$pfq_rule .= " queue " . $this->GetQlimit();
- if ($this->GetWeight())
+ }
+ if ($this->GetWeight()) {
$pfq_rule .= " weight " . $this->GetWeight();
- if ($this->GetBuckets())
+ }
+ if ($this->GetBuckets()) {
$pfq_rule .= " buckets " . $this->GetBuckets();
+ }
$this->build_mask_rules($pfq_rule);
$pfq_rule .= "\n";
@@ -3633,8 +4010,9 @@ class dnqueue_class extends dummynet_class {
$form .= gettext("Enable/Disable");
$form .= "</td><td class=\"vncellreq\">";
$form .= " <input type=\"checkbox\" id=\"enabled\" name=\"enabled\" value=\"on\"";
- if ($this->GetEnabled() == "on")
+ if ($this->GetEnabled() == "on") {
$form .= " checked=\"checked\"";
+ }
$form .= " /><span class=\"vexpl\"> " . gettext("Enable/Disable queue") . "</span>";
$form .= "</td></tr>";
$form .= "<tr><td valign=\"middle\" class=\"vncellreq\"><br /><span class=\"vexpl\">" . gettext("Name") . "</span></td>";
@@ -3653,16 +4031,19 @@ class dnqueue_class extends dummynet_class {
$form .= "<select name=\"mask\" id=\"mask\" class=\"formselect\" onchange=\"enable_maskbits();\" >";
$form .= "<option value=\"none\"";
$mask = $this->GetMask();
- if ($mask['type'] == "none")
+ if ($mask['type'] == "none") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("none") . "</option>";
$form .= "<option value=\"srcaddress\"";
- if ($mask['type'] == "srcaddress")
+ if ($mask['type'] == "srcaddress") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Source addresses") . "</option>";
$form .= "<option value=\"dstaddress\"";
- if ($mask['type'] == "dstaddress")
+ if ($mask['type'] == "dstaddress") {
$form .= " selected=\"selected\"";
+ }
$form .= ">" . gettext("Destination addresses") . "</option>";
$form .= "</select>";
$form .= "&nbsp;slots<br />";
@@ -3672,19 +4053,23 @@ class dnqueue_class extends dummynet_class {
. "respectively. This makes it possible to easily specify bandwidth \n"
. "limits per host.") . "</span><br />";
$form .= "255.255.255.255/&nbsp;<input type=\"text\" class=\"formfld unknown\" size=\"2\" id=\"maskbits\" name=\"maskbits\" value=\"";
- if ($mask['type'] <> "none")
+ if ($mask['type'] <> "none") {
$form .= $mask['bits'];
+ }
$form .= "\"";
- if ($mask['type'] == "none")
+ if ($mask['type'] == "none") {
$form .= " disabled";
+ }
$form .= " />";
$form .= "&nbsp; IPV4 mask bits (1-32)<br />";
$form .= "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/&nbsp;<input type=\"text\" class=\"formfld unknown\" size=\"2\" id=\"maskbitsv6\" name=\"maskbitsv6\" value=\"";
- if ($mask['type'] <> "none")
+ if ($mask['type'] <> "none") {
$form .= $mask['bitsv6'];
+ }
$form .= "\"";
- if ($mask['type'] == "none")
+ if ($mask['type'] == "none") {
$form .= " disabled";
+ }
$form .= " />";
$form .= "&nbsp; IPV6 mask bits (1-128)<br />";
$form .= "<span class=\"vexpl\">" . gettext("If 'source' or 'destination' slots is chosen, \n"
@@ -3757,8 +4142,9 @@ class dnqueue_class extends dummynet_class {
function wconfig() {
$cflink =& get_dn_reference_to_me_in_config($this->GetLink());
- if (!is_array($cflink))
+ if (!is_array($cflink)) {
$cflink = array();
+ }
$cflink['name'] = $this->GetQname();
$cflink['number'] = $this->GetNumber();
$cflink['qlimit'] = $this->GetQlimit();
@@ -3817,7 +4203,7 @@ class layer7 {
$this->rsets = $rsets;
}
- //Add a tuple (rule,sctructure,element) to the $rsets
+ //Add a tuple (rule,structure,element) to the $rsets
function add_rule($l7set) {
$this->rsets[] = $l7set;
@@ -3825,7 +4211,7 @@ class layer7 {
// Build the layer7 rules
function build_l7_rules() {
- if($this->GetREnabled() == "") {
+ if ($this->GetREnabled() == "") {
return;
}
//$l7rules = "#" . $this->rdescription . "\n";
@@ -3840,13 +4226,14 @@ class layer7 {
$this->SetRName($qname);
$this->SetREnabled($q['enabled']);
$this->SetRPort($q['divert_port']);
- if(isset($q['description']) && $q['description'] <> "")
+ if (isset($q['description']) && $q['description'] <> "") {
$this->SetRDescription($q['description']);
+ }
$rsets = $q['l7rules'];
//Put individual rules in the array
- if(is_array($rsets)) {
+ if (is_array($rsets)) {
$this->rsets = array(); // XXX: ugly hack
- foreach($rsets as $l7r) {
+ foreach ($rsets as $l7r) {
$l7obj = new l7rule();
$l7obj->SetRProtocol($l7r['protocol']);
$l7obj->SetRStructure($l7r['structure']);
@@ -3906,13 +4293,13 @@ class layer7 {
function wconfig() {
global $config;
- if(!is_array($config['l7shaper']['container'])) {
+ 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) {
+ // Test if this rule exists already
+ if (!$cflink) {
$cflink =& $config['l7shaper']['container'][];
}
$cflink['name'] = $this->GetRName();
@@ -3920,15 +4307,15 @@ class layer7 {
$cflink['description'] = $this->GetRDescription();
$cflink['divert_port'] = $this->GetRPort();
- //Destroy previously existent rules
- if(is_array($cflink['rules'])) {
+ // Destroy previously existent rules
+ if (is_array($cflink['rules'])) {
unset($cflink['l7rules']);
}
$cflink['l7rules'] = array();
$i = 0;
- foreach($this->rsets as $rulel7) {
+ foreach ($this->rsets as $rulel7) {
$cflink['l7rules'][$i]['protocol'] = $rulel7->GetRProtocol();
$cflink['l7rules'][$i]['structure'] = $rulel7->GetRStructure();
$cflink['l7rules'][$i]['behaviour'] = $rulel7->GetRBehaviour();
@@ -3940,18 +4327,21 @@ class layer7 {
function get_unique_structures() {
$unique_structures = array("action" => false, "dummynet" => false, "altq" => false);
- foreach($this->rsets as $l7rule) {
- if($l7rule->GetRStructure() == "action")
+ foreach ($this->rsets as $l7rule) {
+ if ($l7rule->GetRStructure() == "action") {
$unique_structures['action'] = true;
- else if($l7rule->GetRStructure() == "limiter")
+ } else if ($l7rule->GetRStructure() == "limiter") {
$unique_structures['dummynet'] = true;
- else
+ } 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)
+ foreach ($unique_structures as $key => $value) {
+ if (!$value) {
unset($unique_structures[$key]);
+ }
+ }
return $unique_structures;
}
@@ -3961,8 +4351,9 @@ class layer7 {
shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
- if (!preg_match("/^[a-zA-Z0-9_-]+$/", $data['container']))
+ if (!preg_match("/^[a-zA-Z0-9_-]+$/", $data['container'])) {
$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only.");
+ }
}
function delete_l7c() {
@@ -4007,17 +4398,19 @@ class l7rule {
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] == "?")
+ 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
+ } else {
$l7rule = $this->GetRProtocol() . " = dnpipe " . $value . "\n";
+ }
$found = true;
}
- if($found)
+ if ($found) {
break;
+ }
}
}
break;
@@ -4036,8 +4429,9 @@ function get_divert_ports() {
global $layer7_rules_list;
$dports = array();
- foreach($layer7_rules_list as $l7r)
+ foreach ($layer7_rules_list as $l7r) {
$dports[] = $l7r->GetRPort();
+ }
return $dports;
}
@@ -4047,10 +4441,11 @@ function &get_l7c_reference_to_me_in_config(&$name) {
$ptr = NULL;
- if(is_array($config['l7shaper']['container'])) {
- foreach($config['l7shaper']['container'] as $key => $value) {
- if($value['name'] == $name)
+ if (is_array($config['l7shaper']['container'])) {
+ foreach ($config['l7shaper']['container'] as $key => $value) {
+ if ($value['name'] == $name) {
$ptr =& $config['l7shaper']['container'][$key];
+ }
}
}
return $ptr;
@@ -4060,9 +4455,9 @@ function &get_l7c_reference_to_me_in_config(&$name) {
function unset_l7_object_by_reference(&$name) {
global $config;
- if(is_array($config['l7shaper']['container'])) {
- foreach($config['l7shaper']['container'] as $key => $value) {
- if($value['name'] == $name) {
+ 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;
@@ -4084,8 +4479,9 @@ function read_layer7_config() {
$layer7_rules_list = array();
foreach ($l7cs as $conf) {
- if (empty($conf['name']))
+ if (empty($conf['name'])) {
continue; /* XXX: grrrrrr at php */
+ }
$root =& new layer7();
$root->ReadConfig($conf['name'],$conf);
$layer7_rules_list[$root->GetRName()] = &$root;
@@ -4095,12 +4491,15 @@ function read_layer7_config() {
function update_layer7_custom_patterns() {
global $config;
- if (!is_array($config['l7shaper']['custom_pat']))
+ if (!is_array($config['l7shaper']['custom_pat'])) {
return;
+ }
- foreach ($config['l7shaper']['custom_pat'] as $filename => $filecontent)
- if (!file_exists("/usr/local/share/protocols/" . $filename))
+ 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));
+ }
+ }
}
function generate_layer7_files() {
@@ -4109,16 +4508,17 @@ function generate_layer7_files() {
read_layer7_config();
if (!empty($layer7_rules_list)) {
- if (!is_module_loaded("ipdivert.ko"))
+ if (!is_module_loaded("ipdivert.ko")) {
mwexec("/sbin/kldload ipdivert.ko");
+ }
array_map('unlink', glob("{$g['tmp_path']}/*.l7"));
}
update_layer7_custom_patterns();
- foreach($layer7_rules_list as $l7rules) {
- if($l7rules->GetREnabled()) {
+ foreach ($layer7_rules_list as $l7rules) {
+ if ($l7rules->GetREnabled()) {
$filename = $l7rules->GetRName() . ".l7";
$path = "{$g['tmp_path']}/" . $filename;
@@ -4139,8 +4539,8 @@ function layer7_start_l7daemon() {
* read_layer7_config();
*/
- foreach($layer7_rules_list as $l7rules) {
- if($l7rules->GetREnabled()) {
+ foreach ($layer7_rules_list as $l7rules) {
+ if ($l7rules->GetREnabled()) {
$filename = $l7rules->GetRName() . ".l7";
$path = "{$g['tmp_path']}/" . $filename;
@@ -4151,7 +4551,7 @@ function layer7_start_l7daemon() {
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..
+ // 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);
}
@@ -4166,10 +4566,11 @@ function generate_protocols_array() {
$protocols = return_dir_as_array("/usr/local/share/protocols");
$protocols_new = array();
- if(is_array($protocols)) {
- foreach($protocols as $key => $proto) {
- if (strstr($proto, ".pat"))
+ if (is_array($protocols)) {
+ foreach ($protocols as $key => $proto) {
+ if (strstr($proto, ".pat")) {
$protocols_new[$key] =& str_replace(".pat", "", $proto);
+ }
}
sort($protocols_new);
}
@@ -4180,10 +4581,13 @@ function get_l7_unique_list() {
global $layer7_rules_list;
$l7list = array();
- if(is_array($layer7_rules_list))
- foreach($layer7_rules_list as $l7c)
- if($l7c->GetREnabled())
+ if (is_array($layer7_rules_list)) {
+ foreach ($layer7_rules_list as $l7c) {
+ if ($l7c->GetREnabled()) {
$l7list[] = $l7c->GetRName();
+ }
+ }
+ }
return $l7list;
}
@@ -4192,20 +4596,24 @@ function get_l7_unique_list() {
function cleanup_l7_from_rules(&$name) {
global $config;
- if(is_array($config['filter']['rule']))
+ if (is_array($config['filter']['rule'])) {
foreach ($config['filter']['rule'] as $key => $rule) {
- if ($rule['l7container'] == $name)
+ if ($rule['l7container'] == $name) {
unset($config['filter']['rule'][$key]['l7container']);
+ }
}
+ }
}
function get_dummynet_name_list() {
$dn_name_list =& get_unique_dnqueue_list();
$dn_name = array();
- if(is_array($dn_name_list))
- foreach($dn_name_list as $key => $value)
+ if (is_array($dn_name_list)) {
+ foreach ($dn_name_list as $key => $value) {
$dn_name[] = $key;
+ }
+ }
return $dn_name;
@@ -4214,30 +4622,33 @@ function get_dummynet_name_list() {
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)
+ if (is_array($altq_name_list)) {
+ foreach ($altq_name_list as $key => $aqobj) {
$altq_name[] = $key;
+ }
+ }
return $altq_name;
}
/*
- * XXX: TODO Make a class shaper to hide all these function
+ * XXX: TODO Make a class shaper to hide all these functions
* from the global namespace.
*/
/*
* This is a layer violation but for now there is no way
- * i can find to properly do this with PHP.
+ * I can find to properly do this with PHP.
*/
function altq_get_default_queue($interface) {
global $altq_list_queues;
$altq_tmp = $altq_list_queues[$interface];
- if ($altq_tmp)
+ if ($altq_tmp) {
return $altq_tmp->GetDefaultQueuePresent();
- else
+ } else {
return false;
+ }
}
function altq_check_default_queues() {
@@ -4245,12 +4656,15 @@ function altq_check_default_queues() {
$count = 0;
if (is_array($altq_list_queues)) {
- foreach($altq_list_queues as $altq) {
- if ($altq->GetDefaultQueuePresent())
+ foreach ($altq_list_queues as $altq) {
+ if ($altq->GetDefaultQueuePresent()) {
$count++;
+ }
}
}
- else $count++;
+ else {
+ $count++;
+ }
return 0;
}
@@ -4261,12 +4675,14 @@ function &get_unique_queue_list() {
$qlist = array();
if (is_array($altq_list_queues)) {
foreach ($altq_list_queues as $altq) {
- if ($altq->GetEnabled() == "")
+ if ($altq->GetEnabled() == "") {
continue;
+ }
$tmplist =& $altq->get_queue_list();
foreach ($tmplist as $qname => $link) {
- if ($link->GetEnabled() <> "")
+ if ($link->GetEnabled() <> "") {
$qlist[$qname] = $link;
+ }
}
}
}
@@ -4279,8 +4695,9 @@ function &get_unique_dnqueue_list() {
$qlist = array();
if (is_array($dummynet_pipe_list)) {
foreach ($dummynet_pipe_list as $dn) {
- if ($dn->GetEnabled() == "")
+ if ($dn->GetEnabled() == "") {
continue;
+ }
$tmplist =& $dn->get_queue_list();
foreach ($tmplist as $qname => $link) {
$qlist[$qname] = $link;
@@ -4291,34 +4708,39 @@ function &get_unique_dnqueue_list() {
}
function ref_on_altq_queue_list($parent, $qname) {
- if (isset($GLOBALS['queue_list'][$qname]))
+ if (isset($GLOBALS['queue_list'][$qname])) {
$GLOBALS['queue_list'][$qname]++;
- else
+ } else {
$GLOBALS['queue_list'][$qname] = 1;
+ }
unref_on_altq_queue_list($parent);
}
function unref_on_altq_queue_list($qname) {
$GLOBALS['queue_list'][$qname]--;
- if ($GLOBALS['queue_list'][$qname] <= 1)
+ if ($GLOBALS['queue_list'][$qname] <= 1) {
unset($GLOBALS['queue_list'][$qname]);
+ }
}
function read_altq_config() {
global $altq_list_queues, $config;
$path = array();
- if (!is_array($config['shaper']))
+ if (!is_array($config['shaper'])) {
$config['shaper'] = array();
- if (!is_array($config['shaper']['queue']))
+ }
+ if (!is_array($config['shaper']['queue'])) {
$config['shaper']['queue'] = array();
+ }
$a_int = &$config['shaper']['queue'];
$altq_list_queues = array();
- if (!is_array($config['shaper']['queue']))
+ if (!is_array($config['shaper']['queue'])) {
return;
+ }
foreach ($a_int as $key => $conf) {
$int = $conf['interface'];
@@ -4347,21 +4769,25 @@ function read_dummynet_config() {
global $dummynet_pipe_list, $config;
$path = array();
- if (!is_array($config['dnshaper']))
+ if (!is_array($config['dnshaper'])) {
$config['dnshaper'] = array();
- if (!is_array($config['dnshaper']['queue']))
+ }
+ if (!is_array($config['dnshaper']['queue'])) {
$config['dnshaper']['queue'] = array();
+ }
$a_int = &$config['dnshaper']['queue'];
$dummynet_pipe_list = array();
- if (!is_array($config['dnshaper']['queue'])
- || !count($config['dnshaper']['queue']))
+ if (!is_array($config['dnshaper']['queue']) ||
+ !count($config['dnshaper']['queue'])) {
return;
+ }
foreach ($a_int as $key => $conf) {
- if (empty($conf['name']))
+ if (empty($conf['name'])) {
continue; /* XXX: grrrrrr at php */
+ }
$root =& new dnpipe_class();
$root->ReadConfig($conf);
$dummynet_pipe_list[$root->GetQname()] = &$root;
@@ -4391,8 +4817,9 @@ function get_interface_list_to_show() {
if ($altq_list_queues[$shif]) {
continue;
} else {
- if (!is_altq_capable(get_real_interface($shif)))
+ if (!is_altq_capable(get_real_interface($shif))) {
continue;
+ }
$tree .= " <li><a href=\"firewall_shaper.php?interface=".$shif."&amp;action=add\">".$shDescr."</a></li>";
}
}
@@ -4406,8 +4833,9 @@ function filter_generate_altq_queues() {
read_altq_config();
$altq_rules = "";
- foreach ($altq_list_queues as $altq)
+ foreach ($altq_list_queues as $altq) {
$altq_rules .= $altq->build_rules();
+ }
return $altq_rules;
}
@@ -4420,8 +4848,9 @@ function dnqueue_find_nextnumber() {
foreach ($dummynet_pipe_list as $dn) {
$tmplist =& $dn->get_queue_list();
foreach ($tmplist as $qname => $link) {
- if ($link[0] == "?")
+ if ($link[0] == "?") {
$dnused[$qname] = substr($link, 1);
+ }
}
}
}
@@ -4434,12 +4863,14 @@ function dnqueue_find_nextnumber() {
$dnnumber = $dnnum - 1;
$found = true;
break;
- } else
+ } else {
$dnnumber = $dnnum;
+ }
}
- if ($found == false)
+ if ($found == false) {
$dnnumber++;
+ }
unset($dnused, $dnnum, $found);
return $dnnumber;
@@ -4449,8 +4880,9 @@ function dnpipe_find_nextnumber() {
global $dummynet_pipe_list;
$dnused = array();
- foreach ($dummynet_pipe_list as $dn)
+ foreach ($dummynet_pipe_list as $dn) {
$dnused[] = $dn->GetNumber();
+ }
sort($dnused, SORT_NUMERIC);
$dnnumber = 0;
@@ -4460,12 +4892,14 @@ function dnpipe_find_nextnumber() {
$dnnumber = $dnnum - 1;
$found = true;
break;
- } else
+ } else {
$dnnumber = $dnnum;
+ }
}
- if ($found == false)
+ if ($found == false) {
$dnnumber++;
+ }
unset($dnused, $dnnum, $found);
return $dnnumber;
@@ -4477,8 +4911,9 @@ function filter_generate_dummynet_rules() {
read_dummynet_config();
$dn_rules = "";
- foreach ($dummynet_pipe_list as $dn)
+ foreach ($dummynet_pipe_list as $dn) {
$dn_rules .= $dn->build_rules();
+ }
if (!empty($dn_rules)) {
if (!is_module_loaded("dummynet.ko")) {
@@ -4498,8 +4933,9 @@ function build_iface_without_this_queue($iface, $qname) {
global $shaperIFlist;
$altq =& $altq_list_queues[$iface];
- if ($altq)
+ if ($altq) {
$scheduler = ": " . $altq->GetScheduler();
+ }
$form = "<tr><td width=\"20%\" >";
$form .= "<a href=\"firewall_shaper.php?interface=" . $iface . "&amp;queue=" . $iface."&amp;action=show\">". $shaperIFlist[$iface] . $scheduler."</a>";
$form .= "</td></tr>";
@@ -4519,14 +4955,14 @@ function build_iface_without_this_queue($iface, $qname) {
$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 />";
$default_shaper_msg .= gettext("The tree on the left helps you navigate through the queues <br />"
- . "buttons at the bottom represent queue actions and are activated accordingly.");
+ . "buttons at the bottom represent queue actions and are activated accordingly.");
$default_shaper_msg .= "</strong></span>";
$default_shaper_msg .= "</td></tr>";
$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 />";
$dn_default_shaper_msg .= gettext("The tree on the left helps you navigate through the queues <br />"
- . "buttons at the bottom represent queue actions and are activated accordingly.");
+ . "buttons at the bottom represent queue actions and are activated accordingly.");
$dn_default_shaper_msg .= "</strong></span>";
$dn_default_shaper_msg .= "</td></tr>";
diff --git a/etc/inc/smtp.inc b/etc/inc/smtp.inc
index 525bb33..035a30a 100644
--- a/etc/inc/smtp.inc
+++ b/etc/inc/smtp.inc
@@ -105,7 +105,7 @@ class smtp_class
{
if(feof($this->connection))
{
- $this->error=gettext("reached the end of data while reading from the SMTP server conection");
+ $this->error=gettext("reached the end of data while reading from the SMTP server connection");
return("");
}
if(GetType($data=@fgets($this->connection,100))!="string"
diff --git a/etc/inc/system.inc b/etc/inc/system.inc
index f95e9f3..112c218 100644
--- a/etc/inc/system.inc
+++ b/etc/inc/system.inc
@@ -31,7 +31,7 @@
/*
pfSense_BUILDER_BINARIES: /usr/sbin/powerd /usr/bin/killall /sbin/route
- pfSense_BUILDER_BINARIES: /bin/hostname /bin/ls /usr/sbin/syslogd
+ pfSense_BUILDER_BINARIES: /bin/hostname /bin/ls /usr/sbin/syslogd
pfSense_BUILDER_BINARIES: /usr/sbin/pccardd /usr/local/sbin/lighttpd /bin/chmod /bin/mkdir
pfSense_BUILDER_BINARIES: /usr/bin/tar /usr/local/sbin/ntpd /usr/local/sbin/ntpdate
pfSense_BUILDER_BINARIES: /usr/bin/nohup /sbin/dmesg /usr/local/sbin/atareinit /sbin/kldload
@@ -41,25 +41,31 @@
function activate_powerd() {
global $config, $g;
- if ($g['platform'] == 'jail')
+ if ($g['platform'] == 'jail') {
return;
- if(is_process_running("powerd"))
+ }
+ if (is_process_running("powerd")) {
exec("/usr/bin/killall powerd");
- if(isset($config['system']['powerd_enable'])) {
- if ($g["platform"] == "nanobsd")
+ }
+ if (isset($config['system']['powerd_enable'])) {
+ if ($g["platform"] == "nanobsd") {
exec("/sbin/kldload cpufreq");
+ }
$ac_mode = "hadp";
- if (!empty($config['system']['powerd_ac_mode']))
+ if (!empty($config['system']['powerd_ac_mode'])) {
$ac_mode = $config['system']['powerd_ac_mode'];
+ }
$battery_mode = "hadp";
- if (!empty($config['system']['powerd_battery_mode']))
+ if (!empty($config['system']['powerd_battery_mode'])) {
$battery_mode = $config['system']['powerd_battery_mode'];
+ }
$normal_mode = "hadp";
- if (!empty($config['system']['powerd_normal_mode']))
+ if (!empty($config['system']['powerd_normal_mode'])) {
$normal_mode = $config['system']['powerd_normal_mode'];
+ }
mwexec("/usr/sbin/powerd -b $battery_mode -a $ac_mode -n $normal_mode");
}
@@ -68,8 +74,9 @@ function activate_powerd() {
function get_default_sysctl_value($id) {
global $sysctls;
- if (isset($sysctls[$id]))
+ if (isset($sysctls[$id])) {
return $sysctls[$id];
+ }
}
function get_sysctl_descr($sysctl) {
@@ -85,11 +92,12 @@ function system_get_sysctls() {
$disp_sysctl = array();
$disp_cache = array();
if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) {
- foreach($config['sysctl']['item'] as $id => $tunable) {
- if ($tunable['value'] == "default")
+ foreach ($config['sysctl']['item'] as $id => $tunable) {
+ if ($tunable['value'] == "default") {
$value = get_default_sysctl_value($tunable['tunable']);
- else
+ } else {
$value = $tunable['value'];
+ }
$disp_sysctl[$id] = $tunable;
$disp_sysctl[$id]['modified'] = true;
@@ -98,8 +106,9 @@ function system_get_sysctls() {
}
foreach ($sysctls as $sysctl => $value) {
- if (isset($disp_cache[$sysctl]))
+ if (isset($disp_cache[$sysctl])) {
continue;
+ }
$disp_sysctl[$sysctl] = array('tunable' => $sysctl, 'value' => $value, 'descr' => get_sysctl_descr($sysctl));
}
@@ -110,15 +119,17 @@ function system_get_sysctls() {
function activate_sysctls() {
global $config, $g, $sysctls;
- if ($g['platform'] == 'jail')
+ if ($g['platform'] == 'jail') {
return;
+ }
if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) {
- foreach($config['sysctl']['item'] as $tunable) {
- if($tunable['value'] == "default")
+ foreach ($config['sysctl']['item'] as $tunable) {
+ if ($tunable['value'] == "default") {
$value = get_default_sysctl_value($tunable['tunable']);
- else
+ } else {
$value = $tunable['value'];
+ }
$sysctls[$tunable['tunable']] = $value;
}
@@ -130,45 +141,58 @@ function activate_sysctls() {
function system_resolvconf_generate($dynupdate = false) {
global $config, $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_resolvconf_generate() being called $mt\n";
}
$syscfg = $config['system'];
- if (((isset($config['dnsmasq']['enable']) && (!isset($config['dnsmasq']['port']) || $config['dnsmasq']['port'] == "53") && (empty($config['dnsmasq']['interface']) || in_array("lo0", explode(",", $config['dnsmasq']['interface']))))
- || (isset($config['unbound']['enable'])) && (!isset($config['unbound']['port']) || $config['unbound']['port'] == "53") && (empty($config['unbound']['active_interface']) || in_array("lo0", explode(",", $config['unbound']['active_interface'])) || in_array("all", explode(",", $config['unbound']['active_interface']), true)))
- && !isset($config['system']['dnslocalhost']))
+ if ((((isset($config['dnsmasq']['enable'])) &&
+ (!isset($config['dnsmasq']['port']) || $config['dnsmasq']['port'] == "53") &&
+ (empty($config['dnsmasq']['interface']) ||
+ in_array("lo0", explode(",", $config['dnsmasq']['interface'])))) ||
+ ((isset($config['unbound']['enable'])) &&
+ (!isset($config['unbound']['port']) || $config['unbound']['port'] == "53") &&
+ (empty($config['unbound']['active_interface']) ||
+ in_array("lo0", explode(",", $config['unbound']['active_interface'])) ||
+ in_array("all", explode(",", $config['unbound']['active_interface']), true)))) &&
+ (!isset($config['system']['dnslocalhost']))) {
$resolvconf .= "nameserver 127.0.0.1\n";
+ }
if (isset($syscfg['dnsallowoverride'])) {
/* get dynamically assigned DNS servers (if any) */
$ns = array_unique(get_searchdomains());
- foreach($ns as $searchserver) {
- if($searchserver)
+ foreach ($ns as $searchserver) {
+ if ($searchserver) {
$resolvconf .= "search {$searchserver}\n";
+ }
}
$ns = array_unique(get_nameservers());
- foreach($ns as $nameserver) {
- if($nameserver)
+ foreach ($ns as $nameserver) {
+ if ($nameserver) {
$resolvconf .= "nameserver $nameserver\n";
+ }
}
} else {
// Do not create blank search/domain lines, it can break tools like dig.
- if($syscfg['domain'])
+ if ($syscfg['domain']) {
$resolvconf .= "search {$syscfg['domain']}\n";
+ }
}
if (is_array($syscfg['dnsserver'])) {
foreach ($syscfg['dnsserver'] as $ns) {
- if ($ns)
+ if ($ns) {
$resolvconf .= "nameserver $ns\n";
+ }
}
}
// Add EDNS support
- if (isset($config['unbound']['enable']) && isset($config['unbound']['edns']))
+ if (isset($config['unbound']['enable']) && isset($config['unbound']['edns'])) {
$resolvconf .= "options edns0\n";
+ }
$dnslock = lock('resolvconf', LOCK_EX);
@@ -193,8 +217,9 @@ function system_resolvconf_generate($dynupdate = false) {
if (!platform_booting()) {
/* restart dhcpd (nameservers may have changed) */
- if (!$dynupdate)
+ if (!$dynupdate) {
services_dhcpd_configure();
+ }
}
/* setup static routes for DNS servers. */
@@ -221,7 +246,7 @@ function system_resolvconf_generate($dynupdate = false) {
if (isset($config['system']['route-debug'])) {
$mt = microtime();
log_error("ROUTING debug: $mt - route change -host -inet6 {$syscfg['dnsserver'][$dnscountermo]} $gatewayip ");
- }
+ }
}
}
}
@@ -236,17 +261,19 @@ function get_searchdomains() {
global $config, $g;
$master_list = array();
-
+
// Read in dhclient nameservers
$search_list = glob("/var/etc/searchdomain_*");
if (is_array($search_list)) {
- foreach($search_list as $fdns) {
+ foreach ($search_list as $fdns) {
$contents = file($fdns, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- if (!is_array($contents))
+ if (!is_array($contents)) {
continue;
+ }
foreach ($contents as $dns) {
- if(is_hostname($dns))
+ if (is_hostname($dns)) {
$master_list[] = $dns;
+ }
}
}
}
@@ -257,28 +284,32 @@ function get_searchdomains() {
function get_nameservers() {
global $config, $g;
$master_list = array();
-
+
// Read in dhclient nameservers
$dns_lists = glob("/var/etc/nameserver_*");
if (is_array($dns_lists)) {
- foreach($dns_lists as $fdns) {
+ foreach ($dns_lists as $fdns) {
$contents = file($fdns, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- if (!is_array($contents))
+ if (!is_array($contents)) {
continue;
+ }
foreach ($contents as $dns) {
- if(is_ipaddr($dns))
+ if (is_ipaddr($dns)) {
$master_list[] = $dns;
+ }
}
}
}
// Read in any extra nameservers
- if(file_exists("/var/etc/nameservers.conf")) {
+ if (file_exists("/var/etc/nameservers.conf")) {
$dns_s = file("/var/etc/nameservers.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- if(is_array($dns_s)) {
- foreach($dns_s as $dns)
- if (is_ipaddr($dns))
+ if (is_array($dns_s)) {
+ foreach ($dns_s as $dns) {
+ if (is_ipaddr($dns)) {
$master_list[] = $dns;
+ }
+ }
}
}
@@ -293,10 +324,11 @@ function system_hosts_generate() {
}
$syscfg = $config['system'];
- if (isset($config['unbound']) && isset($config['unbound']['enable']))
+ if (isset($config['unbound']) && isset($config['unbound']['enable'])) {
$dnsmasqcfg = $config['unbound'];
- else
+ } else {
$dnsmasqcfg = $config['dnsmasq'];
+ }
$hosts = "127.0.0.1 localhost localhost.{$syscfg['domain']}\n";
$hosts .= "::1 localhost localhost.{$syscfg['domain']}\n";
@@ -305,11 +337,13 @@ function system_hosts_generate() {
if ($config['interfaces']['lan']) {
$cfgip = get_interface_ip("lan");
- if (is_ipaddr($cfgip))
+ if (is_ipaddr($cfgip)) {
$hosts .= "{$cfgip} {$syscfg['hostname']}.{$syscfg['domain']} {$syscfg['hostname']}\n";
+ }
$cfgipv6 = get_interface_ipv6("lan");
- if (is_ipaddrv6($cfgipv6))
+ if (is_ipaddrv6($cfgipv6)) {
$hosts .= "{$cfgipv6} {$syscfg['hostname']}.{$syscfg['domain']} {$syscfg['hostname']}\n";
+ }
} else {
$sysiflist = get_configured_interface_list();
$hosts_if_found = false;
@@ -325,61 +359,75 @@ function system_hosts_generate() {
$hosts .= "{$cfgipv6} {$syscfg['hostname']}.{$syscfg['domain']} {$syscfg['hostname']}\n";
$hosts_if_found = true;
}
- if ($hosts_if_found == true)
+ if ($hosts_if_found == true) {
break;
+ }
}
}
}
if (isset($dnsmasqcfg['enable'])) {
- if (!is_array($dnsmasqcfg['hosts']))
+ if (!is_array($dnsmasqcfg['hosts'])) {
$dnsmasqcfg['hosts'] = array();
+ }
foreach ($dnsmasqcfg['hosts'] as $host) {
- if ($host['host'])
+ if ($host['host']) {
$lhosts .= "{$host['ip']} {$host['host']}.{$host['domain']} {$host['host']}\n";
- else
+ } else {
$lhosts .= "{$host['ip']} {$host['domain']}\n";
- if (!is_array($host['aliases']) || !is_array($host['aliases']['item']))
+ }
+ if (!is_array($host['aliases']) || !is_array($host['aliases']['item'])) {
continue;
+ }
foreach ($host['aliases']['item'] as $alias) {
- if ($alias['host'])
+ if ($alias['host']) {
$lhosts .= "{$host['ip']} {$alias['host']}.{$alias['domain']} {$alias['host']}\n";
- else
+ } else {
$lhosts .= "{$host['ip']} {$alias['domain']}\n";
+ }
}
}
if (isset($dnsmasqcfg['regdhcpstatic']) && is_array($config['dhcpd'])) {
- foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf)
- if(is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable']))
- foreach ($dhcpifconf['staticmap'] as $host)
- if ($host['ipaddr'] && $host['hostname'] && $host['domain'])
- $dhosts .= "{$host['ipaddr']} {$host['hostname']}.{$host['domain']} {$host['hostname']}\n";
- else if ($host['ipaddr'] && $host['hostname'] && $dhcpifconf['domain'])
- $dhosts .= "{$host['ipaddr']} {$host['hostname']}.{$dhcpifconf['domain']} {$host['hostname']}\n";
- else if ($host['ipaddr'] && $host['hostname'])
- $dhosts .= "{$host['ipaddr']} {$host['hostname']}.{$syscfg['domain']} {$host['hostname']}\n";
+ foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) {
+ if (is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable'])) {
+ foreach ($dhcpifconf['staticmap'] as $host) {
+ if ($host['ipaddr'] && $host['hostname'] && $host['domain']) {
+ $dhosts .= "{$host['ipaddr']} {$host['hostname']}.{$host['domain']} {$host['hostname']}\n";
+ } else if ($host['ipaddr'] && $host['hostname'] && $dhcpifconf['domain']) {
+ $dhosts .= "{$host['ipaddr']} {$host['hostname']}.{$dhcpifconf['domain']} {$host['hostname']}\n";
+ } else if ($host['ipaddr'] && $host['hostname']) {
+ $dhosts .= "{$host['ipaddr']} {$host['hostname']}.{$syscfg['domain']} {$host['hostname']}\n";
+ }
+ }
+ }
+ }
}
if (isset($dnsmasqcfg['regdhcpstatic']) && is_array($config['dhcpdv6'])) {
- foreach ($config['dhcpdv6'] as $dhcpif => $dhcpifconf)
- if(is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable']))
- foreach ($dhcpifconf['staticmap'] as $host)
- if ($host['ipaddrv6'] && $host['hostname'] && $host['domain'])
- $dhosts .= "{$host['ipaddrv6']} {$host['hostname']}.{$host['domain']} {$host['hostname']}\n";
- else if ($host['ipaddrv6'] && $host['hostname'] && $dhcpifconf['domain'])
- $dhosts .= "{$host['ipaddrv6']} {$host['hostname']}.{$dhcpifconf['domain']} {$host['hostname']}\n";
- else if ($host['ipaddrv6'] && $host['hostname'])
- $dhosts .= "{$host['ipaddrv6']} {$host['hostname']}.{$syscfg['domain']} {$host['hostname']}\n";
- }
-
- if (isset($dnsmasqcfg['dhcpfirst']))
+ foreach ($config['dhcpdv6'] as $dhcpif => $dhcpifconf) {
+ if (is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable'])) {
+ foreach ($dhcpifconf['staticmap'] as $host) {
+ if ($host['ipaddrv6'] && $host['hostname'] && $host['domain']) {
+ $dhosts .= "{$host['ipaddrv6']} {$host['hostname']}.{$host['domain']} {$host['hostname']}\n";
+ } else if ($host['ipaddrv6'] && $host['hostname'] && $dhcpifconf['domain']) {
+ $dhosts .= "{$host['ipaddrv6']} {$host['hostname']}.{$dhcpifconf['domain']} {$host['hostname']}\n";
+ } else if ($host['ipaddrv6'] && $host['hostname']) {
+ $dhosts .= "{$host['ipaddrv6']} {$host['hostname']}.{$syscfg['domain']} {$host['hostname']}\n";
+ }
+ }
+ }
+ }
+ }
+
+ if (isset($dnsmasqcfg['dhcpfirst'])) {
$hosts .= $dhosts . $lhosts;
- else
+ } else {
$hosts .= $lhosts . $dhosts;
+ }
}
/*
- * Do not remove this because dhcpleases monitors with kqueue it needs to be
+ * Do not remove this because dhcpleases monitors with kqueue it needs to be
* killed before writing to hosts files.
*/
if (file_exists("{$g['varrun_path']}/dhcpleases.pid")) {
@@ -404,16 +452,18 @@ function system_hosts_generate() {
function system_dhcpleases_configure() {
global $config, $g;
-
- if ($g['platform'] == 'jail')
+
+ if ($g['platform'] == 'jail') {
return;
+ }
/* Start the monitoring process for dynamic dhcpclients. */
- if ((isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcp']))
- || (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcp']))) {
+ if ((isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcp'])) ||
+ (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcp']))) {
/* Make sure we do not error out */
mwexec("/bin/mkdir -p {$g['dhcpd_chroot_path']}/var/db");
- if (!file_exists("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases"))
+ if (!file_exists("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases")) {
@touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases");
+ }
if (isset($config['unbound']['enable'])) {
$dns_pid = "unbound.pid";
@@ -430,13 +480,15 @@ function system_dhcpleases_configure() {
if (intval($retval) == 0) {
sigkillbypid($pidfile, "HUP");
return;
- } else
+ } else {
sigkillbypid($pidfile, "TERM");
+ }
}
/* To ensure we do not start multiple instances of dhcpleases, perform some clean-up first. */
- if (is_process_running("dhcpleases"))
+ if (is_process_running("dhcpleases")) {
sigkillbyname('dhcpleases', "TERM");
+ }
@unlink($pidfile);
mwexec("/usr/local/sbin/dhcpleases -l {$g['dhcpd_chroot_path']}/var/db/dhcpd.leases -d {$config['system']['domain']} -p {$g['varrun_path']}/{$dns_pid} {$unbound_conf} -h {$g['varetc_path']}/hosts");
} else {
@@ -447,7 +499,7 @@ function system_dhcpleases_configure() {
function system_hostname_configure() {
global $config, $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_hostname_configure() being called $mt\n";
}
@@ -458,7 +510,7 @@ function system_hostname_configure() {
$status = mwexec("/bin/hostname " .
escapeshellarg("{$syscfg['hostname']}.{$syscfg['domain']}"));
- /* Setup host GUID ID. This is used by ZFS. */
+ /* Setup host GUID ID. This is used by ZFS. */
mwexec("/etc/rc.d/hostid start");
return $status;
@@ -466,9 +518,10 @@ function system_hostname_configure() {
function system_routing_configure($interface = "") {
global $config, $g;
- if ($g['platform'] == 'jail')
+ if ($g['platform'] == 'jail') {
return;
- if(isset($config['system']['developerspew'])) {
+ }
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_routing_configure() being called $mt\n";
}
@@ -485,33 +538,39 @@ function system_routing_configure($interface = "") {
foreach ($config['gateways']['gateway_item'] as $gateway) {
if (isset($gateway['defaultgw'])) {
if ($foundgw == false && ($gateway['ipprotocol'] != "inet6" && (is_ipaddrv4($gateway['gateway']) || $gateway['gateway'] == "dynamic"))) {
- if(strpos($gateway['gateway'], ":"))
+ if (strpos($gateway['gateway'], ":")) {
continue;
- if ($gateway['gateway'] == "dynamic")
+ }
+ if ($gateway['gateway'] == "dynamic") {
$gateway['gateway'] = get_interface_gateway($gateway['interface']);
+ }
$gatewayip = $gateway['gateway'];
$interfacegw = $gateway['interface'];
if (!empty($gateway['interface'])) {
$defaultif = get_real_interface($gateway['interface']);
- if ($defaultif)
+ if ($defaultif) {
@file_put_contents("{$g['tmp_path']}/{$defaultif}_defaultgw", $gateway['gateway']);
+ }
}
$foundgw = true;
} else if ($foundgwv6 == false && ($gateway['ipprotocol'] == "inet6" && (is_ipaddrv6($gateway['gateway']) || $gateway['gateway'] == "dynamic"))) {
- if ($gateway['gateway'] == "dynamic")
+ if ($gateway['gateway'] == "dynamic") {
$gateway['gateway'] = get_interface_gateway_v6($gateway['interface']);
+ }
$gatewayipv6 = $gateway['gateway'];
$interfacegwv6 = $gateway['interface'];
if (!empty($gateway['interface'])) {
$defaultifv6 = get_real_interface($gateway['interface']);
- if ($defaultifv6)
+ if ($defaultifv6) {
@file_put_contents("{$g['tmp_path']}/{$defaultifv6}_defaultgwv6", $gateway['gateway']);
+ }
}
$foundgwv6 = true;
}
}
- if ($foundgw === true && $foundgwv6 === true)
+ if ($foundgw === true && $foundgwv6 === true) {
break;
+ }
}
}
if ($foundgw == false) {
@@ -519,7 +578,7 @@ function system_routing_configure($interface = "") {
$interfacegw = "wan";
$gatewayip = get_interface_gateway("wan");
@file_put_contents("{$g['tmp_path']}/{$defaultif}_defaultgw", $gatewayip);
- }
+ }
if ($foundgwv6 == false) {
$defaultifv6 = get_real_interface("wan");
$interfacegwv6 = "wan";
@@ -529,8 +588,8 @@ function system_routing_configure($interface = "") {
$dont_add_route = false;
/* if OLSRD is enabled, allow WAN to house DHCP. */
if (is_array($config['installedpackages']['olsrd'])) {
- foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
- if(($olsrd['enabledyngw'] == "on") && ($olsrd['enable'] == "on")) {
+ foreach ($config['installedpackages']['olsrd']['config'] as $olsrd) {
+ if (($olsrd['enabledyngw'] == "on") && ($olsrd['enable'] == "on")) {
$dont_add_route = true;
log_error(sprintf(gettext("Not adding default route because OLSR dynamic gateway is enabled.")));
break;
@@ -538,20 +597,21 @@ function system_routing_configure($interface = "") {
}
}
- if ($dont_add_route == false ) {
- if (!empty($interface) && $interface != $interfacegw)
+ if ($dont_add_route == false) {
+ if (!empty($interface) && $interface != $interfacegw) {
;
- else if (is_ipaddrv4($gatewayip)) {
+ } else if (is_ipaddrv4($gatewayip)) {
log_error("ROUTING: setting default route to $gatewayip");
mwexec("/sbin/route change -inet default " . escapeshellarg($gatewayip));
}
- if (!empty($interface) && $interface != $interfacegwv6)
+ if (!empty($interface) && $interface != $interfacegwv6) {
;
- else if (is_ipaddrv6($gatewayipv6)) {
+ } else if (is_ipaddrv6($gatewayipv6)) {
$ifscope = "";
- if (is_linklocal($gatewayipv6) && !strpos($gatewayipv6, '%'))
+ if (is_linklocal($gatewayipv6) && !strpos($gatewayipv6, '%')) {
$ifscope = "%{$defaultifv6}";
+ }
log_error("ROUTING: setting IPv6 default route to {$gatewayipv6}{$ifscope}");
mwexec("/sbin/route change -inet6 default " . escapeshellarg("{$gatewayipv6}{$ifscope}"));
}
@@ -577,39 +637,46 @@ function system_staticroutes_configure($interface = "", $update_dns = false) {
continue;
}
$gateway = $gateways_arr[$rtent['gateway']];
- if (!empty($interface) && $interface != $gateway['friendlyiface'])
+ if (!empty($interface) && $interface != $gateway['friendlyiface']) {
continue;
+ }
$gatewayip = $gateway['gateway'];
$interfacegw = $gateway['interface'];
$blackhole = "";
- if (!strcasecmp("Null", substr($rtent['gateway'], 0, 3)))
+ if (!strcasecmp("Null", substr($rtent['gateway'], 0, 3))) {
$blackhole = "-blackhole";
+ }
- if (!is_fqdn($rtent['network']) && !is_subnet($rtent['network']))
+ if (!is_fqdn($rtent['network']) && !is_subnet($rtent['network'])) {
continue;
+ }
$dnscache = array();
if ($update_dns === true) {
- if (is_subnet($rtent['network']))
+ if (is_subnet($rtent['network'])) {
continue;
+ }
$dnscache = explode("\n", trim(compare_hostname_to_dnscache($rtent['network'])));
- if (empty($dnscache))
+ if (empty($dnscache)) {
continue;
+ }
}
- if (is_subnet($rtent['network']))
+ if (is_subnet($rtent['network'])) {
$ips = array($rtent['network']);
- else {
- if (!isset($rtent['disabled']))
+ } else {
+ if (!isset($rtent['disabled'])) {
$filterdns_list[] = $rtent['network'];
+ }
$ips = add_hostname_to_watch($rtent['network']);
}
foreach ($dnscache as $ip) {
- if (in_array($ip, $ips))
+ if (in_array($ip, $ips)) {
continue;
+ }
mwexec("/sbin/route delete " . escapeshellarg($ip), true);
if (isset($config['system']['route-debug'])) {
$mt = microtime();
@@ -630,15 +697,16 @@ function system_staticroutes_configure($interface = "", $update_dns = false) {
}
foreach ($ips as $ip) {
- if (is_ipaddrv4($ip))
+ if (is_ipaddrv4($ip)) {
$ip .= "/32";
+ }
// do NOT do the same check here on v6, is_ipaddrv6 returns true when including the CIDR mask. doing so breaks v6 routes
-
+
$inet = (is_subnetv6($ip) ? "-inet6" : "-inet");
$cmd = "/sbin/route change {$inet} {$blackhole} " . escapeshellarg($ip) . " ";
- if (is_subnet($ip))
+ if (is_subnet($ip)) {
if (is_ipaddr($gatewayip)) {
mwexec($cmd . escapeshellarg($gatewayip));
if (isset($config['system']['route-debug'])) {
@@ -652,6 +720,7 @@ function system_staticroutes_configure($interface = "", $update_dns = false) {
log_error("ROUTING debug: $mt - $cmd -iface $interfacegw ");
}
}
+ }
}
}
unset($gateways_arr);
@@ -663,15 +732,17 @@ function system_staticroutes_configure($interface = "", $update_dns = false) {
$interval = 60;
$hostnames = "";
array_unique($filterdns_list);
- foreach ($filterdns_list as $hostname)
+ foreach ($filterdns_list as $hostname) {
$hostnames .= "cmd {$hostname} '/usr/local/sbin/pfSctl -c \"service reload routedns\"'\n";
+ }
file_put_contents("{$g['varetc_path']}/filterdns-route.hosts", $hostnames);
unset($hostnames);
- if (isvalidpid("{$g['varrun_path']}/filterdns-route.pid"))
+ if (isvalidpid("{$g['varrun_path']}/filterdns-route.pid")) {
sigkillbypid("{$g['varrun_path']}/filterdns-route.pid", "HUP");
- else
+ } else {
mwexec("/usr/local/sbin/filterdns -p {$g['varrun_path']}/filterdns-route.pid -i {$interval} -c {$g['varetc_path']}/filterdns-route.hosts -d 1");
+ }
} else {
killbypid("{$g['varrun_path']}/filterdns-route.pid");
@unlink("{$g['varrun_path']}/filterdns-route.pid");
@@ -684,7 +755,7 @@ function system_staticroutes_configure($interface = "", $update_dns = false) {
function system_routing_enable() {
global $config, $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_routing_enable() being called $mt\n";
}
@@ -699,10 +770,11 @@ function system_routing_enable() {
function system_syslogd_fixup_server($server) {
/* If it's an IPv6 IP alone, encase it in brackets */
- if (is_ipaddrv6($server))
+ if (is_ipaddrv6($server)) {
return "[$server]";
- else
+ } else {
return $server;
+ }
}
function system_syslogd_get_remote_servers($syslogcfg, $facility = "*.*") {
@@ -711,18 +783,21 @@ function system_syslogd_get_remote_servers($syslogcfg, $facility = "*.*") {
$remote_servers = "";
$pad_to = 56;
$padding = ceil(($pad_to - strlen($facility))/8)+1;
- if($syslogcfg['remoteserver'])
+ if ($syslogcfg['remoteserver']) {
$remote_servers .= "{$facility}" . str_repeat("\t", $padding) . "@" . system_syslogd_fixup_server($syslogcfg['remoteserver']) . "\n";
- if($syslogcfg['remoteserver2'])
+ }
+ if ($syslogcfg['remoteserver2']) {
$remote_servers .= "{$facility}" . str_repeat("\t", $padding) . "@" . system_syslogd_fixup_server($syslogcfg['remoteserver2']) . "\n";
- if($syslogcfg['remoteserver3'])
+ }
+ if ($syslogcfg['remoteserver3']) {
$remote_servers .= "{$facility}" . str_repeat("\t", $padding) . "@" . system_syslogd_fixup_server($syslogcfg['remoteserver3']) . "\n";
+ }
return $remote_servers;
}
function system_syslogd_start() {
global $config, $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_syslogd_start() being called $mt\n";
}
@@ -731,11 +806,13 @@ function system_syslogd_start() {
$syslogcfg = $config['syslog'];
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Starting syslog...");
+ }
- if (is_process_running("fifolog_writer"))
+ if (is_process_running("fifolog_writer")) {
mwexec('/bin/pkill fifolog_writer');
+ }
// Which logging type are we using this week??
if (isset($config['system']['disablesyslogclog'])) {
@@ -756,9 +833,9 @@ function system_syslogd_start() {
if (isset($syslogcfg)) {
$separatelogfacilities = array('ntp','ntpd','ntpdate','charon','ipsec_starter','openvpn','pptps','poes','l2tps','relayd','hostapd','dnsmasq','filterdns','unbound','dhcpd','dhcrelay','dhclient','dhcp6c','apinger','radvd','routed','olsrd','zebra','ospfd','bgpd','miniupnpd','filterlog');
$syslogconf = "";
- if($config['installedpackages']['package']) {
- foreach($config['installedpackages']['package'] as $package) {
- if($package['logging']) {
+ if ($config['installedpackages']['package']) {
+ foreach ($config['installedpackages']['package'] as $package) {
+ if ($package['logging']) {
array_push($separatelogfacilities, $package['logging']['facilityname']);
mwexec("{$log_create_directive} {$log_size} {$g['varlog_path']}/{$package['logging']['logfilename']}");
$syslogconf .= "!{$package['logging']['facilityname']}\n*.*\t\t\t\t\t\t {$log_directive}{$g['varlog_path']}/{$package['logging']['logfilename']}\n";
@@ -767,76 +844,96 @@ function system_syslogd_start() {
}
$facilitylist = implode(',', array_unique($separatelogfacilities));
$syslogconf .= "!radvd,routed,olsrd,zebra,ospfd,bgpd,miniupnpd\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/routing.log\n";
+ }
$syslogconf .= "!ntp,ntpd,ntpdate\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/ntpd.log\n";
+ }
$syslogconf .= "!ppp\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/ppp.log\n";
+ }
$syslogconf .= "!pptps\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/pptps.log\n";
+ }
$syslogconf .= "!poes\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/poes.log\n";
+ }
$syslogconf .= "!l2tps\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/l2tps.log\n";
+ }
$syslogconf .= "!charon,ipsec_starter\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/ipsec.log\n";
- if (isset($syslogcfg['vpn']))
+ }
+ if (isset($syslogcfg['vpn'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
+ }
$syslogconf .= "!openvpn\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/openvpn.log\n";
- if (isset($syslogcfg['vpn']))
+ }
+ if (isset($syslogcfg['vpn'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
+ }
$syslogconf .= "!apinger\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/gateways.log\n";
- if (isset($syslogcfg['apinger']))
+ }
+ if (isset($syslogcfg['apinger'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
+ }
$syslogconf .= "!dnsmasq,filterdns,unbound\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/resolver.log\n";
+ }
$syslogconf .= "!dhcpd,dhcrelay,dhclient,dhcp6c\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/dhcpd.log\n";
- if (isset($syslogcfg['dhcp']))
+ }
+ if (isset($syslogcfg['dhcp'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
+ }
$syslogconf .= "!relayd\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/relayd.log\n";
- if (isset($syslogcfg['relayd']))
+ }
+ if (isset($syslogcfg['relayd'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
+ }
$syslogconf .= "!hostapd\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/wireless.log\n";
- if (isset($syslogcfg['hostapd']))
+ }
+ if (isset($syslogcfg['hostapd'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
+ }
$syslogconf .= "!filterlog\n";
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/filter.log\n";
- if (isset($syslogcfg['filter']))
+ if (isset($syslogcfg['filter'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
+ }
$syslogconf .= "!-{$facilitylist}\n";
- if (!isset($syslogcfg['disablelocallogging']))
+ if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= <<<EOD
local3.* {$log_directive}{$g['varlog_path']}/vpn.log
local4.* {$log_directive}{$g['varlog_path']}/portalauth.log
@@ -850,12 +947,16 @@ auth.info;authpriv.info |exec /usr/local/sbin/sshlockout_pf 15
*.emerg *
EOD;
- if (isset($syslogcfg['vpn']))
+ }
+ if (isset($syslogcfg['vpn'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "local3.*");
- if (isset($syslogcfg['portalauth']))
+ }
+ if (isset($syslogcfg['portalauth'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "local4.*");
- if (isset($syslogcfg['dhcp']))
+ }
+ if (isset($syslogcfg['dhcp'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "local7.*");
+ }
if (isset($syslogcfg['system'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.notice;kern.debug;lpr.info;mail.crit;");
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "news.err;local0.none;local3.none;local7.none");
@@ -875,7 +976,7 @@ EOD;
EOD;
}
- /* write syslog.conf */
+ /* write syslog.conf */
if (!@file_put_contents("{$g['varetc_path']}/syslog.conf", $syslogconf)) {
printf(gettext("Error: cannot open syslog.conf in system_syslogd_start().%s"), "\n");
unset($syslogconf);
@@ -884,19 +985,22 @@ EOD;
unset($syslogconf);
// Ensure that the log directory exists
- if (!is_dir("{$g['dhcpd_chroot_path']}/var/run"))
+ if (!is_dir("{$g['dhcpd_chroot_path']}/var/run")) {
exec("/bin/mkdir -p {$g['dhcpd_chroot_path']}/var/run");
+ }
$sourceip = "";
if (!empty($syslogcfg['sourceip'])) {
if ($syslogcfg['ipproto'] == "ipv6") {
$ifaddr = is_ipaddr($syslogcfg['sourceip']) ? $syslogcfg['sourceip'] : get_interface_ipv6($syslogcfg['sourceip']);
- if (!is_ipaddr($ifaddr))
+ if (!is_ipaddr($ifaddr)) {
$ifaddr = get_interface_ip($syslogcfg['sourceip']);
+ }
} else {
$ifaddr = is_ipaddr($syslogcfg['sourceip']) ? $syslogcfg['sourceip'] : get_interface_ip($syslogcfg['sourceip']);
- if (!is_ipaddr($ifaddr))
+ if (!is_ipaddr($ifaddr)) {
$ifaddr = get_interface_ipv6($syslogcfg['sourceip']);
+ }
}
if (is_ipaddr($ifaddr)) {
$sourceip = "-b {$ifaddr}";
@@ -910,18 +1014,19 @@ EOD;
sigkillbypid("{$g['varrun_path']}/syslog.pid", "TERM");
usleep(100000); // syslogd often doesn't respond to a TERM quickly enough for the starting of syslogd below to be successful
}
-
+
if (isvalidpid("{$g['varrun_path']}/syslog.pid")) {
- // if it still hasn't responded to the TERM, KILL it.
+ // if it still hasn't responded to the TERM, KILL it.
sigkillbypid("{$g['varrun_path']}/syslog.pid", "KILL");
- usleep(100000);
+ usleep(100000);
}
-
+
$retval = mwexec_bg("/usr/sbin/syslogd -s -c -c -l {$g['dhcpd_chroot_path']}/var/run/log -P {$g['varrun_path']}/syslog.pid {$syslogd_extra}");
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("done.") . "\n";
+ }
return $retval;
}
@@ -929,11 +1034,13 @@ EOD;
function system_webgui_create_certificate() {
global $config, $g;
- if (!is_array($config['ca']))
+ if (!is_array($config['ca'])) {
$config['ca'] = array();
+ }
$a_ca =& $config['ca'];
- if (!is_array($config['cert']))
+ if (!is_array($config['cert'])) {
$config['cert'] = array();
+ }
$a_cert =& $config['cert'];
log_error("Creating SSL Certificate for this host");
@@ -949,8 +1056,8 @@ function system_webgui_create_certificate() {
'emailAddress' => "admin@{$config['system']['hostname']}.{$config['system']['domain']}",
'commonName' => "{$config['system']['hostname']}-{$cert['refid']}");
$old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warnings directly to a page screwing menu tab */
- if (!cert_create($cert, null, 2048, 2000, $dn, "self-signed", "sha256")){
- while($ssl_err = openssl_error_string()){
+ if (!cert_create($cert, null, 2048, 2000, $dn, "self-signed", "sha256")) {
+ while ($ssl_err = openssl_error_string()) {
log_error("Error creating WebGUI Certificate: openssl library returns: " . $ssl_err);
}
error_reporting($old_err_level);
@@ -967,8 +1074,9 @@ function system_webgui_create_certificate() {
function system_webgui_start() {
global $config, $g;
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Starting webConfigurator...");
+ }
chdir($g['www_path']);
@@ -979,19 +1087,22 @@ function system_webgui_start() {
$ca = "";
/* non-standard port? */
- if (isset($config['system']['webgui']['port']) && $config['system']['webgui']['port'] <> "")
+ if (isset($config['system']['webgui']['port']) && $config['system']['webgui']['port'] <> "") {
$portarg = "{$config['system']['webgui']['port']}";
+ }
if ($config['system']['webgui']['protocol'] == "https") {
// Ensure that we have a webConfigurator CERT
$cert =& lookup_cert($config['system']['webgui']['ssl-certref']);
- if(!is_array($cert) || !$cert['crt'] || !$cert['prv'])
+ if (!is_array($cert) || !$cert['crt'] || !$cert['prv']) {
$cert = system_webgui_create_certificate();
+ }
$crt = base64_decode($cert['crt']);
$key = base64_decode($cert['prv']);
- if(!$config['system']['webgui']['port'])
+ if (!$config['system']['webgui']['port']) {
$portarg = "443";
+ }
$ca = ca_chain($cert);
}
@@ -1011,10 +1122,11 @@ function system_webgui_start() {
$res = mwexec("/usr/local/sbin/lighttpd -f {$g['varetc_path']}/lighty-webConfigurator.conf");
if (platform_booting()) {
- if ($res == 0)
+ if ($res == 0) {
echo gettext("done.") . "\n";
- else
+ } else {
echo gettext("failed!") . "\n";
+ }
}
return $res;
@@ -1033,10 +1145,11 @@ function system_generate_lighty_config($filename,
global $config, $g;
- if(!is_dir("{$g['tmp_path']}/lighttpdcompress"))
+ if (!is_dir("{$g['tmp_path']}/lighttpdcompress")) {
mkdir("{$g['tmp_path']}/lighttpdcompress");
+ }
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_generate_lighty_config() being called $mt\n";
}
@@ -1046,13 +1159,15 @@ function system_generate_lighty_config($filename,
$captive_portal_rewrite = "url.rewrite-once = ( \"(.*captiveportal.*)\" => \"$1\", \"(.*)\" => \"/index.php?zone={$captive_portal}&redirurl=$1\" )\n";
$maxprocperip = $config['captiveportal'][$captive_portal]['maxprocperip'];
- if (empty($maxprocperip))
+ if (empty($maxprocperip)) {
$maxprocperip = 10;
+ }
$captive_portal_mod_evasive = "evasive.max-conns-per-ip = {$maxprocperip}";
$server_upload_dirs = "server.upload-dirs = ( \"{$g['tmp_path']}/captiveportal/\" )\n";
- if(!is_dir("{$g['tmp_path']}/captiveportal"))
+ if (!is_dir("{$g['tmp_path']}/captiveportal")) {
@mkdir("{$g['tmp_path']}/captiveportal", 0555);
+ }
$server_max_request_size = "server.max-request-size = 384";
$cgi_config = "";
} else {
@@ -1063,22 +1178,24 @@ function system_generate_lighty_config($filename,
$server_max_request_size = "server.max-request-size = 2097152";
$cgi_config = "cgi.assign = ( \".cgi\" => \"\" )";
}
-
- if (empty($port))
+
+ if (empty($port)) {
$lighty_port = "80";
- else
+ } else {
$lighty_port = $port;
+ }
$memory = get_memory();
$realmem = $memory[1];
// Determine web GUI process settings and take into account low memory systems
- if ($realmem < 255)
+ if ($realmem < 255) {
$max_procs = 1;
- else
+ } else {
$max_procs = ($config['system']['webgui']['max_procs']) ? $config['system']['webgui']['max_procs'] : 2;
+ }
- // Ramp up captive portal max procs, assuming each PHP process can consume up to 64MB RAM
+ // Ramp up captive portal max procs, assuming each PHP process can consume up to 64MB RAM
if ($captive_portal !== false) {
if ($realmem > 135 and $realmem < 256) {
$max_procs += 1; // 2 worker processes
@@ -1087,19 +1204,21 @@ function system_generate_lighty_config($filename,
} else if ($realmem > 512) {
$max_procs += 4; // 6 worker processes
}
- if ($max_procs > 1)
+ if ($max_procs > 1) {
$max_php_children = intval($max_procs/2);
- else
+ } else {
$max_php_children = 1;
+ }
} else {
- if ($realmem < 78)
+ if ($realmem < 78) {
$max_php_children = 0;
- else
+ } else {
$max_php_children = 1;
+ }
}
- if(!isset($config['syslog']['nologlighttpd'])) {
+ if (!isset($config['syslog']['nologlighttpd'])) {
$lighty_use_syslog = <<<EOD
## where to send error-messages to
server.errorlog-use-syslog="enable"
@@ -1254,13 +1373,14 @@ EOD;
$lighty_config .= "server.port = {$lighty_port}\n";
$lighty_config .= "\$SERVER[\"socket\"] == \"0.0.0.0:{$lighty_port}\" { }\n";
$lighty_config .= "\$SERVER[\"socket\"] == \"[::]:{$lighty_port}\" { \n";
- if($cert <> "" and $key <> "") {
+ if ($cert <> "" and $key <> "") {
$lighty_config .= "\n";
$lighty_config .= "## ssl configuration\n";
$lighty_config .= "ssl.engine = \"enable\"\n";
$lighty_config .= "ssl.pemfile = \"{$g['varetc_path']}/{$cert_location}\"\n\n";
- if($ca <> "")
+ if ($ca <> "") {
$lighty_config .= "ssl.ca-file = \"{$g['varetc_path']}/{$ca_location}\"\n\n";
+ }
}
$lighty_config .= " }\n";
@@ -1298,8 +1418,8 @@ compress.filetype = ("text/plain","text/css", "text/xml", "text/javascript" )
{$captive_portal_mod_evasive}
expire.url = (
- "" => "access 50 hours",
- )
+ "" => "access 50 hours",
+ )
EOD;
@@ -1311,7 +1431,7 @@ EOD;
$key = str_replace("\n\n", "\n", $key);
$ca = str_replace("\n\n", "\n", $ca);
- if($cert <> "" and $key <> "") {
+ if ($cert <> "" and $key <> "") {
$fd = fopen("{$g['varetc_path']}/{$cert_location}", "w");
if (!$fd) {
printf(gettext("Error: cannot open cert.pem in system_webgui_start().%s"), "\n");
@@ -1322,7 +1442,7 @@ EOD;
fwrite($fd, "\n");
fwrite($fd, $key);
fclose($fd);
- if(!(empty($ca) || (strlen(trim($ca)) == 0))) {
+ if (!(empty($ca) || (strlen(trim($ca)) == 0))) {
$fd = fopen("{$g['varetc_path']}/{$ca_location}", "w");
if (!$fd) {
printf(gettext("Error: cannot open ca.pem in system_webgui_start().%s"), "\n");
@@ -1347,8 +1467,8 @@ EOD;
while (!feof($fd)) {
$dmesgl = fgets($fd);
if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches) && isset($config['system']['webgui']['beast_protection'])) {
- unset($config['system']['webgui']['beast_protection']);
- log_error("BEAST Protection disabled because a conflicting cryptographic accelerator card has been detected (" . $matches[1] . ")");
+ unset($config['system']['webgui']['beast_protection']);
+ log_error("BEAST Protection disabled because a conflicting cryptographic accelerator card has been detected (" . $matches[1] . ")");
break;
}
}
@@ -1362,14 +1482,16 @@ EOD;
$lighty_config .= "ssl.cipher-list = \"DHE-RSA-CAMELLIA256-SHA:DHE-DSS-CAMELLIA256-SHA:CAMELLIA256-SHA:DHE-DSS-AES256-SHA:AES256-SHA:DHE-RSA-CAMELLIA128-SHA:DHE-DSS-CAMELLIA128-SHA:CAMELLIA128-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:AES128-SHA:!aNULL:!eNULL:!3DES:@STRENGTH\"\n";
}
- if(!(empty($ca) || (strlen(trim($ca)) == 0)))
+ if (!(empty($ca) || (strlen(trim($ca)) == 0))) {
$lighty_config .= "ssl.ca-file = \"{$g['varetc_path']}/{$ca_location}\"\n\n";
+ }
}
- // Add HTTP to HTTPS redirect
+ // Add HTTP to HTTPS redirect
if ($captive_portal === false && $config['system']['webgui']['protocol'] == "https" && !isset($config['system']['webgui']['disablehttpredirect'])) {
- if($lighty_port != "443")
+ if ($lighty_port != "443") {
$redirectport = ":{$lighty_port}";
+ }
$lighty_config .= <<<EOD
\$SERVER["socket"] == ":80" {
\$HTTP["host"] =~ "(.*)" {
@@ -1398,30 +1520,33 @@ EOD;
function system_timezone_configure() {
global $config, $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_timezone_configure() being called $mt\n";
}
$syscfg = $config['system'];
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Setting timezone...");
+ }
/* extract appropriate timezone file */
$timezone = $syscfg['timezone'];
if ($timezone) {
exec('/usr/bin/tar -tvzf /usr/share/zoneinfo.tgz', $tzs);
foreach ($tzs as $tz) {
- if (preg_match(",{$timezone}$,", $tz))
+ if (preg_match(",{$timezone}$,", $tz)) {
break;
+ }
if (preg_match(",{$timezone} link to *(.*)$,", $tz, $matches)) {
$timezone = $matches[1];
break;
}
}
- } else
+ } else {
$timezone = "Etc/UTC";
+ }
conf_mount_rw();
@@ -1431,8 +1556,9 @@ function system_timezone_configure() {
mwexec("sync");
conf_mount_ro();
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("done.") . "\n";
+ }
}
function system_ntp_setup_gps($serialport) {
@@ -1440,8 +1566,9 @@ function system_ntp_setup_gps($serialport) {
$gps_device = '/dev/gps0';
$serialport = '/dev/'.$serialport;
- if (!file_exists($serialport))
+ if (!file_exists($serialport)) {
return false;
+ }
conf_mount_rw();
// Create symlink that ntpd requires
@@ -1451,7 +1578,7 @@ function system_ntp_setup_gps($serialport) {
/* Send the following to the GPS port to initialize the GPS */
if (is_array($config['ntpd']) && is_array($config['ntpd']['gps']) && !empty($config['ntpd']['gps']['type'])) {
$gps_init = base64_decode($config['ntpd']['gps']['initcmd']);
- }else{
+ } else {
$gps_init = base64_decode('JFBVQlgsNDAsR1NWLDAsMCwwLDAqNTkNCiRQVUJYLDQwLEdMTCwwLDAsMCwwKjVDDQokUFVCWCw0MCxaREEsMCwwLDAsMCo0NA0KJFBVQlgsNDAsVlRHLDAsMCwwLDAqNUUNCiRQVUJYLDQwLEdTViwwLDAsMCwwKjU5DQokUFVCWCw0MCxHU0EsMCwwLDAsMCo0RQ0KJFBVQlgsNDAsR0dBLDAsMCwwLDANCiRQVUJYLDQwLFRYVCwwLDAsMCwwDQokUFVCWCw0MCxSTUMsMCwwLDAsMCo0Ng0KJFBVQlgsNDEsMSwwMDA3LDAwMDMsNDgwMCwwDQokUFVCWCw0MCxaREEsMSwxLDEsMQ==');
}
@@ -1463,7 +1590,7 @@ function system_ntp_setup_gps($serialport) {
if (intval(`grep -c '^gps0' /etc/remote`) == 0) {
$gpsbaud = '4800';
if (is_array($config['ntpd']) && is_array($config['ntpd']['gps']) && !empty($config['ntpd']['gps']['speed'])) {
- switch($config['ntpd']['gps']['speed']) {
+ switch ($config['ntpd']['gps']['speed']) {
case '16':
$gpsbaud = '9600';
break;
@@ -1495,8 +1622,9 @@ function system_ntp_setup_pps($serialport) {
$pps_device = '/dev/pps0';
$serialport = '/dev/'.$serialport;
- if (!file_exists($serialport))
+ if (!file_exists($serialport)) {
return false;
+ }
conf_mount_rw();
// Create symlink that ntpd requires
@@ -1516,13 +1644,15 @@ function system_ntp_configure($start_ntpd=true) {
$statsdir = "/var/log/ntp";
$gps_device = '/dev/gps0';
- if ($g['platform'] == 'jail')
+ if ($g['platform'] == 'jail') {
return;
+ }
safe_mkdir($statsdir);
- if (!is_array($config['ntpd']))
+ if (!is_array($config['ntpd'])) {
$config['ntpd'] = array();
+ }
$ntpcfg = "# \n";
$ntpcfg .= "# pfSense ntp configuration file \n";
@@ -1534,21 +1664,21 @@ function system_ntp_configure($start_ntpd=true) {
$ntpcfg .= 'tos orphan ';
if (!empty($config['ntpd']['orphan'])) {
$ntpcfg .= $config['ntpd']['orphan'];
- }else{
+ } else {
$ntpcfg .= '12';
}
$ntpcfg .= "\n";
/* Add PPS configuration */
- if (is_array($config['ntpd']['pps']) && !empty($config['ntpd']['pps']['port'])
- && file_exists('/dev/'.$config['ntpd']['pps']['port'])
- && system_ntp_setup_pps($config['ntpd']['pps']['port'])) {
+ if (is_array($config['ntpd']['pps']) && !empty($config['ntpd']['pps']['port']) &&
+ file_exists('/dev/'.$config['ntpd']['pps']['port']) &&
+ system_ntp_setup_pps($config['ntpd']['pps']['port'])) {
$ntpcfg .= "\n";
$ntpcfg .= "# PPS Setup\n";
$ntpcfg .= 'server 127.127.22.0';
$ntpcfg .= ' minpoll 4 maxpoll 4';
if (empty($config['ntpd']['pps']['prefer'])) { /*note: this one works backwards */
- $ntpcfg .= ' prefer';
+ $ntpcfg .= ' prefer';
}
if (!empty($config['ntpd']['pps']['noselect'])) {
$ntpcfg .= ' noselect ';
@@ -1564,7 +1694,7 @@ function system_ntp_configure($start_ntpd=true) {
}
if (!empty($config['ntpd']['pps']['flag3'])) {
$ntpcfg .= ' flag3 1';
- }else{
+ } else {
$ntpcfg .= ' flag3 0';
}
if (!empty($config['ntpd']['pps']['flag4'])) {
@@ -1579,9 +1709,9 @@ function system_ntp_configure($start_ntpd=true) {
/* End PPS configuration */
/* Add GPS configuration */
- if (is_array($config['ntpd']['gps']) && !empty($config['ntpd']['gps']['port'])
- && file_exists('/dev/'.$config['ntpd']['gps']['port'])
- && system_ntp_setup_gps($config['ntpd']['gps']['port'])) {
+ if (is_array($config['ntpd']['gps']) && !empty($config['ntpd']['gps']['port']) &&
+ file_exists('/dev/'.$config['ntpd']['gps']['port']) &&
+ system_ntp_setup_gps($config['ntpd']['gps']['port'])) {
$ntpcfg .= "\n";
$ntpcfg .= "# GPS Setup\n";
$ntpcfg .= 'server 127.127.20.0 mode ';
@@ -1596,12 +1726,12 @@ function system_ntp_configure($start_ntpd=true) {
$ntpmode += 128;
}
$ntpcfg .= (string) $ntpmode;
- }else{
+ } else {
$ntpcfg .= '0';
}
$ntpcfg .= ' minpoll 4 maxpoll 4';
if (empty($config['ntpd']['gps']['prefer'])) { /*note: this one works backwards */
- $ntpcfg .= ' prefer';
+ $ntpcfg .= ' prefer';
}
if (!empty($config['ntpd']['gps']['noselect'])) {
$ntpcfg .= ' noselect ';
@@ -1618,7 +1748,7 @@ function system_ntp_configure($start_ntpd=true) {
}
if (!empty($config['ntpd']['gps']['flag1'])) {
$ntpcfg .= ' flag1 1';
- }else{
+ } else {
$ntpcfg .= ' flag1 0';
}
if (!empty($config['ntpd']['gps']['flag2'])) {
@@ -1626,7 +1756,7 @@ function system_ntp_configure($start_ntpd=true) {
}
if (!empty($config['ntpd']['gps']['flag3'])) {
$ntpcfg .= ' flag3 1';
- }else{
+ } else {
$ntpcfg .= ' flag3 0';
}
if (!empty($config['ntpd']['gps']['flag4'])) {
@@ -1637,9 +1767,9 @@ function system_ntp_configure($start_ntpd=true) {
$ntpcfg .= $config['ntpd']['gps']['refid'];
}
$ntpcfg .= "\n";
- }elseif (is_array($config['ntpd']) && !empty($config['ntpd']['gpsport'])
- && file_exists('/dev/'.$config['ntpd']['gpsport'])
- && system_ntp_setup_gps($config['ntpd']['gpsport'])) {
+ } elseif (is_array($config['ntpd']) && !empty($config['ntpd']['gpsport']) &&
+ file_exists('/dev/'.$config['ntpd']['gpsport']) &&
+ system_ntp_setup_gps($config['ntpd']['gpsport'])) {
/* This handles a 2.1 and earlier config */
$ntpcfg .= "# GPS Setup\n";
$ntpcfg .= "server 127.127.20.0 mode 0 minpoll 4 maxpoll 4 prefer\n";
@@ -1649,13 +1779,17 @@ function system_ntp_configure($start_ntpd=true) {
$ntpcfg .= "fudge 127.127.1.0 stratum 12\n";
}
/* End GPS configuration */
-
+
$ntpcfg .= "\n\n# Upstream Servers\n";
/* foreach through ntp servers and write out to ntpd.conf */
foreach (explode(' ', $config['system']['timeservers']) as $ts) {
$ntpcfg .= "server {$ts} iburst maxpoll 9";
- if (substr_count($config['ntpd']['prefer'], $ts)) $ntpcfg .= ' prefer';
- if (substr_count($config['ntpd']['noselect'], $ts)) $ntpcfg .= ' noselect';
+ if (substr_count($config['ntpd']['prefer'], $ts)) {
+ $ntpcfg .= ' prefer';
+ }
+ if (substr_count($config['ntpd']['noselect'], $ts)) {
+ $ntpcfg .= ' noselect';
+ }
$ntpcfg .= "\n";
}
unset($ts);
@@ -1689,41 +1823,41 @@ function system_ntp_configure($start_ntpd=true) {
/* Access restrictions */
$ntpcfg .= 'restrict default';
if (empty($config['ntpd']['kod'])) { /*note: this one works backwards */
- $ntpcfg .= ' kod limited';
+ $ntpcfg .= ' kod limited';
}
if (empty($config['ntpd']['nomodify'])) { /*note: this one works backwards */
- $ntpcfg .= ' nomodify';
+ $ntpcfg .= ' nomodify';
}
if (!empty($config['ntpd']['noquery'])) {
$ntpcfg .= ' noquery';
}
if (empty($config['ntpd']['nopeer'])) { /*note: this one works backwards */
- $ntpcfg .= ' nopeer';
+ $ntpcfg .= ' nopeer';
}
if (empty($config['ntpd']['notrap'])) { /*note: this one works backwards */
- $ntpcfg .= ' notrap';
+ $ntpcfg .= ' notrap';
}
if (!empty($config['ntpd']['noserve'])) {
$ntpcfg .= ' noserve';
}
$ntpcfg .= "\nrestrict -6 default";
if (empty($config['ntpd']['kod'])) { /*note: this one works backwards */
- $ntpcfg .= ' kod limited';
+ $ntpcfg .= ' kod limited';
}
if (empty($config['ntpd']['nomodify'])) { /*note: this one works backwards */
- $ntpcfg .= ' nomodify';
+ $ntpcfg .= ' nomodify';
}
if (!empty($config['ntpd']['noquery'])) {
$ntpcfg .= ' noquery';
}
if (empty($config['ntpd']['nopeer'])) { /*note: this one works backwards */
- $ntpcfg .= ' nopeer';
+ $ntpcfg .= ' nopeer';
}
if (!empty($config['ntpd']['noserve'])) {
$ntpcfg .= ' noserve';
}
if (empty($config['ntpd']['notrap'])) { /*note: this one works backwards */
- $ntpcfg .= ' notrap';
+ $ntpcfg .= ' notrap';
}
$ntpcfg .= "\n";
@@ -1734,15 +1868,17 @@ function system_ntp_configure($start_ntpd=true) {
file_put_contents('/var/db/leap-seconds', $leapsec);
$ntpcfg .= "leapfile /var/db/leap-seconds\n";
}
-
+
if (empty($config['ntpd']['interface'])) {
- if (is_array($config['installedpackages']['openntpd']) && !empty($config['installedpackages']['openntpd']['config'][0]['interface']))
+ if (is_array($config['installedpackages']['openntpd']) && !empty($config['installedpackages']['openntpd']['config'][0]['interface'])) {
$interfaces = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
- else
+ } else {
$interfaces = array();
- } else
+ }
+ } else {
$interfaces = explode(",", $config['ntpd']['interface']);
+ }
if (is_array($interfaces) && count($interfaces)) {
$ntpcfg .= "interface ignore all\n";
@@ -1750,8 +1886,9 @@ function system_ntp_configure($start_ntpd=true) {
if (!is_ipaddr($interface)) {
$interface = get_real_interface($interface);
}
- if (!empty($interface))
+ if (!empty($interface)) {
$ntpcfg .= "interface listen {$interface}\n";
+ }
}
}
@@ -1762,8 +1899,9 @@ function system_ntp_configure($start_ntpd=true) {
}
/* At bootup we just want to write out the config. */
- if (!$start_ntpd)
+ if (!$start_ntpd) {
return;
+ }
/* if ntpd is running, kill it */
while (isvalidpid("{$g['varrun_path']}/ntpd.pid")) {
@@ -1772,12 +1910,13 @@ function system_ntp_configure($start_ntpd=true) {
@unlink("{$g['varrun_path']}/ntpd.pid");
/* if /var/empty does not exist, create it */
- if(!is_dir("/var/empty"))
+ if (!is_dir("/var/empty")) {
mkdir("/var/empty", 0775, true);
+ }
/* start opentpd, set time now and use /var/etc/ntpd.conf */
mwexec("/usr/local/sbin/ntpd -g -c {$g['varetc_path']}/ntpd.conf -p {$g['varrun_path']}/ntpd.pid", false, true);
-
+
// Note that we are starting up
log_error("NTPD is starting up.");
return;
@@ -1786,17 +1925,19 @@ function system_ntp_configure($start_ntpd=true) {
function sync_system_time() {
global $config, $g;
- if (platform_booting())
+ if (platform_booting()) {
echo gettext("Syncing system time before startup...");
+ }
/* foreach through servers and write out to ntpd.conf */
foreach (explode(' ', $config['system']['timeservers']) as $ts) {
mwexec("/usr/local/sbin/ntpdate -s $ts");
}
-
- if (platform_booting())
+
+ if (platform_booting()) {
echo gettext("done.") . "\n";
-
+ }
+
}
function system_halt() {
@@ -1842,15 +1983,16 @@ function system_reboot_cleanup() {
function system_do_shell_commands($early = 0) {
global $config, $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_do_shell_commands() being called $mt\n";
}
- if ($early)
+ if ($early) {
$cmdn = "earlyshellcmd";
- else
+ } else {
$cmdn = "shellcmd";
+ }
if (is_array($config['system'][$cmdn])) {
@@ -1859,7 +2001,7 @@ function system_do_shell_commands($early = 0) {
exec($cmd);
}
- } elseif($config['system'][$cmdn] <> "") {
+ } elseif ($config['system'][$cmdn] <> "") {
/* execute single item */
exec($config['system'][$cmdn]);
@@ -1869,7 +2011,7 @@ function system_do_shell_commands($early = 0) {
function system_console_configure() {
global $config, $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_console_configure() being called $mt\n";
}
@@ -1883,7 +2025,7 @@ function system_console_configure() {
function system_dmesg_save() {
global $g;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_dmesg_save() being called $mt\n";
}
@@ -1895,8 +2037,9 @@ function system_dmesg_save() {
$lastcpline = 0;
for ($i = 0; $i < count($dmesg); $i++) {
- if (strstr($dmesg[$i], "Copyright (c) 1992-"))
+ if (strstr($dmesg[$i], "Copyright (c) 1992-")) {
$lastcpline = $i;
+ }
}
$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
@@ -1905,8 +2048,9 @@ function system_dmesg_save() {
return 1;
}
- for ($i = $lastcpline; $i < count($dmesg); $i++)
+ for ($i = $lastcpline; $i < count($dmesg); $i++) {
fwrite($fd, $dmesg[$i] . "\n");
+ }
fclose($fd);
unset($dmesg);
@@ -1916,7 +2060,7 @@ function system_dmesg_save() {
function system_set_harddisk_standby() {
global $g, $config;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_set_harddisk_standby() being called $mt\n";
}
@@ -1948,12 +2092,12 @@ function system_set_harddisk_standby() {
function system_setup_sysctl() {
global $config;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_setup_sysctl() being called $mt\n";
}
- activate_sysctls();
+ activate_sysctls();
if (isset($config['system']['sharednet'])) {
system_disable_arp_wrong_if();
@@ -1962,7 +2106,7 @@ function system_setup_sysctl() {
function system_disable_arp_wrong_if() {
global $config;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_disable_arp_wrong_if() being called $mt\n";
}
@@ -1974,7 +2118,7 @@ function system_disable_arp_wrong_if() {
function system_enable_arp_wrong_if() {
global $config;
- if(isset($config['system']['developerspew'])) {
+ if (isset($config['system']['developerspew'])) {
$mt = microtime();
echo "system_enable_arp_wrong_if() being called $mt\n";
}
@@ -1990,14 +2134,15 @@ function enable_watchdog() {
$install_watchdog = false;
$supported_watchdogs = array("Geode");
$file = file_get_contents("/var/log/dmesg.boot");
- foreach($supported_watchdogs as $sd) {
- if(stristr($file, "Geode")) {
+ foreach ($supported_watchdogs as $sd) {
+ if (stristr($file, "Geode")) {
$install_watchdog = true;
}
}
- if($install_watchdog == true) {
- if(is_process_running("watchdogd"))
+ if ($install_watchdog == true) {
+ if (is_process_running("watchdogd")) {
mwexec("/usr/bin/killall watchdogd", true);
+ }
exec("/usr/sbin/watchdogd");
}
}
@@ -2008,20 +2153,20 @@ function system_check_reset_button() {
$specplatform = system_identify_specific_platform();
switch ($specplatform['name']) {
- case 'alix':
- case 'wrap':
- case 'FW7541':
- case 'APU':
- case 'C2358':
- break;
- default:
- return 0;
+ case 'alix':
+ case 'wrap':
+ case 'FW7541':
+ case 'APU':
+ case 'C2358':
+ break;
+ default:
+ return 0;
}
$retval = mwexec("/usr/local/sbin/" . $specplatform['name'] . "resetbtn");
if ($retval == 99) {
- /* user has pressed reset button for 2 seconds -
+ /* user has pressed reset button for 2 seconds -
reset to factory defaults */
echo <<<EOD
@@ -2032,7 +2177,7 @@ function system_check_reset_button() {
EOD;
-
+
reset_factory_defaults();
system_reboot_sync();
exit(0);
@@ -2048,54 +2193,63 @@ EOD;
*/
function system_identify_specific_platform() {
global $g;
-
- if ($g['platform'] == 'generic-pc')
+
+ if ($g['platform'] == 'generic-pc') {
return array('name' => 'generic-pc', 'descr' => gettext("Generic PC"));
-
- if ($g['platform'] == 'generic-pc-cdrom')
+ }
+
+ if ($g['platform'] == 'generic-pc-cdrom') {
return array('name' => 'generic-pc-cdrom', 'descr' => gettext("Generic PC (CD-ROM)"));
-
+ }
+
/* Try to guess from smbios strings */
unset($output);
$_gb = exec('/bin/kenv smbios.system.product 2>/dev/null', $output);
switch ($output[0]) {
- case 'FW7541':
- return (array('name' => 'FW7541', 'descr' => 'Netgate FW7541'));
- break;
- case 'APU':
- return (array('name' => 'APU', 'descr' => 'Netgate APU'));
- break;
- case 'RCC-VE':
- return (array('name' => 'C2358', 'descr' => 'Netgate C2358'));
- break;
+ case 'FW7541':
+ return (array('name' => 'FW7541', 'descr' => 'Netgate FW7541'));
+ break;
+ case 'APU':
+ return (array('name' => 'APU', 'descr' => 'Netgate APU'));
+ break;
+ case 'RCC-VE':
+ return (array('name' => 'C2358', 'descr' => 'Netgate C2358'));
+ break;
}
/* the rest of the code only deals with 'embedded' platforms */
- if ($g['platform'] != 'nanobsd')
+ if ($g['platform'] != 'nanobsd') {
return array('name' => $g['platform'], 'descr' => $g['platform']);
+ }
$dmesg = get_single_sysctl('hw.model');
- if (strpos($dmesg, "PC Engines WRAP") !== false)
+ if (strpos($dmesg, "PC Engines WRAP") !== false) {
return array('name' => 'wrap', 'descr' => gettext('PC Engines WRAP'));
-
- if (strpos($dmesg, "PC Engines ALIX") !== false)
+ }
+
+ if (strpos($dmesg, "PC Engines ALIX") !== false) {
return array('name' => 'alix', 'descr' => gettext('PC Engines ALIX'));
+ }
- if (preg_match("/Soekris net45../", $dmesg, $matches))
+ if (preg_match("/Soekris net45../", $dmesg, $matches)) {
return array('name' => 'net45xx', 'descr' => $matches[0]);
-
- if (preg_match("/Soekris net48../", $dmesg, $matches))
+ }
+
+ if (preg_match("/Soekris net48../", $dmesg, $matches)) {
return array('name' => 'net48xx', 'descr' => $matches[0]);
-
- if (preg_match("/Soekris net55../", $dmesg, $matches))
+ }
+
+ if (preg_match("/Soekris net55../", $dmesg, $matches)) {
return array('name' => 'net55xx', 'descr' => $matches[0]);
+ }
unset($dmesg);
$dmesg_boot = system_get_dmesg_boot();
- if (strpos($dmesg_boot, "PC Engines ALIX") !== false)
+ if (strpos($dmesg_boot, "PC Engines ALIX") !== false) {
return array('name' => 'alix', 'descr' => gettext('PC Engines ALIX'));
+ }
unset($dmesg_boot);
/* unknown embedded platform */
@@ -2104,7 +2258,7 @@ function system_identify_specific_platform() {
function system_get_dmesg_boot() {
global $g;
-
+
return file_get_contents("{$g['varlog_path']}/dmesg.boot");
}
OpenPOWER on IntegriCloud