1
|
<?php
|
2
|
/*
|
3
|
* system_routes.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7
|
* All rights reserved.
|
8
|
*
|
9
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
10
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11
|
* All rights reserved.
|
12
|
*
|
13
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
14
|
* you may not use this file except in compliance with the License.
|
15
|
* You may obtain a copy of the License at
|
16
|
*
|
17
|
* http://www.apache.org/licenses/LICENSE-2.0
|
18
|
*
|
19
|
* Unless required by applicable law or agreed to in writing, software
|
20
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
21
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
22
|
* See the License for the specific language governing permissions and
|
23
|
* limitations under the License.
|
24
|
*/
|
25
|
|
26
|
##|+PRIV
|
27
|
##|*IDENT=page-system-staticroutes
|
28
|
##|*NAME=System: Static Routes
|
29
|
##|*DESCR=Allow access to the 'System: Static Routes' page.
|
30
|
##|*MATCH=system_routes.php*
|
31
|
##|-PRIV
|
32
|
|
33
|
require_once("guiconfig.inc");
|
34
|
require_once("functions.inc");
|
35
|
require_once("filter.inc");
|
36
|
require_once("shaper.inc");
|
37
|
|
38
|
if (!is_array($config['staticroutes']['route'])) {
|
39
|
$config['staticroutes']['route'] = array();
|
40
|
}
|
41
|
|
42
|
$a_routes = &$config['staticroutes']['route'];
|
43
|
$a_gateways = return_gateways_array(true, true, true);
|
44
|
$changedesc_prefix = gettext("Static Routes") . ": ";
|
45
|
unset($input_errors);
|
46
|
|
47
|
if ($_POST) {
|
48
|
|
49
|
$pconfig = $_POST;
|
50
|
|
51
|
if ($_POST['apply']) {
|
52
|
|
53
|
$retval = 0;
|
54
|
|
55
|
if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
|
56
|
$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
|
57
|
foreach ($toapplylist as $toapply) {
|
58
|
mwexec("{$toapply}");
|
59
|
}
|
60
|
|
61
|
@unlink("{$g['tmp_path']}/.system_routes.apply");
|
62
|
}
|
63
|
|
64
|
$retval |= system_routing_configure();
|
65
|
$retval |= filter_configure();
|
66
|
/* reconfigure our gateway monitor */
|
67
|
setup_gateways_monitor();
|
68
|
|
69
|
if ($retval == 0) {
|
70
|
clear_subsystem_dirty('staticroutes');
|
71
|
}
|
72
|
}
|
73
|
}
|
74
|
|
75
|
function delete_static_route($id) {
|
76
|
global $config, $a_routes, $changedesc_prefix;
|
77
|
|
78
|
if (!isset($a_routes[$id])) {
|
79
|
return;
|
80
|
}
|
81
|
|
82
|
$targets = array();
|
83
|
if (is_alias($a_routes[$id]['network'])) {
|
84
|
foreach (filter_expand_alias_array($a_routes[$id]['network']) as $tgt) {
|
85
|
if (is_ipaddrv4($tgt)) {
|
86
|
$tgt .= "/32";
|
87
|
} else if (is_ipaddrv6($tgt)) {
|
88
|
$tgt .= "/128";
|
89
|
}
|
90
|
if (!is_subnet($tgt)) {
|
91
|
continue;
|
92
|
}
|
93
|
$targets[] = $tgt;
|
94
|
}
|
95
|
} else {
|
96
|
$targets[] = $a_routes[$id]['network'];
|
97
|
}
|
98
|
|
99
|
foreach ($targets as $tgt) {
|
100
|
$family = (is_subnetv6($tgt) ? "-inet6" : "-inet");
|
101
|
mwexec("/sbin/route delete {$family} " . escapeshellarg($tgt));
|
102
|
}
|
103
|
|
104
|
unset($targets);
|
105
|
}
|
106
|
|
107
|
if ($_GET['act'] == "del") {
|
108
|
if ($a_routes[$_GET['id']]) {
|
109
|
$changedesc = $changedesc_prefix . sprintf(gettext("removed route to %s"), $a_routes[$_GET['id']]['network']);
|
110
|
delete_static_route($_GET['id']);
|
111
|
unset($a_routes[$_GET['id']]);
|
112
|
write_config($changedesc);
|
113
|
header("Location: system_routes.php");
|
114
|
exit;
|
115
|
}
|
116
|
}
|
117
|
|
118
|
if (isset($_POST['del_x'])) {
|
119
|
/* delete selected routes */
|
120
|
if (is_array($_POST['route']) && count($_POST['route'])) {
|
121
|
$deleted_routes = "";
|
122
|
foreach ($_POST['route'] as $routei) {
|
123
|
$deleted_routes .= " " . $a_routes[$routei]['network'];
|
124
|
delete_static_route($routei);
|
125
|
unset($a_routes[$routei]);
|
126
|
}
|
127
|
$changedesc = $changedesc_prefix . sprintf(gettext("removed route to%s"), $deleted_routes);
|
128
|
write_config($changedesc);
|
129
|
header("Location: system_routes.php");
|
130
|
exit;
|
131
|
}
|
132
|
|
133
|
} else if ($_GET['act'] == "toggle") {
|
134
|
if ($a_routes[$_GET['id']]) {
|
135
|
$do_update_config = true;
|
136
|
if (isset($a_routes[$_GET['id']]['disabled'])) {
|
137
|
// Do not enable a route whose gateway is disabled
|
138
|
if (isset($a_gateways[$a_routes[$_GET['id']]['gateway']]['disabled'])) {
|
139
|
$do_update_config = false;
|
140
|
$input_errors[] = $changedesc_prefix . sprintf(gettext("gateway is disabled, cannot enable route to %s"), $a_routes[$_GET['id']]['network']);
|
141
|
} else {
|
142
|
unset($a_routes[$_GET['id']]['disabled']);
|
143
|
$changedesc = $changedesc_prefix . sprintf(gettext("enabled route to %s"), $a_routes[$_GET['id']]['network']);
|
144
|
}
|
145
|
} else {
|
146
|
delete_static_route($_GET['id']);
|
147
|
$a_routes[$_GET['id']]['disabled'] = true;
|
148
|
$changedesc = $changedesc_prefix . sprintf(gettext("disabled route to %s"), $a_routes[$_GET['id']]['network']);
|
149
|
}
|
150
|
|
151
|
if ($do_update_config) {
|
152
|
if (write_config($changedesc)) {
|
153
|
mark_subsystem_dirty('staticroutes');
|
154
|
}
|
155
|
header("Location: system_routes.php");
|
156
|
exit;
|
157
|
}
|
158
|
}
|
159
|
} else {
|
160
|
/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
|
161
|
unset($movebtn);
|
162
|
foreach ($_POST as $pn => $pd) {
|
163
|
if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
|
164
|
$movebtn = $matches[1];
|
165
|
break;
|
166
|
}
|
167
|
}
|
168
|
/* move selected routes before this route */
|
169
|
if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
|
170
|
$a_routes_new = array();
|
171
|
|
172
|
/* copy all routes < $movebtn and not selected */
|
173
|
for ($i = 0; $i < $movebtn; $i++) {
|
174
|
if (!in_array($i, $_POST['route'])) {
|
175
|
$a_routes_new[] = $a_routes[$i];
|
176
|
}
|
177
|
}
|
178
|
|
179
|
/* copy all selected routes */
|
180
|
for ($i = 0; $i < count($a_routes); $i++) {
|
181
|
if ($i == $movebtn) {
|
182
|
continue;
|
183
|
}
|
184
|
if (in_array($i, $_POST['route'])) {
|
185
|
$a_routes_new[] = $a_routes[$i];
|
186
|
}
|
187
|
}
|
188
|
|
189
|
/* copy $movebtn route */
|
190
|
if ($movebtn < count($a_routes)) {
|
191
|
$a_routes_new[] = $a_routes[$movebtn];
|
192
|
}
|
193
|
|
194
|
/* copy all routes > $movebtn and not selected */
|
195
|
for ($i = $movebtn+1; $i < count($a_routes); $i++) {
|
196
|
if (!in_array($i, $_POST['route'])) {
|
197
|
$a_routes_new[] = $a_routes[$i];
|
198
|
}
|
199
|
}
|
200
|
if (count($a_routes_new) > 0) {
|
201
|
$a_routes = $a_routes_new;
|
202
|
}
|
203
|
|
204
|
if (write_config()) {
|
205
|
mark_subsystem_dirty('staticroutes');
|
206
|
}
|
207
|
header("Location: system_routes.php");
|
208
|
exit;
|
209
|
}
|
210
|
}
|
211
|
|
212
|
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Static Routes"));
|
213
|
$pglinks = array("", "system_gateways.php", "@self");
|
214
|
$shortcut_section = "routing";
|
215
|
|
216
|
include("head.inc");
|
217
|
|
218
|
if ($input_errors) {
|
219
|
print_input_errors($input_errors);
|
220
|
}
|
221
|
if ($_POST['apply']) {
|
222
|
print_apply_result_box($retval);
|
223
|
}
|
224
|
if (is_subsystem_dirty('staticroutes')) {
|
225
|
print_apply_box(gettext("The static route configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
|
226
|
}
|
227
|
|
228
|
$tab_array = array();
|
229
|
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
|
230
|
$tab_array[1] = array(gettext("Static Routes"), true, "system_routes.php");
|
231
|
$tab_array[2] = array(gettext("Gateway Groups"), false, "system_gateway_groups.php");
|
232
|
display_top_tabs($tab_array);
|
233
|
|
234
|
?>
|
235
|
<div class="panel panel-default">
|
236
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Static Routes')?></h2></div>
|
237
|
<div class="panel-body">
|
238
|
<div class="table-responsive">
|
239
|
<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
|
240
|
<thead>
|
241
|
<tr>
|
242
|
<th></th>
|
243
|
<th><?=gettext("Network")?></th>
|
244
|
<th><?=gettext("Gateway")?></th>
|
245
|
<th><?=gettext("Interface")?></th>
|
246
|
<th><?=gettext("Description")?></th>
|
247
|
<th><?=gettext("Actions")?></th>
|
248
|
</tr>
|
249
|
</thead>
|
250
|
<tbody>
|
251
|
<?php
|
252
|
foreach ($a_routes as $i => $route):
|
253
|
if (isset($route['disabled'])) {
|
254
|
$icon = 'fa-ban';
|
255
|
} else {
|
256
|
$icon = 'fa-check-circle-o';
|
257
|
}
|
258
|
?>
|
259
|
<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
|
260
|
<td><i class="fa <?=$icon?>"></i></td>
|
261
|
<td>
|
262
|
<?=strtolower($route['network'])?>
|
263
|
</td>
|
264
|
<td>
|
265
|
<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
|
266
|
</td>
|
267
|
<td>
|
268
|
<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
|
269
|
</td>
|
270
|
<td>
|
271
|
<?=htmlspecialchars($route['descr'])?>
|
272
|
</td>
|
273
|
<td>
|
274
|
<a href="system_routes_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit route')?>"></a>
|
275
|
|
276
|
<a href="system_routes_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy route')?>"></a>
|
277
|
|
278
|
<?php if (isset($route['disabled'])) {
|
279
|
?>
|
280
|
<a href="?act=toggle&id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable route')?>"></a>
|
281
|
<?php } else {
|
282
|
?>
|
283
|
<a href="?act=toggle&id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable route')?>"></a>
|
284
|
<?php }
|
285
|
?>
|
286
|
<a href="system_routes.php?act=del&id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete route')?>"></a>
|
287
|
|
288
|
</td>
|
289
|
</tr>
|
290
|
<?php endforeach; ?>
|
291
|
</table>
|
292
|
</div>
|
293
|
</div>
|
294
|
</div>
|
295
|
|
296
|
<nav class="action-buttons">
|
297
|
<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
|
298
|
<i class="fa fa-plus icon-embed-btn"></i>
|
299
|
<?=gettext("Add")?>
|
300
|
</a>
|
301
|
</nav>
|
302
|
<?php
|
303
|
|
304
|
include("foot.inc");
|