mirror of
https://github.com/pi-hole/web.git
synced 2025-12-19 18:28:24 +00:00
33
gravity.php
33
gravity.php
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 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')?>
|
||||
@@ -1,11 +1,11 @@
|
||||
<?php /*
|
||||
* 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.
|
||||
<? --[[
|
||||
* 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.
|
||||
*/
|
||||
* 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')
|
||||
?>
|
||||
@@ -22,10 +22,9 @@ mg.include('scripts/pi-hole/lua/header_authenticated.lp','r')
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>IP address</th>
|
||||
<th>IP address (hostname)</th>
|
||||
<th>Hardware address</th>
|
||||
<th>Interface</th>
|
||||
<th>Hostname</th>
|
||||
<th>First seen</th>
|
||||
<th>Last Query</th>
|
||||
<th>Number of queries</th>
|
||||
@@ -36,10 +35,9 @@ mg.include('scripts/pi-hole/lua/header_authenticated.lp','r')
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>IP address</th>
|
||||
<th>IP address (hostname)</th>
|
||||
<th>Hardware address</th>
|
||||
<th>Interface</th>
|
||||
<th>Hostname</th>
|
||||
<th>First seen</th>
|
||||
<th>Last Query</th>
|
||||
<th>Number of queries</th>
|
||||
@@ -1,81 +0,0 @@
|
||||
/* 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");
|
||||
|
||||
// IE does not support EventSource - exit early
|
||||
if (typeof EventSource !== "function") {
|
||||
ta.show();
|
||||
ta.html("Updating lists of ad-serving domains is not supported with this browser!");
|
||||
return;
|
||||
}
|
||||
|
||||
var source = new EventSource("scripts/pi-hole/php/gravity.sh.php");
|
||||
|
||||
ta.html("");
|
||||
ta.show();
|
||||
alInfo.show();
|
||||
alSuccess.hide();
|
||||
|
||||
source.addEventListener(
|
||||
"message",
|
||||
function (e) {
|
||||
if (e.data.indexOf("Pi-hole blocking is") !== -1) {
|
||||
alSuccess.show();
|
||||
}
|
||||
|
||||
// Detect ${OVER}
|
||||
var newString = "<------";
|
||||
|
||||
if (e.data.indexOf(newString) !== -1) {
|
||||
ta.text(ta.text().substring(0, ta.text().lastIndexOf("\n")) + "\n");
|
||||
ta.append(e.data.replace(newString, ""));
|
||||
} else {
|
||||
ta.append(e.data);
|
||||
}
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
// Will be called when script has finished
|
||||
source.addEventListener(
|
||||
"error",
|
||||
function () {
|
||||
alInfo.delay(1000).fadeOut(2000, function () {
|
||||
alInfo.hide();
|
||||
});
|
||||
source.close();
|
||||
$("#gravityBtn").prop("disabled", false);
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
$("#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();
|
||||
}
|
||||
});
|
||||
@@ -5,17 +5,13 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
/* global utils:false */
|
||||
/* global utils:false, apiFailure:false */
|
||||
|
||||
var tableApi;
|
||||
var token = $("#token").text();
|
||||
|
||||
var API_STRING = "api_db.php?network";
|
||||
|
||||
// How many IPs do we show at most per device?
|
||||
var MAXIPDISPLAY = 3;
|
||||
|
||||
var DAY_IN_SECONDS = 24 * 60 * 60;
|
||||
const MAXIPDISPLAY = 3;
|
||||
const DAY_IN_SECONDS = 24 * 60 * 60;
|
||||
|
||||
function handleAjaxError(xhr, textStatus) {
|
||||
if (textStatus === "timeout") {
|
||||
@@ -61,37 +57,33 @@ function parseColor(input) {
|
||||
}
|
||||
|
||||
function deleteNetworkEntry() {
|
||||
var tr = $(this).closest("tr");
|
||||
var id = tr.attr("data-id");
|
||||
const tr = $(this).closest("tr");
|
||||
const id = tr.attr("data-id");
|
||||
const hwaddr = tr.attr("data-hwaddr");
|
||||
|
||||
utils.disableAll();
|
||||
utils.showAlert("info", "", "Deleting network table entry...");
|
||||
$.ajax({
|
||||
url: "scripts/pi-hole/php/network.php",
|
||||
method: "post",
|
||||
dataType: "json",
|
||||
data: { action: "delete_network_entry", id: id, token: token },
|
||||
success: function (response) {
|
||||
url: "/api/network/devices/" + id,
|
||||
method: "DELETE",
|
||||
success: function () {
|
||||
utils.enableAll();
|
||||
if (response.success) {
|
||||
utils.showAlert("success", "far fa-trash-alt", "Successfully deleted network table entry");
|
||||
tableApi.row(tr).remove().draw(false).ajax.reload(null, false);
|
||||
} else {
|
||||
utils.showAlert(
|
||||
"error",
|
||||
"",
|
||||
"Error while network table entry with ID " + id,
|
||||
response.message
|
||||
);
|
||||
}
|
||||
utils.showAlert(
|
||||
"success",
|
||||
"far fa-trash-alt",
|
||||
"Successfully deleted network table entry",
|
||||
hwaddr
|
||||
);
|
||||
tableApi.row(tr).remove().draw(false).ajax.reload(null, false);
|
||||
},
|
||||
error: function (jqXHR, exception) {
|
||||
error: function (data, exception) {
|
||||
apiFailure(data);
|
||||
utils.enableAll();
|
||||
utils.showAlert(
|
||||
"error",
|
||||
"",
|
||||
"Error while deleting network table entry with ID " + id,
|
||||
jqXHR.responseText
|
||||
data.responseText
|
||||
);
|
||||
console.log(exception); // eslint-disable-line no-console
|
||||
},
|
||||
@@ -133,63 +125,29 @@ $(function () {
|
||||
|
||||
// Set determined background color
|
||||
$(row).css("background-color", color);
|
||||
$("td:eq(7)", row).html('<i class="' + iconClasses + '"></i>');
|
||||
$("td:eq(6)", row).html('<i class="' + iconClasses + '"></i>');
|
||||
|
||||
// Insert "Never" into Last Query field when we have
|
||||
// never seen a query from this device
|
||||
if (data.lastQuery === 0) {
|
||||
$("td:eq(5)", row).html("Never");
|
||||
}
|
||||
|
||||
// Set hostname to "unknown" if not available
|
||||
if (!data.name || data.name.length === 0) {
|
||||
$("td:eq(3)", row).html("<em>unknown</em>");
|
||||
} else {
|
||||
var names = [];
|
||||
var name = "";
|
||||
maxiter = Math.min(data.name.length, MAXIPDISPLAY);
|
||||
index = 0;
|
||||
for (index = 0; index < maxiter; index++) {
|
||||
name = data.name[index];
|
||||
if (name.length === 0) continue;
|
||||
names.push('<a href="queries.php?client=' + name + '">' + name + "</a>");
|
||||
}
|
||||
|
||||
if (data.name.length > MAXIPDISPLAY) {
|
||||
// We hit the maximum above, add "..." to symbolize we would
|
||||
// have more to show here
|
||||
names.push("...");
|
||||
}
|
||||
|
||||
maxiter = Math.min(data.ip.length, data.name.length);
|
||||
var allnames = [];
|
||||
for (index = 0; index < maxiter; index++) {
|
||||
name = data.name[index];
|
||||
if (name.length > 0) {
|
||||
allnames.push(name + " (" + data.ip[index] + ")");
|
||||
} else {
|
||||
allnames.push("No host name for " + data.ip[index] + " known");
|
||||
}
|
||||
}
|
||||
|
||||
$("td:eq(3)", row).html(names.join("<br>"));
|
||||
$("td:eq(3)", row).on("hover", function () {
|
||||
this.title = allnames.join("\n");
|
||||
});
|
||||
$("td:eq(4)", row).html("Never");
|
||||
}
|
||||
|
||||
// Set number of queries to localized string (add thousand separators)
|
||||
$("td:eq(6)", row).html(data.numQueries.toLocaleString());
|
||||
$("td:eq(5)", row).html(data.numQueries.toLocaleString());
|
||||
|
||||
var ips = [];
|
||||
maxiter = Math.min(data.ip.length, MAXIPDISPLAY);
|
||||
index = 0;
|
||||
maxiter = Math.min(data.ips.length, MAXIPDISPLAY);
|
||||
for (index = 0; index < maxiter; index++) {
|
||||
var ip = data.ip[index];
|
||||
ips.push('<a href="queries.php?client=' + ip + '">' + ip + "</a>");
|
||||
var ip = data.ips[index];
|
||||
if (ip.name !== null && ip.name.length > 0)
|
||||
ips.push(
|
||||
'<a href="queries.php?client=' + ip.ip + '">' + ip.ip + " (" + ip.name + ")</a>"
|
||||
);
|
||||
else ips.push('<a href="queries.php?client=' + ip.ip + '">' + ip.ip + "</a>");
|
||||
}
|
||||
|
||||
if (data.ip.length > MAXIPDISPLAY) {
|
||||
if (data.ips.length > MAXIPDISPLAY) {
|
||||
// We hit the maximum above, add "..." to symbolize we would
|
||||
// have more to show here
|
||||
ips.push("...");
|
||||
@@ -197,7 +155,7 @@ $(function () {
|
||||
|
||||
$("td:eq(0)", row).html(ips.join("<br>"));
|
||||
$("td:eq(0)", row).on("hover", function () {
|
||||
this.title = data.ip.join("\n");
|
||||
this.title = data.ips.join("\n");
|
||||
});
|
||||
|
||||
// MAC + Vendor field if available
|
||||
@@ -212,29 +170,39 @@ $(function () {
|
||||
|
||||
// Add delete button
|
||||
$(row).attr("data-id", data.id);
|
||||
$(row).attr("data-hwaddr", data.hwaddr);
|
||||
var button =
|
||||
'<button type="button" class="btn btn-danger btn-xs" id="deleteNetworkEntry_' +
|
||||
data.id +
|
||||
'">' +
|
||||
'<span class="far fa-trash-alt"></span>' +
|
||||
"</button>";
|
||||
$("td:eq(8)", row).html(button);
|
||||
$("td:eq(7)", row).html(button);
|
||||
},
|
||||
dom:
|
||||
"<'row'<'col-sm-12'f>>" +
|
||||
"<'row'<'col-sm-4'l><'col-sm-8'p>>" +
|
||||
"<'row'<'col-sm-12'<'table-responsive'tr>>>" +
|
||||
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
|
||||
ajax: { url: API_STRING, error: handleAjaxError, dataSrc: "network" },
|
||||
ajax: {
|
||||
url: "/api/network/devices",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
data: {
|
||||
max_devices: 999,
|
||||
max_addresses: 25,
|
||||
},
|
||||
error: handleAjaxError,
|
||||
dataSrc: "devices",
|
||||
},
|
||||
autoWidth: false,
|
||||
processing: true,
|
||||
order: [[6, "desc"]],
|
||||
columns: [
|
||||
{ data: "id", visible: false },
|
||||
{ data: "ip", type: "ip-address", width: "10%" },
|
||||
{ data: "ip", type: "ip-address", width: "25%" },
|
||||
{ data: "hwaddr", width: "10%" },
|
||||
{ data: "interface", width: "4%" },
|
||||
{ data: "name", width: "15%" },
|
||||
{
|
||||
data: "firstSeen",
|
||||
width: "8%",
|
||||
|
||||
@@ -27,6 +27,18 @@ function GET(name)
|
||||
return mg.request_info.query_string:match(name.."=([^&]*)")
|
||||
-- mg.get_var(mg.request_info.query_string, "REQUEST_URI")
|
||||
end
|
||||
|
||||
-- Function checking if val is in tab
|
||||
function in_array (val, tab)
|
||||
for index, value in ipairs(tab) do
|
||||
if value == val then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
?>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
||||
@@ -176,7 +176,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
<!-- Tools -->
|
||||
<li class="menu-system treeview<? if in_array(scriptname, array('messages.lp', 'gravity.lp', 'queryads.lp', 'taillog.lp', 'taillog-FTL.lp', 'debug.lp', 'network.lp')) then mg.write(" active") end ?>">
|
||||
<li class="menu-system treeview<? if in_array(scriptname, {'messages.lp', 'queryads.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,12 +221,6 @@
|
||||
</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-red">Update Gravity</span>
|
||||
</a>
|
||||
</li>
|
||||
<!-- Query Lists -->
|
||||
<li class="<? if scriptname == 'queryads.lp' then mg.write(" active") end ?>">
|
||||
<a href="queryads.lp">
|
||||
@@ -236,7 +230,7 @@
|
||||
<!-- Network -->
|
||||
<li class="<? if scriptname == 'network.lp' then mg.write(" active") end ?>">
|
||||
<a href="network.lp">
|
||||
<i class="fa fa-fw menu-icon fa-network-wired"></i> <span class="text-red">Network</span>
|
||||
<i class="fa fa-fw menu-icon fa-network-wired"></i> <span class="text-green">Network</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user