Merge pull request #432 from pi-hole/tweak/teleporter

Some tweaks for the Pi-hole Teleporter
This commit is contained in:
Mcat12
2017-03-06 18:00:27 -05:00
committed by DL6ER
parent 078cbb1585
commit f7420d2786
+27 -7
View File
@@ -7,7 +7,9 @@
* Please see LICENSE file for your rights under this license. */ * Please see LICENSE file for your rights under this license. */
require "password.php"; require "password.php";
if(!$auth) die("Not authorized"); if (php_sapi_name() !== "cli") {
if(!$auth) die("Not authorized");
}
require('func.php'); require('func.php');
function process_zip($name) function process_zip($name)
@@ -36,6 +38,22 @@ function add_to_zip($path,$name)
$zip->addFile($path.$name,$name); $zip->addFile($path.$name,$name);
} }
function add_dir_to_zip($path)
{
global $zip;
if($dir = opendir($path))
{
while(false !== ($entry = readdir($dir)))
{
if($entry !== "." && $entry !== "..")
{
$zip->addFile($path.$entry,$entry);
}
}
closedir($dir);
}
}
function check_domains($domains) function check_domains($domains)
{ {
foreach($domains as $domain) foreach($domains as $domain)
@@ -67,9 +85,9 @@ function getWildcardListContent() {
return ""; return "";
} }
if($_POST["action"] == "in") if(isset($_POST["action"]))
{ {
if($_FILES["zip_file"]["name"]) if($_FILES["zip_file"]["name"] && $_POST["action"] == "in")
{ {
$filename = $_FILES["zip_file"]["name"]; $filename = $_FILES["zip_file"]["name"];
$source = $_FILES["zip_file"]["tmp_name"]; $source = $_FILES["zip_file"]["tmp_name"];
@@ -122,12 +140,13 @@ if($_POST["action"] == "in")
} }
else else
{ {
die("No file transmitted."); die("No file transmitted or parameter error.");
} }
} }
else else
{ {
$archive_file_name = "/var/www/html/pi-hole-teleporter_".microtime(true).".zip"; $filename = "pi-hole-teleporter_".date("Y-m-d_h-i-s").".zip";
$archive_file_name = "/var/www/html/".$filename;
$zip = new ZipArchive(); $zip = new ZipArchive();
touch($archive_file_name); touch($archive_file_name);
$res = $zip->open($archive_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE); $res = $zip->open($archive_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE);
@@ -140,17 +159,18 @@ else
add_to_zip("/etc/pihole/","blacklist.txt"); add_to_zip("/etc/pihole/","blacklist.txt");
add_to_zip("/etc/pihole/","adlists.list"); add_to_zip("/etc/pihole/","adlists.list");
add_to_zip("/etc/pihole/","setupVars.conf"); add_to_zip("/etc/pihole/","setupVars.conf");
add_dir_to_zip("/etc/dnsmasq.d/");
$zip->addFromString("wildcardblocking.txt", getWildcardListContent()); $zip->addFromString("wildcardblocking.txt", getWildcardListContent());
$zip->close(); $zip->close();
header("Content-type: application/zip"); header("Content-type: application/zip");
header('Content-Transfer-Encoding: binary'); header('Content-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=pi-hole-teleporter.zip"); header("Content-Disposition: attachment; filename=".$filename);
header("Content-length: " . filesize($archive_file_name)); header("Content-length: " . filesize($archive_file_name));
header("Pragma: no-cache"); header("Pragma: no-cache");
header("Expires: 0"); header("Expires: 0");
ob_end_clean(); if(ob_get_length() > 0) ob_end_clean();
readfile($archive_file_name); readfile($archive_file_name);
exit; exit;
} }