Project

General

Profile

Download (16.8 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
/* if OLSRD is enabled, allow WAN to house DHCP. */
65
if($config['installedpackages']['olsrd']) {
66
	foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
67
		if($olsrd['enable']) {
68
			$is_olsr_enabled = true;
69
			break;
70
		}
71
	}
72
}
73

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

    
78
$iflist = get_configured_interface_with_descr();
79

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

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

    
103
	$pconfig['subnets'] = $config['dhcpdv6'][$if]['subnets']['item'];
104
}
105
if (!is_array($pconfig['subnets']))
106
	$pconfig['subnets'] = array();
107

    
108
$advertise_modes = array("disabled" => "Disabled",
109
			 "router" => "Router Only",
110
			 "unmanaged" => "Unmanaged",
111
			 "managed" => "Managed",
112
			 "assist" => "Assisted");
113
$priority_modes = array("low" => "Low",
114
			"medium" => "Normal",
115
			"high" => "High");
116
$carplist = get_configured_carp_interface_list();
117

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

    
123
if ($_POST) {
124
	unset($input_errors);
125

    
126
	$pconfig = $_POST;
127

    
128
	/* input validation */
129

    
130
	$pconfig['subnets'] = array();
131
	for ($x = 0; $x < 5000; $x += 1) {
132
		$address = trim($_POST['subnet_address' . $x]);
133
		if ($address === "")
134
			continue;
135

    
136
		$bits = trim($_POST['subnet_bits' . $x]);
137
		if ($bits === "")
138
			$bits = "128";
139

    
140
		if (is_alias($address)) {
141
			$pconfig['subnets'][] = $address;
142
		} else {
143
			$pconfig['subnets'][] = $address . "/" . $bits;
144
			if (!is_ipaddrv6($address))
145
				$input_errors[] = sprintf(gettext("An invalid subnet or alias was specified. [%s/%s]"), $address, $bits);
146
		}
147
	}
148

    
149
	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'])))
150
		$input_errors[] = gettext("A valid IPv6 address must be specified for each of the DNS servers.");
151
	if ($_POST['radomainsearchlist']) {
152
		$domain_array=preg_split("/[ ;]+/",$_POST['radomainsearchlist']);
153
		foreach ($domain_array as $curdomain) {
154
			if (!is_domain($curdomain)) {
155
				$input_errors[] = gettext("A valid domain search list must be specified.");
156
				break;
157
			}
158
		}
159
	}
160

    
161
	if (!$input_errors) {
162
		if (!is_array($config['dhcpdv6'][$if]))
163
			$config['dhcpdv6'][$if] = array();
164

    
165
		$config['dhcpdv6'][$if]['ramode'] = $_POST['ramode'];
166
		$config['dhcpdv6'][$if]['rapriority'] = $_POST['rapriority'];
167
		$config['dhcpdv6'][$if]['rainterface'] = $_POST['rainterface'];
168

    
169
		$config['dhcpdv6'][$if]['radomainsearchlist'] = $_POST['radomainsearchlist'];
170
		unset($config['dhcpdv6'][$if]['radnsserver']);
171
		if ($_POST['radns1'])
172
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns1'];
173
		if ($_POST['radns2'])
174
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns2'];
175
		if ($_POST['radns3'])
176
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns3'];
177
		if ($_POST['radns4'])
178
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns4'];
179

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

    
182
		if (count($pconfig['subnets'])) {
183
			$config['dhcpdv6'][$if]['subnets']['item'] = $pconfig['subnets'];
184
		} else {
185
			unset($config['dhcpdv6'][$if]['subnets']);
186
		}
187

    
188
		write_config();
189
		$retval = services_radvd_configure();
190
		$savemsg = get_std_save_message($retval);
191
	}
192
}
193

    
194
$pgtitle = array(gettext("Services"),gettext("Router advertisements"));
195

    
196
include("head.inc");
197

    
198
?>
199

    
200
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
201
<?php include("fbegin.inc"); ?>
202

    
203
<script type="text/javascript" src="/javascript/row_helper.js">
204
</script>
205
<script type="text/javascript" src="/javascript/autosuggest.js?rev=1">
206
</script>
207
<script type="text/javascript" src="/javascript/suggestions.js">
208
</script>
209
<script type="text/javascript">
210
//<![CDATA[
211
	rowname[0] = "subnet_address";
212
	rowtype[0] = "textbox";
213
	rowsize[0] = "30";
214
	rowname[1] = "subnet_bits";
215
	rowtype[1] = "select";
216
	rowsize[1] = "1";
217
	function add_alias_control() {
218
		var name = "subnet_address" + (totalrows - 1);
219
		obj = document.getElementById(name);
220
		obj.setAttribute('class', 'formfldalias');
221
		obj.setAttribute('autocomplete', 'off');
222
		objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
223
	}
224
//]]>
225
</script>
226

    
227
<form action="services_router_advertisements.php" method="post" name="iform" id="iform">
228
<?php if ($input_errors) print_input_errors($input_errors); ?>
229
<?php if ($savemsg) print_info_box($savemsg); ?>
230
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="router advert">
231
<tr><td>
232
<?php
233
	/* active tabs */
