1
|
<?php
|
2
|
/*
|
3
|
* system_gateways.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
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
|
18
|
* the documentation and/or other materials provided with the
|
19
|
* distribution.
|
20
|
*
|
21
|
* 3. All advertising materials mentioning features or use of this software
|
22
|
* must display the following acknowledgment:
|
23
|
* "This product includes software developed by the pfSense Project
|
24
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
25
|
*
|
26
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
27
|
* endorse or promote products derived from this software without
|
28
|
* prior written permission. For written permission, please contact
|
29
|
* coreteam@pfsense.org.
|
30
|
*
|
31
|
* 5. Products derived from this software may not be called "pfSense"
|
32
|
* nor may "pfSense" appear in their names without prior written
|
33
|
* permission of the Electric Sheep Fencing, LLC.
|
34
|
*
|
35
|
* 6. Redistributions of any form whatsoever must retain the following
|
36
|
* acknowledgment:
|
37
|
*
|
38
|
* "This product includes software developed by the pfSense Project
|
39
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
40
|
*
|
41
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
42
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
43
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
44
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
45
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
46
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
47
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
48
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
49
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
50
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
51
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
52
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
53
|
*/
|
54
|
|
55
|
##|+PRIV
|
56
|
##|*IDENT=page-system-gateways
|
57
|
##|*NAME=System: Gateways
|
58
|
##|*DESCR=Allow access to the 'System: Gateways' page.
|
59
|
##|*MATCH=system_gateways.php*
|
60
|
##|-PRIV
|
61
|
|
62
|
require_once("guiconfig.inc");
|
63
|
require_once("functions.inc");
|
64
|
require_once("filter.inc");
|
65
|
require_once("shaper.inc");
|
66
|
|
67
|
$a_gateways = return_gateways_array(true, false, true);
|
68
|
$a_gateways_arr = array();
|
69
|
foreach ($a_gateways as $gw) {
|
70
|
$a_gateways_arr[] = $gw;
|
71
|
}
|
72
|
$a_gateways = $a_gateways_arr;
|
73
|
|
74
|
if (!is_array($config['gateways']['gateway_item'])) {
|
75
|
$config['gateways']['gateway_item'] = array();
|
76
|
}
|
77
|
|
78
|
$a_gateway_item = &$config['gateways']['gateway_item'];
|
79
|
|
80
|
if ($_POST) {
|
81
|
|
82
|
$pconfig = $_POST;
|
83
|
|
84
|
if ($_POST['apply']) {
|
85
|
|
86
|
$retval = 0;
|
87
|
|
88
|
$retval = system_routing_configure();
|
89
|
$retval |= system_resolvconf_generate();
|
90
|
$retval |= filter_configure();
|
91
|
/* reconfigure our gateway monitor */
|
92
|
setup_gateways_monitor();
|
93
|
/* Dynamic DNS on gw groups may have changed */
|
94
|
send_event("service reload dyndnsall");
|
95
|
|
96
|
$savemsg = get_std_save_message($retval);
|
97
|
if ($retval == 0) {
|
98
|
clear_subsystem_dirty('staticroutes');
|
99
|
}
|
100
|
}
|
101
|
}
|
102
|
|
103
|
function can_delete_disable_gateway_item($id, $disable = false) {
|
104
|
global $config, $input_errors, $a_gateways;
|
105
|
|
106
|
if (!isset($a_gateways[$id])) {
|
107
|
return false;
|
108
|
}
|
109
|
|
110
|
if (is_array($config['gateways']['gateway_group'])) {
|
111
|
foreach ($config['gateways']['gateway_group'] as $group) {
|
112
|
foreach ($group['item'] as $item) {
|
113
|
$items = explode("|", $item);
|
114
|
if ($items[0] == $a_gateways[$id]['name']) {
|
115
|
if (!$disable) {
|
116
|
$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be deleted because it is in use on Gateway Group "%2$s"'), $a_gateways[$id]['name'], $group['name']);
|
117
|
} else {
|
118
|
$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be disabled because it is in use on Gateway Group "%2$s"'), $a_gateways[$id]['name'], $group['name']);
|
119
|
}
|
120
|
}
|
121
|
}
|
122
|
}
|
123
|
}
|
124
|
|
125
|
if (is_array($config['staticroutes']['route'])) {
|
126
|
foreach ($config['staticroutes']['route'] as $route) {
|
127
|
if ($route['gateway'] == $a_gateways[$id]['name']) {
|
128
|
if (!$disable) {
|
129
|
// The user wants to delete this gateway, but there is a static route (enabled or disabled) that refers to the gateway.
|
130
|
$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be deleted because it is in use on Static Route "%2$s"'), $a_gateways[$id]['name'], $route['network']);
|
131
|
} else if (!isset($route['disabled'])) {
|
132
|
// The user wants to disable this gateway.
|
133
|
// But there is a static route that uses this gateway and is enabled (not disabled).
|
134
|
$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be disabled because it is in use on Static Route "%2$s"'), $a_gateways[$id]['name'], $route['network']);
|
135
|
}
|
136
|
}
|
137
|
}
|
138
|
}
|
139
|
|
140
|
if (isset($input_errors)) {
|
141
|
return false;
|
142
|
}
|
143
|
|
144
|
return true;
|
145
|
}
|
146
|
|
147
|
function delete_gateway_item($id) {
|
148
|
global $config, $a_gateways;
|
149
|
|
150
|
if (!isset($a_gateways[$id])) {
|
151
|
return;
|
152
|
}
|
153
|
|
154
|
/* If the removed gateway was the default route, remove the default route */
|
155
|
if (!empty($a_gateways[$id]) && is_ipaddr($a_gateways[$id]['gateway']) &&
|
156
|
!isset($a_gateways[$id]['disabled']) &&
|
157
|
isset($a_gateways[$id]['defaultgw'])) {
|
158
|
$inet = (!is_ipaddrv4($a_gateways[$id]['gateway']) ? '-inet6' : '-inet');
|
159
|
mwexec("/sbin/route delete {$inet} default");
|
160
|
}
|
161
|
|
162
|
/* NOTE: Cleanup static routes for the interface route if any */
|
163
|
if (!empty($a_gateways[$id]) && is_ipaddr($a_gateways[$id]['gateway']) &&
|
164
|
$gateway['gateway'] != $a_gateways[$id]['gateway'] &&
|
165
|
isset($a_gateways[$id]["nonlocalgateway"])) {
|
166
|
$realif = get_real_interface($a_gateways[$id]['interface']);
|
167
|
$inet = (!is_ipaddrv4($a_gateways[$id]['gateway']) ? "-inet6" : "-inet");
|
168
|
$cmd = "/sbin/route delete $inet " . escapeshellarg($a_gateways[$id]['gateway']) . " -iface " . escapeshellarg($realif);
|
169
|
mwexec($cmd);
|
170
|
}
|
171
|
/* NOTE: Cleanup static routes for the monitor ip if any */
|
172
|
if (!empty($a_gateways[$id]['monitor']) &&
|
173
|
$a_gateways[$id]['monitor'] != "dynamic" &&
|
174
|
is_ipaddr($a_gateways[$id]['monitor']) &&
|
175
|
$a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
|
176
|
if (is_ipaddrv4($a_gateways[$id]['monitor'])) {
|
177
|
mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']));
|
178
|
} else {
|
179
|
mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']));
|
180
|
}
|
181
|
}
|
182
|
|
183
|
if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) {
|
184
|
unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
|
185
|
}
|
186
|
unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
|
187
|
}
|
188
|
|
189
|
unset($input_errors);
|
190
|
if ($_GET['act'] == "del") {
|
191
|
if (can_delete_disable_gateway_item($_GET['id'])) {
|
192
|
$realid = $a_gateways[$_GET['id']]['attribute'];
|
193
|
delete_gateway_item($_GET['id']);
|
194
|
write_config("Gateways: removed gateway {$realid}");
|
195
|
mark_subsystem_dirty('staticroutes');
|
196
|
header("Location: system_gateways.php");
|
197
|
exit;
|
198
|
}
|
199
|
}
|
200
|
|
201
|
if (isset($_POST['del_x'])) {
|
202
|
/* delete selected items */
|
203
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
204
|
foreach ($_POST['rule'] as $rulei) {
|
205
|
if (!can_delete_disable_gateway_item($rulei)) {
|
206
|
break;
|
207
|
}
|
208
|
}
|
209
|
|
210
|
if (!isset($input_errors)) {
|
211
|
$items_deleted = "";
|
212
|
foreach ($_POST['rule'] as $rulei) {
|
213
|
delete_gateway_item($rulei);
|
214
|
$items_deleted .= "{$rulei} ";
|
215
|
}
|
216
|
if (!empty($items_deleted)) {
|
217
|
write_config(sprintf(gettext("Gateways: removed gateways %s", $items_deleted)));
|
218
|
mark_subsystem_dirty('staticroutes');
|
219
|
}
|
220
|
header("Location: system_gateways.php");
|
221
|
exit;
|
222
|
}
|
223
|
}
|
224
|
|
225
|
} else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) {
|
226
|
$realid = $a_gateways[$_GET['id']]['attribute'];
|
227
|
$disable_gw = !isset($a_gateway_item[$realid]['disabled']);
|
228
|
if ($disable_gw) {
|
229
|
// The user wants to disable the gateway, so check if that is OK.
|
230
|
$ok_to_toggle = can_delete_disable_gateway_item($_GET['id'], $disable_gw);
|
231
|
} else {
|
232
|
// The user wants to enable the gateway. That is always OK.
|
233
|
$ok_to_toggle = true;
|
234
|
}
|
235
|
if ($ok_to_toggle) {
|
236
|
if ($disable_gw) {
|
237
|
$a_gateway_item[$realid]['disabled'] = true;
|
238
|
/* If the disabled gateway was the default route, remove the default route */
|
239
|
if (!empty($a_gateway_item[$realid]) && is_ipaddr($a_gateway_item[$realid]['gateway']) &&
|
240
|
isset($a_gateway_item[$realid]['defaultgw'])) {
|
241
|
$inet = (!is_ipaddrv4($a_gateway_item[$realid]['gateway']) ? '-inet6' : '-inet');
|
242
|
mwexec("/sbin/route delete {$inet} default");
|
243
|
}
|
244
|
} else {
|
245
|
unset($a_gateway_item[$realid]['disabled']);
|
246
|
}
|
247
|
|
248
|
if (write_config("Gateways: enable/disable")) {
|
249
|
mark_subsystem_dirty('staticroutes');
|
250
|
}
|
251
|
|
252
|
header("Location: system_gateways.php");
|
253
|
exit;
|
254
|
}
|
255
|
}
|
256
|
|
257
|
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Gateways"));
|
258
|
$shortcut_section = "gateways";
|
259
|
|
260
|
include("head.inc");
|
261
|
|
262
|
if ($input_errors) {
|
263
|
print_input_errors($input_errors);
|
264
|
}
|
265
|
if ($savemsg) {
|
266
|
print_info_box($savemsg, 'success');
|
267
|
}
|
268
|
|
269
|
if (is_subsystem_dirty('staticroutes')) {
|
270
|
print_apply_box(gettext("The gateway configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
|
271
|
}
|
272
|
|
273
|
$tab_array = array();
|
274
|
$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
|
275
|
$tab_array[1] = array(gettext("Static Routes"), false, "system_routes.php");
|
276
|
$tab_array[2] = array(gettext("Gateway Groups"), false, "system_gateway_groups.php");
|
277
|
display_top_tabs($tab_array);
|
278
|
|
279
|
?>
|
280
|
<div class="panel panel-default">
|
281
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Gateways')?></h2></div>
|
282
|
<div class="panel-body">
|
283
|
<div class="table-responsive">
|
284
|
<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
|
285
|
<thead>
|
286
|
<tr>
|
287
|
<th></th>
|
288
|
<th><?=gettext("Name")?></th>
|
289
|
<th><?=gettext("Interface")?></th>
|
290
|
<th><?=gettext("Gateway")?></th>
|
291
|
<th><?=gettext("Monitor IP")?></th>
|
292
|
<th><?=gettext("Description")?></th>
|
293
|
<th><?=gettext("Actions")?></th>
|
294
|
</tr>
|
295
|
</thead>
|
296
|
<tbody>
|
297
|
<?php
|
298
|
foreach ($a_gateways as $i => $gateway):
|
299
|
if (isset($gateway['inactive'])) {
|
300
|
$icon = 'fa-times-circle-o';
|
301
|
} elseif (isset($gateway['disabled'])) {
|
302
|
$icon = 'fa-ban';
|
303
|
} else {
|
304
|
$icon = 'fa-check-circle-o';
|
305
|
}
|
306
|
|
307
|
if (isset($gateway['inactive'])) {
|
308
|
$title = gettext("This gateway is inactive because interface is missing");
|
309
|
} else {
|
310
|
$title = '';
|
311
|
}
|
312
|
?>
|
313
|
<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
|
314
|
<td title="<?=$title?>"><i class="fa <?=$icon?>"></i></td>
|
315
|
<td>
|
316
|
<?=htmlspecialchars($gateway['name'])?>
|
317
|
<?php
|
318
|
if (isset($gateway['defaultgw'])) {
|
319
|
echo " <strong>(default)</strong>";
|
320
|
}
|
321
|
?>
|
322
|
</td>
|
323
|
<td>
|
324
|
<?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']))?>
|
325
|
</td>
|
326
|
<td>
|
327
|
<?=htmlspecialchars($gateway['gateway'])?>
|
328
|
</td>
|
329
|
<td>
|
330
|
<?=htmlspecialchars($gateway['monitor'])?>
|
331
|
</td>
|
332
|
<td>
|
333
|
<?=htmlspecialchars($gateway['descr'])?>
|
334
|
</td>
|
335
|
<td>
|
336
|
<a href="system_gateways_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit gateway');?>"></a>
|
337
|
<a href="system_gateways_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy gateway')?>"></a>
|
338
|
|
339
|
<?php if (is_numeric($gateway['attribute'])): ?>
|
340
|
<?php if (isset($gateway['disabled'])) {
|
341
|
?>
|
342
|
<a href="?act=toggle&id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable gateway')?>"></a>
|
343
|
<?php } else {
|
344
|
?>
|
345
|
<a href="?act=toggle&id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable gateway')?>"></a>
|
346
|
<?php }
|
347
|
?>
|
348
|
<a href="system_gateways.php?act=del&id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete gateway')?>"></a>
|
349
|
|
350
|
<?php endif; ?>
|
351
|
</td>
|
352
|
</tr>
|
353
|
<?php endforeach; ?>
|
354
|
</tbody>
|
355
|
</table>
|
356
|
</div>
|
357
|
</div>
|
358
|
</div>
|
359
|
|
360
|
<nav class="action-buttons">
|
361
|
<a href="system_gateways_edit.php" role="button" class="btn btn-success">
|
362
|
<i class="fa fa-plus icon-embed-btn"></i>
|
363
|
<?=gettext("Add");?>
|
364
|
</a>
|
365
|
</nav>
|
366
|
<?php
|
367
|
|
368
|
include("foot.inc");
|