Project

General

Profile

Download (27.4 KB) Statistics
| Branch: | Tag: | Revision:
1 d173230c Seth Mos
<?php 
2 124aee67 Chris Buechler
/* $Id$ */
3 d173230c Seth Mos
/*
4
	system_gateways_edit.php
5
	part of pfSense (http://pfsense.com)
6
	
7 6216690b smos
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
8 d173230c Seth Mos
	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 1d333258 Scott Ullrich
/*
32
	pfSense_MODULE:	routing
33
*/
34 d173230c Seth Mos
35 6b07c15a Matthew Grooms
##|+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 124aee67 Chris Buechler
require("guiconfig.inc");
43 4666b787 Ermal Lu?i
require("pkg-utils.inc");
44 d173230c Seth Mos
45 99c61352 Ermal
$a_gateways = return_gateways_array(true);
46 87f0be87 Chris Buechler
$a_gateways_arr = array();
47
foreach($a_gateways as $gw) {
48
	$a_gateways_arr[] = $gw;
49
}
50
$a_gateways = $a_gateways_arr;
51 d173230c Seth Mos
52 616e1956 Seth Mos
if (!is_array($config['gateways']['gateway_item']))
53
        $config['gateways']['gateway_item'] = array();
54
        
55
$a_gateway_item = &$config['gateways']['gateway_item'];
56 eb233517 Phil Davis
$apinger_default = return_apinger_defaults();
57 616e1956 Seth Mos
58 87f0be87 Chris Buechler
$id = $_GET['id'];
59
if (isset($_POST['id']))
60 d173230c Seth Mos
	$id = $_POST['id'];
