Project

General

Profile

Download (15.3 KB) Statistics
| Branch: | Tag: | Revision:
1 4d875b4f Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4 b9546722 Chris Buechler
	status_dhcp_leases.php
5 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6 13d193c2 Scott Ullrich
	Copyright (C) 2004-2009 Scott Ullrich
7 5b237745 Scott Ullrich
	All rights reserved.
8 4d875b4f Scott Ullrich
9 3c4cddc7 Phil Davis
	originally part of m0n0wall (http://m0n0.ch/wall)
10 4d875b4f Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12
13 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 4d875b4f Scott Ullrich
16 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 4d875b4f Scott Ullrich
19 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22 4d875b4f Scott Ullrich
23 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
35 13d193c2 Scott Ullrich
/*
36
	pfSense_BUILDER_BINARIES:	/usr/bin/awk	/bin/cat	/usr/sbin/arp	/usr/bin/wc	/usr/bin/grep
37
	pfSense_MODULE:	dhcpserver
38
*/
39
40 6b07c15a Matthew Grooms
##|+PRIV
41
##|*IDENT=page-status-dhcpleases
42
##|*NAME=Status: DHCP leases page
43
##|*DESCR=Allow access to the 'Status: DHCP leases' page.
44 b9546722 Chris Buechler
##|*MATCH=status_dhcp_leases.php*
45 6b07c15a Matthew Grooms
##|-PRIV
46
47 5b237745 Scott Ullrich
require("guiconfig.inc");
48 7d1e0109 Joecowboy
require_once("config.inc");
49 b63695db Scott Ullrich
50 6c07db48 Phil Davis
$pgtitle = array(gettext("Status"), gettext("DHCP leases"));
51 b32dd0a6 jim-p
$shortcut_section = "dhcp";
52 972e5568 jim-p
53
$leasesfile = "{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases";
54
55
if (($_GET['deleteip']) && (is_ipaddr($_GET['deleteip']))) {
56 f6a11dac jim-p
	/* Stop DHCPD */
57 972e5568 jim-p
	killbyname("dhcpd");
58
59 f6a11dac jim-p
	/* Read existing leases */
60 f6fef11d Phil Davis
	/* $leases_contents has the lines of the file, including the newline char at the end of each line. */
61 d579e3db smos
	$leases_contents = file($leasesfile);
62 972e5568 jim-p
	$newleases_contents = array();
63 6c07db48 Phil Davis
	$i = 0;
64 972e5568 jim-p
	while ($i < count($leases_contents)) {
65 f6a11dac jim-p
		/* Find the lease(s) we want to delete */
66 f6fef11d Phil Davis
		if ($leases_contents[$i] == "lease {$_GET['deleteip']} {\n") {
67 f6a11dac jim-p
			/* Skip to the end of the lease declaration */
68 972e5568 jim-p
			do {
69
				$i++;
70 f6fef11d Phil Davis
			} while ($leases_contents[$i] != "}\n");
71 972e5568 jim-p
		} else {
72 f6a11dac jim-p
			/* It's a line we want to keep, copy it over. */
73 972e5568 jim-p
			$newleases_contents[] = $leases_contents[$i];
74
		}
75
		$i++;
76
	}
77
78 f6a11dac jim-p
	/* Write out the new leases file */
79 972e5568 jim-p
	$fd = fopen($leasesfile, 'w');
80
	fwrite($fd, implode("\n", $newleases_contents));
81
	fclose($fd);
82
83 f6a11dac jim-p
	/* Restart DHCP Service */
84 972e5568 jim-p
	services_dhcpd_configure();
85 b9546722 Chris Buechler
	header("Location: status_dhcp_leases.php?all={$_GET['all']}");
86 972e5568 jim-p
}
87
88 b63695db Scott Ullrich
include("head.inc");
89
90 5b237745 Scott Ullrich
?>
91
92
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
93
<?php include("fbegin.inc"); ?>
94
<?php
95
96
function leasecmp($a, $b) {
97 fff9ee45 Phil Davis
	return strcmp($a[$_GET['order']], $b[$_GET['order']]);
98 5742ca5e Scott Ullrich
}
99
100
function adjust_gmt($dt) {
101 fff9ee45 Phil Davis
	global $config;
102 e085eba5 Joecowboy
	$dhcpd = $config['dhcpd'];
103 d8b37f91 Renato Botelho
	foreach ($dhcpd as $dhcpditem) {
104
		$dhcpleaseinlocaltime = $dhcpditem['dhcpleaseinlocaltime'];
105 42b0c921 Phil Davis
		if ($dhcpleaseinlocaltime == "yes") {
106 df321263 Joecowboy
			break;
107 42b0c921 Phil Davis
		}
108 df321263 Joecowboy
	}
109 e085eba5 Joecowboy
	if ($dhcpleaseinlocaltime == "yes") {
110 d8b37f91 Renato Botelho
		$ts = strtotime($dt . " GMT");
111 39894ed4 Phil Davis
		if ($ts !== false) {
112
			return strftime("%Y/%m/%d %I:%M:%S%p", $ts);
113
		}
114
	}
115
	/* If we did not need to convert to local time or the conversion failed, just return the input. */
116
	return $dt;
117 5b237745 Scott Ullrich
}
118
119 6c07db48 Phil Davis
function remove_duplicate($array, $field) {
120 42b0c921 Phil Davis
	foreach ($array as $sub) {
121 fff9ee45 Phil Davis
		$cmp[] = $sub[$field];
122 42b0c921 Phil Davis
	}
123 6c07db48 Phil Davis
	$unique = array_unique(array_reverse($cmp, true));
124 42b0c921 Phil Davis
	foreach ($unique as $k => $rien) {
125 fff9ee45 Phil Davis
		$new[] = $array[$k];
126 42b0c921 Phil Davis
	}
127 fff9ee45 Phil Davis
	return $new;
128 5b237745 Scott Ullrich
}
129
130 428d20c4 Seth Mos
$awk = "/usr/bin/awk";
131
/* this pattern sticks comments into a single array item */
132
$cleanpattern = "'{ gsub(\"#.*\", \"\");} { gsub(\";\", \"\"); print;}'";
133
/* We then split the leases file by } */
134 b4f7282c Seth Mos
$splitpattern = "'BEGIN { RS=\"}\";} {for (i=1; i<=NF; i++) printf \"%s \", \$i; printf \"}\\n\";}'";
135 5b237745 Scott Ullrich
136 428d20c4 Seth Mos
/* stuff the leases file in a proper format into a array by line */
137 13d193c2 Scott Ullrich
exec("/bin/cat {$leasesfile} | {$awk} {$cleanpattern} | {$awk} {$splitpattern}", $leases_content);
138 428d20c4 Seth Mos
$leases_count = count($leases_content);
139 468b0d65 Seth Mos
exec("/usr/sbin/arp -an", $rawdata);
140 6ccefb28 jim-p
$arpdata_ip = array();
141
$arpdata_mac = array();
142 468b0d65 Seth Mos
foreach ($rawdata as $line) {
143 6c07db48 Phil Davis
	$elements = explode(' ', $line);
144 468b0d65 Seth Mos
	if ($elements[3] != "(incomplete)") {
145
		$arpent = array();
146 6c07db48 Phil Davis
		$arpdata_ip[] = trim(str_replace(array('(', ')'), '', $elements[1]));
147 6ccefb28 jim-p
		$arpdata_mac[] = strtolower(trim($elements[3]));
148 468b0d65 Seth Mos
	}
149
}
150 d579e3db smos
unset($rawdata);
151 428d20c4 Seth Mos
$pools = array();
152 5b237745 Scott Ullrich
$leases = array();
153
$i = 0;
154 b4f7282c Seth Mos
$l = 0;
155
$p = 0;
156 5b237745 Scott Ullrich
157
// Put everything together again
158 42b0c921 Phil Davis
foreach ($leases_content as $lease) {
159 428d20c4 Seth Mos
	/* split the line by space */
160 d579e3db smos
	$data = explode(" ", $lease);
161 428d20c4 Seth Mos
	/* walk the fields */
162
	$f = 0;
163
	$fcount = count($data);
164 73a96698 Phil Davis
	/* with less than 20 fields there is nothing useful */
165 42b0c921 Phil Davis
	if ($fcount < 20) {
166 b4f7282c Seth Mos
		$i++;
167
		continue;
168
	}
169 6c07db48 Phil Davis
	while ($f < $fcount) {
170 42b0c921 Phil Davis
		switch ($data[$f]) {
171 b4f7282c Seth Mos
			case "failover":
172 97752da5 jim-p
				$pools[$p]['name'] = trim($data[$f+2], '"');
173
				$pools[$p]['name'] = "{$pools[$p]['name']} (" . convert_friendly_interface_to_friendly_descr(substr($pools[$p]['name'], 5)) . ")";
174 b4f7282c Seth Mos
				$pools[$p]['mystate'] = $data[$f+7];
175
				$pools[$p]['peerstate'] = $data[$f+14];
176
				$pools[$p]['mydate'] = $data[$f+10];
177
				$pools[$p]['mydate'] .= " " . $data[$f+11];
178
				$pools[$p]['peerdate'] = $data[$f+17];
179
				$pools[$p]['peerdate'] .= " " . $data[$f+18];
180
				$p++;
181
				$i++;
182
				continue 3;
183
			case "lease":
184
				$leases[$l]['ip'] = $data[$f+1];
185
				$leases[$l]['type'] = "dynamic";
186
				$f = $f+2;
187
				break;
188
			case "starts":
189
				$leases[$l]['start'] = $data[$f+2];
190
				$leases[$l]['start'] .= " " . $data[$f+3];
191
				$f = $f+3;
192
				break;
193
			case "ends":
194 39894ed4 Phil Davis
				if ($data[$f+1] == "never") {
195
					// Quote from dhcpd.leases(5) man page:
196
					// If a lease will never expire, date is never instead of an actual date.
197
					$leases[$l]['end'] = gettext("Never");
198
					$f = $f+1;
199
				} else {
200
					$leases[$l]['end'] = $data[$f+2];
201
					$leases[$l]['end'] .= " " . $data[$f+3];
202
					$f = $f+3;
203
				}
204 b4f7282c Seth Mos
				break;
205
			case "tstp":
206
				$f = $f+3;
207
				break;
208
			case "tsfp":
209
				$f = $f+3;
210
				break;
211
			case "atsfp":
212
				$f = $f+3;
213
				break;
214
			case "cltt":
215
				$f = $f+3;
216
				break;
217
			case "binding":
218 42b0c921 Phil Davis
				switch ($data[$f+2]) {
219 b4f7282c Seth Mos
					case "active":
220
						$leases[$l]['act'] = "active";
221 428d20c4 Seth Mos
						break;
222 b4f7282c Seth Mos
					case "free":
223
						$leases[$l]['act'] = "expired";
224
						$leases[$l]['online'] = "offline";
225 428d20c4 Seth Mos
						break;
226 b4f7282c Seth Mos
					case "backup":
227
						$leases[$l]['act'] = "reserved";
228
						$leases[$l]['online'] = "offline";
229 428d20c4 Seth Mos
						break;
230
				}
231 b4f7282c Seth Mos
				$f = $f+1;
232
				break;
233
			case "next":
234
				/* skip the next binding statement */
235
				$f = $f+3;
236
				break;
237 dc073abd jim-p
			case "rewind":
238 042578fd jim-p
				/* skip the rewind binding statement */
239 dc073abd jim-p
				$f = $f+3;
240
				break;
241 b4f7282c Seth Mos
			case "hardware":
242
				$leases[$l]['mac'] = $data[$f+2];
243
				/* check if it's online and the lease is active */
244 6ccefb28 jim-p
				if (in_array($leases[$l]['ip'], $arpdata_ip)) {
245 468b0d65 Seth Mos
					$leases[$l]['online'] = 'online';
246
				} else {
247
					$leases[$l]['online'] = 'offline';
248 14cf741d Scott Ullrich
				}
249 b4f7282c Seth Mos
				$f = $f+2;
250
				break;
251
			case "client-hostname":
252 42b0c921 Phil Davis
				if ($data[$f+1] <> "") {
253 6c07db48 Phil Davis
					$leases[$l]['hostname'] = preg_replace('/"/', '', $data[$f+1]);
254 b4f7282c Seth Mos
				} else {
255
					$hostname = gethostbyaddr($leases[$l]['ip']);
256 42b0c921 Phil Davis
					if ($hostname <> "") {
257 b4f7282c Seth Mos
						$leases[$l]['hostname'] = $hostname;
258
					}
259
				}
260
				$f = $f+1;
261
				break;
262
			case "uid":
263
				$f = $f+1;
264
				break;
265 14cf741d Scott Ullrich
		}
266 428d20c4 Seth Mos
		$f++;
267 14cf741d Scott Ullrich
	}
268 b4f7282c Seth Mos
	$l++;
269 428d20c4 Seth Mos
	$i++;
270 d579e3db smos
	/* slowly chisel away at the source array */
271
	array_shift($leases_content);
272 5b237745 Scott Ullrich
}
273 d579e3db smos
/* remove the old array */
274
unset($lease_content);
275 428d20c4 Seth Mos
276
/* remove duplicate items by mac address */
277 42b0c921 Phil Davis
if (count($leases) > 0) {
278 6c07db48 Phil Davis
	$leases = remove_duplicate($leases, "ip");
279 9255cbc5 Seth Mos
}
280 b4f7282c Seth Mos
281 42b0c921 Phil Davis
if (count($pools) > 0) {
282 6c07db48 Phil Davis
	$pools = remove_duplicate($pools, "name");
283 9255cbc5 Seth Mos
	asort($pools);
284
}
285 428d20c4 Seth Mos
286 42b0c921 Phil Davis
foreach ($config['interfaces'] as $ifname => $ifarr) {
287 fff9ee45 Phil Davis
	if (is_array($config['dhcpd'][$ifname]) &&
288 42b0c921 Phil Davis
	    is_array($config['dhcpd'][$ifname]['staticmap'])) {
289 f5bea142 Phil Davis
		$staticmap_array_index = 0;
290 42b0c921 Phil Davis
		foreach ($config['dhcpd'][$ifname]['staticmap'] as $static) {
291 9252431c Scott Ullrich
			$slease = array();
292
			$slease['ip'] = $static['ipaddr'];
293
			$slease['type'] = "static";
294
			$slease['mac'] = $static['mac'];
295 f5bea142 Phil Davis
			$slease['if'] = $ifname;
296 aedd7929 jim-p
			$slease['start'] = "";
297
			$slease['end'] = "";
298 08cf5428 Scott Ullrich
			$slease['hostname'] = htmlentities($static['hostname']);
299 9252431c Scott Ullrich
			$slease['act'] = "static";
300 6ccefb28 jim-p
			$slease['online'] = in_array(strtolower($slease['mac']), $arpdata_mac) ? 'online' : 'offline';
301 f5bea142 Phil Davis
			$slease['staticmap_array_index'] = $staticmap_array_index;
302 9252431c Scott Ullrich
			$leases[] = $slease;
303 f5bea142 Phil Davis
			$staticmap_array_index++;
304 9252431c Scott Ullrich
		}
305
	}
306
}
307 5b237745 Scott Ullrich
308 42b0c921 Phil Davis
if ($_GET['order']) {
309 5b237745 Scott Ullrich
	usort($leases, "leasecmp");
310 42b0c921 Phil Davis
}
311 428d20c4 Seth Mos
312
/* only print pool status when we have one */
313 42b0c921 Phil Davis
if (count($pools) > 0) {
314 5b237745 Scott Ullrich
?>
315 2871ce84 Colin Fleming
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="dhcp leases">
316 42b0c921 Phil Davis
	<tr>
317
		<td class="listhdrr"><?=gettext("Failover Group"); ?></a></td>
318
		<td class="listhdrr"><?=gettext("My State"); ?></a></td>
319
		<td class="listhdrr"><?=gettext("Since"); ?></a></td>
320
		<td class="listhdrr"><?=gettext("Peer State"); ?></a></td>
321
		<td class="listhdrr"><?=gettext("Since"); ?></a></td>
322
	</tr>
323 428d20c4 Seth Mos
<?php
324 42b0c921 Phil Davis
	foreach ($pools as $data) {
325
		echo "<tr>\n";
326
		echo "<td class=\"listlr\">{$fspans}{$data['name']}{$fspane}</td>\n";
327
		echo "<td class=\"listr\">{$fspans}{$data['mystate']}{$fspane}</td>\n";
328
		echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['mydate']) . "{$fspane}</td>\n";
329
		echo "<td class=\"listr\">{$fspans}{$data['peerstate']}{$fspane}</td>\n";
330
		echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['peerdate']) . "{$fspane}</td>\n";
331
		echo "<td class=\"list\" valign=\"middle\" width=\"17\">&nbsp;</td>\n";
332
		echo "<td class=\"list\" valign=\"middle\" width=\"17\">&nbsp;</td>\n";
333
		echo "</tr>\n";
334
	}
