Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Pi-Hole widgets adding authentication #1074

Merged
merged 2 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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