Project

General

Profile

Download (27.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_gateways_edit.php
5
	part of pfSense (http://pfsense.com)
6

    
7
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_MODULE:	routing
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-system-gateways-editgateway
37
##|*NAME=System: Gateways: Edit Gateway page
38
##|*DESCR=Allow access to the 'System: Gateways: Edit Gateway' page.
39
##|*MATCH=system_gateways_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require("pkg-utils.inc");
44

    
45
$a_gateways = return_gateways_array(true);
46
$a_gateways_arr = array();
47
foreach($a_gateways as $gw) {
48
	$a_gateways_arr[] = $gw;
49
}
50
$a_gateways = $a_gateways_arr;
51

    
52
if (!is_array($config['gateways']['gateway_item']))
53
	$config['gateways']['gateway_item'] = array();
54

    
55
$a_gateway_item = &$config['gateways']['gateway_item'];
56
$apinger_default = return_apinger_defaults();
57

    
58
$id = $_GET['id'];
59
if (isset($_POST['id']))
60
	$id = $_POST['id'];
61

    
62
if (isset($_GET['dup'])) {
63
	$id = $_GET['dup'];
64
}
65

    
66
if (isset($id) && $a_gateways[$id]) {
67
	$pconfig = array();
68
	$pconfig['name'] = $a_gateways[$id]['name'];
69
	$pconfig['weight'] = $a_gateways[$id]['weight'];
70
	$pconfig['interval'] = $a_gateways[$id]['interval'];
71
	$pconfig['interface'] = $a_gateways[$id]['interface'];
72
	$pconfig['friendlyiface'] = $a_gateways[$id]['friendlyiface'];
73
	$pconfig['ipprotocol'] = $a_gateways[$id]['ipprotocol'];
74
	if (isset($a_gateways[$id]['dynamic']))
75
		$pconfig['dynamic'] = true;
76
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
77
	$pconfig['defaultgw'] = isset($a_gateways[$id]['defaultgw']);
78
	$pconfig['latencylow'] = $a_gateway_item[$id]['latencylow'];
79
	$pconfig['latencyhigh'] = $a_gateway_item[$id]['latencyhigh'];
80
	$pconfig['losslow'] = $a_gateway_item[$id]['losslow'];
81
	$pconfig['losshigh'] = $a_gateway_item[$id]['losshigh'];
82
	$pconfig['down'] = $a_gateway_item[$id]['down'];
83
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
84
	$pconfig['monitor_disable'] = isset($a_gateways[$id]['monitor_disable']);
85
	$pconfig['descr'] = $a_gateways[$id]['descr'];
86
	$pconfig['attribute'] = $a_gateways[$id]['attribute'];
87
}
88

    
89
if (isset($_GET['dup'])) {
90
	unset($id);
91
	unset($pconfig['attribute']);
92
}
93

    
94
if ($_POST) {
95

    
96
	unset($input_errors);
97

    
98
	/* input validation */
99
	$reqdfields = explode(" ", "name interface");
100
	$reqdfieldsn = array(gettext("Name"), gettext("Interface"));
101

    
102
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
103

    
104
	if (! isset($_POST['name'])) {
105
		$input_errors[] = "A valid gateway name must be specified.";
106
	}
107
	if (! is_validaliasname($_POST['name'])) {
108
		$input_errors[] = gettext("The gateway name must not contain invalid characters.");
109
	}
110
	/* skip system gateways which have been automatically added */
111
	if (($_POST['gateway'] && (!is_ipaddr($_POST['gateway'])) && ($_POST['attribute'] !== "system")) && ($_POST['gateway'] != "dynamic")) {
112
		$input_errors[] = gettext("A valid gateway IP address must be specified.");
113
	}
114

    
115
	if ($_POST['gateway'] && (is_ipaddr($_POST['gateway'])) && !$_REQUEST['isAjax']) {
116
		if(is_ipaddrv4($_POST['gateway'])) {
117
			$parent_ip = get_interface_ip($_POST['interface']);
118
			$parent_sn = get_interface_subnet($_POST['interface']);
119
			if(empty($parent_ip) || empty($parent_sn)) {
120
				$input_errors[] = gettext("You can not use a IPv4 Gateway Address on a IPv6 only interface.");
121
			} else {
122
				$subnets = array(gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn);
123
				$vips = link_interface_to_vips($_POST['interface']);
124
				if (is_array($vips))
125
					foreach($vips as $vip) {
126
						if (!is_ipaddrv4($vip['subnet']))
127
							continue;
128
						$subnets[] = gen_subnet($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits'];
129
					}
130

    
131
				$found = false;
132
				foreach($subnets as $subnet)
133
					if(ip_in_subnet($_POST['gateway'], $subnet)) {
134
						$found = true;
135
						break;
136
					}
137

    
138
				if ($found === false)
139
					$input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within one of the chosen interface's subnets."), $_POST['gateway']);
140
			}
141
		}
142
		else if(is_ipaddrv6($_POST['gateway'])) {
143
			/* do not do a subnet match on a link local address, it's valid */
144
			if(!is_linklocal($_POST['gateway'])) {
145
				$parent_ip = get_interface_ipv6($_POST['interface']);
146
				$parent_sn = get_interface_subnetv6($_POST['interface']);
147
				if(empty($parent_ip) || empty($parent_sn)) {
148
					$input_errors[] = gettext("You can not use a IPv6 Gateway Address on a IPv4 only interface.");
149
				} else {
150
					$subnets = array(gen_subnetv6($parent_ip, $parent_sn) . "/" . $parent_sn);
151
					$vips = link_interface_to_vips($_POST['interface']);
152
					if (is_array($vips))
153
						foreach($vips as $vip) {
154
							if (!is_ipaddrv6($vip['subnet']))
155
								continue;
156
							$subnets[] = gen_subnetv6($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits'];
157
						}
158

    
159
					$found = false;
160
					foreach($subnets as $subnet)
161
						if(ip_in_subnet($_POST['gateway'], $subnet)) {
162
							$found = true;
163
							break;
164
						}
165

    
166
					if ($found === false)
167
						$input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within one of the chosen interface's subnets."), $_POST['gateway']);
168
				}
169
			}
170
		}
171

    
172
		if (!empty($config['interfaces'][$_POST['interface']]['ipaddr'])) {
173
			if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddr']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic"))
174
				$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv4 configuration.");
175
		}
176
		if (!empty($config['interfaces'][$_POST['interface']]['ipaddrv6'])) {
177
			if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddrv6']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic"))
178
				$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv6 configuration.");
179
		}
180
	}
181
	if (($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") {
182
		$input_errors[] = gettext("A valid monitor IP address must be specified.");
183
	}
184
	/* only allow correct IPv4 and IPv6 gateway addresses */
185
	if (($_POST['gateway'] <> "") && is_ipaddr($_POST['gateway']) && $_POST['gateway'] != "dynamic") {
186
		if(is_ipaddrv6($_POST['gateway']) && ($_POST['ipprotocol'] == "inet")) {
187
			$input_errors[] = gettext("The IPv6 gateway address '{$_POST['gateway']}' can not be used as a IPv4 gateway'.");
188
		}
189
		if(is_ipaddrv4($_POST['gateway']) && ($_POST['ipprotocol'] == "inet6")) {
190
			$input_errors[] = gettext("The IPv4 gateway address '{$_POST['gateway']}' can not be used as a IPv6 gateway'.");
191
		}
192
	}
193
	/* only allow correct IPv4 and IPv6 monitor addresses */
194
	if (($_POST['monitor'] <> "") && is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") {
195
		if(is_ipaddrv6($_POST['monitor']) && ($_POST['ipprotocol'] == "inet")) {
196
			$input_errors[] = gettext("The IPv6 monitor address '{$_POST['monitor']}' can not be used on a IPv4 gateway'.");
197
		}
198
		if(is_ipaddrv4($_POST['monitor']) && ($_POST['ipprotocol'] == "inet6")) {
199
			$input_errors[] = gettext("The IPv4 monitor address '{$_POST['monitor']}' can not be used on a IPv6 gateway'.");
200
		}
201
	}
202

    
203
	if (isset($_POST['name'])) {
204
		/* check for overlaps */
205
		foreach ($a_gateways as $gateway) {
206
			if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway)) {
207
				if ($gateway['name'] != $_POST['name'])
208
					$input_errors[] = gettext("Changing name on a gateway is not allowed.");
209
				continue;
210
			}
211
			if($_POST['name'] <> "") {
212
				if (($gateway['name'] <> "") && ($_POST['name'] == $gateway['name']) && ($gateway['attribute'] !== "system")) {
213
					$input_errors[] = sprintf(gettext('The gateway name "%s" already exists.'), $_POST['name']);
214
					break;
215
				}
216
			}
217
			if(is_ipaddr($_POST['gateway'])) {
218
				if (($gateway['gateway'] <> "") && ($_POST['gateway'] == $gateway['gateway']) && ($gateway['attribute'] !== "system")) {
219
					$input_errors[] = sprintf(gettext('The gateway IP address "%s" already exists.'), $_POST['gateway']);
220
					break;
221
				}
222
			}
223
			if(is_ipaddr($_POST['monitor'])) {
224
				if (($gateway['monitor'] <> "") && ($_POST['monitor'] == $gateway['monitor']) && ($gateway['attribute'] !== "system")) {
225
					$input_errors[] = sprintf(gettext('The monitor IP address "%s" is already in use. You must choose a different monitor IP.'), $_POST['monitor']);
226
					break;
227
				}
228
			}
229
		}
230
	}
231

    
232
	/* input validation of apinger advanced parameters */
233
	if($_POST['latencylow']) {
234
		if (! is_numeric($_POST['latencylow'])) {
235
			$input_errors[] = gettext("The low latency threshold needs to be a numeric value.");
236
		} else {
237
			if ($_POST['latencylow'] < 1) {
238
				$input_errors[] = gettext("The low latency threshold needs to be positive.");
239
			}
240
		}
241
	}
242

    
243
	if($_POST['latencyhigh']) {
244
		if (! is_numeric($_POST['latencyhigh'])) {
245
			$input_errors[] = gettext("The high latency threshold needs to be a numeric value.");
246
		} else {
247
			if ($_POST['latencyhigh'] < 1) {
248
				$input_errors[] = gettext("The high latency threshold needs to be positive.");
249
			}
250
		}
251
	}
252

    
253
	if($_POST['losslow']) {
254
		if (! is_numeric($_POST['losslow'])) {
255
			$input_errors[] = gettext("The low Packet Loss threshold needs to be a numeric value.");
256
		} else {
257
			if ($_POST['losslow'] < 1) {
258
				$input_errors[] = gettext("The low Packet Loss threshold needs to be positive.");
259
			}
260
			if ($_POST['losslow'] >= 100) {
261
				$input_errors[] = gettext("The low Packet Loss threshold needs to be less than 100.");
262
			}
263
		}
264
	}
265

    
266
	if($_POST['losshigh']) {
267
		if (! is_numeric($_POST['losshigh'])) {
268
			$input_errors[] = gettext("The high Packet Loss threshold needs to be a numeric value.");
269
		} else {
270
			if ($_POST['losshigh'] < 1) {
271
				$input_errors[] = gettext("The high Packet Loss threshold needs to be positive.");
272
			}
273
			if ($_POST['losshigh'] > 100) {
274
				$input_errors[] = gettext("The high Packet Loss threshold needs to be 100 or less.");
275
			}
276
		}
277
	}
278

    
279
	if(($_POST['latencylow']) && ($_POST['latencyhigh'])) {
280
		if ((is_numeric($_POST['latencylow'])) && (is_numeric($_POST['latencyhigh']))) {
281
			if(($_POST['latencylow'] > $_POST['latencyhigh'])) {
282
				$input_errors[] = gettext("The high latency threshold needs to be higher than the low latency threshold");
283
			}
284
		}
285
	} else {
286
		if($_POST['latencylow']){
287
			if (is_numeric($_POST['latencylow'])) {
288
				if($_POST['latencylow'] > $apinger_default['latencyhigh']) {
289
					$input_errors[] = gettext(sprintf("The low latency threshold needs to be less than the default high latency threshold (%d)", $apinger_default['latencyhigh']));
290
				}
291
			}
292
		}
293
		if($_POST['latencyhigh']){
294
			if (is_numeric($_POST['latencyhigh'])) {
295
				if($_POST['latencyhigh'] < $apinger_default['latencylow']) {
296
					$input_errors[] = gettext(sprintf("The high latency threshold needs to be higher than the default low latency threshold (%d)", $apinger_default['latencylow']));
297
				}
298
			}
299
		}
300
	}
301

    
302
	if(($_POST['losslow']) && ($_POST['losshigh'])){
303
		if ((is_numeric($_POST['losslow'])) && (is_numeric($_POST['losshigh']))) {
304
			if($_POST['losslow'] > $_POST['losshigh']) {
305
				$input_errors[] = gettext("The high Packet Loss threshold needs to be higher than the low Packet Loss threshold");
306
			}
307
		}
308
	} else {
309
		if($_POST['losslow']){
310
			if (is_numeric($_POST['losslow'])) {
311
				if($_POST['losslow'] > $apinger_default['losshigh']) {
312
					$input_errors[] = gettext(sprintf("The low Packet Loss threshold needs to be less than the default high Packet Loss threshold (%d)", $apinger_default['losshigh']));
313
				}
314
			}
315
		}
316
		if($_POST['losshigh']){
317
			if (is_numeric($_POST['losshigh'])) {
318
				if($_POST['losshigh'] < $apinger_default['losslow']) {
319
					$input_errors[] = gettext(sprintf("The high Packet Loss threshold needs to be higher than the default low Packet Loss threshold (%d)", $apinger_default['losslow']));
320
				}
321
			}
322
		}
323
	}
324

    
325
	if($_POST['interval']) {
326
		if (! is_numeric($_POST['interval'])) {
327
			$input_errors[] = gettext("The probe interval needs to be a numeric value.");
328
		} else {
329
			if ($_POST['interval'] < 1) {
330
				$input_errors[] = gettext("The probe interval needs to be positive.");
331
			}
332
		}
333
	}
334

    
335
	if($_POST['down']) {
336
		if (! is_numeric($_POST['down'])) {
337
			$input_errors[] = gettext("The down time setting needs to be a numeric value.");
338
		} else {
339
			if ($_POST['down'] < 1) {
340
				$input_errors[] = gettext("The down time setting needs to be positive.");
341
			}
342
		}
343
	}
344

    
345
	if(($_POST['interval']) && ($_POST['down'])){
346
		if ((is_numeric($_POST['interval'])) && (is_numeric($_POST['down']))) {
347
			if($_POST['interval'] > $_POST['down']) {
348
				$input_errors[] = gettext("The probe interval needs to be less than the down time setting.");
349
			}
350
		}
351
	} else {
352
		if($_POST['interval']){
353
			if (is_numeric($_POST['interval'])) {
354
				if($_POST['interval'] > $apinger_default['down']) {
355
					$input_errors[] = gettext(sprintf("The probe interval needs to be less than the default down time setting (%d)", $apinger_default['down']));
356
				}
357
			}
358
		}
359
		if($_POST['down']){
360
			if (is_numeric($_POST['down'])) {
361
				if($_POST['down'] < $apinger_default['interval']) {
362
					$input_errors[] = gettext(sprintf("The down time setting needs to be higher than the default probe interval (%d)", $apinger_default['interval']));
363
				}
364
			}
365
		}
366
	}
367

    
368
	if (!$input_errors) {
369
		$reloadif = "";
370
		$gateway = array();
371

    
372
		if (empty($_POST['interface']))
373
			$gateway['interface'] = $pconfig['friendlyiface'];
374
		else
375
			$gateway['interface'] = $_POST['interface'];
376
		if (is_ipaddr($_POST['gateway']))
377
			$gateway['gateway'] = $_POST['gateway'];
378
		else
379
			$gateway['gateway'] = "dynamic";
380
		$gateway['name'] = $_POST['name'];
381
		$gateway['weight'] = $_POST['weight'];
382
		$gateway['ipprotocol'] = $_POST['ipprotocol'];
383
		$gateway['interval'] = $_POST['interval'];
384
		$gateway['descr'] = $_POST['descr'];
385
		if ($_POST['monitor_disable'] == "yes")
386
			$gateway['monitor_disable'] = true;
387
		else if (is_ipaddr($_POST['monitor'])) {
388
			/* NOTE: If monitor ip is changed need to cleanup the old static route */
389
			if ($_POST['monitor'] != "dynamic" && !empty($a_gateway_item[$id]) && is_ipaddr($a_gateway_item[$id]['monitor']) &&
390
			    $_POST['monitor'] != $a_gateway_item[$id]['monitor'] && $gateway['gateway'] != $a_gateway_item[$id]['monitor']) {
391
				if (is_ipaddrv4($a_gateway_item[$id]['monitor']))
392
					mwexec("/sbin/route delete " . escapeshellarg($a_gateway_item[$id]['monitor']));
393
				else
394
					mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateway_item[$id]['monitor']));
395
			}
396
			$gateway['monitor'] = $_POST['monitor'];
397
		}
398

    
399
		if ($_POST['defaultgw'] == "yes" || $_POST['defaultgw'] == "on") {
400
			$i = 0;
401
			/* remove the default gateway bits for all gateways with the same address family */
402
			foreach($a_gateway_item as $gw) {
403
				if ($gateway['ipprotocol'] == $gw['ipprotocol']) {
404
					unset($config['gateways']['gateway_item'][$i]['defaultgw']);
405
					if ($gw['interface'] != $_POST['interface'] && $gw['defaultgw'])
406
						$reloadif = $gw['interface'];
407
				}
408
				$i++;
409
			}
410
			$gateway['defaultgw'] = true;
411
		}
412

    
413
		if ($_POST['latencylow'])
414
			$gateway['latencylow'] = $_POST['latencylow'];
415
		if ($_POST['latencyhigh'])
416
			$gateway['latencyhigh'] = $_POST['latencyhigh'];
417
		if ($_POST['losslow'])
418
			$gateway['losslow'] = $_POST['losslow'];
419
		if ($_POST['losshigh'])
420
			$gateway['losshigh'] = $_POST['losshigh'];
421
		if ($_POST['down'])
422
			$gateway['down'] = $_POST['down'];
423

    
424
		/* when saving the manual gateway we use the attribute which has the corresponding id */
425
		if (isset($id) && $a_gateway_item[$id])
426
			$a_gateway_item[$id] = $gateway;
427
		else
428
			$a_gateway_item[] = $gateway;
429

    
430
		mark_subsystem_dirty('staticroutes');
431

    
432
		write_config();
433

    
434
		if($_REQUEST['isAjax']) {
435
			echo $_POST['name'];
436
			exit;
437
		} else if (!empty($reloadif))
438
			send_event("interface reconfigure {$reloadif}");
439

    
440
		header("Location: system_gateways.php");
441
		exit;
442
	} else {
443
		if ($_REQUEST['isAjax']) {
444
			header("HTTP/1.0 500 Internal Server Error");
445
			header("Content-type: text/plain");
446
			foreach ($input_errors as $error) {
447
				echo("$error\n");
448
			}
449
			exit;
450
		}
451

    
452
		$pconfig = $_POST;
453
		if (empty($_POST['friendlyiface']))
454
			$pconfig['friendlyiface'] = $_POST['interface'];
455
	}
456
}
457

    
458

    
459
$pgtitle = array(gettext("System"),gettext("Gateways"),gettext("Edit gateway"));
460
$shortcut_section = "gateways";
461

    
462
include("head.inc");
463

    
464
?>
465

    
466
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
467
<?php include("fbegin.inc"); ?>
468
<script type="text/javascript">
469
//<![CDATA[
470
function show_advanced_gateway() {
471
	document.getElementById("showadvgatewaybox").innerHTML='';
472
	aodiv = document.getElementById('showgatewayadv');
473
	aodiv.style.display = "block";
474
}
475
function monitor_change() {
476
	document.iform.monitor.disabled = document.iform.monitor_disable.checked;
477
}
478
//]]>
479
</script>
480
<?php if ($input_errors) print_input_errors($input_errors); ?>
481
	<form action="system_gateways_edit.php" method="post" name="iform" id="iform">
482
	<?php
483

    
484
	/* If this is a system gateway we need this var */
485
	if(($pconfig['attribute'] == "system") || is_numeric($pconfig['attribute'])) {
486
		echo "<input type='hidden' name='attribute' id='attribute' value=\"" . htmlspecialchars($pconfig['attribute']) . "\" />\n";
487
	}
488
	echo "<input type='hidden' name='friendlyiface' id='friendlyiface' value=\"" . htmlspecialchars($pconfig['friendlyiface']) . "\" />\n";
489
	?>
490
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="system gateways edit">
491
			<tr>
492
				<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit gateway"); ?></td>
493
			</tr>
494
			<tr>
495
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
496
				<td width="78%" class="vtable">
497
					<select name='interface' class='formselect'>
498
					<?php
499
						$interfaces = get_configured_interface_with_descr(false, true);
500
						foreach ($interfaces as $iface => $ifacename) {
501
							echo "<option value=\"{$iface}\"";
502
							if ($iface == $pconfig['friendlyiface'])
503
								echo " selected='selected'";
504
							echo ">" . htmlspecialchars($ifacename) . "</option>";
505
						}
506
						if (is_package_installed("openbgpd") == 1) {
507
							echo "<option value=\"bgpd\"";
508
							if ($pconfig['interface'] == "bgpd")
509
								echo " selected='selected'";
510
							echo ">" . gettext("Use BGPD") . "</option>";
511
						}
512
					?>
513
					</select><br/>
514
					<span class="vexpl"><?=gettext("Choose which interface this gateway applies to."); ?></span>
515
				</td>
516
			</tr>
517
			<tr>
518
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Address Family"); ?></td>
519
				<td width="78%" class="vtable">
520
					<select name='ipprotocol' class='formselect' >
521
					<?php
522
						$options = array("inet" => "IPv4", "inet6" => "IPv6");
523
						foreach ($options as $name => $string) {
524
							echo "<option value=\"{$name}\"";
525
							if ($name == $pconfig['ipprotocol'])
526
								echo " selected='selected'";
527
							echo ">" . htmlspecialchars($string) . "</option>\n";
528
						}
529
					?>
530
					</select><br/>
531
					<span class="vexpl"><?=gettext("Choose the Internet Protocol this gateway uses."); ?></span>
532
				</td>
533
			</tr>
534
			<tr>
535
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
536
				<td width="78%" class="vtable">
537
					<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" />
538
					<br/><span class="vexpl"><?=gettext("Gateway name"); ?></span>
539
				</td>
540
			</tr>
541
			<tr>
542
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway"); ?></td>
543
				<td width="78%" class="vtable">
544
					<input name="gateway" type="text" class="formfld host" id="gateway" size="28" value="<?php if ($pconfig['dynamic']) echo "dynamic"; else echo htmlspecialchars($pconfig['gateway']); ?>" />
545
					<br/><span class="vexpl"><?=gettext("Gateway IP address"); ?></span>
546
				</td>
547
			</tr>
548
			<tr>
549
				<td width="22%" valign="top" class="vncell"><?=gettext("Default Gateway"); ?></td>
550
				<td width="78%" class="vtable">
551
					<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if ($pconfig['defaultgw'] == true) echo "checked=\"checked\""; ?> />
552
					<strong><?=gettext("Default Gateway"); ?></strong><br />
553
					<?=gettext("This will select the above gateway as the default gateway"); ?>
554
				</td>
555
			</tr>
556
			<tr>
557
				<td width="22%" valign="top" class="vncell"><?=gettext("Disable Gateway Monitoring"); ?></td>
558
				<td width="78%" class="vtable">
559
					<input name="monitor_disable" type="checkbox" id="monitor_disable" value="yes" <?php if ($pconfig['monitor_disable'] == true) echo "checked=\"checked\""; ?> onclick="monitor_change()" />
560
					<strong><?=gettext("Disable Gateway Monitoring"); ?></strong><br />
561
					<?=gettext("This will consider this gateway as always being up"); ?>
562
				</td>
563
			</tr>
564
			<tr>
565
				<td width="22%" valign="top" class="vncell"><?=gettext("Monitor IP"); ?></td>
566
				<td width="78%" class="vtable">
567
					<?php
568
						if ($pconfig['gateway'] == $pconfig['monitor'])
569
							$monitor = "";
570
						else
571
							$monitor = htmlspecialchars($pconfig['monitor']);
572
					?>
573
					<input name="monitor" type="text" id="monitor" value="<?php echo htmlspecialchars($monitor); ?>" size="28" />
574
					<strong><?=gettext("Alternative monitor IP"); ?></strong> <br />
575
					<?=gettext("Enter an alternative address here to be used to monitor the link. This is used for the " .
576
					"quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond " .
577
					"to ICMP echo requests (pings)"); ?>.
578
					<br />
579
				</td>
580
			</tr>
581
			<tr>
582
				<td width="22%" valign="top" class="vncell"><?=gettext("Advanced");?></td>
583
				<td width="78%" class="vtable">
584
					<?php $showbutton = (!empty($pconfig['latencylow']) || !empty($pconfig['latencyhigh']) || !empty($pconfig['losslow']) || !empty($pconfig['losshigh']) || (isset($pconfig['weight']) && $pconfig['weight'] > 1) || (isset($pconfig['interval']) && ($pconfig['interval'] > $apinger_default['interval'])) || (isset($pconfig['down']) && !($pconfig['down'] == $apinger_default['down']))); ?>
585
					<div id="showadvgatewaybox" <?php if ($showbutton) echo "style='display:none'"; ?>>
586
						<input type="button" onclick="show_advanced_gateway()" value="Advanced" /><?=gettext(" - Show advanced option"); ?>
587
					</div>
588
					<div id="showgatewayadv" <?php if (!$showbutton) echo "style='display:none'"; ?>>
589
						<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="6" summary="advanced options">
590
							<tr>
591
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Weight");?></td>
592
								<td width="78%" class="vtable">
593
									<select name='weight' class='formfldselect' id='weight'>
594
									<?php
595
										for ($i = 1; $i < 6; $i++) {
596
											$selected = "";
597
											if ($pconfig['weight'] == $i)
598
												$selected = "selected='selected'";
599
											echo "<option value='{$i}' {$selected} >{$i}</option>";
600
										}
601
									?>
602
									</select>
603
									<br /><?=gettext("Weight for this gateway when used in a Gateway Group.");?> <br />
604
								</td>
605
							</tr>
606
							<tr>
607
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Latency thresholds");?></td>
608
								<td width="78%" class="vtable">
609
									<?=gettext("From");?>
610
									<input name="latencylow" type="text" class="formfld unknown" id="latencylow" size="2"
611
										value="<?=htmlspecialchars($pconfig['latencylow']);?>" />
612
									<?=gettext("To");?>
613
									<input name="latencyhigh" type="text" class="formfld unknown" id="latencyhigh" size="2"
614
										value="<?=htmlspecialchars($pconfig['latencyhigh']);?>" />
615
									<br/><span class="vexpl"><?=gettext(sprintf("Low and high thresholds for latency in milliseconds. Default is %d/%d.", $apinger_default['latencylow'], $apinger_default['latencyhigh']));?></span>
616
								</td>
617
							</tr>
618
							<tr>
619
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Packet Loss thresholds");?></td>
620
								<td width="78%" class="vtable">
621
									<?=gettext("From");?>
622
									<input name="losslow" type="text" class="formfld unknown" id="losslow" size="2"
623
										value="<?=htmlspecialchars($pconfig['losslow']);?>" />
624
									<?=gettext("To");?>
625
									<input name="losshigh" type="text" class="formfld unknown" id="losshigh" size="2"
626
										value="<?=htmlspecialchars($pconfig['losshigh']);?>" />
627
									<br /><span class="vexpl"><?=gettext(sprintf("Low and high thresholds for packet loss in %%. Default is %d/%d.", $apinger_default['losslow'], $apinger_default['losshigh']));?></span>
628
								</td>
629
							</tr>
630
							<tr>
631
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Probe Interval");?></td>
632
								<td width="78%" class="vtable">
633
									<input name="interval" type="text" class="formfld unknown" id="interval" size="2"
634
										value="<?=htmlspecialchars($pconfig['interval']);?>" />
635
									<br/><span class="vexpl">
636
										<?=gettext(sprintf("How often that an ICMP probe will be sent in seconds. Default is %d.", $apinger_default['interval']));?><br/><br/>
637
										<?=gettext("NOTE: The quality graph is averaged over seconds, not intervals, so as the probe interval is increased the accuracy of the quality graph is decreased.");?>
638
									</span>
639
								</td>
640
							</tr>
641
							<tr>
642
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Down");?></td>
643
								<td width="78%" class="vtable">
644
									<input name="down" type="text" class="formfld unknown" id="down" size="2"
645
										value="<?=htmlspecialchars($pconfig['down']);?>" />
646
									<br/><span class="vexpl"><?=gettext(sprintf("The number of seconds of failed probes before the alarm will fire. Default is %d.", $apinger_default['down']));?></span>
647
								</td>
648
							</tr>
649
							<tr>
650
								<td colspan="2">
651
									<?= gettext("The probe interval must be less than the down time, otherwise the gateway will seem to go down then come up again at the next probe."); ?><br/><br/>
652
									<?= gettext("The down time defines the length of time before the gateway is marked as down, but the accuracy is controlled by the probe interval. For example, if your down time is 40 seconds but on a 30 second probe interval, only one probe would have to fail before the gateway is marked down at the 40 second mark. By default, the gateway is considered down after 10 seconds, and the probe interval is 1 second, so 10 probes would have to fail before the gateway is marked down."); ?><br/>
653
								</td>
654
							</tr>
655
						</table>
656
					</div>
657
				</td>
658
			</tr>
659
			<tr>
660
				<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
661
				<td width="78%" class="vtable">
662
					<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
663
					<br/><span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)"); ?>.</span>
664
				</td>
665
			</tr>
666
			<tr>
667
				<td width="22%" valign="top">&nbsp;</td>
668
				<td width="78%">
669
					<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> <input type="button" value="<?=gettext("Cancel");?>" class="formbtn"  onclick="history.back()" />
670
					<?php if (isset($id) && $a_gateways[$id]): ?>
671
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
672
					<?php endif; ?>
673
				</td>
674
			</tr>
675
		</table>
676
	</form>
677
<?php include("fend.inc"); ?>
678
<script type="text/javascript">
679
//<![CDATA[
680
monitor_change();
681
//]]>
682
</script>
683
</body>
684
</html>
(214-214/246)