Project

General

Profile

Download (17.8 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 45630319 jim-p
// Load MAC-Manufacturer table
91
$mac_man = load_mac_manufacturer_table();
92
93 c1640267 Seth Mos
include("head.inc");
94
95
?>
96
97
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
98
<?php include("fbegin.inc"); ?>
99
<?php
100
101
function leasecmp($a, $b) {
102 a4dd274b jim-p
	return strcmp($a[$_GET['order']], $b[$_GET['order']]);
103 c1640267 Seth Mos
}
104
105
function adjust_gmt($dt) {
106 f6bda83c jim-p
	global $config;
107 628a64a9 Ermal
108
	$dhcpv6leaseinlocaltime == "no";
109
	if (is_array($config['dhcpdv6'])) {
110
		$dhcpdv6 = $config['dhcpdv6'];
111
		foreach ($dhcpdv6 as $dhcpv6leaseinlocaltime) {
112
			$dhcpv6leaseinlocaltime = $dhcpv6leaseinlocaltime['dhcpv6leaseinlocaltime'];
113
			if ($dhcpv6leaseinlocaltime == "yes")
114
				break;
115
		}
116 ee0f23b4 Joecowboy
	}
117 628a64a9 Ermal
118 f6bda83c jim-p
	$timezone = $config['system']['timezone'];
119 a4dd274b jim-p
	$ts = strtotime($dt . " GMT");
120 ee0f23b4 Joecowboy
	if ($dhcpv6leaseinlocaltime == "yes") {
121 f6bda83c jim-p
		$this_tz = new DateTimeZone($timezone);
122
		$dhcp_lt = new DateTime(strftime("%I:%M:%S%p", $ts), $this_tz);
123 468618f0 Joecowboy
		$offset = $this_tz->getOffset($dhcp_lt);
124
		$ts = $ts + $offset;
125
		return strftime("%Y/%m/%d %I:%M:%S%p", $ts);
126 f6bda83c jim-p
	}
127 468618f0 Joecowboy
	else
128
		return strftime("%Y/%m/%d %H:%M:%S", $ts);
129 c1640267 Seth Mos
}
130
131 a4dd274b jim-p
function remove_duplicate($array, $field) {
132
	foreach ($array as $sub)
133
		$cmp[] = $sub[$field];
134
	$unique = array_unique(array_reverse($cmp,true));
135
	foreach ($unique as $k => $rien)
136
		$new[] = $array[$k];
137
	return $new;
138
}
139
140
function parse_duid($duid_string) {
141
	$parsed_duid = array();
142
	for ($i=0; $i < strlen($duid_string); $i++) {
143
		$s = substr($duid_string, $i, 1);
144
		if ($s == '\\') {
145
			$n = substr($duid_string, $i+1, 1);
146
			if (($n == '\\') || ($n == '"')) {
147
				$parsed_duid[] = sprintf("%02x", ord($n));
148
			} elseif (is_numeric($n)) {
149
				$parsed_duid[] = sprintf("%02x", octdec(substr($duid_string, $i+1, 3)));
150
				$i += 3;
151
			}
152
		} else {
153
			$parsed_duid[] = sprintf("%02x", ord($s));
154
		}
155
	}
156 f393a514 jim-p
	$iaid = array_slice($parsed_duid, 0, 4);
157
	$duid = array_slice($parsed_duid, 4);
158
	return array($iaid, $duid);
159 c1640267 Seth Mos
}
160
161
$awk = "/usr/bin/awk";
162 ffdcbeb6 jim-p
163 c1640267 Seth Mos
/* this pattern sticks comments into a single array item */
164 0f03ae0f jim-p
$cleanpattern = "'{ gsub(\"^#.*\", \"\");} { gsub(\"^server-duid.*\", \"\");} { gsub(\";$\", \"\"); print;}'";
165 c1640267 Seth Mos
/* We then split the leases file by } */
166
$splitpattern = "'BEGIN { RS=\"}\";} {for (i=1; i<=NF; i++) printf \"%s \", \$i; printf \"}\\n\";}'";
167
168
/* stuff the leases file in a proper format into a array by line */
169 f6bda83c jim-p
exec("/bin/cat {$leasesfile} | {$awk} {$cleanpattern} | {$awk} {$splitpattern} | /usr/bin/grep '^ia-.. '", $leases_content);
170 c1640267 Seth Mos
$leases_count = count($leases_content);
171 bcb24b81 jim-p
exec("/usr/sbin/ndp -an", $rawdata);
172 9d539cb5 jim-p
$ndpdata = array();
173 c1640267 Seth Mos
foreach ($rawdata as $line) {
174 bcb24b81 jim-p
	$elements = preg_split('/\s+/ ',$line);
175
	if ($elements[1] != "(incomplete)") {
176 9d539cb5 jim-p
		$ndpent = array();
177 2fdc8262 jim-p
		$ip = trim(str_replace(array('(',')'),'',$elements[0]));
178 9d539cb5 jim-p
		$ndpent['mac'] = trim($elements[1]);
179
		$ndpent['interface'] = trim($elements[2]);
180
		$ndpdata[$ip] = $ndpent;
181 c1640267 Seth Mos
	}
182
}
183
184
$pools = array();
185
$leases = array();
186 f6bda83c jim-p
$prefixes = array();
187
$mappings = array();
188 c1640267 Seth Mos
$i = 0;
189
$l = 0;
190
$p = 0;
191
192
// Put everything together again
193
while($i < $leases_count) {
194 f6bda83c jim-p
	$entry = array();
195 c1640267 Seth Mos
	/* split the line by space */
196 a4dd274b jim-p
	$duid_split = array();
197 f6bda83c jim-p
	preg_match('/ia-.. "(.*)" { (.*)/ ', $leases_content[$i], $duid_split);
198 a4dd274b jim-p
	if (!empty($duid_split[1])) {
199 f393a514 jim-p
		$iaid_duid = parse_duid($duid_split[1]);
200 f6bda83c jim-p
		$entry['iaid'] = hexdec(implode("", array_reverse($iaid_duid[0])));
201
		$entry['duid'] = implode(":", $iaid_duid[1]);
202 a4dd274b jim-p
		$data = explode(" ", $duid_split[2]);
203
	} else {
204
		$data = explode(" ", $leases_content[$i]);
205
	}
206 c1640267 Seth Mos
	/* walk the fields */
207
	$f = 0;
208
	$fcount = count($data);
209 a4dd274b jim-p
	/* with less then 12 fields there is nothing useful */
210
	if($fcount < 12) {
211 c1640267 Seth Mos
		$i++;
212
		continue;
213
	}
214
	while($f < $fcount) {
215
		switch($data[$f]) {
216
			case "failover":
217
				$pools[$p]['name'] = $data[$f+2];
218
				$pools[$p]['mystate'] = $data[$f+7];
219
				$pools[$p]['peerstate'] = $data[$f+14];
220
				$pools[$p]['mydate'] = $data[$f+10];
221
				$pools[$p]['mydate'] .= " " . $data[$f+11];
222
				$pools[$p]['peerdate'] = $data[$f+17];
223
				$pools[$p]['peerdate'] .= " " . $data[$f+18];
224
				$p++;
225
				$i++;
226
				continue 3;
227 f6bda83c jim-p
			case "ia-pd":
228
				$is_prefix = true;
229 bcb24b81 jim-p
			case "ia-na":
230 f6bda83c jim-p
				$entry['iaid'] = $tmp_iaid;
231
				$entry['duid'] = $tmp_duid;
232 c1f4af16 jim-p
				if ($data[$f+1][0] == '"') {
233
					$duid = "";
234 ffdcbeb6 jim-p
					/* FIXME: This needs a safety belt to prevent an infinite loop */
235 c1f4af16 jim-p
					while ($data[$f][strlen($data[$f])-1] != '"') {
236
						$duid .= " " . $data[$f+1];
237
						$f++;
238
					}
239 f6bda83c jim-p
					$entry['duid'] = $duid;
240 c1f4af16 jim-p
				} else {
241 f6bda83c jim-p
					$entry['duid'] = $data[$f+1];
242 c1f4af16 jim-p
				}
243 f6bda83c jim-p
				$entry['type'] = "dynamic";
244 c1640267 Seth Mos
				$f = $f+2;
245
				break;
246 bcb24b81 jim-p
			case "iaaddr":
247 f6bda83c jim-p
				$entry['ip'] = $data[$f+1];
248
				$entry['type'] = "dynamic";
249
				if (in_array($entry['ip'], array_keys($ndpdata))) {
250
					$entry['online'] = 'online';
251 c1f4af16 jim-p
				} else {
252 f6bda83c jim-p
					$entry['online'] = 'offline';
253 c1f4af16 jim-p
				}
254 bcb24b81 jim-p
				$f = $f+2;
255
				break;
256 f6bda83c jim-p
			case "iaprefix":
257
				$is_prefix = true;
258
				$entry['prefix'] = $data[$f+1];
259
				$entry['type'] = "dynamic";
260
				$f = $f+2;
261
				break;
262 c1640267 Seth Mos
			case "starts":
263 f6bda83c jim-p
				$entry['start'] = $data[$f+2];
264
				$entry['start'] .= " " . $data[$f+3];
265 c1640267 Seth Mos
				$f = $f+3;
266
				break;
267
			case "ends":
268 f6bda83c jim-p
				$entry['end'] = $data[$f+2];
269
				$entry['end'] .= " " . $data[$f+3];
270 c1640267 Seth Mos
				$f = $f+3;
271
				break;
272
			case "tstp":
273
				$f = $f+3;
274
				break;
275
			case "tsfp":
276
				$f = $f+3;
277
				break;
278
			case "atsfp":
279
				$f = $f+3;
280
				break;
281
			case "cltt":
282 f6bda83c jim-p
				$entry['start'] = $data[$f+2];
283
				$entry['start'] .= " " . $data[$f+3];
284 c1640267 Seth Mos
				$f = $f+3;
285
				break;
286
			case "binding":
287
				switch($data[$f+2]) {
288
					case "active":
289 f6bda83c jim-p
						$entry['act'] = "active";
290 c1640267 Seth Mos
						break;
291
					case "free":
292 f6bda83c jim-p
						$entry['act'] = "expired";
293
						$entry['online'] = "offline";
294 c1640267 Seth Mos
						break;
295
					case "backup":
296 f6bda83c jim-p
						$entry['act'] = "reserved";
297
						$entry['online'] = "offline";
298 c1640267 Seth Mos
						break;
299 f6bda83c jim-p
					case "released":
300
						$entry['act'] = "released";
301
						$entry['online'] = "offline";
302 c1640267 Seth Mos
				}
303
				$f = $f+1;
304
				break;
305
			case "next":
306
				/* skip the next binding statement */
307
				$f = $f+3;
308
				break;
309
			case "hardware":
310
				$f = $f+2;
311
				break;
312
			case "client-hostname":
313
				if($data[$f+1] <> "") {
314 f6bda83c jim-p
					$entry['hostname'] = preg_replace('/"/','',$data[$f+1]);
315 c1640267 Seth Mos
				} else {
316 f6bda83c jim-p
					$hostname = gethostbyaddr($entry['ip']);
317 c1640267 Seth Mos
					if($hostname <> "") {
318 f6bda83c jim-p
						$entry['hostname'] = $hostname;
319 c1640267 Seth Mos
					}
320
				}
321
				$f = $f+1;
322
				break;
323
			case "uid":
324
				$f = $f+1;
325
				break;
326
		}
327
		$f++;
328
	}
329 f6bda83c jim-p
	if ($is_prefix) {
330
		$prefixes[] = $entry;
331
	} else {
332
		$leases[] = $entry;
333
		$mappings[$entry['iaid'] . $entry['duid']] = $entry['ip'];
334
	}
335 c1640267 Seth Mos
	$l++;
336
	$i++;
337 f6bda83c jim-p
	$is_prefix = false;
338 c1640267 Seth Mos
}
339
340
if(count($leases) > 0) {
341
	$leases = remove_duplicate($leases,"ip");
342
}
343
344 f6bda83c jim-p
if(count($prefixes) > 0) {
345
	$prefixes = remove_duplicate($prefixes,"prefix");
346
}
347
348 c1640267 Seth Mos
if(count($pools) > 0) {
349
	$pools = remove_duplicate($pools,"name");
350
	asort($pools);
351
}
352
353
foreach($config['interfaces'] as $ifname => $ifarr) {
354 f6bda83c jim-p
	if (is_array($config['dhcpdv6'][$ifname]) &&
355 c1640267 Seth Mos
		is_array($config['dhcpdv6'][$ifname]['staticmap'])) {
356
		foreach($config['dhcpdv6'][$ifname]['staticmap'] as $static) {
357
			$slease = array();
358 4151bdba jim-p
			$slease['ip'] = $static['ipaddrv6'];
359 c1640267 Seth Mos
			$slease['type'] = "static";
360 4151bdba jim-p
			$slease['duid'] = $static['duid'];
361 c1640267 Seth Mos
			$slease['start'] = "";
362
			$slease['end'] = "";
363
			$slease['hostname'] = htmlentities($static['hostname']);
364
			$slease['act'] = "static";
365 9d539cb5 jim-p
			if (in_array($slease['ip'], array_keys($ndpdata))) {
366 c1640267 Seth Mos
				$slease['online'] = 'online';
367
			} else {
368
				$slease['online'] = 'offline';
369
			}
370 4e85523b jim-p
371 c1640267 Seth Mos
			$leases[] = $slease;
372
		}
373
	}
374
}
375
376
if ($_GET['order'])
377
	usort($leases, "leasecmp");
378
379
/* only print pool status when we have one */
380
if(count($pools) > 0) {
381
?>
382
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
383 f6bda83c jim-p
	<tr>
384
		<td class="listhdrr"><?=gettext("Failover Group"); ?></a></td>
385
		<td class="listhdrr"><?=gettext("My State"); ?></a></td>
386
		<td class="listhdrr"><?=gettext("Since"); ?></a></td>
387
		<td class="listhdrr"><?=gettext("Peer State"); ?></a></td>
388
		<td class="listhdrr"><?=gettext("Since"); ?></a></td>
389
	</tr>
390 c1640267 Seth Mos
<?php
391
foreach ($pools as $data) {
392
	echo "<tr>\n";
393
	echo "<td class=\"listlr\">{$fspans}{$data['name']}{$fspane}&nbsp;</td>\n";
394
	echo "<td class=\"listr\">{$fspans}{$data['mystate']}{$fspane}&nbsp;</td>\n";
395
	echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['mydate']) . "{$fspane}&nbsp;</td>\n";
396
	echo "<td class=\"listr\">{$fspans}{$data['peerstate']}{$fspane}&nbsp;</td>\n";
397
	echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['peerdate']) . "{$fspane}&nbsp;</td>\n";
398
	echo "<td class=\"list\" valign=\"middle\" width=\"17\">&nbsp;</td>\n";
399
	echo "<td class=\"list\" valign=\"middle\" width=\"17\">&nbsp;</td>\n";
400
	echo "</tr>\n";
401
}
402
403
?>
404
</table>
405
406
<?php
407
/* only print pool status when we have one */
408
}
409
?>
410
411
412
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
413
  <tr>
