mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
@@ -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 = "<p>Processed files:<ul>";
|
||||
for (var i = 0; i < data.files.length; i++) {
|
||||
text += "<li>/" + utils.escapeHtml(data.files[i]) + "</li>";
|
||||
}
|
||||
|
||||
text += "</ul></p>";
|
||||
$("#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
|
||||
});
|
||||
}
|
||||
@@ -165,7 +165,7 @@
|
||||
</li>
|
||||
<li class="<? if scriptname == 'settings-teleporter.lp' then mg.write(" active") end ?>">
|
||||
<a href="settings-teleporter.lp">
|
||||
<i class="fa-fw menu-icon fa-solid fa-file-export"></i> <span class="text-red">Teleporter</span>
|
||||
<i class="fa-fw menu-icon fa-solid fa-file-export"></i> <span class="text-green">Teleporter</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="<? if scriptname == 'settings-dns-records.lp' then mg.write(" active") end ?>">
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<? --[[
|
||||
* 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.
|
||||
--]]
|
||||
|
||||
mg.include('scripts/pi-hole/lua/header_authenticated.lp','r')
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="box box-warning">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Export your Pi-hole's configuration</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
<div class="col-lg-10">
|
||||
<p>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.</p>
|
||||
<? if not mg.request_info.https then mg.write("<p class='text-danger'>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.</p>") end ?>
|
||||
</div>
|
||||
<div class="col-lg-2">
|
||||
<a class="btn btn-app btn-success" href="/api/teleporter" target="_blank">
|
||||
<i class="fa fa-save"></i><br>Export
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="box box-warning">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Import previously imported configuration</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
<div class="col-lg-10">
|
||||
<div class="form-group">
|
||||
<label for="file">File input</label>
|
||||
<input type="file" name="file" id="file" accept=".zip">
|
||||
<p class="help-block">When importing settings from a <em>newer</em> version of Pi-hole, not yet existing settings will be ignored. When importing from an <em>older</em> version of Pi-hole, settings for newer features will be initialized with their default values.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-2">
|
||||
<a class="btn btn-app btn-success" id="submit-import">
|
||||
<i class="fa fa-upload"></i><br>Import
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="modal-import" style="display: none;">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">Importing Pi-hole teleporter file...</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Depending on your network speed, it may take a few moments until the file is uploaded and imported. Please be patient and don't interrupt the process...</p>
|
||||
<div class="text-center">
|
||||
<i id="import-spinner" class="fas fa-spinner fa-pulse fa-5x"></i>
|
||||
</div>
|
||||
<div id="modal-import-success" style="display:none">
|
||||
<div class="alert alert-success alert-dismissible">
|
||||
<h4><i class="icon fa fa-fw fa-check"></i> <span id="modal-import-success-title"></span></h4>
|
||||
<p id="modal-import-success-message"></p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="modal-import-error" style="display:none">
|
||||
<div class="alert alert-danger alert-dismissible">
|
||||
<h4><i class="icon fa fa-fw fa-ban"></i> <span id="modal-import-error-title"></span></h4>
|
||||
<p id="modal-import-error-message"></p>
|
||||
</div>
|
||||
</div>
|
||||
<p id="modal-import-info-message"></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="<?=pihole.fileversion('scripts/pi-hole/js/settings-teleporter.js')?>"></script>
|
||||
<script src="<?=pihole.fileversion('scripts/pi-hole/js/settings.js')?>"></script>
|
||||
|
||||
<? mg.include('scripts/pi-hole/lua/footer.lp','r')?>
|
||||
Reference in New Issue
Block a user