mirror of
https://github.com/pi-hole/web.git
synced 2026-04-28 12:44:07 +01:00
Merge pull request #992 from trimalcione/devel
Add DHCP leases export/import from teleporter
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
require "password.php";
|
||||
require "auth.php"; // Also imports func.php
|
||||
require "database.php";
|
||||
require "savesettings.php";
|
||||
|
||||
if (php_sapi_name() !== "cli") {
|
||||
if(!$auth) die("Not authorized");
|
||||
@@ -225,6 +226,22 @@ function archive_add_directory($path,$subdir="")
|
||||
}
|
||||
}
|
||||
|
||||
function limit_length(&$item, $key)
|
||||
{
|
||||
// limit max length for a domain entry to 253 chars
|
||||
// return only a part of the string if it is longer
|
||||
$item = substr($item, 0, 253);
|
||||
}
|
||||
|
||||
function process_file($contents)
|
||||
{
|
||||
$domains = array_filter(explode("\n",$contents));
|
||||
// Walk array and apply a max string length
|
||||
// function to every member of the array of domains
|
||||
array_walk($domains, "limit_length");
|
||||
return $domains;
|
||||
}
|
||||
|
||||
if(isset($_POST["action"]))
|
||||
{
|
||||
if($_FILES["zip_file"]["name"] && $_POST["action"] == "in")
|
||||
@@ -260,7 +277,7 @@ if(isset($_POST["action"]))
|
||||
|
||||
$flushtables = isset($_POST["flushtables"]);
|
||||
|
||||
foreach($archive as $file)
|
||||
foreach(new RecursiveIteratorIterator($archive) as $file)
|
||||
{
|
||||
if(isset($_POST["blacklist"]) && $file->getFilename() === "blacklist.txt")
|
||||
{
|
||||
@@ -339,6 +356,31 @@ if(isset($_POST["action"]))
|
||||
echo "Processed domain_audit (".$num." entries)<br>\n";
|
||||
$importedsomething = true;
|
||||
}
|
||||
|
||||
if(isset($_POST["staticdhcpleases"]) && $file->getFilename() === "04-pihole-static-dhcp.conf")
|
||||
{
|
||||
if($flushtables) {
|
||||
$local_file = @fopen("/etc/dnsmasq.d/04-pihole-static-dhcp.conf", "r+");
|
||||
if ($local_file !== false) {
|
||||
ftruncate($local_file, 0);
|
||||
fclose($local_file);
|
||||
}
|
||||
}
|
||||
$num = 0;
|
||||
$staticdhcpleases = process_file(file_get_contents($file));
|
||||
foreach($staticdhcpleases as $lease) {
|
||||
list($mac,$ip,$hostname) = explode(",",$lease);
|
||||
$mac = formatMAC($mac);
|
||||
if(addStaticDHCPLease($mac,$ip,$hostname))
|
||||
$num++;
|
||||
}
|
||||
|
||||
readStaticLeasesFile();
|
||||
echo "Processed static DHCP leases (".$num." entries)<br>\n";
|
||||
if($num > 0) {
|
||||
$importedsomething = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($importedsomething)
|
||||
|
||||
Reference in New Issue
Block a user