335 428d20c4 Seth Mos
?>
336
</table>
337
338
<?php
339
/* only print pool status when we have one */
340
}
341
?>
342
343 2871ce84 Colin Fleming
<br/>
344 428d20c4 Seth Mos
345 2871ce84 Colin Fleming
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="dhcp leases">
346 42b0c921 Phil Davis
	<tr>
347
		<td class="listhdrr"><a href="#"><?=gettext("IP address"); ?></a></td>
348
		<td class="listhdrr"><a href="#"><?=gettext("MAC address"); ?></a></td>
349
		<td class="listhdrr"><a href="#"><?=gettext("Hostname"); ?></a></td>
350
		<td class="listhdrr"><a href="#"><?=gettext("Start"); ?></a></td>
351
		<td class="listhdrr"><a href="#"><?=gettext("End"); ?></a></td>
352
		<td class="listhdrr"><a href="#"><?=gettext("Online"); ?></a></td>
353
		<td class="listhdrr"><a href="#"><?=gettext("Lease Type"); ?></a></td>
354 5b237745 Scott Ullrich
	</tr>
355
<?php
356 57f2840e Evgeny
// Load MAC-Manufacturer table
357
$mac_man = load_mac_manufacturer_table();
358 5b237745 Scott Ullrich
foreach ($leases as $data) {
359 4199bda9 Will Boyce
	if (($data['act'] == "active") || ($data['act'] == "static" && !empty($data['ip'])) || ($_GET['all'] == 1)) {
360 9252431c Scott Ullrich
		if ($data['act'] != "active" && $data['act'] != "static") {
361 5b237745 Scott Ullrich
			$fspans = "<span class=\"gray\">";
362 2871ce84 Colin Fleming
			$fspane = "&nbsp;</span>";
363 5b237745 Scott Ullrich
		} else {
364 2871ce84 Colin Fleming
			$fspans = "";
365
			$fspane = "&nbsp;";
366 5b237745 Scott Ullrich
		}
367 fff9ee45 Phil Davis
		$lip = ip2ulong($data['ip']);
368 f5bea142 Phil Davis
		if ($data['act'] != "static") {
369 8d8f0090 jim-p
			foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) {
370 42b0c921 Phil Davis
				if (!is_array($dhcpifconf['range'])) {
371 8d8f0090 jim-p
					continue;
372 42b0c921 Phil Davis
				}
373 fff9ee45 Phil Davis
				if (($lip >= ip2ulong($dhcpifconf['range']['from'])) && ($lip <= ip2ulong($dhcpifconf['range']['to']))) {
374
					$data['if'] = $dhcpif;
375
					break;
376
				}
377 49878b9e Phil Davis
				// Check if the IP is in the range of any DHCP pools
378
				if (is_array($dhcpifconf['pool'])) {
379
					foreach ($dhcpifconf['pool'] as $dhcppool) {
380
						if (is_array($dhcppool['range'])) {
381
							if (($lip >= ip2ulong($dhcppool['range']['from'])) && ($lip <= ip2ulong($dhcppool['range']['to']))) {
382
								$data['if'] = $dhcpif;
383
								break 2;
384
							}
385
						}
386
					}
387
				}
388 5b2177e4 Scott Ullrich
			}
389 fff9ee45 Phil Davis
		}
390 5b237745 Scott Ullrich
		echo "<tr>\n";
391 fff9ee45 Phil Davis
		echo "<td class=\"listlr\">{$fspans}{$data['ip']}{$fspane}</td>\n";
392
		$mac=$data['mac'];
393 57f2840e Evgeny
		$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
394 fff9ee45 Phil Davis
		if ($data['online'] != "online") {
395 42b0c921 Phil Davis
			if (isset($mac_man[$mac_hi])) { // Manufacturer for this MAC is defined
396 fff9ee45 Phil Davis
				echo "<td class=\"listr\">{$fspans}<a href=\"services_wol.php?if={$data['if']}&amp;mac=$mac\" title=\"" . gettext("$mac - send Wake on LAN packet to this MAC address") ."\">{$mac}</a><br /><font size=\"-2\"><i>{$mac_man[$mac_hi]}</i></font>{$fspane}</td>\n";
397
			} else {
398
				echo "<td class=\"listr\">{$fspans}<a href=\"services_wol.php?if={$data['if']}&amp;mac={$data['mac']}\" title=\"" . gettext("send Wake on LAN packet to this MAC address") ."\">{$data['mac']}</a>{$fspane}</td>\n";
399 57f2840e Evgeny
			}
400 fff9ee45 Phil Davis
		} else {
401 42b0c921 Phil Davis
			if (isset($mac_man[$mac_hi])) { // Manufacturer for this MAC is defined
402 2871ce84 Colin Fleming
				echo "<td class=\"listr\">{$fspans}{$mac}<br /><font size=\"-2\"><i>{$mac_man[$mac_hi]}</i></font>{$fspane}</td>\n";
403 fff9ee45 Phil Davis
			} else {
404
				echo "<td class=\"listr\">{$fspans}{$data['mac']}{$fspane}</td>\n";
405 57f2840e Evgeny
			}
406 fff9ee45 Phil Davis
		}
407 6c07db48 Phil Davis
		echo "<td class=\"listr\">{$fspans}" . htmlentities($data['hostname']) . "{$fspane}</td>\n";
408 fff9ee45 Phil Davis
		if ($data['type'] != "static") {
409
			echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['start']) . "{$fspane}</td>\n";
410
			echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['end']) . "{$fspane}</td>\n";
