forked from pi-hole/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.php
1435 lines (1399 loc) · 97.4 KB
/
settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php /*
* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
require "scripts/pi-hole/php/header.php";
require "scripts/pi-hole/php/savesettings.php";
require_once "scripts/pi-hole/php/FTL.php";
// Reread ini file as things might have been changed
$setupVars = parse_ini_file("/etc/pihole/setupVars.conf");
$piholeFTLConf = piholeFTLConfig();
// Handling of PHP internal errors
$last_error = error_get_last();
if($last_error["type"] === E_WARNING || $last_error["type"] === E_ERROR)
{
$error .= "There was a problem applying your settings.<br>Debugging information:<br>PHP error (".htmlspecialchars($last_error["type"])."): ".htmlspecialchars($last_error["message"])." in ".htmlspecialchars($last_error["file"]).":".htmlspecialchars($last_error["line"]);
}
?>
<style>
.tooltip-inner {
max-width: none;
white-space: nowrap;
}
</style>
<?php // Check if ad lists should be updated after saving ...
if (isset($_POST["submit"])) {
if ($_POST["submit"] == "saveupdate") {
// If that is the case -> refresh to the gravity page and start updating immediately
?>
<meta http-equiv="refresh" content="1;url=gravity.php?go">
<?php }
} ?>
<?php if (isset($debug)) { ?>
<div id="alDebug" class="alert alert-warning alert-dismissible fade in" role="alert">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<h4><i class="icon fa fa-exclamation-triangle"></i> Debug</h4>
<pre><?php print_r($_POST); ?></pre>
</div>
<?php } ?>
<?php if (strlen($success) > 0) { ?>
<div id="alInfo" class="alert alert-info alert-dismissible fade in" role="alert">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<h4><i class="icon fa fa-info"></i> Info</h4>
<?php echo $success; ?>
</div>
<?php } ?>
<?php if (strlen($error) > 0) { ?>
<div id="alError" class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<h4><i class="icon fa fa-ban"></i> Error</h4>
<?php echo $error; ?>
</div>
<?php } ?>
<?php
// Networking
if (isset($setupVars["PIHOLE_INTERFACE"])) {
$piHoleInterface = $setupVars["PIHOLE_INTERFACE"];
} else {
$piHoleInterface = "unknown";
}
if (isset($setupVars["IPV4_ADDRESS"])) {
$piHoleIPv4 = $setupVars["IPV4_ADDRESS"];
} else {
$piHoleIPv4 = "unknown";
}
$IPv6connectivity = false;
if (isset($setupVars["IPV6_ADDRESS"])) {
$piHoleIPv6 = $setupVars["IPV6_ADDRESS"];
sscanf($piHoleIPv6, "%2[0-9a-f]", $hexstr);
if (strlen($hexstr) == 2) {
// Convert HEX string to number
$hex = hexdec($hexstr);
// Global Unicast Address (2000::/3, RFC 4291)
$GUA = (($hex & 0x70) === 0x20);
// Unique Local Address (fc00::/7, RFC 4193)
$ULA = (($hex & 0xfe) === 0xfc);
if ($GUA || $ULA) {
// Scope global address detected
$IPv6connectivity = true;
}
}
} else {
$piHoleIPv6 = "unknown";
}
$hostname = trim(file_get_contents("/etc/hostname"), "\x00..\x1F");
?>
<?php
// DNS settings
$DNSservers = [];
$DNSactive = [];
$i = 1;
while (isset($setupVars["PIHOLE_DNS_" . $i])) {
if (isinserverlist($setupVars["PIHOLE_DNS_" . $i])) {
array_push($DNSactive, $setupVars["PIHOLE_DNS_" . $i]);
} elseif (strpos($setupVars["PIHOLE_DNS_" . $i], ".") !== false) {
if (!isset($custom1)) {
$custom1 = $setupVars["PIHOLE_DNS_" . $i];
} else {
$custom2 = $setupVars["PIHOLE_DNS_" . $i];
}
} elseif (strpos($setupVars["PIHOLE_DNS_" . $i], ":") !== false) {
if (!isset($custom3)) {
$custom3 = $setupVars["PIHOLE_DNS_" . $i];
} else {
$custom4 = $setupVars["PIHOLE_DNS_" . $i];
}
}
$i++;
}
if (isset($setupVars["DNS_FQDN_REQUIRED"])) {
if ($setupVars["DNS_FQDN_REQUIRED"]) {
$DNSrequiresFQDN = true;
} else {
$DNSrequiresFQDN = false;
}
} else {
$DNSrequiresFQDN = true;
}
if (isset($setupVars["DNS_BOGUS_PRIV"])) {
if ($setupVars["DNS_BOGUS_PRIV"]) {
$DNSbogusPriv = true;
} else {
$DNSbogusPriv = false;
}
} else {
$DNSbogusPriv = true;
}
if (isset($setupVars["DNSSEC"])) {
if ($setupVars["DNSSEC"]) {
$DNSSEC = true;
} else {
$DNSSEC = false;
}
} else {
$DNSSEC = false;
}
if (isset($setupVars["DNSMASQ_LISTENING"])) {
if ($setupVars["DNSMASQ_LISTENING"] === "single") {
$DNSinterface = "single";
} elseif ($setupVars["DNSMASQ_LISTENING"] === "all") {
$DNSinterface = "all";
} else {
$DNSinterface = "local";
}
} else {
$DNSinterface = "single";
}
if (isset($setupVars["REV_SERVER"]) && ($setupVars["REV_SERVER"] == 1)) {
$rev_server = true;
$rev_server_cidr = $setupVars["REV_SERVER_CIDR"];
$rev_server_target = $setupVars["REV_SERVER_TARGET"];
$rev_server_domain = $setupVars["REV_SERVER_DOMAIN"];
} else {
$rev_server = false;
}
?>
<?php
// Query logging
if (isset($setupVars["QUERY_LOGGING"])) {
if ($setupVars["QUERY_LOGGING"] == 1) {
$piHoleLogging = true;
} else {
$piHoleLogging = false;
}
} else {
$piHoleLogging = true;
}
?>
<?php
// Excluded domains in API Query Log call
if (isset($setupVars["API_EXCLUDE_DOMAINS"])) {
$excludedDomains = explode(",", $setupVars["API_EXCLUDE_DOMAINS"]);
} else {
$excludedDomains = [];
}
// Exluded clients in API Query Log call
if (isset($setupVars["API_EXCLUDE_CLIENTS"])) {
$excludedClients = explode(",", $setupVars["API_EXCLUDE_CLIENTS"]);
} else {
$excludedClients = [];
}
// Exluded clients
if (isset($setupVars["API_QUERY_LOG_SHOW"])) {
$queryLog = $setupVars["API_QUERY_LOG_SHOW"];
} else {
$queryLog = "all";
}
// Privacy Mode
if (isset($setupVars["API_PRIVACY_MODE"])) {
$privacyMode = $setupVars["API_PRIVACY_MODE"];
} else {
$privacyMode = false;
}
?>
<?php
if (isset($_GET['tab']) && in_array($_GET['tab'], array("sysadmin", "adlists", "dns", "piholedhcp", "api", "privacy", "teleporter"))) {
$tab = $_GET['tab'];
} else {
$tab = "sysadmin";
}
?>
<div class="row">
<div class="col-md-12">
<div class="nav-tabs-custom">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation"<?php if($tab === "sysadmin"){ ?> class="active"<?php } ?>>
<a href="#sysadmin" aria-controls="sysadmin" aria-expanded="<?php echo $tab === "sysadmin" ? "true" : "false"; ?>" role="tab" data-toggle="tab">System</a>
</li>
<li role="presentation"<?php if($tab === "adlists"){ ?> class="active"<?php } ?>>
<a href="#adlists" aria-controls="adlists" aria-expanded="<?php echo $tab === "adlists" ? "true" : "false"; ?>" role="tab" data-toggle="tab">Adlists</a>
</li>
<li role="presentation"<?php if($tab === "dns"){ ?> class="active"<?php } ?>>
<a href="#dns" aria-controls="dns" aria-expanded="<?php echo $tab === "dns" ? "true" : "false"; ?>" role="tab" data-toggle="tab">DNS</a>
</li>
<li role="presentation"<?php if($tab === "piholedhcp"){ ?> class="active"<?php } ?>>
<a href="#piholedhcp" aria-controls="piholedhcp" aria-expanded="<?php echo $tab === "piholedhcp" ? "true" : "false"; ?>" role="tab" data-toggle="tab">DHCP</a>
</li>
<li role="presentation"<?php if($tab === "api"){ ?> class="active"<?php } ?>>
<a href="#api" aria-controls="api" aria-expanded="<?php echo $tab === "api" ? "true" : "false"; ?>" role="tab" data-toggle="tab">API / Web interface</a>
</li>
<li role="presentation"<?php if($tab === "privacy"){ ?> class="active"<?php } ?>>
<a href="#privacy" aria-controls="privacy" aria-expanded="<?php echo $tab === "privacy" ? "true" : "false"; ?>" role="tab" data-toggle="tab">Privacy</a>
</li>
<li role="presentation"<?php if($tab === "teleporter"){ ?> class="active"<?php } ?>>
<a href="#teleporter" aria-controls="teleporter" aria-expanded="<?php echo $tab === "teleporter" ? "true" : "false"; ?>" role="tab" data-toggle="tab">Teleporter</a>
</li>
</ul>
<div class="tab-content">
<!-- ######################################################### System admin ######################################################### -->
<div id="sysadmin" class="tab-pane fade<?php if($tab === "sysadmin"){ ?> in active<?php } ?>">
<div class="row">
<div class="col-md-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Network Information</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-12">
<table class="table table-striped table-bordered nowrap">
<tbody>
<tr>
<th scope="row">Pi-hole Ethernet Interface:</th>
<td><?php echo htmlentities($piHoleInterface); ?></td>
</tr>
<tr>
<th scope="row">Pi-hole IPv4 address:</th>
<td><?php echo htmlentities($piHoleIPv4); ?></td>
</tr>
<tr>
<th scope="row">Pi-hole IPv6 address:</th>
<td class="breakall"><?php echo htmlentities($piHoleIPv6); ?></td>
</tr>
<tr>
<th scope="row">Pi-hole hostname:</th>
<td><?php echo htmlentities($hostname); ?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">FTL Information</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-lg-12">
<?php
if ($FTL) {
function get_FTL_data($arg)
{
global $FTLpid;
return trim(exec("ps -p " . $FTLpid . " -o " . $arg));
}
$FTLversion = exec("/usr/bin/pihole-FTL version");
?>
<table class="table table-striped table-bordered nowrap">
<tbody>
<tr>
<th scope="row">FTL version:</th>
<td><?php echo $FTLversion; ?></td>
</tr>
<tr>
<th scope="row">Process identifier (PID):</th>
<td><?php echo $FTLpid; ?></td>
</tr>
<tr>
<th scope="row">Time FTL started:</th>
<td><?php print_r(get_FTL_data("start")); ?></td>
</tr>
<tr>
<th scope="row">User / Group:</th>
<td><?php print_r(get_FTL_data("euser")); ?> / <?php print_r(get_FTL_data("egroup")); ?></td>
</tr>
<tr>
<th scope="row">Total CPU utilization:</th>
<td><?php print_r(get_FTL_data("%cpu")); ?>%</td>
</tr>
<tr>
<th scope="row">Memory utilization:</th>
<td><?php print_r(get_FTL_data("%mem")); ?>%</td>
</tr>
<tr>
<th scope="row">
<span title="Resident memory is the portion of memory occupied by a process that is held in main memory (RAM). The rest of the occupied memory exists in the swap space or file system.">Used memory:</span>
</th>
<td><?php echo formatSizeUnits(1e3 * floatval(get_FTL_data("rss"))); ?></td>
</tr>
<tr>
<th scope="row">
<span title="Size of the DNS domain cache">DNS cache size:</span>
</th>
<td id="cache-size"> </td>
</tr>
<tr>
<th scope="row">
<span title="Number of cache insertions">DNS cache insertions:</span>
</th>
<td id="cache-inserted"> </td>
</tr>
<tr>
<th scope="row">
<span title="Number of cache entries that had to be removed although they are not expired (increase cache size to reduce this number)">DNS cache evictions:</span>
</th>
<td id="cache-live-freed"> </td>
</tr>
</tbody>
</table>
See also our <a href="https://docs.pi-hole.net/ftldns/dns-cache/" rel="noopener" target="_blank">DNS cache documentation</a>.
<?php } else { ?>
<div>The FTL service is offline!</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="box box-warning">
<div class="box-body">
<div class="row">
<div class="col-md-4">
<?php if ($piHoleLogging) { ?>
<button type="button" class="btn btn-warning confirm-disablelogging-noflush btn-block">Disable query logging</button>
<?php } else { ?>
<form role="form" method="post">
<input type="hidden" name="action" value="Enable">
<input type="hidden" name="field" value="Logging">
<input type="hidden" name="token" value="<?php echo $token ?>">
<button type="submit" class="btn btn-success btn-block">Enable query logging</button>
</form>
<?php } ?>
</div>
<p class="hidden-md hidden-lg"></p>
<div class="col-md-4">
<button type="button" class="btn btn-warning confirm-flusharp btn-block">Flush network table</button>
</div>
<p class="hidden-md hidden-lg"></p>
<div class="col-md-4">
<button type="button" class="btn btn-warning confirm-restartdns btn-block">Restart DNS resolver</button>
</div>
</div>
<br/>
<div class="row">
<div class="col-md-4">
<button type="button" class="btn btn-danger confirm-flushlogs btn-block">Flush logs</button>
</div>
<p class="hidden-md hidden-lg"></p>
<div class="col-md-4">
<button type="button" class="btn btn-danger confirm-poweroff btn-block">Power off system</button>
</div>
<p class="hidden-md hidden-lg"></p>
<div class="col-md-4">
<button type="button" class="btn btn-danger confirm-reboot btn-block">Restart system</button>
</div>
</div>
<form role="form" method="post" id="flushlogsform">
<input type="hidden" name="field" value="flushlogs">
<input type="hidden" name="token" value="<?php echo $token ?>">
</form>
<form role="form" method="post" id="flusharpform">
<input type="hidden" name="field" value="flusharp">
<input type="hidden" name="token" value="<?php echo $token ?>">
</form>
<form role="form" method="post" id="disablelogsform-noflush">
<input type="hidden" name="field" value="Logging">
<input type="hidden" name="action" value="Disable-noflush">
<input type="hidden" name="token" value="<?php echo $token ?>">
</form>
<form role="form" method="post" id="poweroffform">
<input type="hidden" name="field" value="poweroff">
<input type="hidden" name="token" value="<?php echo $token ?>">
</form>
<form role="form" method="post" id="rebootform">
<input type="hidden" name="field" value="reboot">
<input type="hidden" name="token" value="<?php echo $token ?>">
</form>
<form role="form" method="post" id="restartdnsform">
<input type="hidden" name="field" value="restartdns">
<input type="hidden" name="token" value="<?php echo $token ?>">
</form>
</div>
</div>
</div>
</div>
</div>
<!-- ######################################################### Adlists ######################################################### -->
<div id="adlists" class="tab-pane fade<?php if($tab === "adlists"){ ?> in active<?php } ?>">
<div class="row">
<div class="col-md-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Adlists used to generate Pi-hole's Gravity</h3>
</div>
<div class="box-body">
<p>Please use the <a href="groups-adlists.php">group management pages</a> to edit the adlists used by Pi-hole.</p>
</div>
</div>
</div>
</div>
</div>
<!-- ######################################################### DHCP ######################################################### -->
<div id="piholedhcp" class="tab-pane fade<?php if($tab === "piholedhcp"){ ?> in active<?php } ?>">
<?php
// Pi-hole DHCP server
if (isset($setupVars["DHCP_ACTIVE"])) {
if ($setupVars["DHCP_ACTIVE"] == 1) {
$DHCP = true;
} else {
$DHCP = false;
}
// Read setings from config file
if (isset($setupVars["DHCP_START"])) {
$DHCPstart = $setupVars["DHCP_START"];
} else {
$DHCPstart = "";
}
if (isset($setupVars["DHCP_END"])) {
$DHCPend = $setupVars["DHCP_END"];
} else {
$DHCPend = "";
}
if (isset($setupVars["DHCP_ROUTER"])) {
$DHCProuter = $setupVars["DHCP_ROUTER"];
} else {
$DHCProuter = "";
}
// This setting has been added later, we have to check if it exists
if (isset($setupVars["DHCP_LEASETIME"])) {
$DHCPleasetime = $setupVars["DHCP_LEASETIME"];
if (strlen($DHCPleasetime) < 1) {
// Fallback if empty string
$DHCPleasetime = 24;
}
} else {
$DHCPleasetime = 24;
}
if (isset($setupVars["DHCP_IPv6"])) {
$DHCPIPv6 = $setupVars["DHCP_IPv6"];
} else {
$DHCPIPv6 = false;
}
if (isset($setupVars["DHCP_rapid_commit"])) {
$DHCP_rapid_commit = $setupVars["DHCP_rapid_commit"];
} else {
$DHCP_rapid_commit = false;
}
} else {
$DHCP = false;
// Try to guess initial settings
if ($piHoleIPv4 !== "unknown") {
$DHCPdomain = explode(".", $piHoleIPv4);
$DHCPstart = $DHCPdomain[0] . "." . $DHCPdomain[1] . "." . $DHCPdomain[2] . ".201";
$DHCPend = $DHCPdomain[0] . "." . $DHCPdomain[1] . "." . $DHCPdomain[2] . ".251";
$DHCProuter = $DHCPdomain[0] . "." . $DHCPdomain[1] . "." . $DHCPdomain[2] . ".1";
} else {
$DHCPstart = "";
$DHCPend = "";
$DHCProuter = "";
}
$DHCPleasetime = 24;
$DHCPIPv6 = false;
$DHCP_rapid_commit = false;
}
if (isset($setupVars["PIHOLE_DOMAIN"])) {
$piHoleDomain = $setupVars["PIHOLE_DOMAIN"];
} else {
$piHoleDomain = "lan";
}
?>
<form role="form" method="post">
<div class="row">
<!-- DHCP Settings Box -->
<div class="col-md-6">
<div class="box box-warning">
<div class="box-header with-border">
<h3 class="box-title">DHCP Settings</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-12">
<div><input type="checkbox" name="active" id="DHCPchk" <?php if ($DHCP){ ?>checked<?php } ?>><label for="DHCPchk"><strong>DHCP server enabled</strong></label></div><br>
<p id="dhcpnotice" <?php if (!$DHCP){ ?>hidden<?php } ?>>Make sure your router's DHCP server is disabled when using the Pi-hole DHCP server!</p>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<label>Range of IP addresses to hand out</label>
</div>
<div class="col-xs-12 col-sm-6 col-md-12 col-lg-6">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">From</div>
<input type="text" class="form-control DHCPgroup" name="from" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"
value="<?php echo $DHCPstart; ?>"
<?php if (!$DHCP){ ?>disabled<?php } ?>>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-12 col-lg-6">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">To</div>
<input type="text" class="form-control DHCPgroup" name="to" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"
value="<?php echo $DHCPend; ?>"
<?php if (!$DHCP){ ?>disabled<?php } ?>>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<label>Router (gateway) IP address</label>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">Router</div>
<input type="text" class="form-control DHCPgroup" name="router" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"
value="<?php echo $DHCProuter; ?>"
<?php if (!$DHCP){ ?>disabled<?php } ?>>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Advanced DHCP Settings Box -->
<div class="col-md-6">
<div class="box box-warning">
<div class="box-header with-border">
<h3 class="box-title">Advanced DHCP settings</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-12">
<label>Pi-hole domain name</label>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">Domain</div>
<input type="text" class="form-control DHCPgroup" name="domain"
value="<?php echo $piHoleDomain; ?>"
<?php if (!$DHCP){ ?>disabled<?php } ?>>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<label>DHCP lease time</label>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">Lease time in hours</div>
<input type="number" class="form-control DHCPgroup"
name="leasetime"
id="leasetime" value="<?php echo $DHCPleasetime; ?>"
data-mask <?php if (!$DHCP){ ?>disabled<?php } ?>>
</div>
</div>
<p>Hint: 0 = infinite, 24 = one day, 168 = one week, 744 = one month, 8760 = one year</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div><input type="checkbox" name="useIPv6" id="useIPv6" class="DHCPgroup" <?php if ($DHCPIPv6){ ?>checked<?php }; if (!$DHCP){ ?> disabled<?php } ?>> <label for="useIPv6"><strong>Enable IPv6 support (SLAAC + RA)</strong></label></div>
<div><input type="checkbox" name="DHCP_rapid_commit" id="DHCP_rapid_commit" class="DHCPgroup" <?php if ($DHCP_rapid_commit){ ?>checked<?php }; if (!$DHCP){ ?> disabled<?php } ?>> <label for="DHCP_rapid_commit"><strong>Enable DHCP rapid commit (fast address assignment)</strong></label></div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- DHCP Leases Box -->
<div class="row">
<?php
$dhcp_leases = array();
if ($DHCP) {
// Read leases file
$leasesfile = true;
$dhcpleases = @fopen('/etc/pihole/dhcp.leases', 'r');
if (!is_resource($dhcpleases))
$leasesfile = false;
function convertseconds($argument)
{
$seconds = round($argument);
if ($seconds < 60) {
return sprintf('%ds', $seconds);
} elseif ($seconds < 3600) {
return sprintf('%dm %ds', ($seconds / 60), ($seconds % 60));
} elseif ($seconds < 86400) {
return sprintf('%dh %dm %ds', ($seconds / 3600 % 24), ($seconds / 60 % 60), ($seconds % 60));
} else {
return sprintf('%dd %dh %dm %ds', ($seconds / 86400), ($seconds / 3600 % 24), ($seconds / 60 % 60), ($seconds % 60));
}
}
while (!feof($dhcpleases) && $leasesfile) {
$line = explode(" ", trim(fgets($dhcpleases)));
if (count($line) == 5) {
$counter = intval($line[0]);
if ($counter == 0) {
$time = "Infinite";
} elseif ($counter <= 315360000) // 10 years in seconds
{
$time = convertseconds($counter);
} else // Assume time stamp
{
$time = convertseconds($counter - time());
}
if (strpos($line[2], ':') !== false) {
// IPv6 address
$type = 6;
} else {
// IPv4 lease
$type = 4;
}
$host = $line[3];
if ($host == "*") {
$host = "<i>unknown</i>";
}
$clid = $line[4];
if ($clid == "*") {
$clid = "<i>unknown</i>";
}
array_push($dhcp_leases, ["TIME" => $time, "hwaddr" => strtoupper($line[1]), "IP" => $line[2], "host" => $host, "clid" => $clid, "type" => $type]);
}
}
}
readStaticLeasesFile();
?>
<div class="col-md-12">
<div class="box box-warning">
<div class="box-header with-border">
<h3 class="box-title">DHCP leases</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-12">
<label>Currently active DHCP leases</label>
<table id="DHCPLeasesTable" class="table table-striped table-bordered nowrap" width="100%">
<thead>
<tr>
<th>MAC address</th>
<th>IP address</th>
<th>Hostname</th>
<td></td>
</tr>
</thead>
<tbody>
<?php foreach ($dhcp_leases as $lease) { ?>
<tr data-placement="auto" data-container="body" data-toggle="tooltip"
title="Lease type: IPv<?php echo $lease["type"]; ?><br/>Remaining lease time: <?php echo $lease["TIME"]; ?><br/>DHCP UID: <?php echo $lease["clid"]; ?>">
<td id="MAC"><?php echo $lease["hwaddr"]; ?></td>
<td id="IP" data-order="<?php echo bin2hex(inet_pton($lease["IP"])); ?>"><?php echo $lease["IP"]; ?></td>
<td id="HOST"><?php echo htmlentities($lease["host"]); ?></td>
<td>
<button type="button" id="button" class="btn btn-warning btn-xs" data-static="alert">
<span class="fas fas fa-file-import"></span>
</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<br>
</div>
<div class="col-md-12">
<label>Static DHCP leases configuration</label>
<table id="DHCPStaticLeasesTable" class="table table-striped table-bordered nowrap" width="100%">
<thead>
<tr>
<th>MAC address</th>
<th>IP address</th>
<th>Hostname</th>
<td></td>
</tr>
</thead>
<tbody>
<?php foreach ($dhcp_static_leases as $lease) { ?>
<tr>
<td><?php echo $lease["hwaddr"]; ?></td>
<td data-order="<?php echo bin2hex(inet_pton($lease["IP"])); ?>"><?php echo $lease["IP"]; ?></td>
<td><?php echo htmlentities($lease["host"]); ?></td>
<td><?php if (strlen($lease["hwaddr"]) > 0) { ?>
<button type="submit" class="btn btn-danger btn-xs" name="removestatic"
value="<?php echo $lease["hwaddr"]; ?>">
<span class="far fa-trash-alt"></span>
</button>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot style="display: table-row-group">
<tr>
<td><input type="text" class="form-group" name="AddMAC" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"></td>
<td><input type="text" class="form-group" name="AddIP" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"></td>
<td><input type="text" class="form-group" name="AddHostname" value="" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"></td>
<td>
<button type="submit" class="btn btn-success btn-xs" name="addstatic">
<span class="fas fa-plus"></span>
</button>
</td>
</tr>
</tfoot>
</table>
<p>Specifying the MAC address is mandatory and only one entry per MAC
address is allowed. If the IP address is omitted and a host name is
given, the IP address will still be generated dynamically and the
specified host name will be used. If the host name is omitted, only
a static lease will be added.</p>
</div>
</div>
</div>
</div>
<input type="hidden" name="field" value="DHCP">
<input type="hidden" name="token" value="<?php echo $token ?>">
<button type="submit" class="btn btn-primary pull-right">Save</button>
</div>
</div>
</form>
</div>
<!-- ######################################################### DNS ######################################################### -->
<div id="dns" class="tab-pane fade<?php if($tab === "dns"){ ?> in active<?php } ?>">
<form role="form" method="post">
<div class="row">
<div class="col-lg-6">
<div class="box box-warning">
<div class="box-header with-border">
<h1 class="box-title">Upstream DNS Servers</h1>
</div>
<div class="box-body">
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered">
<tr>
<th colspan="2">IPv4</th>
<th colspan="2">IPv6</th>
<th>Name</th>
</tr>
<?php foreach ($DNSserverslist as $key => $value) { ?>
<tr>
<?php if (isset($value["v4_1"])) { ?>
<td title="<?php echo $value["v4_1"]; ?>">
<div><input type="checkbox" name="DNSserver<?php echo $value["v4_1"]; ?>" id="DNS4server<?php echo $value["v4_1"]; ?>" value="true" <?php if (in_array($value["v4_1"], $DNSactive)){ ?>checked<?php } ?>><label for="DNS4server<?php echo $value["v4_1"]; ?>"></label></div>
</td>
<?php } else { ?>
<td></td>
<?php } ?>
<?php if (isset($value["v4_2"])) { ?>
<td title="<?php echo $value["v4_2"]; ?>">
<div><input type="checkbox" name="DNSserver<?php echo $value["v4_2"]; ?>" id="DNS4server<?php echo $value["v4_2"]; ?>" value="true" <?php if (in_array($value["v4_2"], $DNSactive)){ ?>checked<?php } ?>><label for="DNS4server<?php echo $value["v4_2"]; ?>"></label></div>
</td>
<?php } else { ?>
<td></td>
<?php } ?>
<?php if (isset($value["v6_1"])) { ?>
<td title="<?php echo $value["v6_1"]; ?>">
<div><input type="checkbox" name="DNSserver<?php echo $value["v6_1"]; ?>" id="DNS6server<?php echo $value["v6_1"]; ?>" value="true" <?php if (in_array($value["v6_1"], $DNSactive) && $IPv6connectivity){ ?>checked<?php } if (!$IPv6connectivity) { ?> disabled <?php } ?>><label for="DNS6server<?php echo $value["v6_1"]; ?>"></label></div>
</td>
<?php } else { ?>
<td></td>
<?php } ?>
<?php if (isset($value["v6_2"])) { ?>
<td title="<?php echo $value["v6_2"]; ?>">
<div><input type="checkbox" name="DNSserver<?php echo $value["v6_2"]; ?>" id="DNS6server<?php echo $value["v6_2"]; ?>" value="true" <?php if (in_array($value["v6_2"], $DNSactive) && $IPv6connectivity){ ?>checked<?php } if (!$IPv6connectivity) { ?> disabled <?php } ?>><label for="DNS6server<?php echo $value["v6_2"]; ?>"></label></div>
</td>
<?php } else { ?>
<td></td>
<?php } ?>
<td><?php echo $key; ?></td>
</tr>
<?php } ?>
</table>
<p>ECS (Extended Client Subnet) defines a mechanism for recursive resolvers to send partial client IP address information to authoritative DNS name servers. Content Delivery Networks (CDNs) and latency-sensitive services use this to give geo-located responses when responding to name lookups coming through public DNS resolvers. <em>Note that ECS may result in reduced privacy.</em></p>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="box box-warning">
<div class="box-header with-border">
<h1 class="box-title">Upstream DNS Servers</h1>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-6">
<strong>Custom 1 (IPv4)</strong>
<div class="row">
<div class="col-md-1"><div>
<input type="checkbox" name="custom1" id="custom1" value="Customv4" <?php if (isset($custom1)){ ?>checked<?php } ?>>
<label for="custom1"></label></div>
</div>
<div class="col-md-11">
<input type="text" name="custom1val" class="form-control" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"
<?php if (isset($custom1)){ ?>value="<?php echo $custom1; ?>"<?php } ?>>
</div>
</div>
</div>
<div class="col-md-6">
<strong>Custom 2 (IPv4)</strong>
<div class="row">
<div class="col-md-1"><div>
<input type="checkbox" name="custom2" id="custom2" value="Customv4" <?php if (isset($custom2)){ ?>checked<?php } ?>>
<label for="custom2"></label></div>
</div>
<div class="col-md-11">
<input type="text" name="custom2val" class="form-control" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"
<?php if (isset($custom2)){ ?>value="<?php echo $custom2; ?>"<?php } ?>>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<strong>Custom 3 (IPv6)</strong>
<div class="row">
<div class="col-md-1"><div>
<input type="checkbox" name="custom3" id="custom3" value="Customv6" <?php if (isset($custom3)){ ?>checked<?php } ?>>
<label for="custom3"></label></div>
</div>
<div class="col-md-11">
<input type="text" name="custom3val" class="form-control" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"
<?php if (isset($custom3)){ ?>value="<?php echo $custom3; ?>"<?php } ?>>
</div>
</div>
</div>
<div class="col-md-6">
<strong>Custom 4 (IPv6)</strong>
<div class="row">
<div class="col-md-1"><div>
<input type="checkbox" name="custom4" id="custom4" value="Customv6" <?php if (isset($custom4)){ ?>checked<?php } ?>>
<label for="custom4"></label></div>
</div>
<div class="col-md-11">
<input type="text" name="custom4val" class="form-control" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"
<?php if (isset($custom4)){ ?>value="<?php echo $custom4; ?>"<?php } ?>>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="box box-warning">
<div class="box-header with-border">
<h1 class="box-title">Interface listening behavior</h1>
</div>
<div class="box-body">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<div>
<input type="radio" name="DNSinterface" id="DNSinterface1" value="local"
<?php if ($DNSinterface == "local"){ ?>checked<?php } ?>>
<label for="DNSinterface1"><strong>Listen on all interfaces</strong><br>Allows only queries from devices that are at most one hop away (local devices)</label>
</div>
<div>
<input type="radio" name="DNSinterface" id="DNSinterface2" value="single"
<?php if ($DNSinterface == "single"){ ?>checked<?php } ?>>
<label for="DNSinterface2"><strong>Listen only on interface <?php echo htmlentities($piHoleInterface); ?></strong></label>
</div>
<div>
<input type="radio" name="DNSinterface" id="DNSinterface3" value="all"
<?php if ($DNSinterface == "all"){ ?>checked<?php } ?>>
<label for="DNSinterface3"><strong>Listen on all interfaces, permit all origins</strong></label>
</div>
</div>
<p>Note that the last option should not be used on devices which are
directly connected to the Internet. This option is safe if your
Pi-hole is located within your local network, i.e. protected behind
your router, and you have not forwarded port 53 to this device. In
virtually all other cases you have to make sure that your Pi-hole is
properly firewalled.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="box box-warning">
<div class="box-header with-border">
<h3 class="box-title">Advanced DNS settings</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-lg-12">
<div>
<input type="checkbox" name="DNSrequiresFQDN" id="DNSrequiresFQDN" title="domain-needed" <?php if ($DNSrequiresFQDN){ ?>checked<?php } ?>>
<label for="DNSrequiresFQDN"><strong>Never forward non-FQDNs</strong></label>
</div>
<div>
<input type="checkbox" name="DNSbogusPriv" id="DNSbogusPriv" title="bogus-priv" <?php if ($DNSbogusPriv){ ?>checked<?php } ?>>
<label for="DNSbogusPriv"><strong>Never forward reverse lookups for private IP ranges</strong></label>
<p>Note that enabling these two options may increase your privacy
slightly, but may also prevent you from being able to access
local hostnames if the Pi-hole is not used as DHCP server</p>
</div>
<div>
<input type="checkbox" name="DNSSEC" id="DNSSEC" <?php if ($DNSSEC){ ?>checked<?php } ?>>
<label for="DNSSEC"><strong>Use DNSSEC</strong></label>
<p>Validate DNS replies and cache DNSSEC data. When forwarding DNS
queries, Pi-hole requests the DNSSEC records needed to validate
the replies. If a domain fails validation or the upstream does not
support DNSSEC, this setting can cause issues resolving domains.
Use Google, Cloudflare, DNS.WATCH, Quad9, or another DNS
server which supports DNSSEC when activating DNSSEC. Note that
the size of your log might increase significantly
when enabling DNSSEC. A DNSSEC resolver test can be found
<a href="https://dnssec.vs.uni-due.de/" rel="noopener" target="_blank">here</a>.</p>
</div>
<p>Validate DNS replies and cache DNSSEC data. When forwarding DNS
queries, Pi-hole requests the DNSSEC records needed to validate
the replies. If a domain fails validation or the upstream does not
support DNSSEC, this setting can cause issues resolving domains.
Use Google, Cloudflare, DNS.WATCH, Quad9, or another DNS
server which supports DNSSEC when activating DNSSEC. Note that
the size of your log might increase significantly
when enabling DNSSEC. A DNSSEC resolver test can be found
<a href="https://dnssec.vs.uni-due.de/" rel="noopener" target="_blank">here</a>.</p>
<br>
<h4>Conditional forwarding</h4>
<p>If not configured as your DHCP server, Pi-hole typically won't be able to
determine the names of devices on your local network. As a
result, tables such as Top Clients will only show IP addresses.</p>
<p>One solution for this is to configure Pi-hole to forward these
requests to your DHCP server (most likely your router), but only for devices on your
home network. To configure this we will need to know the IP
address of your DHCP server and which addresses belong to your local network.
Exemplary inout is given below as placeholder in the text boxes (if empty).</p>
<p>If your local network spans 192.168.0.1 - 192.168.0.255, then you will have to input
<code>192.168.0.0/24</code>. If your local network is 192.168.47.1 - 192.168.47.255, it will
be <code>192.168.47.0/24</code> and similar. If your network is larger, the CIDR has to be