From 11368987e9096a2f75528b390d1c7853fd6438f2 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 15 Feb 2016 13:21:30 +0100 Subject: [PATCH] (legacy) refactor services_dhcp.php --- src/www/services_dhcp.php | 190 ++++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 102 deletions(-) diff --git a/src/www/services_dhcp.php b/src/www/services_dhcp.php index a38ef37fa..39c681f08 100644 --- a/src/www/services_dhcp.php +++ b/src/www/services_dhcp.php @@ -187,7 +187,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig['range_to'] = !empty($dhcpdconf['range']['to']) ? $dhcpdconf['range']['to'] : ""; $pconfig['wins1'] = !empty($dhcpdconf['winsserver'][0]) ? $dhcpdconf['winsserver'][0] : ""; $pconfig['wins2'] = !empty($dhcpdconf['winsserver'][1]) ? $dhcpdconf['winsserver'][1] : ""; - $pconfig['dns1'] = !empty($dhcpdconf['dnsserver'][0]) ? $dhcpdconf['winsserver'][0] : ""; + $pconfig['dns1'] = !empty($dhcpdconf['dnsserver'][0]) ? $dhcpdconf['dnsserver'][0] : ""; $pconfig['dns2'] = !empty($dhcpdconf['dnsserver'][1]) ? $dhcpdconf['dnsserver'][1] : ""; $pconfig['ntp1'] = !empty($dhcpdconf['ntpserver'][0]) ? $dhcpdconf['winsserver'][0] : ""; $pconfig['ntp2'] = !empty($dhcpdconf['ntpserver'][1]) ? $dhcpdconf['ntpserver'][1] : ""; @@ -455,11 +455,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $dhcpdconf['dnsserver'][] = $pconfig['dns2']; } - // copy pools to this config - if (!empty($config['dhcpd'][$if]['pool'])) { - $dhcpdconf['pools'] = $config['dhcpd'][$if]['pool']; - } - // handle changes if (!isset($pool) && $act != "newpool") { if (isset($config['dhcpd'][$if]['enable']) != !empty($pconfig['enable'])) { @@ -478,6 +473,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } elseif ($act == "newpool") { $a_pools[] = $dhcpdconf; } else { + // copy structures back in + foreach (array('pool', 'staticmap') as $fieldname) { + if (!empty($config['dhcpd'][$if][$fieldname])) { + $dhcpdconf[$fieldname] = $config['dhcpd'][$if][$fieldname]; + } + } $config['dhcpd'][$if] = $dhcpdconf; } write_config(); @@ -493,93 +494,74 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { reconfigure_dhcpd(); header("Location: services_dhcp.php?if={$if}"); exit; + } elseif ($act == "del") { + if (!empty($config['dhcpd'][$if]['staticmap'][$_POST['id']])) { + unset($config['dhcpd'][$if]['staticmap'][$_POST['id']]); + write_config(); + if(isset($config['dhcpd'][$if]['enable'])) { + mark_subsystem_dirty('staticmaps'); + if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic'])) { + mark_subsystem_dirty('hosts'); + } elseif (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) { + mark_subsystem_dirty('unbound'); + } + } + } + header("Location: services_dhcp.php?if={$if}"); + exit; + } elseif ($act == "delpool") { + if (!empty($a_pools[$_POST['id']])) { + unset($a_pools[$_POST['id']]); + write_config(); + } + header("Location: services_dhcp.php?if={$if}"); + exit; } } - - -if ($act == "delpool") { - if ($a_pools[$_GET['id']]) { - unset($a_pools[$_GET['id']]); - write_config(); - header("Location: services_dhcp.php?if={$if}"); - exit; - } -} - -if ($act == "del") { - if (!empty($config['dhcpd'][$if]['staticmap'])) { - $a_maps = &$config['dhcpd'][$if]['staticmap']; - } else { - $a_maps = array(); - } - if ($a_maps[$_GET['id']]) { - unset($a_maps[$_GET['id']]); - write_config(); - if(isset($config['dhcpd'][$if]['enable'])) { - mark_subsystem_dirty('staticmaps'); - if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic'])) { - mark_subsystem_dirty('hosts'); - } elseif (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) { - mark_subsystem_dirty('unbound'); - } - } - header("Location: services_dhcp.php?if={$if}"); - exit; - } -} - $service_hook = 'dhcpd'; legacy_html_escape_form_data($pconfig); include("head.inc"); - ?> @@ -1127,28 +1109,33 @@ include("head.inc"); + + + -
- - - - - - - - - - - - - + if (!isset($pool) && !($act == "newpool")): ?> +
+
+
+
 
- -
+ + + + + + + + + + + + + if (!empty($config['dhcpd'][$if]['staticmap'])): + $i = 0; + foreach ($config['dhcpd'][$if]['staticmap'] as $mapent): ?> "" || $mapent['ipaddr'] <> ""): ?> @@ -1181,15 +1168,14 @@ include("head.inc"); $i++; endforeach; endif; ?> -
 
+ +
-
- - + + + - + endif; ?> +