234
	$tab_array = array();
235
	$tabscounter = 0;
236
	$i = 0;
237
	foreach ($iflist as $ifent => $ifname) {
238
		$oc = $config['interfaces'][$ifent];
239
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
240
			(!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))))
241
			continue;
242
		if ($ifent == $if)
243
			$active = true;
244
		else
245
			$active = false;
246
		$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
247
		$tabscounter++;
248
	}
249
	if ($tabscounter == 0) {
250
		echo "</td></tr></table></form>";
251
		include("fend.inc");
252
		echo "</body>";
253
		echo "</html>";
254
		exit;
255
	}
256
	display_top_tabs($tab_array);
257
?>
258
</td></tr>
259
<tr><td class="tabnavtbl">
260
<?php
261
$tab_array = array();
262
$tab_array[] = array(gettext("DHCPv6 Server"),         false, "services_dhcpv6.php?if={$if}");
263
$tab_array[] = array(gettext("Router Advertisements"), true,  "services_router_advertisements.php?if={$if}");
264
display_top_tabs($tab_array);
265
?>
266
</td></tr>
267
<tr>
268
<td>
269
	<div id="mainarea">
270
		<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
271
			<tr>
272
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Router Advertisements");?></td>
273
			<td width="78%" class="vtable">
274
				<select name="ramode" id="ramode">
275
					<?php foreach($advertise_modes as $name => $value) { ?>
276
					<option value="<?=$name ?>" <?php if ($pconfig['ramode'] == $name) echo "selected=\"selected\""; ?> > <?=$value ?></option>
277
					<?php } ?>
278
				</select><br />
279
			<strong><?php printf(gettext("Select the Operating Mode for the Router Advertisement (RA) Daemon."))?></strong>
280
			<?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"));?>
281
			<?php printf(gettext("It is not required to activate this DHCPv6 server when set to \"Managed\", this can be another host on the network")); ?>
282
			</td>
283
			</tr>
284
			<tr>
285
			<td width="22%" valign="top" class="vncell"><?=gettext("Router Priority");?></td>
286
			<td width="78%" class="vtable">
287
				<select name="rapriority" id="rapriority">
288
					<?php foreach($priority_modes as $name => $value) { ?>
289
					<option value="<?=$name ?>" <?php if ($pconfig['rapriority'] == $name) echo "selected=\"selected\""; ?> > <?=$value ?></option>
290
					<?php } ?>
291
				</select><br />
292
			<strong><?php printf(gettext("Select the Priority for the Router Advertisement (RA) Daemon."))?></strong>
293
			</td>
294
			</tr>
295
			<?php
296
				$carplistif = array();
297
				if(count($carplist) > 0) {
298
					foreach($carplist as $ifname => $vip) {
299
						if((preg_match("/^{$if}_/", $ifname)) && (is_ipaddrv6($vip)))
300
							$carplistif[$ifname] = $vip;
301
					}
302
				}
303
				if(count($carplistif) > 0) {
304
			?>
305
			<tr>
306
			<td width="22%" valign="top" class="vncell"><?=gettext("RA Interface");?></td>
307
			<td width="78%" class="vtable">
308
				<select name="rainterface" id="rainterface">
309
					<?php foreach($carplistif as $ifname => $vip) { ?>
310
					<option value="interface" <?php if ($pconfig['rainterface'] == "interface") echo "selected=\"selected\""; ?> > <?=strtoupper($if); ?></option>
311
					<option value="<?=$ifname ?>" <?php if ($pconfig['rainterface'] == $ifname) echo "selected=\"selected\""; ?> > <?="$ifname - $vip"; ?></option>
312
					<?php } ?>
313
				</select><br />
314
			<strong><?php printf(gettext("Select the Interface for the Router Advertisement (RA) Daemon."))?></strong>
315
			</td>
316
			</tr>
317
			<?php } ?>
318

    
319
			<tr>
320
			<td width="22%" valign="top" class="vncell"><?=gettext("RA Subnet(s)");?></td>
321
			<td width="78%" class="vtable">
322
				<div><?= htmlentities($subnets_help) ?></div>
323
				<table id="maintable" summary="subnets">
324
				<tbody>
325
<?php
326
				$counter = 0;
327
				foreach ($pconfig['subnets'] as $subnet) {
328
					$address_name = "subnet_address" . $counter;
329
					$bits_name = "subnet_bits" . $counter;
330
					list($address, $subnet) = explode("/", $subnet);
331
?>
332
					<tr>
333
						<td>
334
							<input autocomplete="off" name="<?= $address_name ?>" type="text" class="formfldalias" id="<?= $address_name ?>" size="30" value="<?= htmlentities($address) ?>" />
335
						</td>
336
						<td>
337
							<select name="<?= $bits_name ?>" class="formselect" id="<?= $bits_name ?>">
338
							<option value="">
339
							<?php for ($i = 128; $i >= 0; $i -= 1) { ?>
340
								<option value="<?= $i ?>" <?= ("$subnet" === "$i") ? "selected='selected'" : "" ?>><?= $i ?></option>
341
							<?php } ?>
342
							</select>
343
						</td>
344
						<td>
345
							<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>
346
						</td>
347
					</tr>
348
<?php
349
					$counter += 1;
350
				}
