-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns.php
102 lines (66 loc) · 27.3 KB
/
dns.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
<?php
header('Content-Type: text/plain');
$ip = $_GET['ip'];
$hostname = $_GET['hostname'];
$fqdn = $_GET['fqdn'];
//$directory = "/tmp/etc/dnsmasq/hosts/";
$directory = "/jffs/www/dhosts";
function reloadDNSmasq() {
//create reload.dnsmasq file
$runReload = fopen("/tmp/reload.dnsmasq",'w');
fclose($runReload);
}
if (!isset($hostname)) {
$hostname = ' ';
}
if (isset($ip,$hostname,$fqdn)) {
$file = "$directory/$ip";
$current = "$ip $hostname $fqdn";
//create the hosts file
$nhost = fopen($file,'w');
fwrite($nhost,$current);
fclose($nhost);
reloadDNSmasq();
} else {
header('Content-Type: text/html; charset=utf-8');
echo ('<h2>');
echo ('<form action="dns.php" method="post">');
echo ('<label class="heading">Select a entry to be deleted:</label><br>');
foreach(scandir($directory) as $item){
if (!($item == '.')) {
if (!($item == '..')) {
if (!($item == 'reload.dnsmasq')) {
//echo ("<p><span>•</span> ".$item."<br>");
if (!($item == 'hosts')) {
echo ("<input type='checkbox' name='check_list[]' value=".$item."><label>".$item."</label> ");
} else {
echo ("<p><span>•</span> ".$item."<br>");
}
$file = "$directory/$item";
$myfile = fopen($file, "r");
while(!feof($myfile)) {
echo "<small>" . fgets($myfile) . "</small><br>";
}
fclose($myfile);
}}}}
echo ('<input type="submit" name="submit" Value="Delete"/>');
echo ('</h2>');
}
if(isset($_POST['submit'])){
if(!empty($_POST['check_list'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['check_list']);
echo "Following ".$checked_count." entries were deleted: <br/>";
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_list'] as $selected) {
echo "<p><span>•</span>".$selected."</p>";
unlink( $directory . '/' . $selected );
}
reloadDNSmasq();
echo "<br/><b>Note :</b> <span>In a few moments the dnsmasq will be reloaded and the entries above will not be responding anymore.</span>";
echo "<meta http-equiv='refresh' content='3' />";
} else {
echo "<b>Please select atleast one entry to be deleted.</b>";
}
}
?>