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