Project

General

Profile

Download (17.4 KB) Statistics
| Branch: | Tag: | Revision:
1 c1640267 Seth Mos
<?php
2
/* $Id$ */
3
/*
4
	status_dhcpv6_leases.php
5
	Copyright (C) 2004-2009 Scott Ullrich
6
	Copyright (C) 2011 Seth Mos
7
	All rights reserved.
8
9
	originially part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18
19
	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
23
	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
/*
36 9d539cb5 jim-p
	pfSense_BUILDER_BINARIES:	/usr/bin/awk	/bin/cat	/usr/sbin/ndp	/usr/bin/wc	/usr/bin/grep
37 c1640267 Seth Mos
	pfSense_MODULE:	dhcpserver
38
*/
39
40
##|+PRIV
41
##|*IDENT=page-status-dhcpv6leases
42
##|*NAME=Status: DHCPv6 leases page
43
##|*DESCR=Allow access to the 'Status: DHCPv6 leases' page.
44
##|*MATCH=status_dhcpv6_leases.php*
45
##|-PRIV
46
47
require("guiconfig.inc");
48 468618f0 Joecowboy
require_once("config.inc");
49 c1640267 Seth Mos
50
$pgtitle = array(gettext("Status"),gettext("DHCPv6 leases"));
51 b32dd0a6 jim-p
$shortcut_section = "dhcp6";
52 c1640267 Seth Mos
53
$leasesfile = "{$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases";
54
55
if (($_GET['deleteip']) && (is_ipaddr($_GET['deleteip']))) {
56
	/* Stop DHCPD */
57
	killbyname("dhcpd");
58
59
	/* Read existing leases */
60
	$leases_contents = explode("\n", file_get_contents($leasesfile));
61
	$newleases_contents = array();
62
	$i=0;
63
	while ($i < count($leases_contents)) {
64
		/* Find the lease(s) we want to delete */
65 20df6ed7 jim-p
		if ($leases_contents[$i] == "  iaaddr {$_GET['deleteip']} {") {
66
			/* The iaaddr line is two lines down from the start of the lease, so remove those two lines. */
67
			array_pop($newleases_contents);
68
			array_pop($newleases_contents);
69 c1640267 Seth Mos
			/* Skip to the end of the lease declaration */
70
			do {
71
				$i++;
72
			} while ($leases_contents[$i] != "}");
73
		} else {
74
			/* It's a line we want to keep, copy it over. */
75
			$newleases_contents[] = $leases_contents[$i];
76
		}
77
		$i++;
78
	}
79
80
	/* Write out the new leases file */
81
	$fd = fopen($leasesfile, 'w');
82
	fwrite($fd, implode("\n", $newleases_contents));
83
	fclose($fd);
84
85
	/* Restart DHCP Service */
86
	services_dhcpd_configure();
87
	header("Location: status_dhcpv6_leases.php?all={$_GET['all']}");
88
}
89
90
include("head.inc");
91
92
?>
93
94
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
95
<?php include("fbegin.inc"); ?>
96
<?php
97
98
function leasecmp($a, $b) {
99 a4dd274b jim-p
	return strcmp($a[$_GET['order']], $b[$_GET['order']]);
100 c1640267 Seth Mos
}
101
102
function adjust_gmt($dt) {
103 f6bda83c jim-p
	global $config;
104 ee0f23b4 Joecowboy
	$dhcpdv6 = $config['dhcpdv6'];
105
	foreach ($dhcpdv6 as $dhcpv6leaseinlocaltime) {
106
		$dhcpv6leaseinlocaltime = $dhcpv6leaseinlocaltime['dhcpv6leaseinlocaltime'];
107 f6bda83c jim-p
		if ($dhcpv6leaseinlocaltime == "yes")
108 ee0f23b4 Joecowboy
			break;
109
	}
110 f6bda83c jim-p
	$timezone = $config['system']['timezone'];
111 a4dd274b jim-p
	$ts = strtotime($dt . " GMT");
112 ee0f23b4 Joecowboy
	if ($dhcpv6leaseinlocaltime == "yes") {
113 f6bda83c jim-p
		$this_tz = new DateTimeZone($timezone);
114
		$dhcp_lt = new DateTime(strftime("%I:%M:%S%p", $ts), $this_tz);
115 468618f0 Joecowboy
		$offset = $this_tz->getOffset($dhcp_lt);
116
		$ts = $ts + $offset;
117
		return strftime("%Y/%m/%d %I:%M:%S%p", $ts);
118 f6bda83c jim-p
	}
119 468618f0 Joecowboy
	else
120
		return strftime("%Y/%m/%d %H:%M:%S", $ts);
121 c1640267 Seth Mos
}
122
123 a4dd274b jim-p
function remove_duplicate($array, $field) {
124
	foreach ($array as $sub)
125
		$cmp[] = $sub[$field];
126
	$unique = array_unique(array_reverse($cmp,true));
127
	foreach ($unique as $k => $rien)
128
		$new[] = $array[$k];
129
	return $new;
130
}
131
132
function parse_duid($duid_string) {
133
	$parsed_duid = array();
134
	for ($i=0; $i < strlen($duid_string); $i++) {
135
		$s = substr($duid_string, $i, 1);
136
		if ($s == '\\') {
137
			$n = substr($duid_string, $i+1, 1);
138
			if (($n == '\\') || ($n == '"')) {
139
				$parsed_duid[] = sprintf("%02x", ord($n));
140
			} elseif (is_numeric($n)) {
141
				$parsed_duid[] = sprintf("%02x", octdec(substr($duid_string, $i+1, 3)));
142
				$i += 3;
143
			}
144
		} else {
145
			$parsed_duid[] = sprintf("%02x", ord($s));
146
		}
147
	}
148 f393a514 jim-p
	$iaid = array_slice($parsed_duid, 0, 4);
149
	$duid = array_slice($parsed_duid, 4);
150
	return array($iaid, $duid);
151 c1640267 Seth Mos
}
152
153
$awk = "/usr/bin/awk";
154 ffdcbeb6 jim-p
155 c1640267 Seth Mos
/* this pattern sticks comments into a single array item */
156 0f03ae0f jim-p
$cleanpattern = "'{ gsub(\"^#.*\", \"\");} { gsub(\"^server-duid.*\", \"\");} { gsub(\";$\", \"\"); print;}'";
157 c1640267 Seth Mos
/* We then split the leases file by } */
158
$splitpattern = "'BEGIN { RS=\"}\";} {for (i=1; i<=NF; i++) printf \"%s \", \$i; printf \"}\\n\";}'";
159
160
/* stuff the leases file in a proper format into a array by line */
161 f6bda83c jim-p
exec("/bin/cat {$leasesfile} | {$awk} {$cleanpattern} | {$awk} {$splitpattern} | /usr/bin/grep '^ia-.. '", $leases_content);
162 c1640267 Seth Mos
$leases_count = count($leases_content);
163 bcb24b81 jim-p
exec("/usr/sbin/ndp -an", $rawdata);
164 9d539cb5 jim-p
$ndpdata = array();
165 c1640267 Seth Mos
foreach ($rawdata as $line) {
166 bcb24b81 jim-p
	$elements = preg_split('/\s+/ ',$line);
167
	if ($elements[1] != "(incomplete)") {
168 9d539cb5 jim-p
		$ndpent = array();
169 2fdc8262 jim-p
		$ip = trim(str_replace(array('(',')'),'',$elements[0]));
170 9d539cb5 jim-p
		$ndpent['mac'] = trim($elements[1]);
171
		$ndpent['interface'] = trim($elements[2]);
172
		$ndpdata[$ip] = $ndpent;
173 c1640267 Seth Mos
	}
174
}
175
176
$pools = array();
177
$leases = array();
178 f6bda83c jim-p
$prefixes = array();
179
$mappings = array();
180 c1640267 Seth Mos
$i = 0;
181
$l = 0;
182
$p = 0;
183
184
// Put everything together again
185
while($i < $leases_count) {
186 f6bda83c jim-p
	$entry = array();
187 c1640267 Seth Mos
	/* split the line by space */
188 a4dd274b jim-p
	$duid_split = array();
189 f6bda83c jim-p
	preg_match('/ia-.. "(.*)" { (.*)/ ', $leases_content[$i], $duid_split);
190 a4dd274b jim-p
	if (!empty($duid_split[1])) {
191 f393a514 jim-p
		$iaid_duid = parse_duid($duid_split[1]);
192 f6bda83c jim-p
		$entry['iaid'] = hexdec(implode("", array_reverse($iaid_duid[0])));
193
		$entry['duid'] = implode(":", $iaid_duid[1]);
194 a4dd274b jim-p
		$data = explode(" ", $duid_split[2]);
195
	} else {
196
		$data = explode(" ", $leases_content[$i]);
197
	}
198 c1640267 Seth Mos
	/* walk the fields */
199
	$f = 0;
200
	$fcount = count($data);
201 a4dd274b jim-p
	/* with less then 12 fields there is nothing useful */
202
	if($fcount < 12) {
203 c1640267 Seth Mos
		$i++;
204
		continue;
205
	}
206
	while($f < $fcount) {
207
		switch($data[$f]) {
208
			case "failover":
209
				$pools[$p]['name'] = $data[$f+2];
210
				$pools[$p]['mystate'] = $data[$f+7];
211
				$pools[$p]['peerstate'] = $data[$f+14];
212
				$pools[$p]['mydate'] = $data[$f+10];
213
				$pools[$p]['mydate'] .= " " . $data[$f+11];
214
				$pools[$p]['peerdate'] = $data[$f+17];
215
				$pools[$p]['peerdate'] .= " " . $data[$f+18];
216
				$p++;
217
				$i++;
218
				continue 3;
219 f6bda83c jim-p
			case "ia-pd":
220
				$is_prefix = true;
221 bcb24b81 jim-p
			case "ia-na":
222 f6bda83c jim-p
				$entry['iaid'] = $tmp_iaid;
223
				$entry['duid'] = $tmp_duid;
224 c1f4af16 jim-p
				if ($data[$f+1][0] == '"') {
225
					$duid = "";
226 ffdcbeb6 jim-p
					/* FIXME: This needs a safety belt to prevent an infinite loop */
227 c1f4af16 jim-p
					while ($data[$f][strlen($data[$f])-1] != '"') {
228
						$duid .= " " . $data[$f+1];
229
						$f++;
230
					}
231 f6bda83c jim-p
					$entry['duid'] = $duid;
232 c1f4af16 jim-p
				} else {
233 f6bda83c jim-p
					$entry['duid'] = $data[$f+1];
234 c1f4af16 jim-p
				}
235 f6bda83c jim-p
				$entry['type'] = "dynamic";
236 c1640267 Seth Mos
				$f = $f+2;
237
				break;
238 bcb24b81 jim-p
			case "iaaddr":
239 f6bda83c jim-p
				$entry['ip'] = $data[$f+1];
240
				$entry['type'] = "dynamic";
241
				if (in_array($entry['ip'], array_keys($ndpdata))) {
242
					$entry['online'] = 'online';
243 c1f4af16 jim-p
				} else {
244 f6bda83c jim-p
					$entry['online'] = 'offline';
245 c1f4af16 jim-p
				}
246 bcb24b81 jim-p
				$f = $f+2;
247
				break;
248 f6bda83c jim-p
			case "iaprefix":
249
				$is_prefix = true;
250
				$entry['prefix'] = $data[$f+1];
251
				$entry['type'] = "dynamic";
252
				$f = $f+2;
253
				break;
254 c1640267 Seth Mos
			case "starts":
255 f6bda83c jim-p
				$entry['start'] = $data[$f+2];
256
				$entry['start'] .= " " . $data[$f+3];
257 c1640267 Seth Mos
				$f = $f+3;
258
				break;
259
			case "ends":
260 f6bda83c jim-p
				$entry['end'] = $data[$f+2];
261
				$entry['end'] .= " " . $data[$f+3];
262 c1640267 Seth Mos
				$f = $f+3;
263
				break;
264
			case "tstp":
265
				$f = $f+3;
266
				break;
267
			case "tsfp":
268
				$f = $f+3;
269
				break;
270
			case "atsfp":
271
				$f = $f+3;
272
				break;
273
			case "cltt":
274 f6bda83c jim-p
				$entry['start'] = $data[$f+2];
275
				$entry['start'] .= " " . $data[$f+3];
276 c1640267 Seth Mos
				$f = $f+3;
277
				break;
278
			case "binding":
279
				switch($data[$f+2]) {
280
					case "active":
281 f6bda83c jim-p
						$entry['act'] = "active";
282 c1640267 Seth Mos
						break;
283
					case "free":
284 f6bda83c jim-p
						$entry['act'] = "expired";
285
						$entry['online'] = "offline";
286 c1640267 Seth Mos
						break;
287
					case "backup":
288 f6bda83c jim-p
						$entry['act'] = "reserved";
289
						$entry['online'] = "offline";
290 c1640267 Seth Mos
						break;
291 f6bda83c jim-p
					case "released":
292
						$entry['act'] = "released";
293
						$entry['online'] = "offline";
294 c1640267 Seth Mos
				}
295
				$f = $f+1;
296
				break;
297
			case "next":
298
				/* skip the next binding statement */
299
				$f = $f+3;
300
				break;
301
			case "hardware":
302
				$f = $f+2;
303
				break;
304
			case "client-hostname":
305
				if($data[$f+1] <> "") {
306 f6bda83c jim-p
					$entry['hostname'] = preg_replace('/"/','',$data[$f+1]);
307 c1640267 Seth Mos
				} else {
308 f6bda83c jim-p
					$hostname = gethostbyaddr($entry['ip']);
309 c1640267 Seth Mos
					if($hostname <> "") {
310 f6bda83c jim-p
						$entry['hostname'] = $hostname;
311 c1640267 Seth Mos
					}
312
				}
313
				$f = $f+1;
314
				break;
315
			case "uid":
316
				$f = $f+1;
317
				break;
318
		}
319
		$f++;
320
	}
321 f6bda83c jim-p
	if ($is_prefix) {
322
		$prefixes[] = $entry;
323
	} else {
324
		$leases[] = $entry;
325
		$mappings[$entry['iaid'] . $entry['duid']] = $entry['ip'];
326
	}
327 c1640267 Seth Mos
	$l++;
328
	$i++;
329 f6bda83c jim-p
	$is_prefix = false;
330 c1640267 Seth Mos
}
331
332
if(count($leases) > 0) {
333
	$leases = remove_duplicate($leases,"ip");
334
}
335
336 f6bda83c jim-p
if(count($prefixes) > 0) {
337
	$prefixes = remove_duplicate($prefixes,"prefix");
338
}
339
340 c1640267 Seth Mos
if(count($pools) > 0) {
341
	$pools = remove_duplicate($pools,"name");
342
	asort($pools);
343
}
344
345
foreach($config['interfaces'] as $ifname => $ifarr) {
346 f6bda83c jim-p
	if (is_array($config['dhcpdv6'][$ifname]) &&
347 c1640267 Seth Mos
		is_array($config['dhcpdv6'][$ifname]['staticmap'])) {
348
		foreach($config['dhcpdv6'][$ifname]['staticmap'] as $static) {
349
			$slease = array();
350 4151bdba jim-p
			$slease['ip'] = $static['ipaddrv6'];
351 c1640267 Seth Mos
			$slease['type'] = "static";
352 4151bdba jim-p
			$slease['duid'] = $static['duid'];
353 c1640267 Seth Mos
			$slease['start'] = "";
354
			$slease['end'] = "";
355
			$slease['hostname'] = htmlentities($static['hostname']);
356
			$slease['act'] = "static";
357 9d539cb5 jim-p
			if (in_array($slease['ip'], array_keys($ndpdata))) {
358 c1640267 Seth Mos
				$slease['online'] = 'online';
359
			} else {
360
				$slease['online'] = 'offline';
361
			}
362 4e85523b jim-p
363 c1640267 Seth Mos
			$leases[] = $slease;
364
		}
365
	}
366
}
367
368
if ($_GET['order'])
369
	usort($leases, "leasecmp");
370
371
/* only print pool status when we have one */
372
if(count($pools) > 0) {
373
?>
374
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
375 f6bda83c jim-p
	<tr>
376
		<td class="listhdrr"><?=gettext("Failover Group"); ?></a></td>
377
		<td class="listhdrr"><?=gettext("My State"); ?></a></td>
378
		<td class="listhdrr"><?=gettext("Since"); ?></a></td>
379
		<td class="listhdrr"><?=gettext("Peer State"); ?></a></td>
380
		<td class="listhdrr"><?=gettext("Since"); ?></a></td>
381
	</tr>
382 c1640267 Seth Mos
<?php
383
foreach ($pools as $data) {
384
	echo "<tr>\n";
385
	echo "<td class=\"listlr\">{$fspans}{$data['name']}{$fspane}&nbsp;</td>\n";
386
	echo "<td class=\"listr\">{$fspans}{$data['mystate']}{$fspane}&nbsp;</td>\n";
387
	echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['mydate']) . "{$fspane}&nbsp;</td>\n";
388
	echo "<td class=\"listr\">{$fspans}{$data['peerstate']}{$fspane}&nbsp;</td>\n";
389
	echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['peerdate']) . "{$fspane}&nbsp;</td>\n";
390
	echo "<td class=\"list\" valign=\"middle\" width=\"17\">&nbsp;</td>\n";
