1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
system_gateway_groups_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-editgatewaygroups
|
37
|
##|*NAME=System: Gateways: Edit Gateway Groups page
|
38
|
##|*DESCR=Allow access to the 'System: Gateways: Edit Gateway Groups' page.
|
39
|
##|*MATCH=system_gateway_groups_edit.php*
|
40
|
##|-PRIV
|
41
|
|
42
|
require("guiconfig.inc");
|
43
|
require_once("ipsec.inc");
|
44
|
require_once("vpn.inc");
|
45
|
|
46
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_gateway_groups.php');
|
47
|
|
48
|
if (!is_array($config['gateways']['gateway_group']))
|
49
|
$config['gateways']['gateway_group'] = array();
|
50
|
|
51
|
$a_gateway_groups = &$config['gateways']['gateway_group'];
|
52
|
$a_gateways = return_gateways_array();
|
53
|
$carplist = get_configured_carp_interface_list();
|
54
|
|
55
|
$categories = array('down' => gettext("Member Down"),
|
56
|
'downloss' => gettext("Packet Loss"),
|
57
|
'downlatency' => gettext("High Latency"),
|
58
|
'downlosslatency' => gettext("Packet Loss or High Latency"));
|
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_gateway_groups[$id]) {
|
69
|
$pconfig['name'] = $a_gateway_groups[$id]['name'];
|
70
|
$pconfig['item'] = &$a_gateway_groups[$id]['item'];
|
71
|
$pconfig['descr'] = $a_gateway_groups[$id]['descr'];
|
72
|
$pconfig['trigger'] = $a_gateway_groups[$id]['trigger'];
|
73
|
}
|
74
|
|
75
|
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
|
76
|
unset($id);
|
77
|
|
78
|
if ($_POST) {
|
79
|
|
80
|
unset($input_errors);
|
81
|
$pconfig = $_POST;
|
82
|
|
83
|
/* input validation */
|
84
|
$reqdfields = explode(" ", "name");
|
85
|
$reqdfieldsn = explode(",", "Name");
|
86
|
|
87
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
88
|
|
89
|
if (! isset($_POST['name'])) {
|
90
|
$input_errors[] = gettext("A valid gateway group name must be specified.");
|
91
|
}
|
92
|
if (! is_validaliasname($_POST['name'])) {
|
93
|
$input_errors[] = gettext("The gateway name must not contain invalid characters.");
|
94
|
}
|
95
|
|
96
|
if (isset($_POST['name'])) {
|
97
|
/* check for overlaps */
|
98
|
if(is_array($a_gateway_groups)) {
|
99
|
foreach ($a_gateway_groups as $gateway_group) {
|
100
|
if (isset($id) && ($a_gateway_groups[$id]) && ($a_gateway_groups[$id] === $gateway_group)) {
|
101
|
if ($gateway_group['name'] != $_POST['name'])
|
102
|
$input_errors[] = gettext("Changing name on a gateway group is not allowed.");
|
103
|
continue;
|
104
|
}
|
105
|
|
106
|
if ($gateway_group['name'] == $_POST['name']) {
|
107
|
$input_errors[] = sprintf(gettext('A gateway group with this name "%s" already exists.'), $_POST['name']);
|
108
|
break;
|
109
|
}
|
110
|
}
|
111
|
}
|
112
|
}
|
113
|
|
114
|
/* Build list of items in group with priority */
|
115
|
$pconfig['item'] = array();
|
116
|
foreach($a_gateways as $gwname => $gateway) {
|
117
|
if($_POST[$gwname] > 0) {
|
118
|
$vipname = "{$gwname}_vip";
|
119
|
/* we have a priority above 0 (disabled), add item to list */
|
120
|
$pconfig['item'][] = "{$gwname}|{$_POST[$gwname]}|{$_POST[$vipname]}";
|
121
|
}
|
122
|
/* check for overlaps */
|
123
|
if ($_POST['name'] == $gwname)
|
124
|
$input_errors[] = sprintf(gettext('A gateway group cannot have the same name with a gateway "%s" please choose another name.'), $_POST['name']);
|
125
|
|
126
|
}
|
127
|
if(count($pconfig['item']) == 0)
|
128
|
$input_errors[] = gettext("No gateway(s) have been selected to be used in this group");
|
129
|
|
130
|
if (!$input_errors) {
|
131
|
$gateway_group = array();
|
132
|
$gateway_group['name'] = $_POST['name'];
|
133
|
$gateway_group['item'] = $pconfig['item'];
|
134
|
$gateway_group['trigger'] = $_POST['trigger'];
|
135
|
$gateway_group['descr'] = $_POST['descr'];
|
136
|
|
137
|
if (isset($id) && $a_gateway_groups[$id])
|
138
|
$a_gateway_groups[$id] = $gateway_group;
|
139
|
else
|
140
|
$a_gateway_groups[] = $gateway_group;
|
141
|
|
142
|
mark_subsystem_dirty('staticroutes');
|
143
|
mark_subsystem_dirty('gwgroup.' . $gateway_group['name']);
|
144
|
|
145
|
write_config();
|
146
|
|
147
|
header("Location: system_gateway_groups.php");
|
148
|
exit;
|
149
|
}
|
150
|
}
|
151
|
|
152
|
$pgtitle = array(gettext("System"),gettext("Gateways"),gettext("Edit gateway group"));
|
153
|
$shortcut_section = "gateway-groups";
|
154
|
|
155
|
function build_gateway_protocol_map (&$a_gateways) {
|
156
|
$result = array();
|
157
|
foreach ($a_gateways as $gwname => $gateway) {
|
158
|
$result[$gwname] = $gateway['ipprotocol'];
|
159
|
}
|
160
|
return $result;
|
161
|
}
|
162
|
|
163
|
include("head.inc");
|
164
|
|
165
|
?>
|
166
|
|
167
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
168
|
|
169
|
<?php
|
170
|
$gateway_protocol = build_gateway_protocol_map($a_gateways);
|
171
|
$gateway_array = array_keys($a_gateways);
|
172
|
$protocol_array = array_values($gateway_protocol);
|
173
|
$protocol_array = array_values(array_unique($gateway_protocol));
|
174
|
?>
|
175
|
<script type="text/javascript">
|
176
|
//<![CDATA[
|
177
|
jQuery(function ($) {
|
178
|
var gateway_protocol = <?= json_encode($gateway_protocol) ?>;
|
179
|
var gateways = <?= json_encode($gateway_array) ?>;
|
180
|
var protocols = <?= json_encode($protocol_array) ?>;
|
181
|
if (protocols.length <= 1) { return; }
|
182
|
|
183
|
var update_gateway_visibilities = function () {
|
184
|
var which_protocol_to_show = undefined;
|
185
|
$.each(gateways, function (i, gateway) {
|
186
|
var $select = $("#" + gateway);
|
187
|
var value = $select.val();
|
188
|
var protocol = gateway_protocol[gateway];
|
189
|
if (value !== '0' /* i.e., an option is selected */) {
|
190
|
if (which_protocol_to_show === undefined) {
|
191
|
which_protocol_to_show = protocol;
|
192
|
}
|
193
|
else if (which_protocol_to_show !== protocol) {
|
194
|
which_protocol_to_show = 'ALL OF THEM'; // this shouldn't happen
|
195
|
}
|
196
|
}
|
197
|
});
|
198
|
if (which_protocol_to_show !== undefined && which_protocol_to_show !== 'ALL OF THEM') {
|
199
|
$.each(gateways, function (i, gateway) {
|
200
|
var protocol = gateway_protocol[gateway];
|
201
|
var $row = $("tr.gateway_row#" + gateway + "_row");
|
202
|
if (protocol === which_protocol_to_show) {
|
203
|
if ($row.is(":hidden")) {
|
204
|
$row.fadeIn('slow');
|
205
|
}
|
206
|
} else {
|
207
|
if (!$row.is(":hidden")) {
|
208
|
$row.fadeOut('slow');
|
209
|
}
|
210
|
}
|
211
|
});
|
212
|
} else {
|
213
|
$("tr.gateway_row").each(function () {
|
214
|
if ($(this).is(":hidden")) {
|
215
|
$(this).fadeIn('slow');
|
216
|
}
|
217
|
});
|
218
|
}
|
219
|
};
|
220
|
$("select.gateway_tier_selector").change(update_gateway_visibilities);
|
221
|
update_gateway_visibilities();
|
222
|
});
|
223
|
//]]>
|
224
|
</script>
|
225
|
|
226
|
<?php include("fbegin.inc"); ?>
|
227
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
228
|
<form action="system_gateway_groups_edit.php" method="post" name="iform" id="iform">
|
229
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="system groups edit">
|
230
|
<tr>
|
231
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit gateway group entry"); ?></td>
|
232
|
</tr>
|
233
|
<tr>
|
234
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Group Name"); ?></td>
|
235
|
<td width="78%" class="vtable">
|
236
|
<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" />
|
237
|
<br /> <span class="vexpl"><?=gettext("Group Name"); ?></span></td>
|
238
|
</tr>
|
239
|
<tr>
|
240
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway Priority"); ?></td>
|
241
|
<td width="78%" class="vtable">
|
242
|
<table border="0" cellpadding="6" cellspacing="0" summary="gateway priority">
|
243
|
<tr>
|
244
|
<td class="listhdrr">Gateway</td>
|
245
|
<td class="listhdrr">Tier</td>
|
246
|
<td class="listhdrr">Virtual IP</td>
|
247
|
<td class="listhdrr">Description</td>
|
248
|
</tr>
|
249
|
<?php
|
250
|
foreach($a_gateways as $gwname => $gateway) {
|
251
|
if(!empty($pconfig['item'])) {
|
252
|
$af = explode("|", $pconfig['item'][0]);
|
253
|
$family = $a_gateways[$af[0]]['ipprotocol'];
|
254
|
if($gateway['ipprotocol'] != $family)
|
255
|
continue;
|
256
|
}
|
257
|
$interface = $gateway['friendlyiface'];
|
258
|
$selected = array();
|
259
|
foreach((array)$pconfig['item'] as $item) {
|
260
|
$itemsplit = explode("|", $item);
|
261
|
if($itemsplit[0] == $gwname) {
|
262
|
$selected[$itemsplit[1]] = "selected=\"selected\"";
|
263
|
break;
|
264
|
} else {
|
265
|
$selected[0] = "selected=\"selected\"";
|
266
|
}
|
267
|
}
|
268
|
$tr_id = $gwname . "_row";
|
269
|
echo "<tr class='gateway_row' id='{$tr_id}'>\n";
|
270
|
echo "<td class='listlr'>";
|
271
|
echo "<strong>{$gateway['name']} </strong>";
|
272
|
echo "</td><td class='listr'>";
|
273
|
echo "<select name='{$gwname}' class='gateway_tier_selector formfldselect' id='{$gwname}'>\n";
|
274
|
echo "<option value='0' $selected[0] >" . gettext("Never") . "</option>\n";
|
275
|
echo "<option value='1' $selected[1] >" . gettext("Tier 1") . "</option>\n";
|
276
|
echo "<option value='2' $selected[2] >" . gettext("Tier 2") . "</option>\n";
|
277
|
echo "<option value='3' $selected[3] >" . gettext("Tier 3") . "</option>\n";
|
278
|
echo "<option value='4' $selected[4] >" . gettext("Tier 4") . "</option>\n";
|
279
|
echo "<option value='5' $selected[5] >" . gettext("Tier 5") . "</option>\n";
|
280
|
echo "</select>\n";
|
281
|
echo "</td>";
|
282
|
|
283
|
$selected = array();
|
284
|
foreach((array)$pconfig['item'] as $item) {
|
285
|
$itemsplit = explode("|", $item);
|
286
|
if($itemsplit[0] == $gwname) {
|
287
|
$selected[$itemsplit[2]] = "selected=\"selected\"";
|
288
|
break;
|
289
|
} else {
|
290
|
$selected['address'] = "selected=\"selected\"";
|
291
|
}
|
292
|
}
|
293
|
echo "<td class='listr'>";
|
294
|
echo "<select name='{$gwname}_vip' class='gateway_vip_selector formfldselect' id='{$gwname}_vip'>\n";
|
295
|
echo "<option value='address' {$selected['address']} >" . gettext("Interface Address") . "</option>\n";
|
296
|
foreach($carplist as $vip => $address) {
|
297
|
echo "<!-- $vip - $address - $interface -->\n";
|
298
|
if(!preg_match("/^{$interface}_/i", $vip))
|
299
|
continue;
|
300
|
if(($gateway['ipprotocol'] == "inet") && (!is_ipaddrv4($address)))
|
301
|
continue;
|
302
|
if(($gateway['ipprotocol'] == "inet6") && (!is_ipaddrv6($address)))
|
303
|
continue;
|
304
|
echo "<option value='{$vip}' $selected[$vip] >$vip - $address</option>\n";
|
305
|
}
|
306
|
echo "</select></td>";
|
307
|
echo "<td class='listr'><strong>{$gateway['descr']} </strong>";
|
308
|
echo "</td></tr>";
|
309
|
}
|
310
|
?>
|
311
|
</table>
|
312
|
<br /><span class="vexpl">
|
313
|
<strong><?=gettext("Link Priority"); ?></strong> <br />
|
314
|
<?=gettext("The priority selected here defines in what order failover and balancing of links will be done. " .
|
315
|
"Multiple links of the same priority will balance connections until all links in the priority will be exhausted. " .
|
316
|
"If all links in a priority level are exhausted we will use the next available link(s) in the next priority level.") ?>
|
317
|
<br />
|
318
|
<strong><?=gettext("Virtual IP"); ?></strong> <br />
|
319
|
<?=gettext("The virtual IP field selects what (virtual) IP should be used when this group applies to a local Dynamic DNS, IPsec or OpenVPN endpoint") ?>
|
320
|
</span><br />
|
321
|
</td>
|
322
|
</tr>
|
323
|
<tr>
|
324
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Trigger Level"); ?></td>
|
325
|
<td width="78%" class="vtable">
|
326
|
<select name='trigger' class='formfldselect trigger_level_selector' id='trigger'>
|
327
|
<?php
|
328
|
foreach ($categories as $category => $categoryd) {
|
329
|
echo "<option value=\"$category\"";
|
330
|
if ($category == $pconfig['trigger']) echo " selected=\"selected\"";
|
331
|
echo ">" . htmlspecialchars($categoryd) . "</option>\n";
|
332
|
}
|
333
|
?>
|
334
|
</select>
|
335
|
<br /> <span class="vexpl"><?=gettext("When to trigger exclusion of a member"); ?></span></td>
|
336
|
</tr>
|
337
|
<tr>
|
338
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
|
339
|
<td width="78%" class="vtable">
|
340
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
|
341
|
<br /> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)."); ?></span></td>
|
342
|
</tr>
|
343
|
<tr>
|
344
|
<td width="22%" valign="top"> </td>
|
345
|
<td width="78%">
|
346
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
|
347
|
<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
|
348
|
<?php if (isset($id) && $a_gateway_groups[$id]): ?>
|
349
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
350
|
<?php endif; ?>
|
351
|
</td>
|
352
|
</tr>
|
353
|
</table>
|
354
|
</form>
|
355
|
<?php include("fend.inc"); ?>
|
356
|
</body>
|
357
|
</html>
|