Added authentication to Pi-Hole widgets

This commit is contained in:
Alberto Caravaca
2023-01-20 15:02:55 -06:00
parent c957ab6cfe
commit 5cfc9b1bd8
3 changed files with 26 additions and 8 deletions

View File

@@ -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; },
@@ -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 */