Project

General

Profile

Download (15.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 (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
##|*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
##|-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
			if($olsrd['enable']) {
67
				$is_olsr_enabled = true;
68
				break;
69
			}
70
	}
71
}
72

    
73
if (!$_GET['if'])
74
	$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

    
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
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!preg_match("/fe80::/", $oc['ipaddrv6'])))) ||
84
			(!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!preg_match("/fe80::/", $oc['ipaddrv6'])))))
85
			continue;
86
		$if = $ifent;
87
		break;
88
	}
89
}
90

    
91
if (is_array($config['dhcpdv6'][$if])){
92
	/* 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
	$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

    
102
	$pconfig['subnets'] = $config['dhcpdv6'][$if]['subnets']['item'];
103
}
104
if (!is_array($pconfig['subnets'])) {
105
	$pconfig['subnets'] = array();
106
}
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

    
125
	unset($input_errors);
126

    
127
	$pconfig = $_POST;
128

    
129
	/* input validation */
130

    
131
	$pconfig['subnets'] = array();
132
	for ($x = 0; $x < 5000; $x += 1) {
133
		$address = trim($_POST['subnet_address' . $x]);
134
		$bits    = trim($_POST['subnet_bits' . $x]);
135
		if ($address === "") {
136
			continue;
137
		}
138
		if (is_ipaddrv6($address)) {
139
			if ($bits === "") {
140
				$pconfig['subnets'][] = $address . "/128";
141
			} else {
142
				$pconfig['subnets'][] = $address . "/" . $bits;
143
			}
144
		}
145
		else if (is_alias($address)) {
146
			$pconfig['subnets'][] = $address;
147
		}
148
		else {
149
			$input_errors[] = sprintf(gettext("An invalid subnet or alias was specified. [%s/%s]"), $address, $bits);
150
		}
151
	}
152

    
153
	if (($_POST['radns1'] && !is_ipaddrv6($_POST['radns1'])) || ($_POST['radns2'] && !is_ipaddrv6($_POST['radns2'])))
154
		$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary DNS servers.");
155
	if ($_POST['radomainsearchlist']) {
156
		$domain_array=preg_split("/[ ;]+/",$_POST['radomainsearchlist']);
157
		foreach ($domain_array as $curdomain) {
158
			if (!is_domain($curdomain)) {
159
				$input_errors[] = gettext("A valid domain search list must be specified.");
160
				break;
161
			}
162
		}
163
	}
164

    
165
	if (!$input_errors) {
166
		if (!is_array($config['dhcpdv6'][$if]))
167
			$config['dhcpdv6'][$if] = array();
168

    
169
		$config['dhcpdv6'][$if]['ramode'] = $_POST['ramode'];
170
		$config['dhcpdv6'][$if]['rapriority'] = $_POST['rapriority'];
171
		$config['dhcpdv6'][$if]['rainterface'] = $_POST['rainterface'];
172
		
173
		$config['dhcpdv6'][$if]['radomainsearchlist'] = $_POST['radomainsearchlist'];
174
		unset($config['dhcpdv6'][$if]['radnsserver']);
175
		if ($_POST['radns1'])
176
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns1'];
177
		if ($_POST['radns2'])
178
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns2'];
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">
206
</script>
207
<script type="text/javascript" src="/javascript/suggestions.js">
208
</script>
209
<script type="text/javascript">
210
	rowname[0] = "subnet_address";
211
	rowtype[0] = "textbox";
212
	rowsize[0] = "30";
213
	rowname[1] = "subnet_bits";
214
	rowtype[1] = "select";
215
	rowsize[1] = "1";
216
	function add_alias_control() {
217
		var name = "subnet_address" + (totalrows - 1);
218
		obj = document.getElementById(name);
219
		obj.setAttribute('class', 'formfldalias');
220
		obj.setAttribute('autocomplete', 'off');
221
		objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
222
	}
223
</script>
224

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

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

    
363
			<tr>
364
			<td colspan="2" valign="top" class="listtopic">DNS</td>
365
			</tr>
366

    
367
			<tr>
368
			<td width="22%" valign="top" class="vncell"><?=gettext("DNS servers");?></td>
369
			<td width="78%" class="vtable">
370
				<input name="radns1" type="text" class="formfldalias" id="radns1" size="28" value="<?=htmlspecialchars($pconfig['radns1']);?>"><br>
371
				<input name="radns2" type="text" class="formfldalias" id="radns2" size="28" value="<?=htmlspecialchars($pconfig['radns2']);?>"><br>
372
				<?=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.");?>
373
			</td>
374
			</tr>
375

    
376
			<tr>
377
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain search list");?></td>
378
			<td width="78%" class="vtable">
379
				<input name="radomainsearchlist" type="text" class="formfld unknown" id="radomainsearchlist" size="28" value="<?=htmlspecialchars($pconfig['radomainsearchlist']);?>"><br>
380
				<?=gettext("The RA server can optionally provide a domain search list. Use the semicolon character as seperator");?>
381
			</td>
382
			</tr>
383

    
384
			<tr>
385
			<td width="22%" valign="top" class="vncell">&nbsp;</td>
386
			<td width="78%" class="vtable">
387
				<input id="rasamednsasdhcp6" name="rasamednsasdhcp6" type="checkbox" value="yes" <?php if ($pconfig['rasamednsasdhcp6']) { echo "checked='checked'"; } ?> />
388
				<strong><?= gettext("Use same settings as DHCPv6 server"); ?></strong>
389
			</td>
390
			</tr>
391

    
392
			<tr>
393
			<td width="22%" valign="top">&nbsp;</td>
394
			<td width="78%">
395
				<input name="if" type="hidden" value="<?=$if;?>" />
396
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
397
			</td>
398
			</tr>
399
		</table>
400
	</div>
401
</td>
402
</tr>
403
</table>
404
</form>
405

    
406
<script language="JavaScript">
407
//<![CDATA[
408
	jQuery(function ($) {
409
		var $rasamednsasdhcp6 = $("#rasamednsasdhcp6");
410
		var $triggered_checkboxes = $("#radns1, #radns2, #radomainsearchlist");
411
		if ($rasamednsasdhcp6.length !== 1) { return; }
412
		var onchange = function () {
413
			var checked = $rasamednsasdhcp6.is(":checked");
414
			if (checked) {
415
				$triggered_checkboxes.each(function () { this.disabled = true; });
416
			} else {
417
				$triggered_checkboxes.each(function () { this.disabled = false; });
418
			}
419
		};
420
		$rasamednsasdhcp6.bind("change", onchange);
421
		onchange();
422
	});
423

    
424
	var addressarray = <?= json_encode(get_alias_list("host", "network", "openvpn", "urltable")); ?>;
425
	var objAlias = [];
426
	function createAutoSuggest () {
427
		<?php for ($i = 0; $i < $counter; $i += 1) { ?>
428
			objAlias.push(new AutoSuggestControl(document.getElementById('subnet_address<?= $i ?>'), new StateSuggestions(addressarray)));
429
		<?php } ?>
430
		new AutoSuggestControl(document.getElementById('radns1'), new StateSuggestions(addressarray));
431
		new AutoSuggestControl(document.getElementById('radns2'), new StateSuggestions(addressarray));
432
	}
433
	setTimeout(createAutoSuggest, 500);
434
//]]>
435
</script>
436

    
437
<?php include("fend.inc"); ?>
438
</body>
439
</html>
(165-165/249)