From 9fe3e40108040122cdaae55ddcdfc08e59ce0433 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 22 Feb 2016 20:10:48 +0100 Subject: [PATCH] (legacy) prevent some notices in refactored dhcp code --- src/www/services_dhcp.php | 19 ++++++++++--------- src/www/services_dhcp_edit.php | 4 ++-- src/www/services_dhcpv6.php | 6 +++--- src/www/services_dhcpv6_edit.php | 5 ++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/www/services_dhcp.php b/src/www/services_dhcp.php index ebfea9809..a54824242 100644 --- a/src/www/services_dhcp.php +++ b/src/www/services_dhcp.php @@ -139,6 +139,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $savemsg = gettext("The DHCP Server can only be enabled on interfaces configured with static IP addresses") . ".

" . gettext("Only interfaces configured with a static IP will be shown") . "."; } + /* If no interface is provided, choose first one from interfaces */ + if (!isset($if)) { + foreach ($config['interfaces'] as $if_id => $intf) { + if (!empty($intf['enable']) && is_ipaddrv4($intf['ipaddr'])) { + $if = $if_id; + break; + } + } + } + if (empty($config['dhcpd'][$if])) { $config['dhcpd'][$if] = array(); } @@ -153,15 +163,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $act = null; } - /* If no interface is provided, choose first one from interfaces */ - if (!isset($if)) { - foreach ($config['interfaces'] as $if_id => $intf) { - if (!empty($intf['enable']) && is_ipaddrv4($intf['ipaddr'])) { - $if = $if_id; - break; - } - } - } // point to source of data (pool or main dhcp section) if (isset($pool)) { $dhcpdconf = &$a_pools[$pool]; diff --git a/src/www/services_dhcp_edit.php b/src/www/services_dhcp_edit.php index 686c718bf..4e1da1d37 100644 --- a/src/www/services_dhcp_edit.php +++ b/src/www/services_dhcp_edit.php @@ -45,7 +45,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { header("Location: services_dhcp.php"); exit; } - if (!empty($config['dhcpd'][$if]['staticmap'][$_GET['id']])) { + if (isset($if) && isset($_GET['id']) && !empty($config['dhcpd'][$if]['staticmap'][$_GET['id']])) { $id = $_GET['id']; } @@ -56,7 +56,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { 'ddnsdomainprimary', 'ddnsdomainkeyname', 'ddnsdomainkey', 'ddnsupdate', 'ntp1', 'ntp2', 'tftp', 'ipaddr', 'winsserver', 'dnsserver'); foreach ($config_copy_fieldnames as $fieldname) { - if (isset($config['dhcpd'][$if]['staticmap'][$id][$fieldname])) { + if (isset($if) && isset($id) && isset($config['dhcpd'][$if]['staticmap'][$id][$fieldname])) { $pconfig[$fieldname] = $config['dhcpd'][$if]['staticmap'][$id][$fieldname]; } elseif (isset($_GET[$fieldname])) { $pconfig[$fieldname] = $_GET[$fieldname]; diff --git a/src/www/services_dhcpv6.php b/src/www/services_dhcpv6.php index fec7f90cc..f55fd9b27 100644 --- a/src/www/services_dhcpv6.php +++ b/src/www/services_dhcpv6.php @@ -74,7 +74,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { "IP addresses. Only interfaces configured with a static IP will be shown." ); foreach ($config['interfaces'] as $if_id => $intf) { - if (!empty($intf['enable']) && is_ipaddrv6($intf['ipaddrv6']) && !is_linklocal($oc['ipaddrv6'])) { + if (!empty($intf['enable']) && isset($intf['ipaddrv6']) && is_ipaddrv6($intf['ipaddrv6']) && !is_linklocal($intf['ipaddrv6'])) { $if = $if_id; break; } @@ -445,7 +445,7 @@ include("head.inc"); /* active tabs */ $tab_array_main = array(); foreach ($config['interfaces'] as $if_id => $intf) { - if (!empty($intf['enable']) && is_ipaddrv6($intf['ipaddrv6'])) { + if (!empty($intf['enable']) && isset($intf['ipaddrv6']) && is_ipaddrv6($intf['ipaddrv6'])) { $ifname = !empty($intf['descr']) ? htmlspecialchars($intf['descr']) : strtoupper($if_id); if ($if_id == $if) { $tab_array_main[] = array($ifname, true, "services_dhcpv6.php?if={$if_id}"); @@ -815,7 +815,7 @@ include("head.inc"); foreach ($config['dhcpdv6'][$if]['staticmap'] as $mapent): ?> - + diff --git a/src/www/services_dhcpv6_edit.php b/src/www/services_dhcpv6_edit.php index ece2e9807..3b79b01d3 100644 --- a/src/www/services_dhcpv6_edit.php +++ b/src/www/services_dhcpv6_edit.php @@ -37,7 +37,6 @@ function staticmapcmp($a, $b) } - if ($_SERVER['REQUEST_METHOD'] === 'GET') { // handle identifiers and action if (!empty($_GET['if']) && !empty($config['interfaces'][$_GET['if']])) { @@ -46,7 +45,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { header("Location: services_dhcpv6.php"); exit; } - if (!empty($config['dhcpdv6'][$if]['staticmap'][$_GET['id']])) { + if (isset($if) && isset($_GET['id']) && !empty($config['dhcpdv6'][$if]['staticmap'][$_GET['id']])) { $id = $_GET['id']; } @@ -54,7 +53,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig = array(); $config_copy_fieldnames = array('duid', 'hostname', 'ipaddrv6', 'filename' ,'rootpath' ,'descr'); foreach ($config_copy_fieldnames as $fieldname) { - if (isset($config['dhcpdv6'][$if]['staticmap'][$id][$fieldname])) { + if (isset($if) && isset($id) && isset($config['dhcpdv6'][$if]['staticmap'][$id][$fieldname])) { $pconfig[$fieldname] = $config['dhcpdv6'][$if]['staticmap'][$id][$fieldname]; } elseif (isset($_GET[$fieldname])) { $pconfig[$fieldname] = $_GET[$fieldname];