Skip to content

Commit

Permalink
Merge pull request #1247 from pi-hole/release/v5.0
Browse files Browse the repository at this point in the history
Pi-hole web v5.0
  • Loading branch information
PromoFaux authored May 10, 2020
2 parents 62f2ffc + b6d3d6c commit b86e4a3
Show file tree
Hide file tree
Showing 125 changed files with 26,001 additions and 11,077 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests
on: [push, pull_request]
env:
CI: true

jobs:
run:
name: Node ${{ matrix.node }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node: [12]

steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Set Node.js version
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- run: node --version
- run: npm --version

- name: Install npm dependencies
run: npm ci

- name: Run tests
run: npm test
38 changes: 0 additions & 38 deletions .pullapprove.yml

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
<a href="https://pi-hole.net"><img src="https://pi-hole.github.io/graphics/Screenshots/pihole-dashboard.png" alt="Pi-hole Web interface"></a><br/>
</p>

Pi-hole[®](https://pi-hole.net/trademark-rules-and-brand-guidelines/)'s Web interface (based off of [AdminLTE](https://almsaeedstudio.com)) provides a central location to manage your Pi-hole and review the statistics generated by FTLDNS[](https://pi-hole.net/trademark-rules-and-brand-guidelines/).
Pi-hole[®](https://pi-hole.net/trademark-rules-and-brand-guidelines/)'s Web interface (based off of [AdminLTE](https://github.com/ColorlibHQ/AdminLTE)) provides a central location to manage your Pi-hole and review the statistics generated by FTLDNS[](https://pi-hole.net/trademark-rules-and-brand-guidelines/).

- **Easy-to-interpret**: simple graphs and beautiful colors make Pi-hole's stats easy to understand
- **Responsive**: looks great on desktop, tablets, and mobile devices
- **Useful**: control and configure your Pi-hole with our settings
- **Insightful**: use the query log, audit log, or long-term stats to gain insight into your networks activity

---
<a class="badge-align" href="https://www.codacy.com/app/Pi-hole/AdminLTE?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=pi-hole/AdminLTE&amp;utm_campaign=Badge_Grade"><img src="https://api.codacy.com/project/badge/Grade/10540ea45a3b4d5f992c05a2c9714609"/></a>
<img src="https://pi-hole.github.io/graphics/Badges/browserstack-badge.png" height="80"><br>

# Installation
Expand Down
50 changes: 36 additions & 14 deletions api_FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
foreach($return as $line)
{
$tmp = explode(" ",$line);
$top_queries[$tmp[2]] = intval($tmp[1]);
$domain = utf8_encode($tmp[2]);
$top_queries[$domain] = intval($tmp[1]);
}

if($_GET['topItems'] === "audit")
Expand All @@ -125,10 +126,11 @@
foreach($return as $line)
{
$tmp = explode(" ",$line);
$domain = utf8_encode($tmp[2]);
if(count($tmp) > 3)
$top_ads[$tmp[2]." (".$tmp[3].")"] = intval($tmp[1]);
$top_ads[$domain." (".$tmp[3].")"] = intval($tmp[1]);
else
$top_ads[$tmp[2]] = intval($tmp[1]);
$top_ads[$domain] = intval($tmp[1]);
}

$result = array('top_queries' => $top_queries,
Expand Down Expand Up @@ -163,10 +165,14 @@
foreach($return as $line)
{
$tmp = explode(" ",$line);
$clientip = utf8_encode($tmp[2]);
if(count($tmp) > 3 && strlen($tmp[3]) > 0)
$top_clients[$tmp[3]."|".$tmp[2]] = intval($tmp[1]);
{
$clientname = utf8_encode($tmp[3]);
$top_clients[$clientname."|".$clientip] = intval($tmp[1]);
}
else
$top_clients[$tmp[2]] = intval($tmp[1]);
$top_clients[$clientip] = intval($tmp[1]);
}

$result = array('top_sources' => $top_clients);
Expand Down Expand Up @@ -195,10 +201,14 @@
foreach($return as $line)
{
$tmp = explode(" ",$line);
$clientip = utf8_encode($tmp[2]);
if(count($tmp) > 3 && strlen($tmp[3]) > 0)
$top_clients[$tmp[3]."|".$tmp[2]] = intval($tmp[1]);
{
$clientname = utf8_encode($tmp[3]);
$top_clients[$clientname."|".$clientip] = intval($tmp[1]);
}
else
$top_clients[$tmp[2]] = intval($tmp[1]);
$top_clients[$clientip] = intval($tmp[1]);
}

$result = array('top_sources_blocked' => $top_clients);
Expand All @@ -220,10 +230,14 @@
foreach($return as $line)
{
$tmp = explode(" ",$line);
$forwardip = utf8_encode($tmp[2]);
if(count($tmp) > 3 && strlen($tmp[3]) > 0)
$forward_dest[$tmp[3]."|".$tmp[2]] = floatval($tmp[1]);
{
$forwardname = utf8_encode($tmp[3]);
$forward_dest[$forwardname."|".$forwardip] = floatval($tmp[1]);
}
else
$forward_dest[$tmp[2]] = floatval($tmp[1]);
$forward_dest[$forwardip] = floatval($tmp[1]);
}

$result = array('forward_destinations' => $forward_dest);
Expand All @@ -238,6 +252,7 @@
foreach($return as $ret)
{
$tmp = explode(": ",$ret);
// Reply cannot contain non-ASCII characters
$querytypes[$tmp[0]] = floatval($tmp[1]);
}

Expand All @@ -253,6 +268,7 @@
foreach($return as $ret)
{
$tmp = explode(": ",$ret);
// Reply cannot contain non-ASCII characters
$cacheinfo[$tmp[0]] = floatval($tmp[1]);
}

Expand Down Expand Up @@ -301,6 +317,10 @@
foreach($return as $line)
{
$tmp = explode(" ",$line);
// UTF-8 encode domain
$tmp[2] = utf8_encode($tmp[2]);
// UTF-8 encode client host name
$tmp[3] = utf8_encode($tmp[3]);;
array_push($allQueries,$tmp);
}

Expand All @@ -311,7 +331,7 @@
if(isset($_GET["recentBlocked"]))
{
sendRequestFTL("recentBlocked");
die(getResponseFTL()[0]);
die(utf8_encode(getResponseFTL()[0]));
unset($data);
}

Expand All @@ -323,13 +343,15 @@
foreach($return as $line)
{
$tmp = explode(" ",$line);
$forwardip = utf8_encode($tmp[2]);
if(count($tmp) > 3)
{
$forward_dest[$tmp[3]."|".$tmp[2]] = floatval($tmp[1]);
$forwardname = utf8_encode($tmp[3]);
$forward_dest[$forwardname."|".$forwardip] = floatval($tmp[1]);
}
else
{
$forward_dest[$tmp[2]] = floatval($tmp[1]);
$forward_dest[$forwardip] = floatval($tmp[1]);
}
}

Expand Down Expand Up @@ -363,8 +385,8 @@
{
$tmp = explode(" ", $line);
$client_names[] = array(
"name" => $tmp[0],
"ip" => $tmp[1]
"name" => utf8_encode($tmp[0]),
"ip" => utf8_encode($tmp[1])
);
}

Expand Down
94 changes: 39 additions & 55 deletions api_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

$api = true;
header('Content-type: application/json');
require("scripts/pi-hole/php/database.php");
require("scripts/pi-hole/php/password.php");
require("scripts/pi-hole/php/auth.php");
check_cors();
Expand Down Expand Up @@ -48,59 +49,31 @@ function resolveHostname($clientip, $printIP)
return $clientname;
}

// Get posible non-standard location of FTL's database
$FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf");
if(isset($FTLsettings["DBFILE"]))
{
$DBFILE = $FTLsettings["DBFILE"];
}
else
{
$DBFILE = "/etc/pihole/pihole-FTL.db";
}

// Needs package php5-sqlite, e.g.
// sudo apt-get install php5-sqlite

function SQLite3_connect($trytoreconnect)
{
global $DBFILE;
try
{
// connect to database
return new SQLite3($DBFILE, SQLITE3_OPEN_READONLY);
}
catch (Exception $exception)
{
// sqlite3 throws an exception when it is unable to connect, try to reconnect after 3 seconds
if($trytoreconnect)
{
sleep(3);
$db = SQLite3_connect(false);
}
}
}

if(strlen($DBFILE) > 0)
{
$db = SQLite3_connect(true);
}
else
{
die("No database available");
}
if(!$db)
{
die("Error connecting to database");
}
$QUERYDB = getQueriesDBFilename();
$db = SQLite3_connect($QUERYDB);

if(isset($_GET["network"]) && $auth)
{
$network = array();
$results = $db->query('SELECT * FROM network');

while($results !== false && $res = $results->fetchArray(SQLITE3_ASSOC))
{
$id = $res["id"];
// Empty array for holding the IP addresses
$res["ip"] = array();
// Get IP addresses for this device
$network_addresses = $db->query("SELECT ip FROM network_addresses WHERE network_id = $id ORDER BY lastSeen DESC");
while($network_addresses !== false && $ip = $network_addresses->fetchArray(SQLITE3_ASSOC))
array_push($res["ip"],$ip["ip"]);
// UTF-8 encode host name and vendor
$res["name"] = utf8_encode($res["name"]);
$res["macVendor"] = utf8_encode($res["macVendor"]);
array_push($network, $res);
}

$data = array_merge($data, array('network' => $network));
}
Expand Down Expand Up @@ -164,12 +137,15 @@ function SQLite3_connect($trytoreconnect)
case 7:
$query_type = "TXT";
break;
case 8:
$query_type = "NAPTR";
break;
default:
$query_type = "UNKN";
break;
}

$allQueries[] = [$row[0], $query_type, $row[2], $c, $row[4]];
// array: time type domain client status
$allQueries[] = [$row[0], $query_type, utf8_encode($row[2]), utf8_encode($c), $row[4]];
}
}
$result = array('data' => $allQueries);
Expand Down Expand Up @@ -202,8 +178,8 @@ function SQLite3_connect($trytoreconnect)
if(!is_bool($results))
while ($row = $results->fetchArray())
{

$c = resolveHostname($row[0],false);
// Try to resolve host name and convert to UTF-8
$c = utf8_encode(resolveHostname($row[0],false));

if(array_key_exists($c, $clientnums))
{
Expand Down Expand Up @@ -253,8 +229,8 @@ function SQLite3_connect($trytoreconnect)
if(!is_bool($results))
while ($row = $results->fetchArray())
{
// Convert client to lower case
$c = strtolower($row[0]);
// Convert domain to lower case UTF-8
$c = utf8_encode(strtolower($row[0]));
if(array_key_exists($c, $domains))
{
// Entry already exists, add to it (might appear multiple times due to mixed capitalization in the database)
Expand Down Expand Up @@ -303,7 +279,7 @@ function SQLite3_connect($trytoreconnect)
if(!is_bool($results))
while ($row = $results->fetchArray())
{
$addomains[$row[0]] = intval($row[1]);
$addomains[utf8_encode($row[0])] = intval($row[1]);
}
$result = array('top_ads' => $addomains);
$data = array_merge($data, $result);
Expand Down Expand Up @@ -392,20 +368,28 @@ function SQLite3_connect($trytoreconnect)
// Parse the DB result into graph data, filling in missing interval sections with zero
function parseDBData($results, $interval, $from, $until) {
$data = array();
$first_db_timestamp = -1;

if(!is_bool($results)) {
// Read in the data
while($row = $results->fetchArray()) {
// $data[timestamp] = value_in_this_interval
$data[$row[0]] = intval($row[1]);
if($first_db_timestamp === -1)
$first_db_timestamp = intval($row[0]);
}
}

// Fill the missing intervals with zero
// Advance in steps of interval
for($i = $from; $i < $until; $i += $interval) {
if(!array_key_exists($i, $data))
$data[$i] = 0;
}
// It is unpredictable what the first timestamp returned by the database
// will be. This depends on live data. Hence, we re-align the FROM
// timestamp to avoid unaligned holes appearing as additional
// (incorrect) data points
$aligned_from = $from + (($first_db_timestamp - $from) % $interval);

// Fill gaps in returned data
for($i = $aligned_from; $i < $until; $i += $interval) {
if(!array_key_exists($i, $data))
$data[$i] = 0;
}

return $data;
Expand Down
Loading

0 comments on commit b86e4a3

Please sign in to comment.