Commit 62490b09 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy) refactor services_dhcp.php

(cherry picked from commit 11368987)
parent 0becf0c5
...@@ -187,7 +187,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -187,7 +187,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig['range_to'] = !empty($dhcpdconf['range']['to']) ? $dhcpdconf['range']['to'] : ""; $pconfig['range_to'] = !empty($dhcpdconf['range']['to']) ? $dhcpdconf['range']['to'] : "";
$pconfig['wins1'] = !empty($dhcpdconf['winsserver'][0]) ? $dhcpdconf['winsserver'][0] : ""; $pconfig['wins1'] = !empty($dhcpdconf['winsserver'][0]) ? $dhcpdconf['winsserver'][0] : "";
$pconfig['wins2'] = !empty($dhcpdconf['winsserver'][1]) ? $dhcpdconf['winsserver'][1] : ""; $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['dns2'] = !empty($dhcpdconf['dnsserver'][1]) ? $dhcpdconf['dnsserver'][1] : "";
$pconfig['ntp1'] = !empty($dhcpdconf['ntpserver'][0]) ? $dhcpdconf['winsserver'][0] : ""; $pconfig['ntp1'] = !empty($dhcpdconf['ntpserver'][0]) ? $dhcpdconf['winsserver'][0] : "";
$pconfig['ntp2'] = !empty($dhcpdconf['ntpserver'][1]) ? $dhcpdconf['ntpserver'][1] : ""; $pconfig['ntp2'] = !empty($dhcpdconf['ntpserver'][1]) ? $dhcpdconf['ntpserver'][1] : "";
...@@ -455,11 +455,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -455,11 +455,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$dhcpdconf['dnsserver'][] = $pconfig['dns2']; $dhcpdconf['dnsserver'][] = $pconfig['dns2'];
} }
// copy pools to this config
if (!empty($config['dhcpd'][$if]['pool'])) {
$dhcpdconf['pools'] = $config['dhcpd'][$if]['pool'];
}
// handle changes // handle changes
if (!isset($pool) && $act != "newpool") { if (!isset($pool) && $act != "newpool") {
if (isset($config['dhcpd'][$if]['enable']) != !empty($pconfig['enable'])) { if (isset($config['dhcpd'][$if]['enable']) != !empty($pconfig['enable'])) {
...@@ -478,6 +473,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -478,6 +473,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} elseif ($act == "newpool") { } elseif ($act == "newpool") {
$a_pools[] = $dhcpdconf; $a_pools[] = $dhcpdconf;
} else { } 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; $config['dhcpd'][$if] = $dhcpdconf;
} }
write_config(); write_config();
...@@ -493,28 +494,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -493,28 +494,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
reconfigure_dhcpd(); reconfigure_dhcpd();
header("Location: services_dhcp.php?if={$if}"); header("Location: services_dhcp.php?if={$if}");
exit; exit;
} } elseif ($act == "del") {
} if (!empty($config['dhcpd'][$if]['staticmap'][$_POST['id']])) {
unset($config['dhcpd'][$if]['staticmap'][$_POST['id']]);
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(); write_config();
if(isset($config['dhcpd'][$if]['enable'])) { if(isset($config['dhcpd'][$if]['enable'])) {
mark_subsystem_dirty('staticmaps'); mark_subsystem_dirty('staticmaps');
...@@ -524,6 +506,14 @@ if ($act == "del") { ...@@ -524,6 +506,14 @@ if ($act == "del") {
mark_subsystem_dirty('unbound'); 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}"); header("Location: services_dhcp.php?if={$if}");
exit; exit;
} }
...@@ -532,7 +522,6 @@ if ($act == "del") { ...@@ -532,7 +522,6 @@ if ($act == "del") {
$service_hook = 'dhcpd'; $service_hook = 'dhcpd';
legacy_html_escape_form_data($pconfig); legacy_html_escape_form_data($pconfig);
include("head.inc"); include("head.inc");
?> ?>
<body> <body>
...@@ -540,45 +529,38 @@ include("head.inc"); ...@@ -540,45 +529,38 @@ include("head.inc");
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
function show_shownumbervalue() { function show_shownumbervalue() {
document.getElementById("shownumbervaluebox").innerHTML=''; $("#shownumbervaluebox").html('');
aodiv = document.getElementById('shownumbervalue'); $("#shownumbervalue").show();
aodiv.style.display = "block";
} }
function show_ddns_config() { function show_ddns_config() {
document.getElementById("showddnsbox").innerHTML=''; $("#showddnsbox").html('');
aodiv = document.getElementById('showddns'); $("#showddns").show();
aodiv.style.display = "block";
} }
function show_maccontrol_config() { function show_maccontrol_config() {
document.getElementById("showmaccontrolbox").innerHTML=''; $("#showmaccontrolbox").html('');
aodiv = document.getElementById('showmaccontrol'); $("#showmaccontrol").show();
aodiv.style.display = "block";
} }
function show_ntp_config() { function show_ntp_config() {
document.getElementById("showntpbox").innerHTML=''; $("#showntpbox").html('');
aodiv = document.getElementById('showntp'); $("#showntp").show();
aodiv.style.display = "block";
} }
function show_tftp_config() { function show_tftp_config() {
document.getElementById("showtftpbox").innerHTML=''; $("#showtftpbox").html('');
aodiv = document.getElementById('showtftp'); $("#showtftp").show();
aodiv.style.display = "block";
} }
function show_ldap_config() { function show_ldap_config() {
document.getElementById("showldapbox").innerHTML=''; $("#showldapbox").html('');
aodiv = document.getElementById('showldap'); $("#showldap").show();
aodiv.style.display = "block";
} }
function show_netboot_config() { function show_netboot_config() {
document.getElementById("shownetbootbox").innerHTML=''; $("#shownetbootbox").html('');
aodiv = document.getElementById('shownetboot'); $("#shownetboot").show();
aodiv.style.display = "block";
} }
//]]> //]]>
</script> </script>
...@@ -1127,8 +1109,13 @@ include("head.inc"); ...@@ -1127,8 +1109,13 @@ include("head.inc");
</tr> </tr>
</table> </table>
</div> </div>
</form>
</div>
</section>
<?php <?php
if (!isset($pool) && !($act == "newpool")): ?> if (!isset($pool) && !($act == "newpool")): ?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-sort"> <table class="table table-striped table-sort">
<tr> <tr>
...@@ -1183,13 +1170,12 @@ include("head.inc"); ...@@ -1183,13 +1170,12 @@ include("head.inc");
endif; ?> endif; ?>
</table> </table>
</div> </div>
</div>
</section>
<?php <?php
endif; ?> endif; ?>
</form>
</div>
<?php <?php
endif; ?> endif; ?>
</section>
</div> </div>
</div> </div>
</section> </section>
......
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