1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
system_gateways_edit.php
|
5
|
part of pfSense (https://www.pfsense.org)
|
6
|
|
7
|
Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
|
8
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
/*
|
33
|
pfSense_MODULE: routing
|
34
|
*/
|
35
|
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-system-gateways-editgateway
|
38
|
##|*NAME=System: Gateways: Edit Gateway page
|
39
|
##|*DESCR=Allow access to the 'System: Gateways: Edit Gateway' page.
|
40
|
##|*MATCH=system_gateways_edit.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
require("guiconfig.inc");
|
44
|
require("pkg-utils.inc");
|
45
|
|
46
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_gateways.php');
|
47
|
|
48
|
$a_gateways = return_gateways_array(true, false, true);
|
49
|
$a_gateways_arr = array();
|
50
|
foreach($a_gateways as $gw) {
|
51
|
$a_gateways_arr[] = $gw;
|
52
|
}
|
53
|
$a_gateways = $a_gateways_arr;
|
54
|
|
55
|
if (!is_array($config['gateways']['gateway_item']))
|
56
|
$config['gateways']['gateway_item'] = array();
|
57
|
|
58
|
$a_gateway_item = &$config['gateways']['gateway_item'];
|
59
|
$apinger_default = return_apinger_defaults();
|
60
|
|
61
|
if (is_numericint($_GET['id']))
|
62
|
$id = $_GET['id'];
|
63
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
64
|
$id = $_POST['id'];
|
65
|
|
66
|
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
|
67
|
$id = $_GET['dup'];
|
68
|
|
69
|
if (isset($id) && $a_gateways[$id]) {
|
70
|
$pconfig = array();
|
71
|
$pconfig['name'] = $a_gateways[$id]['name'];
|
72
|
$pconfig['weight'] = $a_gateways[$id]['weight'];
|
73
|
$pconfig['interval'] = $a_gateways[$id]['interval'];
|
74
|
$pconfig['avg_delay_samples'] = $a_gateways[$id]['avg_delay_samples'];
|
75
|
$pconfig['avg_delay_samples_calculated'] = isset($a_gateways[$id]['avg_delay_samples_calculated']);
|
76
|
$pconfig['avg_loss_samples'] = $a_gateways[$id]['avg_loss_samples'];
|
77
|
$pconfig['avg_loss_samples_calculated'] = isset($a_gateways[$id]['avg_loss_samples_calculated']);
|
78
|
$pconfig['avg_loss_delay_samples'] = $a_gateways[$id]['avg_loss_delay_samples'];
|
79
|
$pconfig['avg_loss_delay_samples_calculated'] = isset($a_gateways[$id]['avg_loss_delay_samples_calculated']);
|
80
|
$pconfig['interface'] = $a_gateways[$id]['interface'];
|
81
|
$pconfig['friendlyiface'] = $a_gateways[$id]['friendlyiface'];
|
82
|
$pconfig['ipprotocol'] = $a_gateways[$id]['ipprotocol'];
|
83
|
if (isset($a_gateways[$id]['dynamic']))
|
84
|
$pconfig['dynamic'] = true;
|
85
|
$pconfig['gateway'] = $a_gateways[$id]['gateway'];
|
86
|
$pconfig['defaultgw'] = isset($a_gateways[$id]['defaultgw']);
|
87
|
$pconfig['force_down'] = isset($a_gateways[$id]['force_down']);
|
88
|
$pconfig['latencylow'] = $a_gateways[$id]['latencylow'];
|
89
|
$pconfig['latencyhigh'] = $a_gateways[$id]['latencyhigh'];
|
90
|
$pconfig['losslow'] = $a_gateways[$id]['losslow'];
|
91
|
$pconfig['losshigh'] = $a_gateways[$id]['losshigh'];
|
92
|
$pconfig['down'] = $a_gateways[$id]['down'];
|
93
|
$pconfig['monitor'] = $a_gateways[$id]['monitor'];
|
94
|
$pconfig['monitor_disable'] = isset($a_gateways[$id]['monitor_disable']);
|
95
|
$pconfig['descr'] = $a_gateways[$id]['descr'];
|
96
|
$pconfig['attribute'] = $a_gateways[$id]['attribute'];
|
97
|
$pconfig['disabled'] = isset($a_gateways[$id]['disabled']);
|
98
|
}
|
99
|
|
100
|
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) {
|
101
|
unset($id);
|
102
|
unset($pconfig['attribute']);
|
103
|
}
|
104
|
|
105
|
if (isset($id) && $a_gateways[$id])
|
106
|
$realid = $a_gateways[$id]['attribute'];
|
107
|
|
108
|
if ($_POST) {
|
109
|
|
110
|
unset($input_errors);
|
111
|
|
112
|
/* input validation */
|
113
|
$reqdfields = explode(" ", "name interface");
|
114
|
$reqdfieldsn = array(gettext("Name"), gettext("Interface"));
|
115
|
|
116
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
117
|
|
118
|
if (! isset($_POST['name'])) {
|
119
|
$input_errors[] = "A valid gateway name must be specified.";
|
120
|
}
|
121
|
if (! is_validaliasname($_POST['name'])) {
|
122
|
$input_errors[] = gettext("The gateway name must not contain invalid characters.");
|
123
|
}
|
124
|
/* skip system gateways which have been automatically added */
|
125
|
if (($_POST['gateway'] && (!is_ipaddr($_POST['gateway'])) && ($_POST['attribute'] !== "system")) && ($_POST['gateway'] != "dynamic")) {
|
126
|
$input_errors[] = gettext("A valid gateway IP address must be specified.");
|
127
|
}
|
128
|
|
129
|
if ($_POST['gateway'] && (is_ipaddr($_POST['gateway'])) && !$_REQUEST['isAjax']) {
|
130
|
if(is_ipaddrv4($_POST['gateway'])) {
|
131
|
$parent_ip = get_interface_ip($_POST['interface']);
|
132
|
$parent_sn = get_interface_subnet($_POST['interface']);
|
133
|
if(empty($parent_ip) || empty($parent_sn)) {
|
134
|
$input_errors[] = gettext("Cannot add IPv4 Gateway Address because no IPv4 address could be found on the interface.");
|
135
|
} else {
|
136
|
$subnets = array(gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn);
|
137
|
$vips = link_interface_to_vips($_POST['interface']);
|
138
|
if (is_array($vips))
|
139
|
foreach($vips as $vip) {
|
140
|
if (!is_ipaddrv4($vip['subnet']))
|
141
|
continue;
|
142
|
$subnets[] = gen_subnet($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits'];
|
143
|
}
|
144
|
|
145
|
$found = false;
|
146
|
foreach($subnets as $subnet)
|
147
|
if(ip_in_subnet($_POST['gateway'], $subnet)) {
|
148
|
$found = true;
|
149
|
break;
|
150
|
}
|
151
|
|
152
|
if ($found === false)
|
153
|
$input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within one of the chosen interface's subnets."), $_POST['gateway']);
|
154
|
}
|
155
|
}
|
156
|
else if(is_ipaddrv6($_POST['gateway'])) {
|
157
|
/* do not do a subnet match on a link local address, it's valid */
|
158
|
if(!is_linklocal($_POST['gateway'])) {
|
159
|
$parent_ip = get_interface_ipv6($_POST['interface']);
|
160
|
$parent_sn = get_interface_subnetv6($_POST['interface']);
|
161
|
if(empty($parent_ip) || empty($parent_sn)) {
|
162
|
$input_errors[] = gettext("Cannot add IPv6 Gateway Address because no IPv6 address could be found on the interface.");
|
163
|
} else {
|
164
|
$subnets = array(gen_subnetv6($parent_ip, $parent_sn) . "/" . $parent_sn);
|
165
|
$vips = link_interface_to_vips($_POST['interface']);
|
166
|
if (is_array($vips))
|
167
|
foreach($vips as $vip) {
|
168
|
if (!is_ipaddrv6($vip['subnet']))
|
169
|
continue;
|
170
|
$subnets[] = gen_subnetv6($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits'];
|
171
|
}
|
172
|
|
173
|
$found = false;
|
174
|
foreach($subnets as $subnet)
|
175
|
if(ip_in_subnet($_POST['gateway'], $subnet)) {
|
176
|
$found = true;
|
177
|
break;
|
178
|
}
|
179
|
|
180
|
if ($found === false)
|
181
|
$input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within one of the chosen interface's subnets."), $_POST['gateway']);
|
182
|
}
|
183
|
}
|
184
|
}
|
185
|
|
186
|
if (!empty($config['interfaces'][$_POST['interface']]['ipaddr'])) {
|
187
|
if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddr']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic"))
|
188
|
$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv4 configuration.");
|
189
|
}
|
190
|
if (!empty($config['interfaces'][$_POST['interface']]['ipaddrv6'])) {
|
191
|
if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddrv6']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic"))
|
192
|
$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv6 configuration.");
|
193
|
}
|
194
|
}
|
195
|
if (($_POST['monitor'] != "") && !is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") {
|
196
|
$input_errors[] = gettext("A valid monitor IP address must be specified.");
|
197
|
}
|
198
|
/* only allow correct IPv4 and IPv6 gateway addresses */
|
199
|
if (($_POST['gateway'] != "") && is_ipaddr($_POST['gateway']) && $_POST['gateway'] != "dynamic") {
|
200
|
if(is_ipaddrv6($_POST['gateway']) && ($_POST['ipprotocol'] == "inet")) {
|
201
|
$input_errors[] = gettext("The IPv6 gateway address '{$_POST['gateway']}' can not be used as a IPv4 gateway'.");
|
202
|
}
|
203
|
if(is_ipaddrv4($_POST['gateway']) && ($_POST['ipprotocol'] == "inet6")) {
|
204
|
$input_errors[] = gettext("The IPv4 gateway address '{$_POST['gateway']}' can not be used as a IPv6 gateway'.");
|
205
|
}
|
206
|
}
|
207
|
/* only allow correct IPv4 and IPv6 monitor addresses */
|
208
|
if (($_POST['monitor'] != "") && is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") {
|
209
|
if(is_ipaddrv6($_POST['monitor']) && ($_POST['ipprotocol'] == "inet")) {
|
210
|
$input_errors[] = gettext("The IPv6 monitor address '{$_POST['monitor']}' can not be used on a IPv4 gateway'.");
|
211
|
}
|
212
|
if(is_ipaddrv4($_POST['monitor']) && ($_POST['ipprotocol'] == "inet6")) {
|
213
|
$input_errors[] = gettext("The IPv4 monitor address '{$_POST['monitor']}' can not be used on a IPv6 gateway'.");
|
214
|
}
|
215
|
}
|
216
|
|
217
|
if (isset($_POST['name'])) {
|
218
|
/* check for overlaps */
|
219
|
foreach ($a_gateways as $gateway) {
|
220
|
if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway)) {
|
221
|
if ($gateway['name'] != $_POST['name'])
|
222
|
$input_errors[] = gettext("Changing name on a gateway is not allowed.");
|
223
|
continue;
|
224
|
}
|
225
|
if($_POST['name'] != "") {
|
226
|
if (($gateway['name'] != "") && ($_POST['name'] == $gateway['name']) && ($gateway['attribute'] !== "system")) {
|
227
|
$input_errors[] = sprintf(gettext('The gateway name "%s" already exists.'), $_POST['name']);
|
228
|
break;
|
229
|
}
|
230
|
}
|
231
|
if(is_ipaddr($_POST['gateway'])) {
|
232
|
if (($gateway['gateway'] != "") && ($_POST['gateway'] == $gateway['gateway']) && ($gateway['attribute'] !== "system")) {
|
233
|
$input_errors[] = sprintf(gettext('The gateway IP address "%s" already exists.'), $_POST['gateway']);
|
234
|
break;
|
235
|
}
|
236
|
}
|
237
|
if(is_ipaddr($_POST['monitor'])) {
|
238
|
if (($gateway['monitor'] != "") && ($_POST['monitor'] == $gateway['monitor']) && ($gateway['attribute'] !== "system")) {
|
239
|
$input_errors[] = sprintf(gettext('The monitor IP address "%s" is already in use. You must choose a different monitor IP.'), $_POST['monitor']);
|
240
|
break;
|
241
|
}
|
242
|
}
|
243
|
}
|
244
|
}
|
245
|
|
246
|
/* input validation of apinger advanced parameters */
|
247
|
if($_POST['latencylow']) {
|
248
|
if (! is_numeric($_POST['latencylow'])) {
|
249
|
$input_errors[] = gettext("The low latency threshold needs to be a numeric value.");
|
250
|
} else {
|
251
|
if ($_POST['latencylow'] < 1) {
|
252
|
$input_errors[] = gettext("The low latency threshold needs to be positive.");
|
253
|
}
|
254
|
}
|
255
|
}
|
256
|
|
257
|
if($_POST['latencyhigh']) {
|
258
|
if (! is_numeric($_POST['latencyhigh'])) {
|
259
|
$input_errors[] = gettext("The high latency threshold needs to be a numeric value.");
|
260
|
} else {
|
261
|
if ($_POST['latencyhigh'] < 1) {
|
262
|
$input_errors[] = gettext("The high latency threshold needs to be positive.");
|
263
|
}
|
264
|
}
|
265
|
}
|
266
|
|
267
|
if($_POST['losslow']) {
|
268
|
if (! is_numeric($_POST['losslow'])) {
|
269
|
$input_errors[] = gettext("The low Packet Loss threshold needs to be a numeric value.");
|
270
|
} else {
|
271
|
if ($_POST['losslow'] < 1) {
|
272
|
$input_errors[] = gettext("The low Packet Loss threshold needs to be positive.");
|
273
|
}
|
274
|
if ($_POST['losslow'] >= 100) {
|
275
|
$input_errors[] = gettext("The low Packet Loss threshold needs to be less than 100.");
|
276
|
}
|
277
|
}
|
278
|
}
|
279
|
|
280
|
if($_POST['losshigh']) {
|
281
|
if (! is_numeric($_POST['losshigh'])) {
|
282
|
$input_errors[] = gettext("The high Packet Loss threshold needs to be a numeric value.");
|
283
|
} else {
|
284
|
if ($_POST['losshigh'] < 1) {
|
285
|
$input_errors[] = gettext("The high Packet Loss threshold needs to be positive.");
|
286
|
}
|
287
|
if ($_POST['losshigh'] > 100) {
|
288
|
$input_errors[] = gettext("The high Packet Loss threshold needs to be 100 or less.");
|
289
|
}
|
290
|
}
|
291
|
}
|
292
|
|
293
|
if(($_POST['latencylow']) && ($_POST['latencyhigh'])) {
|
294
|
if ((is_numeric($_POST['latencylow'])) && (is_numeric($_POST['latencyhigh']))) {
|
295
|
if(($_POST['latencylow'] > $_POST['latencyhigh'])) {
|
296
|
$input_errors[] = gettext("The high latency threshold needs to be higher than the low latency threshold");
|
297
|
}
|
298
|
}
|
299
|
} else {
|
300
|
if($_POST['latencylow']){
|
301
|
if (is_numeric($_POST['latencylow'])) {
|
302
|
if($_POST['latencylow'] > $apinger_default['latencyhigh']) {
|
303
|
$input_errors[] = gettext(sprintf("The low latency threshold needs to be less than the default high latency threshold (%d)", $apinger_default['latencyhigh']));
|
304
|
}
|
305
|
}
|
306
|
}
|
307
|
if($_POST['latencyhigh']){
|
308
|
if (is_numeric($_POST['latencyhigh'])) {
|
309
|
if($_POST['latencyhigh'] < $apinger_default['latencylow']) {
|
310
|
$input_errors[] = gettext(sprintf("The high latency threshold needs to be higher than the default low latency threshold (%d)", $apinger_default['latencylow']));
|
311
|
}
|
312
|
}
|
313
|
}
|
314
|
}
|
315
|
|
316
|
if(($_POST['losslow']) && ($_POST['losshigh'])){
|
317
|
if ((is_numeric($_POST['losslow'])) && (is_numeric($_POST['losshigh']))) {
|
318
|
if($_POST['losslow'] > $_POST['losshigh']) {
|
319
|
$input_errors[] = gettext("The high Packet Loss threshold needs to be higher than the low Packet Loss threshold");
|
320
|
}
|
321
|
}
|
322
|
} else {
|
323
|
if($_POST['losslow']){
|
324
|
if (is_numeric($_POST['losslow'])) {
|
325
|
if($_POST['losslow'] > $apinger_default['losshigh']) {
|
326
|
$input_errors[] = gettext(sprintf("The low Packet Loss threshold needs to be less than the default high Packet Loss threshold (%d)", $apinger_default['losshigh']));
|
327
|
}
|
328
|
}
|
329
|
}
|
330
|
if($_POST['losshigh']){
|
331
|
if (is_numeric($_POST['losshigh'])) {
|
332
|
if($_POST['losshigh'] < $apinger_default['losslow']) {
|
333
|
$input_errors[] = gettext(sprintf("The high Packet Loss threshold needs to be higher than the default low Packet Loss threshold (%d)", $apinger_default['losslow']));
|
334
|
}
|
335
|
}
|
336
|
}
|
337
|
}
|
338
|
|
339
|
if($_POST['interval']) {
|
340
|
if (! is_numeric($_POST['interval'])) {
|
341
|
$input_errors[] = gettext("The probe interval needs to be a numeric value.");
|
342
|
} else {
|
343
|
if ($_POST['interval'] < 1) {
|
344
|
$input_errors[] = gettext("The probe interval needs to be positive.");
|
345
|
}
|
346
|
}
|
347
|
}
|
348
|
|
349
|
if($_POST['down']) {
|
350
|
if (! is_numeric($_POST['down'])) {
|
351
|
$input_errors[] = gettext("The down time setting needs to be a numeric value.");
|
352
|
} else {
|
353
|
if ($_POST['down'] < 1) {
|
354
|
$input_errors[] = gettext("The down time setting needs to be positive.");
|
355
|
}
|
356
|
}
|
357
|
}
|
358
|
|
359
|
if(($_POST['interval']) && ($_POST['down'])){
|
360
|
if ((is_numeric($_POST['interval'])) && (is_numeric($_POST['down']))) {
|
361
|
if($_POST['interval'] > $_POST['down']) {
|
362
|
$input_errors[] = gettext("The probe interval needs to be less than the down time setting.");
|
363
|
}
|
364
|
}
|
365
|
} else {
|
366
|
if($_POST['interval']){
|
367
|
if (is_numeric($_POST['interval'])) {
|
368
|
if($_POST['interval'] > $apinger_default['down']) {
|
369
|
$input_errors[] = gettext(sprintf("The probe interval needs to be less than the default down time setting (%d)", $apinger_default['down']));
|
370
|
}
|
371
|
}
|
372
|
}
|
373
|
if($_POST['down']){
|
374
|
if (is_numeric($_POST['down'])) {
|
375
|
if($_POST['down'] < $apinger_default['interval']) {
|
376
|
$input_errors[] = gettext(sprintf("The down time setting needs to be higher than the default probe interval (%d)", $apinger_default['interval']));
|
377
|
}
|
378
|
}
|
379
|
}
|
380
|
}
|
381
|
|
382
|
if($_POST['avg_delay_samples']) {
|
383
|
if (! is_numeric($_POST['avg_delay_samples'])) {
|
384
|
$input_errors[] = gettext("The average delay replies qty needs to be a numeric value.");
|
385
|
} else {
|
386
|
if ($_POST['avg_delay_samples'] < 1) {
|
387
|
$input_errors[] = gettext("The average delay replies qty needs to be positive.");
|
388
|
}
|
389
|
}
|
390
|
}
|
391
|
|
392
|
if($_POST['avg_loss_samples']) {
|
393
|
if (! is_numeric($_POST['avg_loss_samples'])) {
|
394
|
$input_errors[] = gettext("The average packet loss probes qty needs to be a numeric value.");
|
395
|
} else {
|
396
|
if ($_POST['avg_loss_samples'] < 1) {
|
397
|
$input_errors[] = gettext("The average packet loss probes qty needs to be positive.");
|
398
|
}
|
399
|
}
|
400
|
}
|
401
|
|
402
|
if($_POST['avg_loss_delay_samples']) {
|
403
|
if (! is_numeric($_POST['avg_loss_delay_samples'])) {
|
404
|
$input_errors[] = gettext("The lost probe delay needs to be a numeric value.");
|
405
|
} else {
|
406
|
if ($_POST['avg_loss_delay_samples'] < 1) {
|
407
|
$input_errors[] = gettext("The lost probe delay needs to be positive.");
|
408
|
}
|
409
|
}
|
410
|
}
|
411
|
|
412
|
if (!$input_errors) {
|
413
|
$reloadif = "";
|
414
|
$gateway = array();
|
415
|
|
416
|
if (empty($_POST['interface']))
|
417
|
$gateway['interface'] = $pconfig['friendlyiface'];
|
418
|
else
|
419
|
$gateway['interface'] = $_POST['interface'];
|
420
|
if (is_ipaddr($_POST['gateway']))
|
421
|
$gateway['gateway'] = $_POST['gateway'];
|
422
|
else
|
423
|
$gateway['gateway'] = "dynamic";
|
424
|
$gateway['name'] = $_POST['name'];
|
425
|
$gateway['weight'] = $_POST['weight'];
|
426
|
$gateway['ipprotocol'] = $_POST['ipprotocol'];
|
427
|
$gateway['interval'] = $_POST['interval'];
|
428
|
|
429
|
$gateway['avg_delay_samples'] = $_POST['avg_delay_samples'];
|
430
|
if ($_POST['avg_delay_samples_calculated'] == "yes" || $_POST['avg_delay_samples_calculated'] == "on")
|
431
|
$gateway['avg_delay_samples_calculated'] = true;
|
432
|
|
433
|
$gateway['avg_loss_samples'] = $_POST['avg_loss_samples'];
|
434
|
if ($_POST['avg_loss_samples_calculated'] == "yes" || $_POST['avg_loss_samples_calculated'] == "on")
|
435
|
$gateway['avg_loss_samples_calculated'] = true;
|
436
|
|
437
|
$gateway['avg_loss_delay_samples'] = $_POST['avg_loss_delay_samples'];
|
438
|
if ($_POST['avg_loss_delay_samples_calculated'] == "yes" || $_POST['avg_loss_delay_samples_calculated'] == "on")
|
439
|
$gateway['avg_loss_delay_samples_calculated'] = true;
|
440
|
|
441
|
$gateway['descr'] = $_POST['descr'];
|
442
|
if ($_POST['monitor_disable'] == "yes")
|
443
|
$gateway['monitor_disable'] = true;
|
444
|
if ($_POST['force_down'] == "yes")
|
445
|
$gateway['force_down'] = true;
|
446
|
if (is_ipaddr($_POST['monitor']))
|
447
|
$gateway['monitor'] = $_POST['monitor'];
|
448
|
|
449
|
/* NOTE: If monitor ip is changed need to cleanup the old static route */
|
450
|
if ($_POST['monitor'] != "dynamic" && !empty($a_gateway_item[$realid]) && is_ipaddr($a_gateway_item[$realid]['monitor']) &&
|
451
|
$_POST['monitor'] != $a_gateway_item[$realid]['monitor'] && $gateway['gateway'] != $a_gateway_item[$realid]['monitor']) {
|
452
|
if (is_ipaddrv4($a_gateway_item[$realid]['monitor']))
|
453
|
mwexec("/sbin/route delete " . escapeshellarg($a_gateway_item[$realid]['monitor']));
|
454
|
else
|
455
|
mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateway_item[$realid]['monitor']));
|
456
|
}
|
457
|
|
458
|
if ($_POST['defaultgw'] == "yes" || $_POST['defaultgw'] == "on") {
|
459
|
$i = 0;
|
460
|
/* remove the default gateway bits for all gateways with the same address family */
|
461
|
foreach($a_gateway_item as $gw) {
|
462
|
if ($gateway['ipprotocol'] == $gw['ipprotocol']) {
|
463
|
unset($config['gateways']['gateway_item'][$i]['defaultgw']);
|
464
|
if ($gw['interface'] != $_POST['interface'] && $gw['defaultgw'])
|
465
|
$reloadif = $gw['interface'];
|
466
|
}
|
467
|
$i++;
|
468
|
}
|
469
|
$gateway['defaultgw'] = true;
|
470
|
}
|
471
|
|
472
|
if ($_POST['latencylow'])
|
473
|
$gateway['latencylow'] = $_POST['latencylow'];
|
474
|
if ($_POST['latencyhigh'])
|
475
|
$gateway['latencyhigh'] = $_POST['latencyhigh'];
|
476
|
if ($_POST['losslow'])
|
477
|
$gateway['losslow'] = $_POST['losslow'];
|
478
|
if ($_POST['losshigh'])
|
479
|
$gateway['losshigh'] = $_POST['losshigh'];
|
480
|
if ($_POST['down'])
|
481
|
$gateway['down'] = $_POST['down'];
|
482
|
|
483
|
if(isset($_POST['disabled']))
|
484
|
$gateway['disabled'] = true;
|
485
|
else
|
486
|
unset($gateway['disabled']);
|
487
|
|
488
|
/* when saving the manual gateway we use the attribute which has the corresponding id */
|
489
|
if (isset($realid) && $a_gateway_item[$realid])
|
490
|
$a_gateway_item[$realid] = $gateway;
|
491
|
else
|
492
|
$a_gateway_item[] = $gateway;
|
493
|
|
494
|
mark_subsystem_dirty('staticroutes');
|
495
|
|
496
|
write_config();
|
497
|
|
498
|
if($_REQUEST['isAjax']) {
|
499
|
echo $_POST['name'];
|
500
|
exit;
|
501
|
} else if (!empty($reloadif))
|
502
|
send_event("interface reconfigure {$reloadif}");
|
503
|
|
504
|
header("Location: system_gateways.php");
|
505
|
exit;
|
506
|
} else {
|
507
|
if ($_REQUEST['isAjax']) {
|
508
|
header("HTTP/1.0 500 Internal Server Error");
|
509
|
header("Content-type: text/plain");
|
510
|
foreach ($input_errors as $error) {
|
511
|
echo("$error\n");
|
512
|
}
|
513
|
exit;
|
514
|
}
|
515
|
|
516
|
$pconfig = $_POST;
|
517
|
if (empty($_POST['friendlyiface']))
|
518
|
$pconfig['friendlyiface'] = $_POST['interface'];
|
519
|
}
|
520
|
}
|
521
|
|
522
|
|
523
|
$pgtitle = array(gettext("System"),gettext("Gateways"),gettext("Edit gateway"));
|
524
|
$shortcut_section = "gateways";
|
525
|
|
526
|
include("head.inc");
|
527
|
|
528
|
if ($input_errors)
|
529
|
print_input_errors($input_errors);
|
530
|
|
531
|
?>
|
532
|
<script>
|
533
|
var systemGatewaysEditRecalculate = function(){
|
534
|
var interval = $('#interval')[0].value;
|
535
|
|
536
|
$('input[name$=_calculated]').each(function (idx, c){
|
537
|
c = $(c);
|
538
|
i = $(c.parents('.form-group').find('input[type=number]')[0]);
|
539
|
|
540
|
c.prop('disabled', interval==0);
|
541
|
|
542
|
if (interval==0)
|
543
|
c.prop('checked', false);
|
544
|
|
545
|
if (!c.prop('checked'))
|
546
|
return i.prop('readonly', false);
|
547
|
|
548
|
switch (i.attr('name'))
|
549
|
{
|
550
|
case 'avg_delay_samples':
|
551
|
// How many replies should be used to compute average delay
|
552
|
// for controlling "delay" alarms.
|
553
|
// Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60).
|
554
|
i.attr('value', Math.round(60 * (1/6) / Math.pow(interval, 0.333)));
|
555
|
break;
|
556
|
|
557
|
case 'avg_loss_samples':
|
558
|
// How many probes should be used to compute average loss.
|
559
|
// Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60).
|
560
|
i.attr('value', Math.round(60 / interval));
|
561
|
break;
|
562
|
|
563
|
case 'avg_loss_delay_samples':
|
564
|
// The delay (in samples) after which loss is computed
|
565
|
// without this delays larger than interval would be treated as loss.
|
566
|
// Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60).
|
567
|
i.attr('value', Math.round(60 * (1/3) / interval));
|
568
|
break;
|
569
|
}
|
570
|
|
571
|
i.prop('readonly', true);
|
572
|
});
|
573
|
};
|
574
|
|
575
|
events.push(function(){
|
576
|
$('#interval').on('change', systemGatewaysEditRecalculate);
|
577
|
$('input[name$=_calculated]').on('change', systemGatewaysEditRecalculate);
|
578
|
|
579
|
systemGatewaysEditRecalculate();
|
580
|
});
|
581
|
</script>
|
582
|
<?php
|
583
|
|
584
|
require('classes/Form.class.php');
|
585
|
$form = new Form;
|
586
|
|
587
|
/* If this is a system gateway we need this var */
|
588
|
if(($pconfig['attribute'] == "system") || is_numeric($pconfig['attribute'])) {
|
589
|
$form->addGlobal(new Form_Input(
|
590
|
'attribute',
|
591
|
null,
|
592
|
'hidden',
|
593
|
$pconfig['attribute']
|
594
|
));
|
595
|
}
|
596
|
|
597
|
if (isset($id) && $a_gateways[$id]) {
|
598
|
$form->addGlobal(new Form_Input(
|
599
|
'id',
|
600
|
null,
|
601
|
'hidden',
|
602
|
$id
|
603
|
));
|
604
|
}
|
605
|
|
606
|
$form->addGlobal(new Form_Input(
|
607
|
'friendlyiface',
|
608
|
null,
|
609
|
'hidden',
|
610
|
$pconfig['friendlyiface']
|
611
|
));
|
612
|
|
613
|
$section = new Form_Section('Edit gateway');
|
614
|
|
615
|
$section->addInput(new Form_Checkbox(
|
616
|
'disabled',
|
617
|
'Disabled',
|
618
|
'Disable this gateway',
|
619
|
$pconfig['disabled']
|
620
|
))->setHelp('Set this option to disable this gateway without removing it from the '.
|
621
|
'list.');
|
622
|
|
623
|
$section->addInput(new Form_Select(
|
624
|
'interface',
|
625
|
'Interface',
|
626
|
$pconfig['friendlyiface'],
|
627
|
get_configured_interface_with_descr(false, true)
|
628
|
))->setHelp('Choose which interface this gateway applies to.');
|
629
|
|
630
|
$section->addInput(new Form_Select(
|
631
|
'ipprotocol',
|
632
|
'Address Family',
|
633
|
$pconfig['ipprotocol'],
|
634
|
array(
|
635
|
"inet" => "IPv4",
|
636
|
"inet6" => "IPv6"
|
637
|
)
|
638
|
))->setHelp('Choose the Internet Protocol this gateway uses.');
|
639
|
|
640
|
$section->addInput(new Form_Input(
|
641
|
'name',
|
642
|
'Name',
|
643
|
'text',
|
644
|
$pconfig['name']
|
645
|
))->setHelp('Gateway name');
|
646
|
|
647
|
$section->addInput(new Form_Input(
|
648
|
'gateway',
|
649
|
'Gateway',
|
650
|
'text',
|
651
|
($pconfig['dynamic'] ? 'dynamic' : $pconfig['gateway'])
|
652
|
))->setHelp('Gateway IP address');
|
653
|
|
654
|
$section->addInput(new Form_Checkbox(
|
655
|
'defaultgw',
|
656
|
'Default Gateway',
|
657
|
'This will select the above gateway as the default gateway',
|
658
|
$pconfig['defaultgw']
|
659
|
));
|
660
|
|
661
|
$section->addInput(new Form_Checkbox(
|
662
|
'monitor_disable',
|
663
|
'Gateway Monitoring',
|
664
|
'Disable Gateway Monitoring',
|
665
|
$pconfig['monitor_disable']
|
666
|
))->toggles('.toggle-monitor-ip')->setHelp('This will consider this gateway as always being up');
|
667
|
|
668
|
$group = new Form_Group('Monitor IP');
|
669
|
$group->addClass('toggle-monitor-ip', 'collapse');
|
670
|
|
671
|
if (!$pconfig['monitor_disable'])
|
672
|
$group->addClass('in');
|
673
|
|
674
|
$group->add(new Form_Input(
|
675
|
'monitor',
|
676
|
null,
|
677
|
'text',
|
678
|
($pconfig['gateway'] == $pconfig['monitor'] ? '' : $pconfig['monitor'])
|
679
|
))->setHelp('Enter an alternative address here to be '.
|
680
|
'used to monitor the link. This is used for the quality RRD graphs as well as the '.
|
681
|
'load balancer entries. Use this if the gateway does not respond to ICMP echo '.
|
682
|
'requests (pings).');
|
683
|
$section->add($group);
|
684
|
|
685
|
$section->addInput(new Form_Checkbox(
|
686
|
'force_down',
|
687
|
'Force state',
|
688
|
'Mark Gateway as Down',
|
689
|
$pconfig['force_down']
|
690
|
))->setHelp('This will force this gateway to be considered Down');
|
691
|
|
692
|
$section->addInput(new Form_Input(
|
693
|
'descr',
|
694
|
'Description',
|
695
|
'text',
|
696
|
$pconfig['descr']
|
697
|
))->setHelp('You may enter a description here for your reference (not parsed).');
|
698
|
|
699
|
$form->add($section);
|
700
|
$section = new Form_Section('Advanced');
|
701
|
|
702
|
$section->addInput(new Form_Select(
|
703
|
'weight',
|
704
|
'Weight',
|
705
|
$pconfig['weight'],
|
706
|
array_combine(range(1, 5), range(1, 5))
|
707
|
))->setHelp('Weight for this gateway when used in a Gateway Group.');
|
708
|
|
709
|
$group = new Form_Group('Latency thresholds');
|
710
|
$group->add(new Form_Input(
|
711
|
'latencylow',
|
712
|
'From',
|
713
|
'number',
|
714
|
$pconfig['latencylow'],
|
715
|
['placeholder' => $apinger_default['latencylow']]
|
716
|
));
|
717
|
$group->add(new Form_Input(
|
718
|
'latencyhigh',
|
719
|
'To',
|
720
|
'number',
|
721
|
$pconfig['latencyhigh'],
|
722
|
['placeholder' => $apinger_default['latencyhigh']]
|
723
|
));
|
724
|
$group->setHelp('Low and high thresholds for latency in milliseconds.
|
725
|
Default is %d/%d.', [$apinger_default['latencylow'], $apinger_default['latencyhigh']]);
|
726
|
|
727
|
$section->add($group);
|
728
|
|
729
|
$group = new Form_Group('Packet Loss thresholds');
|
730
|
$group->add(new Form_Input(
|
731
|
'losslow',
|
732
|
'From',
|
733
|
'number',
|
734
|
$pconfig['losslow'],
|
735
|
['placeholder' => $apinger_default['losslow']]
|
736
|
));
|
737
|
$group->add(new Form_Input(
|
738
|
'losshigh',
|
739
|
'To',
|
740
|
'number',
|
741
|
$pconfig['losshigh'],
|
742
|
['placeholder' => $apinger_default['losshigh']]
|
743
|
));
|
744
|
$group->setHelp('Low and high thresholds for packet loss in milliseconds.
|
745
|
Default is %d/%d.', [$apinger_default['losslow'], $apinger_default['losshigh']]);
|
746
|
$section->add($group);
|
747
|
|
748
|
$section->addInput(new Form_Input(
|
749
|
'interval',
|
750
|
'Probe Interval',
|
751
|
'number',
|
752
|
$pconfig['interval'],
|
753
|
[
|
754
|
'placeholder' => $apinger_default['interval'],
|
755
|
'max' => 86400
|
756
|
]
|
757
|
))->setHelp('How often an ICMP probe will be sent in seconds. Default is %d.'.
|
758
|
'NOTE: The quality graph is averaged over seconds, not intervals, so as '.
|
759
|
'the probe interval is increased the accuracy of the quality graph is '.
|
760
|
'decreased.', [$apinger_default['interval']]);
|
761
|
|
762
|
$section->addInput(new Form_Input(
|
763
|
'down',
|
764
|
'Down',
|
765
|
'number',
|
766
|
$pconfig['down'],
|
767
|
['placeholder' => $apinger_default['down']]
|
768
|
))->setHelp('The number of seconds of failed probes before the alarm '.
|
769
|
'will fire. Default is %d.', [$apinger_default['down']]);
|
770
|
|
771
|
$group = new Form_Group('Avg. Delay Replies Qty');
|
772
|
$group->add(new Form_Input(
|
773
|
'avg_delay_samples',
|
774
|
null,
|
775
|
'number',
|
776
|
$pconfig['avg_delay_samples'],
|
777
|
[
|
778
|
'placeholder' => $apinger_default['avg_delay_samples'],
|
779
|
'max' => 100
|
780
|
]
|
781
|
));
|
782
|
$group->add(new Form_Checkbox(
|
783
|
'avg_delay_samples_calculated',
|
784
|
null,
|
785
|
'Use calculated value.',
|
786
|
$pconfig['avg_delay_samples_calculated']
|
787
|
));
|
788
|
$group->setHelp('How many replies should be used to compute average delay for '.
|
789
|
'controlling "delay" alarms? Default is %d.',
|
790
|
[$apinger_default['avg_delay_samples']]);
|
791
|
$section->add($group);
|
792
|
|
793
|
$group = new Form_Group('Avg. Packet Loss Probes');
|
794
|
$group->add(new Form_Input(
|
795
|
'avg_loss_samples',
|
796
|
null,
|
797
|
'number',
|
798
|
$pconfig['avg_loss_samples'],
|
799
|
[
|
800
|
'placeholder' => $apinger_default['avg_loss_samples'],
|
801
|
'max' => 1000
|
802
|
]
|
803
|
));
|
804
|
$group->add(new Form_Checkbox(
|
805
|
'avg_loss_samples_calculated',
|
806
|
null,
|
807
|
'Use calculated value.',
|
808
|
$pconfig['avg_loss_samples_calculated']
|
809
|
));
|
810
|
$group->setHelp('How many probes should be useds to compute average packet loss? '.
|
811
|
'Default is %d.',
|
812
|
[$apinger_default['avg_loss_samples']]);
|
813
|
$section->add($group);
|
814
|
|
815
|
$group = new Form_Group('Lost Probe Delay');
|
816
|
$group->add(new Form_Input(
|
817
|
'avg_loss_delay_samples',
|
818
|
null,
|
819
|
'number',
|
820
|
$pconfig['avg_loss_delay_samples'],
|
821
|
[
|
822
|
'placeholder' => $apinger_default['avg_loss_delay_samples'],
|
823
|
'max' => 200
|
824
|
]
|
825
|
));
|
826
|
$group->add(new Form_Checkbox(
|
827
|
'avg_loss_delay_samples_calculated',
|
828
|
null,
|
829
|
'Use calculated value.',
|
830
|
$pconfig['avg_loss_samples_calculated']
|
831
|
));
|
832
|
$group->setHelp('The delay (in qty of probe samples) after which loss is '.
|
833
|
'computed. Without this, delays longer than the probe interval would be '.
|
834
|
'treated as packet loss. Default is %d.',
|
835
|
[$apinger_default['avg_loss_delay_samples']]);
|
836
|
$section->add($group);
|
837
|
|
838
|
$section->addInput(new Form_StaticText(
|
839
|
'Additional information',
|
840
|
'<span class="help-block">'.
|
841
|
gettext('The probe interval must be less than the down time, otherwise the '.
|
842
|
'gateway will seem to go down then come up again at the next probe.').
|
843
|
'<br/><br/>'.
|
844
|
gettext('The down time defines the length of time before the gateway is marked '.
|
845
|
'as down, but the accuracy is controlled by the probe interval. For example, '.
|
846
|
'if your down time is 40 seconds but on a 30 second probe interval, only one '.
|
847
|
'probe would have to fail before the gateway is marked down at the 40 second '.
|
848
|
'mark. By default, the gateway is considered down after 10 seconds, and the '.
|
849
|
'probe interval is 1 second, so 10 probes would have to fail before the gateway '.
|
850
|
'is marked down.').
|
851
|
'</span>'
|
852
|
));
|
853
|
|
854
|
$form->add($section);
|
855
|
|
856
|
print $form;
|
857
|
include("foot.inc");
|