summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2015-03-03 00:39:50 +0545
committerPhil Davis <phil.davis@inf.org>2015-03-03 00:39:50 +0545
commit751533a2c8ee81b8db7a8435da1c321135b427f9 (patch)
tree5c913d06429787410fd2f84a8288ebe17f1fbc90 /etc
parent8f5f40c9fca0bfb637589b4c86e53bfb80753c87 (diff)
downloadpfsense-751533a2c8ee81b8db7a8435da1c321135b427f9.zip
pfsense-751533a2c8ee81b8db7a8435da1c321135b427f9.tar.gz
Code style etc inc u
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/unbound.inc189
-rw-r--r--etc/inc/upgrade_config.inc992
-rw-r--r--etc/inc/util.inc709
-rw-r--r--etc/inc/uuid.php8
4 files changed, 1126 insertions, 772 deletions
diff --git a/etc/inc/unbound.inc b/etc/inc/unbound.inc
index bbe8027..bef0f4a 100644
--- a/etc/inc/unbound.inc
+++ b/etc/inc/unbound.inc
@@ -55,7 +55,7 @@ function unbound_optimization() {
$optimization_settings = array();
- /*
+ /*
* Set the number of threads equal to number of CPUs.
* Use 1 to disable threading, if for some reason this sysctl fails.
*/
@@ -95,8 +95,9 @@ function unbound_optimization() {
}
}
// Safety check in case kern.ipc.maxsockbuf is not available.
- if (!isset($optimization['so_rcvbuf']))
+ if (!isset($optimization['so_rcvbuf'])) {
$optimization['so_rcvbuf'] = "#so-rcvbuf: 4m";
+ }
return $optimization;
@@ -112,8 +113,9 @@ function unbound_generate_config() {
if (isset($config['unbound']['dnssec'])) {
$module_config = "validator iterator";
$anchor_file = "auto-trust-anchor-file: {$g['unbound_chroot_path']}/root.key";
- } else
+ } else {
$module_config = "iterator";
+ }
// Setup DNS Rebinding
if (!isset($config['system']['webgui']['nodnsrebindcheck'])) {
@@ -138,19 +140,22 @@ EOF;
$bindints .= "interface: ::0\n";
$bindints .= "interface-automatic: yes\n";
} else {
- foreach($active_interfaces as $ubif) {
+ foreach ($active_interfaces as $ubif) {
if (is_ipaddr($ubif)) {
- //$bindints .= "interface: $ubif\n"; -- until redmine #4062 is fixed, then uncomment this.
+ //$bindints .= "interface: $ubif\n"; -- until redmine #4062 is fixed, then uncomment this.
} else {
$intip = get_interface_ip($ubif);
- if (is_ipaddrv4($intip))
+ if (is_ipaddrv4($intip)) {
$bindints .= "interface: $intip\n";
+ }
$intip = get_interface_ipv6($ubif);
- if (is_ipaddrv6($intip))
- if (!is_linklocal($intip)) // skipping link local for the moment to not break people's configs: https://redmine.pfsense.org/issues/4062
+ if (is_ipaddrv6($intip)) {
+ if (!is_linklocal($intip)) { // skipping link local for the moment to not break people's configs: https://redmine.pfsense.org/issues/4062
$bindints .= "interface: $intip\n";
+ }
+ }
}
- }
+ }
}
} else {
$bindints .= "interface: 0.0.0.0\n";
@@ -162,13 +167,15 @@ EOF;
if (!empty($config['unbound']['outgoing_interface'])) {
$outgoingints = "# Outgoing interfaces to be used\n";
$outgoing_interfaces = explode(",", $config['unbound']['outgoing_interface']);
- foreach($outgoing_interfaces as $outif) {
+ foreach ($outgoing_interfaces as $outif) {
$outip = get_interface_ip($outif);
- if (!is_null($outip))
+ if (!is_null($outip)) {
$outgoingints .= "outgoing-interface: $outip\n";
+ }
$outip = get_interface_ipv6($outif);
- if (!is_null($outip))
+ if (!is_null($outip)) {
$outgoingints .= "outgoing-interface: $outip\n";
+ }
}
}
@@ -197,8 +204,9 @@ EOF;
if ($config['unbound']['custom_options']) {
$custom_options_source = explode("\n", base64_decode($config['unbound']['custom_options']));
$custom_options = "# Unbound custom options\n";
- foreach ($custom_options_source as $ent)
+ foreach ($custom_options_source as $ent) {
$custom_options .= $ent."\n";
+ }
}
// Server configuration variables
@@ -219,8 +227,9 @@ EOF;
$infra_host_ttl = (!empty($config['unbound']['infra_host_ttl'])) ? $config['unbound']['infra_host_ttl'] : "900";
$infra_cache_numhosts = (!empty($config['unbound']['infra_cache_numhosts'])) ? $config['unbound']['infra_cache_numhosts'] : "10000";
$unwanted_reply_threshold = (!empty($config['unbound']['unwanted_reply_threshold'])) ? $config['unbound']['unwanted_reply_threshold'] : "0";
- if ($unwanted_reply_threshold == "disabled")
+ if ($unwanted_reply_threshold == "disabled") {
$unwanted_reply_threshold = "0";
+ }
$msg_cache_size = (!empty($config['unbound']['msgcachesize'])) ? $config['unbound']['msgcachesize'] : "4";
$verbosity = isset($config['unbound']['log_verbosity']) ? $config['unbound']['log_verbosity'] : 1;
$use_caps = isset($config['unbound']['use_caps']) ? "yes" : "no";
@@ -230,15 +239,17 @@ EOF;
$dnsservers = array();
if (isset($config['system']['dnsallowoverride'])) {
$ns = array_unique(get_nameservers());
- foreach($ns as $nameserver) {
- if ($nameserver)
+ foreach ($ns as $nameserver) {
+ if ($nameserver) {
$dnsservers[] = $nameserver;
+ }
}
} else {
$ns = array_unique(get_dns_servers());
- foreach($ns as $nameserver) {
- if ($nameserver)
+ foreach ($ns as $nameserver) {
+ if ($nameserver) {
$dnsservers[] = $nameserver;
+ }
}
}
@@ -249,11 +260,13 @@ forward-zone:
name: "."
EOD;
- foreach($dnsservers as $dnsserver)
+ foreach ($dnsservers as $dnsserver) {
$forward_conf .= "\tforward-addr: $dnsserver\n";
+ }
}
- } else
+ } else {
$forward_conf = "";
+ }
// Size of the RRset cache == 2 * msg-cache-size per Unbound's recommendations
$rrset_cache_size = $msg_cache_size * 2;
@@ -380,19 +393,22 @@ function read_hosts() {
*/
$etc_hosts = array();
foreach (file('/etc/hosts') as $line) {
- if (strpos($line, "dhcpleases automatically entered"))
+ if (strpos($line, "dhcpleases automatically entered")) {
break;
+ }
$d = preg_split('/\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
- if (empty($d) || substr(reset($d), 0, 1) == "#")
+ if (empty($d) || substr(reset($d), 0, 1) == "#") {
continue;
+ }
$ip = array_shift($d);
$fqdn = array_shift($d);
$name = array_shift($d);
if (!empty($fqdn) && $fqdn != "empty") {
- if (!empty($name) && $name != "empty")
+ if (!empty($name) && $name != "empty") {
array_push($etc_hosts, array(ipaddr => "$ip", fqdn => "$fqdn", name => "$name"));
- else
+ } else {
array_push($etc_hosts, array(ipaddr => "$ip", fqdn => "$fqdn"));
+ }
}
}
return $etc_hosts;
@@ -409,26 +425,31 @@ function sync_unbound_service() {
unbound_generate_config();
do_as_unbound_user("start");
require_once("service-utils.inc");
- if (is_service_running("unbound"))
+ if (is_service_running("unbound")) {
do_as_unbound_user("restore_cache");
+ }
}
function unbound_acl_id_used($id) {
global $config;
- if (is_array($config['unbound']['acls']))
- foreach($config['unbound']['acls'] as & $acls)
- if ($id == $acls['aclid'])
+ if (is_array($config['unbound']['acls'])) {
+ foreach ($config['unbound']['acls'] as & $acls) {
+ if ($id == $acls['aclid']) {
return true;
+ }
+ }
+ }
return false;
}
function unbound_get_next_id() {
$aclid = 0;
- while(unbound_acl_id_used($aclid))
+ while (unbound_acl_id_used($aclid)) {
$aclid++;
+ }
return $aclid;
}
@@ -437,23 +458,23 @@ function do_as_unbound_user($cmd) {
global $g;
switch ($cmd) {
- case "start":
- mwexec("/usr/local/sbin/unbound -c {$g['unbound_chroot_path']}/unbound.conf");
- break;
- case "stop":
- mwexec("echo '/usr/local/sbin/unbound-control stop' | /usr/bin/su -m unbound", true);
- break;
- case "reload":
- mwexec("echo '/usr/local/sbin/unbound-control reload' | /usr/bin/su -m unbound", true);
- break;
- case "unbound-anchor":
- mwexec("echo '/usr/local/sbin/unbound-anchor -a {$g['unbound_chroot_path']}/root.key' | /usr/bin/su -m unbound", true);
- break;
- case "unbound-control-setup":
- mwexec("echo '/usr/local/sbin/unbound-control-setup -d {$g['unbound_chroot_path']}' | /usr/bin/su -m unbound", true);
- break;
- default:
- break;
+ case "start":
+ mwexec("/usr/local/sbin/unbound -c {$g['unbound_chroot_path']}/unbound.conf");
+ break;
+ case "stop":
+ mwexec("echo '/usr/local/sbin/unbound-control stop' | /usr/bin/su -m unbound", true);
+ break;
+ case "reload":
+ mwexec("echo '/usr/local/sbin/unbound-control reload' | /usr/bin/su -m unbound", true);
+ break;
+ case "unbound-anchor":
+ mwexec("echo '/usr/local/sbin/unbound-anchor -a {$g['unbound_chroot_path']}/root.key' | /usr/bin/su -m unbound", true);
+ break;
+ case "unbound-control-setup":
+ mwexec("echo '/usr/local/sbin/unbound-control-setup -d {$g['unbound_chroot_path']}' | /usr/bin/su -m unbound", true);
+ break;
+ default:
+ break;
}
}
@@ -464,16 +485,17 @@ function unbound_add_domain_overrides($pvt_rev="") {
$sorted_domains = msort($domains, "domain");
$result = array();
- foreach($sorted_domains as $domain) {
+ foreach ($sorted_domains as $domain) {
$domain_key = current($domain);
- if (!isset($result[$domain_key]))
+ if (!isset($result[$domain_key])) {
$result[$domain_key] = array();
+ }
$result[$domain_key][] = $domain['ip'];
}
// Domain overrides that have multiple entries need multiple stub-addr: added
$domain_entries = "";
- foreach($result as $domain=>$ips) {
+ foreach ($result as $domain=>$ips) {
if ($pvt_rev == "private") {
$domain_entries .= "private-domain: \"$domain\"\n";
$domain_entries .= "domain-insecure: \"$domain\"\n";
@@ -484,15 +506,16 @@ function unbound_add_domain_overrides($pvt_rev="") {
} else {
$domain_entries .= "stub-zone:\n";
$domain_entries .= "\tname: \"$domain\"\n";
- foreach($ips as $ip)
+ foreach ($ips as $ip) {
$domain_entries .= "\tstub-addr: $ip\n";
+ }
$domain_entries .= "\tstub-prime: no\n";
}
}
- if ($pvt_rev != "")
+ if ($pvt_rev != "") {
return $domain_entries;
- else {
+ } else {
create_unbound_chroot_path();
file_put_contents("{$g['unbound_chroot_path']}/domainoverrides.conf", $domain_entries);
}
@@ -506,20 +529,22 @@ function unbound_add_host_entries() {
$hosts = read_hosts();
$added_ptr = array();
foreach ($hosts as $host) {
- if (is_ipaddrv4($host['ipaddr']))
+ if (is_ipaddrv4($host['ipaddr'])) {
$type = 'A';
- else if (is_ipaddrv6($host['ipaddr']))
+ } else if (is_ipaddrv6($host['ipaddr'])) {
$type = 'AAAA';
- else
+ } else {
continue;
+ }
- if(!$added_ptr[$host['ipaddr']]) {
+ if (!$added_ptr[$host['ipaddr']]) {
$unbound_entries .= "local-data-ptr: \"{$host['ipaddr']} {$host['fqdn']}\"\n";
$added_ptr[$host['ipaddr']] = true;
}
$unbound_entries .= "local-data: \"{$host['fqdn']} {$type} {$host['ipaddr']}\"\n";
- if (isset($host['name']))
+ if (isset($host['name'])) {
$unbound_entries .= "local-data: \"{$host['name']} {$type} {$host['ipaddr']}\"\n";
+ }
}
// Write out entries
@@ -539,28 +564,33 @@ function unbound_control($action) {
case "start":
// Start Unbound
if ($config['unbound']['enable'] == "on") {
- if (!is_service_running("unbound"))
+ if (!is_service_running("unbound")) {
do_as_unbound_user("start");
+ }
}
break;
case "stop":
- if ($config['unbound']['enable'] == "on")
+ if ($config['unbound']['enable'] == "on") {
do_as_unbound_user("stop");
+ }
break;
case "reload":
- if ($config['unbound']['enable'] == "on")
+ if ($config['unbound']['enable'] == "on") {
do_as_unbound_user("reload");
+ }
break;
case "dump_cache":
// Dump Unbound's Cache
- if ($config['unbound']['dumpcache'] == "on")
+ if ($config['unbound']['dumpcache'] == "on") {
do_as_unbound_user("dump_cache");
+ }
break;
case "restore_cache":
// Restore Unbound's Cache
if ((is_service_running("unbound")) && ($config['unbound']['dumpcache'] == "on")) {
- if (file_exists($cache_dumpfile) && filesize($cache_dumpfile) > 0)
+ if (file_exists($cache_dumpfile) && filesize($cache_dumpfile) > 0) {
do_as_unbound_user("load_cache < /var/tmp/unbound_cache");
+ }
}
break;
default:
@@ -576,10 +606,11 @@ function unbound_statistics() {
if ($config['stats'] == "on") {
$stats_interval = $config['unbound']['stats_interval'];
$cumulative_stats = $config['cumulative_stats'];
- if ($config['extended_stats'] == "on")
+ if ($config['extended_stats'] == "on") {
$extended_stats = "yes";
- else
+ } else {
$extended_stats = "no";
+ }
} else {
$stats_interval = "0";
$cumulative_stats = "no";
@@ -607,13 +638,15 @@ function unbound_acls_config() {
// Add our networks for active interfaces including localhost
if (!empty($config['unbound']['active_interface'])) {
$active_interfaces = array_flip(explode(",", $config['unbound']['active_interface']));
- if (in_array("all", $active_interfaces))
+ if (in_array("all", $active_interfaces)) {
$active_interfaces = get_configured_interface_with_descr();
- } else
+ }
+ } else {
$active_interfaces = get_configured_interface_with_descr();
-
+ }
+
$bindints = "";
- foreach($active_interfaces as $ubif => $ifdesc) {
+ foreach ($active_interfaces as $ubif => $ifdesc) {
$ifip = get_interface_ip($ubif);
if (is_ipaddrv4($ifip)) {
// IPv4 is handled via NAT networks below
@@ -623,13 +656,14 @@ function unbound_acls_config() {
if (!is_linklocal($ifip)) {
$subnet_bits = get_interface_subnetv6($ubif);
$subnet_ip = gen_subnetv6($ifip, $subnet_bits);
- // only add LAN-type interfaces
- if (!interface_has_gateway($ubif))
+ // only add LAN-type interfaces
+ if (!interface_has_gateway($ubif)) {
$aclcfg .= "access-control: {$subnet_ip}/{$subnet_bits} allow\n";
+ }
}
// add for IPv6 static routes to local networks
// for safety, we include only routes reachable on an interface with no
- // gateway specified - read: not an Internet connection.
+ // gateway specified - read: not an Internet connection.
$static_routes = get_staticroutes();
foreach ($static_routes as $route) {
if ((lookup_gateway_interface_by_name($route['gateway']) == $ubif) && !interface_has_gateway($ubif)) {
@@ -639,7 +673,7 @@ function unbound_acls_config() {
}
}
}
-
+
// Generate IPv4 access-control entries using the same logic as automatic outbound NAT
if (empty($FilterIflist)) {
filter_generate_optcfg_array();
@@ -647,17 +681,18 @@ function unbound_acls_config() {
$natnetworks_array = array();
$natnetworks_array = filter_nat_rules_automatic_tonathosts();
foreach ($natnetworks_array as $allowednet) {
- $aclcfg .= "access-control: $allowednet allow \n";
- }
+ $aclcfg .= "access-control: $allowednet allow \n";
+ }
}
// Configure the custom ACLs
if (is_array($config['unbound']['acls'])) {
- foreach($config['unbound']['acls'] as $unbound_acl) {
+ foreach ($config['unbound']['acls'] as $unbound_acl) {
$aclcfg .= "#{$unbound_acl['aclname']}\n";
- foreach($unbound_acl['row'] as $network) {
- if ($unbound_acl['aclaction'] == "allow snoop")
+ foreach ($unbound_acl['row'] as $network) {
+ if ($unbound_acl['aclaction'] == "allow snoop") {
$unbound_acl['aclaction'] = "allow_snoop";
+ }
$aclcfg .= "access-control: {$network['acl_network']}/{$network['mask']} {$unbound_acl['aclaction']}\n";
}
}
diff --git a/etc/inc/upgrade_config.inc b/etc/inc/upgrade_config.inc
index be70d73..89bef33 100644
--- a/etc/inc/upgrade_config.inc
+++ b/etc/inc/upgrade_config.inc
@@ -35,8 +35,9 @@
pfSense_MODULE: config
*/
-if(!function_exists("dump_rrd_to_xml"))
+if (!function_exists("dump_rrd_to_xml")) {
require("rrd.inc");
+}
/* Upgrade functions must be named:
* upgrade_XXX_to_YYY
@@ -107,9 +108,9 @@ function upgrade_010_to_011() {
$fr = &$config['filter']['rule'][$i];
/* remap interface */
- if (array_key_exists($fr['interface'], $ifmap))
+ if (array_key_exists($fr['interface'], $ifmap)) {
$fr['interface'] = $ifmap[$fr['interface']];
- else {
+ } else {
/* remove the rule */
printf(gettext("%sWarning: filter rule removed " .
"(interface '%s' does not exist anymore)."), "\n", $fr['interface']);
@@ -119,9 +120,9 @@ function upgrade_010_to_011() {
/* remap source network */
if (isset($fr['source']['network'])) {
- if (array_key_exists($fr['source']['network'], $ifmap))
+ if (array_key_exists($fr['source']['network'], $ifmap)) {
$fr['source']['network'] = $ifmap[$fr['source']['network']];
- else {
+ } else {
/* remove the rule */
printf(gettext("%sWarning: filter rule removed " .
"(source network '%s' does not exist anymore)."), "\n", $fr['source']['network']);
@@ -132,9 +133,9 @@ function upgrade_010_to_011() {
/* remap destination network */
if (isset($fr['destination']['network'])) {
- if (array_key_exists($fr['destination']['network'], $ifmap))
+ if (array_key_exists($fr['destination']['network'], $ifmap)) {
$fr['destination']['network'] = $ifmap[$fr['destination']['network']];
- else {
+ } else {
/* remove the rule */
printf(gettext("%sWarning: filter rule removed " .
"(destination network '%s' does not exist anymore)."), "\n", $fr['destination']['network']);
@@ -146,45 +147,46 @@ function upgrade_010_to_011() {
/* convert shaper rules */
$n = count($config['pfqueueing']['rule']);
- if (is_array($config['pfqueueing']['rule']))
- for ($i = 0; $i < $n; $i++) {
-
- $fr = &$config['pfqueueing']['rule'][$i];
+ if (is_array($config['pfqueueing']['rule'])) {
+ for ($i = 0; $i < $n; $i++) {
- /* remap interface */
- if (array_key_exists($fr['interface'], $ifmap))
- $fr['interface'] = $ifmap[$fr['interface']];
- else {
- /* remove the rule */
- printf(gettext("%sWarning: traffic shaper rule removed " .
- "(interface '%s' does not exist anymore)."), "\n", $fr['interface']);
- unset($config['pfqueueing']['rule'][$i]);
- continue;
- }
+ $fr = &$config['pfqueueing']['rule'][$i];
- /* remap source network */
- if (isset($fr['source']['network'])) {
- if (array_key_exists($fr['source']['network'], $ifmap))
- $fr['source']['network'] = $ifmap[$fr['source']['network']];
- else {
+ /* remap interface */
+ if (array_key_exists($fr['interface'], $ifmap)) {
+ $fr['interface'] = $ifmap[$fr['interface']];
+ } else {
/* remove the rule */
printf(gettext("%sWarning: traffic shaper rule removed " .
- "(source network '%s' does not exist anymore)."), "\n", $fr['source']['network']);
+ "(interface '%s' does not exist anymore)."), "\n", $fr['interface']);
unset($config['pfqueueing']['rule'][$i]);
continue;
}
- }
- /* remap destination network */
- if (isset($fr['destination']['network'])) {
- if (array_key_exists($fr['destination']['network'], $ifmap))
- $fr['destination']['network'] = $ifmap[$fr['destination']['network']];
- else {
- /* remove the rule */
- printf(gettext("%sWarning: traffic shaper rule removed " .
- "(destination network '%s' does not exist anymore)."), "\n", $fr['destination']['network']);
- unset($config['pfqueueing']['rule'][$i]);
- continue;
+ /* remap source network */
+ if (isset($fr['source']['network'])) {
+ if (array_key_exists($fr['source']['network'], $ifmap)) {
+ $fr['source']['network'] = $ifmap[$fr['source']['network']];
+ } else {
+ /* remove the rule */
+ printf(gettext("%sWarning: traffic shaper rule removed " .
+ "(source network '%s' does not exist anymore)."), "\n", $fr['source']['network']);
+ unset($config['pfqueueing']['rule'][$i]);
+ continue;
+ }
+ }
+
+ /* remap destination network */
+ if (isset($fr['destination']['network'])) {
+ if (array_key_exists($fr['destination']['network'], $ifmap)) {
+ $fr['destination']['network'] = $ifmap[$fr['destination']['network']];
+ } else {
+ /* remove the rule */
+ printf(gettext("%sWarning: traffic shaper rule removed " .
+ "(destination network '%s' does not exist anymore)."), "\n", $fr['destination']['network']);
+ unset($config['pfqueueing']['rule'][$i]);
+ continue;
+ }
}
}
}
@@ -252,20 +254,25 @@ function upgrade_013_to_014() {
function upgrade_014_to_015() {
global $config;
/* Default route moved */
- if (isset($config['interfaces']['wan']['gateway']))
- if ($config['interfaces']['wan']['gateway'] <> "")
+ if (isset($config['interfaces']['wan']['gateway'])) {
+ if ($config['interfaces']['wan']['gateway'] <> "") {
$config['system']['gateway'] = $config['interfaces']['wan']['gateway'];
+ }
+ }
unset($config['interfaces']['wan']['gateway']);
/* Queues are no longer interface specific */
- if (isset($config['interfaces']['lan']['schedulertype']))
+ if (isset($config['interfaces']['lan']['schedulertype'])) {
unset($config['interfaces']['lan']['schedulertype']);
- if (isset($config['interfaces']['wan']['schedulertype']))
+ }
+ if (isset($config['interfaces']['wan']['schedulertype'])) {
unset($config['interfaces']['wan']['schedulertype']);
+ }
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
- if(isset($config['interfaces']['opt' . $i]['schedulertype']))
+ if (isset($config['interfaces']['opt' . $i]['schedulertype'])) {
unset($config['interfaces']['opt' . $i]['schedulertype']);
+ }
}
}
@@ -300,9 +307,9 @@ function upgrade_016_to_017() {
function upgrade_017_to_018() {
global $config;
- if(isset($config['proxyarp']) && is_array($config['proxyarp']['proxyarpnet'])) {
+ if (isset($config['proxyarp']) && is_array($config['proxyarp']['proxyarpnet'])) {
$proxyarp = &$config['proxyarp']['proxyarpnet'];
- foreach($proxyarp as $arpent){
+ foreach ($proxyarp as $arpent) {
$vip = array();
$vip['mode'] = "proxyarp";
$vip['interface'] = $arpent['interface'];
@@ -325,9 +332,9 @@ function upgrade_017_to_018() {
}
unset($config['proxyarp']);
}
- if(isset($config['installedpackages']) && isset($config['installedpackages']['carp']) && is_array($config['installedpackages']['carp']['config'])) {
+ if (isset($config['installedpackages']) && isset($config['installedpackages']['carp']) && is_array($config['installedpackages']['carp']['config'])) {
$carp = &$config['installedpackages']['carp']['config'];
- foreach($carp as $carpent){
+ foreach ($carp as $carpent) {
$vip = array();
$vip['mode'] = "carp";
$vip['interface'] = "AUTO";
@@ -360,7 +367,7 @@ function upgrade_018_to_019() {
function upgrade_019_to_020() {
global $config;
- if(is_array($config['ipsec']['tunnel'])) {
+ if (is_array($config['ipsec']['tunnel'])) {
reset($config['ipsec']['tunnel']);
while (list($index, $tunnel) = each($config['ipsec']['tunnel'])) {
/* Sanity check on required variables */
@@ -375,7 +382,7 @@ function upgrade_019_to_020() {
function upgrade_020_to_021() {
global $config;
/* shaper scheduler moved */
- if(isset($config['system']['schedulertype'])) {
+ if (isset($config['system']['schedulertype'])) {
$config['shaper']['schedulertype'] = $config['system']['schedulertype'];
unset($config['system']['schedulertype']);
}
@@ -390,7 +397,7 @@ function upgrade_021_to_022() {
function upgrade_022_to_023() {
global $config;
- if(isset($config['shaper'])) {
+ if (isset($config['shaper'])) {
/* wipe previous shaper configuration */
unset($config['shaper']);
}
@@ -627,7 +634,7 @@ function upgrade_039_to_040() {
function upgrade_040_to_041() {
global $config;
- if(!$config['sysctl']) {
+ if (!$config['sysctl']) {
$config['sysctl']['item'] = array();
$config['sysctl']['item'][0]['tunable'] = "net.inet.tcp.blackhole";
@@ -720,10 +727,12 @@ function upgrade_040_to_041() {
function upgrade_041_to_042() {
global $config;
- if (isset($config['shaper']))
+ if (isset($config['shaper'])) {
unset($config['shaper']);
- if (isset($config['ezshaper']))
+ }
+ if (isset($config['ezshaper'])) {
unset($config['ezshaper']);
+ }
}
@@ -733,12 +742,12 @@ function upgrade_042_to_043() {
$iflist = get_configured_interface_list(false, true);
$gateways = array();
$i = 0;
- foreach($iflist as $ifname => $interface) {
- if(! interface_has_gateway($ifname)) {
+ foreach ($iflist as $ifname => $interface) {
+ if (! interface_has_gateway($ifname)) {
continue;
}
$config['gateways']['gateway_item'][$i] = array();
- if(is_ipaddr($config['interfaces'][$ifname]['gateway'])) {
+ if (is_ipaddr($config['interfaces'][$ifname]['gateway'])) {
$config['gateways']['gateway_item'][$i]['gateway'] = $config['interfaces'][$ifname]['gateway'];
$config['gateways']['gateway_item'][$i]['descr'] = sprintf(gettext("Interface %s Static Gateway"), $ifname);
} else {
@@ -748,10 +757,10 @@ function upgrade_042_to_043() {
$config['gateways']['gateway_item'][$i]['interface'] = $ifname;
$config['gateways']['gateway_item'][$i]['name'] = "GW_" . strtoupper($ifname);
/* add default gateway bit for wan on upgrade */
- if($ifname == "wan") {
+ if ($ifname == "wan") {
$config['gateways']['gateway_item'][$i]['defaultgw'] = true;
}
- if(is_ipaddr($config['interfaces'][$ifname]['use_rrd_gateway'])) {
+ if (is_ipaddr($config['interfaces'][$ifname]['use_rrd_gateway'])) {
$config['gateways']['gateway_item'][$i]['monitor'] = $config['interfaces'][$ifname]['use_rrd_gateway'];
unset($config['interfaces'][$ifname]['use_rrd_gateway']);
}
@@ -759,12 +768,13 @@ function upgrade_042_to_043() {
/* Update all filter rules which might reference this gateway */
$j = 0;
- foreach($config['filter']['rule'] as $rule) {
- if(is_ipaddr($rule['gateway'])) {
- if ($rule['gateway'] == $config['gateways']['gateway_item'][$i]['gateway'])
+ foreach ($config['filter']['rule'] as $rule) {
+ if (is_ipaddr($rule['gateway'])) {
+ if ($rule['gateway'] == $config['gateways']['gateway_item'][$i]['gateway']) {
$config['filter']['rule'][$j]['gateway'] = $config['gateways']['gateway_item'][$i]['name'];
- else if ($rule['gateway'] == $ifname)
+ } else if ($rule['gateway'] == $ifname) {
$config['filter']['rule'][$j]['gateway'] = $config['gateways']['gateway_item'][$i]['name'];
+ }
}
$j++;
}
@@ -772,7 +782,7 @@ function upgrade_042_to_043() {
/* rename old Quality RRD files in the process */
$rrddbpath = "/var/db/rrd";
$gwname = "GW_" . strtoupper($ifname);
- if(is_readable("{$rrddbpath}/{$ifname}-quality.rrd")) {
+ if (is_readable("{$rrddbpath}/{$ifname}-quality.rrd")) {
rename("{$rrddbpath}/{$ifname}-quality.rrd", "{$rrddbpath}/{$gwname}-quality.rrd");
}
$i++;
@@ -797,7 +807,7 @@ function upgrade_043_to_044() {
break;
}
}
- if($gwmap[$sroute['gateway']]) {
+ if ($gwmap[$sroute['gateway']]) {
/* We already added a gateway name for this IP */
$config['staticroutes']['route'][$idx]['gateway'] = "{$gwmap[$sroute['gateway']]}";
$found = true;
@@ -810,8 +820,9 @@ function upgrade_043_to_044() {
$gateway['gateway'] = $sroute['gateway'];
$gateway['interface'] = $sroute['interface'];
$gateway['descr'] = sprintf(gettext("Upgraded static route for %s"), $sroute['network']);
- if (!is_array($config['gateways']['gateway_item']))
+ if (!is_array($config['gateways']['gateway_item'])) {
$config['gateways']['gateway_item'] = array();
+ }
$config['gateways']['gateway_item'][] = $gateway;
$config['staticroutes']['route'][$idx]['gateway'] = $gateway['name'];
$i++;
@@ -829,8 +840,8 @@ function upgrade_044_to_045() {
foreach ($config['vlans']['vlan'] as $id => $vlan) {
/* Make sure to update the interfaces section with the right name */
$vlan_name = "{$vlan['if']}_vlan{$vlan['tag']}";
- foreach($iflist as $ifname) {
- if($config['interfaces'][$ifname]['if'] == "vlan{$i}") {
+ foreach ($iflist as $ifname) {
+ if ($config['interfaces'][$ifname]['if'] == "vlan{$i}") {
$config['interfaces'][$ifname]['if'] = $vlan_name;
continue;
}
@@ -847,39 +858,39 @@ function upgrade_045_to_046() {
/* Load up monitors that are in the default config for 2.0 but not in 1.2.3
thus wouldn't be in an upgraded config. */
$config['load_balancer']['monitor_type'] = array (
- array ( 'name' => 'ICMP',
+ array ('name' => 'ICMP',
'type' => 'icmp',
'descr' => 'ICMP',
'options' => '',
),
- array ( 'name' => 'TCP',
+ array ('name' => 'TCP',
'type' => 'tcp',
'descr' => 'Generic TCP',
'options' => '',
),
- array ( 'name' => 'HTTP',
+ array ('name' => 'HTTP',
'type' => 'http',
'descr' => 'Generic HTTP',
'options' =>
- array ( 'path' => '/',
+ array ('path' => '/',
'host' => '',
'code' => '200',
),
),
- array ( 'name' => 'HTTPS',
+ array ('name' => 'HTTPS',
'type' => 'https',
'descr' => 'Generic HTTPS',
'options' =>
- array ( 'path' => '/',
+ array ('path' => '/',
'host' => '',
'code' => '200',
),
),
- array ( 'name' => 'SMTP',
+ array ('name' => 'SMTP',
'type' => 'send',
'descr' => 'Generic SMTP',
'options' =>
- array ( 'send' => '',
+ array ('send' => '',
'expect' => '220 *',
),
),
@@ -890,9 +901,9 @@ function upgrade_045_to_046() {
$pool_a = &$config['load_balancer']['lbpool'];
$pools = array();
/* Index pools by name */
- if(is_array($pool_a)) {
+ if (is_array($pool_a)) {
for ($i = 0; isset($pool_a[$i]); $i++) {
- if($pool_a[$i]['type'] == "server") {
+ if ($pool_a[$i]['type'] == "server") {
$pools[$pool_a[$i]['name']] = $pool_a[$i];
}
}
@@ -907,8 +918,9 @@ function upgrade_045_to_046() {
$pool['behaviour'] = 'balance';
$pool['name'] = "{$vs_a[$i]['name']}-sitedown";
$pool['descr'] = sprintf(gettext("Sitedown pool for VS: %s"), $vs_a[$i]['name']);
- if (is_array($vs_a[$i]['pool']))
+ if (is_array($vs_a[$i]['pool'])) {
$vs_a[$i]['pool'] = $vs_a[$i]['pool'][0];
+ }
$pool['port'] = $pools[$vs_a[$i]['pool']]['port'];
$pool['servers'] = array();
$pool['servers'][] = $vs_a[$i]['sitedown'];
@@ -918,7 +930,7 @@ function upgrade_045_to_046() {
}
}
}
- if(count($config['load_balancer']) == 0) {
+ if (count($config['load_balancer']) == 0) {
unset($config['load_balancer']);
}
mwexec('/usr/sbin/pw groupadd -n _relayd -g 913');
@@ -930,7 +942,7 @@ function upgrade_046_to_047() {
global $config;
/* Upgrade IPsec from tunnel to phase1/phase2 */
- if(is_array($config['ipsec']['tunnel'])) {
+ if (is_array($config['ipsec']['tunnel'])) {
$a_phase1 = array();
$a_phase2 = array();
@@ -960,7 +972,7 @@ function upgrade_046_to_047() {
/* none found, create a new one */
- if (!isset( $ph1ent )) {
+ if (!isset($ph1ent)) {
/* build new phase1 entry */
@@ -968,11 +980,12 @@ function upgrade_046_to_047() {
$ph1ent['ikeid'] = ++$ikeid;
- if (isset($tunnel['disabled']))
+ if (isset($tunnel['disabled'])) {
$ph1ent['disabled'] = $tunnel['disabled'];
+ }
/* convert to the new vip[$vhid] name */
- if(preg_match("/^carp/", $tunnel['interface'])) {
+ if (preg_match("/^carp/", $tunnel['interface'])) {
$carpid = str_replace("carp", "", $tunnel['interface']);
$tunnel['interface'] = "vip" . $config['virtualip']['vip'][$carpid]['vhid'];
}
@@ -982,8 +995,9 @@ function upgrade_046_to_047() {
$ph1ent['mode'] = $tunnel['p1']['mode'];
- if (isset($tunnel['p1']['myident']['myaddress']))
+ if (isset($tunnel['p1']['myident']['myaddress'])) {
$ph1ent['myid_type'] = "myaddress";
+ }
if (isset($tunnel['p1']['myident']['address'])) {
$ph1ent['myid_type'] = "address";
$ph1ent['myid_data'] = $tunnel['p1']['myident']['address'];
@@ -1009,24 +1023,24 @@ function upgrade_046_to_047() {
switch ($tunnel['p1']['encryption-algorithm']) {
case "des":
- $ph1alg = array( 'name' => 'des' );
- break;
+ $ph1alg = array('name' => 'des');
+ break;
case "3des":
- $ph1alg = array( 'name' => '3des' );
- break;
+ $ph1alg = array('name' => '3des');
+ break;
case "blowfish":
- $ph1alg = array( 'name' => 'blowfish', 'keylen' => '128' );
- break;
+ $ph1alg = array('name' => 'blowfish', 'keylen' => '128');
+ break;
case "cast128":
- $ph1alg = array( 'name' => 'cast128' );
- break;
+ $ph1alg = array('name' => 'cast128');
+ break;
case "rijndael":
- $ph1alg = array( 'name' => 'aes', 'keylen' => '128' );
- break;
+ $ph1alg = array('name' => 'aes', 'keylen' => '128');
+ break;
case "rijndael 256":
case "aes 256":
- $ph1alg = array( 'name' => 'aes', 'keylen' => '256' );
- break;
+ $ph1alg = array('name' => 'aes', 'keylen' => '256');
+ break;
}
$ph1ent['encryption-algorithm'] = $ph1alg;
@@ -1035,14 +1049,18 @@ function upgrade_046_to_047() {
$ph1ent['lifetime'] = $tunnel['p1']['lifetime'];
$ph1ent['authentication_method'] = $tunnel['p1']['authentication_method'];
- if (isset($tunnel['p1']['pre-shared-key']))
+ if (isset($tunnel['p1']['pre-shared-key'])) {
$ph1ent['pre-shared-key'] = $tunnel['p1']['pre-shared-key'];
- if (isset($tunnel['p1']['cert']))
+ }
+ if (isset($tunnel['p1']['cert'])) {
$ph1ent['cert'] = $tunnel['p1']['cert'];
- if (isset($tunnel['p1']['peercert']))
+ }
+ if (isset($tunnel['p1']['peercert'])) {
$ph1ent['peercert'] = $tunnel['p1']['peercert'];
- if (isset($tunnel['p1']['private-key']))
+ }
+ if (isset($tunnel['p1']['private-key'])) {
$ph1ent['private-key'] = $tunnel['p1']['private-key'];
+ }
$ph1ent['nat_traversal'] = "on";
$ph1ent['dpd_enable'] = 1;
@@ -1058,32 +1076,35 @@ function upgrade_046_to_047() {
$ph2ent['ikeid'] = $ph1ent['ikeid'];
- if (isset($tunnel['disabled']))
+ if (isset($tunnel['disabled'])) {
$ph1ent['disabled'] = $tunnel['disabled'];
+ }
$ph2ent['descr'] = sprintf(gettext("phase2 for %s"), $tunnel['descr']);
$type = "lan";
- if ($tunnel['local-subnet']['network'])
+ if ($tunnel['local-subnet']['network']) {
$type = $tunnel['local-subnet']['network'];
+ }
if ($tunnel['local-subnet']['address']) {
list($address,$netbits) = explode("/",$tunnel['local-subnet']['address']);
- if (is_null($netbits))
+ if (is_null($netbits)) {
$type = "address";
- else
+ } else {
$type = "network";
+ }
}
switch ($type) {
case "address":
- $ph2ent['localid'] = array('type' => $type,'address' => $address);
- break;
+ $ph2ent['localid'] = array('type' => $type,'address' => $address);
+ break;
case "network":
- $ph2ent['localid'] = array('type' => $type,'address' => $address,'netbits' => $netbits);
- break;
+ $ph2ent['localid'] = array('type' => $type,'address' => $address,'netbits' => $netbits);
+ break;
default:
- $ph2ent['localid'] = array('type' => $type);
- break;
+ $ph2ent['localid'] = array('type' => $type);
+ break;
}
list($address,$netbits) = explode("/",$tunnel['remote-subnet']);
@@ -1092,40 +1113,42 @@ function upgrade_046_to_047() {
$ph2ent['protocol'] = $tunnel['p2']['protocol'];
$aes_count = 0;
- foreach( $tunnel['p2']['encryption-algorithm-option'] as $tunalg ) {
+ foreach ($tunnel['p2']['encryption-algorithm-option'] as $tunalg) {
$aes_found = false;
switch ($tunalg) {
case "des":
- $ph2alg = array( 'name' => 'des' );
- break;
+ $ph2alg = array('name' => 'des');
+ break;
case "3des":
- $ph2alg = array( 'name' => '3des' );
- break;
+ $ph2alg = array('name' => '3des');
+ break;
case "blowfish":
- $ph2alg = array( 'name' => 'blowfish', 'keylen' => 'auto' );
- break;
+ $ph2alg = array('name' => 'blowfish', 'keylen' => 'auto');
+ break;
case "cast128":
- $ph2alg = array( 'name' => 'cast128' );
- break;
+ $ph2alg = array('name' => 'cast128');
+ break;
case "rijndael":
case "rijndael 256":
case "aes 256":
- $ph2alg = array( 'name' => 'aes', 'keylen' => 'auto' );
- $aes_found = true;
- $aes_count++;
- break;
+ $ph2alg = array('name' => 'aes', 'keylen' => 'auto');
+ $aes_found = true;
+ $aes_count++;
+ break;
}
- if( !$aes_found || ($aes_count < 2))
+ if (!$aes_found || ($aes_count < 2)) {
$ph2ent['encryption-algorithm-option'][] = $ph2alg;
+ }
}
$ph2ent['hash-algorithm-option'] = $tunnel['p2']['hash-algorithm-option'];
$ph2ent['pfsgroup'] = $tunnel['p2']['pfsgroup'];
$ph2ent['lifetime'] = $tunnel['p2']['lifetime'];
- if (isset($tunnel['pinghost']['pinghost']))
+ if (isset($tunnel['pinghost']['pinghost'])) {
$ph2ent['pinghost'] = $tunnel['pinghost'];
+ }
$a_phase2[] = $ph2ent;
}
@@ -1136,10 +1159,10 @@ function upgrade_046_to_047() {
}
/* Upgrade Mobile IPsec */
- if (isset($config['ipsec']['mobileclients'])
- && is_array($config['ipsec']['mobileclients'])
- && is_array($config['ipsec']['mobileclients']['p1'])
- && is_array($config['ipsec']['mobileclients']['p2'])) {
+ if (isset($config['ipsec']['mobileclients']) &&
+ is_array($config['ipsec']['mobileclients']) &&
+ is_array($config['ipsec']['mobileclients']['p1']) &&
+ is_array($config['ipsec']['mobileclients']['p2'])) {
if (isset($config['ipsec']['mobileclients']['enable'])) {
$config['ipsec']['client']['enable'] = true;
@@ -1152,16 +1175,18 @@ function upgrade_046_to_047() {
$ph1ent = array();
$ph1ent['ikeid'] = ++$ikeid;
- if (!isset($mobilecfg['enable']))
+ if (!isset($mobilecfg['enable'])) {
$ph1ent['disabled'] = true;
+ }
/* Assume WAN since mobile tunnels couldn't be on a separate interface on 1.2.x */
$ph1ent['interface'] = 'wan';
$ph1ent['descr'] = "Mobile Clients (upgraded)";
$ph1ent['mode'] = $mobilecfg['p1']['mode'];
- if (isset($mobilecfg['p1']['myident']['myaddress']))
+ if (isset($mobilecfg['p1']['myident']['myaddress'])) {
$ph1ent['myid_type'] = "myaddress";
+ }
if (isset($mobilecfg['p1']['myident']['address'])) {
$ph1ent['myid_type'] = "address";
$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['address'];
@@ -1187,24 +1212,24 @@ function upgrade_046_to_047() {
switch ($mobilecfg['p1']['encryption-algorithm']) {
case "des":
- $ph1alg = array( 'name' => 'des' );
- break;
+ $ph1alg = array('name' => 'des');
+ break;
case "3des":
- $ph1alg = array( 'name' => '3des' );
- break;
+ $ph1alg = array('name' => '3des');
+ break;
case "blowfish":
- $ph1alg = array( 'name' => 'blowfish', 'keylen' => '128' );
- break;
+ $ph1alg = array('name' => 'blowfish', 'keylen' => '128');
+ break;
case "cast128":
- $ph1alg = array( 'name' => 'cast128' );
- break;
+ $ph1alg = array('name' => 'cast128');
+ break;
case "rijndael":
- $ph1alg = array( 'name' => 'aes', 'keylen' => '128' );
- break;
+ $ph1alg = array('name' => 'aes', 'keylen' => '128');
+ break;
case "rijndael 256":
case "aes 256":
- $ph1alg = array( 'name' => 'aes', 'keylen' => '256' );
- break;
+ $ph1alg = array('name' => 'aes', 'keylen' => '256');
+ break;
}
$ph1ent['encryption-algorithm'] = $ph1alg;
@@ -1213,12 +1238,15 @@ function upgrade_046_to_047() {
$ph1ent['lifetime'] = $mobilecfg['p1']['lifetime'];
$ph1ent['authentication_method'] = $mobilecfg['p1']['authentication_method'];
- if (isset($mobilecfg['p1']['cert']))
+ if (isset($mobilecfg['p1']['cert'])) {
$ph1ent['cert'] = $mobilecfg['p1']['cert'];
- if (isset($mobilecfg['p1']['peercert']))
+ }
+ if (isset($mobilecfg['p1']['peercert'])) {
$ph1ent['peercert'] = $mobilecfg['p1']['peercert'];
- if (isset($mobilecfg['p1']['private-key']))
+ }
+ if (isset($mobilecfg['p1']['private-key'])) {
$ph1ent['private-key'] = $mobilecfg['p1']['private-key'];
+ }
$ph1ent['nat_traversal'] = "on";
$ph1ent['dpd_enable'] = 1;
@@ -1234,32 +1262,33 @@ function upgrade_046_to_047() {
$ph2ent['protocol'] = $mobilecfg['p2']['protocol'];
$aes_count = 0;
- foreach( $mobilecfg['p2']['encryption-algorithm-option'] as $tunalg ) {
+ foreach ($mobilecfg['p2']['encryption-algorithm-option'] as $tunalg) {
$aes_found = false;
switch ($tunalg) {
case "des":
- $ph2alg = array( 'name' => 'des' );
- break;
+ $ph2alg = array('name' => 'des');
+ break;
case "3des":
- $ph2alg = array( 'name' => '3des' );
- break;
+ $ph2alg = array('name' => '3des');
+ break;
case "blowfish":
- $ph2alg = array( 'name' => 'blowfish', 'keylen' => 'auto' );
- break;
+ $ph2alg = array('name' => 'blowfish', 'keylen' => 'auto');
+ break;
case "cast128":
- $ph2alg = array( 'name' => 'cast128' );
- break;
+ $ph2alg = array('name' => 'cast128');
+ break;
case "rijndael":
case "rijndael 256":
case "aes 256":
- $ph2alg = array( 'name' => 'aes', 'keylen' => 'auto' );
- $aes_found = true;
- $aes_count++;
- break;
+ $ph2alg = array('name' => 'aes', 'keylen' => 'auto');
+ $aes_found = true;
+ $aes_count++;
+ break;
}
- if( !$aes_found || ($aes_count < 2))
+ if (!$aes_found || ($aes_count < 2)) {
$ph2ent['encryption-algorithm-option'][] = $ph2alg;
+ }
}
$ph2ent['hash-algorithm-option'] = $mobilecfg['p2']['hash-algorithm-option'];
$ph2ent['pfsgroup'] = $mobilecfg['p2']['pfsgroup'];
@@ -1278,7 +1307,7 @@ function upgrade_047_to_048() {
if (!empty($config['dyndns'])) {
$config['dyndnses'] = array();
$config['dyndnses']['dyndns'] = array();
- if(isset($config['dyndns'][0]['host'])) {
+ if (isset($config['dyndns'][0]['host'])) {
$tempdyn = array();
$tempdyn['enable'] = isset($config['dyndns'][0]['enable']);
$tempdyn['type'] = $config['dyndns'][0]['type'];
@@ -1295,10 +1324,12 @@ function upgrade_047_to_048() {
}
if (!empty($config['dnsupdate'])) {
$pconfig = $config['dnsupdate'][0];
- if (!$pconfig['ttl'])
+ if (!$pconfig['ttl']) {
$pconfig['ttl'] = 60;
- if (!$pconfig['keytype'])
+ }
+ if (!$pconfig['keytype']) {
$pconfig['keytype'] = "zone";
+ }
$pconfig['interface'] = "wan";
$config['dnsupdates']['dnsupdate'][] = $pconfig;
unset($config['dnsupdate']);
@@ -1329,7 +1360,7 @@ function upgrade_047_to_048() {
$config['interfaces']['wan']['pptp_username'] = $pconfig['username'];
$config['interfaces']['wan']['pptp_password'] = $pconfig['password'];
$config['interfaces']['wan']['provider'] = $pconfig['provider'];
- $config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand'] );
+ $config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand']);
$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
}
}
@@ -1345,26 +1376,30 @@ function upgrade_048_to_049() {
$all['gid'] = 1998;
$all['member'] = array();
- if (!is_array($config['system']['user']))
+ if (!is_array($config['system']['user'])) {
$config['system']['user'] = array();
- if (!is_array($config['system']['group']))
+ }
+ if (!is_array($config['system']['group'])) {
$config['system']['group'] = array();
+ }
/* work around broken uid assignments */
$config['system']['nextuid'] = 2000;
foreach ($config['system']['user'] as & $user) {
- if (isset($user['uid']) && !$user['uid'])
+ if (isset($user['uid']) && !$user['uid']) {
continue;
+ }
$user['uid'] = $config['system']['nextuid']++;
}
/* work around broken gid assignments */
$config['system']['nextgid'] = 2000;
foreach ($config['system']['group'] as & $group) {
- if ($group['name'] == $g['admin_group'])
+ if ($group['name'] == $g['admin_group']) {
$group['gid'] = 1999;
- else
+ } else {
$group['gid'] = $config['system']['nextgid']++;
+ }
}
/* build group membership information */
@@ -1372,8 +1407,9 @@ function upgrade_048_to_049() {
$group['member'] = array();
foreach ($config['system']['user'] as & $user) {
$groupnames = explode(",", $user['groupname']);
- if (in_array($group['name'],$groupnames))
+ if (in_array($group['name'],$groupnames)) {
$group['member'][] = $user['uid'];
+ }
}
}
@@ -1384,9 +1420,11 @@ function upgrade_048_to_049() {
}
/* reset group scope information */
- foreach ($config['system']['group'] as & $group)
- if ($group['name'] != $g['admin_group'])
- $group['scope'] = "user";
+ foreach ($config['system']['group'] as & $group) {
+ if ($group['name'] != $g['admin_group']) {
+ $group['scope'] = "user";
+ }
+ }
/* insert new all group */
$groups = Array();
@@ -1399,8 +1437,9 @@ function upgrade_048_to_049() {
function upgrade_049_to_050() {
global $config;
- if (!is_array($config['system']['user']))
+ if (!is_array($config['system']['user'])) {
$config['system']['user'] = array();
+ }
/* update user privileges */
foreach ($config['system']['user'] as & $user) {
$privs = array();
@@ -1409,13 +1448,13 @@ function upgrade_049_to_050() {
continue;
}
foreach ($user['priv'] as $priv) {
- switch($priv['id']) {
+ switch ($priv['id']) {
case "hasshell":
- $privs[] = "user-shell-access";
- break;
+ $privs[] = "user-shell-access";
+ break;
case "copyfiles":
- $privs[] = "user-copy-files";
- break;
+ $privs[] = "user-copy-files";
+ break;
}
}
$user['priv'] = $privs;
@@ -1430,8 +1469,9 @@ function upgrade_049_to_050() {
}
foreach ($group['pages'] as $page) {
$priv = map_page_privname($page);
- if ($priv)
+ if ($priv) {
$privs[] = $priv;
+ }
}
unset($group['pages']);
$group['priv'] = $privs;
@@ -1458,7 +1498,7 @@ function upgrade_050_to_051() {
unset($config['bridge']);
$convert_bridges = false;
- foreach($config['interfaces'] as $intf) {
+ foreach ($config['interfaces'] as $intf) {
if (isset($intf['bridge']) && $intf['bridge'] <> "") {
$config['bridges'] = array();
$config['bridges']['bridged'] = array();
@@ -1486,10 +1526,12 @@ function upgrade_050_to_051() {
function upgrade_051_to_052() {
global $config;
$config['openvpn'] = array();
- if (!is_array($config['ca']))
+ if (!is_array($config['ca'])) {
$config['ca'] = array();
- if (!is_array($config['cert']))
+ }
+ if (!is_array($config['cert'])) {
$config['cert'] = array();
+ }
$vpnid = 1;
@@ -1498,10 +1540,11 @@ function upgrade_051_to_052() {
$config['openvpn']['openvpn-server'] = array();
$index = 1;
- foreach($config['installedpackages']['openvpnserver']['config'] as $server) {
+ foreach ($config['installedpackages']['openvpnserver']['config'] as $server) {
- if (!is_array($server))
+ if (!is_array($server)) {
continue;
+ }
if ($server['auth_method'] == "pki") {
@@ -1523,8 +1566,9 @@ function upgrade_051_to_052() {
$crl['descr'] = "Imported OpenVPN CRL #{$index}";
$crl['caref'] = $ca['refid'];
$crl['text'] = $server['crl'][0];
- if(!is_array($config['crl']))
+ if (!is_array($config['crl'])) {
$config['crl'] = array();
+ }
$config['crl'][] = $crl;
$server['crlref'] = $crl['refid'];
}
@@ -1548,7 +1592,7 @@ function upgrade_051_to_052() {
/* determine operational mode */
if ($server['auth_method'] == 'pki') {
- if($server['nopool']) {
+ if ($server['nopool']) {
$server['mode'] = "p2p_tls";
} else {
$server['mode'] = "server_tls";
@@ -1561,18 +1605,20 @@ function upgrade_051_to_052() {
/* modify configuration values */
$server['dh_length'] = 1024;
unset($server['dh_params']);
- if (!$server['interface'])
+ if (!$server['interface']) {
$server['interface'] = 'any';
+ }
$server['tunnel_network'] = $server['addresspool'];
unset($server['addresspool']);
if (isset($server['use_lzo']) && ($server['use_lzo'] == "on")) {
$server['compression'] = "on";
unset($server['use_lzo']);
}
- if ($server['nopool'])
+ if ($server['nopool']) {
$server['pool_enable'] = false;
- else
+ } else {
$server['pool_enable'] = "yes";
+ }
unset($server['nopool']);
$server['dns_domain'] = $server['dhcp_domainname'];
unset($server['dhcp_domainname']);
@@ -1593,10 +1639,11 @@ function upgrade_051_to_052() {
}
unset($server['dhcp_ntp']);
- if ($server['dhcp_nbtdisable'])
+ if ($server['dhcp_nbtdisable']) {
$server['netbios_enable'] = false;
- else
+ } else {
$server['netbios_enable'] = "yes";
+ }
unset($server['dhcp_nbtdisable']);
$server['netbios_ntype'] = $server['dhcp_nbttype'];
unset($server['dhcp_nbttype']);
@@ -1619,10 +1666,11 @@ function upgrade_051_to_052() {
}
unset($server['dhcp_wins']);
- if (!empty($server['disable']))
+ if (!empty($server['disable'])) {
$server['disable'] = true;
- else
+ } else {
unset($server['disable']);
+ }
/* allocate vpnid */
$server['vpnid'] = $vpnid++;
@@ -1640,8 +1688,9 @@ function upgrade_051_to_052() {
} else if (substr($tmpstr, 0, 5) == "local") {
$localip = substr($tmpstr, 5);
$server['ipaddr'] = str_replace("\n", "", $localip);
- } else
+ } else {
$cstmopts[] = $tmpcstmopt;
+ }
}
$server['custom_options'] = implode(";", $cstmopts);
if (!empty($assigned_if)) {
@@ -1664,10 +1713,11 @@ function upgrade_051_to_052() {
$config['openvpn']['openvpn-client'] = array();
$index = 1;
- foreach($config['installedpackages']['openvpnclient']['config'] as $client) {
+ foreach ($config['installedpackages']['openvpnclient']['config'] as $client) {
- if (!is_array($client))
+ if (!is_array($client)) {
continue;
+ }
if ($client['auth_method'] == "pki") {
@@ -1701,15 +1751,17 @@ function upgrade_051_to_052() {
}
/* determine operational mode */
- if ($client['auth_method'] == 'pki')
+ if ($client['auth_method'] == 'pki') {
$client['mode'] = "p2p_tls";
- else
+ } else {
$client['mode'] = "p2p_shared_key";
+ }
unset($client['auth_method']);
/* modify configuration values */
- if (!$client['interface'])
+ if (!$client['interface']) {
$client['interface'] = 'wan';
+ }
$client['tunnel_network'] = $client['interface_ip'];
unset($client['interface_ip']);
$client['server_addr'] = $client['serveraddr'];
@@ -1741,8 +1793,9 @@ function upgrade_051_to_052() {
} else if (substr($tmpstr, 0, 5) == "local") {
$localip = substr($tmpstr, 5);
$client['ipaddr'] = str_replace("\n", "", $localip);
- } else
+ } else {
$cstmopts[] = $tmpcstmopt;
+ }
}
$client['custom_options'] = implode(";", $cstmopts);
if (!empty($assigned_if)) {
@@ -1755,10 +1808,11 @@ function upgrade_051_to_052() {
}
}
- if (!empty($client['disable']))
+ if (!empty($client['disable'])) {
$client['disable'] = true;
- else
+ } else {
unset($client['disable']);
+ }
$config['openvpn']['openvpn-client'][] = $client;
}
@@ -1770,10 +1824,11 @@ function upgrade_051_to_052() {
if (is_array($config['installedpackages']['openvpncsc'])) {
$config['openvpn']['openvpn-csc'] = array();
- foreach($config['installedpackages']['openvpncsc']['config'] as $csc) {
+ foreach ($config['installedpackages']['openvpncsc']['config'] as $csc) {
- if (!is_array($csc))
+ if (!is_array($csc)) {
continue;
+ }
/* modify configuration values */
$csc['common_name'] = $csc['commonname'];
@@ -1799,10 +1854,11 @@ function upgrade_051_to_052() {
}
unset($csc['dhcp_ntp']);
- if ($csc['dhcp_nbtdisable'])
+ if ($csc['dhcp_nbtdisable']) {
$csc['netbios_enable'] = false;
- else
+ } else {
$csc['netbios_enable'] = "yes";
+ }
unset($csc['dhcp_nbtdisable']);
$csc['netbios_ntype'] = $csc['dhcp_nbttype'];
unset($csc['dhcp_nbttype']);
@@ -1825,10 +1881,11 @@ function upgrade_051_to_052() {
}
unset($csc['dhcp_wins']);
- if (!empty($csc['disable']))
+ if (!empty($csc['disable'])) {
$csc['disable'] = true;
- else
+ } else {
unset($csc['disable']);
+ }
$config['openvpn']['openvpn-csc'][] = $csc;
}
@@ -1837,7 +1894,7 @@ function upgrade_051_to_052() {
}
if (count($config['openvpn']['openvpn-server']) > 0 ||
- count($config['openvpn']['openvpn-client']) > 0) {
+ count($config['openvpn']['openvpn-client']) > 0) {
$ovpnrule = array();
$ovpnrule['type'] = "pass";
$ovpnrule['interface'] = "openvpn";
@@ -1854,24 +1911,28 @@ function upgrade_051_to_052() {
* FIXME: hack to keep things working with no installedpackages
* or carp array in the configuration data.
*/
- if (!is_array($config['installedpackages']))
+ if (!is_array($config['installedpackages'])) {
$config['installedpackages'] = array();
- if (!is_array($config['installedpackages']['carp']))
+ }
+ if (!is_array($config['installedpackages']['carp'])) {
$config['installedpackages']['carp'] = array();
+ }
}
function upgrade_052_to_053() {
global $config;
- if (!is_array($config['ca']))
+ if (!is_array($config['ca'])) {
$config['ca'] = array();
- if (!is_array($config['cert']))
+ }
+ if (!is_array($config['cert'])) {
$config['cert'] = array();
+ }
/* migrate advanced admin page webui ssl to certificate manager */
if ($config['system']['webgui']['certificate'] &&
- $config['system']['webgui']['private-key']) {
+ $config['system']['webgui']['private-key']) {
/* create cert entry */
$cert = array();
@@ -1898,27 +1959,29 @@ function upgrade_052_to_053() {
function upgrade_053_to_054() {
global $config;
- if(is_array($config['load_balancer']['lbpool'])) {
+ if (is_array($config['load_balancer']['lbpool'])) {
$lbpool_arr = $config['load_balancer']['lbpool'];
$lbpool_srv_arr = array();
$gateway_group_arr = array();
$gateways = return_gateways_array();
$group_name_changes = array();
- if (! is_array($config['gateways']['gateway_item']))
+ if (! is_array($config['gateways']['gateway_item'])) {
$config['gateways']['gateway_item'] = array();
+ }
$a_gateways =& $config['gateways']['gateway_item'];
- foreach($lbpool_arr as $lbpool) {
- if($lbpool['type'] == "gateway") {
+ foreach ($lbpool_arr as $lbpool) {
+ if ($lbpool['type'] == "gateway") {
// Gateway Groups have to have valid names in pf, old lb pools did not. Clean them up.
- $group_name = preg_replace("/[^A-Za-z0-9]/", "", $lbpool['name'] );
+ $group_name = preg_replace("/[^A-Za-z0-9]/", "", $lbpool['name']);
// If we made and changes, check for collisions and note the change.
if ($group_name != $lbpool['name']) {
// Make sure the name isn't already in use.
foreach ($gateway_group_arr as $gwg) {
// If the name is in use, add some random bits to avoid collision.
- if ($gwg['name'] == $group_name)
+ if ($gwg['name'] == $group_name) {
$group_name .= uniqid();
+ }
}
$group_name_changes[$lbpool['name']] = $group_name;
}
@@ -1927,19 +1990,22 @@ function upgrade_053_to_054() {
$gateway_group['trigger'] = "down";
$gateway_group['item'] = array();
$i = 0;
- foreach($lbpool['servers'] as $member) {
+ foreach ($lbpool['servers'] as $member) {
$split = explode("|", $member);
$interface = $split[0];
$monitor = $split[1];
/* on static upgraded configuration we automatically prepend GW_ */
$static_name = "GW_" . strtoupper($interface);
- if(is_ipaddr($monitor))
- foreach ($a_gateways as & $gw)
- if ($gw['name'] == $static_name)
+ if (is_ipaddr($monitor)) {
+ foreach ($a_gateways as & $gw) {
+ if ($gw['name'] == $static_name) {
$gw['monitor'] = $monitor;
+ }
+ }
+ }
/* on failover increment tier. Else always assign 1 */
- if($lbpool['behaviour'] == "failover") {
+ if ($lbpool['behaviour'] == "failover") {
$i++;
} else {
$i = 1;
@@ -1956,7 +2022,7 @@ function upgrade_053_to_054() {
}
// Unset lbpool if we no longer have any server pools
if (count($lbpool_srv_arr) == 0) {
- if(empty($config['load_balancer'])) {
+ if (empty($config['load_balancer'])) {
unset($config['load_balancer']);
} else {
unset($config['load_balancer']['lbpool']);
@@ -1968,10 +2034,13 @@ function upgrade_053_to_054() {
if (count($gateway_group_arr) != 0) {
$config['gateways']['gateway_group'] = $gateway_group_arr;
// Update any rules that had a gateway change, if any.
- if (count($group_name_changes) > 0)
- foreach ($config['filter']['rule'] as & $rule)
- if (!empty($rule["gateway"]) && array_key_exists($rule["gateway"], $group_name_changes))
+ if (count($group_name_changes) > 0) {
+ foreach ($config['filter']['rule'] as & $rule) {
+ if (!empty($rule["gateway"]) && array_key_exists($rule["gateway"], $group_name_changes)) {
$rule["gateway"] = $group_name_changes[$rule["gateway"]];
+ }
+ }
+ }
}
}
@@ -2013,17 +2082,19 @@ function upgrade_054_to_055() {
}
/* the roundtrip times need to be divided by 1000 to get seconds, really */
$databases = array();
- if (!file_exists($rrddbpath))
+ if (!file_exists($rrddbpath)) {
@mkdir($rrddbpath);
+ }
chdir($rrddbpath);
$databases = glob("*-quality.rrd");
rsort($databases);
- foreach($databases as $database) {
+ foreach ($databases as $database) {
$xmldump = "{$database}.old.xml";
$xmldumpnew = "{$database}.new.xml";
- if (platform_booting())
+ if (platform_booting()) {
echo "Migrate RRD database {$database} to new format for IPv6 \n";
+ }
mwexec("$rrdtool tune {$rrddbpath}{$database} -r roundtrip:delay 2>&1");
dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}");
@@ -2031,9 +2102,9 @@ function upgrade_054_to_055() {
$rrdold = $rrdold['rrd'];
$i = 0;
- foreach($rrdold['rra'] as $rra) {
+ foreach ($rrdold['rra'] as $rra) {
$l = 0;
- foreach($rra['database']['row'] as $row) {
+ foreach ($rra['database']['row'] as $row) {
$vnew = divide_delay($row['v'][1]);
$rrdold['rra'][$i]['database']['row'][$l]['v'][1] = $vnew;
$l++;
@@ -2049,20 +2120,22 @@ function upgrade_054_to_055() {
@unlink("{$g['tmp_path']}/{$xmldumpnew}");
}
/* let apinger recreate required files */
- if (!platform_booting())
+ if (!platform_booting()) {
setup_gateways_monitor();
+ }
/* build a list of traffic and packets databases */
$databases = return_dir_as_array($rrddbpath, '/-(traffic|packets)\.rrd$/');
rsort($databases);
- foreach($databases as $database) {
+ foreach ($databases as $database) {
$databasetmp = "{$database}.tmp";
$xmldump = "{$database}.old.xml";
$xmldumptmp = "{$database}.tmp.xml";
$xmldumpnew = "{$database}.new.xml";
- if (platform_booting())
+ if (platform_booting()) {
echo "Migrate RRD database {$database} to new format \n";
+ }
/* rename DS source */
mwexec("$rrdtool tune {$rrddbpath}/{$database} -r in:inpass 2>&1");
mwexec("$rrdtool tune {$rrddbpath}/{$database} -r out:outpass 2>71");
@@ -2094,7 +2167,7 @@ function upgrade_054_to_055() {
/* remove any MAX RRA's. Not needed for traffic. */
$i = 0;
foreach ($rrdold['rra'] as $rra) {
- if(trim($rra['cf']) == "MAX") {
+ if (trim($rra['cf']) == "MAX") {
unset($rrdold['rra'][$i]);
}
$i++;
@@ -2112,34 +2185,39 @@ function upgrade_054_to_055() {
@unlink("{$g['tmp_path']}/{$xmldump}");
@unlink("{$g['tmp_path']}/{$xmldumpnew}");
}
- if (!platform_booting())
+ if (!platform_booting()) {
enable_rrd_graphing();
+ }
/* Let's save the RRD graphs after we run enable RRD graphing */
/* The function will restore the rrd.tgz so we will save it after */
exec("cd /; LANG=C NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='{$g['cf_conf_path']}' /etc/rc.backup_rrd.sh");
unlink_if_exists("{$g['vardb_path']}/rrd/*.xml");
- if (platform_booting())
+ if (platform_booting()) {
echo "Updating configuration...";
+ }
}
function upgrade_055_to_056() {
global $config;
- if (!is_array($config['ca']))
+ if (!is_array($config['ca'])) {
$config['ca'] = array();
- if (!is_array($config['cert']))
+ }
+ if (!is_array($config['cert'])) {
$config['cert'] = array();
+ }
/* migrate ipsec ca's to cert manager */
if (is_array($config['ipsec']['cacert'])) {
- foreach($config['ipsec']['cacert'] as & $cacert) {
+ foreach ($config['ipsec']['cacert'] as & $cacert) {
$ca = array();
$ca['refid'] = uniqid();
- if (is_array($cacert['cert']))
+ if (is_array($cacert['cert'])) {
$ca['crt'] = $cacert['cert'][0];
- else
+ } else {
$ca['crt'] = $cacert['cert'];
+ }
$ca['descr'] = $cacert['ident'];
$config['ca'][] = $ca;
}
@@ -2148,23 +2226,27 @@ function upgrade_055_to_056() {
/* migrate phase1 certificates to cert manager */
if (is_array($config['ipsec']['phase1'])) {
- foreach($config['ipsec']['phase1'] as & $ph1ent) {
+ foreach ($config['ipsec']['phase1'] as & $ph1ent) {
$cert = array();
$cert['refid'] = uniqid();
$cert['descr'] = "IPsec Peer {$ph1ent['remote-gateway']} Certificate";
- if (is_array($ph1ent['cert']))
+ if (is_array($ph1ent['cert'])) {
$cert['crt'] = $ph1ent['cert'][0];
- else
+ } else {
$cert['crt'] = $ph1ent['cert'];
+ }
$cert['prv'] = $ph1ent['private-key'];
$config['cert'][] = $cert;
$ph1ent['certref'] = $cert['refid'];
- if ($ph1ent['cert'])
+ if ($ph1ent['cert']) {
unset($ph1ent['cert']);
- if ($ph1ent['private-key'])
+ }
+ if ($ph1ent['private-key']) {
unset($ph1ent['private-key']);
- if ($ph1ent['peercert'])
+ }
+ if ($ph1ent['peercert']) {
unset($ph1ent['peercert']);
+ }
}
}
}
@@ -2173,11 +2255,12 @@ function upgrade_055_to_056() {
function upgrade_056_to_057() {
global $config;
- if (!is_array($config['system']['user']))
+ if (!is_array($config['system']['user'])) {
$config['system']['user'] = array();
+ }
/* migrate captivate portal to user manager */
if (is_array($config['captiveportal']['user'])) {
- foreach($config['captiveportal']['user'] as $user) {
+ foreach ($config['captiveportal']['user'] as $user) {
// avoid user conflicts
$found = false;
foreach ($config['system']['user'] as $userent) {
@@ -2186,8 +2269,9 @@ function upgrade_056_to_057() {
break;
}
}
- if ($found)
+ if ($found) {
continue;
+ }
$user['scope'] = "user";
if (isset($user['expirationdate'])) {
$user['expires'] = $user['expirationdate'];
@@ -2207,17 +2291,20 @@ function upgrade_056_to_057() {
function upgrade_057_to_058() {
global $config;
/* set all phase2 entries to tunnel mode */
- if (is_array($config['ipsec']['phase2']))
- foreach($config['ipsec']['phase2'] as & $ph2ent)
+ if (is_array($config['ipsec']['phase2'])) {
+ foreach ($config['ipsec']['phase2'] as & $ph2ent) {
$ph2ent['mode'] = 'tunnel';
+ }
+ }
}
function upgrade_058_to_059() {
global $config;
if (is_array($config['schedules']['schedule'])) {
- foreach ($config['schedules']['schedule'] as & $schedl)
+ foreach ($config['schedules']['schedule'] as & $schedl) {
$schedl['schedlabel'] = uniqid();
+ }
}
}
@@ -2229,10 +2316,11 @@ function upgrade_059_to_060() {
foreach ($config['ca'] as & $ca) {
$subject = cert_get_subject($ca['crt']);
$issuer = cert_get_issuer($ca['crt']);
- if($issuer <> $subject) {
+ if ($issuer <> $subject) {
$issuer_crt =& lookup_ca_by_subject($issuer);
- if($issuer_crt)
+ if ($issuer_crt) {
$ca['caref'] = $issuer_crt['refid'];
+ }
}
}
@@ -2241,10 +2329,11 @@ function upgrade_059_to_060() {
foreach ($config['cert'] as & $cert) {
$subject = cert_get_subject($cert['crt']);
$issuer = cert_get_issuer($cert['crt']);
- if($issuer <> $subject) {
+ if ($issuer <> $subject) {
$issuer_crt =& lookup_ca_by_subject($issuer);
- if($issuer_crt)
+ if ($issuer_crt) {
$cert['caref'] = $issuer_crt['refid'];
+ }
}
}
}
@@ -2254,10 +2343,12 @@ function upgrade_059_to_060() {
function upgrade_060_to_061() {
global $config;
- if (is_array($config['interfaces']['wan']))
+ if (is_array($config['interfaces']['wan'])) {
$config['interfaces']['wan']['enable'] = true;
- if (is_array($config['interfaces']['lan']))
+ }
+ if (is_array($config['interfaces']['lan'])) {
$config['interfaces']['lan']['enable'] = true;
+ }
/* On 1.2.3 the "mtu" field adjusted MSS.
On 2.x the "mtu" field is actually the MTU. Rename accordingly.
@@ -2314,7 +2405,7 @@ function upgrade_062_to_063() {
/* Upgrade legacy Themes to the new pfsense_ng */
global $config;
- switch($config['theme']) {
+ switch ($config['theme']) {
case "nervecenter":
$config['theme'] = "pfsense_ng";
break;
@@ -2332,63 +2423,73 @@ function upgrade_063_to_064() {
$config['ppps']['ppp'][$pppid]['if'] = "ppp".$j;
$config['ppps']['ppp'][$pppid]['ptpid'] = $j;
$j++;
- if (isset($ppp['port'])){
+ if (isset($ppp['port'])) {
$config['ppps']['ppp'][$pppid]['ports'] = $ppp['port'];
unset($config['ppps']['ppp'][$pppid]['port']);
}
- if (!isset($ppp['type'])){
+ if (!isset($ppp['type'])) {
$config['ppps']['ppp'][$pppid]['type'] = "ppp";
}
- if (isset($ppp['defaultgw']))
+ if (isset($ppp['defaultgw'])) {
unset($config['ppps']['ppp'][$pppid]['defaultgw']);
+ }
}
}
- if (!is_array($config['ppps']['ppp']))
+ if (!is_array($config['ppps']['ppp'])) {
$config['ppps']['ppp'] = array();
+ }
$a_ppps = &$config['ppps']['ppp'];
foreach ($ifcfg as $ifname => $ifinfo) {
$ppp = array();
// For pppoe conversion
- if ($ifinfo['ipaddr'] == "pppoe" || $ifinfo['ipaddr'] == "pptp"){
- if (isset($ifinfo['ptpid']))
+ if ($ifinfo['ipaddr'] == "pppoe" || $ifinfo['ipaddr'] == "pptp") {
+ if (isset($ifinfo['ptpid'])) {
continue;
+ }
$ppp['ptpid'] = $j;
$ppp['type'] = $ifinfo['ipaddr'];
$ppp['if'] = $ifinfo['ipaddr'].$j;
$ppp['ports'] = $ifinfo['if'];
- if ($ifinfo['ipaddr'] == "pppoe"){
+ if ($ifinfo['ipaddr'] == "pppoe") {
$ppp['username'] = $ifinfo['pppoe_username'];
$ppp['password'] = base64_encode($ifinfo['pppoe_password']);
}
- if ($ifinfo['ipaddr'] == "pptp"){
+ if ($ifinfo['ipaddr'] == "pptp") {
$ppp['username'] = $ifinfo['pptp_username'];
$ppp['password'] = base64_encode($ifinfo['pptp_password']);
}
- if (isset($ifinfo['provider']))
+ if (isset($ifinfo['provider'])) {
$ppp['provider'] = $ifinfo['provider'];
- if (isset($ifinfo['ondemand']))
+ }
+ if (isset($ifinfo['ondemand'])) {
$ppp['ondemand'] = true;
- if (isset($ifinfo['timeout']))
+ }
+ if (isset($ifinfo['timeout'])) {
$ppp['idletimeout'] = $ifinfo['timeout'];
- if (isset($ifinfo['pppoe']['pppoe-reset-type'])){
+ }
+ if (isset($ifinfo['pppoe']['pppoe-reset-type'])) {
$ppp['pppoe-reset-type'] = $ifinfo['pppoe']['pppoe-reset-type'];
if (is_array($config['cron']['item'])) {
for ($i = 0; $i < count($config['cron']['item']); $i++) {
$item = $config['cron']['item'][$i];
- if (strpos($item['command'], "/conf/pppoe{$ifname}restart") !== false)
+ if (strpos($item['command'], "/conf/pppoe{$ifname}restart") !== false) {
$config['cron']['item'][$i]['command'] = "/var/etc/pppoe_restart_" . $ppp['if'];
+ }
}
}
}
- if (isset($ifinfo['local']))
+ if (isset($ifinfo['local'])) {
$ppp['localip'] = $ifinfo['local'];
- if (isset($ifinfo['subnet']))
+ }
+ if (isset($ifinfo['subnet'])) {
$ppp['subnet'] = $ifinfo['subnet'];
- if (isset($ifinfo['remote']))
+ }
+ if (isset($ifinfo['remote'])) {
$ppp['gateway'] = $ifinfo['remote'];
+ }
$ifcfg[$ifname]['if'] = $ifinfo['ipaddr'].$j;
$j++;
@@ -2436,8 +2537,9 @@ function upgrade_065_to_066() {
$foundifs = true;
}
}
- if ($foundifs == true)
+ if ($foundifs == true) {
$dhcrelaycfg['interface'] = implode(",", $dhcrelayifs);
+ }
}
}
@@ -2463,8 +2565,9 @@ function upgrade_067_to_068() {
$username = array();
foreach ($config['pppoe']['user'] as $user) {
$usr = $user['name'] . ":" . base64_encode($user['password']);
- if ($user['ip'])
+ if ($user['ip']) {
$usr .= ":{$user['ip']}";
+ }
$username[] = $usr;
}
$config['pppoes']['pppoe'][0]['username'] = implode(" ", $username);
@@ -2475,26 +2578,31 @@ function upgrade_067_to_068() {
function upgrade_068_to_069() {
global $config;
- if (!is_array($config['system']['user']))
+ if (!is_array($config['system']['user'])) {
return;
+ }
foreach ($config['system']['user'] as & $user) {
- if (!is_array($user['cert']))
+ if (!is_array($user['cert'])) {
continue;
+ }
$rids = array();
foreach ($user['cert'] as $id => $cert) {
- if (!isset($cert['descr']))
+ if (!isset($cert['descr'])) {
continue;
+ }
$tcert = $cert;
// Make sure each cert gets a refid
- if (!isset($tcert['refid']))
+ if (!isset($tcert['refid'])) {
$tcert['refid'] = uniqid();
+ }
// Keep the cert references for this user
$rids[] = $tcert['refid'];
$config['cert'][] = $tcert;
}
// Replace user certs with cert references instead.
- if (count($rids) > 0)
+ if (count($rids) > 0) {
$user['cert'] = $rids;
+ }
}
}
@@ -2504,10 +2612,11 @@ function upgrade_069_to_070() {
/* Convert NAT 1:1 rules */
if (is_array($config['nat']['onetoone'])) {
foreach ($config['nat']['onetoone'] as $nidx => $natent) {
- if ($natent['subnet'] == 32)
+ if ($natent['subnet'] == 32) {
$config['nat']['onetoone'][$nidx]['source'] = array("address" => $natent['internal']);
- else
+ } else {
$config['nat']['onetoone'][$nidx]['source'] = array("address" => $natent['internal'] . "/" . $natent['subnet']);
+ }
$config['nat']['onetoone'][$nidx]['destination'] = array("any" => true);
@@ -2523,8 +2632,8 @@ function upgrade_070_to_071() {
global $config;
if (is_array($config['cron']['item'])) {
- foreach($config['cron']['item'] as $idx => $cronitem) {
- if(stristr($cronitem['command'], "checkreload.sh")) {
+ foreach ($config['cron']['item'] as $idx => $cronitem) {
+ if (stristr($cronitem['command'], "checkreload.sh")) {
unset($config['cron']['item'][$idx]);
break;
}
@@ -2534,35 +2643,44 @@ function upgrade_070_to_071() {
function rename_field(& $section, $oldname, $newname) {
if (is_array($section)) {
- foreach($section as & $item) {
- if (is_array($item) && !empty($item[$oldname]))
+ foreach ($section as & $item) {
+ if (is_array($item) && !empty($item[$oldname])) {
$item[$newname] = $item[$oldname];
- if (is_array($item) && isset($item[$oldname]))
+ }
+ if (is_array($item) && isset($item[$oldname])) {
unset($item[$oldname]);
+ }
}
}
}
function upgrade_071_to_072() {
global $config;
- if (is_array($config['sysctl']) && is_array($config['sysctl']['item']))
+ if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) {
rename_field($config['sysctl']['item'], 'desc', 'descr');
+ }
}
function upgrade_072_to_073() {
global $config;
- if (!is_array($config['load_balancer']))
+ if (!is_array($config['load_balancer'])) {
return;
- if (is_array($config['load_balancer']['monitor_type']))
+ }
+ if (is_array($config['load_balancer']['monitor_type'])) {
rename_field($config['load_balancer']['monitor_type'], 'desc', 'descr');
- if (is_array($config['load_balancer']['lbpool']))
+ }
+ if (is_array($config['load_balancer']['lbpool'])) {
rename_field($config['load_balancer']['lbpool'], 'desc', 'descr');
- if (is_array($config['load_balancer']['lbaction']))
+ }
+ if (is_array($config['load_balancer']['lbaction'])) {
rename_field($config['load_balancer']['lbaction'], 'desc', 'descr');
- if (is_array($config['load_balancer']['lbprotocol']))
+ }
+ if (is_array($config['load_balancer']['lbprotocol'])) {
rename_field($config['load_balancer']['lbprotocol'], 'desc', 'descr');
- if (is_array($config['load_balancer']['virtual_server']))
+ }
+ if (is_array($config['load_balancer']['virtual_server'])) {
rename_field($config['load_balancer']['virtual_server'], 'desc', 'descr');
+ }
}
function upgrade_073_to_074() {
@@ -2572,12 +2690,15 @@ function upgrade_073_to_074() {
function upgrade_074_to_075() {
global $config;
- if (is_array($config['ca']))
+ if (is_array($config['ca'])) {
rename_field($config['ca'], 'name', 'descr');
- if (is_array($config['cert']))
+ }
+ if (is_array($config['cert'])) {
rename_field($config['cert'], 'name', 'descr');
- if (is_array($config['crl']))
+ }
+ if (is_array($config['crl'])) {
rename_field($config['crl'], 'name', 'descr');
+ }
}
function upgrade_075_to_076() {
@@ -2595,16 +2716,17 @@ function upgrade_075_to_076() {
function upgrade_076_to_077() {
global $config;
- foreach($config['filter']['rule'] as & $rule) {
- if (isset($rule['protocol']) && !empty($rule['protocol']))
- $rule['protocol'] = strtolower($rule['protocol']);
+ foreach ($config['filter']['rule'] as & $rule) {
+ if (isset($rule['protocol']) && !empty($rule['protocol'])) {
+ $rule['protocol'] = strtolower($rule['protocol']);
+ }
}
}
function upgrade_077_to_078() {
global $config;
- if (is_array($config['pptpd']) && is_array($config['pptpd']['radius'])
- && !is_array($config['pptpd']['radius']['server'])) {
+ if (is_array($config['pptpd']) && is_array($config['pptpd']['radius']) &&
+ !is_array($config['pptpd']['radius']['server'])) {
$radarr = array();
$radsvr = array();
$radsvr['ip'] = $config['pptpd']['radius']['server'];
@@ -2613,8 +2735,9 @@ function upgrade_077_to_078() {
$radsvr['acctport'] = 1813;
$radsvr['enable'] = isset($config['pptpd']['radius']['enable']);
$radarr['accounting'] = isset($config['pptpd']['radius']['accounting']);
- if ($radarr['accounting'])
+ if ($radarr['accounting']) {
$radarr['acct_update'] = $radsvr['ip'];
+ }
$radarr['server'] = $radsvr;
$config['pptpd']['radius'] = $radarr;
}
@@ -2633,7 +2756,7 @@ function upgrade_079_to_080() {
/* Upgrade config in 1.2.3 specifying a username other than admin for syncing. */
if (!empty($config['system']['username']) && is_array($config['installedpackages']['carpsettings']) &&
- is_array($config['installedpackages']['carpsettings']['config'])) {
+ is_array($config['installedpackages']['carpsettings']['config'])) {
$config['installedpackages']['carpsettings']['config'][0]['username'] = $config['system']['username'];
unset($config['system']['username']);
}
@@ -2646,8 +2769,8 @@ function upgrade_080_to_081() {
/* tag all the existing gateways as being IPv4 */
$i = 0;
- if(is_array($config['gateways']['gateway_item'])) {
- foreach($config['gateways']['gateway_item'] as $gw) {
+ if (is_array($config['gateways']['gateway_item'])) {
+ foreach ($config['gateways']['gateway_item'] as $gw) {
$config['gateways']['gateway_item'][$i]['ipprotocol'] = "inet";
$i++;
}
@@ -2679,12 +2802,13 @@ function upgrade_080_to_081() {
/* build a list of traffic and packets databases */
$databases = return_dir_as_array($rrddbpath, '/-(traffic|packets)\.rrd$/');
rsort($databases);
- foreach($databases as $database) {
+ foreach ($databases as $database) {
$xmldump = "{$database}.old.xml";
$xmldumpnew = "{$database}.new.xml";
- if (platform_booting())
+ if (platform_booting()) {
echo "Migrate RRD database {$database} to new format for IPv6.\n";
+ }
/* dump contents to xml and move database out of the way */
dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}");
@@ -2782,16 +2906,16 @@ function upgrade_080_to_081() {
$value = "<v> NaN </v>";
$xml = file_get_contents("{$g['tmp_path']}/{$xmldump}");
- foreach($ds_arr as $ds) {
+ foreach ($ds_arr as $ds) {
$xml = preg_replace("/$ds_search/s", "$ds{$ds_search}", $xml);
}
- foreach($cdp_arr as $cdp) {
+ foreach ($cdp_arr as $cdp) {
$xml = preg_replace("/$cdp_search/s", "$cdp{$cdp_replace}", $xml);
}
- foreach($ds_arr as $ds) {
+ foreach ($ds_arr as $ds) {
$xml = preg_replace("/$value_search/s", "$value{$value_replace}", $xml);
}
-
+
file_put_contents("{$g['tmp_path']}/{$xmldumpnew}", $xml);
mwexec("$rrdtool restore -f {$g['tmp_path']}/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1");
unset($xml);
@@ -2799,16 +2923,19 @@ function upgrade_080_to_081() {
unlink_if_exists("{$g['tmp_path']}/{$xmldump}");
unlink_if_exists("{$g['tmp_path']}/{$xmldumpnew}");
}
- if (!platform_booting())
+ if (!platform_booting()) {
enable_rrd_graphing();
+ }
/* Let's save the RRD graphs after we run enable RRD graphing */
/* The function will restore the rrd.tgz so we will save it after */
exec("cd /; LANG=C NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='{$g['cf_conf_path']}' /etc/rc.backup_rrd.sh");
- if (platform_booting())
+ if (platform_booting()) {
echo "Updating configuration...";
- foreach($config['filter']['rule'] as & $rule) {
- if (isset($rule['protocol']) && !empty($rule['protocol']))
+ }
+ foreach ($config['filter']['rule'] as & $rule) {
+ if (isset($rule['protocol']) && !empty($rule['protocol'])) {
$rule['protocol'] = strtolower($rule['protocol']);
+ }
}
unset($rule);
}
@@ -2828,8 +2955,9 @@ function upgrade_082_to_083() {
$config['captiveportal']['cpzone'] = $tmpcp;
$config['captiveportal']['cpzone']['zoneid'] = 8000;
$config['captiveportal']['cpzone']['zone'] = "cpzone";
- if ($config['captiveportal']['cpzone']['auth_method'] == "radius")
+ if ($config['captiveportal']['cpzone']['auth_method'] == "radius") {
$config['captiveportal']['cpzone']['radius_protocol'] = "PAP";
+ }
}
if (!empty($config['voucher'])) {
$tmpcp = $config['voucher'];
@@ -2864,8 +2992,8 @@ function upgrade_084_to_085() {
$gateways = return_gateways_array();
$oldnames = array();
/* setup translation array */
- foreach($gateways as $name => $gw) {
- if(isset($gw['dynamic'])){
+ foreach ($gateways as $name => $gw) {
+ if (isset($gw['dynamic'])) {
$oldname = strtoupper($config['interfaces'][$gw['friendlyiface']]['descr']);
$oldnames[$oldname] = $name;
} else {
@@ -2874,14 +3002,14 @@ function upgrade_084_to_085() {
}
/* process the old array */
- if(is_array($config['gateways']['gateway_group'])) {
+ if (is_array($config['gateways']['gateway_group'])) {
$group_array_new = array();
- foreach($config['gateways']['gateway_group'] as $name => $group) {
- if(is_array($group['item'])) {
+ foreach ($config['gateways']['gateway_group'] as $name => $group) {
+ if (is_array($group['item'])) {
$newlist = array();
- foreach($group['item'] as $entry) {
+ foreach ($group['item'] as $entry) {
$elements = explode("|", $entry);
- if($oldnames[$elements[0]] <> "") {
+ if ($oldnames[$elements[0]] <> "") {
$newlist[] = "{$oldnames[$elements[0]]}|{$elements[1]}";
} else {
$newlist[] = "{$elements[0]}|{$elements[1]}";
@@ -2895,8 +3023,8 @@ function upgrade_084_to_085() {
}
/* rename old Quality RRD files in the process */
$rrddbpath = "/var/db/rrd";
- foreach($oldnames as $old => $new) {
- if(is_readable("{$rrddbpath}/{$old}-quality.rrd")) {
+ foreach ($oldnames as $old => $new) {
+ if (is_readable("{$rrddbpath}/{$old}-quality.rrd")) {
@rename("{$rrddbpath}/{$old}-quality.rrd", "{$rrddbpath}/{$new}-quality.rrd");
}
}
@@ -2910,8 +3038,9 @@ function upgrade_085_to_086() {
if (is_array($config['virtualip']['vip'])) {
$vipchg = array();
foreach ($config['virtualip']['vip'] as $vip) {
- if ($vip['mode'] != "carp")
+ if ($vip['mode'] != "carp") {
continue;
+ }
$config = array_replace_values_recursive(
$config,
'^vip' . $vip['vhid'] . '$',
@@ -2924,10 +3053,12 @@ function upgrade_085_to_086() {
function upgrade_086_to_087() {
global $config, $dummynet_pipe_list;
- if (!is_array($config['filter']) || !is_array($config['filter']['rule']))
+ if (!is_array($config['filter']) || !is_array($config['filter']['rule'])) {
return;
- if (!is_array($config['dnshaper']) || !is_array($config['dnshaper']['queue']))
+ }
+ if (!is_array($config['dnshaper']) || !is_array($config['dnshaper']['queue'])) {
return;
+ }
$dnqueue_number = 1;
$dnpipe_number = 1;
@@ -2961,12 +3092,14 @@ function upgrade_086_to_087() {
foreach ($config['filter']['rule'] as $idx => $rule) {
if (!empty($rule['dnpipe'])) {
- if (!empty($dn_list[$rule['dnpipe']]))
+ if (!empty($dn_list[$rule['dnpipe']])) {
$config['filter']['rule'][$idx]['dnpipe'] = $dn_list[$rule['dnpipe']];
+ }
}
if (!empty($rule['pdnpipe'])) {
- if (!empty($dn_list[$rule['pdnpipe']]))
+ if (!empty($dn_list[$rule['pdnpipe']])) {
$config['filter']['rule'][$idx]['pdnpipe'] = $dn_list[$rule['pdnpipe']];
+ }
}
}
}
@@ -2980,10 +3113,12 @@ function upgrade_087_to_088() {
function upgrade_088_to_089() {
global $config;
- if (!is_array($config['ca']))
+ if (!is_array($config['ca'])) {
$config['ca'] = array();
- if (!is_array($config['cert']))
+ }
+ if (!is_array($config['cert'])) {
$config['cert'] = array();
+ }
/* migrate captive portal ssl to certificate manager */
if (is_array($config['captiveportal'])) {
@@ -3074,13 +3209,16 @@ function upgrade_092_to_093() {
$suffixes = array("concurrent", "loggedin");
- foreach ($suffixes as $suffix)
- if (file_exists("{$g['vardb_path']}/rrd/captiveportal-{$suffix}.rrd"))
+ foreach ($suffixes as $suffix) {
+ if (file_exists("{$g['vardb_path']}/rrd/captiveportal-{$suffix}.rrd")) {
rename("{$g['vardb_path']}/rrd/captiveportal-{$suffix}.rrd",
"{$g['vardb_path']}/rrd/captiveportal-cpZone-{$suffix}.rrd");
+ }
+ }
- if (!platform_booting())
+ if (!platform_booting()) {
enable_rrd_graphing();
+ }
}
function upgrade_093_to_094() {
@@ -3096,13 +3234,17 @@ function upgrade_093_to_094() {
function upgrade_094_to_095() {
global $config;
- if (!isset($config['interfaces']) || !is_array($config['interfaces']))
+ if (!isset($config['interfaces']) || !is_array($config['interfaces'])) {
return;
+ }
- foreach ($config['interfaces'] as $iface => $cfg)
- if (isset($cfg['ipaddrv6']) && ($cfg['ipaddrv6'] == "track6"))
- if (!isset($cfg['track6-prefix-id']) || ($cfg['track6-prefix-id'] == ""))
+ foreach ($config['interfaces'] as $iface => $cfg) {
+ if (isset($cfg['ipaddrv6']) && ($cfg['ipaddrv6'] == "track6")) {
+ if (!isset($cfg['track6-prefix-id']) || ($cfg['track6-prefix-id'] == "")) {
$config['interfaces'][$iface]['track6-prefix-id'] = 0;
+ }
+ }
+ }
}
function upgrade_095_to_096() {
@@ -3127,18 +3269,21 @@ function upgrade_095_to_096() {
/* build a list of traffic and packets databases */
$databases = return_dir_as_array($rrddbpath, '/-(traffic|packets)\.rrd$/');
rsort($databases);
- foreach($databases as $database) {
- if (platform_booting())
+ foreach ($databases as $database) {
+ if (platform_booting()) {
echo "Update RRD database {$database}.\n";
+ }
$cmd = "{$rrdtool} tune {$rrddbpath}/{$database}";
- foreach ($names as $name)
+ foreach ($names as $name) {
$cmd .= " -a {$name}:{$stream}";
+ }
mwexec("{$cmd} 2>&1");
}
- if (!platform_booting())
+ if (!platform_booting()) {
enable_rrd_graphing();
+ }
/* Let's save the RRD graphs after we run enable RRD graphing */
/* The function will restore the rrd.tgz so we will save it after */
exec("cd /; LANG=C NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='{$g['cf_conf_path']}' /etc/rc.backup_rrd.sh");
@@ -3162,8 +3307,9 @@ function upgrade_097_to_098() {
function upgrade_098_to_099() {
global $config;
- if (empty($config['dhcpd']) || !is_array($config['dhcpd']))
+ if (empty($config['dhcpd']) || !is_array($config['dhcpd'])) {
return;
+ }
foreach ($config['dhcpd'] as & $dhcpifconf) {
if (isset($dhcpifconf['next-server'])) {
@@ -3181,15 +3327,18 @@ function upgrade_099_to_100() {
function upgrade_100_to_101() {
global $config, $g;
- if (!is_array($config['voucher']))
+ if (!is_array($config['voucher'])) {
return;
+ }
foreach ($config['voucher'] as $cpzone => $cp) {
- if (!is_array($cp['roll']))
+ if (!is_array($cp['roll'])) {
continue;
+ }
foreach ($cp['roll'] as $ridx => $rcfg) {
- if (!empty($rcfg['comment']))
+ if (!empty($rcfg['comment'])) {
$config['voucher'][$cpzone]['roll'][$ridx]['descr'] = $rcfg['comment'];
+ }
}
}
}
@@ -3199,11 +3348,13 @@ function upgrade_101_to_102() {
if (is_array($config['captiveportal'])) {
foreach ($config['captiveportal'] as $cpzone => $cp) {
- if (!is_array($cp['passthrumac']))
+ if (!is_array($cp['passthrumac'])) {
continue;
+ }
- foreach ($cp['passthrumac'] as $idx => $passthrumac)
+ foreach ($cp['passthrumac'] as $idx => $passthrumac) {
$config['captiveportal'][$cpzone]['passthrumac'][$idx]['action'] = 'pass';
+ }
}
}
@@ -3212,14 +3363,16 @@ function upgrade_101_to_102() {
if (isset($config['openvpn']) && is_array($config['openvpn'])) {
if (is_array($config['openvpn']['openvpn-server'])) {
foreach ($config['openvpn']['openvpn-server'] as &$vpn) {
- if (!empty($vpn['compression']))
+ if (!empty($vpn['compression'])) {
$vpn['compression'] = "adaptive";
+ }
}
}
if (is_array($config['openvpn']['openvpn-client'])) {
foreach ($config['openvpn']['openvpn-client'] as &$vpn) {
- if (!empty($vpn['compression']))
+ if (!empty($vpn['compression'])) {
$vpn['compression'] = "adaptive";
+ }
}
}
}
@@ -3231,8 +3384,9 @@ function upgrade_102_to_103() {
if (isset($config['nat']['advancedoutbound']['enable'])) {
$config['nat']['advancedoutbound']['mode'] = "advanced";
unset($config['nat']['advancedoutbound']['enable']);
- } else
+ } else {
$config['nat']['advancedoutbound']['mode'] = "automatic";
+ }
$config['nat']['outbound'] = $config['nat']['advancedoutbound'];
@@ -3252,21 +3406,25 @@ function upgrade_103_to_104() {
/* update user privileges */
foreach ($config['system']['user'] as & $user) {
- if (!is_array($user['priv']))
+ if (!is_array($user['priv'])) {
continue;
+ }
foreach ($user['priv'] as & $priv) {
- if (array_key_exists($priv, $changed_privs))
+ if (array_key_exists($priv, $changed_privs)) {
$priv = $changed_privs[$priv];
+ }
}
}
/* update group privileges */
foreach ($config['system']['group'] as & $group) {
- if (!is_array($group['priv']))
+ if (!is_array($group['priv'])) {
continue;
+ }
foreach ($group['priv'] as & $priv) {
- if (array_key_exists($priv, $changed_privs))
+ if (array_key_exists($priv, $changed_privs)) {
$priv = $changed_privs[$priv];
+ }
}
}
@@ -3316,7 +3474,6 @@ function upgrade_106_to_107() {
$config['nat']['rule'][$ridx]['tracker'] = $tracker;
$tracker++;
}
-
}
unset($tracker, $ridx);
}
@@ -3325,25 +3482,29 @@ function upgrade_106_to_107() {
function upgrade_107_to_108() {
global $config;
- if (isset($config['system']['webgui']['noautocomplete']))
+ if (isset($config['system']['webgui']['noautocomplete'])) {
unset($config['system']['webgui']['noautocomplete']);
- else
+ } else {
$config['system']['webgui']['loginautocomplete'] = true;
+ }
}
function upgrade_108_to_109() {
global $config;
- if (!isset($config['filter']['rule']) || !is_array($config['filter']['rule']))
+ if (!isset($config['filter']['rule']) || !is_array($config['filter']['rule'])) {
return;
+ }
foreach ($config['filter']['rule'] as &$rule) {
- if (!isset($rule['dscp']) || empty($rule['dscp']))
+ if (!isset($rule['dscp']) || empty($rule['dscp'])) {
continue;
+ }
$pos = strpos($rule['dscp'], ' ');
- if ($pos !== false)
+ if ($pos !== false) {
$rule['dscp'] = substr($rule['dscp'], 0, $pos);
+ }
unset($pos);
}
}
@@ -3351,12 +3512,14 @@ function upgrade_108_to_109() {
function upgrade_109_to_110() {
global $config;
- if (!is_array($config['ipsec']) || !is_array($config['ipsec']['phase2']))
+ if (!is_array($config['ipsec']) || !is_array($config['ipsec']['phase2'])) {
return;
+ }
foreach ($config['ipsec']['phase2'] as &$rule) {
- if (!empty($rule['uniqid']))
+ if (!empty($rule['uniqid'])) {
continue;
+ }
$rule['uniqid'] = uniqid();
}
@@ -3381,8 +3544,9 @@ function upgrade_110_to_111() {
/* Remove old menu and service entries */
if (isset($config['installedpackages']['menu']) && is_array($config['installedpackages']['menu'])) {
foreach ($config['installedpackages']['menu'] as $idx => $menu) {
- if ($menu['name'] != 'Unbound DNS')
+ if ($menu['name'] != 'Unbound DNS') {
continue;
+ }
unset($config['installedpackages']['menu'][$idx]);
break;
@@ -3391,20 +3555,23 @@ function upgrade_110_to_111() {
if (isset($config['installedpackages']['service']) && is_array($config['installedpackages']['service'])) {
foreach ($config['installedpackages']['service'] as $idx => $service) {
- if ($service['name'] != 'unbound')
+ if ($service['name'] != 'unbound') {
continue;
+ }
unset($config['installedpackages']['service'][$idx]);
break;
}
}
- if (!isset($config['installedpackages']['unbound']['config'][0]))
+ if (!isset($config['installedpackages']['unbound']['config'][0])) {
return;
+ }
$pkg = $config['installedpackages']['unbound']['config'][0];
- if (isset($config['installedpackages']['unboundadvanced']['config'][0]))
+ if (isset($config['installedpackages']['unboundadvanced']['config'][0])) {
$pkg = array_merge($pkg, $config['installedpackages']['unboundadvanced']['config'][0]);
+ }
$new = array();
@@ -3425,8 +3592,9 @@ function upgrade_110_to_111() {
foreach ($fields as $oldk => $newk) {
if (isset($pkg[$oldk])) {
- if ($pkg[$oldk] == 'on')
+ if ($pkg[$oldk] == 'on') {
$new[$newk] = true;
+ }
unset($pkg[$oldk]);
}
}
@@ -3456,36 +3624,44 @@ function upgrade_110_to_111() {
}
}
- if (isset($new['custom_options']) && !empty($new['custom_options']))
+ if (isset($new['custom_options']) && !empty($new['custom_options'])) {
$new['custom_options'] = str_replace("\r\n", "\n", $new['custom_options']);
+ }
/* Following options were removed, bring them as custom_options */
if (isset($pkg['stats']) && $pkg['stats'] == "on") {
- if (isset($pkg['stats_interval']))
+ if (isset($pkg['stats_interval'])) {
$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "statistics-interval: {$pkg['stats_interval']}";
- if (isset($pkg['cumulative_stats']))
+ }
+ if (isset($pkg['cumulative_stats'])) {
$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "statistics-cumulative: {$pkg['cumulative_stats']}";
- if (isset($pkg['extended_stats']) && $pkg['extended_stats'] == "on")
+ }
+ if (isset($pkg['extended_stats']) && $pkg['extended_stats'] == "on") {
$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "extended-statistics: yes";
- else
+ } else {
$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "extended-statistics: no";
+ }
}
$new['acls'] = array();
if (isset($config['installedpackages']['unboundacls']['config']) &&
is_array($config['installedpackages']['unboundacls']['config'])) {
- foreach ($config['installedpackages']['unboundacls']['config'] as $acl)
+ foreach ($config['installedpackages']['unboundacls']['config'] as $acl) {
$new['acls'][] = $acl;
+ }
}
$config['unbound'] = $new;
- if(isset($config['installedpackages']['unbound']))
+ if (isset($config['installedpackages']['unbound'])) {
unset($config['installedpackages']['unbound']);
- if(isset($config['installedpackages']['unboundadvanced']))
+ }
+ if (isset($config['installedpackages']['unboundadvanced'])) {
unset($config['installedpackages']['unboundadvanced']);
- if(isset($config['installedpackages']['unboundacls']))
+ }
+ if (isset($config['installedpackages']['unboundacls'])) {
unset($config['installedpackages']['unboundacls']);
+ }
unset($pkg, $new);
}
@@ -3508,64 +3684,74 @@ function upgrade_112_to_113() {
global $config;
if (isset($config['notifications']['smtp']['ssl']) &&
- $config['notifications']['smtp']['ssl'] == "checked")
+ $config['notifications']['smtp']['ssl'] == "checked") {
$config['notifications']['smtp']['ssl'] = true;
- else
+ } else {
unset($config['notifications']['smtp']['ssl']);
+ }
if (isset($config['notifications']['smtp']['tls']) &&
- $config['notifications']['smtp']['tls'] == "checked")
+ $config['notifications']['smtp']['tls'] == "checked") {
$config['notifications']['smtp']['tls'] = true;
- else
+ } else {
unset($config['notifications']['smtp']['tls']);
+ }
}
function upgrade_113_to_114() {
global $config;
if (!isset($config['ipsec']['phase1']) ||
- !is_array($config['ipsec']['phase1']))
+ !is_array($config['ipsec']['phase1'])) {
return;
+ }
- foreach($config['ipsec']['phase1'] as &$ph1ent)
- if (!isset($ph1ent['iketype']))
+ foreach ($config['ipsec']['phase1'] as &$ph1ent) {
+ if (!isset($ph1ent['iketype'])) {
$ph1ent['iketype'] = 'ikev1';
+ }
+ }
}
function upgrade_114_to_115() {
global $config;
- if (isset($config['unbound']['custom_options']))
+ if (isset($config['unbound']['custom_options'])) {
$config['unbound']['custom_options'] = base64_encode($config['unbound']['custom_options']);
+ }
}
function upgrade_115_to_116() {
global $config;
- if (!is_array($config['ipsec']) || !is_array($config['ipsec']['phase2']))
- return;
+ if (!is_array($config['ipsec']) || !is_array($config['ipsec']['phase2'])) {
+ return;
+ }
- $keyid = 1;
- foreach ($config['ipsec']['phase2'] as $idx => $ph2) {
- $config['ipsec']['phase2'][$idx]['reqid'] = $keyid;
+ $keyid = 1;
+ foreach ($config['ipsec']['phase2'] as $idx => $ph2) {
+ $config['ipsec']['phase2'][$idx]['reqid'] = $keyid;
$keyid++;
}
}
function upgrade_116_to_117() {
- global $config;
+ global $config;
- if (!isset($config['installedpackages']['miniupnpd']['config'][0]))
+ if (!isset($config['installedpackages']['miniupnpd']['config'][0])) {
return;
+ }
$miniupnpd =& $config['installedpackages']['miniupnpd']['config'][0];
$miniupnpd['row'] = array();
for ($i = 1; $i <= 4; $i++) {
- if (isset($miniupnpd["permuser{$i}"]) && !empty($miniupnpd["permuser{$i}"]))
+ if (isset($miniupnpd["permuser{$i}"]) && !empty($miniupnpd["permuser{$i}"])) {
$miniupnpd['row'][] = array('permuser' => $miniupnpd["permuser{$i}"]);
+ }
unset($miniupnpd["permuser{$i}"]);
}
}
?>
+
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index 993c4df..05b33ed 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -64,32 +64,37 @@ function isvalidproc($proc) {
/* sigkill a process by pid file */
/* return 1 for success and 0 for a failure */
function sigkillbypid($pidfile, $sig) {
- if (file_exists($pidfile))
+ if (file_exists($pidfile)) {
return mwexec("/bin/pkill " . escapeshellarg("-{$sig}") . " -F {$pidfile}", true);
+ }
return 0;
}
/* kill a process by name */
function sigkillbyname($procname, $sig) {
- if(isvalidproc($procname))
+ if (isvalidproc($procname)) {
return mwexec("/usr/bin/killall " . escapeshellarg("-{$sig}") . " " . escapeshellarg($procname), true);
+ }
}
/* kill a process by name */
function killbyname($procname) {
- if(isvalidproc($procname))
+ if (isvalidproc($procname)) {
mwexec("/usr/bin/killall " . escapeshellarg($procname));
+ }
}
function is_subsystem_dirty($subsystem = "") {
global $g;
- if ($subsystem == "")
+ if ($subsystem == "") {
return false;
+ }
- if (file_exists("{$g['varrun_path']}/{$subsystem}.dirty"))
+ if (file_exists("{$g['varrun_path']}/{$subsystem}.dirty")) {
return true;
+ }
return false;
}
@@ -97,8 +102,9 @@ function is_subsystem_dirty($subsystem = "") {
function mark_subsystem_dirty($subsystem = "") {
global $g;
- if (!file_put_contents("{$g['varrun_path']}/{$subsystem}.dirty", "DIRTY"))
+ if (!file_put_contents("{$g['varrun_path']}/{$subsystem}.dirty", "DIRTY")) {
log_error(sprintf(gettext("WARNING: Could not mark subsystem: %s dirty"), $subsystem));
+ }
}
function clear_subsystem_dirty($subsystem = "") {
@@ -117,25 +123,28 @@ function config_unlock() {
/* lock configuration file */
function lock($lock, $op = LOCK_SH) {
global $g, $cfglckkeyconsumers;
- if (!$lock)
+ if (!$lock) {
die(gettext("WARNING: You must give a name as parameter to lock() function."));
+ }
if (!file_exists("{$g['tmp_path']}/{$lock}.lock")) {
@touch("{$g['tmp_path']}/{$lock}.lock");
@chmod("{$g['tmp_path']}/{$lock}.lock", 0666);
}
$cfglckkeyconsumers++;
if ($fp = fopen("{$g['tmp_path']}/{$lock}.lock", "w")) {
- if (flock($fp, $op))
+ if (flock($fp, $op)) {
return $fp;
- else
+ } else {
fclose($fp);
+ }
}
}
function try_lock($lock, $timeout = 5) {
global $g, $cfglckkeyconsumers;
- if (!$lock)
+ if (!$lock) {
die(gettext("WARNING: You must give a name as parameter to try_lock() function."));
+ }
if (!file_exists("{$g['tmp_path']}/{$lock}.lock")) {
@touch("{$g['tmp_path']}/{$lock}.lock");
@chmod("{$g['tmp_path']}/{$lock}.lock", 0666);
@@ -143,7 +152,7 @@ function try_lock($lock, $timeout = 5) {
$cfglckkeyconsumers++;
if ($fp = fopen("{$g['tmp_path']}/{$lock}.lock", "w")) {
$trycounter = 0;
- while(!flock($fp, LOCK_EX | LOCK_NB)) {
+ while (!flock($fp, LOCK_EX | LOCK_NB)) {
if ($trycounter >= $timeout) {
fclose($fp);
return NULL;
@@ -176,8 +185,9 @@ function unlock_force($lock) {
function send_event($cmd) {
global $g;
- if(!isset($g['event_address']))
+ if (!isset($g['event_address'])) {
$g['event_address'] = "unix:///var/run/check_reload_status";
+ }
$try = 0;
while ($try < 3) {
@@ -185,12 +195,14 @@ function send_event($cmd) {
if ($fd) {
fwrite($fd, $cmd);
$resp = fread($fd, 4096);
- if ($resp != "OK\n")
+ if ($resp != "OK\n") {
log_error("send_event: sent {$cmd} got {$resp}");
+ }
fclose($fd);
$try = 3;
- } else if (!is_process_running("check_reload_status"))
+ } else if (!is_process_running("check_reload_status")) {
mwexec_bg("/usr/bin/nice -n20 /usr/local/sbin/check_reload_status");
+ }
$try++;
}
}
@@ -198,11 +210,13 @@ function send_event($cmd) {
function send_multiple_events($cmds) {
global $g;
- if(!isset($g['event_address']))
+ if (!isset($g['event_address'])) {
$g['event_address'] = "unix:///var/run/check_reload_status";
+ }
- if (!is_array($cmds))
+ if (!is_array($cmds)) {
return;
+ }
while ($try < 3) {
$fd = @fsockopen($g['event_address']);
@@ -210,13 +224,15 @@ function send_multiple_events($cmds) {
foreach ($cmds as $cmd) {
fwrite($fd, $cmd);
$resp = fread($fd, 4096);
- if ($resp != "OK\n")
+ if ($resp != "OK\n") {
log_error("send_event: sent {$cmd} got {$resp}");
+ }
}
fclose($fd);
$try = 3;
- } else if (!is_process_running("check_reload_status"))
+ } else if (!is_process_running("check_reload_status")) {
mwexec_bg("/usr/bin/nice -n20 /usr/local/sbin/check_reload_status");
+ }
$try++;
}
}
@@ -271,8 +287,9 @@ function refcount_unreference($reference) {
if ($shm_data < 0) {
//debug_backtrace();
log_error(sprintf(gettext("Reference %s is going negative, not doing unreference."), $reference));
- } else
+ } else {
@shmop_write($shmid, str_pad($shm_data, 10, "\x0", STR_PAD_RIGHT), 0);
+ }
@shmop_close($shmid);
unlock($shm_lck);
} catch (Exception $e) {
@@ -300,30 +317,33 @@ function is_module_loaded($module_name) {
$module_name = str_replace(".ko", "", $module_name);
$running = 0;
$_gb = exec("/sbin/kldstat -qn {$module_name} 2>&1", $_gb, $running);
- if (intval($running) == 0)
+ if (intval($running) == 0) {
return true;
- else
+ } else {
return false;
+ }
}
/* validate non-negative numeric string, or equivalent numeric variable */
function is_numericint($arg) {
- return (((is_int($arg) && $arg >= 0) || (is_string($arg) && strlen($arg) > 0 && ctype_digit($arg))) ? true : false);
+ return (((is_int($arg) && $arg >= 0) || (is_string($arg) && strlen($arg) > 0 && ctype_digit($arg))) ? true : false);
}
-/* Generate the (human readable) ipv4 or ipv6 subnet address (i.e., netmask, or subnet start IP)
+/* Generate the (human readable) ipv4 or ipv6 subnet address (i.e., netmask, or subnet start IP)
given an (human readable) ipv4 or ipv6 host address and subnet bit count */
function gen_subnet($ipaddr, $bits) {
- if (($sn = gen_subnetv6($ipaddr, $bits)) == '')
+ if (($sn = gen_subnetv6($ipaddr, $bits)) == '') {
$sn = gen_subnetv4($ipaddr, $bits); // try to avoid rechecking IPv4/v6
+ }
return $sn;
}
/* same as gen_subnet() but accepts IPv4 only */
function gen_subnetv4($ipaddr, $bits) {
if (is_ipaddrv4($ipaddr) && is_numericint($bits) && $bits <= 32) {
- if ($bits == 0)
+ if ($bits == 0) {
return '0.0.0.0'; // avoids <<32
+ }
return long2ip(ip2long($ipaddr) & ((0xFFFFFFFF << (32 - $bits)) & 0xFFFFFFFF));
}
return "";
@@ -331,24 +351,27 @@ function gen_subnetv4($ipaddr, $bits) {
/* same as gen_subnet() but accepts IPv6 only */
function gen_subnetv6($ipaddr, $bits) {
- if (is_ipaddrv6($ipaddr) && is_numericint($bits) && $bits <= 128)
+ if (is_ipaddrv6($ipaddr) && is_numericint($bits) && $bits <= 128) {
return Net_IPv6::compress(Net_IPv6::getNetmask($ipaddr, $bits));
+ }
return "";
}
/* Generate the (human readable) ipv4 or ipv6 subnet end address (i.e., highest address, end IP, or IPv4 broadcast address)
given an (human readable) ipv4 or ipv6 host address and subnet bit count. */
function gen_subnet_max($ipaddr, $bits) {
- if (($sn = gen_subnetv6_max($ipaddr, $bits)) == '')
+ if (($sn = gen_subnetv6_max($ipaddr, $bits)) == '') {
$sn = gen_subnetv4_max($ipaddr, $bits); // try to avoid rechecking IPv4/v6
+ }
return $sn;
}
/* same as gen_subnet_max() but validates IPv4 only */
function gen_subnetv4_max($ipaddr, $bits) {
if (is_ipaddrv4($ipaddr) && is_numericint($bits) && $bits <= 32) {
- if ($bits == 32)
+ if ($bits == 32) {
return $ipaddr;
+ }
return long2ip32(ip2long($ipaddr) | ~gen_subnet_mask_long($bits));
}
return "";
@@ -385,7 +408,7 @@ function long2ip32($ip) {
/* Convert IP address to long int, truncated to 32-bits to avoid sign extension on 64-bit platforms. */
function ip2long32($ip) {
- return ( ip2long($ip) & 0xFFFFFFFF );
+ return (ip2long($ip) & 0xFFFFFFFF);
}
/* Convert IP address to unsigned long int. */
@@ -442,12 +465,13 @@ function ip_greater_than($ip1, $ip2) {
/* compare two IP addresses */
function ipcmp($a, $b) {
- if (ip_less_than($a, $b))
+ if (ip_less_than($a, $b)) {
return -1;
- else if (ip_greater_than($a, $b))
+ } else if (ip_greater_than($a, $b)) {
return 1;
- else
+ } else {
return 0;
+ }
}
/* Convert a range of IPv4 addresses to an array of individual addresses. */
@@ -464,9 +488,10 @@ function ip_range_to_address_array($startip, $endip, $max_size = 5000) {
$endip = $temp;
}
- if (ip_range_size_v4($startip, $endip) > $max_size)
+ if (ip_range_size_v4($startip, $endip) > $max_size) {
return false;
-
+ }
+
// Container for IP addresses within this range.
$rangeaddresses = array();
$end_int = ip2ulong($endip);
@@ -547,28 +572,30 @@ function ip_range_to_subnet_array($startip, $endip) {
}
/* returns true if $range is a valid pair of IPv4 or IPv6 addresses separated by a "-"
- false - if not a valid pair
- true (numeric 4 or 6) - if valid, gives type of addresses */
+ false - if not a valid pair
+ true (numeric 4 or 6) - if valid, gives type of addresses */
function is_iprange($range) {
if (substr_count($range, '-') != 1) {
return false;
}
list($ip1, $ip2) = explode ('-', $range);
- if (is_ipaddrv4($ip1) && is_ipaddrv4($ip2))
+ if (is_ipaddrv4($ip1) && is_ipaddrv4($ip2)) {
return 4;
- if (is_ipaddrv6($ip1) && is_ipaddrv6($ip2))
+ }
+ if (is_ipaddrv6($ip1) && is_ipaddrv6($ip2)) {
return 6;
+ }
return false;
}
/* returns true if $ipaddr is a valid dotted IPv4 address or a IPv6
- false - not valid
- true (numeric 4 or 6) - if valid, gives type of address */
+ false - not valid
+ true (numeric 4 or 6) - if valid, gives type of address */
function is_ipaddr($ipaddr) {
- if(is_ipaddrv4($ipaddr)) {
+ if (is_ipaddrv4($ipaddr)) {
return 4;
}
- if(is_ipaddrv6($ipaddr)) {
+ if (is_ipaddrv6($ipaddr)) {
return 6;
}
return false;
@@ -576,8 +603,9 @@ function is_ipaddr($ipaddr) {
/* returns true if $ipaddr is a valid IPv6 address */
function is_ipaddrv6($ipaddr) {
- if (!is_string($ipaddr) || empty($ipaddr))
+ if (!is_string($ipaddr) || empty($ipaddr)) {
return false;
+ }
if (strstr($ipaddr, "%") && is_linklocal($ipaddr)) {
$tmpip = explode("%", $ipaddr);
$ipaddr = $tmpip[0];
@@ -587,16 +615,18 @@ function is_ipaddrv6($ipaddr) {
/* returns true if $ipaddr is a valid dotted IPv4 address */
function is_ipaddrv4($ipaddr) {
- if (!is_string($ipaddr) || empty($ipaddr))
+ if (!is_string($ipaddr) || empty($ipaddr)) {
return false;
+ }
$ip_long = ip2long($ipaddr);
$ip_reverse = long2ip32($ip_long);
- if ($ipaddr == $ip_reverse)
+ if ($ipaddr == $ip_reverse) {
return true;
- else
+ } else {
return false;
+ }
}
/* returns true if $ipaddr is a valid IPv6 linklocal address */
@@ -606,40 +636,45 @@ function is_linklocal($ipaddr) {
/* returns scope of a linklocal address */
function get_ll_scope($addr) {
- if (!is_linklocal($addr) || !strstr($addr, "%"))
+ if (!is_linklocal($addr) || !strstr($addr, "%")) {
return "";
+ }
list ($ll, $scope) = explode("%", $addr);
return $scope;
}
/* returns true if $ipaddr is a valid literal IPv6 address */
function is_literalipaddrv6($ipaddr) {
- if(preg_match("/\[([0-9a-f:]+)\]/i", $ipaddr, $match))
+ if (preg_match("/\[([0-9a-f:]+)\]/i", $ipaddr, $match)) {
$ipaddr = $match[1];
- else
+ } else {
return false;
+ }
return is_ipaddrv6($ipaddr);
}
/* returns true if $iport is a valid IPv4/IPv6 address + port
- false - not valid
- true (numeric 4 or 6) - if valid, gives type of address */
+ false - not valid
+ true (numeric 4 or 6) - if valid, gives type of address */
function is_ipaddrwithport($ipport) {
$c = strrpos($ipport, ":");
- if ($c === false)
+ if ($c === false) {
return false; // can't split at final colon if no colon exists
-
- if (!is_port(substr($ipport, $c + 1)))
+ }
+
+ if (!is_port(substr($ipport, $c + 1))) {
return false; // no valid port after last colon
+ }
$ip = substr($ipport, 0, $c); // else is text before last colon a valid IP
- if (is_literalipaddrv6($ip))
+ if (is_literalipaddrv6($ip)) {
return 6;
- elseif (is_ipaddrv4($ip))
+ } elseif (is_ipaddrv4($ip)) {
return 4;
- else
+ } else {
return false;
+ }
}
function is_hostnamewithport($hostport) {
@@ -659,25 +694,29 @@ function is_ipaddroralias($ipaddr) {
if (is_alias($ipaddr)) {
if (is_array($config['aliases']['alias'])) {
foreach ($config['aliases']['alias'] as $alias) {
- if ($alias['name'] == $ipaddr && !preg_match("/port/i", $alias['type']))
+ if ($alias['name'] == $ipaddr && !preg_match("/port/i", $alias['type'])) {
return true;
+ }
}
}
return false;
- } else
+ } else {
return is_ipaddr($ipaddr);
+ }
}
/* returns true if $subnet is a valid IPv4 or IPv6 subnet in CIDR format
- false - if not a valid subnet
- true (numeric 4 or 6) - if valid, gives type of subnet */
+ false - if not a valid subnet
+ true (numeric 4 or 6) - if valid, gives type of subnet */
function is_subnet($subnet) {
if (is_string($subnet) && preg_match('/^(?:([0-9.]{7,15})|([0-9a-f:]{2,39}))\/(\d{1,3})$/i', $subnet, $parts)) {
- if (is_ipaddrv4($parts[1]) && $parts[3] <= 32)
+ if (is_ipaddrv4($parts[1]) && $parts[3] <= 32) {
return 4;
- if (is_ipaddrv6($parts[2]) && $parts[3] <= 128)
+ }
+ if (is_ipaddrv6($parts[2]) && $parts[3] <= 128) {
return 6;
+ }
}
return false;
}
@@ -696,10 +735,11 @@ function is_subnetv6($subnet) {
function is_subnetoralias($subnet) {
global $aliastable;
- if (isset($aliastable[$subnet]) && is_subnet($aliastable[$subnet]))
+ if (isset($aliastable[$subnet]) && is_subnet($aliastable[$subnet])) {
return true;
- else
+ } else {
return is_subnet($subnet);
+ }
}
function subnet_size($subnet) {
@@ -743,15 +783,18 @@ function subnetv4_expand($subnet) {
/* find out whether two subnets overlap */
function check_subnets_overlap($subnet1, $bits1, $subnet2, $bits2) {
- if (!is_numeric($bits1))
+ if (!is_numeric($bits1)) {
$bits1 = 32;
- if (!is_numeric($bits2))
+ }
+ if (!is_numeric($bits2)) {
$bits2 = 32;
+ }
- if ($bits1 < $bits2)
+ if ($bits1 < $bits2) {
$relbits = $bits1;
- else
+ } else {
$relbits = $bits2;
+ }
$sn1 = gen_subnet_mask_long($relbits) & ip2long($subnet1);
$sn2 = gen_subnet_mask_long($relbits) & ip2long($subnet2);
@@ -771,7 +814,7 @@ function check_subnetsv6_overlap($subnet1, $bits1, $subnet2, $bits2) {
/* return true if $addr is in $subnet, false if not */
function ip_in_subnet($addr,$subnet) {
- if(is_ipaddrv6($addr) && is_subnetv6($subnet)) {
+ if (is_ipaddrv6($addr) && is_subnetv6($subnet)) {
return (Net_IPv6::isInNetmask($addr, $subnet));
} else if (is_ipaddrv4($addr) && is_subnetv4($subnet)) {
list($ip, $mask) = explode('/', $subnet);
@@ -783,40 +826,46 @@ function ip_in_subnet($addr,$subnet) {
/* returns true if $hostname is just a valid hostname (top part without any of the domain part) */
function is_unqualified_hostname($hostname) {
- if (!is_string($hostname))
+ if (!is_string($hostname)) {
return false;
+ }
- if (preg_match('/^(?:[a-z0-9_]|[a-z0-9_][a-z0-9_\-]*[a-z0-9_])$/i', $hostname))
+ if (preg_match('/^(?:[a-z0-9_]|[a-z0-9_][a-z0-9_\-]*[a-z0-9_])$/i', $hostname)) {
return true;
- else
+ } else {
return false;
+ }
}
/* returns true if $hostname is a valid hostname, with or without being a fully-qualified domain name. */
function is_hostname($hostname) {
- if (!is_string($hostname))
+ if (!is_string($hostname)) {
return false;
+ }
- if (is_domain($hostname))
+ if (is_domain($hostname)) {
if ((substr_count($hostname, ".") == 1) && ($hostname[strlen($hostname)-1] == ".")) {
/* Only a single dot at the end like "test." - hosts cannot be directly in the root domain. */
return false;
} else {
return true;
}
- else
+ } else {
return false;
+ }
}
/* returns true if $domain is a valid domain name */
function is_domain($domain) {
- if (!is_string($domain))
+ if (!is_string($domain)) {
return false;
+ }
- if (preg_match('/^(?:(?:[a-z_0-9]|[a-z_0-9][a-z_0-9\-]*[a-z_0-9])\.)*(?:[a-z_0-9]|[a-z_0-9][a-z_0-9\-]*[a-z_0-9\.])$/i', $domain))
+ if (preg_match('/^(?:(?:[a-z_0-9]|[a-z_0-9][a-z_0-9\-]*[a-z_0-9])\.)*(?:[a-z_0-9]|[a-z_0-9][a-z_0-9\-]*[a-z_0-9\.])$/i', $domain)) {
return true;
- else
+ } else {
return false;
+ }
}
/* returns true if $macaddr is a valid MAC address */
@@ -829,27 +878,31 @@ function is_macaddr($macaddr, $partial=false) {
returns NULL if a reserved word is used
returns FALSE for bad chars in the name - this allows calling code to determine what the problem was.
aliases cannot be:
- bad chars: anything except a-z 0-9 and underscore
- bad names: empty string, pure numeric, pure underscore
- reserved words: pre-defined service/protocol/port names which should not be ambiguous, and the words "port" and "pass" */
+ bad chars: anything except a-z 0-9 and underscore
+ bad names: empty string, pure numeric, pure underscore
+ reserved words: pre-defined service/protocol/port names which should not be ambiguous, and the words "port" and "pass" */
function is_validaliasname($name) {
/* Array of reserved words */
$reserved = array("port", "pass");
- if (!is_string($name) || strlen($name) >= 32 || preg_match('/(^_*$|^\d*$|[^a-z0-9_])/i', $name))
+ if (!is_string($name) || strlen($name) >= 32 || preg_match('/(^_*$|^\d*$|[^a-z0-9_])/i', $name)) {
return false;
- if (in_array($name, $reserved, true) || getservbyname($name, "tcp") || getservbyname($name, "udp") || getprotobyname($name))
+ }
+ if (in_array($name, $reserved, true) || getservbyname($name, "tcp") || getservbyname($name, "udp") || getprotobyname($name)) {
return; /* return NULL */
+ }
return true;
}
/* returns true if $port is a valid TCP/UDP port */
function is_port($port) {
- if (ctype_digit($port) && ((intval($port) >= 1) && (intval($port) <= 65535)))
+ if (ctype_digit($port) && ((intval($port) >= 1) && (intval($port) <= 65535))) {
return true;
- if (getservbyname($port, "tcp") || getservbyname($port, "udp"))
+ }
+ if (getservbyname($port, "tcp") || getservbyname($port, "udp")) {
return true;
+ }
return false;
}
@@ -867,19 +920,22 @@ function is_portoralias($port) {
if (is_alias($port)) {
if (is_array($config['aliases']['alias'])) {
foreach ($config['aliases']['alias'] as $alias) {
- if ($alias['name'] == $port && preg_match("/port/i", $alias['type']))
+ if ($alias['name'] == $port && preg_match("/port/i", $alias['type'])) {
return true;
}
}
- return false;
- } else
+ }
+ return false;
+ } else {
return is_port($port);
+ }
}
/* create ranges of sequential port numbers (200:215) and remove duplicates */
function group_ports($ports) {
- if (!is_array($ports) || empty($ports))
+ if (!is_array($ports) || empty($ports)) {
return;
+ }
$uniq = array();
foreach ($ports as $port) {
@@ -890,12 +946,15 @@ function group_ports($ports) {
$begin = $end;
$end = $aux;
}
- for ($i = $begin; $i <= $end; $i++)
- if (!in_array($i, $uniq))
+ for ($i = $begin; $i <= $end; $i++) {
+ if (!in_array($i, $uniq)) {
$uniq[] = $i;
+ }
+ }
} else if (is_port($port)) {
- if (!in_array($port, $uniq))
+ if (!in_array($port, $uniq)) {
$uniq[] = $port;
+ }
}
}
sort($uniq, SORT_NUMERIC);
@@ -908,10 +967,11 @@ function group_ports($ports) {
}
$last = end($result);
- if (is_portrange($last))
+ if (is_portrange($last)) {
list($begin, $end) = explode(":", $last);
- else
+ } else {
$begin = $end = $last;
+ }
if ($port == ($end+1)) {
$end++;
@@ -931,18 +991,20 @@ function is_valid_shaperbw($val) {
/* returns true if $test is in the range between $start and $end */
function is_inrange_v4($test, $start, $end) {
- if ( (ip2ulong($test) <= ip2ulong($end)) && (ip2ulong($test) >= ip2ulong($start)) )
+ if ((ip2ulong($test) <= ip2ulong($end)) && (ip2ulong($test) >= ip2ulong($start))) {
return true;
- else
+ } else {
return false;
+ }
}
/* returns true if $test is in the range between $start and $end */
function is_inrange_v6($test, $start, $end) {
- if ( (inet_pton($test) <= inet_pton($end)) && (inet_pton($test) >= inet_pton($start)) )
+ if ((inet_pton($test) <= inet_pton($end)) && (inet_pton($test) >= inet_pton($start))) {
return true;
- else
+ } else {
return false;
+ }
}
/* returns true if $test is in the range between $start and $end */
@@ -956,45 +1018,49 @@ function get_configured_carp_interface_list($carpinterface = '', $family = 'inet
$iflist = array();
- if(is_array($config['virtualip']['vip'])) {
+ if (is_array($config['virtualip']['vip'])) {
$viparr = &$config['virtualip']['vip'];
foreach ($viparr as $vip) {
switch ($vip['mode']) {
- case "carp":
- if (!empty($carpinterface)) {
- if ($carpinterface == "_vip{$vip['uniqid']}") {
- switch ($what) {
- case 'subnet':
- if ($family == 'inet' && is_ipaddrv4($vip['subnet']))
- return $vip['subnet_bits'];
- else if ($family == 'inet6' && is_ipaddrv6($vip['subnet']))
- return $vip['subnet_bits'];
- break;
- case 'iface':
- if ($family == 'inet' && is_ipaddrv4($vip['subnet']))
- return $vip['interface'];
- else if ($family == 'inet6' && is_ipaddrv6($vip['subnet']))
- return $vip['interface'];
- break;
- case 'vip':
- if ($family == 'inet' && is_ipaddrv4($vip['subnet']))
- return $vip;
- else if ($family == 'inet6' && is_ipaddrv6($vip['subnet']))
- return $vip;
- break;
- case 'ip':
- default:
- if ($family == 'inet' && is_ipaddrv4($vip['subnet']))
- return $vip['subnet'];
- else if ($family == 'inet6' && is_ipaddrv6($vip['subnet']))
- return $vip['subnet'];
- break;
+ case "carp":
+ if (!empty($carpinterface)) {
+ if ($carpinterface == "_vip{$vip['uniqid']}") {
+ switch ($what) {
+ case 'subnet':
+ if ($family == 'inet' && is_ipaddrv4($vip['subnet'])) {
+ return $vip['subnet_bits'];
+ } else if ($family == 'inet6' && is_ipaddrv6($vip['subnet'])) {
+ return $vip['subnet_bits'];
+ }
+ break;
+ case 'iface':
+ if ($family == 'inet' && is_ipaddrv4($vip['subnet'])) {
+ return $vip['interface'];
+ } else if ($family == 'inet6' && is_ipaddrv6($vip['subnet'])) {
+ return $vip['interface'];
+ }
+ break;
+ case 'vip':
+ if ($family == 'inet' && is_ipaddrv4($vip['subnet'])) {
+ return $vip;
+ } else if ($family == 'inet6' && is_ipaddrv6($vip['subnet'])) {
+ return $vip;
+ }
+ break;
+ case 'ip':
+ default:
+ if ($family == 'inet' && is_ipaddrv4($vip['subnet'])) {
+ return $vip['subnet'];
+ } else if ($family == 'inet6' && is_ipaddrv6($vip['subnet'])) {
+ return $vip['subnet'];
+ }
+ break;
+ }
}
+ } else {
+ $iflist["_vip{$vip['uniqid']}"] = $vip['subnet'];
}
- } else {
- $iflist["_vip{$vip['uniqid']}"] = $vip['subnet'];
- }
- break;
+ break;
}
}
}
@@ -1008,14 +1074,15 @@ function get_configured_ip_aliases_list($returnfullentry = false) {
$alias_list=array();
- if(is_array($config['virtualip']['vip'])) {
+ if (is_array($config['virtualip']['vip'])) {
$viparr = &$config['virtualip']['vip'];
foreach ($viparr as $vip) {
if ($vip['mode']=="ipalias") {
- if ($returnfullentry)
+ if ($returnfullentry) {
$alias_list[$vip['subnet']] = $vip;
- else
+ } else {
$alias_list[$vip['subnet']] = $vip['interface'];
+ }
}
}
}
@@ -1029,13 +1096,14 @@ function get_configured_vips_list() {
$alias_list=array();
- if(is_array($config['virtualip']['vip'])) {
+ if (is_array($config['virtualip']['vip'])) {
$viparr = &$config['virtualip']['vip'];
foreach ($viparr as $vip) {
- if ($vip['mode'] == "carp")
+ if ($vip['mode'] == "carp") {
$alias_list[] = array("ipaddr" => $vip['subnet'], "if" => "{$vip['interface']}_vip{$vip['vhid']}");
- else
+ } else {
$alias_list[] = array("ipaddr" => $vip['subnet'], "if" => $vip['interface']);
+ }
}
}
@@ -1044,16 +1112,17 @@ function get_configured_vips_list() {
/* comparison function for sorting by the order in which interfaces are normally created */
function compare_interface_friendly_names($a, $b) {
- if ($a == $b)
+ if ($a == $b) {
return 0;
- else if ($a == 'wan')
+ } else if ($a == 'wan') {
return -1;
- else if ($b == 'wan')
+ } else if ($b == 'wan') {
return 1;
- else if ($a == 'lan')
+ } else if ($a == 'lan') {
return -1;
- else if ($b == 'lan')
+ } else if ($b == 'lan') {
return 1;
+ }
return strnatcmp($a, $b);
}
@@ -1065,11 +1134,13 @@ function get_configured_interface_list($only_opt = false, $withdisabled = false)
$iflist = array();
/* if list */
- foreach($config['interfaces'] as $if => $ifdetail) {
- if ($only_opt && ($if == "wan" || $if == "lan"))
+ foreach ($config['interfaces'] as $if => $ifdetail) {
+ if ($only_opt && ($if == "wan" || $if == "lan")) {
continue;
- if (isset($ifdetail['enable']) || $withdisabled == true)
+ }
+ if (isset($ifdetail['enable']) || $withdisabled == true) {
$iflist[$if] = $if;
+ }
}
return $iflist;
@@ -1082,13 +1153,15 @@ function get_configured_interface_list_by_realif($only_opt = false, $withdisable
$iflist = array();
/* if list */
- foreach($config['interfaces'] as $if => $ifdetail) {
- if ($only_opt && ($if == "wan" || $if == "lan"))
+ foreach ($config['interfaces'] as $if => $ifdetail) {
+ if ($only_opt && ($if == "wan" || $if == "lan")) {
continue;
+ }
if (isset($ifdetail['enable']) || $withdisabled == true) {
$tmpif = get_real_interface($if);
- if (!empty($tmpif))
+ if (!empty($tmpif)) {
$iflist[$tmpif] = $if;
+ }
}
}
@@ -1102,14 +1175,16 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled =
$iflist = array();
/* if list */
- foreach($config['interfaces'] as $if => $ifdetail) {
- if ($only_opt && ($if == "wan" || $if == "lan"))
+ foreach ($config['interfaces'] as $if => $ifdetail) {
+ if ($only_opt && ($if == "wan" || $if == "lan")) {
continue;
+ }
if (isset($ifdetail['enable']) || $withdisabled == true) {
- if(empty($ifdetail['descr']))
+ if (empty($ifdetail['descr'])) {
$iflist[$if] = strtoupper($if);
- else
+ } else {
$iflist[$if] = strtoupper($ifdetail['descr']);
+ }
}
}
@@ -1124,26 +1199,29 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled =
function get_configured_ip_addresses() {
global $config;
- if (!function_exists('get_interface_ip'))
+ if (!function_exists('get_interface_ip')) {
require_once("interfaces.inc");
+ }
$ip_array = array();
$interfaces = get_configured_interface_list();
if (is_array($interfaces)) {
- foreach($interfaces as $int) {
+ foreach ($interfaces as $int) {
$ipaddr = get_interface_ip($int);
$ip_array[$int] = $ipaddr;
}
}
$interfaces = get_configured_carp_interface_list();
- if (is_array($interfaces))
- foreach($interfaces as $int => $ipaddr)
+ if (is_array($interfaces)) {
+ foreach ($interfaces as $int => $ipaddr) {
$ip_array[$int] = $ipaddr;
+ }
+ }
/* pppoe server */
if (is_array($config['pppoes']) && is_array($config['pppoes']['pppoe'])) {
- foreach($config['pppoes']['pppoe'] as $pppoe) {
+ foreach ($config['pppoes']['pppoe'] as $pppoe) {
if ($pppoe['mode'] == "server") {
- if(is_ipaddr($pppoe['localip'])) {
+ if (is_ipaddr($pppoe['localip'])) {
$int = "pppoes". $pppoe['pppoeid'];
$ip_array[$int] = $pppoe['localip'];
}
@@ -1163,16 +1241,18 @@ function get_configured_ipv6_addresses() {
require_once("interfaces.inc");
$ipv6_array = array();
$interfaces = get_configured_interface_list();
- if(is_array($interfaces)) {
- foreach($interfaces as $int) {
+ if (is_array($interfaces)) {
+ foreach ($interfaces as $int) {
$ipaddrv6 = get_interface_ipv6($int);
$ipv6_array[$int] = $ipaddrv6;
}
}
$interfaces = get_configured_carp_interface_list();
- if(is_array($interfaces))
- foreach($interfaces as $int => $ipaddrv6)
+ if (is_array($interfaces)) {
+ foreach ($interfaces as $int => $ipaddrv6) {
$ipv6_array[$int] = $ipaddrv6;
+ }
+ }
return $ipv6_array;
}
@@ -1188,7 +1268,7 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "")
global $config;
$upints = array();
/* get a list of virtual interface types */
- if(!$vfaces) {
+ if (!$vfaces) {
$vfaces = array (
'bridge',
'ppp',
@@ -1214,24 +1294,26 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "")
'ipfw'
);
}
- switch($mode) {
- case "active":
- $upints = pfSense_interface_listget(IFF_UP);
- break;
- case "media":
- $intlist = pfSense_interface_listget();
- $ifconfig = "";
- exec("/sbin/ifconfig -a", $ifconfig);
- $regexp = '/(' . implode('|', $intlist) . '):\s/';
- $ifstatus = preg_grep('/status:/', $ifconfig);
- foreach($ifstatus as $status) {
- $int = array_shift($intlist);
- if(stristr($status, "active")) $upints[] = $int;
- }
- break;
- default:
- $upints = pfSense_interface_listget();
- break;
+ switch ($mode) {
+ case "active":
+ $upints = pfSense_interface_listget(IFF_UP);
+ break;
+ case "media":
+ $intlist = pfSense_interface_listget();
+ $ifconfig = "";
+ exec("/sbin/ifconfig -a", $ifconfig);
+ $regexp = '/(' . implode('|', $intlist) . '):\s/';
+ $ifstatus = preg_grep('/status:/', $ifconfig);
+ foreach ($ifstatus as $status) {
+ $int = array_shift($intlist);
+ if (stristr($status, "active")) {
+ $upints[] = $int;
+ }
+ }
+ break;
+ default:
+ $upints = pfSense_interface_listget();
+ break;
}
/* build interface list with netstat */
$linkinfo = "";
@@ -1241,30 +1323,33 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "")
$ipinfo = "";
exec("/usr/bin/netstat -inW -f inet | awk '{ print $1, $4 }'", $ipinfo);
array_shift($ipinfo);
- foreach($linkinfo as $link) {
+ foreach ($linkinfo as $link) {
$friendly = "";
$alink = explode(" ", $link);
$ifname = rtrim(trim($alink[0]), '*');
/* trim out all numbers before checking for vfaces */
if (!in_array(array_shift(preg_split('/\d/', $ifname)), $vfaces) &&
- !stristr($ifname, "_vlan") && !stristr($ifname, "_wlan")) {
+ !stristr($ifname, "_vlan") && !stristr($ifname, "_wlan")) {
$toput = array(
"mac" => trim($alink[1]),
"up" => in_array($ifname, $upints)
);
- foreach($ipinfo as $ip) {
+ foreach ($ipinfo as $ip) {
$aip = explode(" ", $ip);
- if($aip[0] == $ifname) {
+ if ($aip[0] == $ifname) {
$toput['ipaddr'] = $aip[1];
}
}
if (is_array($config['interfaces'])) {
- foreach($config['interfaces'] as $name => $int)
- if($int['if'] == $ifname) $friendly = $name;
+ foreach ($config['interfaces'] as $name => $int) {
+ if ($int['if'] == $ifname) {
+ $friendly = $name;
+ }
+ }
}
- switch($keyby) {
+ switch ($keyby) {
case "physical":
- if($friendly != "") {
+ if ($friendly != "") {
$toput['friendly'] = $friendly;
}
$dmesg_arr = array();
@@ -1276,7 +1361,7 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "")
case "ppp":
case "friendly":
- if($friendly != "") {
+ if ($friendly != "") {
$toput['if'] = $ifname;
$iflist[$friendly] = $toput;
}
@@ -1303,8 +1388,9 @@ function log_error($error) {
$page = basename($files[0]);
}
syslog(LOG_ERR, "$page: $error");
- if ($g['debug'])
+ if ($g['debug']) {
syslog(LOG_WARNING, var_dump(debug_backtrace()));
+ }
return;
}
@@ -1320,8 +1406,9 @@ function log_auth($error) {
global $g;
$page = $_SERVER['SCRIPT_NAME'];
syslog(LOG_AUTH, "$page: $error");
- if ($g['debug'])
+ if ($g['debug']) {
syslog(LOG_WARNING, var_dump(debug_backtrace()));
+ }
return;
}
@@ -1346,8 +1433,9 @@ function mwexec($command, $mute = false, $clearsigmask = false) {
global $g;
if ($g['debug']) {
- if (!$_SERVER['REMOTE_ADDR'])
+ if (!$_SERVER['REMOTE_ADDR']) {
echo "mwexec(): $command\n";
+ }
}
$oarr = array();
$retval = 0;
@@ -1361,9 +1449,10 @@ function mwexec($command, $mute = false, $clearsigmask = false) {
pcntl_sigprocmask(SIG_SETMASK, $oldset);
}
- if(isset($config['system']['developerspew']))
+ if (isset($config['system']['developerspew'])) {
$mute = false;
- if(($retval <> 0) && ($mute === false)) {
+ }
+ if (($retval <> 0) && ($mute === false)) {
$output = implode(" ", $oarr);
log_error(sprintf(gettext("The command '%1\$s' returned exit code '%2\$d', the output was '%3\$s' "), $command, $retval, $output));
unset($output);
@@ -1377,8 +1466,9 @@ function mwexec_bg($command, $clearsigmask = false) {
global $g;
if ($g['debug']) {
- if (!$_SERVER['REMOTE_ADDR'])
+ if (!$_SERVER['REMOTE_ADDR']) {
echo "mwexec(): $command\n";
+ }
}
if ($clearsigmask) {
@@ -1395,9 +1485,10 @@ function mwexec_bg($command, $clearsigmask = false) {
/* unlink a file, if it exists */
function unlink_if_exists($fn) {
$to_do = glob($fn);
- if(is_array($to_do)) {
- foreach($to_do as $filename)
+ if (is_array($to_do)) {
+ foreach ($to_do as $filename) {
@unlink($filename);
+ }
} else {
@unlink($fn);
}
@@ -1410,8 +1501,9 @@ function alias_make_table($config) {
if (is_array($config['aliases']['alias'])) {
foreach ($config['aliases']['alias'] as $alias) {
- if ($alias['name'])
+ if ($alias['name']) {
$aliastable[$alias['name']] = $alias['address'];
+ }
}
}
}
@@ -1428,8 +1520,9 @@ function alias_get_type($name) {
if (is_array($config['aliases']['alias'])) {
foreach ($config['aliases']['alias'] as $alias) {
- if ($name == $alias['name'])
+ if ($name == $alias['name']) {
return $alias['type'];
+ }
}
}
@@ -1440,12 +1533,13 @@ function alias_get_type($name) {
function alias_expand($name) {
global $aliastable;
- if (isset($aliastable[$name]))
+ if (isset($aliastable[$name])) {
return "\${$name}";
- else if (is_ipaddr($name) || is_subnet($name) || is_port($name) || is_portrange($name))
+ } else if (is_ipaddr($name) || is_subnet($name) || is_port($name) || is_portrange($name)) {
return "{$name}";
- else
+ } else {
return null;
+ }
}
function alias_expand_urltable($name) {
@@ -1456,10 +1550,11 @@ function alias_expand_urltable($name) {
if (is_array($config['aliases']['alias'])) {
foreach ($config['aliases']['alias'] as $alias) {
if (preg_match("/urltable/i", $alias['type']) && ($alias['name'] == $name)) {
- if (is_URL($alias["url"]) && file_exists($urltable_filename) && filesize($urltable_filename))
+ if (is_URL($alias["url"]) && file_exists($urltable_filename) && filesize($urltable_filename)) {
return $urltable_filename;
- else if (process_alias_urltable($name, $alias["url"], 0, true))
+ } else if (process_alias_urltable($name, $alias["url"], 0, true)) {
return $urltable_filename;
+ }
}
}
}
@@ -1470,8 +1565,9 @@ function alias_expand_urltable($name) {
function verify_digital_signature($fname) {
global $g;
- if(!file_exists("/usr/local/sbin/gzsig"))
+ if (!file_exists("/usr/local/sbin/gzsig")) {
return 4;
+ }
return mwexec("/usr/local/sbin/gzsig verify {$g['etc_path']}/pubkey.pem < " . escapeshellarg($fname));
}
@@ -1485,10 +1581,11 @@ function arp_get_mac_by_ip($ip) {
if ($arpoutput[0]) {
$arpi = explode(" ", $arpoutput[0]);
$macaddr = $arpi[3];
- if (is_macaddr($macaddr))
+ if (is_macaddr($macaddr)) {
return $macaddr;
- else
+ } else {
return false;
+ }
}
return false;
@@ -1509,28 +1606,29 @@ function mac_format($clientmac) {
$mac = explode(":", $clientmac);
$mac_format = $cpzone ? $config['captiveportal'][$cpzone]['radmac_format'] : false;
- switch($mac_format) {
- case 'singledash':
- return "$mac[0]$mac[1]$mac[2]-$mac[3]$mac[4]$mac[5]";
+ switch ($mac_format) {
+ case 'singledash':
+ return "$mac[0]$mac[1]$mac[2]-$mac[3]$mac[4]$mac[5]";
- case 'ietf':
- return "$mac[0]-$mac[1]-$mac[2]-$mac[3]-$mac[4]-$mac[5]";
+ case 'ietf':
+ return "$mac[0]-$mac[1]-$mac[2]-$mac[3]-$mac[4]-$mac[5]";
- case 'cisco':
- return "$mac[0]$mac[1].$mac[2]$mac[3].$mac[4]$mac[5]";
+ case 'cisco':
+ return "$mac[0]$mac[1].$mac[2]$mac[3].$mac[4]$mac[5]";
- case 'unformatted':
- return "$mac[0]$mac[1]$mac[2]$mac[3]$mac[4]$mac[5]";
+ case 'unformatted':
+ return "$mac[0]$mac[1]$mac[2]$mac[3]$mac[4]$mac[5]";
- default:
- return $clientmac;
+ default:
+ return $clientmac;
}
}
function resolve_retry($hostname, $retries = 5) {
- if (is_ipaddr($hostname))
+ if (is_ipaddr($hostname)) {
return $hostname;
+ }
for ($i = 0; $i < $retries; $i++) {
// FIXME: gethostbyname does not work for AAAA hostnames, boo, hiss
@@ -1579,11 +1677,13 @@ function return_dir_as_array($dir, $filter_regex = '') {
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
- if (($file == ".") || ($file == ".."))
+ if (($file == ".") || ($file == "..")) {
continue;
+ }
- if (empty($filter_regex) || preg_match($filter_regex, $file))
+ if (empty($filter_regex) || preg_match($filter_regex, $file)) {
array_push($dir_array, $file);
+ }
}
closedir($dh);
}
@@ -1598,10 +1698,11 @@ function run_plugins($directory) {
$files = return_dir_as_array($directory);
if (is_array($files)) {
foreach ($files as $file) {
- if (stristr($file, ".sh") == true)
+ if (stristr($file, ".sh") == true) {
mwexec($directory . $file . " start");
- else if (!is_dir($directory . "/" . $file) && stristr($file,".inc"))
+ } else if (!is_dir($directory . "/" . $file) && stristr($file,".inc")) {
require_once($directory . "/" . $file);
+ }
}
}
}
@@ -1629,8 +1730,9 @@ function make_dirs($path, $mode = 0755) {
foreach (explode('/', $path) as $dir) {
$base .= "/$dir";
if (!is_dir($base)) {
- if (!@mkdir($base, $mode))
+ if (!@mkdir($base, $mode)) {
return false;
+ }
}
}
return true;
@@ -1642,23 +1744,26 @@ function make_dirs($path, $mode = 0755) {
* name) and return an array of key/value pairs set for those that exist
*/
function get_sysctl($names) {
- if (empty($names))
+ if (empty($names)) {
return array();
+ }
if (is_array($names)) {
$name_list = array();
foreach ($names as $name) {
$name_list[] = escapeshellarg($name);
}
- } else
+ } else {
$name_list = array(escapeshellarg($names));
+ }
exec("/sbin/sysctl -i " . implode(" ", $name_list), $output);
$values = array();
foreach ($output as $line) {
$line = explode(": ", $line, 2);
- if (count($line) == 2)
+ if (count($line) == 2) {
$values[$line[0]] = $line[1];
+ }
}
return $values;
@@ -1670,12 +1775,14 @@ function get_sysctl($names) {
* return the value for sysctl $name or empty string if it doesn't exist
*/
function get_single_sysctl($name) {
- if (empty($name))
+ if (empty($name)) {
return "";
+ }
$value = get_sysctl($name);
- if (empty($value) || !isset($value[$name]))
+ if (empty($value) || !isset($value[$name])) {
return "";
+ }
return $value[$name];
}
@@ -1686,8 +1793,9 @@ function get_single_sysctl($name) {
* an array with keys set for those that succeeded
*/
function set_sysctl($values) {
- if (empty($values))
+ if (empty($values)) {
return array();
+ }
$value_list = array();
foreach ($values as $key => $value) {
@@ -1706,8 +1814,9 @@ function set_sysctl($values) {
$ret = array();
foreach ($output as $line) {
$line = explode(": ", $line, 2);
- if (count($line) == 2)
+ if (count($line) == 2) {
$ret[$line[0]] = true;
+ }
}
return $ret;
@@ -1716,16 +1825,18 @@ function set_sysctl($values) {
/*
* set_single_sysctl($name, $value)
* Wrapper to set_sysctl() to make it simple to set only one sysctl
- * returns boolean meaning if it suceed
+ * returns boolean meaning if it succeeded
*/
function set_single_sysctl($name, $value) {
- if (empty($name))
+ if (empty($name)) {
return false;
+ }
$result = set_sysctl(array($name => $value));
- if (!isset($result[$name]) || $result[$name] != $value)
+ if (!isset($result[$name]) || $result[$name] != $value) {
return false;
+ }
return true;
}
@@ -1753,8 +1864,9 @@ function mute_kernel_msgs() {
case "jail":
return;
}
- if($config['system']['enableserial'])
+ if ($config['system']['enableserial']) {
return;
+ }
exec("/sbin/conscontrol mute on");
}
@@ -1773,9 +1885,10 @@ function unmute_kernel_msgs() {
function start_devd() {
global $g;
- if ($g['platform'] == 'jail')
+ if ($g['platform'] == 'jail') {
return;
- /* Use the undocumented -q options of devd to quite its log spamming */
+ }
+ /* Use the undocumented -q options of devd to quiet its log spamming */
$_gb = exec("/sbin/devd -q");
sleep(1);
unset($_gb);
@@ -1786,8 +1899,9 @@ function is_interface_vlan_mismatch() {
if (is_array($config['vlans']['vlan'])) {
foreach ($config['vlans']['vlan'] as $vlan) {
- if (does_interface_exist($vlan['if']) == false)
+ if (does_interface_exist($vlan['if']) == false) {
return true;
+ }
}
}
@@ -1806,22 +1920,24 @@ function is_interface_mismatch() {
// Do not check these interfaces.
$i++;
continue;
- }
- else if (does_interface_exist($ifcfg['if']) == false) {
+ } else if (does_interface_exist($ifcfg['if']) == false) {
$missing_interfaces[] = $ifcfg['if'];
$do_assign = true;
- } else
+ } else {
$i++;
+ }
}
}
- if (file_exists("{$g['tmp_path']}/assign_complete"))
+ if (file_exists("{$g['tmp_path']}/assign_complete")) {
$do_assign = false;
+ }
- if (!empty($missing_interfaces) && $do_assign)
+ if (!empty($missing_interfaces) && $do_assign) {
file_put_contents("{$g['tmp_path']}/missing_interfaces", implode(' ', $missing_interfaces));
- else
+ } else {
@unlink("{$g['tmp_path']}/missing_interfaces");
+ }
return $do_assign;
}
@@ -1853,17 +1969,22 @@ function isAjax() {
* returns 1 char of user input or null if no input.
******/
function timeout($timer = 9) {
- while(!isset($key)) {
- if ($timer >= 9) { echo chr(8) . chr(8) . ($timer==9 ? chr(32) : null) . "{$timer}"; }
- else { echo chr(8). "{$timer}"; }
+ while (!isset($key)) {
+ if ($timer >= 9) {
+ echo chr(8) . chr(8) . ($timer==9 ? chr(32) : null) . "{$timer}";
+ } else {
+ echo chr(8). "{$timer}";
+ }
`/bin/stty -icanon min 0 time 25`;
$key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
`/bin/stty icanon`;
- if ($key == '')
+ if ($key == '') {
unset($key);
+ }
$timer--;
- if ($timer == 0)
+ if ($timer == 0) {
break;
+ }
}
return $key;
}
@@ -1878,7 +1999,7 @@ function timeout($timer = 9) {
******/
function msort($array, $id="id", $sort_ascending=true) {
$temp_array = array();
- while(count($array)>0) {
+ while (count($array)>0) {
$lowest_id = 0;
$index=0;
foreach ($array as $item) {
@@ -1911,15 +2032,17 @@ function msort($array, $id="id", $sort_ascending=true) {
******/
function is_URL($url) {
$match = preg_match("'\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))'", $url);
- if($match)
+ if ($match) {
return true;
+ }
return false;
}
function is_file_included($file = "") {
$files = get_included_files();
- if (in_array($file, $files))
+ if (in_array($file, $files)) {
return true;
+ }
return false;
}
@@ -1928,14 +2051,17 @@ function is_file_included($file = "") {
* Replace a value on a deep associative array using regex
*/
function array_replace_values_recursive($data, $match, $replace) {
- if (empty($data))
+ if (empty($data)) {
return $data;
+ }
- if (is_string($data))
+ if (is_string($data)) {
$data = preg_replace("/{$match}/", $replace, $data);
- else if (is_array($data))
- foreach ($data as $k => $v)
+ } else if (is_array($data)) {
+ foreach ($data as $k => $v) {
$data[$k] = array_replace_values_recursive($v, $match, $replace);
+ }
+ }
return $data;
}
@@ -1954,30 +2080,30 @@ function array_merge_recursive_unique($array0, $array1) {
$result = array();
// loop available array
- foreach($arrays as $array) {
+ foreach ($arrays as $array) {
// The first remaining array is $array. We are processing it. So
- // we remove it from remaing arrays.
+ // we remove it from remaining arrays.
array_shift($remains);
// We don't care non array param, like array_merge since PHP 5.0.
- if(is_array($array)) {
+ if (is_array($array)) {
// Loop values
- foreach($array as $key => $value) {
- if(is_array($value)) {
+ foreach ($array as $key => $value) {
+ if (is_array($value)) {
// we gather all remaining arrays that have such key available
$args = array();
- foreach($remains as $remain) {
- if(array_key_exists($key, $remain)) {
+ foreach ($remains as $remain) {
+ if (array_key_exists($key, $remain)) {
array_push($args, $remain[$key]);
}
}
- if(count($args) > 2) {
+ if (count($args) > 2) {
// put the recursion
$result[$key] = call_user_func_array(__FUNCTION__, $args);
} else {
- foreach($value as $vkey => $vval) {
+ foreach ($value as $vkey => $vval) {
$result[$key][$vkey] = $vval;
}
}
@@ -2010,26 +2136,29 @@ function get_staticroutes($returnsubnetsonly = false, $returnhostnames = false)
global $config, $aliastable;
/* Bail if there are no routes, but return an array always so callers don't have to check. */
- if (!is_array($config['staticroutes']['route']))
+ if (!is_array($config['staticroutes']['route'])) {
return array();
+ }
$allstaticroutes = array();
$allsubnets = array();
/* Loop through routes and expand aliases as we find them. */
foreach ($config['staticroutes']['route'] as $route) {
if (is_alias($route['network'])) {
- if (!isset($aliastable[$route['network']]))
+ if (!isset($aliastable[$route['network']])) {
continue;
+ }
$subnets = preg_split('/\s+/', $aliastable[$route['network']]);
foreach ($subnets as $net) {
if (!is_subnet($net)) {
- if (is_ipaddrv4($net))
+ if (is_ipaddrv4($net)) {
$net .= "/32";
- else if (is_ipaddrv6($net))
+ } else if (is_ipaddrv6($net)) {
$net .= "/128";
- else if ($returnhostnames === false || !is_fqdn($net))
+ } else if ($returnhostnames === false || !is_fqdn($net)) {
continue;
+ }
}
$temproute = $route;
$temproute['network'] = $net;
@@ -2041,10 +2170,11 @@ function get_staticroutes($returnsubnetsonly = false, $returnhostnames = false)
$allsubnets[] = $route['network'];
}
}
- if ($returnsubnetsonly)
+ if ($returnsubnetsonly) {
return $allsubnets;
- else
+ } else {
return $allstaticroutes;
+ }
}
/****f* util/get_alias_list
@@ -2065,13 +2195,11 @@ function get_alias_list($type = null) {
foreach ($config['aliases']['alias'] as $alias) {
if ($type === null) {
$result[] = $alias['name'];
- }
- else if (is_array($type)) {
+ } else if (is_array($type)) {
if (in_array($alias['type'], $type)) {
$result[] = $alias['name'];
}
- }
- else if ($type === $alias['type']) {
+ } else if ($type === $alias['type']) {
$result[] = $alias['name'];
}
}
@@ -2096,22 +2224,25 @@ function get_current_theme() {
global $config, $g;
/*
* if user has selected a custom template, use it.
- * otherwise default to pfsense tempalte
+ * otherwise default to pfsense template
*/
- if (($g["disablethemeselection"] === true) && !empty($g["default_theme"]) && (is_dir($g["www_path"].'/themes/'.$g["default_theme"])))
+ if (($g["disablethemeselection"] === true) && !empty($g["default_theme"]) && (is_dir($g["www_path"].'/themes/'.$g["default_theme"]))) {
$theme = $g["default_theme"];
- elseif($config['theme'] <> "" && (is_dir($g["www_path"].'/themes/'.$config['theme'])))
+ } elseif ($config['theme'] <> "" && (is_dir($g["www_path"].'/themes/'.$config['theme']))) {
$theme = $config['theme'];
- else
+ } else {
$theme = "pfsense";
+ }
/*
* If this device is an apple ipod/iphone
* switch the theme to one that works with it.
*/
$lowres_ua = array("iPhone", "iPod", "iPad", "Android", "BlackBerry", "Opera Mini", "Opera Mobi", "PlayBook", "IEMobile");
- foreach($lowres_ua as $useragent)
- if(strstr($_SERVER['HTTP_USER_AGENT'], $useragent))
+ foreach ($lowres_ua as $useragent) {
+ if (strstr($_SERVER['HTTP_USER_AGENT'], $useragent)) {
$theme = (empty($g['theme_lowres']) && (is_dir($g["www_path"].'/themes/'.$g['theme_lowres']))) ? "pfsense" : $g['theme_lowres'];
+ }
+ }
return $theme;
}
@@ -2119,16 +2250,18 @@ function get_current_theme() {
function prefer_ipv4_or_ipv6() {
global $config;
- if (isset($config['system']['prefer_ipv4']))
+ if (isset($config['system']['prefer_ipv4'])) {
mwexec("/etc/rc.d/ip6addrctl prefer_ipv4");
- else
+ } else {
mwexec("/etc/rc.d/ip6addrctl prefer_ipv6");
+ }
}
/* Redirect to page passing parameters via POST */
function post_redirect($page, $params) {
- if (!is_array($params))
+ if (!is_array($params)) {
return;
+ }
print "<html><body><form action=\"{$page}\" name=\"formredir\" method=\"post\">\n";
foreach ($params as $key => $value) {
diff --git a/etc/inc/uuid.php b/etc/inc/uuid.php
index 9eaf2fd..700f392 100644
--- a/etc/inc/uuid.php
+++ b/etc/inc/uuid.php
@@ -44,7 +44,7 @@ class UUID {
const FMT_BINARY = 102;
const FMT_QWORD = 1; /* Quad-word, 128-bit (not impl.) */
const FMT_DWORD = 2; /* Double-word, 64-bit (not impl.) */
- const FMT_WORD = 4; /* Word, 32-bit (not impl.) */
+ const FMT_WORD = 4; /* Word, 32-bit (not impl.) */
const FMT_SHORT = 8; /* Short (not impl.) */
const FMT_BYTE = 16; /* Byte */
const FMT_DEFAULT = 16;
@@ -169,7 +169,7 @@ class UUID {
$raw .= $node;
/* Hash the namespace and node and convert to a byte array */
- $val = $hash($raw, true);
+ $val = $hash($raw, true);
$tmp = unpack('C16', $val);
foreach (array_keys($tmp) as $key)
$byte[$key - 1] = $tmp[$key];
@@ -187,7 +187,7 @@ class UUID {
$field['time_hi'] &= 0x0fff;
$field['time_hi'] |= ($version << 12);
- return ($field);
+ return ($field);
}
static private function generateNameMD5($ns, $node) {
return self::generateName($ns, $node, "md5",
@@ -221,7 +221,7 @@ class UUID {
$uuid['time_low'] = $low;
$uuid['time_mid'] = $high & 0x0000ffff;
$uuid['time_hi'] = ($high & 0x0fff) | (self::UUID_TIME << 12);
-
+
/*
* We don't support saved state information and generate
* a random clock sequence each time.
OpenPOWER on IntegriCloud