Skip to content

Commit

Permalink
Pi-hole web v5.16 (#2387)
Browse files Browse the repository at this point in the history
  • Loading branch information
PromoFaux committed Oct 10, 2022
2 parents b110ecc + 470c1de commit c2afe42
Show file tree
Hide file tree
Showing 24 changed files with 786 additions and 717 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3.0.2
uses: actions/checkout@v3.1.0
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codespell.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/checkout@v3.0.2
uses: actions/checkout@v3.1.0
-
name: Spell-Checking
uses: codespell-project/actions-codespell@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/editorconfig-checker.yml
Expand Up @@ -9,6 +9,6 @@ jobs:
name: editorconfig-checker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.0.2
- uses: actions/checkout@v3.1.0
- uses: editorconfig-checker/action-editorconfig-checker@main
- run: editorconfig-checker
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Expand Up @@ -6,7 +6,7 @@ jobs:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.0.2
- uses: actions/checkout@v3.1.0
- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.0.2
- uses: actions/checkout@v3.1.0
- name: Change PHP version
run: |
sudo update-alternatives --set php /usr/bin/php8.0
Expand All @@ -21,7 +21,7 @@ jobs:
run: composer validate
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3.0.8
uses: actions/cache@v3.0.10
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
issues: write

steps:
- uses: actions/stale@v5.2.0
- uses: actions/stale@v6.0.1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 30
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync-back-to-dev.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Syncing branches
steps:
- name: Checkout
uses: actions/checkout@v3.0.2
uses: actions/checkout@v3.1.0
- name: Opening pull request
id: pull
uses: tretuna/sync-branches@1.4.0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -19,10 +19,10 @@ jobs:

steps:
- name: Clone repository
uses: actions/checkout@v3.0.2
uses: actions/checkout@v3.1.0

- name: Set up Node.js
uses: actions/setup-node@v3.4.1
uses: actions/setup-node@v3.5.0
with:
node-version: "16.x"
cache: npm
Expand Down
66 changes: 35 additions & 31 deletions api_db.php
Expand Up @@ -295,11 +295,11 @@
$limit = '';

if (isset($_GET['from'], $_GET['until'])) {
$limit = ' AND timestamp >= :from AND timestamp <= :until';
$limit = 'timestamp >= :from AND timestamp <= :until';
} elseif (isset($_GET['from']) && !isset($_GET['until'])) {
$limit = ' AND timestamp >= :from';
$limit = 'timestamp >= :from';
} elseif (!isset($_GET['from']) && isset($_GET['until'])) {
$limit = ' AND timestamp <= :until';
$limit = 'timestamp <= :until';
}

$interval = 600;
Expand All @@ -315,8 +315,24 @@
$from = intval((intval($_GET['from']) / $interval) * $interval);
$until = intval((intval($_GET['until']) / $interval) * $interval);

// Count permitted queries in intervals
$stmt = $db->prepare('SELECT (timestamp/:interval)*:interval interval, COUNT(*) FROM queries WHERE (status != 0 )'.$limit.' GROUP by interval ORDER by interval');
// Count domains and blocked queries using the same intervals
$sqlcommand = "
SELECT
(timestamp / :interval) * :interval AS interval,
SUM(CASE
WHEN status !=0 THEN 1
ELSE 0
END) AS domains,
SUM(CASE
WHEN status IN (1,4,5,6,7,8,9,10,11,15,16) THEN 1
ELSE 0
END) AS blocked
FROM queries
WHERE $limit
GROUP BY interval
ORDER BY interval";

$stmt = $db->prepare($sqlcommand);
$stmt->bindValue(':from', $from, SQLITE3_INTEGER);
$stmt->bindValue(':until', $until, SQLITE3_INTEGER);
$stmt->bindValue(':interval', $interval, SQLITE3_INTEGER);
Expand All @@ -325,52 +341,40 @@
// Parse the DB result into graph data, filling in missing interval sections with zero
function parseDBData($results, $interval, $from, $until)
{
$data = array();
$domains = array();
$blocked = 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]);
$domains[$row['interval']] = intval($row['domains']);
$blocked[$row['interval']] = intval($row['blocked']);
if ($first_db_timestamp === -1) {
$first_db_timestamp = intval($row[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
// It is unpredictable what the first timestamp returned by the database will be.
// This depends on live data. The bar graph can handle "gaps", but the Area graph can't.
// Hence, we filling the "missing" timeslots with 0 to avoid wrong graphic render.
// (https://github.com/pi-hole/AdminLTE/pull/2374#issuecomment-1261865428)
$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;
if (!array_key_exists($i, $domains)) {
$domains[$i] = 0;
$blocked[$i] = 0;
}
}

return $data;
return array('domains_over_time' => $domains, 'ads_over_time' => $blocked);
}

$domains = parseDBData($results, $interval, $from, $until);

$result = array('domains_over_time' => $domains);
$data = array_merge($data, $result);

// Count blocked queries in intervals
$stmt = $db->prepare('SELECT (timestamp/:interval)*:interval interval, COUNT(*) FROM queries WHERE status IN (1,4,5,6,7,8,9,10,11)'.$limit.' GROUP by interval ORDER by interval');
$stmt->bindValue(':from', $from, SQLITE3_INTEGER);
$stmt->bindValue(':until', $until, SQLITE3_INTEGER);
$stmt->bindValue(':interval', $interval, SQLITE3_INTEGER);
$results = $stmt->execute();

$addomains = parseDBData($results, $interval, $from, $until);

$result = array('ads_over_time' => $addomains);
$data = array_merge($data, $result);
$over_time = parseDBData($results, $interval, $from, $until);
$data = array_merge($data, $over_time);
}

