Project

General

Profile

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