Commit 0145541f authored by Ad Schellevis's avatar Ad Schellevis

(legacy) fix more php issues in etc/inc

parent 8d561f62
......@@ -1228,7 +1228,7 @@ function auth_get_authserver_list() {
$list = array();
if (is_array($config['system']['authserver'])) {
if (isset($config['system']['authserver']) && is_array($config['system']['authserver'])) {
foreach ($config['system']['authserver'] as $authcfg) {
/* Add support for disabled entries? */
$list[$authcfg['name']] = $authcfg;
......
......@@ -48,17 +48,18 @@ $openssl_crl_status = array(
function & lookup_ca($refid) {
global $config;
$false = false;
if (is_array($config['ca']))
foreach ($config['ca'] as & $ca)
if ($ca['refid'] == $refid)
return $ca;
return false;
return $false;
}
function & lookup_ca_by_subject($subject) {
global $config;
$false = false;
if (is_array($config['ca']))
foreach ($config['ca'] as & $ca)
......@@ -68,37 +69,41 @@ function & lookup_ca_by_subject($subject) {
return $ca;
}
return false;
return $false;
}
function & lookup_cert($refid) {
global $config;
$false = false;
if (is_array($config['cert']))
foreach ($config['cert'] as & $cert)
if ($cert['refid'] == $refid)
return $cert;
return false;
return $false;
}
function & lookup_cert_by_name($name) {
global $config;
$null = null;
if (is_array($config['cert']))
foreach ($config['cert'] as & $cert)
if ($cert['descr'] == $name)
return $cert;
return $null;
}
function & lookup_crl($refid) {
global $config;
$false = false;
if (is_array($config['crl']))
foreach ($config['crl'] as & $crl)
if ($crl['refid'] == $refid)
return $crl;
return false;
return $false;
}
function ca_chain_array(& $cert) {
......@@ -395,11 +400,11 @@ function cert_get_subject($str_crt, $decode = true) {
ksort($v);
foreach ($v as $w) {
$asubject = "{$a}={$w}";
$subject = (strlen($subject)) ? "{$asubject}, {$subject}" : $asubject;
$subject = (isset($subject)) ? "{$asubject}, {$subject}" : $asubject;
}
} else {
$asubject = "{$a}={$v}";
$subject = (strlen($subject)) ? "{$asubject}, {$subject}" : $asubject;
$subject = (isset($subject)) ? "{$asubject}, {$subject}" : $asubject;
}
}
......@@ -445,11 +450,11 @@ function cert_get_issuer($str_crt, $decode = true) {
ksort($v);
foreach ($v as $w) {
$aissuer = "{$a}={$w}";
$issuer = (strlen($issuer)) ? "{$aissuer}, {$issuer}" : $aissuer;
$issuer = (isset($issuer)) ? "{$aissuer}, {$issuer}" : $aissuer;
}
} else {
$aissuer = "{$a}={$v}";
$issuer = (strlen($issuer)) ? "{$aissuer}, {$issuer}" : $aissuer;
$issuer = (isset($issuer)) ? "{$aissuer}, {$issuer}" : $aissuer;
}
}
......@@ -490,7 +495,11 @@ function cert_get_purpose($str_crt, $decode = true) {
$crt_details = openssl_x509_parse($str_crt);
$purpose = array();
$purpose['ca'] = (stristr($crt_details['extensions']['basicConstraints'], 'CA:TRUE') === false) ? 'No': 'Yes';
$purpose['server'] = ($crt_details['extensions']['nsCertType'] == "SSL Server") ? 'Yes': 'No';
if (isset($crt_details['extensions']['nsCertType']) && $crt_details['extensions']['nsCertType'] == "SSL Server") {
$purpose['server'] = 'Yes';
} else {
$purpose['server'] = 'No';
}
return $purpose;
}
......@@ -524,7 +533,7 @@ function is_user_cert($certref)
}
foreach ($config['system']['user'] as $user) {
if (!is_array($user['cert'])) {
if (!isset($user['cert']) || !is_array($user['cert'])) {
continue;
}
foreach ($user['cert'] as $cert) {
......@@ -696,7 +705,7 @@ function cert_compare($cert1, $cert2) {
function is_cert_revoked($cert, $crlref = "") {
global $config;
if (!is_array($config['crl']))
if (!isset($config['crl']) || !is_array($config['crl']))
return false;
if (!empty($crlref)) {
......
......@@ -838,8 +838,13 @@ function filter_generate_optcfg_array()
$oic['ipv6'] = get_interface_ipv6($if);
if(!is_ipaddrv4($oc['ipaddr']) && !empty($oc['ipaddr']))
$oic['type'] = $oc['ipaddr'];
if(!is_ipaddrv6($oc['ipaddrv6']) && !empty($oc['ipaddrv6']))
$oic['type6'] = $oc['ipaddrv6'];
if (isset($oc['ipaddrv6'])) {
if( !is_ipaddrv6($oc['ipaddrv6']) && !empty($oc['ipaddrv6'])) {
$oic['type6'] = $oc['ipaddrv6'];
}
} else {
$oic['type6'] = null;
}
if (!empty($oc['track6-interface']))
$oic['track6-interface'] = $oc['track6-interface'];
$oic['sn'] = get_interface_subnet($if);
......@@ -849,11 +854,31 @@ function filter_generate_optcfg_array()
$oic['descr'] = $ifdetail;
$oic['sa'] = gen_subnet($oic['ip'], $oic['sn']);
$oic['sav6'] = gen_subnetv6($oic['ipv6'], $oic['snv6']);
$oic['nonat'] = $oc['nonat'];
$oic['alias-address'] = $oc['alias-address'];
$oic['alias-subnet'] = $oc['alias-subnet'];
$oic['gateway'] = $oc['gateway'];
$oic['gatewayv6'] = $oc['gatewayv6'];
if (isset($oc['nonat'])) {
$oic['nonat'] = $oc['nonat'];
} else {
$oic['nonat'] = null;
}
if (isset($oc['alias-address'])) {
$oic['alias-address'] = $oc['alias-address'];
} else {
$oic['alias-address'] = null;
}
if (isset($oc['alias-subnet'])) {
$oic['alias-subnet'] = $oc['alias-subnet'];
} else {
$oc['alias-subnet'] = null;
}
if (isset($oc['gateway'])) {
$oic['gateway'] = $oc['gateway'];
} else {
$oic['gateway'] = null ;
}
if (isset($oc['gatewayv6'])) {
$oic['gatewayv6'] = $oc['gatewayv6'];
} else {
$oic['gatewayv6'] = null;
}
$oic['spoofcheck'] = "yes";
$oic['bridge'] = link_interface_to_bridge($if);
$vips = link_interface_to_vips($if);
......@@ -896,7 +921,7 @@ function filter_generate_optcfg_array()
$oic['sn'] = "32";
$FilterIflist['pptp'] = $oic;
}
if($config['l2tp']['mode'] == "server") {
if(isset($config['l2tp']['mode']) && $config['l2tp']['mode'] == "server") {
$oic = array();
$oic['if'] = 'l2tp';
$oic['descr'] = 'L2TP';
......@@ -910,7 +935,7 @@ function filter_generate_optcfg_array()
$oic['virtual'] = true;
$FilterIflist['l2tp'] = $oic;
}
if (is_array($config['pppoes']['pppoe']) && (count($config['pppoes']['pppoe']) > 0)) {
if (isset($config['pppoes']['pppoe']) && is_array($config['pppoes']['pppoe']) && (count($config['pppoes']['pppoe']) > 0)) {
$pppoeifs = array();
foreach($config['pppoes']['pppoe'] as $pppoe) {
if ($pppoe['mode'] == "server") {
......
......@@ -388,7 +388,7 @@ function return_gateways_status($byname = false)
foreach($gateways_arr as $gwitem) {
if(!isset($gwitem['monitor_disable']))
continue;
if(!is_ipaddr($gwitem['monitorip'])) {
if(!isset($gwitem['monitorip']) || !is_ipaddr($gwitem['monitorip'])) {
$realif = $gwitem['interface'];
$tgtip = get_interface_gateway($realif);
if (!is_ipaddr($tgtip))
......@@ -943,26 +943,28 @@ function get_interface_gateway($interface, &$dynamic = false)
$gw = NULL;
$gwcfg = $config['interfaces'][$interface];
if (!empty($gwcfg['gateway']) && is_array($config['gateways']['gateway_item'])) {
foreach($config['gateways']['gateway_item'] as $gateway) {
if(($gateway['name'] == $gwcfg['gateway']) && (is_ipaddrv4($gateway['gateway']))) {
$gw = $gateway['gateway'];
break;
if (isset($config['interfaces'][$interface])) {
$gwcfg = $config['interfaces'][$interface];
if (isset($gwcfg['gateway']) && is_array($config['gateways']['gateway_item'])) {
foreach($config['gateways']['gateway_item'] as $gateway) {
if(($gateway['name'] == $gwcfg['gateway']) && (is_ipaddrv4($gateway['gateway']))) {
$gw = $gateway['gateway'];
break;
}
}
}
}
// for dynamic interfaces we handle them through the $interface_router file.
if (!is_ipaddrv4($gw) && !is_ipaddrv4($gwcfg['ipaddr'])) {
$realif = get_real_interface($interface);
if (file_exists("/tmp/{$realif}_router")) {
// for dynamic interfaces we handle them through the $interface_router file.
if (!is_ipaddrv4($gw) && !is_ipaddrv4($gwcfg['ipaddr'])) {
$realif = get_real_interface($interface);
if (file_exists("/tmp/{$realif}_router")) {
$gw = trim(file_get_contents("/tmp/{$realif}_router"), " \n");
$dynamic = true;
$dynamic = true;
}
if (file_exists("/tmp/{$realif}_defaultgw")) {
$dynamic = "default";
}
}
if (file_exists("/tmp/{$realif}_defaultgw"))
$dynamic = "default";
}
/* return gateway */
......@@ -985,7 +987,7 @@ function get_interface_gateway_v6($interface, &$dynamic = false)
}
// for dynamic interfaces we handle them through the $interface_router file.
if (!is_ipaddrv6($gw) && !is_ipaddrv6($gwcfg['ipaddrv6'])) {
if (!is_ipaddrv6($gw) && ( !isset($gwcfg['ipaddrv6']) || !is_ipaddrv6($gwcfg['ipaddrv6']))) {
$realif = get_real_interface($interface);
if (file_exists("/tmp/{$realif}_routerv6")) {
$gw = trim(file_get_contents("/tmp/{$realif}_routerv6"), " \n");
......
......@@ -4146,6 +4146,7 @@ function convert_real_interface_to_friendly_interface_name($interface = "wan") {
/* attempt to resolve interface to friendly descr */
function convert_friendly_interface_to_friendly_descr($interface) {
global $config;
$ifdesc = null;
switch ($interface) {
case "l2tp":
......@@ -4752,8 +4753,9 @@ function find_interface_ipv6($interface, $flush = false) {
$interface_ipv6_arr_cache[$interface] = $ifinfo['ipaddr6'];
$interface_snv6_arr_cache[$interface] = $ifinfo['subnetbits6'];
}
return $interface_ipv6_arr_cache[$interface];
}
return $interface_ipv6_arr_cache[$interface];
return;
}
/*
......@@ -4794,11 +4796,13 @@ function find_interface_subnet($interface, $flush = false) {
if (!isset($interface_sn_arr_cache[$interface]) or $flush) {
$ifinfo = pfSense_get_interface_addresses($interface);
$interface_ip_arr_cache[$interface] = $ifinfo['ipaddr'];
$interface_sn_arr_cache[$interface] = $ifinfo['subnetbits'];
if (isset($ifinfo['ipaddr'])) {
$interface_ip_arr_cache[$interface] = $ifinfo['ipaddr'];
$interface_sn_arr_cache[$interface] = $ifinfo['subnetbits'];
return $interface_sn_arr_cache[$interface];
}
}
return $interface_sn_arr_cache[$interface];
return;
}
function find_interface_subnetv6($interface, $flush = false) {
......@@ -4811,11 +4815,13 @@ function find_interface_subnetv6($interface, $flush = false) {
if (!isset($interface_snv6_arr_cache[$interface]) or $flush) {
$ifinfo = pfSense_get_interface_addresses($interface);
$interface_ipv6_arr_cache[$interface] = $ifinfo['ipaddr6'];
$interface_snv6_arr_cache[$interface] = $ifinfo['subnetbits6'];
if (isset($ifinfo['ipaddr6'])) {
$interface_ipv6_arr_cache[$interface] = $ifinfo['ipaddr6'];
$interface_snv6_arr_cache[$interface] = $ifinfo['subnetbits6'];
return $interface_snv6_arr_cache[$interface];
}
}
return $interface_snv6_arr_cache[$interface];
return;
}
function ip_in_interface_alias_subnet($interface, $ipalias) {
......@@ -4984,7 +4990,12 @@ function interface_has_gatewayv6($friendly) {
if (!empty($config['interfaces'][$friendly])) {
$ifname = &$config['interfaces'][$friendly];
switch ($ifname['ipaddrv6']) {
if (isset($ifname['ipaddrv6'])) {
$ipaddrv6 = $ifname['ipaddrv6'];
} else {
$ipaddrv6 = "";
}
switch ($ipaddrv6) {
case "slaac":
case "dhcp6":
case "6to4":
......@@ -5227,13 +5238,13 @@ function get_failover_interface($interface, $family = "all") {
global $config;
/* shortcut to get_real_interface if we find it in the config */
if (is_array($config['interfaces'][$interface])) {
if (isset($config['interfaces'][$interface]) && is_array($config['interfaces'][$interface])) {
return get_real_interface($interface, $family);
}
/* compare against gateway groups */
$a_groups = return_gateway_groups_array();
if (is_array($a_groups[$interface])) {
if (isset($a_groups[$interface]) && is_array($a_groups[$interface])) {
/* we found a gateway group, fetch the interface or vip */
if ($a_groups[$interface][0]['vip'] <> "")
return $a_groups[$interface][0]['vip'];
......
......@@ -1016,7 +1016,7 @@ function openvpn_get_active_servers($type="multipoint") {
global $config, $g;
$servers = array();
if (is_array($config['openvpn']['openvpn-server'])) {
if (isset($config['openvpn']['openvpn-server']) && is_array($config['openvpn']['openvpn-server'])) {
foreach ($config['openvpn']['openvpn-server'] as & $settings) {
if (empty($settings) || isset($settings['disable']))
continue;
......@@ -1118,7 +1118,7 @@ function openvpn_get_active_clients() {
global $config, $g;
$clients = array();
if (is_array($config['openvpn']['openvpn-client'])) {
if (isset($config['openvpn']['openvpn-client']) && is_array($config['openvpn']['openvpn-client'])) {
foreach ($config['openvpn']['openvpn-client'] as & $settings) {
if (empty($settings) || isset($settings['disable']))
......
......@@ -37,7 +37,7 @@
******/
function have_natpfruleint_access($if) {
$security_url = "firewall_nat_edit.php?if=". strtolower($if);
if(isAllowedPage($security_url, $allowed))
if(isAllowedPage($security_url))
return true;
return false;
}
......@@ -810,8 +810,9 @@ function is_dhcpv6_server_enabled() {
function is_radvd_enabled() {
global $config;
if (!is_array($config['dhcpdv6']))
if (!isset($config['dhcpdv6']) || !is_array($config['dhcpdv6'])) {
$config['dhcpdv6'] = array();
}
$dhcpdv6cfg = $config['dhcpdv6'];
$Iflist = get_configured_interface_list();
......@@ -1905,8 +1906,9 @@ function is_ipaddr_configured($ipaddr, $ignore_if = "", $check_localip = false,
function calculate_ipv6_delegation_length($if) {
global $config;
if(!is_array($config['interfaces'][$if]))
if(!isset($config['interfaces'][$if]) || !is_array($config['interfaces'][$if])) {
return false;
}
switch($config['interfaces'][$if]['ipaddrv6']) {
case "6to4":
......@@ -2027,7 +2029,7 @@ function zte_simstate_to_string($state) {
function get_configured_pppoe_server_interfaces() {
global $config;
$iflist = array();
if (is_array($config['pppoes']['pppoe'])) {
if (isset($config['pppoes']['pppoe']) && is_array($config['pppoes']['pppoe'])) {
foreach($config['pppoes']['pppoe'] as $pppoe) {
if ($pppoe['mode'] == "server") {
$int = "poes". $pppoe['pppoeid'];
......
......@@ -69,7 +69,7 @@ if (!function_exists('get_services')) {
$pconfig['description'] = gettext("NTP clock sync");
$services[] = $pconfig;
if (is_array($config['captiveportal'])) {
if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
foreach ($config['captiveportal'] as $zone => $setting) {
if (isset($setting['enable'])) {
$pconfig = array();
......@@ -125,7 +125,7 @@ if (!function_exists('get_services')) {
$services[] = $pconfig;
}
if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
if (isset($config['igmpproxy']['igmpentry']) && is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
$pconfig = array();
$pconfig['name'] = "igmpproxy";
$pconfig['description'] = gettext("IGMP proxy");
......@@ -169,7 +169,7 @@ if (!function_exists('get_services')) {
}
}
if (count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
if (isset($config['load_balancer']['virtual_server']) && isset($config['load_balancer']['lbpool']) && count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
$pconfig = array();
$pconfig['name'] = "relayd";
$pconfig['description'] = gettext("Server load balancing daemon");
......
......@@ -1728,7 +1728,7 @@ function get_possible_traffic_source_addresses($include_ipv6_link_local=false) {
global $config;
$sourceips = get_possible_listen_ips($include_ipv6_link_local);
foreach (array('server', 'client') as $mode) {
if (is_array($config['openvpn']["openvpn-{$mode}"])) {
if (isset($config['openvpn']["openvpn-{$mode}"]) && is_array($config['openvpn']["openvpn-{$mode}"])) {
foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
if (!isset($setting['disable'])) {
$vpn = array();
......
......@@ -942,7 +942,11 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "")
$dmesg_arr = array();
exec("/sbin/dmesg |grep $ifname | head -n1", $dmesg_arr);
preg_match_all("/<(.*?)>/i", $dmesg_arr[0], $dmesg);
$toput['dmesg'] = $dmesg[1][0];
if (isset($dmesg[1][0])) {
$toput['dmesg'] = $dmesg[1][0];
} else {
$toput['dmesg'] = null;
}
$iflist[$ifname] = $toput;
break;
case "ppp":
......
......@@ -464,15 +464,23 @@ function get_lb_summary() {
$relay_hosts=Array();
foreach( (array) $relayctl as $line) {
$t = explode("\t", $line);
switch (trim($t[1])) {
case "table":
$curpool=trim($t[2]);
break;
case "host":
$curhost=trim($t[2]);
$relay_hosts[$curpool][$curhost]['avail']=trim($t[3]);
$relay_hosts[$curpool][$curhost]['state']=trim($t[4]);
break;
if (isset($t[1])) {
switch (trim($t[1])) {
case "table":
$curpool=trim($t[2]);
break;
case "host":
$curhost=trim($t[2]);
if (!isset($relay_hosts[$curpool])) {
$relay_hosts[$curpool] = array();
}
if (!isset($relay_hosts[$curpool][$curhost])) {
$relay_hosts[$curpool][$curhost]['avail'] = array();
}
$relay_hosts[$curpool][$curhost]['avail']=trim($t[3]);
$relay_hosts[$curpool][$curhost]['state']=trim($t[4]);
break;
}
}
}
return $relay_hosts;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment