Project

General

Profile

Download (15.7 KB) Statistics
| Branch: | Tag: | Revision:
1 5ef4a9e1 Darren Embry
<?php
2
/* $Id$ */
3
/*
4 f3475477 Darren Embry
	services_router_advertisements.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 5ef4a9e1 Darren Embry
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9
10
	part of pfSense (http://www.pfsense.org)
11
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
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
	pfSense_BUILDER_BINARIES:	/bin/rm
37
	pfSense_MODULE:	interfaces
38
*/
39
40
##|+PRIV
41 f3475477 Darren Embry
##|*IDENT=page-services-router-advertisements
42
##|*NAME=Services: Router advertisementspage
43
##|*DESCR=Allow access to the 'Services: Router Advertisements' page.
44
##|*MATCH=services_router_advertisements.php*
45 5ef4a9e1 Darren Embry
##|-PRIV
46
47
require("guiconfig.inc");
48
49
if(!$g['services_dhcp_server_enable']) {
50
	Header("Location: /");
51
	exit;
52
}
53
54
/*  Fix failover DHCP problem
55
 *  http://article.gmane.org/gmane.comp.security.firewalls.pfsense.support/18749
56
 */
57
ini_set("memory_limit","64M");
58
59
$if = $_GET['if'];
60
if ($_POST['if'])
61
	$if = $_POST['if'];
62
63
/* if OLSRD is enabled, allow WAN to house DHCP. */
64
if($config['installedpackages']['olsrd']) {
65
	foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
66 e1968b0d Renato Botelho
		if($olsrd['enable']) {
67
			$is_olsr_enabled = true;
68
			break;
69
		}
70 5ef4a9e1 Darren Embry
	}
71
}
72
73
if (!$_GET['if'])
74 f3475477 Darren Embry
	$savemsg = "<p><b>" . gettext("The DHCPv6 Server can only be enabled on interfaces configured with static IP addresses") . ".</b></p>" .
75
		   "<p><b>" . gettext("Only interfaces configured with a static IP will be shown") . ".</b></p>";
76 5ef4a9e1 Darren Embry
77
$iflist = get_configured_interface_with_descr();
78
79
/* set the starting interface */
80
if (!$if || !isset($iflist[$if])) {
81
	foreach ($iflist as $ifent => $ifname) {
82
		$oc = $config['interfaces'][$ifent];
83 db7a628c Renato Botelho
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
84
			(!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))))
85 5ef4a9e1 Darren Embry
			continue;
86
		$if = $ifent;
87
		break;
88
	}
89
}
90
91 fba196c3 Renato Botelho
if (is_array($config['dhcpdv6'][$if])) {
92 5ef4a9e1 Darren Embry
	/* RA specific */
93
	$pconfig['ramode'] = $config['dhcpdv6'][$if]['ramode'];
94
	$pconfig['rapriority'] = $config['dhcpdv6'][$if]['rapriority'];
95
	if($pconfig['rapriority'] == "")
96
		$pconfig['rapriority'] = "medium";
97
	$pconfig['rainterface'] = $config['dhcpdv6'][$if]['rainterface'];
98 163e4b91 Darren Embry
	$pconfig['radomainsearchlist'] = $config['dhcpdv6'][$if]['radomainsearchlist'];
99
	list($pconfig['radns1'],$pconfig['radns2']) = $config['dhcpdv6'][$if]['radnsserver'];
100
	$pconfig['rasamednsasdhcp6'] = isset($config['dhcpdv6'][$if]['rasamednsasdhcp6']);
101 8c4ee062 Darren Embry
102
	$pconfig['subnets'] = $config['dhcpdv6'][$if]['subnets']['item'];
103
}
104 fba196c3 Renato Botelho
if (!is_array($pconfig['subnets']))
105 8c4ee062 Darren Embry
	$pconfig['subnets'] = array();
106 5ef4a9e1 Darren Embry
107
$advertise_modes = array("disabled" => "Disabled",
108 f3475477 Darren Embry
			 "router" => "Router Only",
109
			 "unmanaged" => "Unmanaged",
110
			 "managed" => "Managed",
111
			 "assist" => "Assisted");
112 5ef4a9e1 Darren Embry
$priority_modes = array("low" => "Low",
113 f3475477 Darren Embry
			"medium" => "Normal",
114
			"high" => "High");
115 5ef4a9e1 Darren Embry
$carplist = get_configured_carp_interface_list();
116
117 8c4ee062 Darren Embry
$subnets_help = gettext("Subnets are specified in CIDR format.  " .
118 e1968b0d Renato Botelho
			"Select the CIDR mask that pertains to each entry.  " .
119
			"/128 specifies a single IPv6 host; /64 specifies a normal IPv6 network; etc.  " .
120
			"If no subnets are specified here, the Router Advertisement (RA) Daemon will advertise to the subnet to which the router's interface is assigned.");
121 8c4ee062 Darren Embry
122 5ef4a9e1 Darren Embry
if ($_POST) {
123
	unset($input_errors);
124
125
	$pconfig = $_POST;
126
127 163e4b91 Darren Embry
	/* input validation */
128 8c4ee062 Darren Embry
129
	$pconfig['subnets'] = array();
130
	for ($x = 0; $x < 5000; $x += 1) {
131
		$address = trim($_POST['subnet_address' . $x]);
132 fba196c3 Renato Botelho
		if ($address === "")
133 8c4ee062 Darren Embry
			continue;
134 fba196c3 Renato Botelho
135
		$bits = trim($_POST['subnet_bits' . $x]);
136
		if ($bits === "")
137
			$bits = "128";
138
139
		if (is_alias($address)) {
140 8c4ee062 Darren Embry
			$pconfig['subnets'][] = $address;
141 fba196c3 Renato Botelho
		} else {
142
			$pconfig['subnets'][] = $address . "/" . $bits;
143
			if (!is_ipaddrv6($address))
144
				$input_errors[] = sprintf(gettext("An invalid subnet or alias was specified. [%s/%s]"), $address, $bits);
145 8c4ee062 Darren Embry
		}
146
	}
147
148 163e4b91 Darren Embry
	if (($_POST['radns1'] && !is_ipaddrv6($_POST['radns1'])) || ($_POST['radns2'] && !is_ipaddrv6($_POST['radns2'])))
149
		$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary DNS servers.");
150
	if ($_POST['radomainsearchlist']) {
151
		$domain_array=preg_split("/[ ;]+/",$_POST['radomainsearchlist']);
152
		foreach ($domain_array as $curdomain) {
153
			if (!is_domain($curdomain)) {
154
				$input_errors[] = gettext("A valid domain search list must be specified.");
155
				break;
156
			}
157
		}
158
	}
159
160 5ef4a9e1 Darren Embry
	if (!$input_errors) {
161
		if (!is_array($config['dhcpdv6'][$if]))
162
			$config['dhcpdv6'][$if] = array();
163
164
		$config['dhcpdv6'][$if]['ramode'] = $_POST['ramode'];
165
		$config['dhcpdv6'][$if]['rapriority'] = $_POST['rapriority'];
166
		$config['dhcpdv6'][$if]['rainterface'] = $_POST['rainterface'];
167 e1968b0d Renato Botelho
168 163e4b91 Darren Embry
		$config['dhcpdv6'][$if]['radomainsearchlist'] = $_POST['radomainsearchlist'];
169
		unset($config['dhcpdv6'][$if]['radnsserver']);
170
		if ($_POST['radns1'])
171
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns1'];
172
		if ($_POST['radns2'])
173
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns2'];
174
175
		$config['dhcpdv6'][$if]['rasamednsasdhcp6'] = ($_POST['rasamednsasdhcp6']) ? true : false;
176
177 8c4ee062 Darren Embry
		if (count($pconfig['subnets'])) {
178
			$config['dhcpdv6'][$if]['subnets']['item'] = $pconfig['subnets'];
179
		} else {
180
			unset($config['dhcpdv6'][$if]['subnets']);
181
		}
182
183 5ef4a9e1 Darren Embry
		write_config();
184 f3475477 Darren Embry
		$retval = services_radvd_configure();
185 5ef4a9e1 Darren Embry
		$savemsg = get_std_save_message($retval);
186
	}
187
}
188
189 f3475477 Darren Embry
$pgtitle = array(gettext("Services"),gettext("Router advertisements"));
190 5ef4a9e1 Darren Embry
191
include("head.inc");
192
193
?>
194
195
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
196
<?php include("fbegin.inc"); ?>
197 8c4ee062 Darren Embry
198
<script type="text/javascript" src="/javascript/row_helper.js">
199
</script>
200
<script type="text/javascript" src="/javascript/autosuggest.js">
201
</script>
202
<script type="text/javascript" src="/javascript/suggestions.js">
203
</script>
204
<script type="text/javascript">
205
	rowname[0] = "subnet_address";
206
	rowtype[0] = "textbox";
207
	rowsize[0] = "30";
208
	rowname[1] = "subnet_bits";
209
	rowtype[1] = "select";
210
	rowsize[1] = "1";
211
	function add_alias_control() {
212
		var name = "subnet_address" + (totalrows - 1);
213
		obj = document.getElementById(name);
214
		obj.setAttribute('class', 'formfldalias');
215
		obj.setAttribute('autocomplete', 'off');
216
		objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
217
	}
218
</script>
219
220 f3475477 Darren Embry
<form action="services_router_advertisements.php" method="post" name="iform" id="iform">
221 5ef4a9e1 Darren Embry
<?php if ($input_errors) print_input_errors($input_errors); ?>
222
<?php if ($savemsg) print_info_box($savemsg); ?>
223
<table width="100%" border="0" cellpadding="0" cellspacing="0">
224
<tr><td>
225
<?php
226
	/* active tabs */
227
	$tab_array = array();
228
	$tabscounter = 0;
229
	$i = 0;
230
	foreach ($iflist as $ifent => $ifname) {
231
		$oc = $config['interfaces'][$ifent];
232 db7a628c Renato Botelho
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
233
			(!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))))
234 5ef4a9e1 Darren Embry
			continue;
235
		if ($ifent == $if)
236
			$active = true;
237
		else
238
			$active = false;
239
		$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
240
		$tabscounter++;
241
	}
242
	if ($tabscounter == 0) {
243
		echo "</td></tr></table></form>";
244
		include("fend.inc");
245
		echo "</body>";
246
		echo "</html>";
247
		exit;
248
	}
249
	display_top_tabs($tab_array);
250
?>
251
</td></tr>
252 f3475477 Darren Embry
<tr><td class="tabnavtbl">
253
<?php
254
$tab_array = array();
255
$tab_array[] = array(gettext("DHCPv6 Server"),         false, "services_dhcpv6.php?if={$if}");
256
$tab_array[] = array(gettext("Router Advertisements"), true,  "services_router_advertisements.php?if={$if}");
257
display_top_tabs($tab_array);
258
?>
259
</td></tr>
260 5ef4a9e1 Darren Embry
<tr>
261
<td>
262
	<div id="mainarea">
263
		<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
264
			<tr>
265
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Router Advertisements");?></td>
266
			<td width="78%" class="vtable">
267
				<select name="ramode" id="ramode">
268
					<?php foreach($advertise_modes as $name => $value) { ?>
269
					<option value="<?=$name ?>" <?php if ($pconfig['ramode'] == $name) echo "selected"; ?> > <?=$value ?></option>
270
					<?php } ?>
271
				</select><br />
272
			<strong><?php printf(gettext("Select the Operating Mode for the Router Advertisement (RA) Daemon."))?></strong>
273
			<?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"));?>
274
			<?php printf(gettext("It is not required to activate this DHCPv6 server when set to \"Managed\", this can be another host on the network")); ?>
275
			</td>
276
			</tr>
277
			<tr>
278
			<td width="22%" valign="top" class="vncell"><?=gettext("Router Priority");?></td>
279
			<td width="78%" class="vtable">
280
				<select name="rapriority" id="rapriority">
281
					<?php foreach($priority_modes as $name => $value) { ?>
282
					<option value="<?=$name ?>" <?php if ($pconfig['rapriority'] == $name) echo "selected"; ?> > <?=$value ?></option>
283
					<?php } ?>
284
				</select><br />
285
			<strong><?php printf(gettext("Select the Priority for the Router Advertisement (RA) Daemon."))?></strong>
286
			</td>
287
			</tr>
288
			<?php
289
				$carplistif = array();
290
				if(count($carplist) > 0) {
291
					foreach($carplist as $ifname => $vip) {
292
						if((preg_match("/^{$if}_/", $ifname)) && (is_ipaddrv6($vip)))
293
							$carplistif[$ifname] = $vip;
294
					}
295
				}
296
				if(count($carplistif) > 0) {
297
			?>
298
			<tr>
299
			<td width="22%" valign="top" class="vncell"><?=gettext("RA Interface");?></td>
300
			<td width="78%" class="vtable">
301
				<select name="rainterface" id="rainterface">
302
					<?php foreach($carplistif as $ifname => $vip) { ?>
303
					<option value="interface" <?php if ($pconfig['rainterface'] == "interface") echo "selected"; ?> > <?=strtoupper($if); ?></option>
304
					<option value="<?=$ifname ?>" <?php if ($pconfig['rainterface'] == $ifname) echo "selected"; ?> > <?="$ifname - $vip"; ?></option>
305
					<?php } ?>
306
				</select><br />
307
			<strong><?php printf(gettext("Select the Interface for the Router Advertisement (RA) Daemon."))?></strong>
308
			</td>
309
			</tr>
310
			<?php } ?>
311 4e0fc44f Darren Embry
312 8c4ee062 Darren Embry
			<tr>
313
			<td width="22%" valign="top" class="vncell"><?=gettext("RA Subnet(s)");?></td>
314
			<td width="78%" class="vtable">
315
				<div><?= htmlentities($subnets_help) ?></div>
316
				<table id="maintable">
317
				<tbody>
318
<?php
319
				$counter = 0;
320
				foreach ($pconfig['subnets'] as $subnet) {
321
					$address_name = "subnet_address" . $counter;
322
					$bits_name = "subnet_bits" . $counter;
323
					list($address, $subnet) = explode("/", $subnet);
324
?>
325
					<tr>
326
						<td>
327
							<input autocomplete="off" name="<?= $address_name ?>" type="text" class="formfldalias" id="<?= $address_name ?>" size="30" value="<?= htmlentities($address) ?>" />
328
						</td>
329
						<td>
330
							<select name="<?= $bits_name ?>" class="formselect" id="<?= $bits_name ?>">
331
							<option value="">
332
							<?php for ($i = 128; $i >= 0; $i -= 1) { ?>
333
								<option value="<?= $i ?>" <?= ("$subnet" === "$i") ? "selected='selected'" : "" ?>><?= $i ?></option>
334
							<?php } ?>
335
							</select>
336
						</td>
337
						<td>
338
							<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>
339
						</td>
340
					</tr>
341
<?php
342
					$counter += 1;
343
				}
344
?>
345
				</tbody>
346
				</table>
347
				<script type="text/javascript">
348
					field_counter_js = 2;
349
					totalrows = <?= $counter ?>;
350
				</script>
351
				<div id="addrowbutton">
352
					<a onclick="javascript:addRowTo('maintable'); add_alias_control(); return false;" href="#"><!--
353
					--><img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" /></a>
354
				</div>
355
			</td>
356
			</tr>
357 e1968b0d Renato Botelho
358 61071c30 bcyrill
			<tr>
359
			<td colspan="2" class="list" height="12">&nbsp;</td>
360
			</tr>
361 e1968b0d Renato Botelho
362 4e0fc44f Darren Embry
			<tr>
363
			<td colspan="2" valign="top" class="listtopic">DNS</td>
364
			</tr>
365
366
			<tr>