351
?>
352
				<tr style="display:none"><td></td></tr>
353
				</tbody>
354
				</table>
355
				<script type="text/javascript">
356
				//<![CDATA[
357
					field_counter_js = 2;
358
					totalrows = <?= $counter ?>;
359
				//]]>
360
				</script>
361
				<div id="addrowbutton">
362
					<a onclick="javascript:addRowTo('maintable'); add_alias_control(); return false;" href="#"><!--
363
					--><img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" /></a>
364
				</div>
365
			</td>
366
			</tr>
367

    
368
			<tr>
369
			<td colspan="2" class="list" height="12">&nbsp;</td>
370
			</tr>
371

    
372
			<tr>
373
			<td colspan="2" valign="top" class="listtopic">DNS</td>
374
			</tr>
375

    
376
			<tr>
377
			<td width="22%" valign="top" class="vncell"><?=gettext("DNS servers");?></td>
378
			<td width="78%" class="vtable">
379
				<input name="radns1" type="text" class="formfld unknown" id="radns1" size="28" value="<?=htmlspecialchars($pconfig['radns1']);?>" /><br />
380
				<input name="radns2" type="text" class="formfld unknown" id="radns2" size="28" value="<?=htmlspecialchars($pconfig['radns2']);?>" /><br />
381
				<input name="radns3" type="text" class="formfld unknown" id="radns3" size="28" value="<?=htmlspecialchars($pconfig['radns3']);?>" /><br />
382
				<input name="radns4" type="text" class="formfld unknown" id="radns4" size="28" value="<?=htmlspecialchars($pconfig['radns4']);?>" /><br />
383
				<?=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.");?>
384
			</td>
385
			</tr>
386

    
387
			<tr>
388
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain search list");?></td>
389
			<td width="78%" class="vtable">
390
				<input name="radomainsearchlist" type="text" class="formfld unknown" id="radomainsearchlist" size="28" value="<?=htmlspecialchars($pconfig['radomainsearchlist']);?>" /><br />
391
				<?=gettext("The RA server can optionally provide a domain search list. Use the semicolon character as separator");?>
392
			</td>
393
			</tr>
394

    
395
			<tr>
396
			<td width="22%" valign="top" class="vncell">&nbsp;</td>
397
			<td width="78%" class="vtable">
398
				<input id="rasamednsasdhcp6" name="rasamednsasdhcp6" type="checkbox" value="yes" <?php if ($pconfig['rasamednsasdhcp6']) { echo "checked='checked'"; } ?> />
399
				<strong><?= gettext("Use same settings as DHCPv6 server"); ?></strong>
400
			</td>
401
			</tr>
402

    
403
			<tr>
404
			<td width="22%" valign="top">&nbsp;</td>
405
			<td width="78%">
406
				<input name="if" type="hidden" value="<?=$if;?>" />
407
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
408
			</td>
409
			</tr>
410
		</table>
411
	</div>
412
</td>
413
</tr>
414
</table>
415
</form>
416

    
417
<script type="text/javascript">
418
//<![CDATA[
419
	jQuery(function ($) {
420
		var $rasamednsasdhcp6 = $("#rasamednsasdhcp6");
421
		var $triggered_checkboxes = $("#radns1, #radns2, #radns3, #radns4, #radomainsearchlist");
422
		if ($rasamednsasdhcp6.length !== 1) { return; }
423
		var onchange = function () {
424
			var checked = $rasamednsasdhcp6.is(":checked");
425
			if (checked) {
426
				$triggered_checkboxes.each(function () { this.disabled = true; });
427
			} else {
428
				$triggered_checkboxes.each(function () { this.disabled = false; });
429
			}
430
		};
431
		$rasamednsasdhcp6.bind("change", onchange);
432
		onchange();
433
	});
434

    
435
	var addressarray = <?= json_encode(get_alias_list("host", "network", "openvpn", "urltable")); ?>;
436
	var objAlias = [];
437
	function createAutoSuggest () {
438
		<?php for ($i = 0; $i < $counter; $i += 1) { ?>
439
			objAlias.push(new AutoSuggestControl(document.getElementById('subnet_address<?= $i ?>'), new StateSuggestions(addressarray)));
440
		<?php } ?>
441
		new AutoSuggestControl(document.getElementById('radns1'), new StateSuggestions(addressarray));
442
		new AutoSuggestControl(document.getElementById('radns2'), new StateSuggestions(addressarray));
443
		new AutoSuggestControl(document.getElementById('radns3'), new StateSuggestions(addressarray));
444
		new AutoSuggestControl(document.getElementById('radns4'), new StateSuggestions(addressarray));
445
	}
446
	setTimeout(createAutoSuggest, 500);
447
//]]>
448
</script>
449

    
450
<?php include("fend.inc"); ?>
451
</body>
452
</html>
(165-165/252)