-
Notifications
You must be signed in to change notification settings - Fork 0
/
dhcp.php
200 lines (192 loc) · 6.94 KB
/
dhcp.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
<?php
require 'inc/functions.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$file = "/etc/dnsmasq.d/hsh.dns";
?>
<!doctype html>
<html lang="en">
<head>
<?php
require 'inc/header.php';
?>
</head>
<body>
<?php require 'inc/menu.php'; ?>
<main role="main" class="container">
<h1>DHCP & DNS</h1>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item active" aria-current="page">DHCP & DNS</li>
</ol>
</nav>
<?php
if( isset( $_POST['submit_edit'] ) ) {
$dns_domain = filter_var( $_POST['dns_domain'] , FILTER_SANITIZE_STRING );
$range_start = filter_var( $_POST['range_start'] , FILTER_VALIDATE_IP );
$range_end = filter_var( $_POST['range_end'] , FILTER_VALIDATE_IP );
$leasetime = filter_var( $_POST['leasetime'] , FILTER_SANITIZE_NUMBER_INT ) . "h";
$router = filter_var( $_POST['router'] , FILTER_VALIDATE_IP );
$dns = filter_var( $_POST['dns'] , FILTER_VALIDATE_IP );
$dns_cache = filter_var( $_POST['dns_cache'] , FILTER_SANITIZE_NUMBER_INT );
$editfile = fopen( $file , "w" );
$range = $range_start . "," . $range_end . "," . $leasetime;
$construct =
"
# DHCP
domain-needed
bogus-priv
domain=$dns_domain
dhcp-range=$range
dhcp-option=3,$router
dhcp-option=6,$dns
# DNS
cache-size=$dns_cache
";
fwrite( $editfile , $construct );
fclose( $editfile );
echo "<div class='alert alert-warning' role='alert'>Changes saved. You may need to restart your server to reload the changes.</div>";
}
?>
<div class="card">
<div class="card-header"><strong>Service Status:</strong></div>
<div class="card-body">
<?php
exec( "pgrep dnsmasq", $output, $return );
if( $return == 0 ) {
echo "<div class='alert alert-success' role='alert'>DNS & DNS Services are running!</div>";
} else {
echo "<div class='alert alert-danger' role='alert'>DNS & DNS Services are not running!<br />You may need to enable it using commend: <br /><br />
<span style='margin-top: 10px; padding: 5px; border: solid 1px #000;'><em>sudo systemctl enable dnsmasq & sudo systemctl start dnsmasq</em></span>
</div>";
}
$server_ip = $_SERVER['SERVER_ADDR'];
?>
</div>
</div>
<div class="card">
<div class="card-header"><strong>Current:</strong></div>
<div class="card-body">
<table width="100%" border="1">
<thead>
<tr>
<th>Setting</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<?php
$lines = file( $file );
foreach( $lines as $line ) {
$bit = explode( "=" , $line );
if( count( $bit ) == 2 ) {
// Settings
switch( $bit[0] ) {
case "domain":
echo "<tr>";
echo "<td>DNS Domain:</td>";
echo "<td>" . $bit[1] . "</td>";
$dns_domain = filter_var( $bit[1] , FILTER_SANITIZE_STRING );
echo "</tr>";
break;
case "dhcp-range":
$range_bit = explode( "," , $bit[1] );
echo "<tr><td>DHCP Range Start</td>";
echo "<td>" . $range_bit[0] . "</td></tr>";
$range_start = filter_var( $range_bit[0] , FILTER_VALIDATE_IP );
echo "<tr><td>DHCP Range End</td>";
echo "<td>" . $range_bit[1] . "</td></tr>";
$range_end = filter_var( $range_bit[1] , FILTER_VALIDATE_IP );
echo "<tr><td>DHCP Lease:</td>";
echo "<td>" . $range_bit[2] . "</td></tr>";
$leasetime = str_replace( "h" , "" , filter_var( $range_bit[2] , FILTER_SANITIZE_STRING ) );
break;
case "dhcp-option":
$option_bit = explode( "," , $bit[1] );
if( (int)$option_bit[0] == 3 ) {
echo "<tr><td>DHCP Router:</td>";
echo "<td>" . $option_bit[1] . "</td></tr>";
$router = filter_var( $option_bit[1] , FILTER_SANITIZE_STRING );
//$router = $option_bit[1];
} else if( (int)$option_bit[0] == 6 ) {
echo "<tr><td>DHCP DNS Server:</td>";
echo "<td>" . $option_bit[1] . "</td></tr>";
$dns = filter_var( $option_bit[1] , FILTER_SANITIZE_STRING );
}
break;
case "cache-size":
echo "<tr><td>DNS Cache Size:</td>";
echo "<td>" . $bit[1] . "MB</td></tr>";
$dns_cache = filter_var( $bit[1] , FILTER_SANITIZE_NUMBER_INT );
}
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><strong>Edit:</strong></div>
<div class="card-body">
<form method="post">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">DNS Domain:</span>
</div>
<input class="form-control" name="dns_domain" value="<?php echo $dns_domain; ?>">
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">DNS Cache Size:</span>
</div>
<input class="form-control" name="dns_cache" value="<?php echo $dns_cache; ?>">
<div class="input-group-append">
<span class="input-group-text">MB</span>
</div>
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">DHCP Range Start:</span>
</div>
<input placeholder="192.168.1.2" class="form-control" name="range_start" value="<?php echo $range_start; ?>">
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">DHCP Range End:</span>
</div>
<input placeholder="192.168.1.254" class="form-control" name="range_end" value="<?php echo $range_end; ?>">
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">DHCP Lease Time:</span>
</div>
<input placeholder="192.168.1.254" class="form-control" name="leasetime" value="<?php echo $leasetime; ?>">
<div class="input-group-append">
<span class="input-group-text">Hours</span>
</div>
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">DHCP Router IP:</span>
</div>
<input placeholder="192.168.1.1" class="form-control" name="router" value="<?php echo $router; ?>">
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">DHCP DNS Server:</span>
</div>
<input placeholder="192.168.1.1" class="form-control" name="dns" value="<?php echo $dns; ?>">
</div>
<br />
<button class="btn btn-success" type="submit" name="submit_edit">Save</button>
</form>
</div>
</div>
</main>
<?php require 'inc/footer.php'; ?>
</body>
</html>