391
	echo "<td class=\"list\" valign=\"middle\" width=\"17\">&nbsp;</td>\n";
392
	echo "</tr>\n";
393
}
394
395
?>
396
</table>
397
398
<?php
399
/* only print pool status when we have one */
400
}
401
?>
402
403
<p>
404
405
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
406
  <tr>
407
    <td class="listhdrr"><a href="#"><?=gettext("IPv6 address"); ?></a></td>
408 f393a514 jim-p
    <td class="listhdrr"><a href="#"><?=gettext("IAID"); ?></a></td>
409 c1f4af16 jim-p
    <td class="listhdrr"><a href="#"><?=gettext("DUID"); ?></a></td>
410 2fdc8262 jim-p
    <td class="listhdrr"><a href="#"><?=gettext("Hostname/MAC"); ?></a></td>
411 c1640267 Seth Mos
    <td class="listhdrr"><a href="#"><?=gettext("Start"); ?></a></td>
412
    <td class="listhdrr"><a href="#"><?=gettext("End"); ?></a></td>
413
    <td class="listhdrr"><a href="#"><?=gettext("Online"); ?></a></td>
414
    <td class="listhdrr"><a href="#"><?=gettext("Lease Type"); ?></a></td>
415
	</tr>
416
<?php
417
foreach ($leases as $data) {
418
	if (($data['act'] == "active") || ($data['act'] == "static") || ($_GET['all'] == 1)) {
419
		if ($data['act'] != "active" && $data['act'] != "static") {
420
			$fspans = "<span class=\"gray\">";
421
			$fspane = "</span>";
422
		} else {
423
			$fspans = $fspane = "";
424
		}
425 9c070452 jim-p
426 c1640267 Seth Mos
		if ($data['act'] == "static") {
427
			foreach ($config['dhcpdv6'] as $dhcpif => $dhcpifconf) {
428
				if(is_array($dhcpifconf['staticmap'])) {
429
					foreach ($dhcpifconf['staticmap'] as $staticent) {
430
						if ($data['ip'] == $staticent['ipaddr']) {
431
							$data['if'] = $dhcpif;
432
							break;
433
						}
434
					}
435
				}
436
				/* exit as soon as we have an interface */
437
				if ($data['if'] != "")
438
					break;
439
			}
440
		} else {
441 9c070452 jim-p
			$data['if'] = convert_real_interface_to_friendly_interface_name(guess_interface_from_ip($data['ip']));
442 f6bda83c jim-p
		}
443 c1640267 Seth Mos
		echo "<tr>\n";
444 f6bda83c jim-p
		echo "<td class=\"listlr\">{$fspans}{$data['ip']}{$fspane}&nbsp;</td>\n";
445 f393a514 jim-p
		echo "<td class=\"listr\">{$fspans}{$data['iaid']}{$fspane}&nbsp;</td>\n";
446 c1f4af16 jim-p
		echo "<td class=\"listr\">{$fspans}{$data['duid']}{$fspane}&nbsp;</td>\n";
447 2fdc8262 jim-p
		echo "<td class=\"listr\">{$fspans}";
448
		if (!empty($data['hostname'])) {
449
			echo htmlentities($data['hostname']) . "<br/>";
450
		}
451 9d539cb5 jim-p
		echo htmlentities($ndpdata[$data['ip']]['mac']);
452 2fdc8262 jim-p
		echo "{$fspane}&nbsp;</td>\n";
453 f6bda83c jim-p
		if ($data['type'] != "static") {
454
			echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['start']) . "{$fspane}&nbsp;</td>\n";
455
			echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['end']) . "{$fspane}&nbsp;</td>\n";
456
		} else {
457
			echo "<td class=\"listr\">{$fspans} n/a {$fspane}&nbsp;</td>\n";
458
			echo "<td class=\"listr\">{$fspans} n/a {$fspane}&nbsp;</td>\n";
459
		}