61
62
if (isset($_GET['dup'])) {
63
	$id = $_GET['dup'];
64
}
65
66
if (isset($id) && $a_gateways[$id]) {
67 bb849003 Ermal
	$pconfig = array();
68 e90db2b4 Ermal Lu?i
	$pconfig['name'] = $a_gateways[$id]['name'];
69 5f53260a Ermal
	$pconfig['weight'] = $a_gateways[$id]['weight'];
70 f7203985 Ermal
	$pconfig['interval'] = $a_gateways[$id]['interval'];
71 e90db2b4 Ermal Lu?i
	$pconfig['interface'] = $a_gateways[$id]['interface'];
72 883c53c9 Ermal Lu?i
	$pconfig['friendlyiface'] = $a_gateways[$id]['friendlyiface'];
73 c1d36d26 smos
	$pconfig['ipprotocol'] = $a_gateways[$id]['ipprotocol'];
74 d44d26c1 Ermal
	if (isset($a_gateways[$id]['dynamic']))
75
		$pconfig['dynamic'] = true;
76
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
77 883c53c9 Ermal Lu?i
	$pconfig['defaultgw'] = isset($a_gateways[$id]['defaultgw']);
78 023920e7 Ermal
	$pconfig['latencylow'] = $a_gateway_item[$id]['latencylow'];
79 eb233517 Phil Davis
	$pconfig['latencyhigh'] = $a_gateway_item[$id]['latencyhigh'];
80
	$pconfig['losslow'] = $a_gateway_item[$id]['losslow'];
81
	$pconfig['losshigh'] = $a_gateway_item[$id]['losshigh'];
82
	$pconfig['down'] = $a_gateway_item[$id]['down'];
83 99c61352 Ermal
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
84 33c06ef7 Ermal
	$pconfig['monitor_disable'] = isset($a_gateways[$id]['monitor_disable']);
85 e90db2b4 Ermal Lu?i
	$pconfig['descr'] = $a_gateways[$id]['descr'];
86
	$pconfig['attribute'] = $a_gateways[$id]['attribute'];
87 d173230c Seth Mos
}
88
89 124aee67 Chris Buechler
if (isset($_GET['dup'])) {
90 d173230c Seth Mos
	unset($id);
91 124aee67 Chris Buechler
	unset($pconfig['attribute']);
92
}
93 d173230c Seth Mos
94
if ($_POST) {
95
96
	unset($input_errors);
97
98
	/* input validation */
99 d44d26c1 Ermal
	$reqdfields = explode(" ", "name interface");
100
	$reqdfieldsn = array(gettext("Name"), gettext("Interface"));
101 883c53c9 Ermal Lu?i
102 d173230c Seth Mos
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
103 883c53c9 Ermal Lu?i
104 d173230c Seth Mos
	if (! isset($_POST['name'])) {
105
		$input_errors[] = "A valid gateway name must be specified.";
106
	}
107 31ace93c Seth Mos
	if (! is_validaliasname($_POST['name'])) {
108 df152a88 Carlos Eduardo Ramos
		$input_errors[] = gettext("The gateway name must not contain invalid characters.");
109 31ace93c Seth Mos
	}
110 87f0be87 Chris Buechler
	/* skip system gateways which have been automatically added */
111 283d78c6 Darren Embry
	if (($_POST['gateway'] && (!is_ipaddr($_POST['gateway'])) && ($_POST['attribute'] !== "system")) && ($_POST['gateway'] != "dynamic")) {
112 df152a88 Carlos Eduardo Ramos
		$input_errors[] = gettext("A valid gateway IP address must be specified.");
113 87f0be87 Chris Buechler
	}
114 15a13dab Scott Ullrich
115 d44d26c1 Ermal
	if ($_POST['gateway'] && (is_ipaddr($_POST['gateway'])) && !$_REQUEST['isAjax']) {
116 9e80d14c Seth Mos
		if(is_ipaddrv4($_POST['gateway'])) {
117 47593ac6 Seth Mos
			$parent_ip = get_interface_ip($_POST['interface']);
118 e227df57 Ermal Lu?i
			$parent_sn = get_interface_subnet($_POST['interface']);
119 9e80d14c Seth Mos
			if(empty($parent_ip) || empty($parent_sn)) {
120
				$input_errors[] = gettext("You can not use a IPv6 Gateway Address on a IPv4 only interface.");
121
			} else {
122
				$subnet = gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn;
123
				if(!ip_in_subnet($_POST['gateway'], $subnet))
124
					$input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within the chosen interface's subnet '%2\$s'."), $_POST['gateway'],$subnet);
125 e227df57 Ermal Lu?i
			}
126 e7d3b8f4 Seth Mos
		}
127 9e80d14c Seth Mos
		if(is_ipaddrv6($_POST['gateway'])) {
128 2a9cb3b2 smos
			/* do not do a subnet match on a link local address, it's valid */
129
			if(! preg_match("/fe80::/", $_POST['gateway'])) {
130
				$parent_ip = get_interface_ipv6($_POST['interface']);
131
				$parent_sn = get_interface_subnetv6($_POST['interface']);
132
				if(empty($parent_ip) || empty($parent_sn)) {
133
					$input_errors[] = gettext("You can not use a IPv4 Gateway Address on a IPv6 only interface.");
134
				} else {
135 35af7141 smos
					$subnet = gen_subnetv6($parent_ip, $parent_sn) . "/" . $parent_sn;
136
					if(!ip_in_subnet($_POST['gateway'], $subnet))
137
						$input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within the chosen interface's subnet '%2\$s'."), $_POST['gateway'],$subnet);
138
				}
139 7617e245 Seth Mos
			}
140
		}
141 9e80d14c Seth Mos
142
		if (!empty($config['interfaces'][$_POST['interface']]['ipaddr'])) {
143
			if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddr']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic"))
144
				$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv4 configuration.");
145
		}
146
		if (!empty($config['interfaces'][$_POST['interface']]['ipaddrv6'])) {
147
			if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddrv6']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic"))
148
				$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv6 configuration.");
149
		}
150 e7d3b8f4 Seth Mos
	}
151 883c53c9 Ermal Lu?i
	if (($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") {
152 df152a88 Carlos Eduardo Ramos
		$input_errors[] = gettext("A valid monitor IP address must be specified.");
153 d173230c Seth Mos
	}
154 2972b3e7 smos
	/* only allow correct IPv4 and IPv6 gateway addresses */
155
	if (($_POST['gateway'] <> "") && is_ipaddr($_POST['gateway']) && $_POST['gateway'] != "dynamic") {
156
		if(is_ipaddrv6($_POST['gateway']) && ($_POST['ipprotocol'] == "inet")) {
157
			$input_errors[] = gettext("The IPv6 gateway address '{$_POST['gateway']}' can not be used as a IPv4 gateway'.");
158
		}
159
		if(is_ipaddrv4($_POST['gateway']) && ($_POST['ipprotocol'] == "inet6")) {
160
			$input_errors[] = gettext("The IPv4 gateway address '{$_POST['gateway']}' can not be used as a IPv6 gateway'.");
161
		}
162
	}
163
	/* only allow correct IPv4 and IPv6 monitor addresses */
164 9e80d14c Seth Mos
	if (($_POST['monitor'] <> "") && is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") {
165 2972b3e7 smos
		if(is_ipaddrv6($_POST['monitor']) && ($_POST['ipprotocol'] == "inet")) {
166
			$input_errors[] = gettext("The IPv6 monitor address '{$_POST['monitor']}' can not be used on a IPv4 gateway'.");
167 c1d36d26 smos
		}
168 2972b3e7 smos
		if(is_ipaddrv4($_POST['monitor']) && ($_POST['ipprotocol'] == "inet6")) {
169
			$input_errors[] = gettext("The IPv4 monitor address '{$_POST['monitor']}' can not be used on a IPv6 gateway'.");
170 9e80d14c Seth Mos
		}
171
	}
172 d173230c Seth Mos
173 8b060357 Seth Mos
	if (isset($_POST['name'])) {
174 31ace93c Seth Mos
		/* check for overlaps */
175
		foreach ($a_gateways as $gateway) {
176 2328dcc5 Seth Mos
			if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway)) {
177 23fafd14 Ermal
				if ($gateway['name'] != $_POST['name'])
178 33802679 Chris Buechler
					$input_errors[] = gettext("Changing name on a gateway is not allowed.");
179 31ace93c Seth Mos
				continue;
180
			}
181 2328dcc5 Seth Mos
			if($_POST['name'] <> "") {
182 283d78c6 Darren Embry
				if (($gateway['name'] <> "") && ($_POST['name'] == $gateway['name']) && ($gateway['attribute'] !== "system")) {
183 0e94685b Renato Botelho
					$input_errors[] = sprintf(gettext('The gateway name "%s" already exists.'), $_POST['name']);
184 2328dcc5 Seth Mos
					break;
185
				}
186
			}
187
			if(is_ipaddr($_POST['gateway'])) {
188 283d78c6 Darren Embry
				if (($gateway['gateway'] <> "") && ($_POST['gateway'] == $gateway['gateway']) && ($gateway['attribute'] !== "system")) {
189 0e94685b Renato Botelho
					$input_errors[] = sprintf(gettext('The gateway IP address "%s" already exists.'), $_POST['gateway']);
190 2328dcc5 Seth Mos
					break;
191
				}
192 31ace93c Seth Mos
			}
193 2328dcc5 Seth Mos
			if(is_ipaddr($_POST['monitor'])) {
194 283d78c6 Darren Embry
				if (($gateway['monitor'] <> "") && ($_POST['monitor'] == $gateway['monitor']) && ($gateway['attribute'] !== "system")) {
195 0e94685b Renato Botelho
					$input_errors[] = sprintf(gettext('The monitor IP address "%s" is already in use. You must choose a different monitor IP.'), $_POST['monitor']);
196 2328dcc5 Seth Mos
					break;
197
				}
198 31ace93c Seth Mos
			}
199 d173230c Seth Mos
		}
200
	}
