aboutsummaryrefslogtreecommitdiffstats
path: root/config/Fit123/bin/ltsp/services_dhcp.abc
diff options
context:
space:
mode:
Diffstat (limited to 'config/Fit123/bin/ltsp/services_dhcp.abc')
-rwxr-xr-x[-rw-r--r--]config/Fit123/bin/ltsp/services_dhcp.abc66
1 files changed, 60 insertions, 6 deletions
diff --git a/config/Fit123/bin/ltsp/services_dhcp.abc b/config/Fit123/bin/ltsp/services_dhcp.abc
index 89548502..7a203491 100644..100755
--- a/config/Fit123/bin/ltsp/services_dhcp.abc
+++ b/config/Fit123/bin/ltsp/services_dhcp.abc
@@ -31,6 +31,57 @@
require("guiconfig.inc");
+/* Fix failover DHCP problem
+ * http://article.gmane.org/gmane.comp.security.firewalls.pfsense.support/18749
+ */
+ini_set("memory_limit","64M");
+
+/* This function will remove entries from dhcpd.leases that would otherwise
+ * overlap with static DHCP reservations. If we don't clean these out,
+ * then DHCP will print a warning in the logs about a duplicate lease
+ */
+function dhcp_clean_leases() {
+ global $g, $config;
+ $leasesfile = "{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases";
+ if (!file_exists($leasesfile))
+ return;
+ /* Build list of static MACs */
+ $staticmacs = array();
+ foreach($config['interfaces'] as $ifname => $ifarr)
+ if (is_array($config['dhcpd'][$ifname]['staticmap']))
+ foreach($config['dhcpd'][$ifname]['staticmap'] as $static)
+ $staticmacs[] = $static['mac'];
+ /* Read existing leases */
+ $leases_contents = explode("\n", file_get_contents($leasesfile));
+ $newleases_contents = array();
+ $i=0;
+ while ($i < count($leases_contents)) {
+ /* Find a lease definition */
+ if (substr($leases_contents[$i], 0, 6) == "lease ") {
+ $templease = array();
+ $thismac = "";
+ /* Read to the end of the lease declaration */
+ do {
+ if (substr($leases_contents[$i], 0, 20) == " hardware ethernet ")
+ $thismac = substr($leases_contents[$i], 20, 17);
+ $templease[] = $leases_contents[$i];
+ $i++;
+ } while ($leases_contents[$i-1] != "}");
+ /* Check for a matching MAC address and if not present, keep it. */
+ if (! in_array($thismac, $staticmacs))
+ $newleases_contents = array_merge($newleases_contents, $templease);
+ } else {
+ /* It's a line we want to keep, copy it over. */
+ $newleases_contents[] = $leases_contents[$i];
+ $i++;
+ }
+ }
+ /* Write out the new leases file */
+ $fd = fopen($leasesfile, 'w');
+ fwrite($fd, implode("\n", $newleases_contents));
+ fclose($fd);
+}
+
$if = $_GET['if'];
if ($_POST['if'])
$if = $_POST['if'];
@@ -225,7 +276,7 @@ if ($_POST) {
$config['dhcpd'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
$config['dhcpd'][$if]['next-server'] = $_POST['nextserver'];
$config['dhcpd'][$if]['filename'] = $_POST['filename'];
- $config['dhcpd'][$if]['rootpath'] = $_POST['rootpath'];
+ $config['dhcpd'][$if]['rootpath'] = $_POST['rootpath'];
write_config();
@@ -236,6 +287,9 @@ if ($_POST) {
$retvaldhcp = 0;
$retvaldns = 0;
config_lock();
+ /* Stop DHCP so we can cleanup leases */
+ killbyname("dhcpd");
+ dhcp_clean_leases();
/* dnsmasq_configure calls dhcpd_configure */
/* no need to restart dhcpd twice */
if (isset($config['dnsmasq']['regdhcpstatic'])) {
@@ -302,7 +356,7 @@ function enable_change(enable_over) {
document.iform.netboot.disabled = endis;
document.iform.nextserver.disabled = endis;
document.iform.filename.disabled = endis;
- document.iform.rootpath.disabled = endis;
+ document.iform.rootpath.disabled = endis;
document.iform.denyunknown.disabled = endis;
}
@@ -544,10 +598,10 @@ function show_netboot_config() {
<p>
<input name="filename" type="text" class="formfld" id="filename" size="20" value="<?=htmlspecialchars($pconfig['filename']);?>"><br>
Enter the filename used for network booting.<br />
- Note: You need both a filename and a boot server configured for this to work!<br />
- <p>
- <input name="rootpath" type="text" class="formfld" id="rootpath" size="20" value="<?=htmlspecialchars($pconfig['rootpath']);?>"><br>
- Enter option root-path.
+ Note: You need both a filename and a boot server configured for this to work!<br />
+ <p>
+ <input name="rootpath" type="text" class="formfld" id="rootpath" size="20" value="<?=htmlspecialchars($pconfig['rootpath']);?>"><br>
+ Enter option root-path.
</div>
</td>
</tr>