Selaa lähdekoodia

Fix Latest Pi-Hole breaks stats if password enabled (#1896)
Fixed issue with tabs not loading in settings
added piholeToken to config items
updated pihole hp item to reflect auth change to new pihole version
fixed issue if pihole could not connect

CauseFX 3 vuotta sitten
vanhempi
commit
0c90a4e1ec
3 muutettua tiedostoa jossa 74 lisäystä ja 41 poistoa
  1. 1 0
      api/config/default.php
  2. 16 8
      api/homepage/pihole.php
  3. 57 33
      js/functions.js

+ 1 - 0
api/config/default.php

@@ -533,6 +533,7 @@ return [
 	'homepagePiholeCombine' => false,
 	'homepagePiholeCombine' => false,
 	'piholeHeaderToggle' => true,
 	'piholeHeaderToggle' => true,
 	'piholeURL' => '',
 	'piholeURL' => '',
+	'piholeToken' => '',
 	'homepageAdGuardEnabled' => false,
 	'homepageAdGuardEnabled' => false,
 	'homepageAdGuardAuth' => '1',
 	'homepageAdGuardAuth' => '1',
 	'homepageAdGuardRefresh' => '10000',
 	'homepageAdGuardRefresh' => '10000',

+ 16 - 8
api/homepage/pihole.php

@@ -22,7 +22,8 @@ trait PiHoleHomepageItem
 					$this->settingsOption('auth', 'homepagePiholeAuth'),
 					$this->settingsOption('auth', 'homepagePiholeAuth'),
 				],
 				],
 				'Connection' => [
 				'Connection' => [
-					$this->settingsOption('url', 'piholeURL', ['help' => 'Please make sure to use local IP address and port and to include \'/admin/\' at the end of the URL. You can add multiple Pi-holes by comma separating the URLs.', 'placeholder' => 'http(s)://hostname:port/admin/']),
+					$this->settingsOption('multiple-url', 'piholeURL', ['help' => 'Please make sure to use local IP address and port and to include \'/admin/\' at the end of the URL. You can add multiple Pi-holes by comma separating the URLs.', 'placeholder' => 'http(s)://hostname:port/admin/']),
+					$this->settingsOption('multiple-token', 'piholeToken'),
 				],
 				],
 				'Misc' => [
 				'Misc' => [
 					$this->settingsOption('toggle-title', 'piholeHeaderToggle'),
 					$this->settingsOption('toggle-title', 'piholeHeaderToggle'),
@@ -47,8 +48,12 @@ trait PiHoleHomepageItem
 		$failed = false;
 		$failed = false;
 		$errors = '';
 		$errors = '';
 		$urls = explode(',', $this->config['piholeURL']);
 		$urls = explode(',', $this->config['piholeURL']);
-		foreach ($urls as $url) {
-			$url = $url . '/api.php?';
+		$list = $this->csvHomepageUrlToken($this->config['piholeURL'], $this->config['piholeToken']);
+		foreach ($list as $key => $value) {
+			$url = $value['url'] . '/api.php?';
+			if ($value['token'] !== '' && $value['token'] !== null) {
+				$url = $url . '&auth=' . $value['token'];
+			}
 			try {
 			try {
 				$response = Requests::get($url, [], []);
 				$response = Requests::get($url, [], []);
 				if ($response->success) {
 				if ($response->success) {
@@ -119,10 +124,13 @@ trait PiHoleHomepageItem
 		if (!$this->homepageItemPermissions($this->piholeHomepagePermissions('main'), true)) {
 		if (!$this->homepageItemPermissions($this->piholeHomepagePermissions('main'), true)) {
 			return false;
 			return false;
 		}
 		}
-		$api = array();
-		$urls = explode(',', $this->config['piholeURL']);
-		foreach ($urls as $url) {
-			$url = $url . '/api.php?';
+		$api = [];
+		$list = $this->csvHomepageUrlToken($this->config['piholeURL'], $this->config['piholeToken']);
+		foreach ($list as $key => $value) {
+			$url = $value['url'] . '/api.php?summaryRaw';
+			if ($value['token'] !== '' && $value['token'] !== null) {
+				$url = $url . '&auth=' . $value['token'];
+			}
 			try {
 			try {
 				$response = Requests::get($url, [], []);
 				$response = Requests::get($url, [], []);
 				if ($response->success) {
 				if ($response->success) {
@@ -140,7 +148,7 @@ trait PiHoleHomepageItem
 		}
 		}
 		$api['options']['combine'] = $this->config['homepagePiholeCombine'];
 		$api['options']['combine'] = $this->config['homepagePiholeCombine'];
 		$api['options']['title'] = $this->config['piholeHeaderToggle'];
 		$api['options']['title'] = $this->config['piholeHeaderToggle'];
-		$api = isset($api) ? $api : null;
+		$api = $api ?? null;
 		$this->setAPIResponse('success', null, 200, $api);
 		$this->setAPIResponse('success', null, 200, $api);
 		return $api;
 		return $api;
 	}
 	}

+ 57 - 33
js/functions.js

@@ -3480,9 +3480,14 @@ function buildCategoryEditorItem(array){
 function buildTabEditorItem(array){
 function buildTabEditorItem(array){
 	var tabList = '';
 	var tabList = '';
 	$.each(array.tabs, function(i,v) {
 	$.each(array.tabs, function(i,v) {
-		var deleteDisabled = v.url.indexOf('/page/settings') > 0 ? 'disabled' : 'deleteTab';
-		var buttonDisabled = v.url.indexOf('/page/settings') > 0 ? 'disabled' : '';
-        var typeDisabled = v.url.indexOf('/v2/page/') > 0 ? 'disabled' : '';
+		let deleteDisabled = 'deleteTab';
+		let buttonDisabled = '';
+		let typeDisabled = '';
+		if(v.url !== null){
+			deleteDisabled = v.url.indexOf('/page/settings') > 0 ? 'disabled' : 'deleteTab';
+			buttonDisabled = v.url.indexOf('/page/settings') > 0 ? 'disabled' : '';
+			typeDisabled = v.url.indexOf('/v2/page/') > 0 ? 'disabled' : '';
+		}
 		tabList += `
 		tabList += `
 		<tr class="tabEditor" data-order="`+v.order+`" data-original-order="`+v.order+`" data-id="`+v.id+`" data-group-id="`+v.group_id+`" data-category-id="`+v.category_id+`" data-name="`+v.name+`" data-url="`+v.url+`" data-local-url="`+v.url_local+`" data-ping-url="`+v.ping_url+`" data-image="`+v.image+`" data-tab-action-type="`+v.timeout+`" data-tab-action-time="`+v.timeout_ms+`">
 		<tr class="tabEditor" data-order="`+v.order+`" data-original-order="`+v.order+`" data-id="`+v.id+`" data-group-id="`+v.group_id+`" data-category-id="`+v.category_id+`" data-name="`+v.name+`" data-url="`+v.url+`" data-local-url="`+v.url_local+`" data-ping-url="`+v.ping_url+`" data-image="`+v.image+`" data-tab-action-type="`+v.timeout+`" data-tab-action-time="`+v.timeout_ms+`">
 			<input type="hidden" class="form-control" name="tab[`+v.id+`].id" value="`+v.id+`">
 			<input type="hidden" class="form-control" name="tab[`+v.id+`].id" value="`+v.id+`">
@@ -7869,6 +7874,7 @@ function buildPiholeItem(array){
     var length = Object.keys(array['data']).length;
     var length = Object.keys(array['data']).length;
     var combine = array['options']['combine'];
     var combine = array['options']['combine'];
     var totalQueries = function(data) {
     var totalQueries = function(data) {
+
         var card = `
         var card = `
         <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
         <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
             <div class="card text-white mb-3 pihole-stat bg-green">
             <div class="card text-white mb-3 pihole-stat bg-green">
@@ -7881,10 +7887,14 @@ function buildPiholeItem(array){
 	            if(length > 1 && !combine) {
 	            if(length > 1 && !combine) {
 		            card += `<p class="d-inline text-muted">(`+key+`)</p>`;
 		            card += `<p class="d-inline text-muted">(`+key+`)</p>`;
 	            }
 	            }
-	            card += `<h3 data-toggle="tooltip" data-placement="right" title="`+key+`">`+e['dns_queries_today'].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")+`</h3>`;
-            }
+				let value = 'Error';
+				if(e.length == undefined){
+					value = e['dns_queries_today'].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
+				}
+	            card += `<h3 data-toggle="tooltip" data-placement="right" title="`+key+`">`+value+`</h3>`;
 
 
-        };
+            }
+        }
         card += `
         card += `
                     </div>
                     </div>
                     <i class="fa fa-globe inline-block" aria-hidden="true"></i>
                     <i class="fa fa-globe inline-block" aria-hidden="true"></i>
@@ -7907,9 +7917,13 @@ function buildPiholeItem(array){
 		        if (length > 1 && !combine) {
 		        if (length > 1 && !combine) {
 			        card += `<p class="d-inline text-muted">(${key})</p>`;
 			        card += `<p class="d-inline text-muted">(${key})</p>`;
 		        }
 		        }
-		        card += `<h3 data-toggle="tooltip" data-placement="right" title="${key}">${e['ads_blocked_today'].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}</h3>`;
-	        }
-        };
+		        let value = 'Error';
+		        if(e.length == undefined){
+			        value = e['ads_blocked_today'].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
+		        }
+		        card += `<h3 data-toggle="tooltip" data-placement="right" title="`+key+`">`+value+`</h3>`;
+			}
+        }
         card += `
         card += `
                     </div>
                     </div>
                     <i class="fa fa-hand-paper-o inline-block" aria-hidden="true"></i>
                     <i class="fa fa-hand-paper-o inline-block" aria-hidden="true"></i>
@@ -7932,9 +7946,13 @@ function buildPiholeItem(array){
 		        if (length > 1 && !combine) {
 		        if (length > 1 && !combine) {
 			        card += `<p class="d-inline text-muted">(${key})</p>`;
 			        card += `<p class="d-inline text-muted">(${key})</p>`;
 		        }
 		        }
-		        card += `<h3 data-toggle="tooltip" data-placement="right" title="${key}">${e['ads_percentage_today'].toFixed(1)}%</h3>`
+		        let value = 'Error';
+		        if(e.length == undefined){
+			        value = e['ads_percentage_today'].toFixed(1)
+		        }
+		        card += `<h3 data-toggle="tooltip" data-placement="right" title="`+key+`">`+value+`</h3>`;
 	        }
 	        }
-        };
+        }
         card += `
         card += `
                     </div>
                     </div>
                     <i class="fa fa-pie-chart inline-block" aria-hidden="true"></i>
                     <i class="fa fa-pie-chart inline-block" aria-hidden="true"></i>
@@ -7957,9 +7975,13 @@ function buildPiholeItem(array){
 		        if (length > 1 && !combine) {
 		        if (length > 1 && !combine) {
 			        card += `<p class="d-inline text-muted">(${key})</p>`;
 			        card += `<p class="d-inline text-muted">(${key})</p>`;
 		        }
 		        }
-		        card += `<h3 data-toggle="tooltip" data-placement="right" title="${key}">${e['domains_being_blocked'].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}</h3>`;
+		        let value = 'Error';
+		        if(e.length == undefined){
+			        value = e['domains_being_blocked'].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
+		        }
+		        card += `<h3 data-toggle="tooltip" data-placement="right" title="`+key+`">`+value+`</h3>`;
 	        }
 	        }
-        };
+        }
         card += `
         card += `
                     </div>
                     </div>
                     <i class="fa fa-list inline-block" aria-hidden="true"></i>
                     <i class="fa fa-list inline-block" aria-hidden="true"></i>
@@ -7969,26 +7991,28 @@ function buildPiholeItem(array){
         `
         `
         return card;
         return card;
     };
     };
-    if(combine) {
-        stats += '<div class="row">'
-        stats += totalQueries(array['data']);
-        stats += totalBlocked(array['data']);
-        stats += percentBlocked(array['data']);
-        stats += domainsBlocked(array['data']);
-        stats += '</div>';
-    } else {
-        for(var key in array['data']) {
-            var data = array['data'][key];
-            obj = {};
-            obj[key] = data;
-            stats += '<div class="row">'
-            stats += totalQueries(obj);
-            stats += totalBlocked(obj);
-            stats += percentBlocked(obj);
-            stats += domainsBlocked(obj);
-            stats += '</div>';
-        };
-    }
+
+	if(combine) {
+		stats += '<div class="row">'
+		stats += totalQueries(array['data']);
+		stats += totalBlocked(array['data']);
+		stats += percentBlocked(array['data']);
+		stats += domainsBlocked(array['data']);
+		stats += '</div>';
+	} else {
+		for(var key in array['data']) {
+			var data = array['data'][key];
+			obj = {};
+			obj[key] = data;
+			stats += '<div class="row">'
+			stats += totalQueries(obj);
+			stats += totalBlocked(obj);
+			stats += percentBlocked(obj);
+			stats += domainsBlocked(obj);
+			stats += '</div>';
+		};
+	}
+
     return stats;
     return stats;
 }
 }
 function homepagePihole(timeout){
 function homepagePihole(timeout){