201
202 eb233517 Phil Davis
	/* input validation of apinger advanced parameters */
203
	if($_POST['latencylow']) {
204
		if (! is_numeric($_POST['latencylow'])) {
205
			$input_errors[] = gettext("The low latency threshold needs to be a numeric value.");
206
		} else {
207
			if ($_POST['latencylow'] < 1) {
208
				$input_errors[] = gettext("The low latency threshold needs to be positive.");
209
			}
210
		}
211
	}
212
213
	if($_POST['latencyhigh']) {
214
		if (! is_numeric($_POST['latencyhigh'])) {
215
			$input_errors[] = gettext("The high latency threshold needs to be a numeric value.");
216
		} else {
217
			if ($_POST['latencyhigh'] < 1) {
218
				$input_errors[] = gettext("The high latency threshold needs to be positive.");
219
			}
220
		}
221
	}
222
223
	if($_POST['losslow']) {
224
		if (! is_numeric($_POST['losslow'])) {
225
			$input_errors[] = gettext("The low Packet Loss threshold needs to be a numeric value.");
226
		} else {
227
			if ($_POST['losslow'] < 1) {
228
				$input_errors[] = gettext("The low Packet Loss threshold needs to be positive.");
229
			}
230
			if ($_POST['losslow'] >= 100) {
231
				$input_errors[] = gettext("The low Packet Loss threshold needs to be less than 100.");
232
			}
233
		}
234
	}
235
236
	if($_POST['losshigh']) {
237
		if (! is_numeric($_POST['losshigh'])) {
238
			$input_errors[] = gettext("The high Packet Loss threshold needs to be a numeric value.");
239
		} else {
240
			if ($_POST['losshigh'] < 1) {
241
				$input_errors[] = gettext("The high Packet Loss threshold needs to be positive.");
242
			}
243
			if ($_POST['losshigh'] > 100) {
244
				$input_errors[] = gettext("The high Packet Loss threshold needs to be 100 or less.");
245
			}
246
		}
247
	}
