Project

General

Profile

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

    
7
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
8
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
9
	All rights reserved.
10

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

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

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

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

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

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

    
46
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_gateways.php');
47

    
48
$a_gateways = return_gateways_array(true, false, true);
49
$a_gateways_arr = array();
50
foreach($a_gateways as $gw) {
51
	$a_gateways_arr[] = $gw;
52
}
53
$a_gateways = $a_gateways_arr;
54

    
55
if (!is_array($config['gateways']['gateway_item']))
56
	$config['gateways']['gateway_item'] = array();
57

    
58
$a_gateway_item = &$config['gateways']['gateway_item'];
59
$apinger_default = return_apinger_defaults();
60

    
61
if (is_numericint($_GET['id']))
62
	$id = $_GET['id'];
63
if (isset($_POST['id']) && is_numericint($_POST['id']))
64
	$id = $_POST['id'];
65

    
66
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
67
	$id = $_GET['dup'];
68

    
69
if (isset($id) && $a_gateways[$id]) {
70
	$pconfig = array();
71
	$pconfig['name'] = $a_gateways[$id]['name'];
72
	$pconfig['weight'] = $a_gateways[$id]['weight'];
73
	$pconfig['interval'] = $a_gateways[$id]['interval'];
74
	$pconfig['avg_delay_samples'] = $a_gateways[$id]['avg_delay_samples'];
75
	$pconfig['avg_delay_samples_calculated'] = isset($a_gateways[$id]['avg_delay_samples_calculated']);
76
	$pconfig['avg_loss_samples'] = $a_gateways[$id]['avg_loss_samples'];
77
	$pconfig['avg_loss_samples_calculated'] = isset($a_gateways[$id]['avg_loss_samples_calculated']);
78
	$pconfig['avg_loss_delay_samples'] = $a_gateways[$id]['avg_loss_delay_samples'];
79
	$pconfig['avg_loss_delay_samples_calculated'] = isset($a_gateways[$id]['avg_loss_delay_samples_calculated']);
80
	$pconfig['interface'] = $a_gateways[$id]['interface'];
81
	$pconfig['friendlyiface'] = $a_gateways[$id]['friendlyiface'];
82
	$pconfig['ipprotocol'] = $a_gateways[$id]['ipprotocol'];
83
	if (isset($a_gateways[$id]['dynamic']))
84
		$pconfig['dynamic'] = true;
85
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
86
	$pconfig['defaultgw'] = isset($a_gateways[$id]['defaultgw']);
87
	$pconfig['force_down'] = isset($a_gateways[$id]['force_down']);
88
	$pconfig['latencylow'] = $a_gateways[$id]['latencylow'];
89
	$pconfig['latencyhigh'] = $a_gateways[$id]['latencyhigh'];
90
	$pconfig['losslow'] = $a_gateways[$id]['losslow'];
91
	$pconfig['losshigh'] = $a_gateways[$id]['losshigh'];
92
	$pconfig['down'] = $a_gateways[$id]['down'];
93
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
94
	$pconfig['monitor_disable'] = isset($a_gateways[$id]['monitor_disable']);
95
	$pconfig['descr'] = $a_gateways[$id]['descr'];
96
	$pconfig['attribute'] = $a_gateways[$id]['attribute'];
97
	$pconfig['disabled'] = isset($a_gateways[$id]['disabled']);
98
}
99

    
100
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) {
101
	unset($id);
102
	unset($pconfig['attribute']);
103
}
104

    
105
if (isset($id) && $a_gateways[$id])
106
	$realid = $a_gateways[$id]['attribute'];
