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,93 +494,74 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -493,93 +494,74 @@ 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']]);
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'; $service_hook = 'dhcpd';
legacy_html_escape_form_data($pconfig); legacy_html_escape_form_data($pconfig);
include("head.inc"); include("head.inc");
?> ?>
<body> <body>
<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,28 +1109,33 @@ include("head.inc"); ...@@ -1127,28 +1109,33 @@ include("head.inc");
</tr> </tr>
</table> </table>
</div> </div>
</form>
</div>
</section>
<?php <?php
if (!isset($pool) && !($act == "newpool")): ?> if (!isset($pool) && !($act == "newpool")): ?>
<div class="table-responsive"> <section class="col-xs-12">
<table class="table table-striped table-sort"> <div class="tab-content content-box col-xs-12">
<tr> <div class="table-responsive">
<td colspan="5" valign="top"><?=gettext("DHCP Static Mappings for this interface.");?></td> <table class="table table-striped table-sort">
<td>&nbsp;</td> <tr>
</tr> <td colspan="5" valign="top"><?=gettext("DHCP Static Mappings for this interface.");?></td>
<tr> <td>&nbsp;</td>
<td><?=gettext("Static ARP");?></td> </tr>
<td><?=gettext("MAC address");?></td> <tr>
<td><?=gettext("IP address");?></td> <td><?=gettext("Static ARP");?></td>
<td><?=gettext("Hostname");?></td> <td><?=gettext("MAC address");?></td>
<td><?=gettext("Description");?></td> <td><?=gettext("IP address");?></td>
<td> <td><?=gettext("Hostname");?></td>
<a href="services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a> <td><?=gettext("Description");?></td>
</td> <td>
</tr> <a href="services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a>
</td>
</tr>
<?php <?php
if (!empty($config['dhcpd'][$if]['staticmap'])): if (!empty($config['dhcpd'][$if]['staticmap'])):
$i = 0; $i = 0;
foreach ($config['dhcpd'][$if]['staticmap'] as $mapent): ?> foreach ($config['dhcpd'][$if]['staticmap'] as $mapent): ?>
<?php <?php
if($mapent['mac'] <> "" || $mapent['ipaddr'] <> ""): ?> if($mapent['mac'] <> "" || $mapent['ipaddr'] <> ""): ?>
<tr> <tr>
...@@ -1181,15 +1168,14 @@ include("head.inc"); ...@@ -1181,15 +1168,14 @@ include("head.inc");
$i++; $i++;
endforeach; endforeach;
endif; ?> endif; ?>
</table> </table>
</div> </div>
<?php
endif; ?>
</form>
</div> </div>
</section>
<?php
endif; ?>
<?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