460
		echo "<td class=\"listr\">{$fspans}{$data['online']}{$fspane}&nbsp;</td>\n";
461
		echo "<td class=\"listr\">{$fspans}{$data['act']}{$fspane}&nbsp;</td>\n";
462
463 c1640267 Seth Mos
		if ($data['type'] == "dynamic") {
464 c1f4af16 jim-p
			echo "<td valign=\"middle\"><a href=\"services_dhcpv6_edit.php?if={$data['if']}&duid={$data['duid']}&hostname={$data['hostname']}\">";
465 c1640267 Seth Mos
			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") ."\"></a></td>\n";
466
		} else {
467 f6bda83c jim-p
			echo "<td class=\"list\" valign=\"middle\">";
468 c1640267 Seth Mos
			echo "<img src=\"/themes/{$g['theme']}/images/icons/icon_plus_mo.gif\" width=\"17\" height=\"17\" border=\"0\"></td>\n";
469
		}
470
471
		/* Only show the button for offline dynamic leases */
472
		if (($data['type'] == "dynamic") && ($data['online'] != "online")) {
473 bcb24b81 jim-p
			echo "<td class=\"list\" valign=\"middle\"><a href=\"status_dhcpv6_leases.php?deleteip={$data['ip']}&all=" . htmlspecialchars($_GET['all']) . "\">";
474 c1640267 Seth Mos
			echo "<img src=\"/themes/{$g['theme']}/images/icons/icon_x.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"" . gettext("delete this DHCP lease") . "\"></a></td>\n";
475
		}
