1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
system_gateways.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
|
38
|
##|*NAME=System: Gateways page
|
39
|
##|*DESCR=Allow access to the 'System: Gateways' page.
|
40
|
##|*MATCH=system_gateways.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
require("guiconfig.inc");
|
44
|
require_once("functions.inc");
|
45
|
require_once("filter.inc");
|
46
|
require_once("shaper.inc");
|
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
|
|
59
|
$a_gateway_item = &$config['gateways']['gateway_item'];
|
60
|
|
61
|
if ($_POST) {
|
62
|
|
63
|
$pconfig = $_POST;
|
64
|
|
65
|
if ($_POST['apply']) {
|
66
|
|
67
|
$retval = 0;
|
68
|
|
69
|
$retval = system_routing_configure();
|
70
|
$retval |= filter_configure();
|
71
|
/* reconfigure our gateway monitor */
|
72
|
setup_gateways_monitor();
|
73
|
|
74
|
$savemsg = get_std_save_message($retval);
|
75
|
if ($retval == 0) {
|
76
|
clear_subsystem_dirty('staticroutes');
|
77
|
}
|
78
|
}
|
79
|
}
|
80
|
|
81
|
function can_delete_disable_gateway_item($id, $disable = false) {
|
82
|
global $config, $input_errors, $a_gateways;
|
83
|
|
84
|
if (!isset($a_gateways[$id])) {
|
85
|
return false;
|
86
|
}
|
87
|
|
88
|
if (is_array($config['gateways']['gateway_group'])) {
|
89
|
foreach ($config['gateways']['gateway_group'] as $group) {
|
90
|
foreach ($group['item'] as $item) {
|
91
|
$items = explode("|", $item);
|
92
|
if ($items[0] == $a_gateways[$id]['name']) {
|
93
|
if (!$disable) {
|
94
|
$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Gateway Group '%s'"), $a_gateways[$id]['name'], $group['name']);
|
95
|
} else {
|
96
|
$input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Gateway Group '%s'"), $a_gateways[$id]['name'], $group['name']);
|
97
|
}
|
98
|
}
|
99
|
}
|
100
|
}
|
101
|
}
|
102
|
|
103
|
if (is_array($config['staticroutes']['route'])) {
|
104
|
foreach ($config['staticroutes']['route'] as $route) {
|
105
|
if ($route['gateway'] == $a_gateways[$id]['name']) {
|
106
|
if (!$disable) {
|
107
|
// The user wants to delete this gateway, but there is a static route (enabled or disabled) that refers to the gateway.
|
108
|
$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Static Route '%s'"), $a_gateways[$id]['name'], $route['network']);
|
109
|
} else if (!isset($route['disabled'])) {
|
110
|
// The user wants to disable this gateway.
|
111
|
// But there is a static route that uses this gateway and is enabled (not disabled).
|
112
|
$input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Static Route '%s'"), $a_gateways[$id]['name'], $route['network']);
|
113
|
}
|
114
|
}
|
115
|
}
|
116
|
}
|
117
|
|
118
|
if (isset($input_errors)) {
|
119
|
return false;
|
120
|
}
|
121
|
|
122
|
return true;
|
123
|
}
|
124
|
|
125
|
function delete_gateway_item($id) {
|
126
|
global $config, $a_gateways;
|
127
|
|
128
|
if (!isset($a_gateways[$id])) {
|
129
|
return;
|
130
|
}
|
131
|
|
132
|
/* NOTE: Cleanup static routes for the monitor ip if any */
|
133
|
if (!empty($a_gateways[$id]['monitor']) &&
|
134
|
$a_gateways[$id]['monitor'] != "dynamic" &&
|
135
|
is_ipaddr($a_gateways[$id]['monitor']) &&
|
136
|
$a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
|
137
|
if (is_ipaddrv4($a_gateways[$id]['monitor'])) {
|
138
|
mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']));
|
139
|
} else {
|
140
|
mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']));
|
141
|
}
|
142
|
}
|
143
|
|
144
|
if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) {
|
145
|
unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
|
146
|
}
|
147
|
unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
|
148
|
}
|
149
|
|
150
|
unset($input_errors);
|
151
|
if ($_GET['act'] == "del") {
|
152
|
if (can_delete_disable_gateway_item($_GET['id'])) {
|
153
|
$realid = $a_gateways[$_GET['id']]['attribute'];
|
154
|
delete_gateway_item($_GET['id']);
|
155
|
write_config("Gateways: removed gateway {$realid}");
|
156
|
mark_subsystem_dirty('staticroutes');
|
157
|
header("Location: system_gateways.php");
|
158
|
exit;
|
159
|
}
|
160
|
}
|
161
|
|
162
|
if (isset($_POST['del_x'])) {
|
163
|
/* delete selected items */
|
164
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
165
|
foreach ($_POST['rule'] as $rulei) {
|
166
|
if (!can_delete_disable_gateway_item($rulei)) {
|
167
|
break;
|
168
|
}
|
169
|
}
|
170
|
|
171
|
if (!isset($input_errors)) {
|
172
|
$items_deleted = "";
|
173
|
foreach ($_POST['rule'] as $rulei) {
|
174
|
delete_gateway_item($rulei);
|
175
|
$items_deleted .= "{$rulei} ";
|
176
|
}
|
177
|
if (!empty($items_deleted)) {
|
178
|
write_config("Gateways: removed gateways {$items_deleted}");
|
179
|
mark_subsystem_dirty('staticroutes');
|
180
|
}
|
181
|
header("Location: system_gateways.php");
|
182
|
exit;
|
183
|
}
|
184
|
}
|
185
|
|
186
|
} else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) {
|
187
|
$realid = $a_gateways[$_GET['id']]['attribute'];
|
188
|
$disable_gw = !isset($a_gateway_item[$realid]['disabled']);
|
189
|
if ($disable_gw) {
|
190
|
// The user wants to disable the gateway, so check if that is OK.
|
191
|
$ok_to_toggle = can_delete_disable_gateway_item($_GET['id'], $disable_gw);
|
192
|
} else {
|
193
|
// The user wants to enable the gateway. That is always OK.
|
194
|
$ok_to_toggle = true;
|
195
|
}
|
196
|
if ($ok_to_toggle) {
|
197
|
if ($disable_gw) {
|
198
|
$a_gateway_item[$realid]['disabled'] = true;
|
199
|
} else {
|
200
|
unset($a_gateway_item[$realid]['disabled']);
|
201
|
}
|
202
|
|
203
|
if (write_config("Gateways: enable/disable")) {
|
204
|
mark_subsystem_dirty('staticroutes');
|
205
|
}
|
206
|
|
207
|
header("Location: system_gateways.php");
|
208
|
exit;
|
209
|
}
|
210
|
}
|
211
|
|
212
|
$pgtitle = array(gettext("System"), gettext("Gateways"));
|
213
|
$shortcut_section = "gateways";
|
214
|
|
215
|
include("head.inc");
|
216
|
|
217
|
if ($input_errors)
|
218
|
print_input_errors($input_errors);
|
219
|
if ($savemsg)
|
220
|
print_info_box($savemsg);
|
221
|
if (is_subsystem_dirty('staticroutes'))
|
222
|
print_info_box_np(gettext("The gateway configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
|
223
|
|
224
|
$tab_array = array();
|
225
|
$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
|
226
|
$tab_array[1] = array(gettext("Routes"), false, "system_routes.php");
|
227
|
$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
|
228
|
display_top_tabs($tab_array);
|
229
|
|
230
|
?>
|
231
|
<table class="table">
|
232
|
<thead>
|
233
|
<tr>
|
234
|
<th></th>
|
235
|
<th><?=gettext("Name")?></th>
|
236
|
<th><?=gettext("Interface")?></th>
|
237
|
<th><?=gettext("Gateway")?></th>
|
238
|
<th><?=gettext("Monitor IP")?></th>
|
239
|
<th><?=gettext("Description")?></th>
|
240
|
<th></th>
|
241
|
</tr>
|
242
|
</thead>
|
243
|
<tbody>
|
244
|
<?php
|
245
|
foreach ($a_gateways as $i => $gateway):
|
246
|
if (isset($gateway['inactive']))
|
247
|
$icon = 'icon-remove-circle';
|
248
|
elseif (isset($gateway['disabled']))
|
249
|
$icon = 'icon-ban-circle';
|
250
|
else
|
251
|
$icon = 'icon-ok-circle';
|
252
|
|
253
|
if (isset($gateway['inactive']))
|
254
|
$title = gettext("This gateway is inactive because interface is missing");
|
255
|
else
|
256
|
$title = '';
|
257
|
?>
|
258
|
<tr<?=($icon != 'icon-ok-circle')? ' class="disabled"' : ''?>>
|
259
|
<td title="<?=$title?>"><i class="icon <?=$icon?>"></i></td>
|
260
|
<td>
|
261
|
<?=$gateway['name']?>
|
262
|
<?php
|
263
|
if (isset($gateway['defaultgw']))
|
264
|
echo " <strong>(default)</strong>";
|
265
|
?>
|
266
|
</td>
|
267
|
<td>
|
268
|
<?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']))?>
|
269
|
</td>
|
270
|
<td>
|
271
|
<?=$gateway['gateway']?>
|
272
|
</td>
|
273
|
<td>
|
274
|
<?=htmlspecialchars($gateway['monitor'])?>
|
275
|
</td>
|
276
|
<td>
|
277
|
<?=htmlspecialchars($gateway['descr'])?>
|
278
|
</td>
|
279
|
<td>
|
280
|
<a class="btn btn-xs btn-primary" href="system_gateways_edit.php?id=<?=$i?>">
|
281
|
edit
|
282
|
</a>
|
283
|
<a class="btn btn-xs btn-default" href="system_gateways_edit.php?dup=<?=$i?>">
|
284
|
copy
|
285
|
</a>
|
286
|
<? if (is_numeric($gateway['attribute'])): ?>
|
287
|
<a class="btn btn-xs btn-danger" href="system_gateways.php?act=del&id=<?=$i?>">
|
288
|
delete
|
289
|
</a>
|
290
|
<a class="btn btn-xs btn-default" href="?act=toggle&id=<?=$i?>">
|
291
|
toggle
|
292
|
</a>
|
293
|
<? endif?>
|
294
|
</td>
|
295
|
</tr>
|
296
|
<? endforeach?>
|
297
|
</tbody>
|
298
|
</table>
|
299
|
|
300
|
<nav class="action-buttons">
|
301
|
<a href="system_gateways_edit.php" role="button" class="btn btn-success">
|
302
|
<?=gettext("edit default");?>
|
303
|
</a>
|
304
|
</nav>
|
305
|
<?php
|
306
|
|
307
|
include("foot.inc");
|