mirror of
https://github.com/pi-hole/web.git
synced 2025-12-20 02:38:28 +00:00
31
gravity.lp
Normal file
31
gravity.lp
Normal file
@@ -0,0 +1,31 @@
|
||||
<? --[[
|
||||
* Pi-hole: A black hole for Internet advertisements
|
||||
* (c) 2017 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')
|
||||
?>
|
||||
<!-- Title -->
|
||||
<div class="page-header">
|
||||
<h1>Update Gravity (list of blocked domains)</h1>
|
||||
</div>
|
||||
|
||||
<!-- Alerts -->
|
||||
<div id="alInfo" class="alert alert-info alert-dismissible fade in" role="alert" hidden>
|
||||
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
Updating... this may take a while. <strong>Please do not navigate away from or close this page.</strong>
|
||||
</div>
|
||||
<div id="alSuccess" class="alert alert-success alert-dismissible fade in" role="alert" hidden>
|
||||
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
Success!
|
||||
</div>
|
||||
|
||||
<button type="button" id="gravityBtn" class="btn btn-lg btn-primary btn-block">Update</button>
|
||||
<pre id="output" style="width: 100%; height: 100%;" hidden></pre>
|
||||
|
||||
<script src="<?=pihole.fileversion('scripts/pi-hole/js/gravity.js')?>"></script>
|
||||
<? mg.include('scripts/pi-hole/lua/footer.lp','r')?>
|
||||
83
scripts/pi-hole/js/gravity.js
Normal file
83
scripts/pi-hole/js/gravity.js
Normal file
@@ -0,0 +1,83 @@
|
||||
/* Pi-hole: A black hole for Internet advertisements
|
||||
* (c) 2017 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. */
|
||||
|
||||
function eventsource() {
|
||||
var alInfo = $("#alInfo");
|
||||
var alSuccess = $("#alSuccess");
|
||||
var ta = $("#output");
|
||||
|
||||
// https://caniuse.com/fetch - everything except IE
|
||||
// This is fine, as we dropped support for IE a while ago
|
||||
if (typeof fetch !== "function") {
|
||||
ta.show();
|
||||
ta.html("Updating lists of ad-serving domains is not supported with this browser!");
|
||||
return;
|
||||
}
|
||||
|
||||
ta.html("");
|
||||
ta.show();
|
||||
alInfo.show();
|
||||
alSuccess.hide();
|
||||
|
||||
fetch("/api/action/gravity", {
|
||||
method: "POST",
|
||||
})
|
||||
// Retrieve its body as ReadableStream
|
||||
.then((response) => {
|
||||
const reader = response.body.getReader();
|
||||
return new ReadableStream({
|
||||
start(controller) {
|
||||
return pump();
|
||||
function pump() {
|
||||
return reader.read().then(({ done, value }) => {
|
||||
// When no more data needs to be consumed, close the stream
|
||||
if (done) {
|
||||
controller.close();
|
||||
alInfo.hide();
|
||||
$("#gravityBtn").prop("disabled", false);
|
||||
return;
|
||||
}
|
||||
// Enqueue the next data chunk into our target stream
|
||||
controller.enqueue(value);
|
||||
var string = new TextDecoder().decode(value);
|
||||
// Remove ${OVER} from the string
|
||||
string = string.replaceAll("\r[K", "\n");
|
||||
console.log(string);
|
||||
ta.append(string);
|
||||
if (string.indexOf("Pi-hole blocking is") !== -1) {
|
||||
alSuccess.show();
|
||||
}
|
||||
return pump();
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
}
|
||||
|
||||
$("#gravityBtn").on("click", function () {
|
||||
$("#gravityBtn").prop("disabled", true);
|
||||
eventsource();
|
||||
});
|
||||
|
||||
// Handle hiding of alerts
|
||||
$(function () {
|
||||
$("[data-hide]").on("click", function () {
|
||||
$(this)
|
||||
.closest("." + $(this).attr("data-hide"))
|
||||
.hide();
|
||||
});
|
||||
|
||||
// Do we want to start updating immediately?
|
||||
// gravity.php?go
|
||||
var searchString = window.location.search.substring(1);
|
||||
if (searchString.indexOf("go") !== -1) {
|
||||
$("#gravityBtn").prop("disabled", true);
|
||||
eventsource();
|
||||
}
|
||||
});
|
||||
@@ -176,7 +176,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
<!-- Tools -->
|
||||
<li class="menu-system treeview<? if in_array(scriptname, {'messages.lp', 'queryads.lp', 'taillog.lp', 'network.lp'}) then mg.write(" active") end ?>">
|
||||
<li class="menu-system treeview<? if in_array(scriptname, {'messages.lp', 'gravity.lp', 'search.lp', 'taillog.lp', 'network.lp'}) then mg.write(" active") end ?>">
|
||||
<a href="#">
|
||||
<i class="fa fa-fw menu-icon fa-tools"></i> <span>Tools</span>
|
||||
<span class="warning-count hidden"></span>
|
||||
@@ -221,10 +221,16 @@
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<!-- Run gravity.sh -->
|
||||
<li class="<? if scriptname == 'gravity.lp' then mg.write(" active") end ?>">
|
||||
<a href="gravity.lp">
|
||||
<i class="fa fa-fw menu-icon fa-arrow-circle-down"></i> <span class="text-green">Update Gravity</span>
|
||||
</a>
|
||||
</li>
|
||||
<!-- Query Lists -->
|
||||
<li class="<? if scriptname == 'search.lp' then mg.write(" active") end ?>">
|
||||
<a href="search.lp">
|
||||
<i class="fa fa-fw menu-icon fa-search"></i> <span class="text-red">Search Adlists</span>
|
||||
<i class="fa fa-fw menu-icon fa-search"></i> <span class="text-green">Search Adlists</span>
|
||||
</a>
|
||||
</li>
|
||||
<!-- Network -->
|
||||
|
||||
Reference in New Issue
Block a user