. */ // ************************************************************************************************************** // // The purpose of this script is to dynamically remove hosts from your local network. Well, hosts won't actually // be kicked off the network, but they will be moved into the unknown hosts pool. See add_host.php for more info. // Hosts can be removed individually, or more interesting, hosts can be removed after their expiration date if // you have added hosts using the add_host.php script and set an expiration date. To do this automatically, maybe // add a script to your hourly cron like the following: // // #!/bin/sh // wget -O - http://username:password@localhost/secure/rm_host.php?old=true > /dev/null 2>&1 // // And boom! You can temporarily add hosts to the known pool of your local network and have them auto-expire // // ************************************************************************************************************** // ************************************************************************************************************** // // Apache will need to be able to sudo your dhcpd init script, and write to dhcpd.conf and the hosts file: // visudo: www-data ALL=NOPASSWD: /etc/init.d/dhcp3-server // // ************************************************************************************************************** $dhcpd_conf_path = "/etc/dhcp3/dhcpd.conf"; $dhcpd_init_path = "/etc/init.d/dhcp3-server"; $hosts_path = "/etc/hosts"; $admin = str_replace("!", "@", "root!jusme.org"); print "\n"; print "
\n"; print "Old hosts removed:\n";
foreach ($removed as $name)
print "
$name\n";
}
}
elseif ($_GET["submit"] == "true")
{
$name = $_POST["name"];
$dhcpd = $orig_dhcpd = file_get_contents($dhcpd_conf_path);
$dhcpd = preg_replace("/host $name\\n{.*}\\n/sU", "", $dhcpd);
file_put_contents($dhcpd_conf_path, $dhcpd);
passthru("sudo $dhcpd_init_path restart", $ret);
// Restarting dhcpd failed, probably malformed conf file
if ($ret != 0)
{
// Revert back to previous data, which presumably was working before
file_put_contents($dhcpd_conf_path, $orig_dhcpd);
passthru("sudo $dhcpd_init_path restart", $ret);
die('DHCPD restart failed!');
}
$hosts = file_get_contents($hosts_path);
$hosts = preg_replace("/\d+\.\d+\.\d+\.\d+\t$name( .*)?\\n/U", "", $hosts);
file_put_contents($hosts_path, $hosts);
print "
Host removed.\n"; } else { $dhcpd = file_get_contents($dhcpd_conf_path); preg_match_all("/host (.*)\\n{/U", $dhcpd, $matches); print "
\n"; print "OR
\n"; print "\n"; } print "\n"; print "\n"; ?>