411
		} else {
412
			echo "<td class=\"listr\">{$fspans} n/a {$fspane}</td>\n";
413
			echo "<td class=\"listr\">{$fspans} n/a {$fspane}</td>\n";
414
		}
415
		echo "<td class=\"listr\">{$fspans}{$data['online']}{$fspane}</td>\n";
416
		echo "<td class=\"listr\">{$fspans}{$data['act']}{$fspane}</td>\n";
417
		echo "<td valign=\"middle\">&nbsp;";
418 9252431c Scott Ullrich
		if ($data['type'] == "dynamic") {
419 2871ce84 Colin Fleming
			echo "<a href=\"services_dhcp_edit.php?if={$data['if']}&amp;mac={$data['mac']}&amp;hostname={$data['hostname']}\">";
420
			echo "<img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"" . gettext("add a static mapping for this MAC address") ."\" alt=\"add\" /></a>&nbsp;\n";
421 9252431c Scott Ullrich
		} else {
422 f5bea142 Phil Davis
			echo "<a href=\"services_dhcp_edit.php?if={$data['if']}&amp;id={$data['staticmap_array_index']}\">";
423 73a96698 Phil Davis
			echo "<img src=\"/themes/{$g['theme']}/images/icons/icon_e.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"" . gettext("edit the static mapping for this entry") ."\" alt=\"add\" />&nbsp;\n";
424 9252431c Scott Ullrich
		}