248
249
	if(($_POST['latencylow']) && ($_POST['latencyhigh'])) {
250
		if ((is_numeric($_POST['latencylow'])) && (is_numeric($_POST['latencyhigh']))) {
251
			if(($_POST['latencylow'] > $_POST['latencyhigh'])) {
252
				$input_errors[] = gettext("The high latency threshold needs to be higher than the low latency threshold");
253
			}
254
		}
255
	} else {
256
		if($_POST['latencylow']){
257
			if (is_numeric($_POST['latencylow'])) {
258
				if($_POST['latencylow'] > $apinger_default['latencyhigh']) {
259
					$input_errors[] = gettext(sprintf("The low latency threshold needs to be less than the default high latency threshold (%d)", $apinger_default['latencyhigh']));
260
				}
261
			}
262
		}
263
		if($_POST['latencyhigh']){
264
			if (is_numeric($_POST['latencyhigh'])) {
265
				if($_POST['latencyhigh'] < $apinger_default['latencylow']) {
266
					$input_errors[] = gettext(sprintf("The high latency threshold needs to be higher than the default low latency threshold (%d)", $apinger_default['latencylow']));
267
				}
268
			}
269
		}
270
	}
271
272
	if(($_POST['losslow']) && ($_POST['losshigh'])){
273
		if ((is_numeric($_POST['losslow'])) && (is_numeric($_POST['losshigh']))) {
274
			if($_POST['losslow'] > $_POST['losshigh']) {
275
				$input_errors[] = gettext("The high Packet Loss threshold needs to be higher than the low Packet Loss threshold");
276
			}
277
		}
278
	} else {
279
		if($_POST['losslow']){
280
			if (is_numeric($_POST['losslow'])) {
281
				if($_POST['losslow'] > $apinger_default['losshigh']) {
282
					$input_errors[] = gettext(sprintf("The low Packet Loss threshold needs to be less than the default high Packet Loss threshold (%d)", $apinger_default['losshigh']));
283
				}
284
			}
285
		}
286
		if($_POST['losshigh']){
287
			if (is_numeric($_POST['losshigh'])) {
288
				if($_POST['losshigh'] < $apinger_default['losslow']) {
289
					$input_errors[] = gettext(sprintf("The high Packet Loss threshold needs to be higher than the default low Packet Loss threshold (%d)", $apinger_default['losslow']));
290
				}
291
			}
292
		}
293
	}
294
295
	if($_POST['interval']) {
296
		if (! is_numeric($_POST['interval'])) {
297
			$input_errors[] = gettext("The frequency probe interval needs to be a numeric value.");
298
		} else {
299
			if ($_POST['interval'] < 1) {
300
				$input_errors[] = gettext("The frequency probe interval needs to be positive.");
301
			}
302
		}
303
	}
304
305 023920e7 Ermal
	if($_POST['down']) {
306 eb233517 Phil Davis
		if (! is_numeric($_POST['down'])) {
307
			$input_errors[] = gettext("The down time setting needs to be a numeric value.");
308
		} else {
309
			if ($_POST['down'] < 1) {
310
				$input_errors[] = gettext("The down time setting needs to be positive.");
311
			}
312
		}
313
	}
314
315
	if(($_POST['interval']) && ($_POST['down'])){
316
		if ((is_numeric($_POST['interval'])) && (is_numeric($_POST['down']))) {
317
			if($_POST['interval'] > $_POST['down']) {
318
				$input_errors[] = gettext("The Frequency Probe interval needs to be less than the down time setting.");
319
			}
320
		}
321
	} else {
322
		if($_POST['interval']){
323
			if (is_numeric($_POST['interval'])) {
324
				if($_POST['interval'] > $apinger_default['down']) {
325
					$input_errors[] = gettext(sprintf("The Frequency Probe interval needs to be less than the default down time setting (%d)", $apinger_default['down']));
326
				}
327
			}
328
		}
329
		if($_POST['down']){
330
			if (is_numeric($_POST['down'])) {
331
				if($_POST['down'] < $apinger_default['interval']) {
332
					$input_errors[] = gettext(sprintf("The down time setting needs to be higher than the default Frequency Probe interval (%d)", $apinger_default['interval']));
333
				}
334
			}
335
		}
336
	}