414
    <td class="listhdrr"><a href="#"><?=gettext("IPv6 address"); ?></a></td>
415 f393a514 jim-p
    <td class="listhdrr"><a href="#"><?=gettext("IAID"); ?></a></td>
416 c1f4af16 jim-p
    <td class="listhdrr"><a href="#"><?=gettext("DUID"); ?></a></td>
417 2fdc8262 jim-p
    <td class="listhdrr"><a href="#"><?=gettext("Hostname/MAC"); ?></a></td>
418 c1640267 Seth Mos
    <td class="listhdrr"><a href="#"><?=gettext("Start"); ?></a></td>
419
    <td class="listhdrr"><a href="#"><?=gettext("End"); ?></a></td>
420
    <td class="listhdrr"><a href="#"><?=gettext("Online"); ?></a></td>
421
    <td class="listhdrr"><a href="#"><?=gettext("Lease Type"); ?></a></td>
422
	</tr>
423
<?php
424
foreach ($leases as $data) {
425
	if (($data['act'] == "active") || ($data['act'] == "static") || ($_GET['all'] == 1)) {
426
		if ($data['act'] != "active" && $data['act'] != "static") {
427
			$fspans = "<span class=\"gray\">";
428
			$fspane = "</span>";
429
		} else {
430
			$fspans = $fspane = "";
431
		}
432 9c070452 jim-p
433 c1640267 Seth Mos
		if ($data['act'] == "static") {
434
			foreach ($config['dhcpdv6'] as $dhcpif => $dhcpifconf) {
435
				if(is_array($dhcpifconf['staticmap'])) {
436
					foreach ($dhcpifconf['staticmap'] as $staticent) {
437
						if ($data['ip'] == $staticent['ipaddr']) {
438
							$data['if'] = $dhcpif;
439
							break;
440
						}
441
					}
442
				}
443
				/* exit as soon as we have an interface */
444
				if ($data['if'] != "")
445
					break;
446
			}
447
		} else {
448 9c070452 jim-p
			$data['if'] = convert_real_interface_to_friendly_interface_name(guess_interface_from_ip($data['ip']));
449 f6bda83c jim-p
		}
450 c1640267 Seth Mos
		echo "<tr>\n";
451 f6bda83c jim-p
		echo "<td class=\"listlr\">{$fspans}{$data['ip']}{$fspane}&nbsp;</td>\n";
452 f393a514 jim-p
		echo "<td class=\"listr\">{$fspans}{$data['iaid']}{$fspane}&nbsp;</td>\n";
453 c1f4af16 jim-p
		echo "<td class=\"listr\">{$fspans}{$data['duid']}{$fspane}&nbsp;</td>\n";
454 2fdc8262 jim-p
		echo "<td class=\"listr\">{$fspans}";
455
		if (!empty($data['hostname'])) {
456
			echo htmlentities($data['hostname']) . "<br/>";
457
		}
458 45630319 jim-p
459
		$mac=trim($ndpdata[$data['ip']]['mac']);
460
		if (!empty($mac)) {
461
			$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
462
			print htmlentities($mac);
463
			if(isset($mac_man[$mac_hi])){ print "<br/><font size=\"-2\"><i>{$mac_man[$mac_hi]}</i></font>"; }
464
		}
465
466 2fdc8262 jim-p
		echo "{$fspane}&nbsp;</td>\n";
467 f6bda83c jim-p
		if ($data['type'] != "static") {
468
			echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['start']) . "{$fspane}&nbsp;</td>\n";
469
			echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['end']) . "{$fspane}&nbsp;</td>\n";
470
		} else {
471
			echo "<td class=\"listr\">{$fspans} n/a {$fspane}&nbsp;</td>\n";
472
			echo "<td class=\"listr\">{$fspans} n/a {$fspane}&nbsp;</td>\n";
473
		}