107

    
108
if ($_POST) {
109

    
110
	unset($input_errors);
111

    
112
	/* input validation */
113
	$reqdfields = explode(" ", "name interface");
114
	$reqdfieldsn = array(gettext("Name"), gettext("Interface"));
115

    
116
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
117

    
118
	if (! isset($_POST['name'])) {
119
		$input_errors[] = "A valid gateway name must be specified.";
120
	}
121
	if (! is_validaliasname($_POST['name'])) {
122
		$input_errors[] = gettext("The gateway name must not contain invalid characters.");
123
	}
124
	/* skip system gateways which have been automatically added */
125
	if (($_POST['gateway'] && (!is_ipaddr($_POST['gateway'])) && ($_POST['attribute'] !== "system")) && ($_POST['gateway'] != "dynamic")) {
126
		$input_errors[] = gettext("A valid gateway IP address must be specified.");
127
	}
128

    
129
	if ($_POST['gateway'] && (is_ipaddr($_POST['gateway'])) && !$_REQUEST['isAjax']) {
130
		if(is_ipaddrv4($_POST['gateway'])) {
131
			$parent_ip = get_interface_ip($_POST['interface']);
132
			$parent_sn = get_interface_subnet($_POST['interface']);
133
			if(empty($parent_ip) || empty($parent_sn)) {
134
				$input_errors[] = gettext("Cannot add IPv4 Gateway Address because no IPv4 address could be found on the interface.");
135
			} else {
136
				$subnets = array(gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn);
137
				$vips = link_interface_to_vips($_POST['interface']);
138
				if (is_array($vips))
139
					foreach($vips as $vip) {
140
						if (!is_ipaddrv4($vip['subnet']))
141
							continue;
142
						$subnets[] = gen_subnet($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits'];
143
					}
144

    
145
				$found = false;
146
				foreach($subnets as $subnet)
147
					if(ip_in_subnet($_POST['gateway'], $subnet)) {
148
						$found = true;
149
						break;
150
					}
151

    
152
				if ($found === false)
153
					$input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within one of the chosen interface's subnets."), $_POST['gateway']);
154
			}
155
		}
156
		else if(is_ipaddrv6($_POST['gateway'])) {
157
			/* do not do a subnet match on a link local address, it's valid */
158
			if(!is_linklocal($_POST['gateway'])) {
159
				$parent_ip = get_interface_ipv6($_POST['interface']);
160
				$parent_sn = get_interface_subnetv6($_POST['interface']);
161
				if(empty($parent_ip) || empty($parent_sn)) {
162
					$input_errors[] = gettext("Cannot add IPv6 Gateway Address because no IPv6 address could be found on the interface.");
163
				} else {
164
					$subnets = array(gen_subnetv6($parent_ip, $parent_sn) . "/" . $parent_sn);
165
					$vips = link_interface_to_vips($_POST['interface']);
166
					if (is_array($vips))
167
						foreach($vips as $vip) {
168
							if (!is_ipaddrv6($vip['subnet']))
169
								continue;
170
							$subnets[] = gen_subnetv6($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits'];
171
						}
172

    
173
					$found = false;
174
					foreach($subnets as $subnet)
175
						if(ip_in_subnet($_POST['gateway'], $subnet)) {
176
							$found = true;
177
							break;
178
						}
179

    
180
					if ($found === false)
181
						$input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within one of the chosen interface's subnets."), $_POST['gateway']);
182
				}
183
			}
184
		}
185

    
186
		if (!empty($config['interfaces'][$_POST['interface']]['ipaddr'])) {
187
			if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddr']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic"))
188
				$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv4 configuration.");
189
		}
190
		if (!empty($config['interfaces'][$_POST['interface']]['ipaddrv6'])) {
191
			if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddrv6']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic"))
192
				$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv6 configuration.");
193
		}
194
	}
195
	if (($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") {
196
		$input_errors[] = gettext("A valid monitor IP address must be specified.");
197
	}
198
	/* only allow correct IPv4 and IPv6 gateway addresses */
199
	if (($_POST['gateway'] <> "") && is_ipaddr($_POST['gateway']) && $_POST['gateway'] != "dynamic") {
200
		if(is_ipaddrv6($_POST['gateway']) && ($_POST['ipprotocol'] == "inet")) {
201
			$input_errors[] = gettext("The IPv6 gateway address '{$_POST['gateway']}' can not be used as a IPv4 gateway'.");
202
		}
203
		if(is_ipaddrv4($_POST['gateway']) && ($_POST['ipprotocol'] == "inet6")) {
204
			$input_errors[] = gettext("The IPv4 gateway address '{$_POST['gateway']}' can not be used as a IPv6 gateway'.");
205
		}
206
	}
207
	/* only allow correct IPv4 and IPv6 monitor addresses */
208
	if (($_POST['monitor'] <> "") && is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") {
209
		if(is_ipaddrv6($_POST['monitor']) && ($_POST['ipprotocol'] == "inet")) {
210
			$input_errors[] = gettext("The IPv6 monitor address '{$_POST['monitor']}' can not be used on a IPv4 gateway'.");
211
		}
212
		if(is_ipaddrv4($_POST['monitor']) && ($_POST['ipprotocol'] == "inet6")) {
213
			$input_errors[] = gettext("The IPv4 monitor address '{$_POST['monitor']}' can not be used on a IPv6 gateway'.");
214
		}
215
	}
216

    
217
	if (isset($_POST['name'])) {
218
		/* check for overlaps */
219
		foreach ($a_gateways as $gateway) {
220
			if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway)) {
221
				if ($gateway['name'] != $_POST['name'])
222
					$input_errors[] = gettext("Changing name on a gateway is not allowed.");
223
				continue;
224
			}
225
			if($_POST['name'] <> "") {
226
				if (($gateway['name'] <> "") && ($_POST['name'] == $gateway['name']) && ($gateway['attribute'] !== "system")) {
227
					$input_errors[] = sprintf(gettext('The gateway name "%s" already exists.'), $_POST['name']);
228
					break;
229
				}
230
			}
231
			if(is_ipaddr($_POST['gateway'])) {
232
				if (($gateway['gateway'] <> "") && ($_POST['gateway'] == $gateway['gateway']) && ($gateway['attribute'] !== "system")) {
233
					$input_errors[] = sprintf(gettext('The gateway IP address "%s" already exists.'), $_POST['gateway']);
234
					break;
235
				}
236
			}
237
			if(is_ipaddr($_POST['monitor'])) {
238
				if (($gateway['monitor'] <> "") && ($_POST['monitor'] == $gateway['monitor']) && ($gateway['attribute'] !== "system")) {
239
					$input_errors[] = sprintf(gettext('The monitor IP address "%s" is already in use. You must choose a different monitor IP.'), $_POST['monitor']);
240
					break;
241
				}
242
			}
243
		}
244
	}
245

    
246
	/* input validation of apinger advanced parameters */
247
	if($_POST['latencylow']) {
248
		if (! is_numeric($_POST['latencylow'])) {
249
			$input_errors[] = gettext("The low latency threshold needs to be a numeric value.");
250
		} else {
251
			if ($_POST['latencylow'] < 1) {
252
				$input_errors[] = gettext("The low latency threshold needs to be positive.");
253
			}
254
		}
255
	}
256

    
257
	if($_POST['latencyhigh']) {
258
		if (! is_numeric($_POST['latencyhigh'])) {
259
			$input_errors[] = gettext("The high latency threshold needs to be a numeric value.");
260
		} else {
261
			if ($_POST['latencyhigh'] < 1) {
262
				$input_errors[] = gettext("The high latency threshold needs to be positive.");
263
			}
264
		}
265
	}
266

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

    
280
	if($_POST['losshigh']) {
281
		if (! is_numeric($_POST['losshigh'])) {
282
			$input_errors[] = gettext("The high Packet Loss threshold needs to be a numeric value.");
283
		} else {
284
			if ($_POST['losshigh'] < 1) {
285
				$input_errors[] = gettext("The high Packet Loss threshold needs to be positive.");
286
			}
287
			if ($_POST['losshigh'] > 100) {
288
				$input_errors[] = gettext("The high Packet Loss threshold needs to be 100 or less.");
289
			}
290
		}
291
	}
292

    
293
	if(($_POST['latencylow']) && ($_POST['latencyhigh'])) {
294
		if ((is_numeric($_POST['latencylow'])) && (is_numeric($_POST['latencyhigh']))) {
295
			if(($_POST['latencylow'] > $_POST['latencyhigh'])) {
296
				$input_errors[] = gettext("The high latency threshold needs to be higher than the low latency threshold");
297
			}
298
		}
299
	} else {
300
		if($_POST['latencylow']){
301
			if (is_numeric($_POST['latencylow'])) {
302
				if($_POST['latencylow'] > $apinger_default['latencyhigh']) {
303
					$input_errors[] = gettext(sprintf("The low latency threshold needs to be less than the default high latency threshold (%d)", $apinger_default['latencyhigh']));
304
				}
305
			}
306
		}
307
		if($_POST['latencyhigh']){
308
			if (is_numeric($_POST['latencyhigh'])) {
309
				if($_POST['latencyhigh'] < $apinger_default['latencylow']) {
310
					$input_errors[] = gettext(sprintf("The high latency threshold needs to be higher than the default low latency threshold (%d)", $apinger_default['latencylow']));
311
				}
312
			}
313
		}
314
	}
315

    
316
	if(($_POST['losslow']) && ($_POST['losshigh'])){
317
		if ((is_numeric($_POST['losslow'])) && (is_numeric($_POST['losshigh']))) {
318
			if($_POST['losslow'] > $_POST['losshigh']) {
319
				$input_errors[] = gettext("The high Packet Loss threshold needs to be higher than the low Packet Loss threshold");
320
			}
321
		}
322
	} else {
323
		if($_POST['losslow']){
324
			if (is_numeric($_POST['losslow'])) {
325
				if($_POST['losslow'] > $apinger_default['losshigh']) {
326
					$input_errors[] = gettext(sprintf("The low Packet Loss threshold needs to be less than the default high Packet Loss threshold (%d)", $apinger_default['losshigh']));
327
				}
328
			}
329
		}
330
		if($_POST['losshigh']){
331
			if (is_numeric($_POST['losshigh'])) {
332
				if($_POST['losshigh'] < $apinger_default['losslow']) {
333
					$input_errors[] = gettext(sprintf("The high Packet Loss threshold needs to be higher than the default low Packet Loss threshold (%d)", $apinger_default['losslow']));
334
				}
335
			}
336
		}
337
	}
338

    
339
	if($_POST['interval']) {
340
		if (! is_numeric($_POST['interval'])) {
341
			$input_errors[] = gettext("The probe interval needs to be a numeric value.");
342
		} else {
343
			if ($_POST['interval'] < 1) {
344
				$input_errors[] = gettext("The probe interval needs to be positive.");
345
			}
346
		}
347
	}
348

    
349
	if($_POST['down']) {
350
		if (! is_numeric($_POST['down'])) {
351
			$input_errors[] = gettext("The down time setting needs to be a numeric value.");
352
		} else {
353
			if ($_POST['down'] < 1) {
354
				$input_errors[] = gettext("The down time setting needs to be positive.");
355
			}
356
		}
357
	}
358

    
359
	if(($_POST['interval']) && ($_POST['down'])){
360
		if ((is_numeric($_POST['interval'])) && (is_numeric($_POST['down']))) {
361
			if($_POST['interval'] > $_POST['down']) {
362
				$input_errors[] = gettext("The probe interval needs to be less than the down time setting.");
363
			}
364
		}
365
	} else {
366
		if($_POST['interval']){
367
			if (is_numeric($_POST['interval'])) {
368
				if($_POST['interval'] > $apinger_default['down']) {
369
					$input_errors[] = gettext(sprintf("The probe interval needs to be less than the default down time setting (%d)", $apinger_default['down']));
370
				}
371
			}
372
		}
373
		if($_POST['down']){
374
			if (is_numeric($_POST['down'])) {
375
				if($_POST['down'] < $apinger_default['interval']) {
376
					$input_errors[] = gettext(sprintf("The down time setting needs to be higher than the default probe interval (%d)", $apinger_default['interval']));
377
				}
378
			}
379
		}
380
	}
381

    
382
	if($_POST['avg_delay_samples']) {
383
		if (! is_numeric($_POST['avg_delay_samples'])) {
384
			$input_errors[] = gettext("The average delay replies qty needs to be a numeric value.");
385
		} else {
386
			if ($_POST['avg_delay_samples'] < 1) {
387
				$input_errors[] = gettext("The average delay replies qty needs to be positive.");
388
			}
389
		}
390
	}
391

    
392
	if($_POST['avg_loss_samples']) {
393
		if (! is_numeric($_POST['avg_loss_samples'])) {
394
			$input_errors[] = gettext("The average packet loss probes qty needs to be a numeric value.");
395
		} else {
396
			if ($_POST['avg_loss_samples'] < 1) {
397
				$input_errors[] = gettext("The average packet loss probes qty needs to be positive.");
398
			}
399
		}
400
	}
401

    
402
	if($_POST['avg_loss_delay_samples']) {
403
		if (! is_numeric($_POST['avg_loss_delay_samples'])) {
404
			$input_errors[] = gettext("The lost probe delay needs to be a numeric value.");
405
		} else {
406
			if ($_POST['avg_loss_delay_samples'] < 1) {
407
				$input_errors[] = gettext("The lost probe delay needs to be positive.");
408
			}
409
		}
410
	}
411

    
412
	if (!$input_errors) {
413
		$reloadif = "";
414
		$gateway = array();
415

    
416
		if (empty($_POST['interface']))
417
			$gateway['interface'] = $pconfig['friendlyiface'];
418
		else
419
			$gateway['interface'] = $_POST['interface'];
420
		if (is_ipaddr($_POST['gateway']))
421
			$gateway['gateway'] = $_POST['gateway'];
422
		else
423
			$gateway['gateway'] = "dynamic";
424
		$gateway['name'] = $_POST['name'];
425
		$gateway['weight'] = $_POST['weight'];
426
		$gateway['ipprotocol'] = $_POST['ipprotocol'];
427
		$gateway['interval'] = $_POST['interval'];
428

    
429
		$gateway['avg_delay_samples'] = $_POST['avg_delay_samples'];
430
		if ($_POST['avg_delay_samples_calculated'] == "yes" || $_POST['avg_delay_samples_calculated'] == "on")
431
			$gateway['avg_delay_samples_calculated'] = true;
432

    
433
		$gateway['avg_loss_samples'] = $_POST['avg_loss_samples'];
434
		if ($_POST['avg_loss_samples_calculated'] == "yes" || $_POST['avg_loss_samples_calculated'] == "on")
435
			$gateway['avg_loss_samples_calculated'] = true;
436

    
437
		$gateway['avg_loss_delay_samples'] = $_POST['avg_loss_delay_samples'];
438
		if ($_POST['avg_loss_delay_samples_calculated'] == "yes" || $_POST['avg_loss_delay_samples_calculated'] == "on")
439
			$gateway['avg_loss_delay_samples_calculated'] = true;
440

    
441
		$gateway['descr'] = $_POST['descr'];
442
		if ($_POST['monitor_disable'] == "yes")
443
			$gateway['monitor_disable'] = true;
444
		if ($_POST['force_down'] == "yes")
445
			$gateway['force_down'] = true;
446
		if (is_ipaddr($_POST['monitor']))
447
			$gateway['monitor'] = $_POST['monitor'];
448

    
449
		/* NOTE: If monitor ip is changed need to cleanup the old static route */
450
		if ($_POST['monitor'] != "dynamic" && !empty($a_gateway_item[$realid]) && is_ipaddr($a_gateway_item[$realid]['monitor']) &&
451
		    $_POST['monitor'] != $a_gateway_item[$realid]['monitor'] && $gateway['gateway'] != $a_gateway_item[$realid]['monitor']) {
452
			if (is_ipaddrv4($a_gateway_item[$realid]['monitor']))
453
				mwexec("/sbin/route delete " . escapeshellarg($a_gateway_item[$realid]['monitor']));
454
			else
455
				mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateway_item[$realid]['monitor']));
456
		}
457

    
458
		if ($_POST['defaultgw'] == "yes" || $_POST['defaultgw'] == "on") {
459
			$i = 0;
460
			/* remove the default gateway bits for all gateways with the same address family */
461
			foreach($a_gateway_item as $gw) {
462
				if ($gateway['ipprotocol'] == $gw['ipprotocol']) {
463
					unset($config['gateways']['gateway_item'][$i]['defaultgw']);
464
					if ($gw['interface'] != $_POST['interface'] && $gw['defaultgw'])
465
						$reloadif = $gw['interface'];
466
				}
467
				$i++;
468
			}
469
			$gateway['defaultgw'] = true;
470
		}
471

    
472
		if ($_POST['latencylow'])
473
			$gateway['latencylow'] = $_POST['latencylow'];
474
		if ($_POST['latencyhigh'])
475
			$gateway['latencyhigh'] = $_POST['latencyhigh'];
476
		if ($_POST['losslow'])
477
			$gateway['losslow'] = $_POST['losslow'];
478
		if ($_POST['losshigh'])
479
			$gateway['losshigh'] = $_POST['losshigh'];
480
		if ($_POST['down'])
481
			$gateway['down'] = $_POST['down'];
482

    
483
		if(isset($_POST['disabled']))
484
			$gateway['disabled'] = true;
485
		else
486
			unset($gateway['disabled']);
487

    
488
		/* when saving the manual gateway we use the attribute which has the corresponding id */
489
		if (isset($realid) && $a_gateway_item[$realid])
490
			$a_gateway_item[$realid] = $gateway;
491
		else
492
			$a_gateway_item[] = $gateway;
493

    
494
		mark_subsystem_dirty('staticroutes');
495

    
496
		write_config();
497

    
498
		if($_REQUEST['isAjax']) {
499
			echo $_POST['name'];
500
			exit;
501
		} else if (!empty($reloadif))
502
			send_event("interface reconfigure {$reloadif}");
503

    
504
		header("Location: system_gateways.php");
505
		exit;
506
	} else {
507
		if ($_REQUEST['isAjax']) {
508
			header("HTTP/1.0 500 Internal Server Error");
509
			header("Content-type: text/plain");
510
			foreach ($input_errors as $error) {
511
				echo("$error\n");
512
			}
513
			exit;
514
		}
515

    
516
		$pconfig = $_POST;
517
		if (empty($_POST['friendlyiface']))
518
			$pconfig['friendlyiface'] = $_POST['interface'];
519
	}
520
}
521

    
522

    
523
$pgtitle = array(gettext("System"),gettext("Gateways"),gettext("Edit gateway"));
524
$shortcut_section = "gateways";
525

    
526
include("head.inc");
527

    
528
?>
529

    
530
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
531
<?php include("fbegin.inc"); ?>
532
<script type="text/javascript">
533
//<![CDATA[
534
function show_advanced_gateway() {
535
	document.getElementById("showadvgatewaybox").innerHTML='';
536
	aodiv = document.getElementById('showgatewayadv');
537
	aodiv.style.display = "block";
538
}
539
function monitor_change() {
540
	document.iform.monitor.disabled = document.iform.monitor_disable.checked;
541
}
542

    
543
function interval_change(interval_obj) {
544
	valid_value(interval_obj, 1, 86400);
545
	calculate_state_change();
546

    
547
	calculated_change(document.iform.avg_delay_samples_calculated, document.iform.avg_delay_samples);
548
	calculated_change(document.iform.avg_loss_samples_calculated, document.iform.avg_loss_samples);
549
	calculated_change(document.iform.avg_loss_delay_samples_calculated, document.iform.avg_loss_delay_samples);
550
}
551

    
552
function samples_change(calculated_obj, samples_obj) {
553
	calculated_change(calculated_obj, samples_obj);
554
}
555

    
556
function calculated_change(calculated_obj, samples_obj) {
557
	switch (samples_obj.name) {
558

    
559
	case 'avg_delay_samples':
560
		// How many replies should be used to compute average delay 
561
		// for controlling "delay" alarms.
562
		// Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60).
563
		if (calculated_obj.checked && (document.iform.interval.value > 0))
564
			samples_obj.value = 60 * (1/6) / Math.pow(document.iform.interval.value, 0.333);	// Calculate & Round to Integer
565
		valid_value(samples_obj, 1, 100);
566
		break;
567

    
568
	case 'avg_loss_samples':
569
		// How many probes should be used to compute average loss.
570
		// Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60).
571
		if (calculated_obj.checked && (document.iform.interval.value > 0))
572
			samples_obj.value = 60 / document.iform.interval.value;	// Calculate & Round to Integer
573
		valid_value(samples_obj, 1, 1000);
574
		break;
575

    
576
	case 'avg_loss_delay_samples':
577
		// The delay (in samples) after which loss is computed
578
		// without this delays larger than interval would be treated as loss.
579
		// Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60).
580
		if (calculated_obj.checked && (document.iform.interval.value > 0))
581
			samples_obj.value = 60 * (1/3) / document.iform.interval.value;	// Calculate & Round to Integer
582
		valid_value(samples_obj, 1, 200);
583
		break;
584
	default:
585
	}
586

    
587
	calculate_state_change();
588
}
589

    
590
function valid_value(object, min, max) {
591
	if (object.value) {
592
		object.value = Math.round(object.value);		// Round to integer
593
		if (object.value < min)  object.value = min;	// Min Value
594
		if (object.value > max)  object.value = max;	// Max Value
595
		if (isNaN(object.value)) object.value =  '';	// Empty Value
596
	}
597
}
598

    
599
function calculate_state_change() {
600
	if (document.iform.interval.value > 0) {
601
		document.iform.avg_delay_samples_calculated.disabled = false;
602
		document.iform.avg_loss_samples_calculated.disabled = false;
603
		document.iform.avg_loss_delay_samples_calculated.disabled = false;
604

    
605
		document.iform.avg_delay_samples.disabled = document.iform.avg_delay_samples_calculated.checked;
606
		document.iform.avg_loss_samples.disabled = document.iform.avg_loss_samples_calculated.checked;
607
		document.iform.avg_loss_delay_samples.disabled = document.iform.avg_loss_delay_samples_calculated.checked;
608
	}
609
	else {
610
		document.iform.avg_delay_samples_calculated.disabled = true;
611
		document.iform.avg_loss_samples_calculated.disabled = true;
612
		document.iform.avg_loss_delay_samples_calculated.disabled = true;
613
		document.iform.interval.value = '';
614

    
615
		document.iform.avg_delay_samples.disabled = false;
616
		document.iform.avg_loss_samples.disabled = false;
617
		document.iform.avg_loss_delay_samples.disabled = false;
618

    
619
		document.iform.avg_delay_samples_calculated.checked = false;
620
		document.iform.avg_loss_samples_calculated.checked = false;
621
		document.iform.avg_loss_delay_samples_calculated.checked = false;
622
	}
623
}
624

    
625
function enable_change() {
626
	document.iform.avg_delay_samples.disabled = false;
627
	document.iform.avg_loss_samples.disabled = false;
628
	document.iform.avg_loss_delay_samples.disabled = false;
629
}
630
//]]>
631
</script>
632
<?php if ($input_errors) print_input_errors($input_errors); ?>
633
	<form action="system_gateways_edit.php" method="post" name="iform" id="iform">
634
	<?php
635

    
636
	/* If this is a system gateway we need this var */
637
	if(($pconfig['attribute'] == "system") || is_numeric($pconfig['attribute'])) {
638
		echo "<input type='hidden' name='attribute' id='attribute' value=\"" . htmlspecialchars($pconfig['attribute']) . "\" />\n";
639
	}
640
	echo "<input type='hidden' name='friendlyiface' id='friendlyiface' value=\"" . htmlspecialchars($pconfig['friendlyiface']) . "\" />\n";
641
	?>
642
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="system gateways edit">
643
			<tr>
644
				<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit gateway"); ?></td>
645
			</tr>
646
			<tr>
647
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled");?></td>
648
				<td width="78%" class="vtable">
649
					<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
650
					<strong><?=gettext("Disable this gateway");?></strong><br />
651
					<span class="vexpl"><?=gettext("Set this option to disable this gateway without removing it from the list.");?></span>
652
				</td>
653
			</tr>
654
			<tr>
655
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
656
				<td width="78%" class="vtable">
657
					<select name='interface' class='formselect'>
658
					<?php
659
						$interfaces = get_configured_interface_with_descr(false, true);
660
						foreach ($interfaces as $iface => $ifacename) {
661
							echo "<option value=\"{$iface}\"";
662
							if ($iface == $pconfig['friendlyiface'])
663
								echo " selected='selected'";
664
							echo ">" . htmlspecialchars($ifacename) . "</option>";
665
						}
666
					?>
667
					</select><br />
668
					<span class="vexpl"><?=gettext("Choose which interface this gateway applies to."); ?></span>
669
				</td>
670
			</tr>
671
			<tr>
672
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Address Family"); ?></td>
673
				<td width="78%" class="vtable">
674
					<select name='ipprotocol' class='formselect' >
675
					<?php
676
						$options = array("inet" => "IPv4", "inet6" => "IPv6");
677
						foreach ($options as $name => $string) {
678
							echo "<option value=\"{$name}\"";
679
							if ($name == $pconfig['ipprotocol'])
680
								echo " selected='selected'";
681
							echo ">" . htmlspecialchars($string) . "</option>\n";
682
						}
683
					?>
684
					</select><br />
685
					<span class="vexpl"><?=gettext("Choose the Internet Protocol this gateway uses."); ?></span>
686
				</td>
687
			</tr>
688
			<tr>
689
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
690
				<td width="78%" class="vtable">
691
					<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" />
692
					<br /><span class="vexpl"><?=gettext("Gateway name"); ?></span>
693
				</td>
694
			</tr>
695
			<tr>
696
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway"); ?></td>
697
				<td width="78%" class="vtable">
698
					<input name="gateway" type="text" class="formfld host" id="gateway" size="28" value="<?php if ($pconfig['dynamic']) echo "dynamic"; else echo htmlspecialchars($pconfig['gateway']); ?>" />
699
					<br /><span class="vexpl"><?=gettext("Gateway IP address"); ?></span>
700
				</td>
701
			</tr>
702
			<tr>
703
				<td width="22%" valign="top" class="vncell"><?=gettext("Default Gateway"); ?></td>
704
				<td width="78%" class="vtable">
705
					<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if ($pconfig['defaultgw'] == true) echo "checked=\"checked\""; ?> />
706
					<strong><?=gettext("Default Gateway"); ?></strong><br />
707
					<?=gettext("This will select the above gateway as the default gateway"); ?>
708
				</td>
709
			</tr>
710
			<tr>
711
				<td width="22%" valign="top" class="vncell"><?=gettext("Disable Gateway Monitoring"); ?></td>
712
				<td width="78%" class="vtable">
713
					<input name="monitor_disable" type="checkbox" id="monitor_disable" value="yes" <?php if ($pconfig['monitor_disable'] == true) echo "checked=\"checked\""; ?> onclick="monitor_change()" />
714
					<strong><?=gettext("Disable Gateway Monitoring"); ?></strong><br />
715
					<?=gettext("This will consider this gateway as always being up"); ?>
716
				</td>
717
			</tr>
718
			<tr>
719
				<td width="22%" valign="top" class="vncell"><?=gettext("Monitor IP"); ?></td>