337 023920e7 Ermal
338 d173230c Seth Mos
	if (!$input_errors) {
339 c6865c5e Ermal
		$reloadif = "";
340 d44d26c1 Ermal
		$gateway = array();
341
342
		if (empty($_POST['interface']))
343
			$gateway['interface'] = $pconfig['friendlyiface'];
344
		else
345 3befe730 Ermal
			$gateway['interface'] = $_POST['interface'];
346 d44d26c1 Ermal
		if (is_ipaddr($_POST['gateway']))
347
			$gateway['gateway'] = $_POST['gateway'];
348
		else
349
			$gateway['gateway'] = "dynamic";
350
		$gateway['name'] = $_POST['name'];
351
		$gateway['weight'] = $_POST['weight'];
352 e02caf4a smos
		$gateway['ipprotocol'] = $_POST['ipprotocol'];
353 f7203985 Ermal
		$gateway['interval'] = $_POST['interval'];
354 d44d26c1 Ermal
		$gateway['descr'] = $_POST['descr'];
355 33c06ef7 Ermal
		if ($_POST['monitor_disable'] == "yes")
356
			$gateway['monitor_disable'] = true;
357
		else if (is_ipaddr($_POST['monitor']))
358 d44d26c1 Ermal
			$gateway['monitor'] = $_POST['monitor'];
359
360
		if ($_POST['defaultgw'] == "yes" || $_POST['defaultgw'] == "on") {
361
			$i = 0;
362 2f14d021 Seth Mos
			/* remove the default gateway bits for all gateways with the same address family */
363 a531d687 Ermal
			foreach($a_gateway_item as $gw) {
364 2f14d021 Seth Mos
				if(is_ipaddrv4($gateway['gateway']) && is_ipaddrv4($gw['gateway'])) {
365
					unset($config['gateways']['gateway_item'][$i]['defaultgw']);
366
					if ($gw['interface'] != $_POST['interface'] && $gw['defaultgw'])
367
						$reloadif = $gw['interface'];
368
				}
369
				if(is_ipaddrv6($gateway['gateway']) && is_ipaddrv6($gw['gateway'])) {
370
					unset($config['gateways']['gateway_item'][$i]['defaultgw']);
371
					if ($gw['interface'] != $_POST['interface'] && $gw['defaultgw'])
372
						$reloadif = $gw['interface'];
373
				}
374 d44d26c1 Ermal
				$i++;
375 bb849003 Ermal
			}
376 d44d26c1 Ermal
			$gateway['defaultgw'] = true;
377 124aee67 Chris Buechler
		}
378 d44d26c1 Ermal
379
		if ($_POST['latencylow'])
380
			$gateway['latencylow'] = $_POST['latencylow'];
381
		if ($_POST['latencyhigh'])
382
               		$gateway['latencyhigh'] = $_POST['latencyhigh'];
383
		if ($_POST['losslow'])
384 a0edece9 Darren Embry
			$gateway['losslow'] = $_POST['losslow'];
385 d44d26c1 Ermal
		if ($_POST['losshigh'])
386
               		$gateway['losshigh'] = $_POST['losshigh'];
387
		if ($_POST['down'])
388
               		$gateway['down'] = $_POST['down'];
389
390
		/* when saving the manual gateway we use the attribute which has the corresponding id */
391
		if (isset($id) && $a_gateway_item[$id])
392
			$a_gateway_item[$id] = $gateway;
393
		else
394
			$a_gateway_item[] = $gateway;
395
396 a368a026 Ermal Lu?i
		mark_subsystem_dirty('staticroutes');
397 d44d26c1 Ermal
	
398 d173230c Seth Mos
		write_config();
399 d44d26c1 Ermal
400 ad862220 Charlie
		if($_REQUEST['isAjax']) {
401
			echo $_POST['name'];
402
			exit;
403 c6865c5e Ermal
		} else if (!empty($reloadif))
404
			send_event("interface reconfigure {$reloadif}");
405 ad862220 Charlie
		
406 d173230c Seth Mos
		header("Location: system_gateways.php");
407
		exit;
408 ea939fc3 Ermal
	} else {
409 a0edece9 Darren Embry
		if ($_REQUEST['isAjax']) {
410
			header("HTTP/1.0 500 Internal Server Error");
411
			header("Content-type: text/plain");
412
			foreach ($input_errors as $error) {
413
				echo("$error\n");
414
			}
415
			exit;
416
		}
417
		
418 883c53c9 Ermal Lu?i
		$pconfig = $_POST;
419 ea939fc3 Ermal
		if (empty($_POST['friendlyiface']))
420
			$pconfig['friendlyiface'] = $_POST['interface'];
421
	}
