Modal Dialog for Teleporter-import

fixes page reload every time the DHCP tab gets active

Signed-off-by: Th3M3 <the_me@outlook.de>
This commit is contained in:
Th3M3
2020-05-21 18:52:00 +02:00
committed by Adam Warner
parent ce3e2dba0a
commit 0d24f25f3c
3 changed files with 112 additions and 20 deletions
+44 -4
View File
@@ -18,6 +18,50 @@ $(function () {
$('input[name="AddIP"]').val(ip);
$('input[name="AddMAC"]').val(mac);
});
// prepare Teleporter Modal & iframe for operation
$("#teleporterModal").on("show.bs.modal", function () {
$('iframe[name="teleporter_iframe"]').removeAttr("style").contents().find("body").html("");
$(this).find("button").prop("disabled", true);
$(this).find(".overlay").show();
});
// set Teleporter iframe's font, enable Modal's button(s), ...
$('iframe[name="teleporter_iframe"]').on("load", function () {
var font = {
"font-family": $("pre").css("font-family"),
"font-size": $("pre").css("font-size")
};
var contents = $(this).contents();
contents.find("body").css(font);
$("#teleporterModal").find(".overlay").hide();
var BtnEls = $(this).parents(".modal-content").find("button").prop("disabled", false);
// force user to reload the page if necessary
var reloadEl = contents.find("span[data-forcereload]");
if (reloadEl.length > 0) {
var msg = "The page must now be reloaded to display the imported entries";
reloadEl.append(msg);
BtnEls.toggleClass("hidden")
.not(".hidden")
.on("click", function () {
// window.location.href avoids a browser warning for resending form data
window.location = window.location.href;
});
}
// expand iframe's height
var contentHeight = contents.find("html").height();
if (contentHeight > $(this).height()) {
$(this).height(contentHeight);
}
});
// display selected import file on button's adjacent textfield
$("#zip_file").change(function () {
var fileName = $(this)[0].files.length === 1 ? $(this)[0].files[0].name : "";
$("#zip_filename").val(fileName);
});
});
$(".confirm-poweroff").confirm({
text: "Are you sure you want to send a poweroff command to your Pi-hole?",
@@ -258,10 +302,6 @@ $(function () {
$(".nav-tabs a").on("shown.bs.tab", function (e) {
var tab = e.target.hash.substring(1);
window.history.pushState("", "", "?tab=" + tab);
if (tab === "piholedhcp") {
window.location.reload();
}
window.scrollTo(0, 0);
});
+28 -13
View File
@@ -320,6 +320,15 @@ function process_file($contents)
return $domains;
}
function noun($num)
{
if($num === 1)
{
return " entry";
}
return " entries";
}
if(isset($_POST["action"]))
{
if($_FILES["zip_file"]["name"] && $_POST["action"] == "in")
@@ -352,6 +361,7 @@ if(isset($_POST["action"]))
$archive = new PharData($fullfilename);
$importedsomething = false;
$reloadsettingspage = false;
$flushtables = isset($_POST["flushtables"]);
@@ -360,21 +370,21 @@ if(isset($_POST["action"]))
if(isset($_POST["blacklist"]) && $file->getFilename() === "blacklist.txt")
{
$num = archive_insert_into_table($file, "blacklist", $flushtables);
echo "Processed blacklist (exact) (".$num." entries)<br>\n";
echo "Processed blacklist (exact) (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
if(isset($_POST["whitelist"]) && $file->getFilename() === "whitelist.txt")
{
$num = archive_insert_into_table($file, "whitelist", $flushtables);
echo "Processed whitelist (exact) (".$num." entries)<br>\n";
echo "Processed whitelist (exact) (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
if(isset($_POST["regexlist"]) && $file->getFilename() === "regex.list")
{
$num = archive_insert_into_table($file, "regex_blacklist", $flushtables);
echo "Processed blacklist (regex) (".$num." entries)<br>\n";
echo "Processed blacklist (regex) (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
@@ -382,63 +392,63 @@ if(isset($_POST["action"]))
if(isset($_POST["regexlist"]) && $file->getFilename() === "wildcardblocking.txt")
{
$num = archive_insert_into_table($file, "regex_blacklist", $flushtables, true);
echo "Processed blacklist (regex, wildcard style) (".$num." entries)<br>\n";
echo "Processed blacklist (regex, wildcard style) (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
if(isset($_POST["auditlog"]) && $file->getFilename() === "auditlog.list")
{
$num = archive_insert_into_table($file, "domain_audit", $flushtables);
echo "Processed audit log (".$num." entries)<br>\n";
echo "Processed audit log (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
if(isset($_POST["adlist"]) && $file->getFilename() === "adlists.list")
{
$num = archive_insert_into_table($file, "adlist", $flushtables);
echo "Processed adlists (".$num." entries)<br>\n";
echo "Processed adlists (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
if(isset($_POST["blacklist"]) && $file->getFilename() === "blacklist.exact.json")
{
$num = archive_restore_table($file, "blacklist", $flushtables);
echo "Processed blacklist (exact) (".$num." entries)<br>\n";
echo "Processed blacklist (exact) (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
if(isset($_POST["regexlist"]) && $file->getFilename() === "blacklist.regex.json")
{
$num = archive_restore_table($file, "regex_blacklist", $flushtables);
echo "Processed blacklist (regex) (".$num." entries)<br>\n";
echo "Processed blacklist (regex) (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
if(isset($_POST["whitelist"]) && $file->getFilename() === "whitelist.exact.json")
{
$num = archive_restore_table($file, "whitelist", $flushtables);
echo "Processed whitelist (exact) (".$num." entries)<br>\n";
echo "Processed whitelist (exact) (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
if(isset($_POST["regex_whitelist"]) && $file->getFilename() === "whitelist.regex.json")
{
$num = archive_restore_table($file, "regex_whitelist", $flushtables);
echo "Processed whitelist (regex) (".$num." entries)<br>\n";
echo "Processed whitelist (regex) (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
if(isset($_POST["adlist"]) && $file->getFilename() === "adlist.json")
{
$num = archive_restore_table($file, "adlist", $flushtables);
echo "Processed adlist (".$num." entries)<br>\n";
echo "Processed adlist (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
if(isset($_POST["auditlog"]) && $file->getFilename() === "domain_audit.json")
{
$num = archive_restore_table($file, "domain_audit", $flushtables);
echo "Processed domain_audit (".$num." entries)<br>\n";
echo "Processed domain_audit (".$num.noun($num).")<br>\n";
$importedsomething = true;
}
@@ -498,9 +508,10 @@ if(isset($_POST["action"]))
}
readStaticLeasesFile();
echo "Processed static DHCP leases (".$num." entries)<br>\n";
echo "Processed static DHCP leases (".$num.noun($num).")<br>\n";
if($num > 0) {
$importedsomething = true;
$reloadsettingspage = true;
}
}
@@ -560,6 +571,10 @@ if(isset($_POST["action"]))
unlink($fullfilename);
echo "OK";
if($reloadsettingspage)
{
echo "<br>\n<span data-forcereload></span>";
}
}
else
{