720
				<td width="78%" class="vtable">
721
					<?php
722
						if ($pconfig['gateway'] == $pconfig['monitor'])
723
							$monitor = "";
724
						else
725
							$monitor = htmlspecialchars($pconfig['monitor']);
726
					?>
727
					<input name="monitor" type="text" id="monitor" value="<?php echo htmlspecialchars($monitor); ?>" size="28" />
728
					<strong><?=gettext("Alternative monitor IP"); ?></strong> <br />
729
					<?=gettext("Enter an alternative address here to be used to monitor the link. This is used for the " .
730
					"quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond " .
731
					"to ICMP echo requests (pings)"); ?>.
732
					<br />
733
				</td>
734
			</tr>
735
			<tr>
736
				<td width="22%" valign="top" class="vncell"><?=gettext("Mark Gateway as Down"); ?></td>
737
				<td width="78%" class="vtable">
738
					<input name="force_down" type="checkbox" id="force_down" value="yes" <?php if ($pconfig['force_down'] == true) echo "checked=\"checked\""; ?> />
739
					<strong><?=gettext("Mark Gateway as Down"); ?></strong><br />
740
					<?=gettext("This will force this gateway to be considered Down"); ?>
741
				</td>
742
			</tr>
743
			<tr>
744
				<td width="22%" valign="top" class="vncell"><?=gettext("Advanced");?></td>
745
				<td width="78%" class="vtable">
746
					<?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']))); ?>
747
					<div id="showadvgatewaybox" <?php if ($showbutton) echo "style='display:none'"; ?>>
748
						<input type="button" onclick="show_advanced_gateway()" value="Advanced" /><?=gettext(" - Show advanced option"); ?>
749
					</div>
750
					<div id="showgatewayadv" <?php if (!$showbutton) echo "style='display:none'"; ?>>
751
						<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="6" summary="advanced options">
752
							<tr>
753
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Weight");?></td>
754
								<td width="78%" class="vtable">
755
									<select name='weight' class='formfldselect' id='weight'>
756
									<?php
757
										for ($i = 1; $i < 6; $i++) {
758
											$selected = "";
759
											if ($pconfig['weight'] == $i)
760
												$selected = "selected='selected'";
761
											echo "<option value='{$i}' {$selected} >{$i}</option>";
762
										}
763
									?>
764
									</select>
765
									<br /><?=gettext("Weight for this gateway when used in a Gateway Group.");?> <br />
766
								</td>
767
							</tr>
768
							<tr>
769
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Latency thresholds");?></td>
770
								<td width="78%" class="vtable">
771
									<?=gettext("From");?>
772
									<input name="latencylow" type="text" class="formfld unknown" id="latencylow" size="2"
773
										value="<?=htmlspecialchars($pconfig['latencylow']);?>" />
774
									<?=gettext("To");?>
775
									<input name="latencyhigh" type="text" class="formfld unknown" id="latencyhigh" size="2"
776
										value="<?=htmlspecialchars($pconfig['latencyhigh']);?>" />
777
									<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>
778
								</td>
779
							</tr>
780
							<tr>
781
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Packet Loss thresholds");?></td>
782
								<td width="78%" class="vtable">
783
									<?=gettext("From");?>
784
									<input name="losslow" type="text" class="formfld unknown" id="losslow" size="2"
785
										value="<?=htmlspecialchars($pconfig['losslow']);?>" />
786
									<?=gettext("To");?>
787
									<input name="losshigh" type="text" class="formfld unknown" id="losshigh" size="2"
788
										value="<?=htmlspecialchars($pconfig['losshigh']);?>" />