422 d173230c Seth Mos
}
423
424 2328dcc5 Seth Mos
425 df152a88 Carlos Eduardo Ramos
$pgtitle = array(gettext("System"),gettext("Gateways"),gettext("Edit gateway"));
426 b32dd0a6 jim-p
$shortcut_section = "gateways";
427 02ca24c9 jim-p
428 d173230c Seth Mos
include("head.inc");
429
430
?>
431
432
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
433
<?php include("fbegin.inc"); ?>
434 883c53c9 Ermal Lu?i
<script language="JavaScript">
435 023920e7 Ermal
function show_advanced_gateway() {
436
        document.getElementById("showadvgatewaybox").innerHTML='';
437
        aodiv = document.getElementById('showgatewayadv');
438
        aodiv.style.display = "block";
439
}
440 33c06ef7 Ermal
function monitor_change() {
441
        document.iform.monitor.disabled = document.iform.monitor_disable.checked;
442
}
443 883c53c9 Ermal Lu?i
</script>
444 d173230c Seth Mos
<?php if ($input_errors) print_input_errors($input_errors); ?>
445
            <form action="system_gateways_edit.php" method="post" name="iform" id="iform">
446 124aee67 Chris Buechler
	<?php
447 e9df5769 Seth Mos
448
	/* If this is a system gateway we need this var */
449 124aee67 Chris Buechler
	if(($pconfig['attribute'] == "system") || is_numeric($pconfig['attribute'])) {
450 a138f065 jim-p
		echo "<input type='hidden' name='attribute' id='attribute' value='" . htmlspecialchars($pconfig['attribute']) . "' >\n";
451 124aee67 Chris Buechler
	}
452 a138f065 jim-p
	echo "<input type='hidden' name='friendlyiface' id='friendlyiface' value='" . htmlspecialchars($pconfig['friendlyiface']) . "' >\n";
453 124aee67 Chris Buechler
	?>
454 d173230c Seth Mos
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
455 56d4e7fb Scott Ullrich
				<tr>
456 df152a88 Carlos Eduardo Ramos
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit gateway"); ?></td>
457 56d4e7fb Scott Ullrich
				</tr>	
458 d173230c Seth Mos
                <tr> 
459 df152a88 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
460 d173230c Seth Mos
                  <td width="78%" class="vtable">
461 d44d26c1 Ermal
		 	<select name='interface' class='formselect' >
462 bb849003 Ermal
463 11d2be54 Ermal
		<?php 
464 883c53c9 Ermal Lu?i
                      	$interfaces = get_configured_interface_with_descr(false, true);
465
			foreach ($interfaces as $iface => $ifacename) {
466
				echo "<option value=\"{$iface}\"";
467
				if ($iface == $pconfig['friendlyiface'])
468
					echo " selected";
469
				echo ">" . htmlspecialchars($ifacename) . "</option>";
470
			}
471
			if (is_package_installed("openbgpd") == 1) {
472
				echo "<option value=\"bgpd\"";
473
				if ($pconfig['interface'] == "bgpd") 
474
					echo " selected";
475 df152a88 Carlos Eduardo Ramos
				echo ">" . gettext("Use BGPD") . "</option>";
476 883c53c9 Ermal Lu?i
			}
477
 		  ?>
478 d173230c Seth Mos
                    </select> <br>
479 df152a88 Carlos Eduardo Ramos
                    <span class="vexpl"><?=gettext("Choose which interface this gateway applies to."); ?></span></td>
480 d173230c Seth Mos
                </tr>
481 c1d36d26 smos
                <tr> 
482
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Address Family"); ?></td>
483
                  <td width="78%" class="vtable">
484
		 	<select name='ipprotocol' class='formselect' >
485
		<?php
486
			$options = array("inet" => "IPv4", "inet6" => "IPv6");
487
			foreach ($options as $name => $string) {
488
				echo "<option value=\"{$name}\"";
489
				if ($name == $pconfig['ipprotocol'])
490
					echo " selected";
491
				echo ">" . htmlspecialchars($string) . "</option>\n";
492
			}
493
		?>
494
                    </select> <br>
495
                    <span class="vexpl"><?=gettext("Choose the Internet Protocol this gateway uses."); ?></span></td>
496 d173230c Seth Mos
                <tr>
497 df152a88 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
498 d173230c Seth Mos
                  <td width="78%" class="vtable"> 
