Projet

Général

Profil

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

univnautes / usr / local / www / system_gateways_edit.php @ fab1cd2f

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
	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, false, 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
if (is_numericint($_GET['id']))
59
	$id = $_GET['id'];
60
if (isset($_POST['id']) && is_numericint($_POST['id']))
61
	$id = $_POST['id'];
62

    
63
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
64
	$id = $_GET['dup'];
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['avg_delay_samples'] = $a_gateways[$id]['avg_delay_samples'];
72
	$pconfig['avg_delay_samples_calculated'] = isset($a_gateways[$id]['avg_delay_samples_calculated']);
73
	$pconfig['avg_loss_samples'] = $a_gateways[$id]['avg_loss_samples'];
74
	$pconfig['avg_loss_samples_calculated'] = isset($a_gateways[$id]['avg_loss_samples_calculated']);
75
	$pconfig['avg_loss_delay_samples'] = $a_gateways[$id]['avg_loss_delay_samples'];
76
	$pconfig['avg_loss_delay_samples_calculated'] = isset($a_gateways[$id]['avg_loss_delay_samples_calculated']);
77
	$pconfig['interface'] = $a_gateways[$id]['interface'];
78
	$pconfig['friendlyiface'] = $a_gateways[$id]['friendlyiface'];
79
	$pconfig['ipprotocol'] = $a_gateways[$id]['ipprotocol'];
80
	if (isset($a_gateways[$id]['dynamic']))
81
		$pconfig['dynamic'] = true;
82
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
83
	$pconfig['defaultgw'] = isset($a_gateways[$id]['defaultgw']);
84
	$pconfig['force_down'] = isset($a_gateways[$id]['force_down']);
85
	$pconfig['latencylow'] = $a_gateways[$id]['latencylow'];
86
	$pconfig['latencyhigh'] = $a_gateways[$id]['latencyhigh'];
87
	$pconfig['losslow'] = $a_gateways[$id]['losslow'];
88
	$pconfig['losshigh'] = $a_gateways[$id]['losshigh'];
89
	$pconfig['down'] = $a_gateways[$id]['down'];
90
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
91
	$pconfig['monitor_disable'] = isset($a_gateways[$id]['monitor_disable']);
92
	$pconfig['descr'] = $a_gateways[$id]['descr'];
93
	$pconfig['attribute'] = $a_gateways[$id]['attribute'];
94
	$pconfig['disabled'] = isset($a_gateways[$id]['disabled']);
95
}
96

    
97
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) {
98
	unset($id);
99
	unset($pconfig['attribute']);
100
}
101

    
102
if (isset($id) && $a_gateways[$id])
103
	$realid = $a_gateways[$id]['attribute'];
104

    
105
if ($_POST) {
106

    
107
	unset($input_errors);
108

    
109
	/* input validation */
110
	$reqdfields = explode(" ", "name interface");
111
	$reqdfieldsn = array(gettext("Name"), gettext("Interface"));
112

    
113
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
114

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
409
	if (!$input_errors) {
410
		$reloadif = "";
411
		$gateway = array();
412

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

    
426
		$gateway['avg_delay_samples'] = $_POST['avg_delay_samples'];
427
		if ($_POST['avg_delay_samples_calculated'] == "yes" || $_POST['avg_delay_samples_calculated'] == "on")
428
			$gateway['avg_delay_samples_calculated'] = true;
429

    
430
		$gateway['avg_loss_samples'] = $_POST['avg_loss_samples'];
431
		if ($_POST['avg_loss_samples_calculated'] == "yes" || $_POST['avg_loss_samples_calculated'] == "on")
432
			$gateway['avg_loss_samples_calculated'] = true;
433

    
434
		$gateway['avg_loss_delay_samples'] = $_POST['avg_loss_delay_samples'];
435
		if ($_POST['avg_loss_delay_samples_calculated'] == "yes" || $_POST['avg_loss_delay_samples_calculated'] == "on")
436
			$gateway['avg_loss_delay_samples_calculated'] = true;
437

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

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

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

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

    
480
		if(isset($_POST['disabled']))
481
			$gateway['disabled'] = true;
482
		else
483
			unset($gateway['disabled']);
484

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

    
491
		mark_subsystem_dirty('staticroutes');
492

    
493
		write_config();
494

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

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

    
513
		$pconfig = $_POST;
514
		if (empty($_POST['friendlyiface']))
515
			$pconfig['friendlyiface'] = $_POST['interface'];
516
	}
517
}
518

    
519

    
520
$pgtitle = array(gettext("System"),gettext("Gateways"),gettext("Edit gateway"));
521
$shortcut_section = "gateways";
522

    
523
include("head.inc");
524

    
525
?>
526

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

    
540
function interval_change(interval_obj) {
541
	valid_value(interval_obj, 1, 86400);
542
	calculate_state_change();
543

    
544
	calculated_change(document.iform.avg_delay_samples_calculated, document.iform.avg_delay_samples);
545
	calculated_change(document.iform.avg_loss_samples_calculated, document.iform.avg_loss_samples);
546
	calculated_change(document.iform.avg_loss_delay_samples_calculated, document.iform.avg_loss_delay_samples);
547
}
548

    
549
function samples_change(calculated_obj, samples_obj) {
550
	calculated_change(calculated_obj, samples_obj);
551
}
552

    
553
function calculated_change(calculated_obj, samples_obj) {
554
	switch (samples_obj.name) {
555

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

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

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

    
584
	calculate_state_change();
585
}
586

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

    
596
function calculate_state_change() {
597
	if (document.iform.interval.value > 0) {
598
		document.iform.avg_delay_samples_calculated.disabled = false;
599
		document.iform.avg_loss_samples_calculated.disabled = false;
600
		document.iform.avg_loss_delay_samples_calculated.disabled = false;
601

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

    
612
		document.iform.avg_delay_samples.disabled = false;
613
		document.iform.avg_loss_samples.disabled = false;
614
		document.iform.avg_loss_delay_samples.disabled = false;
615

    
616
		document.iform.avg_delay_samples_calculated.checked = false;
617
		document.iform.avg_loss_samples_calculated.checked = false;
618
		document.iform.avg_loss_delay_samples_calculated.checked = false;
619
	}
620
}
621

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

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