Projet

Général

Profil

Télécharger (15,9 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_router_advertisements.php @ 6f3d2063

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']) = $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'])))
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
	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

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

    
177
		if (count($pconfig['subnets'])) {
178
			$config['dhcpdv6'][$if]['subnets']['item'] = $pconfig['subnets'];
179
		} else {
180
			unset($config['dhcpdv6'][$if]['subnets']);
181
		}
182

    
183
		write_config();
184
		$retval = services_radvd_configure();
185
		$savemsg = get_std_save_message($retval);
186
	}
187
}
188

    
189
$pgtitle = array(gettext("Services"),gettext("Router advertisements"));
190

    
191
include("head.inc");
192

    
193
?>
194

    
195
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
196
<?php include("fbegin.inc"); ?>
197

    
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
//<![CDATA[
206
	rowname[0] = "subnet_address";
207
	rowtype[0] = "textbox";
208
	rowsize[0] = "30";
209
	rowname[1] = "subnet_bits";
210
	rowtype[1] = "select";
211
	rowsize[1] = "1";
212
	function add_alias_control() {
213
		var name = "subnet_address" + (totalrows - 1);
214
		obj = document.getElementById(name);
215
		obj.setAttribute('class', 'formfldalias');
216
		obj.setAttribute('autocomplete', 'off');
217
		objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
218
	}
219
//]]>
220
</script>
221

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

    
314
			<tr>
315
			<td width="22%" valign="top" class="vncell"><?=gettext("RA Subnet(s)");?></td>
316
			<td width="78%" class="vtable">
317
				<div><?= htmlentities($subnets_help) ?></div>
318
				<table id="maintable" summary="subnets">
319
				<tbody>
320
<?php
321
				$counter = 0;
322
				foreach ($pconfig['subnets'] as $subnet) {
323
					$address_name = "subnet_address" . $counter;
324
					$bits_name = "subnet_bits" . $counter;
325
					list($address, $subnet) = explode("/", $subnet);
326
?>
327
					<tr>
328
						<td>
329
							<input autocomplete="off" name="<?= $address_name ?>" type="text" class="formfldalias" id="<?= $address_name ?>" size="30" value="<?= htmlentities($address) ?>" />
330
						</td>
331
						<td>
332
							<select name="<?= $bits_name ?>" class="formselect" id="<?= $bits_name ?>">
333
							<option value="">
334
							<?php for ($i = 128; $i >= 0; $i -= 1) { ?>
335
								<option value="<?= $i ?>" <?= ("$subnet" === "$i") ? "selected='selected'" : "" ?>><?= $i ?></option>
336
							<?php } ?>
337
							</select>
338
						</td>
339
						<td>
340
							<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>
341
						</td>
342
					</tr>
343
<?php
344
					$counter += 1;
345
				}
346
?>
347
				<tr style="display:none"><td></td></tr>
348
				</tbody>
349
				</table>
350
				<script type="text/javascript">
351
				//<![CDATA[
352
					field_counter_js = 2;
353
					totalrows = <?= $counter ?>;
354
				//]]>
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" class="list" height="12">&nbsp;</td>
365
			</tr>
366

    
367
			<tr>
368
			<td colspan="2" valign="top" class="listtopic">DNS</td>
369
			</tr>
370

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

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

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

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

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

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

    
441
<?php include("fend.inc"); ?>
442
</body>
443
</html>
(167-167/255)