499
                    <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
500 df152a88 Carlos Eduardo Ramos
                    <br> <span class="vexpl"><?=gettext("Gateway name"); ?></span></td>
501 d173230c Seth Mos
                </tr>
502
		<tr>
503 df152a88 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway"); ?></td>
504 d173230c Seth Mos
                  <td width="78%" class="vtable"> 
505 a138f065 jim-p
                    <input name="gateway" type="text" class="formfld host" id="gateway" size="28" value="<?php if ($pconfig['dynamic']) echo "dynamic"; else echo htmlspecialchars($pconfig['gateway']); ?>">
506 df152a88 Carlos Eduardo Ramos
                    <br> <span class="vexpl"><?=gettext("Gateway IP address"); ?></span></td>
507 d173230c Seth Mos
                </tr>
508
		<tr>
509 df152a88 Carlos Eduardo Ramos
		  <td width="22%" valign="top" class="vncell"><?=gettext("Default Gateway"); ?></td>
510 d173230c Seth Mos
		  <td width="78%" class="vtable">
511 d44d26c1 Ermal
			<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if ($pconfig['defaultgw'] == true) echo "checked"; ?> />
512 df152a88 Carlos Eduardo Ramos
			<strong><?=gettext("Default Gateway"); ?></strong><br />
513
			<?=gettext("This will select the above gateway as the default gateway"); ?>
514 d173230c Seth Mos
		  </td>
515
		</tr>
516 33c06ef7 Ermal
		<tr>
517
		  <td width="22%" valign="top" class="vncell"><?=gettext("Disable Gateway Monitoring"); ?></td>
518
		  <td width="78%" class="vtable">
519
			<input name="monitor_disable" type="checkbox" id="monitor_disable" value="yes" <?php if ($pconfig['monitor_disable'] == true) echo "checked"; ?> onClick="monitor_change()" />
520
			<strong><?=gettext("Disable Gateway Monitoring"); ?></strong><br />
521
			<?=gettext("This will consider this gateway as always being up"); ?>
522
		  </td>
523
		</tr>
524 d173230c Seth Mos
		<tr>
525 df152a88 Carlos Eduardo Ramos
		  <td width="22%" valign="top" class="vncell"><?=gettext("Monitor IP"); ?></td>
526 d173230c Seth Mos
		  <td width="78%" class="vtable">
527 616e1956 Seth Mos
			<?php
528 d44d26c1 Ermal
				if ($pconfig['gateway'] == $pconfig['monitor'])
529 616e1956 Seth Mos
					$monitor = "";
530 d44d26c1 Ermal
				else
531 616e1956 Seth Mos
					$monitor = htmlspecialchars($pconfig['monitor']);
532
			?>
533 a138f065 jim-p
			<input name="monitor" type="text" id="monitor" value="<?php echo htmlspecialchars($monitor); ?>" size="28" />
534 df152a88 Carlos Eduardo Ramos
			<strong><?=gettext("Alternative monitor IP"); ?></strong> <br />
535 e88ace75 Chris Buechler
			<?=gettext("Enter an alternative address here to be used to monitor the link. This is used for the " .
536 0e94685b Renato Botelho
			"quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond " .
537
			"to ICMP echo requests (pings)"); ?>.</strong>
538 d173230c Seth Mos
			<br />
539
		  </td>
540
		</tr>
541 5f53260a Ermal
		<tr>
542 023920e7 Ermal
		  <td width="22%" valign="top" class="vncell"><?=gettext("Advanced");?></td>
543 5f53260a Ermal
		  <td width="78%" class="vtable">
544 eb233517 Phil Davis
			<?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']))); ?>
545 a3381369 Colin Fleming
			<div id="showadvgatewaybox" <?php if ($showbutton) echo "style='display:none'"; ?>>
546 023920e7 Ermal
				<input type="button" onClick="show_advanced_gateway()" value="Advanced"></input> - Show advanced option</a>
547
			</div>
548 a3381369 Colin Fleming
			<div id="showgatewayadv" <?php if (!$showbutton) echo "style='display:none'"; ?>>
549 023920e7 Ermal
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="6">
550
			<tr>
551
                                <td width="22%" valign="top" class="vncellreq"><?=gettext("Weight");?></td>
552
                                <td width="78%" class="vtable">
553
					<select name='weight' class='formfldselect' id='weight'>
554
				<?php
