Skip to content

Commit 9c739d7

Browse files
jaycollettmvdkleijn
authored andcommitted
feat(TechnitiumDNS): add enhanced app support with live stats
Implement the EnhancedApps interface for Technitium DNS to display queries blocked and percentage blocked stats on the dashboard tile. - Add test() method for API connection validation - Add livestats() method to fetch stats from /api/dashboard/stats/get - Add config.blade.php for API token configuration - Add livestats.blade.php for stats display template - Set enhanced: true in app.json Closes linuxserver/Heimdall#1531
1 parent 6aa7931 commit 9c739d7

4 files changed

Lines changed: 65 additions & 2 deletions

File tree

TechnitiumDNS/TechnitiumDNS.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,44 @@
22

33
namespace App\SupportedApps\TechnitiumDNS;
44

5-
class TechnitiumDNS extends \App\SupportedApps
5+
class TechnitiumDNS extends \App\SupportedApps implements \App\EnhancedApps
66
{
7+
public $config;
8+
9+
public function test()
10+
{
11+
$test = parent::appTest($this->url("api/dashboard/stats/get"));
12+
echo $test->status;
13+
}
14+
15+
public function livestats()
16+
{
17+
$status = "inactive";
18+
$data = [];
19+
20+
$res = parent::execute($this->url("api/dashboard/stats/get"));
21+
$details = json_decode($res->getBody());
22+
23+
if ($details && isset($details->response) && isset($details->response->stats)) {
24+
$stats = $details->response->stats;
25+
$data["queries_blocked"] = number_format($stats->totalBlocked);
26+
27+
// Calculate percentage blocked
28+
$percent = 0;
29+
if ($stats->totalQueries > 0) {
30+
$percent = ($stats->totalBlocked / $stats->totalQueries) * 100;
31+
}
32+
$data["percent_blocked"] = number_format($percent, 1);
33+
$status = "active";
34+
}
35+
36+
return parent::getLiveStats($status, $data);
37+
}
38+
39+
public function url($endpoint)
40+
{
41+
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
42+
$api_url .= "?token=" . $this->config->apikey . "&type=LastDay";
43+
return $api_url;
44+
}
745
}

TechnitiumDNS/app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"website": "https://technitium.com/dns",
55
"license": "GNU General Public License v3.0 only",
66
"description": "Technitium DNS Server is an open source authoritative as well as recursive DNS server that can be used for self hosting a DNS server for privacy & security. It works out-of-the-box with no or minimal configuration and provides a user friendly web console accessible using any modern web browser.",
7-
"enhanced": false,
7+
"enhanced": true,
88
"tile_background": "dark",
99
"icon": "technitiumdns.png"
1010
}

TechnitiumDNS/config.blade.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
2+
<div class="items">
3+
<input type="hidden" data-config="dataonly" class="config-item" name="config[dataonly]" value="1" />
4+
<div class="input">
5+
<label>{{ strtoupper(__('app.url')) }}</label>
6+
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
7+
</div>
8+
<div class="input">
9+
<label>API Token</label>
10+
{!! Form::text('config[apikey]', isset($item) && property_exists($item->getconfig(), 'apikey') ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!}
11+
</div>
12+
<div class="input">
13+
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
14+
</div>
15+
</div>

TechnitiumDNS/livestats.blade.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<ul class="livestats">
2+
<li>
3+
<span class="title">Queries<br />Blocked</span>
4+
<strong>{!! $queries_blocked !!}</strong>
5+
</li>
6+
<li>
7+
<span class="title">Percent<br /> Blocked</span>
8+
<strong>{!! $percent_blocked !!}</strong>
9+
</li>
10+
</ul>

0 commit comments

Comments
 (0)