Project

General

Profile

services_router_advertisements.php.patch

Marc Posch, 06/22/2014 05:23 PM

View differences:

services_router_advertisements.php 2014-06-01 03:40:58.757814500 +0200
98 98
	$pconfig['radomainsearchlist'] = $config['dhcpdv6'][$if]['radomainsearchlist'];
99 99
	list($pconfig['radns1'],$pconfig['radns2']) = $config['dhcpdv6'][$if]['radnsserver'];
100 100
	$pconfig['rasamednsasdhcp6'] = isset($config['dhcpdv6'][$if]['rasamednsasdhcp6']);
101 101

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

  
107 110
$advertise_modes = array("disabled" => "Disabled",
108 111
			 "router" => "Router Only",
109 112
			 "unmanaged" => "Unmanaged",
110 113
			 "managed" => "Managed",
......
116 119

  
117 120
$subnets_help = gettext("Subnets are specified in CIDR format.  " .
118 121
			"Select the CIDR mask that pertains to each entry.  " .
119 122
			"/128 specifies a single IPv6 host; /64 specifies a normal IPv6 network; etc.  " .
120 123
			"If no subnets are specified here, the Router Advertisement (RA) Daemon will advertise to the subnet to which the router's interface is assigned.");
124
			
125
$routes_help = gettext("Routes are specified in CIDR format. " .
126
			"Enter subnets to which routes should be advertised, and their priority. " .
127
			"If you need a default route, specify it with ::/0 here.  " .
128
			"If no routes are specified here, the Router Advertisement (RA) Daemon will advertise only the default route.");
121 129

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

  
125 133
	$pconfig = $_POST;
......
142 150
			$pconfig['subnets'][] = $address . "/" . $bits;
143 151
			if (!is_ipaddrv6($address))
144 152
				$input_errors[] = sprintf(gettext("An invalid subnet or alias was specified. [%s/%s]"), $address, $bits);
145 153
		}
146 154
	}
155
	
156
	$pconfig['routes'] = array();
157
	for ($x = 0; $x < 5000; $x += 1) {
158
		$address = trim($_POST['route_address' . $x]);
159
		if ($address === "")
160
			continue;
161

  
162
		$bits = trim($_POST['route_bits' . $x]);
163
		if ($bits === "")
164
			$bits = "128";
165
			
166
		$priority = trim($_POST['route_priority' . $x]);
167
		if ($priority === "")
168
			$priority = "medium";
147 169

  
170
		if (is_alias($address)) {
171
			$pconfig['routes'][] = array('destination' => $address);
172
		} else {
173
			$pconfig['routes'][] = array('destination' => $address . "/" . $bits, 'priority' => $priority);
174
			if (!is_ipaddrv6($address))
175
				$input_errors[] = sprintf(gettext("An invalid route was specified. [%s/%s]"), $address, $bits);
176
		}
177
	}
178
	
148 179
	if (($_POST['radns1'] && !is_ipaddrv6($_POST['radns1'])) || ($_POST['radns2'] && !is_ipaddrv6($_POST['radns2'])))
149 180
		$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary DNS servers.");
150 181
	if ($_POST['radomainsearchlist']) {
151 182
		$domain_array=preg_split("/[ ;]+/",$_POST['radomainsearchlist']);
152 183
		foreach ($domain_array as $curdomain) {
......
177 208
		if (count($pconfig['subnets'])) {
178 209
			$config['dhcpdv6'][$if]['subnets']['item'] = $pconfig['subnets'];
179 210
		} else {
180 211
			unset($config['dhcpdv6'][$if]['subnets']);
181 212
		}
213
		if (count($pconfig['routes'])) {
214
			$config['dhcpdv6'][$if]['routes']['item'] = $pconfig['routes'];
215
		} else {
216
			unset($config['dhcpdv6'][$if]['routes']);
217
		}
218

  
182 219

  
183 220
		write_config();
184 221
		$retval = services_radvd_configure();
185 222
		$savemsg = get_std_save_message($retval);
186 223
	}
......
200 237
<script type="text/javascript" src="/javascript/autosuggest.js">
201 238
</script>
202 239
<script type="text/javascript" src="/javascript/suggestions.js">
203 240
</script>
204 241
<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);
242
	function addrow_maintable () {
243
		field_counter_js = 2;
244
		rowname[0] = "subnet_address";
245
		rowtype[0] = "textbox";
246
		rowsize[0] = "30";
247
		rowname[1] = "subnet_bits";
248
		rowtype[1] = "select";
249
		rowsize[1] = "1";
250
		totalrows = totalrows_maintable;
251
		addRowTo('maintable');
252
		totalrows_maintable = totalrows;
253
	}
