Project

General

Profile

Download (38.1 KB) Statistics
| Branch: | Tag: | Revision:

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

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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_gateways.php');
46

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

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

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

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

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

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

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

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

    
107
if ($_POST) {
108

    
109
	unset($input_errors);
110

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
493
		mark_subsystem_dirty('staticroutes');
494

    
495
		write_config();
496

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

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

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

    
521

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

    
525
include("head.inc");
526

    
527
?>
528

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

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

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

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

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

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

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

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

    
586
	calculate_state_change();
587
}
588

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

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

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

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

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

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

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