Use a random name when creating intermediat archive for teleporter

Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
Christian König
2022-07-02 13:35:53 +02:00
parent 032d0db8b9
commit 0caa8bd02b

View File

@@ -89,7 +89,7 @@ function archive_restore_table($file, $table, $flush=false)
{
$tableExists = $db->querySingle("SELECT name FROM sqlite_master WHERE type='table' AND name='".$table."';");
if ($tableExists)
{
{
$db->exec("DELETE FROM \"".$table."\"");
array_push($flushed_tables, $table);
}
@@ -354,6 +354,7 @@ if(isset($_POST["action"]))
}
$fullfilename = sys_get_temp_dir()."/".$filename;
if(!move_uploaded_file($source, $fullfilename))
{
die("Failed moving ".htmlentities($source)." to ".htmlentities($fullfilename));
@@ -603,7 +604,10 @@ else
$hostname = gethostname() ? str_replace(".", "_", gethostname())."-" : "";
$tarname = "pi-hole-".$hostname."teleporter_".date("Y-m-d_H-i-s").".tar";
$filename = $tarname.".gz";
$archive_file_name = sys_get_temp_dir() ."/". $tarname;
$archive_file_name = tempnam(sys_get_temp_dir(), 'pihole_teleporter_'); //create a random file name in the system's tmp dir for the intermediat archive
unlink($archive_file_name); //remove intermediate file created by tempnam()
$archive_file_name .= ".tar"; // Append ".tar" extension
$archive = new PharData($archive_file_name);
if ($archive->isWritable() !== TRUE) {