Project

General

Profile

Download (16.7 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / services_router_advertisements.php @ a1b66bec

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
	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']) && (!is_linklocal($oc['ipaddrv6'])))) ||
84
			(!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($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'],$pconfig['radns3'],$pconfig['radns4']) = $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
$advertise_modes = array("disabled" => "Disabled",
108
			 "router" => "Router Only",
109
			 "unmanaged" => "Unmanaged",
110
			 "managed" => "Managed",
111
			 "assist" => "Assisted");
112
$priority_modes = array("low" => "Low",
113
			"medium" => "Normal",
114
			"high" => "High");
115
$carplist = get_configured_carp_interface_list();
116

    
117
$subnets_help = gettext("Subnets are specified in CIDR format.  " .
118
			"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

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

    
125
	$pconfig = $_POST;
126

    
127
	/* input validation */
128

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

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

    
139
		if (is_alias($address)) {
140
			$pconfig['subnets'][] = $address;
141
		} 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
		}
146
	}
147

    
148
	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'])))
149
		$input_errors[] = gettext("A valid IPv6 address must be specified for each of the 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
	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

    
168
		$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
		if ($_POST['radns3'])
175
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns3'];
176
		if ($_POST['radns4'])
177
			$config['dhcpdv6'][$if]['radnsserver'][] = $_POST['radns4'];
178

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

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

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

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

    
195
include("head.inc");
196

    
197
?>
198

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

    
202
<script type="text/javascript" src="/javascript/row_helper.js">
203
</script>
204
<script type="text/javascript" src="/javascript/autosuggest.js">
205
</script>
206
<script type="text/javascript" src="/javascript/suggestions.js">
207
</script>
208
<script type="text/javascript">
209
//<![CDATA[
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
//]]>
224
</script>
225

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

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

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

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

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

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

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

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

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

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

    
449
<?php include("fend.inc"); ?>
450
</body>
451
</html>
(168-168/256)