|
27 | 27 |
|
28 | 28 | #include "Settings.h" |
29 | 29 |
|
30 | | -#define VERSION "3.02" |
| 30 | +#define VERSION "3.03" |
31 | 31 |
|
32 | 32 | #define HOSTNAME "CLOCK-" |
33 | 33 | #define CONFIG "/conf.txt" |
@@ -149,14 +149,16 @@ static const char PIHOLE_FORM[] PROGMEM = "<form class='w3-container' action='/s |
149 | 149 | "<p><input name='displaypihole' class='w3-check w3-margin-top' type='checkbox' %PIHOLECHECKED%> Show Pi-hole Statistics</p>" |
150 | 150 | "<label>Pi-hole Address (do not include http://)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='piholeAddress' id='piholeAddress' value='%PIHOLEADDRESS%' maxlength='60'>" |
151 | 151 | "<label>Pi-hole Port</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='piholePort' id='piholePort' value='%PIHOLEPORT%' maxlength='5' onkeypress='return isNumberKey(event)'>" |
| 152 | + "<label>Pi-hole API Token (from Pi-hole → Settings → API/Web interface)</label>" |
| 153 | + "<input class='w3-input w3-border w3-margin-bottom' type='text' name='piApiToken' id='piApiToken' value='%PIAPITOKEN%' maxlength='65'>" |
152 | 154 | "<input type='button' value='Test Connection and JSON Response' onclick='testPiHole()'><p id='PiHoleTest'></p>" |
153 | 155 | "<button class='w3-button w3-block w3-green w3-section w3-padding' type='submit'>Save</button></form>" |
154 | 156 | "<script>function isNumberKey(e){var h=e.which?e.which:event.keyCode;return!(h>31&&(h<48||h>57))}</script>"; |
155 | 157 |
|
156 | 158 | static const char PIHOLE_TEST[] PROGMEM = "<script>function testPiHole(){var e=document.getElementById(\"PiHoleTest\"),t=document.getElementById(\"piholeAddress\").value," |
157 | | - "n=document.getElementById(\"piholePort\").value;" |
| 159 | + "n=document.getElementById(\"piholePort\").value,api=document.getElementById(\"piApiToken\").value;;" |
158 | 160 | "if(e.innerHTML=\"\",\"\"==t||\"\"==n)return e.innerHTML=\"* Address and Port are required\"," |
159 | | - "void(e.style.background=\"\");var r=\"http://\"+t+\":\"+n;r+=\"/admin/api.php?summary\",window.open(r,\"_blank\").focus()}</script>"; |
| 161 | + "void(e.style.background=\"\");var r=\"http://\"+t+\":\"+n;r+=\"/admin/api.php?summary=3&auth=\"+api,window.open(r,\"_blank\").focus()}</script>"; |
160 | 162 |
|
161 | 163 | static const char NEWS_FORM1[] PROGMEM = "<form class='w3-container' action='/savenews' method='get'><h2>News Configuration:</h2>" |
162 | 164 | "<p><input name='displaynews' class='w3-check w3-margin-top' type='checkbox' %NEWSCHECKED%> Display News Headlines</p>" |
@@ -427,8 +429,8 @@ void loop() { |
427 | 429 | msg += "(" + printerClient.getProgressCompletion() + "%) "; |
428 | 430 | } |
429 | 431 | if (USE_PIHOLE) { |
430 | | - piholeClient.getPiHoleData(PiHoleServer, PiHolePort); |
431 | | - piholeClient.getGraphData(PiHoleServer, PiHolePort); |
| 432 | + piholeClient.getPiHoleData(PiHoleServer, PiHolePort, PiHoleApiKey); |
| 433 | + piholeClient.getGraphData(PiHoleServer, PiHolePort, PiHoleApiKey); |
432 | 434 | if (piholeClient.getPiHoleStatus() != "") { |
433 | 435 | msg += " Pi-hole (" + piholeClient.getPiHoleStatus() + "): " + piholeClient.getAdsPercentageToday() + "% "; |
434 | 436 | } |
@@ -553,10 +555,12 @@ void handleSavePihole() { |
553 | 555 | USE_PIHOLE = server.hasArg("displaypihole"); |
554 | 556 | PiHoleServer = server.arg("piholeAddress"); |
555 | 557 | PiHolePort = server.arg("piholePort").toInt(); |
| 558 | + PiHoleApiKey = server.arg("piApiToken"); |
| 559 | + Serial.println("PiHoleApiKey from save: " + PiHoleApiKey); |
556 | 560 | writeCityIds(); |
557 | 561 | if (USE_PIHOLE) { |
558 | | - piholeClient.getPiHoleData(PiHoleServer, PiHolePort); |
559 | | - piholeClient.getGraphData(PiHoleServer, PiHolePort); |
| 562 | + piholeClient.getPiHoleData(PiHoleServer, PiHolePort, PiHoleApiKey); |
| 563 | + piholeClient.getGraphData(PiHoleServer, PiHolePort, PiHoleApiKey); |
560 | 564 | } |
561 | 565 | redirectHome(); |
562 | 566 | } |
@@ -746,6 +750,8 @@ void handlePiholeConfigure() { |
746 | 750 | form.replace("%PIHOLECHECKED%", isPiholeDisplayedChecked); |
747 | 751 | form.replace("%PIHOLEADDRESS%", PiHoleServer); |
748 | 752 | form.replace("%PIHOLEPORT%", String(PiHolePort)); |
| 753 | + form.replace("%PIAPITOKEN%", PiHoleApiKey); |
| 754 | + |
749 | 755 |
|
750 | 756 | server.sendContent(form); |
751 | 757 | form = ""; |
@@ -1348,6 +1354,7 @@ String writeCityIds() { |
1348 | 1354 | f.println("USE_PIHOLE=" + String(USE_PIHOLE)); |
1349 | 1355 | f.println("PiHoleServer=" + PiHoleServer); |
1350 | 1356 | f.println("PiHolePort=" + String(PiHolePort)); |
| 1357 | + f.println("PiHoleApiKey=" + String(PiHoleApiKey)); |
1351 | 1358 | f.println("themeColor=" + themeColor); |
1352 | 1359 | } |
1353 | 1360 | f.close(); |
@@ -1540,6 +1547,11 @@ void readCityIds() { |
1540 | 1547 | PiHolePort = line.substring(line.lastIndexOf("PiHolePort=") + 11).toInt(); |
1541 | 1548 | Serial.println("PiHolePort=" + String(PiHolePort)); |
1542 | 1549 | } |
| 1550 | + if (line.indexOf("PiHoleApiKey=") >= 0) { |
| 1551 | + PiHoleApiKey = line.substring(line.lastIndexOf("PiHoleApiKey=") + 13); |
| 1552 | + PiHoleApiKey.trim(); |
| 1553 | + Serial.println("PiHoleApiKey=" + String(PiHoleApiKey)); |
| 1554 | + } |
1543 | 1555 | if (line.indexOf("themeColor=") >= 0) { |
1544 | 1556 | themeColor = line.substring(line.lastIndexOf("themeColor=") + 11); |
1545 | 1557 | themeColor.trim(); |
|
0 commit comments