Project

General

Profile

Download (17.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_router_advertisements.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	part of pfSense (https://www.pfsense.org)
11
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
12
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
13
	All rights reserved.
14

    
15
	Redistribution and use in source and binary forms, with or without
16
	modification, are permitted provided that the following conditions are met:
17

    
18
	1. Redistributions of source code must retain the above copyright notice,
19
	   this list of conditions and the following disclaimer.
20

    
21
	2. Redistributions in binary form must reproduce the above copyright
22
	   notice, this list of conditions and the following disclaimer in the
23
	   documentation and/or other materials provided with the distribution.
24

    
25
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
26
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
29
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
	POSSIBILITY OF SUCH DAMAGE.
35
*/
36
/*
37
	pfSense_BUILDER_BINARIES:	/bin/rm
38
	pfSense_MODULE:	interfaces
39
*/
40

    
41
##|+PRIV
42
##|*IDENT=page-services-router-advertisements
43
##|*NAME=Services: Router advertisementspage
44
##|*DESCR=Allow access to the 'Services: Router Advertisements' page.
45
##|*MATCH=services_router_advertisements.php*
46
##|-PRIV
47

    
48
require("guiconfig.inc");
49

    
50
if (!$g['services_dhcp_server_enable']) {
51
	header("Location: /");
52
	exit;
53
}
54

    
55
/*  Fix failover DHCP problem
56
 *  http://article.gmane.org/gmane.comp.security.firewalls.pfsense.support/18749
57
 */
58
ini_set("memory_limit", "64M");
59

    
60
$if = $_GET['if'];
61
if ($_POST['if']) {
62
	$if = $_POST['if'];
63
}
64

    
65
/* if OLSRD is enabled, allow WAN to house DHCP. */
66
if ($config['installedpackages']['olsrd']) {
67
	foreach ($config['installedpackages']['olsrd']['config'] as $olsrd) {
68
		if ($olsrd['enable']) {
69
			$is_olsr_enabled = true;
70
			break;
71
		}
72
	}
73
}
74

    
75
if (!$_GET['if']) {
76
	$savemsg = "<p><b>" . gettext("The DHCPv6 Server can only be enabled on interfaces configured with static IP addresses") . ".</b></p>" .
77
		"<p><b>" . gettext("Only interfaces configured with a static IP will be shown") . ".</b></p>";
78
}
79

    
80
$iflist = get_configured_interface_with_descr();
81

    
82
/* set the starting interface */
83
if (!$if || !isset($iflist[$if])) {
84
	foreach ($iflist as $ifent => $ifname) {
85
		$oc = $config['interfaces'][$ifent];
86
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
87
		    (!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6']))))) {
88
			continue;
89
		}
90
		$if = $ifent;
91
		break;
92
	}
93
}
94

    
95
if (is_array($config['dhcpdv6'][$if])) {
96
	/* RA specific */
97
	$pconfig['ramode'] = $config['dhcpdv6'][$if]['ramode'];
98
	$pconfig['rapriority'] = $config['dhcpdv6'][$if]['rapriority'];
99
	if ($pconfig['rapriority'] == "") {
100
		$pconfig['rapriority'] = "medium";
101
	}
102
	$pconfig['rainterface'] = $config['dhcpdv6'][$if]['rainterface'];
103
	$pconfig['radomainsearchlist'] = $config['dhcpdv6'][$if]['radomainsearchlist'];
104
	list($pconfig['radns1'], $pconfig['radns2'], $pconfig['radns3'], $pconfig['radns4']) = $config['dhcpdv6'][$if]['radnsserver'];
105
	$pconfig['rasamednsasdhcp6'] = isset($config['dhcpdv6'][$if]['rasamednsasdhcp6']);
106

    
107
	$pconfig['subnets'] = $config['dhcpdv6'][$if]['subnets']['item'];
108
}
109
if (!is_array($pconfig['subnets'])) {
110
	$pconfig['subnets'] = array();
111
}
112

    
113
$advertise_modes = array("disabled" => "Disabled",
114
	"router" => "Router Only",
115
	"unmanaged" => "Unmanaged",
116
	"managed" => "Managed",
117
	"assist" => "Assisted",
118
	"stateless_dhcp" => "Stateless DHCP");
119
$priority_modes = array("low" => "Low",
120
	"medium" => "Normal",
121
	"high" => "High");
122
$carplist = get_configured_carp_interface_list();
123

    
124
$subnets_help = gettext("Subnets are specified in CIDR format.  " .
125
	"Select the CIDR mask that pertains to each entry.  " .
126
	"/128 specifies a single IPv6 host; /64 specifies a normal IPv6 network; etc.  " .
127
	"If no subnets are specified here, the Router Advertisement (RA) Daemon will advertise to the subnet to which the router's interface is assigned.");
128

    
129
if ($_POST) {
130
	unset($input_errors);
131

    
132
	$pconfig = $_POST;
133

    
134
	/* input validation */
135

    
136
	$pconfig['subnets'] = array();
137
	for ($x = 0; $x < 5000; $x += 1) {
138
		$address = trim($_POST['subnet_address' . $x]);
139
		if ($address === "") {
140
			continue;
141
		}
142

    
143
		$bits = trim($_POST['subnet_bits' . $x]);
144
		if ($bits === "") {
145
			$bits = "128";
146
		}
147

    
148
		if (is_alias($address)) {
149
			$pconfig['subnets'][] = $address;
150
		} else {
151
			$pconfig['subnets'][] = $address . "/" . $bits;
152
			if (!is_ipaddrv6($address)) {
153
				$input_errors[] = sprintf(gettext("An invalid subnet or alias was specified. [%s/%s]"), $address, $bits);
154
			}
155
		}
156
	}
157

    
158
	if (($_POST['radns1'] && !is_ipaddrv6($_POST['radns1'])) || ($_POST['radns2'] && !is_ipaddrv6($_POST['radns2'])) || ($_POST['radns3'] && !is_ipaddrv6($_POST['radns3'])) || ($_POST['radns4'] && !is_ipaddrv6($_POST['radns4']))) {
159
		$input_errors[] = gettext("A valid IPv6 address must be specified for each of the DNS servers.");
160
	}
161
	if ($_POST['radomainsearchlist']) {
162
		$domain_array=preg_split("/[ ;]+/", $_POST['radomainsearchlist']);
163
		foreach ($domain_array as $curdomain) {
164
			if (!is_domain($curdomain)) {
165
				$input_errors[] = gettext("A valid domain search list must be specified.");
166
				break;
167
			}
168
		}
169
	}
170

    
171
	if (!$input_errors) {
172
		if (!is_array($config['dhcpdv6'][$if])) {
173
			$config['dhcpdv6'][$if] = array();
174
		}
175

    
176
		$config['dhcpdv6'][$if]['ramode'] = $_POST['ramode'];
177
		$config['dhcpdv6'][$if]['rapriority'] = $_POST['rapriority'];
178
		$config['dhcpdv6'][$if]['rainterface'] = $_POST['rainterface'];
179

    
180
		$config['dhcpdv6'][$if]['radomainsearchlist'] = $_POST['radomainsearchlist'];
181
		unset($config['dhcpdv6'][$if]['radnsserver']);
182
		if ($_POST['radns1']) {
183
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns1'];
184
		}
185
		if ($_POST['radns2']) {
186
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns2'];
187
		}
188
		if ($_POST['radns3']) {
189
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns3'];
190
		}
191
		if ($_POST['radns4']) {
192
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns4'];
193
		}
194

    
195
		$config['dhcpdv6'][$if]['rasamednsasdhcp6'] = ($_POST['rasamednsasdhcp6']) ? true : false;
196

    
197
		if (count($pconfig['subnets'])) {
198
			$config['dhcpdv6'][$if]['subnets']['item'] = $pconfig['subnets'];
199
		} else {
200
			unset($config['dhcpdv6'][$if]['subnets']);
201
		}
202

    
203
		write_config();
204
		$retval = services_radvd_configure();
205
		$savemsg = get_std_save_message($retval);
206
	}
207
}
208

    
209
$pgtitle = array(gettext("Services"), gettext("Router advertisements"));
210

    
211
include("head.inc");
212

    
213
?>
214

    
215
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
216
<?php include("fbegin.inc"); ?>
217

    
218
<script type="text/javascript" src="/javascript/row_helper.js">
219
</script>
220
<script type="text/javascript" src="/javascript/autosuggest.js?rev=1">
221
</script>
222
<script type="text/javascript" src="/javascript/suggestions.js">
223
</script>
224
<script type="text/javascript">
225
//<![CDATA[
226
	rowname[0] = "subnet_address";
227
	rowtype[0] = "textbox";
228
	rowsize[0] = "30";
229
	rowname[1] = "subnet_bits";
230
	rowtype[1] = "select";
231
	rowsize[1] = "1";
232
	function add_alias_control() {
233
		var name = "subnet_address" + (totalrows - 1);
234
		obj = document.getElementById(name);
235
		obj.setAttribute('class', 'formfldalias');
236
		obj.setAttribute('autocomplete', 'off');
237
		objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
238
	}
239
//]]>
240
</script>
241

    
242
<form action="services_router_advertisements.php" method="post" name="iform" id="iform">
243
<?php if ($input_errors) print_input_errors($input_errors); ?>
244
<?php if ($savemsg) print_info_box($savemsg); ?>
245
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="router advert">
246
	<tr>
247
		<td>
248
<?php
249
	/* active tabs */
250
	$tab_array = array();
251
	$tabscounter = 0;
252
	$i = 0;
253
	foreach ($iflist as $ifent => $ifname) {
254
		$oc = $config['interfaces'][$ifent];
255
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
256
		    (!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6']))))) {
257
			continue;
258
		}
259
		if ($ifent == $if) {
260
			$active = true;
261
		} else {
262
			$active = false;
263
		}
264
		$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
265
		$tabscounter++;
266
	}
267
	if ($tabscounter == 0) {
268
		echo "</td></tr></table></form>";
269
		include("fend.inc");
270
		echo "</body>";
271
		echo "</html>";
272
		exit;
273
	}
274
	display_top_tabs($tab_array);
275
?>
276
		</td>
277
	</tr>
278
	<tr>
279
		<td class="tabnavtbl">
280
<?php
281
	$tab_array = array();
282
	$tab_array[] = array(gettext("DHCPv6 Server"),         false, "services_dhcpv6.php?if={$if}");
283
	$tab_array[] = array(gettext("Router Advertisements"), true,  "services_router_advertisements.php?if={$if}");
284
	display_top_tabs($tab_array);
285
?>
286
		</td>
287
	</tr>
288
	<tr>
289
		<td>
290
			<div id="mainarea">
291
			<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
292
				<tr>
293
					<td width="22%" valign="top" class="vncellreq"><?=gettext("Router Advertisements");?></td>
294
					<td width="78%" class="vtable">
295
						<select name="ramode" id="ramode">
296
							<?php foreach ($advertise_modes as $name => $value) { ?>
297
							<option value="<?=$name ?>" <?php if ($pconfig['ramode'] == $name) echo "selected=\"selected\""; ?> > <?=$value ?></option>
298
							<?php } ?>
299
						</select>
300
						<br />
301
						<strong><?php printf(gettext("Select the Operating Mode for the Router Advertisement (RA) Daemon."))?></strong>
302
						<?php printf(gettext("Use \"Router Only\" to only advertise this router, \"Unmanaged\" for Router Advertising with Stateless Autoconfig, \"Managed\" for assignment through (a) DHCPv6 Server, \"Assisted\" for DHCPv6 Server assignment combined with Stateless Autoconfig"));?>
303
						<?php printf(gettext("It is not required to activate this DHCPv6 server when set to \"Managed\", this can be another host on the network")); ?>
304
					</td>
305
				</tr>
306
				<tr>
307
					<td width="22%" valign="top" class="vncell"><?=gettext("Router Priority");?></td>
308
					<td width="78%" class="vtable">
309
						<select name="rapriority" id="rapriority">
310
							<?php foreach ($priority_modes as $name => $value) { ?>
311
							<option value="<?=$name ?>" <?php if ($pconfig['rapriority'] == $name) echo "selected=\"selected\""; ?> > <?=$value ?></option>
312
							<?php } ?>
313
						</select>
314
						<br />
315
						<strong><?php printf(gettext("Select the Priority for the Router Advertisement (RA) Daemon."))?></strong>
316
					</td>
317
				</tr>
318
<?php
319
	$carplistif = array();
320
	if (count($carplist) > 0) {
321
		foreach ($carplist as $ifname => $vip) {
322
			if ((preg_match("/^{$if}_/", $ifname)) && (is_ipaddrv6($vip))) {
323
				$carplistif[$ifname] = $vip;
324
			}
325
		}
326
	}
327
	if (count($carplistif) > 0) {
328
?>
329
				<tr>
330
					<td width="22%" valign="top" class="vncell"><?=gettext("RA Interface");?></td>
331
					<td width="78%" class="vtable">
332
						<select name="rainterface" id="rainterface">
333
							<?php foreach ($carplistif as $ifname => $vip) { ?>
334
							<option value="interface" <?php if ($pconfig['rainterface'] == "interface") echo "selected=\"selected\""; ?> > <?=strtoupper($if); ?></option>
335
							<option value="<?=$ifname ?>" <?php if ($pconfig['rainterface'] == $ifname) echo "selected=\"selected\""; ?> > <?="$ifname - $vip"; ?></option>
336
							<?php } ?>
337
						</select>
338
						<br />
339
						<strong><?php printf(gettext("Select the Interface for the Router Advertisement (RA) Daemon."))?></strong>
340
					</td>
341
				</tr>
342
<?php
343
	}
344
?>
345
				<tr>
346
					<td width="22%" valign="top" class="vncell"><?=gettext("RA Subnet(s)");?></td>
347
					<td width="78%" class="vtable">
348
						<div><?= htmlentities($subnets_help) ?></div>
349
						<table id="maintable" summary="subnets">
350
							<tbody>
351
<?php
352
	$counter = 0;
353
	foreach ($pconfig['subnets'] as $subnet) {
354
		$address_name = "subnet_address" . $counter;
355
		$bits_name = "subnet_bits" . $counter;
356
		list($address, $subnet) = explode("/", $subnet);
357
?>
358
							<tr>
359
								<td>
360
									<input autocomplete="off" name="<?= $address_name ?>" type="text" class="formfldalias" id="<?= $address_name ?>" size="30" value="<?= htmlentities($address) ?>" />
361
								</td>
362
								<td>
363
									<select name="<?= $bits_name ?>" class="formselect" id="<?= $bits_name ?>">
364
										<option value="">
365
										<?php for ($i = 128; $i >= 0; $i -= 1) { ?>
366
										<option value="<?= $i ?>" <?= ("$subnet" === "$i") ? "selected='selected'" : "" ?>><?= $i ?></option>
367
										<?php } ?>
368
									</select>
369
								</td>
370
								<td>
371
									<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="" title="<?=gettext("remove this entry"); ?>" /></a>
372
								</td>
373
							</tr>
374
<?php
375
		$counter += 1;
376
	}
377
?>
378
							<tr style="display:none">
379
								<td></td>
380
							</tr>
381
							</tbody>
382
						</table>
383
						<script type="text/javascript">
384
						//<![CDATA[
385
							field_counter_js = 2;
386
							totalrows = <?= $counter ?>;
387
						//]]>
388
						</script>
389
						<div id="addrowbutton">
390
							<a onclick="javascript:addRowTo('maintable'); add_alias_control(); return false;" href="#"><!--
391
							--><img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" /></a>
392
						</div>
393
					</td>
394
				</tr>
395

    
396
				<tr>
397
					<td colspan="2" class="list" height="12">&nbsp;</td>
398
				</tr>
399

    
400
				<tr>
401
					<td colspan="2" valign="top" class="listtopic">DNS</td>
402
				</tr>
403

    
404
				<tr>
405
					<td width="22%" valign="top" class="vncell"><?=gettext("DNS servers");?></td>
406
					<td width="78%" class="vtable">
407
						<input name="radns1" type="text" class="formfld unknown" id="radns1" size="28" value="<?=htmlspecialchars($pconfig['radns1']);?>" /><br />
408
						<input name="radns2" type="text" class="formfld unknown" id="radns2" size="28" value="<?=htmlspecialchars($pconfig['radns2']);?>" /><br />
409
						<input name="radns3" type="text" class="formfld unknown" id="radns3" size="28" value="<?=htmlspecialchars($pconfig['radns3']);?>" /><br />
410
						<input name="radns4" type="text" class="formfld unknown" id="radns4" size="28" value="<?=htmlspecialchars($pconfig['radns4']);?>" /><br />
411
						<?=gettext("NOTE: leave blank to use the system default DNS servers - this interface's IP if DNS Forwarder or Resolver is enabled, otherwise the servers configured on the General page.");?>
412
					</td>
413
				</tr>
414

    
415
				<tr>
416
					<td width="22%" valign="top" class="vncell"><?=gettext("Domain search list");?></td>
417
					<td width="78%" class="vtable">
418
						<input name="radomainsearchlist" type="text" class="formfld unknown" id="radomainsearchlist" size="28" value="<?=htmlspecialchars($pconfig['radomainsearchlist']);?>" /><br />
419
						<?=gettext("The RA server can optionally provide a domain search list. Use the semicolon character as separator");?>
420
					</td>
421
				</tr>
422

    
423
				<tr>
424
					<td width="22%" valign="top" class="vncell">&nbsp;</td>
425
					<td width="78%" class="vtable">
426
						<input id="rasamednsasdhcp6" name="rasamednsasdhcp6" type="checkbox" value="yes" <?php if ($pconfig['rasamednsasdhcp6']) { echo "checked='checked'"; } ?> />
427
						<strong><?= gettext("Use same settings as DHCPv6 server"); ?></strong>
428
					</td>
429
				</tr>
430

    
431
				<tr>
432
					<td width="22%" valign="top">&nbsp;</td>
433
					<td width="78%">
434
						<input name="if" type="hidden" value="<?=$if;?>" />
435
						<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
436
					</td>
437
				</tr>
438
			</table>
439
			</div>
440
		</td>
441
	</tr>
442
</table>
443
</form>
444

    
445
<script type="text/javascript">
446
//<![CDATA[
447
	jQuery(function ($) {
448
		var $rasamednsasdhcp6 = $("#rasamednsasdhcp6");
449
		var $triggered_checkboxes = $("#radns1, #radns2, #radns3, #radns4, #radomainsearchlist");
450
		if ($rasamednsasdhcp6.length !== 1) { return; }
451
		var onchange = function () {
452
			var checked = $rasamednsasdhcp6.is(":checked");
453
			if (checked) {
454
				$triggered_checkboxes.each(function () { this.disabled = true; });
455
			} else {
456
				$triggered_checkboxes.each(function () { this.disabled = false; });
457
			}
458
		};
459
		$rasamednsasdhcp6.bind("change", onchange);
460
		onchange();
461
	});
462

    
463
	var addressarray = <?= json_encode(get_alias_list("host", "network", "openvpn", "urltable")); ?>;
464
	var objAlias = [];
465
	function createAutoSuggest () {
466
		<?php for ($i = 0; $i < $counter; $i += 1) { ?>
467
			objAlias.push(new AutoSuggestControl(document.getElementById('subnet_address<?= $i ?>'), new StateSuggestions(addressarray)));
468
		<?php } ?>
469
		new AutoSuggestControl(document.getElementById('radns1'), new StateSuggestions(addressarray));
470
		new AutoSuggestControl(document.getElementById('radns2'), new StateSuggestions(addressarray));
471
		new AutoSuggestControl(document.getElementById('radns3'), new StateSuggestions(addressarray));
472
		new AutoSuggestControl(document.getElementById('radns4'), new StateSuggestions(addressarray));
473
	}
474
	setTimeout(createAutoSuggest, 500);
475
//]]>
476
</script>
477

    
478
<?php include("fend.inc"); ?>
479
</body>
480
</html>
(151-151/238)