Skip to content

Commit

Permalink
🔀 Merge pull request #1074 from albcp/master
Browse files Browse the repository at this point in the history
Fixed Pi-Hole widgets adding authentication
  • Loading branch information
Lissy93 authored Jan 21, 2023
2 parents c957ab6 + c867a90 commit 4a5024c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
12 changes: 8 additions & 4 deletions docs/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a
- [System Load History](#load-history-netdata)
- [Pi Hole Stats](#pi-hole-stats)
- [Pi Hole Queries](#pi-hole-queries)
- [Recent Traffic](#recent-traffic)
- [Pi Hole Recent Traffic](#pi-hole-recent-traffic)
- [Stat Ping Statuses](#stat-ping-statuses)
- [Synology Download Station](#synology-download-station)
- [AdGuard Home Block Stats](#adguard-home-block-stats)
Expand Down Expand Up @@ -1338,19 +1338,21 @@ Displays the number of queries blocked by [Pi-Hole](https://pi-hole.net/).
--- | --- | --- | ---
**`hostname`** | `string` | Required | The URL to your Pi-Hole instance
**`hideStatus`** / **`hideChart`** / **`hideInfo`** | `boolean` | _Optional_ | Optionally hide any of the three parts of the widget
**`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`

#### Example

```yaml
- type: pi-hole-stats
options:
hostname: http://192.168.130.1
apiKey: xxxxxxxxxxxxxxxxxxxxxxx
```

#### Info

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

---

### Recent Traffic
### Pi Hole Recent Traffic

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

Expand All @@ -1401,19 +1403,21 @@ Shows number of recent traffic, using allowed and blocked queries from [Pi-Hole]
**Field** | **Type** | **Required** | **Description**
--- | --- | --- | ---
**`hostname`** | `string` | Required | The URL to your Pi-Hole instance
**`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`

#### Example

```yaml
- type: pi-hole-traffic
options:
hostname: https://pi-hole.local
apiKey: xxxxxxxxxxxxxxxxxxxxxxx
```

#### Info

- **CORS**: 🟢 Enabled
- **Auth**: 🟢 Not Required
- **Auth**: 🔴 Required
- **Price**: 🟢 Free
- **Host**: Self-Hosted (see [GitHub - Pi-hole](https://github.com/pi-hole/pi-hole))
- **Privacy**: _See [Pi-Hole Privacy Guide](https://pi-hole.net/privacy/)_
Expand Down
12 changes: 10 additions & 2 deletions src/components/Widgets/PiHoleStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ export default {
if (!usersChoice) this.error('You must specify the hostname for your Pi-Hole server');
return usersChoice || 'http://pi.hole';
},
apiKey() {
if (!this.options.apiKey) this.error('API Key is required, please see the docs');
return this.options.apiKey;
},
endpoint() {
return `${this.hostname}/admin/api.php`;
return `${this.hostname}/admin/api.php?summary&auth=${this.apiKey}`;
},
hideStatus() { return this.options.hideStatus; },
hideChart() { return this.options.hideChart; },
Expand All @@ -57,7 +61,11 @@ export default {
fetchData() {
this.makeRequest(this.endpoint)
.then((response) => {
this.processData(response);
if (Array.isArray(response)) {
this.error('Got success, but found no results, possible authorization error');
} else {
this.processData(response);
}
});
},
/* Assign data variables to the returned data */
Expand Down
10 changes: 8 additions & 2 deletions src/components/Widgets/PiHoleTraffic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ export default {
if (!usersChoice) this.error('You must specify the hostname for your Pi-Hole server');
return usersChoice || 'http://pi.hole';
},
apiKey() {
if (!this.options.apiKey) this.error('API Key is required, please see the docs');
return this.options.apiKey;
},
endpoint() {
return `${this.hostname}/admin/api.php?overTimeData10mins`;
return `${this.hostname}/admin/api.php?overTimeData10mins&auth=${this.apiKey}`;
},
},
methods: {
Expand All @@ -38,7 +42,9 @@ export default {
});
},
validate(response) {
if (!response.ads_over_time || !response.domains_over_time) {
if (Array.isArray(response)) {
this.error('Got success, but found no results, possible authorization error');
} else if (!response.ads_over_time || !response.domains_over_time) {
this.error('Expected data was not returned from Pi-Hole');
return false;
} else if (response.ads_over_time.length < 1) {
Expand Down

0 comments on commit 4a5024c

Please sign in to comment.