Skip to content

Commit 4a5024c

Browse files
authored
🔀 Merge pull request Lissy93#1074 from albcp/master
Fixed Pi-Hole widgets adding authentication
2 parents c957ab6 + c867a90 commit 4a5024c

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

docs/widgets.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a
4343
- [System Load History](#load-history-netdata)
4444
- [Pi Hole Stats](#pi-hole-stats)
4545
- [Pi Hole Queries](#pi-hole-queries)
46-
- [Recent Traffic](#recent-traffic)
46+
- [Pi Hole Recent Traffic](#pi-hole-recent-traffic)
4747
- [Stat Ping Statuses](#stat-ping-statuses)
4848
- [Synology Download Station](#synology-download-station)
4949
- [AdGuard Home Block Stats](#adguard-home-block-stats)
@@ -1338,19 +1338,21 @@ Displays the number of queries blocked by [Pi-Hole](https://pi-hole.net/).
13381338
--- | --- | --- | ---
13391339
**`hostname`** | `string` | Required | The URL to your Pi-Hole instance
13401340
**`hideStatus`** / **`hideChart`** / **`hideInfo`** | `boolean` | _Optional_ | Optionally hide any of the three parts of the widget
1341+
**`apiKey`** | `string` | Required | Your Pi-Hole web password. It is **NOT** your pi-hole admin interface or server password. It can be found in `/etc/pihole/setupVars.conf`, and is a 64-character located on the line that starts with `WEBPASSWORD`
13411342

13421343
#### Example
13431344

13441345
```yaml
13451346
- type: pi-hole-stats
13461347
options:
13471348
hostname: http://192.168.130.1
1349+
apiKey: xxxxxxxxxxxxxxxxxxxxxxx
13481350
```
13491351

13501352
#### Info
13511353

13521354
- **CORS**: 🟢 Enabled
1353-
- **Auth**: 🟢 Not Required
1355+
- **Auth**: 🔴 Required
13541356
- **Price**: 🟢 Free
13551357
- **Host**: Self-Hosted (see [GitHub - Pi-hole](https://github.com/pi-hole/pi-hole))
13561358
- **Privacy**: _See [Pi-Hole Privacy Guide](https://pi-hole.net/privacy/)_
@@ -1390,7 +1392,7 @@ Shows top queries that were blocked and allowed by [Pi-Hole](https://pi-hole.net
13901392

13911393
---
13921394

1393-
### Recent Traffic
1395+
### Pi Hole Recent Traffic
13941396

13951397
Shows number of recent traffic, using allowed and blocked queries from [Pi-Hole](https://pi-hole.net/)
13961398

@@ -1401,19 +1403,21 @@ Shows number of recent traffic, using allowed and blocked queries from [Pi-Hole]
14011403
**Field** | **Type** | **Required** | **Description**
14021404
--- | --- | --- | ---
14031405
**`hostname`** | `string` | Required | The URL to your Pi-Hole instance
1406+
**`apiKey`** | `string` | Required | Your Pi-Hole web password. It is **NOT** your pi-hole admin interface or server password. It can be found in `/etc/pihole/setupVars.conf`, and is a 64-character located on the line that starts with `WEBPASSWORD`
14041407

14051408
#### Example
14061409

14071410
```yaml
14081411
- type: pi-hole-traffic
14091412
options:
14101413
hostname: https://pi-hole.local
1414+
apiKey: xxxxxxxxxxxxxxxxxxxxxxx
14111415
```
14121416

14131417
#### Info
14141418

14151419
- **CORS**: 🟢 Enabled
1416-
- **Auth**: 🟢 Not Required
1420+
- **Auth**: 🔴 Required
14171421
- **Price**: 🟢 Free
14181422
- **Host**: Self-Hosted (see [GitHub - Pi-hole](https://github.com/pi-hole/pi-hole))
14191423
- **Privacy**: _See [Pi-Hole Privacy Guide](https://pi-hole.net/privacy/)_

src/components/Widgets/PiHoleStats.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ export default {
4040
if (!usersChoice) this.error('You must specify the hostname for your Pi-Hole server');
4141
return usersChoice || 'http://pi.hole';
4242
},
43+
apiKey() {
44+
if (!this.options.apiKey) this.error('API Key is required, please see the docs');
45+
return this.options.apiKey;
46+
},
4347
endpoint() {
44-
return `${this.hostname}/admin/api.php`;
48+
return `${this.hostname}/admin/api.php?summary&auth=${this.apiKey}`;
4549
},
4650
hideStatus() { return this.options.hideStatus; },
4751
hideChart() { return this.options.hideChart; },
@@ -57,7 +61,11 @@ export default {
5761
fetchData() {
5862
this.makeRequest(this.endpoint)
5963
.then((response) => {
60-
this.processData(response);
64+
if (Array.isArray(response)) {
65+
this.error('Got success, but found no results, possible authorization error');
66+
} else {
67+
this.processData(response);
68+
}
6169
});
6270
},
6371
/* Assign data variables to the returned data */

src/components/Widgets/PiHoleTraffic.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ export default {
2323
if (!usersChoice) this.error('You must specify the hostname for your Pi-Hole server');
2424
return usersChoice || 'http://pi.hole';
2525
},
26+
apiKey() {
27+
if (!this.options.apiKey) this.error('API Key is required, please see the docs');
28+
return this.options.apiKey;
29+
},
2630
endpoint() {
27-
return `${this.hostname}/admin/api.php?overTimeData10mins`;
31+
return `${this.hostname}/admin/api.php?overTimeData10mins&auth=${this.apiKey}`;
2832
},
2933
},
3034
methods: {
@@ -38,7 +42,9 @@ export default {
3842
});
3943
},
4044
validate(response) {
41-
if (!response.ads_over_time || !response.domains_over_time) {
45+
if (Array.isArray(response)) {
46+
this.error('Got success, but found no results, possible authorization error');
47+
} else if (!response.ads_over_time || !response.domains_over_time) {
4248
this.error('Expected data was not returned from Pi-Hole');
4349
return false;
4450
} else if (response.ads_over_time.length < 1) {

0 commit comments

Comments
 (0)