789
									<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>
790
								</td>
791
							</tr>
792
							<tr>
793
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Probe Interval");?></td>
794
								<td width="78%" class="vtable">
795
									<input name="interval" type="text" class="formfld unknown" id="interval" size="2"
796
										value="<?=htmlspecialchars($pconfig['interval']);?>" onchange="interval_change(this)" />
797
									<br /><span class="vexpl">
798
										<?=gettext(sprintf("How often that an ICMP probe will be sent in seconds. Default is %d.", $apinger_default['interval']));?><br /><br />
799
										<?=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.");?>
800
									</span>
801
								</td>
802
							</tr>
803
							<tr>
804
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Down");?></td>
805
								<td width="78%" class="vtable">
806
									<input name="down" type="text" class="formfld unknown" id="down" size="2"
807
										value="<?=htmlspecialchars($pconfig['down']);?>" />
808
									<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>
809
								</td>
810
							</tr>
811
							<tr>
812
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Average Delay Replies Qty");?></td>
813
								<td width="78%" class="vtable">
814
									<input name="avg_delay_samples" type="text" class="formfld unknown" id="avg_delay_samples" size="2"
815
										value="<?=htmlspecialchars($pconfig['avg_delay_samples']);?>" onchange="samples_change(document.iform.avg_delay_samples_calculated, this)" /> 
816
									<input name="avg_delay_samples_calculated" type="checkbox" id="avg_delay_samples_calculated" value="yes" <?php if ($pconfig['avg_delay_samples_calculated'] == true) echo "checked=\"checked\""; ?> onclick="calculated_change(this, document.iform.avg_delay_samples)" />
817
										<?=gettext("Use calculated value."); ?>
818
									<br /><span class="vexpl"><?=gettext(sprintf("How many replies should be used to compute average delay for controlling \"delay\" alarms?  Default is %d.", $apinger_default['avg_delay_samples']));?><br /><br /></span>
819
								</td>
820
							</tr>
821
							<tr>
822
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Average Packet Loss Probes Qty");?></td>
823
								<td width="78%" class="vtable">
824
									<input name="avg_loss_samples" type="text" class="formfld unknown" id="avg_loss_samples" size="2"
825
										value="<?=htmlspecialchars($pconfig['avg_loss_samples']);?>" onchange="samples_change(document.iform.avg_loss_samples_calculated, this)" />
826
									<input name="avg_loss_samples_calculated" type="checkbox" id="avg_loss_samples_calculated" value="yes" <?php if ($pconfig['avg_loss_samples_calculated'] == true) echo "checked=\"checked\""; ?> onclick="calculated_change(this, document.iform.avg_loss_samples)" />
827
										<?=gettext("Use calculated value."); ?>
828
									<br /><span class="vexpl"><?=gettext(sprintf("How many probes should be useds to compute average packet loss?  Default is %d.", $apinger_default['avg_loss_samples']));?><br /><br /></span>
829
								</td>
830
							</tr>
831
							<tr>
832
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Lost Probe Delay");?></td>
833
								<td width="78%" class="vtable">
834
									<input name="avg_loss_delay_samples" type="text" class="formfld unknown" id="avg_loss_delay_samples" size="2"
835
										value="<?=htmlspecialchars($pconfig['avg_loss_delay_samples']);?>" onchange="samples_change(document.iform.avg_loss_delay_samples_calculated, this)" />
836
									<input name="avg_loss_delay_samples_calculated" type="checkbox" id="avg_loss_delay_samples_calculated" value="yes" <?php if ($pconfig['avg_loss_delay_samples_calculated'] == true) echo "checked=\"checked\""; ?> onclick="calculated_change(this, document.iform.avg_loss_delay_samples)" />
837
										<?=gettext("Use calculated value."); ?>
838
									<br /><span class="vexpl"><?=gettext(sprintf("The delay (in qty of probe samples) after which loss is computed.  Without this, delays longer than the probe interval would be treated as packet loss.  Default is %d.", $apinger_default['avg_loss_delay_samples']));?><br /><br /></span>
839
								</td>
840
							</tr>
841
							<tr>
842
								<td colspan="2">
843
									<?= 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 />
844
									<?= 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 />
845
								</td>
846
							</tr>
847
						</table>
848
					</div>
849
				</td>
850
			</tr>
851
			<tr>
852
				<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
853
				<td width="78%" class="vtable">
854
					<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
855
					<br /><span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)"); ?>.</span>
856
				</td>
857
			</tr>
858
			<tr>
859
				<td width="22%" valign="top">&nbsp;</td>
860
				<td width="78%">
861
					<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change()" />
862
					<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
863
					<?php if (isset($id) && $a_gateways[$id]): ?>
864
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
865
					<?php endif; ?>
866
				</td>
867
			</tr>
868
		</table>
869
	</form>
870
<?php include("fend.inc"); ?>
871
<script type="text/javascript">
872
//<![CDATA[
873
monitor_change();
874
calculate_state_change();
875
//]]>
876
</script>
877
</body>
878
</html>
(223-223/256)