1 |
d173230c
|
Seth Mos
|
<?php
|
2 |
124aee67
|
Chris Buechler
|
/* $Id$ */
|
3 |
d173230c
|
Seth Mos
|
/*
|
4 |
|
|
system_gateways.php
|
5 |
5721595b
|
Chris Buechler
|
part of pfSense (https://www.pfsense.org)
|
6 |
d173230c
|
Seth Mos
|
|
7 |
6216690b
|
smos
|
Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
|
8 |
ce77a9c4
|
Phil Davis
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
9 |
d173230c
|
Seth Mos
|
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 |
1d333258
|
Scott Ullrich
|
/*
|
33 |
|
|
pfSense_MODULE: routing
|
34 |
|
|
*/
|
35 |
d173230c
|
Seth Mos
|
|
36 |
6b07c15a
|
Matthew Grooms
|
##|+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 |
d173230c
|
Seth Mos
|
require("guiconfig.inc");
|
44 |
7a927e67
|
Scott Ullrich
|
require_once("functions.inc");
|
45 |
|
|
require_once("filter.inc");
|
46 |
|
|
require_once("shaper.inc");
|
47 |
d173230c
|
Seth Mos
|
|
48 |
e97df865
|
Renato Botelho
|
$a_gateways = return_gateways_array(true, false, true);
|
49 |
b92305a6
|
--global
|
$a_gateways_arr = array();
|
50 |
e0c7b2fe
|
Phil Davis
|
foreach ($a_gateways as $gw) {
|
51 |
3df6d458
|
Seth Mos
|
$a_gateways_arr[] = $gw;
|
52 |
e0c7b2fe
|
Phil Davis
|
}
|
53 |
b92305a6
|
--global
|
$a_gateways = $a_gateways_arr;
|
54 |
616e1956
|
Seth Mos
|
|
55 |
e0c7b2fe
|
Phil Davis
|
if (!is_array($config['gateways']['gateway_item'])) {
|
56 |
d251a8d4
|
Renato Botelho
|
$config['gateways']['gateway_item'] = array();
|
57 |
e0c7b2fe
|
Phil Davis
|
}
|
58 |
616e1956
|
Seth Mos
|
|
59 |
|
|
$a_gateway_item = &$config['gateways']['gateway_item'];
|
60 |
|
|
|
61 |
d173230c
|
Seth Mos
|
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 |
13bbe450
|
Seth Mos
|
/* reconfigure our gateway monitor */
|
72 |
|
|
setup_gateways_monitor();
|
73 |
d173230c
|
Seth Mos
|
|
74 |
|
|
$savemsg = get_std_save_message($retval);
|
75 |
e0c7b2fe
|
Phil Davis
|
if ($retval == 0) {
|
76 |
a368a026
|
Ermal Lu?i
|
clear_subsystem_dirty('staticroutes');
|
77 |
e0c7b2fe
|
Phil Davis
|
}
|
78 |
d173230c
|
Seth Mos
|
}
|
79 |
|
|
}
|
80 |
|
|
|
81 |
028ff8f8
|
Phil Davis
|
function can_delete_disable_gateway_item($id, $disable = false) {
|
82 |
e97df865
|
Renato Botelho
|
global $config, $input_errors, $a_gateways;
|
83 |
d251a8d4
|
Renato Botelho
|
|
84 |
e0c7b2fe
|
Phil Davis
|
if (!isset($a_gateways[$id])) {
|
85 |
e97df865
|
Renato Botelho
|
return false;
|
86 |
e0c7b2fe
|
Phil Davis
|
}
|
87 |
e97df865
|
Renato Botelho
|
|
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 |
205178aa
|
Phil Davis
|
if (!$disable) {
|
94 |
028ff8f8
|
Phil Davis
|
$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 |
205178aa
|
Phil Davis
|
} 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 |
028ff8f8
|
Phil Davis
|
}
|
98 |
f78302e8
|
Ermal
|
}
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
e97df865
|
Renato Botelho
|
}
|
102 |
|
|
|
103 |
|
|
if (is_array($config['staticroutes']['route'])) {
|
104 |
|
|
foreach ($config['staticroutes']['route'] as $route) {
|
105 |
|
|
if ($route['gateway'] == $a_gateways[$id]['name']) {
|
106 |
205178aa
|
Phil Davis
|
if (!$disable) {
|
107 |
028ff8f8
|
Phil Davis
|
// 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 |
205178aa
|
Phil Davis
|
} 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 |
028ff8f8
|
Phil Davis
|
}
|
114 |
f78302e8
|
Ermal
|
}
|
115 |
|
|
}
|
116 |
e97df865
|
Renato Botelho
|
}
|
117 |
|
|
|
118 |
e0c7b2fe
|
Phil Davis
|
if (isset($input_errors)) {
|
119 |
e97df865
|
Renato Botelho
|
return false;
|
120 |
e0c7b2fe
|
Phil Davis
|
}
|
121 |
e97df865
|
Renato Botelho
|
|
122 |
|
|
return true;
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
function delete_gateway_item($id) {
|
126 |
dde20226
|
Renato Botelho
|
global $config, $a_gateways;
|
127 |
|
|
|
128 |
e0c7b2fe
|
Phil Davis
|
if (!isset($a_gateways[$id])) {
|
129 |
e97df865
|
Renato Botelho
|
return;
|
130 |
e0c7b2fe
|
Phil Davis
|
}
|
131 |
32a9eb18
|
Ermal
|
|
132 |
e97df865
|
Renato Botelho
|
/* NOTE: Cleanup static routes for the monitor ip if any */
|
133 |
|
|
if (!empty($a_gateways[$id]['monitor']) &&
|
134 |
c3c692a9
|
Sjon Hortensius
|
$a_gateways[$id]['monitor'] != "dynamic" &&
|
135 |
|
|
is_ipaddr($a_gateways[$id]['monitor']) &&
|
136 |
|
|
$a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
|
137 |
e0c7b2fe
|
Phil Davis
|
if (is_ipaddrv4($a_gateways[$id]['monitor'])) {
|
138 |
e97df865
|
Renato Botelho
|
mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']));
|
139 |
e0c7b2fe
|
Phil Davis
|
} else {
|
140 |
e97df865
|
Renato Botelho
|
mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']));
|
141 |
e0c7b2fe
|
Phil Davis
|
}
|
142 |
e97df865
|
Renato Botelho
|
}
|
143 |
|
|
|
144 |
e0c7b2fe
|
Phil Davis
|
if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) {
|
145 |
e97df865
|
Renato Botelho
|
unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
|
146 |
e0c7b2fe
|
Phil Davis
|
}
|
147 |
e97df865
|
Renato Botelho
|
unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
unset($input_errors);
|
151 |
|
|
if ($_GET['act'] == "del") {
|
152 |
028ff8f8
|
Phil Davis
|
if (can_delete_disable_gateway_item($_GET['id'])) {
|
153 |
e97df865
|
Renato Botelho
|
$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 |
e0c7b2fe
|
Phil Davis
|
foreach ($_POST['rule'] as $rulei) {
|
166 |
028ff8f8
|
Phil Davis
|
if (!can_delete_disable_gateway_item($rulei)) {
|
167 |
e97df865
|
Renato Botelho
|
break;
|
168 |
e0c7b2fe
|
Phil Davis
|
}
|
169 |
|
|
}
|
170 |
e97df865
|
Renato Botelho
|
|
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 |
f78302e8
|
Ermal
|
header("Location: system_gateways.php");
|
182 |
|
|
exit;
|
183 |
|
|
}
|
184 |
d173230c
|
Seth Mos
|
}
|
185 |
|
|
|
186 |
e97df865
|
Renato Botelho
|
} else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) {
|
187 |
|
|
$realid = $a_gateways[$_GET['id']]['attribute'];
|
188 |
028ff8f8
|
Phil Davis
|
$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 |
e0c7b2fe
|
Phil Davis
|
} else {
|
193 |
028ff8f8
|
Phil Davis
|
// The user wants to enable the gateway. That is always OK.
|
194 |
|
|
$ok_to_toggle = true;
|
195 |
e0c7b2fe
|
Phil Davis
|
}
|
196 |
028ff8f8
|
Phil Davis
|
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 |
e97df865
|
Renato Botelho
|
|
203 |
028ff8f8
|
Phil Davis
|
if (write_config("Gateways: enable/disable")) {
|
204 |
|
|
mark_subsystem_dirty('staticroutes');
|
205 |
|
|
}
|
206 |
e97df865
|
Renato Botelho
|
|
207 |
028ff8f8
|
Phil Davis
|
header("Location: system_gateways.php");
|
208 |
|
|
exit;
|
209 |
|
|
}
|
210 |
e97df865
|
Renato Botelho
|
}
|
211 |
124aee67
|
Chris Buechler
|
|
212 |
e0c7b2fe
|
Phil Davis
|
$pgtitle = array(gettext("System"), gettext("Gateways"));
|
213 |
b32dd0a6
|
jim-p
|
$shortcut_section = "gateways";
|
214 |
02ca24c9
|
jim-p
|
|
215 |
d173230c
|
Seth Mos
|
include("head.inc");
|
216 |
|
|
|
217 |
c3c692a9
|
Sjon Hortensius
|
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 |
d173230c
|
Seth Mos
|
|
230 |
d251a8d4
|
Renato Botelho
|
?>
|
231 |
c3c692a9
|
Sjon Hortensius
|
<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 |
e97df865
|
Renato Botelho
|
<?php
|
245 |
c3c692a9
|
Sjon Hortensius
|
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 |
e97df865
|
Renato Botelho
|
?>
|
258 |
c3c692a9
|
Sjon Hortensius
|
<tr<?=($icon != 'icon-ok-circle')? ' class="disabled"' : ''?>>
|
259 |
|
|
<td title="<?=$title?>"><i class="icon <?=$icon?>"></i></td>
|
260 |
|
|
<td>
|
261 |
|
|
<?=$gateway['name']?>
|
262 |
e97df865
|
Renato Botelho
|
<?php
|
263 |
c3c692a9
|
Sjon Hortensius
|
if (isset($gateway['defaultgw']))
|
264 |
|
|
echo " <strong>(default)</strong>";
|
265 |
e97df865
|
Renato Botelho
|
?>
|
266 |
c3c692a9
|
Sjon Hortensius
|
</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 |
45d6ada5
|
Sjon Hortensius
|
<a class="btn btn-xs btn-danger" href="system_gateways.php?act=del&id=<?=$i?>">
|
288 |
c3c692a9
|
Sjon Hortensius
|
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 |
e97df865
|
Renato Botelho
|
<?php
|
306 |
c3c692a9
|
Sjon Hortensius
|
|
307 |
|
|
include("foot.inc");
|