474
		echo "<td class=\"listr\">{$fspans}{$data['online']}{$fspane}&nbsp;</td>\n";
475
		echo "<td class=\"listr\">{$fspans}{$data['act']}{$fspane}&nbsp;</td>\n";
476
477 c1640267 Seth Mos
		if ($data['type'] == "dynamic") {
478 c1f4af16 jim-p
			echo "<td valign=\"middle\"><a href=\"services_dhcpv6_edit.php?if={$data['if']}&duid={$data['duid']}&hostname={$data['hostname']}\">";
479 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";
480
		} else {
481 f6bda83c jim-p
			echo "<td class=\"list\" valign=\"middle\">";
482 c1640267 Seth Mos
			echo "<img src=\"/themes/{$g['theme']}/images/icons/icon_plus_mo.gif\" width=\"17\" height=\"17\" border=\"0\"></td>\n";
483
		}
484
485
		/* Only show the button for offline dynamic leases */
486
		if (($data['type'] == "dynamic") && ($data['online'] != "online")) {
487 bcb24b81 jim-p
			echo "<td class=\"list\" valign=\"middle\"><a href=\"status_dhcpv6_leases.php?deleteip={$data['ip']}&all=" . htmlspecialchars($_GET['all']) . "\">";
488 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";
489
		}