367
			<td width="22%" valign="top" class="vncell"><?=gettext("DNS servers");?></td>
368
			<td width="78%" class="vtable">
369 61071c30 bcyrill
				<input name="radns1" type="text" class="formfld unknown" id="radns1" size="28" value="<?=htmlspecialchars($pconfig['radns1']);?>"><br>
370
				<input name="radns2" type="text" class="formfld unknown" id="radns2" size="28" value="<?=htmlspecialchars($pconfig['radns2']);?>"><br>
371 4e0fc44f Darren Embry
				<?=gettext("NOTE: leave blank to use the system default DNS servers - this interface's IP if DNS forwarder is enabled, otherwise the servers configured on the General page.");?>
372
			</td>
373
			</tr>
374
375
			<tr>
376
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain search list");?></td>
377
			<td width="78%" class="vtable">
378
				<input name="radomainsearchlist" type="text" class="formfld unknown" id="radomainsearchlist" size="28" value="<?=htmlspecialchars($pconfig['radomainsearchlist']);?>"><br>
379 eab652e4 Renato Botelho
				<?=gettext("The RA server can optionally provide a domain search list. Use the semicolon character as separator");?>
380 4e0fc44f Darren Embry
			</td>
381
			</tr>
382
383
			<tr>
384
			<td width="22%" valign="top" class="vncell">&nbsp;</td>
385
			<td width="78%" class="vtable">
386
				<input id="rasamednsasdhcp6" name="rasamednsasdhcp6" type="checkbox" value="yes" <?php if ($pconfig['rasamednsasdhcp6']) { echo "checked='checked'"; } ?> />
387
				<strong><?= gettext("Use same settings as DHCPv6 server"); ?></strong>
388
			</td>
389
			</tr>
390
391 5ef4a9e1 Darren Embry
			<tr>
392
			<td width="22%" valign="top">&nbsp;</td>
393
			<td width="78%">
394 f3475477 Darren Embry
				<input name="if" type="hidden" value="<?=$if;?>" />
395
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
396 5ef4a9e1 Darren Embry
			</td>
397
			</tr>
398
		</table>
399
	</div>
400
</td>
401
</tr>
402
</table>
403
</form>
404 8c4ee062 Darren Embry
405 4e0fc44f Darren Embry
<script language="JavaScript">
406 8c4ee062 Darren Embry
//<![CDATA[
407 4e0fc44f Darren Embry
	jQuery(function ($) {
408
		var $rasamednsasdhcp6 = $("#rasamednsasdhcp6");
409
		var $triggered_checkboxes = $("#radns1, #radns2, #radomainsearchlist");
410
		if ($rasamednsasdhcp6.length !== 1) { return; }
411
		var onchange = function () {
412
			var checked = $rasamednsasdhcp6.is(":checked");
413
			if (checked) {
414
				$triggered_checkboxes.each(function () { this.disabled = true; });
415
			} else {
416
				$triggered_checkboxes.each(function () { this.disabled = false; });
417
			}
418
		};
419
		$rasamednsasdhcp6.bind("change", onchange);
420
		onchange();
421
	});
422 8c4ee062 Darren Embry
423
	var addressarray = <?= json_encode(get_alias_list("host", "network", "openvpn", "urltable")); ?>;
424
	var objAlias = [];
425
	function createAutoSuggest () {
426
		<?php for ($i = 0; $i < $counter; $i += 1) { ?>
427
			objAlias.push(new AutoSuggestControl(document.getElementById('subnet_address<?= $i ?>'), new StateSuggestions(addressarray)));
428
		<?php } ?>
429
		new AutoSuggestControl(document.getElementById('radns1'), new StateSuggestions(addressarray));
430
		new AutoSuggestControl(document.getElementById('radns2'), new StateSuggestions(addressarray));
431
	}
432
	setTimeout(createAutoSuggest, 500);
433
//]]>
434 4e0fc44f Darren Embry
</script>
435 8c4ee062 Darren Embry
436 5ef4a9e1 Darren Embry
<?php include("fend.inc"); ?>
437
</body>
438
</html>