476 f6bda83c jim-p
		echo "</tr>\n";
477 c1640267 Seth Mos
	}
478
}
479 f6bda83c jim-p
?>
480
</table>
481
<p>
482
<h3>Delegated Prefixes</h3>
483
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
484
	<tr>
485
		<td class="listhdrr"><a href="#"><?=gettext("IPv6 Prefix"); ?></a></td>
486
		<td class="listhdrr"><a href="#"><?=gettext("IAID"); ?></a></td>
487
		<td class="listhdrr"><a href="#"><?=gettext("DUID"); ?></a></td>
488
		<td class="listhdrr"><a href="#"><?=gettext("Start"); ?></a></td>
489
		<td class="listhdrr"><a href="#"><?=gettext("End"); ?></a></td>
490
		<td class="listhdrr"><a href="#"><?=gettext("State"); ?></a></td>
491
	</tr>
492
<?php
493
foreach ($prefixes as $data) {
494
	if (($data['act'] == "active") || ($data['act'] == "static") || ($_GET['all'] == 1)) {
495
		if ($data['act'] != "active" && $data['act'] != "static") {
496
			$fspans = "<span class=\"gray\">";
497
			$fspane = "</span>";
498
		} else {
499
			$fspans = $fspane = "";
500
		}
501 c1640267 Seth Mos
502 f6bda83c jim-p
		if ($data['act'] == "static") {
503
			foreach ($config['dhcpdv6'] as $dhcpif => $dhcpifconf) {
504
				if(is_array($dhcpifconf['staticmap'])) {
505
					foreach ($dhcpifconf['staticmap'] as $staticent) {
506
						if ($data['ip'] == $staticent['ipaddr']) {
507
							$data['if'] = $dhcpif;
508
							break;
509
						}
510
					}
511
				}
512
				/* exit as soon as we have an interface */
513
				if ($data['if'] != "")
514
					break;
515
			}
516
		} else {
517
			$data['if'] = convert_real_interface_to_friendly_interface_name(guess_interface_from_ip($data['ip']));
518
		}
519
		echo "<tr>\n";
520
		if ($mappings[$data['iaid'] . $data['duid']]) {
521
			$dip = "<br/>Routed To: {$mappings[$data['iaid'] . $data['duid']]}";
522
		}
523
		echo "<td class=\"listlr\">{$fspans}{$data['prefix']}{$dip}{$fspane}&nbsp;</td>\n";
524
		echo "<td class=\"listr\">{$fspans}{$data['iaid']}{$fspane}&nbsp;</td>\n";
525
		echo "<td class=\"listr\">{$fspans}{$data['duid']}{$fspane}&nbsp;</td>\n";
526
		if ($data['type'] != "static") {
527
			echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['start']) . "{$fspane}&nbsp;</td>\n";
528
			echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['end']) . "{$fspane}&nbsp;</td>\n";
529
		} else {
530
			echo "<td class=\"listr\">{$fspans} n/a {$fspane}&nbsp;</td>\n";
531
			echo "<td class=\"listr\">{$fspans} n/a {$fspane}&nbsp;</td>\n";
532
		}
533
		echo "<td class=\"listr\">{$fspans}{$data['act']}{$fspane}&nbsp;</td>\n";
534
		echo "</tr>\n";
535
	}
536
}
537 c1640267 Seth Mos
?>
538
</table>
539
<p>
540 bcb24b81 jim-p
<form action="status_dhcpv6_leases.php" method="GET">
541 c1640267 Seth Mos
<input type="hidden" name="order" value="<?=htmlspecialchars($_GET['order']);?>">
542
<?php if ($_GET['all']): ?>
543
<input type="hidden" name="all" value="0">
544
<input type="submit" class="formbtn" value="<?=gettext("Show active and static leases only"); ?>">
545
<?php else: ?>
546
<input type="hidden" name="all" value="1">
547
<input type="submit" class="formbtn" value="<?=gettext("Show all configured leases"); ?>">
548
<?php endif; ?>
549
</form>
550
<?php if($leases == 0): ?>
551
<p><strong><?=gettext("No leases file found. Is the DHCP server active"); ?>?</strong></p>
552
<?php endif; ?>
553
554
<?php include("fend.inc"); ?>
555
</body>
556
</html>