1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
4a5ac5e0
|
Phil Davis
|
/*
|
3 |
|
|
system_routes.php
|
4 |
|
|
*/
|
5 |
c0411930
|
Stephen Beaver
|
/* ====================================================================
|
6 |
|
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7 |
191cb31d
|
Stephen Beaver
|
*
|
8 |
cb41dd63
|
Renato Botelho
|
* Some or all of this file is based on the m0n0wall project which is
|
9 |
|
|
* Copyright (c) 2004 Manuel Kasper (BSD 2 clause)
|
10 |
c0411930
|
Stephen Beaver
|
*
|
11 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
12 |
|
|
* 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
|
19 |
|
|
* the documentation and/or other materials provided with the
|
20 |
|
|
* distribution.
|
21 |
|
|
*
|
22 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
23 |
|
|
* must display the following acknowledgment:
|
24 |
|
|
* "This product includes software developed by the pfSense Project
|
25 |
|
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
26 |
|
|
*
|
27 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
28 |
|
|
* endorse or promote products derived from this software without
|
29 |
|
|
* prior written permission. For written permission, please contact
|
30 |
|
|
* coreteam@pfsense.org.
|
31 |
|
|
*
|
32 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
33 |
|
|
* nor may "pfSense" appear in their names without prior written
|
34 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
35 |
|
|
*
|
36 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
37 |
|
|
* acknowledgment:
|
38 |
|
|
*
|
39 |
|
|
* "This product includes software developed by the pfSense Project
|
40 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
41 |
|
|
*
|
42 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
43 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
44 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
45 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
46 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
47 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
48 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
49 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
50 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
51 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
52 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
53 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
54 |
|
|
*
|
55 |
|
|
* ====================================================================
|
56 |
|
|
*
|
57 |
|
|
*/
|
58 |
1d333258
|
Scott Ullrich
|
/*
|
59 |
|
|
pfSense_MODULE: routing
|
60 |
|
|
*/
|
61 |
5b237745
|
Scott Ullrich
|
|
62 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
63 |
|
|
##|*IDENT=page-system-staticroutes
|
64 |
5230f468
|
jim-p
|
##|*NAME=System: Static Routes
|
65 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'System: Static Routes' page.
|
66 |
|
|
##|*MATCH=system_routes.php*
|
67 |
|
|
##|-PRIV
|
68 |
|
|
|
69 |
5b237745
|
Scott Ullrich
|
require("guiconfig.inc");
|
70 |
7a927e67
|
Scott Ullrich
|
require_once("functions.inc");
|
71 |
|
|
require_once("filter.inc");
|
72 |
|
|
require_once("shaper.inc");
|
73 |
5b237745
|
Scott Ullrich
|
|
74 |
d38bd840
|
Phil Davis
|
if (!is_array($config['staticroutes']['route'])) {
|
75 |
5b237745
|
Scott Ullrich
|
$config['staticroutes']['route'] = array();
|
76 |
d38bd840
|
Phil Davis
|
}
|
77 |
5b237745
|
Scott Ullrich
|
|
78 |
|
|
$a_routes = &$config['staticroutes']['route'];
|
79 |
70cb0375
|
Renato Botelho
|
$a_gateways = return_gateways_array(true, true, true);
|
80 |
|
|
$changedesc_prefix = gettext("Static Routes") . ": ";
|
81 |
028ff8f8
|
Phil Davis
|
unset($input_errors);
|
82 |
5b237745
|
Scott Ullrich
|
|
83 |
|
|
if ($_POST) {
|
84 |
|
|
|
85 |
|
|
$pconfig = $_POST;
|
86 |
|
|
|
87 |
|
|
if ($_POST['apply']) {
|
88 |
691dade5
|
Scott Ullrich
|
|
89 |
5b237745
|
Scott Ullrich
|
$retval = 0;
|
90 |
3851094f
|
Scott Ullrich
|
|
91 |
e8471084
|
Ermal
|
if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
|
92 |
bfe407e5
|
Warren Baker
|
$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
|
93 |
d38bd840
|
Phil Davis
|
foreach ($toapplylist as $toapply) {
|
94 |
e8471084
|
Ermal
|
mwexec("{$toapply}");
|
95 |
d38bd840
|
Phil Davis
|
}
|
96 |
966780ad
|
Renato Botelho
|
|
97 |
e8471084
|
Ermal
|
@unlink("{$g['tmp_path']}/.system_routes.apply");
|
98 |
|
|
}
|
99 |
|
|
|
100 |
3851094f
|
Scott Ullrich
|
$retval = system_routing_configure();
|
101 |
|
|
$retval |= filter_configure();
|
102 |
13bbe450
|
Seth Mos
|
/* reconfigure our gateway monitor */
|
103 |
|
|
setup_gateways_monitor();
|
104 |
3851094f
|
Scott Ullrich
|
|
105 |
5b237745
|
Scott Ullrich
|
$savemsg = get_std_save_message($retval);
|
106 |
d38bd840
|
Phil Davis
|
if ($retval == 0) {
|
107 |
a368a026
|
Ermal Lu?i
|
clear_subsystem_dirty('staticroutes');
|
108 |
d38bd840
|
Phil Davis
|
}
|
109 |
5b237745
|
Scott Ullrich
|
}
|
110 |
|
|
}
|
111 |
|
|
|
112 |
70cb0375
|
Renato Botelho
|
function delete_static_route($id) {
|
113 |
|
|
global $config, $a_routes, $changedesc_prefix;
|
114 |
|
|
|
115 |
d38bd840
|
Phil Davis
|
if (!isset($a_routes[$id])) {
|
116 |
70cb0375
|
Renato Botelho
|
return;
|
117 |
d38bd840
|
Phil Davis
|
}
|
118 |
70cb0375
|
Renato Botelho
|
|
119 |
|
|
$targets = array();
|
120 |
|
|
if (is_alias($a_routes[$id]['network'])) {
|
121 |
|
|
foreach (filter_expand_alias_array($a_routes[$id]['network']) as $tgt) {
|
122 |
d38bd840
|
Phil Davis
|
if (is_ipaddrv4($tgt)) {
|
123 |
70cb0375
|
Renato Botelho
|
$tgt .= "/32";
|
124 |
d38bd840
|
Phil Davis
|
} else if (is_ipaddrv6($tgt)) {
|
125 |
70cb0375
|
Renato Botelho
|
$tgt .= "/128";
|
126 |
d38bd840
|
Phil Davis
|
}
|
127 |
|
|
if (!is_subnet($tgt)) {
|
128 |
70cb0375
|
Renato Botelho
|
continue;
|
129 |
d38bd840
|
Phil Davis
|
}
|
130 |
70cb0375
|
Renato Botelho
|
$targets[] = $tgt;
|
131 |
|
|
}
|
132 |
|
|
} else {
|
133 |
|
|
$targets[] = $a_routes[$id]['network'];
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
foreach ($targets as $tgt) {
|
137 |
|
|
$family = (is_subnetv6($tgt) ? "-inet6" : "-inet");
|
138 |
|
|
mwexec("/sbin/route delete {$family} " . escapeshellarg($tgt));
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
unset($targets);
|
142 |
|
|
}
|
143 |
|
|
|
144 |
5b237745
|
Scott Ullrich
|
if ($_GET['act'] == "del") {
|
145 |
|
|
if ($a_routes[$_GET['id']]) {
|
146 |
70cb0375
|
Renato Botelho
|
$changedesc = $changedesc_prefix . gettext("removed route to") . " " . $a_routes[$_GET['id']]['network'];
|
147 |
|
|
delete_static_route($_GET['id']);
|
148 |
|
|
unset($a_routes[$_GET['id']]);
|
149 |
|
|
write_config($changedesc);
|
150 |
|
|
header("Location: system_routes.php");
|
151 |
|
|
exit;
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
if (isset($_POST['del_x'])) {
|
156 |
|
|
/* delete selected routes */
|
157 |
|
|
if (is_array($_POST['route']) && count($_POST['route'])) {
|
158 |
|
|
$changedesc = $changedesc_prefix . gettext("removed route to");
|
159 |
|
|
foreach ($_POST['route'] as $routei) {
|
160 |
|
|
$changedesc .= " " . $a_routes[$routei]['network'];
|
161 |
|
|
delete_static_route($routei);
|
162 |
|
|
unset($a_routes[$routei]);
|
163 |
|
|
}
|
164 |
|
|
write_config($changedesc);
|
165 |
|
|
header("Location: system_routes.php");
|
166 |
|
|
exit;
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
} else if ($_GET['act'] == "toggle") {
|
170 |
|
|
if ($a_routes[$_GET['id']]) {
|
171 |
028ff8f8
|
Phil Davis
|
$do_update_config = true;
|
172 |
d38bd840
|
Phil Davis
|
if (isset($a_routes[$_GET['id']]['disabled'])) {
|
173 |
028ff8f8
|
Phil Davis
|
// Do not enable a route whose gateway is disabled
|
174 |
|
|
if (isset($a_gateways[$a_routes[$_GET['id']]['gateway']]['disabled'])) {
|
175 |
|
|
$do_update_config = false;
|
176 |
|
|
$input_errors[] = $changedesc_prefix . gettext("gateway is disabled, cannot enable route to") . " " . $a_routes[$_GET['id']]['network'];
|
177 |
|
|
} else {
|
178 |
|
|
unset($a_routes[$_GET['id']]['disabled']);
|
179 |
|
|
$changedesc = $changedesc_prefix . gettext("enabled route to") . " " . $a_routes[$_GET['id']]['network'];
|
180 |
|
|
}
|
181 |
25c3f30c
|
Renato Botelho
|
} else {
|
182 |
70cb0375
|
Renato Botelho
|
delete_static_route($_GET['id']);
|
183 |
|
|
$a_routes[$_GET['id']]['disabled'] = true;
|
184 |
6135a11f
|
Phil Davis
|
$changedesc = $changedesc_prefix . gettext("disabled route to") . " " . $a_routes[$_GET['id']]['network'];
|
185 |
9c115b40
|
Ermal
|
}
|
186 |
25c3f30c
|
Renato Botelho
|
|
187 |
028ff8f8
|
Phil Davis
|
if ($do_update_config) {
|
188 |
|
|
if (write_config($changedesc)) {
|
189 |
|
|
mark_subsystem_dirty('staticroutes');
|
190 |
|
|
}
|
191 |
|
|
header("Location: system_routes.php");
|
192 |
|
|
exit;
|
193 |
d38bd840
|
Phil Davis
|
}
|
194 |
70cb0375
|
Renato Botelho
|
}
|
195 |
|
|
} else {
|
196 |
|
|
/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
|
197 |
|
|
unset($movebtn);
|
198 |
|
|
foreach ($_POST as $pn => $pd) {
|
199 |
|
|
if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
|
200 |
|
|
$movebtn = $matches[1];
|
201 |
|
|
break;
|
202 |
25c3f30c
|
Renato Botelho
|
}
|
203 |
70cb0375
|
Renato Botelho
|
}
|
204 |
|
|
/* move selected routes before this route */
|
205 |
|
|
if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
|
206 |
|
|
$a_routes_new = array();
|
207 |
25c3f30c
|
Renato Botelho
|
|
208 |
70cb0375
|
Renato Botelho
|
/* copy all routes < $movebtn and not selected */
|
209 |
|
|
for ($i = 0; $i < $movebtn; $i++) {
|
210 |
d38bd840
|
Phil Davis
|
if (!in_array($i, $_POST['route'])) {
|
211 |
70cb0375
|
Renato Botelho
|
$a_routes_new[] = $a_routes[$i];
|
212 |
d38bd840
|
Phil Davis
|
}
|
213 |
70cb0375
|
Renato Botelho
|
}
|
214 |
|
|
|
215 |
|
|
/* copy all selected routes */
|
216 |
|
|
for ($i = 0; $i < count($a_routes); $i++) {
|
217 |
d38bd840
|
Phil Davis
|
if ($i == $movebtn) {
|
218 |
70cb0375
|
Renato Botelho
|
continue;
|
219 |
d38bd840
|
Phil Davis
|
}
|
220 |
|
|
if (in_array($i, $_POST['route'])) {
|
221 |
70cb0375
|
Renato Botelho
|
$a_routes_new[] = $a_routes[$i];
|
222 |
d38bd840
|
Phil Davis
|
}
|
223 |
70cb0375
|
Renato Botelho
|
}
|
224 |
|
|
|
225 |
|
|
/* copy $movebtn route */
|
226 |
d38bd840
|
Phil Davis
|
if ($movebtn < count($a_routes)) {
|
227 |
70cb0375
|
Renato Botelho
|
$a_routes_new[] = $a_routes[$movebtn];
|
228 |
d38bd840
|
Phil Davis
|
}
|
229 |
70cb0375
|
Renato Botelho
|
|
230 |
|
|
/* copy all routes > $movebtn and not selected */
|
231 |
|
|
for ($i = $movebtn+1; $i < count($a_routes); $i++) {
|
232 |
d38bd840
|
Phil Davis
|
if (!in_array($i, $_POST['route'])) {
|
233 |
70cb0375
|
Renato Botelho
|
$a_routes_new[] = $a_routes[$i];
|
234 |
d38bd840
|
Phil Davis
|
}
|
235 |
70cb0375
|
Renato Botelho
|
}
|
236 |
d38bd840
|
Phil Davis
|
if (count($a_routes_new) > 0) {
|
237 |
70cb0375
|
Renato Botelho
|
$a_routes = $a_routes_new;
|
238 |
d38bd840
|
Phil Davis
|
}
|
239 |
70cb0375
|
Renato Botelho
|
|
240 |
d38bd840
|
Phil Davis
|
if (write_config()) {
|
241 |
70cb0375
|
Renato Botelho
|
mark_subsystem_dirty('staticroutes');
|
242 |
d38bd840
|
Phil Davis
|
}
|
243 |
25c3f30c
|
Renato Botelho
|
header("Location: system_routes.php");
|
244 |
|
|
exit;
|
245 |
5b237745
|
Scott Ullrich
|
}
|
246 |
|
|
}
|
247 |
7f43ca88
|
Scott Ullrich
|
|
248 |
d036bc07
|
Stephen Beaver
|
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Static Routes"));
|
249 |
b32dd0a6
|
jim-p
|
$shortcut_section = "routing";
|
250 |
02ca24c9
|
jim-p
|
|
251 |
7f43ca88
|
Scott Ullrich
|
include("head.inc");
|
252 |
|
|
|
253 |
f3bb71cf
|
Sjon Hortensius
|
if ($input_errors)
|
254 |
|
|
print_input_errors($input_errors);
|
255 |
|
|
if ($savemsg)
|
256 |
|
|
print_info_box($savemsg);
|
257 |
|
|
if (is_subsystem_dirty('staticroutes'))
|
258 |
|
|
print_info_box_np(gettext("The static route configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
|
259 |
|
|
|
260 |
|
|
$tab_array = array();
|
261 |
|
|
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
|
262 |
|
|
$tab_array[1] = array(gettext("Routes"), true, "system_routes.php");
|
263 |
|
|
$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
|
264 |
|
|
display_top_tabs($tab_array);
|
265 |
0f282d7a
|
Scott Ullrich
|
|
266 |
f3bb71cf
|
Sjon Hortensius
|
?>
|
267 |
|
|
<table class="table">
|
268 |
|
|
<thead>
|
269 |
966780ad
|
Renato Botelho
|
<tr>
|
270 |
f3bb71cf
|
Sjon Hortensius
|
<th></th>
|
271 |
|
|
<th><?=gettext("Network")?></th>
|
272 |
|
|
<th><?=gettext("Gateway")?></th>
|
273 |
|
|
<th><?=gettext("Interface")?></th>
|
274 |
|
|
<th><?=gettext("Description")?></th>
|
275 |
4a5ac5e0
|
Phil Davis
|
<th><?=gettext("Actions")?></th>
|
276 |
966780ad
|
Renato Botelho
|
</tr>
|
277 |
f3bb71cf
|
Sjon Hortensius
|
</thead>
|
278 |
|
|
<tbody>
|
279 |
70cb0375
|
Renato Botelho
|
<?php
|
280 |
f3bb71cf
|
Sjon Hortensius
|
foreach ($a_routes as $i => $route):
|
281 |
|
|
if (isset($route['disabled']))
|
282 |
1b7379f9
|
Jared Dillard
|
$icon = 'fa-ban';
|
283 |
f3bb71cf
|
Sjon Hortensius
|
else
|
284 |
1b7379f9
|
Jared Dillard
|
$icon = 'fa-check-circle-o';
|
285 |
70cb0375
|
Renato Botelho
|
?>
|
286 |
1b7379f9
|
Jared Dillard
|
<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
|
287 |
|
|
<td><i class="fa <?=$icon?>"></i></td>
|
288 |
f3bb71cf
|
Sjon Hortensius
|
<td>
|
289 |
|
|
<?=strtolower($route['network'])?>
|
290 |
|
|
</td>
|
291 |
|
|
<td>
|
292 |
|
|
<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
|
293 |
|
|
</td>
|
294 |
|
|
<td>
|
295 |
|
|
<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
|
296 |
|
|
</td>
|
297 |
|
|
<td>
|
298 |
|
|
<?=htmlspecialchars($route['descr'])?>
|
299 |
966780ad
|
Renato Botelho
|
</td>
|
300 |
f3bb71cf
|
Sjon Hortensius
|
<td>
|
301 |
5d339e8e
|
heper
|
<a href="system_routes_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
|
302 |
f74457df
|
Stephen Beaver
|
|
303 |
5d339e8e
|
heper
|
<a href="system_routes_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
|
304 |
f74457df
|
Stephen Beaver
|
|
305 |
5d339e8e
|
heper
|
<?php if (isset($route['disabled'])) {
|
306 |
f74457df
|
Stephen Beaver
|
?>
|
307 |
5d339e8e
|
heper
|
<a href="?act=toggle&id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
|
308 |
|
|
<?php } else {
|
309 |
|
|
?>
|
310 |
|
|
<a href="?act=toggle&id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
|
311 |
|
|
<?php }
|
312 |
f74457df
|
Stephen Beaver
|
?>
|
313 |
33f0b0d5
|
Stephen Beaver
|
<a href="system_routes.php?act=del&id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete')?>"></a>
|
314 |
f3bb71cf
|
Sjon Hortensius
|
|
315 |
|
|
</td>
|
316 |
|
|
<? endforeach?>
|
317 |
966780ad
|
Renato Botelho
|
</tr>
|
318 |
|
|
</table>
|
319 |
f3bb71cf
|
Sjon Hortensius
|
|
320 |
c10cb196
|
Stephen Beaver
|
<nav class="action-buttons">
|
321 |
f74457df
|
Stephen Beaver
|
<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
|
322 |
9d5a20cf
|
heper
|
<i class="fa fa-plus icon-embed-btn"></i>
|
323 |
f74457df
|
Stephen Beaver
|
<?=gettext("Add")?>
|
324 |
f3bb71cf
|
Sjon Hortensius
|
</a>
|
325 |
|
|
</nav>
|
326 |
|
|
<?php
|
327 |
|
|
|
328 |
5d339e8e
|
heper
|
include("foot.inc");
|