if (isset($_GET['status']) && $auth) {
Expand Down
44 changes: 26 additions & 18 deletions index.php
Expand Up @@ -20,27 +20,33 @@
<div class="row">
<div class="col-lg-3 col-sm-6">
<!-- small box -->
<div class="small-box bg-green no-user-select" id="total_queries" title="only A + AAAA queries">
<div class="small-box bg-aqua no-user-select" id="total_queries" title="only A + AAAA queries">
<div class="inner">
<p>Total queries (<span id="unique_clients">-</span> clients)</p>
<p>Total queries</p>
<h3 class="statistic"><span id="dns_queries_today">---</span></h3>
</div>
<div class="icon">
<i class="fas fa-globe-americas"></i>
</div>
<a href="network.php" class="small-box-footer" title="">
<span id="unique_clients">-</span> active clients <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-sm-6">
<!-- small box -->
<div class="small-box bg-aqua no-user-select">
<div class="small-box bg-red no-user-select">
<div class="inner">
<p>Queries Blocked</p>
<h3 class="statistic"><span id="queries_blocked_today">---</span></h3>
</div>
<div class="icon">
<i class="fas fa-hand-paper"></i>
</div>
<a href="queries.php?forwarddest=blocked" class="small-box-footer" title="">
List blocked queries <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
<!-- ./col -->
Expand All @@ -54,19 +60,25 @@
<div class="icon">
<i class="fas fa-chart-pie"></i>
</div>
<a href="queries.php" class="small-box-footer" title="">
List all queries <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-sm-6">
<!-- small box -->
<div class="small-box bg-red no-user-select" title="<?php echo gravity_last_update(); ?>">
<div class="small-box bg-green no-user-select" title="<?php echo gravity_last_update(); ?>">
<div class="inner">
<p>Domains on Adlists</p>
<h3 class="statistic"><span id="domains_being_blocked">---</span></h3>
</div>
<div class="icon">
<i class="fas fa-list-alt"></i>
</div>
<a href="groups-adlists.php" class="small-box-footer" title="">
Manage adlists <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
<!-- ./col -->
Expand All @@ -79,8 +91,8 @@
<h3 class="box-title">Total queries over last <span class="maxlogage-interval">24</span> hours</h3>
</div>
<div class="box-body">
<div class="chart">
<canvas id="queryOverTimeChart" width="800" height="140"></canvas>
<div class="chart" style="width: 100%; height: 180px">
<canvas id="queryOverTimeChart"></canvas>
</div>
</div>
<div class="overlay">
Expand All @@ -97,8 +109,8 @@
<h3 class="box-title">Client activity over last <span class="maxlogage-interval">24</span> hours</h3>
</div>
<div class="box-body">
<div class="chart">
<canvas id="clientsChart" width="800" height="140" class="extratooltipcanvas no-user-select"></canvas>
<div class="chart" style="width: 100%; height: 180px">
<canvas id="clientsChart" class="extratooltipcanvas no-user-select"></canvas>
</div>
</div>
<div class="overlay">
Expand All @@ -116,12 +128,10 @@
<h3 class="box-title">Query Types</h3>
</div>
<div class="box-body">
<div class="pull-left" style="width:50%">
<canvas id="queryTypePieChart" width="120" height="120"></canvas>
</div>
<div class="pull-left" style="width:50%">
<div id="query-types-legend" class="chart-legend"></div>
<div style="width:50%">
<canvas id="queryTypePieChart" width="280" height="280"></canvas>
</div>
<div class="chart-legend" style="width:50%" id="query-types-legend" ></div>
</div>
<div class="overlay">
<i class="fa fa-sync fa-spin"></i>
Expand All @@ -135,12 +145,10 @@
<h3 class="box-title">Upstream servers</h3>
</div>
<div class="box-body">
<div class="pull-left" style="width:50%">
<canvas id="forwardDestinationPieChart" width="120" height="120" class="extratooltipcanvas no-user-select"></canvas>
</div>
<div class="pull-left" style="width:50%">
<div id="forward-destinations-legend" class="chart-legend extratooltipcanvas no-user-select"></div>
<div style="width:50%">
<canvas id="forwardDestinationPieChart" width="280" height="280" class="extratooltipcanvas no-user-select"></canvas>
</div>
<div class="chart-legend" style="width:50%" id="forward-destinations-legend"></div>
</div>
<div class="overlay">
<i class="fa fa-sync fa-spin"></i>
Expand Down

0 comments on commit c2afe42

Please sign in to comment.