diff --git a/scripts/pi-hole/js/settings-teleporter.js b/scripts/pi-hole/js/settings-teleporter.js new file mode 100644 index 00000000..a1dbacee --- /dev/null +++ b/scripts/pi-hole/js/settings-teleporter.js @@ -0,0 +1,72 @@ +/* Pi-hole: A black hole for Internet advertisements + * (c) 2023 Pi-hole, LLC (https://pi-hole.net) + * Network-wide ad blocking via your own hardware. + * + * This file is copyright under the latest version of the EUPL. + * Please see LICENSE file for your rights under this license. */ + +/* global utils:false */ + +// Add event listener to import button +document.getElementById("submit-import").addEventListener("click", function () { + importZIP(); +}); + +// Upload file to Pi-hole +function importZIP() { + var file = document.getElementById("file").files[0]; + if (file === undefined) { + alert("Please select a file to import."); + return; + } + + // https://caniuse.com/fetch - everything except IE + // This is fine, as we dropped support for IE a while ago + if (typeof fetch !== "function") { + alert("Importing Tricorder files is not supported with this browser!"); + return; + } + + const formData = new FormData(); + formData.append("file", file); + // eslint-disable-next-line compat/compat + fetch("/api/teleporter", { + method: "POST", + body: formData, + }) + .then(response => response.json()) + .then(data => { + $("#import-spinner").hide(); + $("#modal-import-success").hide(); + $("#modal-import-error").hide(); + $("#modal-import-info").hide(); + + if ("error" in data) { + $("#modal-import-error").show(); + $("#modal-import-error-title").text("Error: " + data.error.message); + if (data.error.hint !== null) $("#modal-import-error-message").text(data.error.hint); + } else if ("files" in data) { + $("#modal-import-success").show(); + $("#modal-import-success-title").text("Import successful"); + var text = "

Processed files:

"; + $("#modal-import-success-message").html(text); + } + + if ("took" in data) { + $("#modal-import-info-message").text( + "Processing took " + data.took.toFixed(3) + " seconds." + ); + } + + $("#modal-import").modal("show"); + }) + .catch(error => { + alert("An unexpected error occurred."); + console.error(error); // eslint-disable-line no-console + }); +} diff --git a/scripts/pi-hole/lua/sidebar.lp b/scripts/pi-hole/lua/sidebar.lp index de4c5009..e1da3afa 100644 --- a/scripts/pi-hole/lua/sidebar.lp +++ b/scripts/pi-hole/lua/sidebar.lp @@ -165,7 +165,7 @@
  • "> - Teleporter + Teleporter
  • "> diff --git a/settings-teleporter.lp b/settings-teleporter.lp new file mode 100644 index 00000000..4cb2126f --- /dev/null +++ b/settings-teleporter.lp @@ -0,0 +1,95 @@ + +
    +
    +
    +
    +

    Export your Pi-hole's configuration

    +
    +
    +
    +
    +

    Warning: This archive contains sensitive information about your Pi-hole installation, e.g. the API token and the 2FA-TOTP secret (if enabled). Please be careful with this file and do not share it with anyone even if they claim to help you.

    + Warning: You are currently not using an end-to-end encryption. This means that your API token and 2FA-TOTP secret will be transmitted in plain text. We recommend to use HTTPS when exporting your configuration.

    ") end ?> +
    + +
    +
    +
    +
    +
    +
    +
    +

    Import previously imported configuration

    +
    +
    +
    +
    +
    + + +

    When importing settings from a newer version of Pi-hole, not yet existing settings will be ignored. When importing from an older version of Pi-hole, settings for newer features will be initialized with their default values.

    +
    +
    + +
    +
    +
    +
    +
    + + + + + + +