555
					for ($i = 1; $i < 6; $i++) {
556
                                        	$selected = "";
557
                                        	if ($pconfig['weight'] == $i)
558
                                                	$selected = "selected";
559
                                        	echo "<option value='{$i}' {$selected} >{$i}</option>";
560
                                	}
561
				?>
562
					</select>
563
					<br /><?=gettext("Weight for this gateway when used in a Gateway Group.");?> <br />
564
		   		</td>
565
			</tr>
566
                        <tr>
567
                                <td width="22%" valign="top" class="vncellreq"><?=gettext("Latency thresholds");?></td>
568
                                <td width="78%" class="vtable">
569
                                <?=gettext("From");?>
570
                                    <input name="latencylow" type="text" class="formfld unknown" id="latencylow" size="2"
571
                                        value="<?=htmlspecialchars($pconfig['latencylow']);?>">
572
                                <?=gettext("To");?>
573
                                    <input name="latencyhigh" type="text" class="formfld unknown" id="latencyhigh" size="2"
574
                                        value="<?=htmlspecialchars($pconfig['latencyhigh']);?>">
575 eb233517 Phil Davis
                                    <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></td>
576 023920e7 Ermal
                                </td>
577
                        </tr>
578
                        <tr>
579
                                <td width="22%" valign="top" class="vncellreq"><?=gettext("Packet Loss thresholds");?></td>
580
                                <td width="78%" class="vtable">
581
                                <?=gettext("From");?>
582
                                    <input name="losslow" type="text" class="formfld unknown" id="losslow" size="2"
583
                                        value="<?=htmlspecialchars($pconfig['losslow']);?>">
584
                                <?=gettext("To");?>
585
                                    <input name="losshigh" type="text" class="formfld unknown" id="losshigh" size="2"
586
                                        value="<?=htmlspecialchars($pconfig['losshigh']);?>">
587 eb233517 Phil Davis
                                    <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></td>
588 023920e7 Ermal
                                </td>
589
                        </tr>
590
			<tr>
591 ec9bb09f jim-p
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Frequency Probe");?></td>
592
				<td width="78%" class="vtable">
593
					<input name="interval" type="text" class="formfld unknown" id="interval" size="2"
594
						value="<?=htmlspecialchars($pconfig['interval']);?>">
595
					<br><span class="vexpl">
596 eb233517 Phil Davis
						<?=gettext(sprintf("How often that an ICMP probe will be sent in seconds. Default is %d.", $apinger_default['interval']));?><br/><br/>
597 ec9bb09f jim-p
						<?=gettext("NOTE: The quality graph is averaged over seconds, not intervals, so as the frequency probe is increased the accuracy of the quality graph is decreased.");?>
598
					</span></td>
599
				</td>
600
			</tr>
601 f7203985 Ermal
			<tr>
602 ec9bb09f jim-p
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Down");?></td>
603
				<td width="78%" class="vtable">
604
					<input name="down" type="text" class="formfld unknown" id="down" size="2"
605
						value="<?=htmlspecialchars($pconfig['down']);?>">
606 eb233517 Phil Davis
					<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></td>
607 ec9bb09f jim-p
				</td>
608
			</tr>
609
			<tr>
610
				<td colspan="2">
611 eb233517 Phil Davis
					<?= gettext("NOTE: The Frequency 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/>
612 ec9bb09f jim-p
				</td>
613
			</tr>
614 023920e7 Ermal
                        </table>
615
			</div>
616 5f53260a Ermal
		   </td>
617
		</tr>
618 d173230c Seth Mos
		<tr>
619 df152a88 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
620 d173230c Seth Mos
                  <td width="78%" class="vtable"> 
621
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
622 0e94685b Renato Botelho
                    <br> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)"); ?>.</span></td>
623 d173230c Seth Mos
                </tr>
624
                <tr>
625
                  <td width="22%" valign="top">&nbsp;</td>
626
                  <td width="78%"> 
627 bfb0b9dc Vinicius Coque
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>"> <input type="button" value="<?=gettext("Cancel");?>" class="formbtn"  onclick="history.back()">
628 d173230c Seth Mos
                    <?php if (isset($id) && $a_gateways[$id]): ?>
629 225a2f0b Scott Ullrich
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
630 d173230c Seth Mos
                    <?php endif; ?>
631
                  </td>
632
                </tr>
633
              </table>
634
</form>
635
<?php include("fend.inc"); ?>
636
<script language="JavaScript">
637 33c06ef7 Ermal
monitor_change();
638 d173230c Seth Mos
</script>
639
</body>
640 eb233517 Phil Davis
</html>