254
	function add_alias_control_maintable() {
255
		var name = "subnet_address" + (totalrows_maintable - 1);
213 256
		obj = document.getElementById(name);
214 257
		obj.setAttribute('class', 'formfldalias');
215 258
		obj.setAttribute('autocomplete', 'off');
216
		objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
259
		objAlias[totalrows_maintable - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
260
	}
261
	function addrow_routetable () {
262
		var opt = document.createElement("option");
263
		field_counter_js = 3;
264
		rowname[0] = "route_address";
265
		rowtype[0] = "textbox";
266
		rowsize[0] = "30";
267
		rowname[1] = "route_bits";
268
		rowtype[1] = "select";
269
		rowsize[1] = "1";
270
		rowname[2] = "route_priority";
271
		rowtype[2] = function (r_name, r_size, t_rows) {
272
						var str;
273
						<?php foreach($priority_modes as $name => $value) { ?>
274
						str = str + "<option value=\"" + "<?=$name ?>" + "\" >" + "<?=$value ?>"  + "</option>";
275
						<?php } ?>
276
						str = "<select size='" + r_size + "' name='" + r_name + t_rows + "' id='" + r_name + t_rows + "'>" + str + "</select> ";
277
						return str
278
					}
279
		rowsize[2] = "1";
280
		totalrows = totalrows_routetable;
281
		addRowTo('routetable');
282
		totalrows_routetable = totalrows;
283
		obj = document.getElementById("route_bits" + (totalrows_routetable - 1));
284
		obj.options.add(opt);
285
		opt.text = "0";
286
		opt.value = 0;
287
	}
288
	function add_alias_control_routetable() {
289
		var name = "route_address" + (totalrows_routetable - 1);
290
		obj = document.getElementById(name);
291
		obj.setAttribute('class', 'formfldalias');
292
		obj.setAttribute('autocomplete', 'off');
293
		objAlias[totalrows_routetable - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
217 294
	}
218 295
</script>
219 296

  
220 297
<form action="services_router_advertisements.php" method="post" name="iform" id="iform">
221 298
<?php if ($input_errors) print_input_errors($input_errors); ?>
......
343 420
				}
344 421
?>
345 422
				</tbody>
346 423
				</table>
347 424
				<script type="text/javascript">
348
					field_counter_js = 2;
349
					totalrows = <?= $counter ?>;
425
					totalrows_maintable = <?= $counter ?>;
350 426
				</script>
351 427
				<div id="addrowbutton">
352
					<a onclick="javascript:addRowTo('maintable'); add_alias_control(); return false;" href="#"><!--
428
					<a onclick="javascript:addrow_maintable(); add_alias_control_maintable(); return false;" href="#"><!--
429
					--><img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" /></a>
430
				</div>
431
			</td>
432
			</tr>
433
			
434
			<tr>
435
			<td width="22%" valign="top" class="vncell"><?=gettext("Routes");?></td>
436
			<td width="78%" class="vtable">
437
				<div><?= htmlentities($routes_help) ?></div>
438
				<table id="routetable">
439
				<tbody>
440
<?php
441
				$route_counter = 0;
442
				foreach ($pconfig['routes'] as $route) {
443
					$route_address_name = "route_address" . $route_counter;
444
					$route_bits_name = "route_bits" . $route_counter;
445
					$route_priority_name = "route_priority" . $route_counter;
446
					list($address, $mask) = explode("/", $route['destination']);
447
					$priority = $route['priority'];
448
?>
449
					<tr>
450
						<td>
451
							<input autocomplete="off" name="<?= $route_address_name ?>" type="text" class="formfldalias" id="<?= $route_address_name ?>" size="30" value="<?= htmlentities($address) ?>" />
452
						</td>
453
						<td>
454
							<select name="<?= $route_bits_name ?>" class="formselect" id="<?= $route_bits_name ?>">
455
							<option value="">
456
							<?php for ($i = 128; $i >= 0; $i -= 1) { ?>
457
								<option value="<?= $i ?>" <?= ("$mask" === "$i") ? "selected='selected'" : "" ?>><?= $i ?></option>
458
							<?php } ?>
459
							</select>
460
						</td>
461
						<td>
462
							<select name="<?= $route_priority_name ?>" class="formselect" id="<?= $route_priority_name ?>">
463
							<option value="">
464
							<?php foreach($priority_modes as $name => $value) { ?>
465
								<option value="<?=$name ?>" <?php if ($priority == $name) echo "selected='selected'" ?> > <?=$value ?></option>
466
							<?php } ?>
467
							</select>
468
						</td>
469
						<td>
470
							<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>
471
						</td>
472
					</tr>
473
<?php
474
					$route_counter += 1;
475
				}
476
?>
477
				</tbody>
478
				</table>
479
				<script type="text/javascript">
480
					totalrows_routetable = <?= $route_counter ?>;
481
				</script>
482
				<div id="addrowbutton">
483
					<a onclick="javascript:addrow_routetable(); add_alias_control_routetable(); return false;" href="#"><!--
353 484
					--><img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" /></a>
354 485
				</div>
355 486
			</td>
356 487
			</tr>
357 488

  
......
424 555
	var objAlias = [];
425 556
	function createAutoSuggest () {
426 557
		<?php for ($i = 0; $i < $counter; $i += 1) { ?>
427 558
			objAlias.push(new AutoSuggestControl(document.getElementById('subnet_address<?= $i ?>'), new StateSuggestions(addressarray)));
428 559
		<?php } ?>
560
		<?php for ($i = 0; $i < $route_counter; $i += 1) { ?>
561
			objAlias.push(new AutoSuggestControl(document.getElementById('route_address<?= $i ?>'), new StateSuggestions(addressarray)));
562
		<?php } ?>
429 563
		new AutoSuggestControl(document.getElementById('radns1'), new StateSuggestions(addressarray));
430 564
		new AutoSuggestControl(document.getElementById('radns2'), new StateSuggestions(addressarray));
431 565
	}
432 566
	setTimeout(createAutoSuggest, 500);
433 567
//]]>