getFilename() === "blacklist.txt")
{
$blacklist = process_file(file_get_contents($file));
echo "Processing blacklist.txt
\n";
exec("sudo pihole -b -nr --nuke");
exec("sudo pihole -b -q -nr ".implode(" ", $blacklist));
$importedsomething = true;
}
if(isset($_POST["whitelist"]) && $file->getFilename() === "whitelist.txt")
{
$whitelist = process_file(file_get_contents($file));
echo "Processing whitelist.txt
\n";
exec("sudo pihole -w -nr --nuke");
exec("sudo pihole -w -q -nr ".implode(" ", $whitelist));
$importedsomething = true;
}
if(isset($_POST["wildlist"]) && $file->getFilename() === "wildcardblocking.txt")
{
$wildlist = process_file(file_get_contents($file));
echo "Processing wildcardblocking.txt
\n";
exec("sudo pihole -wild -nr --nuke");
exec("sudo pihole -wild -q -nr ".implode(" ", $wildlist));
$importedsomething = true;
}
if($importedsomething)
{
exec("sudo pihole restartdns");
}
}
unlink($fullfilename);
echo "OK";
}
else
{
die("No file transmitted or parameter error.");
}
}
else
{
$tarname = "pi-hole-teleporter_".date("Y-m-d_h-i-s").".tar";
$filename = $tarname.".gz";
$archive_file_name = sys_get_temp_dir() ."/". $tarname;
$archive = new PharData($archive_file_name);
if ($archive->isWritable() !== TRUE) {
exit("cannot open/create ".htmlentities($archive_file_name)."
\nPHP user: ".exec('whoami')."\n");
}
archive_add_file("/etc/pihole/","whitelist.txt");
archive_add_file("/etc/pihole/","blacklist.txt");
archive_add_file("/etc/pihole/","adlists.list");
archive_add_file("/etc/pihole/","setupVars.conf");
archive_add_directory("/etc/dnsmasq.d/");
$archive["wildcardblocking.txt"] = getWildcardListContent();
$archive->compress(Phar::GZ); // Creates a gziped copy
unlink($archive_file_name); // Unlink original tar file as it is not needed anymore
$archive_file_name .= ".gz"; // Append ".gz" extension to ".tar"
header("Content-type: application/zip");
header('Content-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=".$filename);
header("Content-length: " . filesize($archive_file_name));
header("Pragma: no-cache");
header("Expires: 0");
if(ob_get_length() > 0) ob_end_clean();
readfile($archive_file_name);
ignore_user_abort(true);
unlink($archive_file_name);
exit;
}
?>