490 f6bda83c jim-p
		echo "</tr>\n";
491 c1640267 Seth Mos
	}
492
}
493 f6bda83c jim-p
?>
494
</table>
495 fd889d72 N0YB
496 f6bda83c jim-p
<h3>Delegated Prefixes</h3>
497
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
498
	<tr>
499
		<td class="listhdrr"><a href="#"><?=gettext("IPv6 Prefix"); ?></a></td>
500
		<td class="listhdrr"><a href="#"><?=gettext("IAID"); ?></a></td>
501
		<td class="listhdrr"><a href="#"><?=gettext("DUID"); ?></a></td>
502
		<td class="listhdrr"><a href="#"><?=gettext("Start"); ?></a></td>
503
		<td class="listhdrr"><a href="#"><?=gettext("End"); ?></a></td>
504
		<td class="listhdrr"><a href="#"><?=gettext("State"); ?></a></td>
505
	</tr>
506
<?php
507
foreach ($prefixes as $data) {
508
	if (($data['act'] == "active") || ($data['act'] == "static") || ($_GET['all'] == 1)) {
509
		if ($data['act'] != "active" && $data['act'] != "static") {
510
			$fspans = "<span class=\"gray\">";
511
			$fspane = "</span>";
512
		} else {
513
			$fspans = $fspane = "";
514
		}
515 c1640267 Seth Mos
516 f6bda83c jim-p
		if ($data['act'] == "static") {
517
			foreach ($config['dhcpdv6'] as $dhcpif => $dhcpifconf) {
518
				if(is_array($dhcpifconf['staticmap'])) {
519
					foreach ($dhcpifconf['staticmap'] as $staticent) {
520
						if ($data['ip'] == $staticent['ipaddr']) {
521
							$data['if'] = $dhcpif;
522
							break;
523
						}
524
					}
525
				}
526
				/* exit as soon as we have an interface */
527
				if ($data['if'] != "")
528
					break;
529
			}
530
		} else {
531
			$data['if'] = convert_real_interface_to_friendly_interface_name(guess_interface_from_ip($data['ip']));
532
		}
533
		echo "<tr>\n";
534
		if ($mappings[$data['iaid'] . $data['duid']]) {
535
			$dip = "<br/>Routed To: {$mappings[$data['iaid'] . $data['duid']]}";
536
		}
537
		echo "<td class=\"listlr\">{$fspans}{$data['prefix']}{$dip}{$fspane}&nbsp;</td>\n";
538
		echo "<td class=\"listr\">{$fspans}{$data['iaid']}{$fspane}&nbsp;</td>\n";
539
		echo "<td class=\"listr\">{$fspans}{$data['duid']}{$fspane}&nbsp;</td>\n";
540
		if ($data['type'] != "static") {
541
			echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['start']) . "{$fspane}&nbsp;</td>\n";
542
			echo "<td class=\"listr\">{$fspans}" . adjust_gmt($data['end']) . "{$fspane}&nbsp;</td>\n";
543
		} else {
544
			echo "<td class=\"listr\">{$fspans} n/a {$fspane}&nbsp;</td>\n";
545
			echo "<td class=\"listr\">{$fspans} n/a {$fspane}&nbsp;</td>\n";
546
		}
547
		echo "<td class=\"listr\">{$fspans}{$data['act']}{$fspane}&nbsp;</td>\n";
548
		echo "</tr>\n";
549
	}
550
}
551 c1640267 Seth Mos
?>
552
</table>
553 fd889d72 N0YB
554
<form action="status_dhcpv6_leases.php" method="get">
555
<input type="hidden" name="order" value="<?=htmlspecialchars($_GET['order']);?>"/>
556 c1640267 Seth Mos
<?php if ($_GET['all']): ?>
557 fd889d72 N0YB
<input type="hidden" name="all" value="0"/>
558
<input type="submit" class="formbtn" value="<?=gettext("Show active and static leases only"); ?>"/>
559 c1640267 Seth Mos
<?php else: ?>
560 fd889d72 N0YB
<input type="hidden" name="all" value="1"/>
561
<input type="submit" class="formbtn" value="<?=gettext("Show all configured leases"); ?>"/>
562 c1640267 Seth Mos
<?php endif; ?>
563
</form>
564
<?php if($leases == 0): ?>
565
<p><strong><?=gettext("No leases file found. Is the DHCP server active"); ?>?</strong></p>
566
<?php endif; ?>
567
568
<?php include("fend.inc"); ?>
569
</body>
570
</html>