1 |
d173230c
|
Seth Mos
|
<?php
|
2 |
|
|
/*
|
3 |
c5d81585
|
Renato Botelho
|
* system_gateways.php
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
|
|
* Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
|
7 |
|
|
* Copyright (c) 2010 Seth Mos <seth.mos@dds.nl>
|
8 |
|
|
* All rights reserved.
|
9 |
|
|
*
|
10 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
11 |
|
|
* you may not use this file except in compliance with the License.
|
12 |
|
|
* You may obtain a copy of the License at
|
13 |
c5d81585
|
Renato Botelho
|
*
|
14 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15 |
c5d81585
|
Renato Botelho
|
*
|
16 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
17 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
18 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19 |
|
|
* See the License for the specific language governing permissions and
|
20 |
|
|
* limitations under the License.
|
21 |
6ff05704
|
Stephen Beaver
|
*/
|
22 |
d173230c
|
Seth Mos
|
|
23 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
24 |
|
|
##|*IDENT=page-system-gateways
|
25 |
5230f468
|
jim-p
|
##|*NAME=System: Gateways
|
26 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'System: Gateways' page.
|
27 |
|
|
##|*MATCH=system_gateways.php*
|
28 |
|
|
##|-PRIV
|
29 |
|
|
|
30 |
c81ef6e2
|
Phil Davis
|
require_once("guiconfig.inc");
|
31 |
7a927e67
|
Scott Ullrich
|
require_once("functions.inc");
|
32 |
|
|
require_once("filter.inc");
|
33 |
|
|
require_once("shaper.inc");
|
34 |
d173230c
|
Seth Mos
|
|
35 |
e97df865
|
Renato Botelho
|
$a_gateways = return_gateways_array(true, false, true);
|
36 |
b92305a6
|
--global
|
$a_gateways_arr = array();
|
37 |
e0c7b2fe
|
Phil Davis
|
foreach ($a_gateways as $gw) {
|
38 |
3df6d458
|
Seth Mos
|
$a_gateways_arr[] = $gw;
|
39 |
e0c7b2fe
|
Phil Davis
|
}
|
40 |
b92305a6
|
--global
|
$a_gateways = $a_gateways_arr;
|
41 |
616e1956
|
Seth Mos
|
|
42 |
e0c7b2fe
|
Phil Davis
|
if (!is_array($config['gateways']['gateway_item'])) {
|
43 |
d251a8d4
|
Renato Botelho
|
$config['gateways']['gateway_item'] = array();
|
44 |
e0c7b2fe
|
Phil Davis
|
}
|
45 |
616e1956
|
Seth Mos
|
|
46 |
|
|
$a_gateway_item = &$config['gateways']['gateway_item'];
|
47 |
|
|
|
48 |
d173230c
|
Seth Mos
|
if ($_POST) {
|
49 |
|
|
|
50 |
|
|
$pconfig = $_POST;
|
51 |
|
|
|
52 |
|
|
if ($_POST['apply']) {
|
53 |
|
|
|
54 |
|
|
$retval = 0;
|
55 |
|
|
|
56 |
|
|
$retval = system_routing_configure();
|
57 |
138e4140
|
Renato Botelho
|
$retval |= system_resolvconf_generate();
|
58 |
d173230c
|
Seth Mos
|
$retval |= filter_configure();
|
59 |
13bbe450
|
Seth Mos
|
/* reconfigure our gateway monitor */
|
60 |
|
|
setup_gateways_monitor();
|
61 |
acda1403
|
Chris Buechler
|
/* Dynamic DNS on gw groups may have changed */
|
62 |
|
|
send_event("service reload dyndnsall");
|
63 |
d173230c
|
Seth Mos
|
|
64 |
|
|
$savemsg = get_std_save_message($retval);
|
65 |
e0c7b2fe
|
Phil Davis
|
if ($retval == 0) {
|
66 |
a368a026
|
Ermal Lu?i
|
clear_subsystem_dirty('staticroutes');
|
67 |
e0c7b2fe
|
Phil Davis
|
}
|
68 |
d173230c
|
Seth Mos
|
}
|
69 |
|
|
}
|
70 |
|
|
|
71 |
028ff8f8
|
Phil Davis
|
function can_delete_disable_gateway_item($id, $disable = false) {
|
72 |
e97df865
|
Renato Botelho
|
global $config, $input_errors, $a_gateways;
|
73 |
d251a8d4
|
Renato Botelho
|
|
74 |
e0c7b2fe
|
Phil Davis
|
if (!isset($a_gateways[$id])) {
|
75 |
e97df865
|
Renato Botelho
|
return false;
|
76 |
e0c7b2fe
|
Phil Davis
|
}
|
77 |
e97df865
|
Renato Botelho
|
|
78 |
|
|
if (is_array($config['gateways']['gateway_group'])) {
|
79 |
|
|
foreach ($config['gateways']['gateway_group'] as $group) {
|
80 |
|
|
foreach ($group['item'] as $item) {
|
81 |
|
|
$items = explode("|", $item);
|
82 |
|
|
if ($items[0] == $a_gateways[$id]['name']) {
|
83 |
205178aa
|
Phil Davis
|
if (!$disable) {
|
84 |
762faef5
|
Phil Davis
|
$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']);
|
85 |
205178aa
|
Phil Davis
|
} else {
|
86 |
762faef5
|
Phil Davis
|
$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']);
|
87 |
028ff8f8
|
Phil Davis
|
}
|
88 |
f78302e8
|
Ermal
|
}
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
e97df865
|
Renato Botelho
|
}
|
92 |
|
|
|
93 |
|
|
if (is_array($config['staticroutes']['route'])) {
|
94 |
|
|
foreach ($config['staticroutes']['route'] as $route) {
|
95 |
|
|
if ($route['gateway'] == $a_gateways[$id]['name']) {
|
96 |
205178aa
|
Phil Davis
|
if (!$disable) {
|
97 |
028ff8f8
|
Phil Davis
|
// The user wants to delete this gateway, but there is a static route (enabled or disabled) that refers to the gateway.
|
98 |
762faef5
|
Phil Davis
|
$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']);
|
99 |
205178aa
|
Phil Davis
|
} else if (!isset($route['disabled'])) {
|
100 |
|
|
// The user wants to disable this gateway.
|
101 |
|
|
// But there is a static route that uses this gateway and is enabled (not disabled).
|
102 |
762faef5
|
Phil Davis
|
$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']);
|
103 |
028ff8f8
|
Phil Davis
|
}
|
104 |
f78302e8
|
Ermal
|
}
|
105 |
|
|
}
|
106 |
e97df865
|
Renato Botelho
|
}
|
107 |
|
|
|
108 |
e0c7b2fe
|
Phil Davis
|
if (isset($input_errors)) {
|
109 |
e97df865
|
Renato Botelho
|
return false;
|
110 |
e0c7b2fe
|
Phil Davis
|
}
|
111 |
e97df865
|
Renato Botelho
|
|
112 |
|
|
return true;
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
function delete_gateway_item($id) {
|
116 |
dde20226
|
Renato Botelho
|
global $config, $a_gateways;
|
117 |
|
|
|
118 |
e0c7b2fe
|
Phil Davis
|
if (!isset($a_gateways[$id])) {
|
119 |
e97df865
|
Renato Botelho
|
return;
|
120 |
e0c7b2fe
|
Phil Davis
|
}
|
121 |
32a9eb18
|
Ermal
|
|
122 |
e75f0e7d
|
PiBa-NL
|
/* NOTE: Cleanup static routes for the interface route if any */
|
123 |
d61309a0
|
Phil Davis
|
if (!empty($a_gateways[$id]) && is_ipaddr($a_gateways[$id]['gateway']) &&
|
124 |
|
|
$gateway['gateway'] != $a_gateways[$id]['gateway'] &&
|
125 |
|
|
isset($a_gateways[$id]["nonlocalgateway"])) {
|
126 |
e75f0e7d
|
PiBa-NL
|
$realif = get_real_interface($a_gateways[$id]['interface']);
|
127 |
|
|
$inet = (!is_ipaddrv4($a_gateways[$id]['gateway']) ? "-inet6" : "-inet");
|
128 |
|
|
$cmd = "/sbin/route delete $inet " . escapeshellarg($a_gateways[$id]['gateway']) . " -iface " . escapeshellarg($realif);
|
129 |
|
|
mwexec($cmd);
|
130 |
|
|
}
|
131 |
e97df865
|
Renato Botelho
|
/* NOTE: Cleanup static routes for the monitor ip if any */
|
132 |
|
|
if (!empty($a_gateways[$id]['monitor']) &&
|
133 |
d61309a0
|
Phil Davis
|
$a_gateways[$id]['monitor'] != "dynamic" &&
|
134 |
|
|
is_ipaddr($a_gateways[$id]['monitor']) &&
|
135 |
|
|
$a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
|
136 |
e0c7b2fe
|
Phil Davis
|
if (is_ipaddrv4($a_gateways[$id]['monitor'])) {
|
137 |
e97df865
|
Renato Botelho
|
mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']));
|
138 |
e0c7b2fe
|
Phil Davis
|
} else {
|
139 |
e97df865
|
Renato Botelho
|
mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']));
|
140 |
e0c7b2fe
|
Phil Davis
|
}
|
141 |
e97df865
|
Renato Botelho
|
}
|
142 |
|
|
|
143 |
e0c7b2fe
|
Phil Davis
|
if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) {
|
144 |
e97df865
|
Renato Botelho
|
unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
|
145 |
e0c7b2fe
|
Phil Davis
|
}
|
146 |
e97df865
|
Renato Botelho
|
unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
unset($input_errors);
|
150 |
|
|
if ($_GET['act'] == "del") {
|
151 |
028ff8f8
|
Phil Davis
|
if (can_delete_disable_gateway_item($_GET['id'])) {
|
152 |
e97df865
|
Renato Botelho
|
$realid = $a_gateways[$_GET['id']]['attribute'];
|
153 |
|
|
delete_gateway_item($_GET['id']);
|
154 |
|
|
write_config("Gateways: removed gateway {$realid}");
|
155 |
|
|
mark_subsystem_dirty('staticroutes');
|
156 |
|
|
header("Location: system_gateways.php");
|
157 |
|
|
exit;
|
158 |
|
|
}
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
if (isset($_POST['del_x'])) {
|
162 |
|
|
/* delete selected items */
|
163 |
|
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
164 |
e0c7b2fe
|
Phil Davis
|
foreach ($_POST['rule'] as $rulei) {
|
165 |
028ff8f8
|
Phil Davis
|
if (!can_delete_disable_gateway_item($rulei)) {
|
166 |
e97df865
|
Renato Botelho
|
break;
|
167 |
e0c7b2fe
|
Phil Davis
|
}
|
168 |
|
|
}
|
169 |
e97df865
|
Renato Botelho
|
|
170 |
|
|
if (!isset($input_errors)) {
|
171 |
|
|
$items_deleted = "";
|
172 |
|
|
foreach ($_POST['rule'] as $rulei) {
|
173 |
|
|
delete_gateway_item($rulei);
|
174 |
|
|
$items_deleted .= "{$rulei} ";
|
175 |
|
|
}
|
176 |
|
|
if (!empty($items_deleted)) {
|
177 |
762faef5
|
Phil Davis
|
write_config(sprintf(gettext("Gateways: removed gateways %s", $items_deleted)));
|
178 |
e97df865
|
Renato Botelho
|
mark_subsystem_dirty('staticroutes');
|
179 |
|
|
}
|
180 |
f78302e8
|
Ermal
|
header("Location: system_gateways.php");
|
181 |
|
|
exit;
|
182 |
|
|
}
|
183 |
d173230c
|
Seth Mos
|
}
|
184 |
|
|
|
185 |
e97df865
|
Renato Botelho
|
} else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) {
|
186 |
|
|
$realid = $a_gateways[$_GET['id']]['attribute'];
|
187 |
028ff8f8
|
Phil Davis
|
$disable_gw = !isset($a_gateway_item[$realid]['disabled']);
|
188 |
|
|
if ($disable_gw) {
|
189 |
|
|
// The user wants to disable the gateway, so check if that is OK.
|
190 |
|
|
$ok_to_toggle = can_delete_disable_gateway_item($_GET['id'], $disable_gw);
|
191 |
e0c7b2fe
|
Phil Davis
|
} else {
|
192 |
028ff8f8
|
Phil Davis
|
// The user wants to enable the gateway. That is always OK.
|
193 |
|
|
$ok_to_toggle = true;
|
194 |
e0c7b2fe
|
Phil Davis
|
}
|
195 |
028ff8f8
|
Phil Davis
|
if ($ok_to_toggle) {
|
196 |
|
|
if ($disable_gw) {
|
197 |
|
|
$a_gateway_item[$realid]['disabled'] = true;
|
198 |
|
|
} else {
|
199 |
|
|
unset($a_gateway_item[$realid]['disabled']);
|
200 |
|
|
}
|
201 |
e97df865
|
Renato Botelho
|
|
202 |
028ff8f8
|
Phil Davis
|
if (write_config("Gateways: enable/disable")) {
|
203 |
|
|
mark_subsystem_dirty('staticroutes');
|
204 |
|
|
}
|
205 |
e97df865
|
Renato Botelho
|
|
206 |
028ff8f8
|
Phil Davis
|
header("Location: system_gateways.php");
|
207 |
|
|
exit;
|
208 |
|
|
}
|
209 |
e97df865
|
Renato Botelho
|
}
|
210 |
124aee67
|
Chris Buechler
|
|
211 |
d036bc07
|
Stephen Beaver
|
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Gateways"));
|
212 |
b32dd0a6
|
jim-p
|
$shortcut_section = "gateways";
|
213 |
02ca24c9
|
jim-p
|
|
214 |
d173230c
|
Seth Mos
|
include("head.inc");
|
215 |
|
|
|
216 |
d61309a0
|
Phil Davis
|
if ($input_errors) {
|
217 |
c3c692a9
|
Sjon Hortensius
|
print_input_errors($input_errors);
|
218 |
d61309a0
|
Phil Davis
|
}
|
219 |
|
|
if ($savemsg) {
|
220 |
a9929d56
|
Stephen Beaver
|
print_info_box($savemsg, 'success');
|
221 |
d61309a0
|
Phil Davis
|
}
|
222 |
f74457df
|
Stephen Beaver
|
|
223 |
d61309a0
|
Phil Davis
|
if (is_subsystem_dirty('staticroutes')) {
|
224 |
7fdca5ff
|
NOYB
|
print_apply_box(gettext("The gateway configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
|
225 |
d61309a0
|
Phil Davis
|
}
|
226 |
c3c692a9
|
Sjon Hortensius
|
|
227 |
|
|
$tab_array = array();
|
228 |
|
|
$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
|
229 |
80b4d0c5
|
heper
|
$tab_array[1] = array(gettext("Static Routes"), false, "system_routes.php");
|
230 |
|
|
$tab_array[2] = array(gettext("Gateway Groups"), false, "system_gateway_groups.php");
|
231 |
c3c692a9
|
Sjon Hortensius
|
display_top_tabs($tab_array);
|
232 |
d173230c
|
Seth Mos
|
|
233 |
d251a8d4
|
Renato Botelho
|
?>
|
234 |
060ed238
|
Stephen Beaver
|
<div class="panel panel-default">
|
235 |
|
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Gateways')?></h2></div>
|
236 |
|
|
<div class="panel-body">
|
237 |
|
|
<div class="table-responsive">
|
238 |
1c10ce97
|
PiBa-NL
|
<table class="table table-striped tabel-hover table-condensed table-rowdblclickedit">
|
239 |
060ed238
|
Stephen Beaver
|
<thead>
|
240 |
|
|
<tr>
|
241 |
|
|
<th></th>
|
242 |
|
|
<th><?=gettext("Name")?></th>
|
243 |
|
|
<th><?=gettext("Interface")?></th>
|
244 |
|
|
<th><?=gettext("Gateway")?></th>
|
245 |
|
|
<th><?=gettext("Monitor IP")?></th>
|
246 |
|
|
<th><?=gettext("Description")?></th>
|
247 |
|
|
<th><?=gettext("Actions")?></th>
|
248 |
|
|
</tr>
|
249 |
|
|
</thead>
|
250 |
|
|
<tbody>
|
251 |
e97df865
|
Renato Botelho
|
<?php
|
252 |
c3c692a9
|
Sjon Hortensius
|
foreach ($a_gateways as $i => $gateway):
|
253 |
d61309a0
|
Phil Davis
|
if (isset($gateway['inactive'])) {
|
254 |
1b7379f9
|
Jared Dillard
|
$icon = 'fa-times-circle-o';
|
255 |
d61309a0
|
Phil Davis
|
} elseif (isset($gateway['disabled'])) {
|
256 |
1b7379f9
|
Jared Dillard
|
$icon = 'fa-ban';
|
257 |
d61309a0
|
Phil Davis
|
} else {
|
258 |
1b7379f9
|
Jared Dillard
|
$icon = 'fa-check-circle-o';
|
259 |
d61309a0
|
Phil Davis
|
}
|
260 |
c3c692a9
|
Sjon Hortensius
|
|
261 |
d61309a0
|
Phil Davis
|
if (isset($gateway['inactive'])) {
|
262 |
c3c692a9
|
Sjon Hortensius
|
$title = gettext("This gateway is inactive because interface is missing");
|
263 |
d61309a0
|
Phil Davis
|
} else {
|
264 |
c3c692a9
|
Sjon Hortensius
|
$title = '';
|
265 |
d61309a0
|
Phil Davis
|
}
|
266 |
e97df865
|
Renato Botelho
|
?>
|
267 |
060ed238
|
Stephen Beaver
|
<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
|
268 |
|
|
<td title="<?=$title?>"><i class="fa <?=$icon?>"></i></td>
|
269 |
|
|
<td>
|
270 |
|
|
<?=htmlspecialchars($gateway['name'])?>
|
271 |
e97df865
|
Renato Botelho
|
<?php
|
272 |
d61309a0
|
Phil Davis
|
if (isset($gateway['defaultgw'])) {
|
273 |
c3c692a9
|
Sjon Hortensius
|
echo " <strong>(default)</strong>";
|
274 |
d61309a0
|
Phil Davis
|
}
|
275 |
e97df865
|
Renato Botelho
|
?>
|
276 |
060ed238
|
Stephen Beaver
|
</td>
|
277 |
|
|
<td>
|
278 |
|
|
<?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']))?>
|
279 |
|
|
</td>
|
280 |
|
|
<td>
|
281 |
|
|
<?=htmlspecialchars($gateway['gateway'])?>
|
282 |
|
|
</td>
|
283 |
|
|
<td>
|
284 |
|
|
<?=htmlspecialchars($gateway['monitor'])?>
|
285 |
|
|
</td>
|
286 |
|
|
<td>
|
287 |
|
|
<?=htmlspecialchars($gateway['descr'])?>
|
288 |
|
|
</td>
|
289 |
|
|
<td>
|
290 |
5154b00d
|
Phil Davis
|
<a href="system_gateways_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit gateway');?>"></a>
|
291 |
|
|
<a href="system_gateways_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy gateway')?>"></a>
|
292 |
f74457df
|
Stephen Beaver
|
|
293 |
fa172bc5
|
NewEraCracker
|
<?php if (is_numeric($gateway['attribute'])): ?>
|
294 |
1629e8ea
|
heper
|
<?php if (isset($gateway['disabled'])) {
|
295 |
f74457df
|
Stephen Beaver
|
?>
|
296 |
5154b00d
|
Phil Davis
|
<a href="?act=toggle&id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable gateway')?>"></a>
|
297 |
1629e8ea
|
heper
|
<?php } else {
|
298 |
|
|
?>
|
299 |
5154b00d
|
Phil Davis
|
<a href="?act=toggle&id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable gateway')?>"></a>
|
300 |
1629e8ea
|
heper
|
<?php }
|
301 |
f74457df
|
Stephen Beaver
|
?>
|
302 |
5154b00d
|
Phil Davis
|
<a href="system_gateways.php?act=del&id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete gateway')?>"></a>
|
303 |
f74457df
|
Stephen Beaver
|
|
304 |
fa172bc5
|
NewEraCracker
|
<?php endif; ?>
|
305 |
060ed238
|
Stephen Beaver
|
</td>
|
306 |
|
|
</tr>
|
307 |
fa172bc5
|
NewEraCracker
|
<?php endforeach; ?>
|
308 |
060ed238
|
Stephen Beaver
|
</tbody>
|
309 |
|
|
</table>
|
310 |
|
|
</div>
|
311 |
|
|
</div>
|
312 |
|
|
</div>
|
313 |
c3c692a9
|
Sjon Hortensius
|
|
314 |
c10cb196
|
Stephen Beaver
|
<nav class="action-buttons">
|
315 |
c3c692a9
|
Sjon Hortensius
|
<a href="system_gateways_edit.php" role="button" class="btn btn-success">
|
316 |
9d5a20cf
|
heper
|
<i class="fa fa-plus icon-embed-btn"></i>
|
317 |
f74457df
|
Stephen Beaver
|
<?=gettext("Add");?>
|
318 |
c3c692a9
|
Sjon Hortensius
|
</a>
|
319 |
|
|
</nav>
|
320 |
e97df865
|
Renato Botelho
|
<?php
|
321 |
c3c692a9
|
Sjon Hortensius
|
|
322 |
1629e8ea
|
heper
|
include("foot.inc");
|