425
426 fff9ee45 Phil Davis
		echo "<a href=\"services_wol_edit.php?if={$data['if']}&amp;mac={$data['mac']}&amp;descr={$data['hostname']}\">";
427 2871ce84 Colin Fleming
		echo "<img src=\"/themes/{$g['theme']}/images/icons/icon_wol_all.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"" . gettext("add a Wake on LAN mapping for this MAC address") ."\" alt=\"add\" /></a>&nbsp;\n";
428 f6a11dac jim-p
429
		/* Only show the button for offline dynamic leases */
430
		if (($data['type'] == "dynamic") && ($data['online'] != "online")) {
431 2871ce84 Colin Fleming
			echo "<a href=\"status_dhcp_leases.php?deleteip={$data['ip']}&amp;all=" . htmlspecialchars($_GET['all']) . "\">";
432
			echo "<img src=\"/themes/{$g['theme']}/images/icons/icon_x.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"" . gettext("delete this DHCP lease") . "\" alt=\"delete\" /></a>&nbsp;\n";
433 f6a11dac jim-p
		}
434 fff9ee45 Phil Davis
	echo "</td></tr>\n";
435 5b237745 Scott Ullrich
	}
436
}
437 428d20c4 Seth Mos
438 5b237745 Scott Ullrich
?>
439
</table>
440 2871ce84 Colin Fleming
<br/>
441 3ae16b9b Colin Fleming
<form action="status_dhcp_leases.php" method="get">
442 42b0c921 Phil Davis
	<input type="hidden" name="order" value="<?=htmlspecialchars($_GET['order']);?>" />
443 5b237745 Scott Ullrich
<?php if ($_GET['all']): ?>
444 42b0c921 Phil Davis
	<input type="hidden" name="all" value="0" />
445
	<input type="submit" class="formbtn" value="<?=gettext("Show active and static leases only"); ?>" />
446 5b237745 Scott Ullrich
<?php else: ?>
447 42b0c921 Phil Davis
	<input type="hidden" name="all" value="1" />
448
	<input type="submit" class="formbtn" value="<?=gettext("Show all configured leases"); ?>" />
449 5b237745 Scott Ullrich
<?php endif; ?>
450
</form>
451 42b0c921 Phil Davis
<?php if ($leases == 0): ?>
452 f75d8a89 Carlos Eduardo Ramos
<p><strong><?=gettext("No leases file found. Is the DHCP server active"); ?>?</strong></p>
453 5b237745 Scott Ullrich
<?php endif; ?>
454 fda1fdae Scott Ullrich
455 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
456
</body>
457
</html>