| 1 |
5b237745
|
Scott Ullrich
|
<?php
|
| 2 |
4a5ac5e0
|
Phil Davis
|
/*
|
| 3 |
c5d81585
|
Renato Botelho
|
* system_routes.php
|
| 4 |
191cb31d
|
Stephen Beaver
|
*
|
| 5 |
c5d81585
|
Renato Botelho
|
* part of pfSense (https://www.pfsense.org)
|
| 6 |
81299b5c
|
Renato Botelho
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
| 7 |
c5d81585
|
Renato Botelho
|
* All rights reserved.
|
| 8 |
c0411930
|
Stephen Beaver
|
*
|
| 9 |
c5d81585
|
Renato Botelho
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
| 10 |
|
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
| 11 |
|
|
* All rights reserved.
|
| 12 |
c0411930
|
Stephen Beaver
|
*
|
| 13 |
b12ea3fb
|
Renato Botelho
|
* 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 |
c0411930
|
Stephen Beaver
|
*
|
| 17 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
| 18 |
c0411930
|
Stephen Beaver
|
*
|
| 19 |
b12ea3fb
|
Renato Botelho
|
* 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 |
c0411930
|
Stephen Beaver
|
*/
|
| 25 |
5b237745
|
Scott Ullrich
|
|
| 26 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
| 27 |
|
|
##|*IDENT=page-system-staticroutes
|
| 28 |
5230f468
|
jim-p
|
##|*NAME=System: Static Routes
|
| 29 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'System: Static Routes' page.
|
| 30 |
|
|
##|*MATCH=system_routes.php*
|
| 31 |
|
|
##|-PRIV
|
| 32 |
|
|
|
| 33 |
c81ef6e2
|
Phil Davis
|
require_once("guiconfig.inc");
|
| 34 |
7a927e67
|
Scott Ullrich
|
require_once("functions.inc");
|
| 35 |
|
|
require_once("filter.inc");
|
| 36 |
|
|
require_once("shaper.inc");
|
| 37 |
5b237745
|
Scott Ullrich
|
|
| 38 |
d38bd840
|
Phil Davis
|
if (!is_array($config['staticroutes']['route'])) {
|
| 39 |
5b237745
|
Scott Ullrich
|
$config['staticroutes']['route'] = array();
|
| 40 |
d38bd840
|
Phil Davis
|
}
|
| 41 |
5b237745
|
Scott Ullrich
|
|
| 42 |
|
|
$a_routes = &$config['staticroutes']['route'];
|
| 43 |
70cb0375
|
Renato Botelho
|
$a_gateways = return_gateways_array(true, true, true);
|
| 44 |
|
|
$changedesc_prefix = gettext("Static Routes") . ": ";
|
| 45 |
028ff8f8
|
Phil Davis
|
unset($input_errors);
|
| 46 |
5b237745
|
Scott Ullrich
|
|
| 47 |
|
|
if ($_POST) {
|
| 48 |
|
|
|
| 49 |
|
|
$pconfig = $_POST;
|
| 50 |
|
|
|
| 51 |
|
|
if ($_POST['apply']) {
|
| 52 |
691dade5
|
Scott Ullrich
|
|
| 53 |
5b237745
|
Scott Ullrich
|
$retval = 0;
|
| 54 |
3851094f
|
Scott Ullrich
|
|
| 55 |
e8471084
|
Ermal
|
if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
|
| 56 |
bfe407e5
|
Warren Baker
|
$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
|
| 57 |
d38bd840
|
Phil Davis
|
foreach ($toapplylist as $toapply) {
|
| 58 |
e8471084
|
Ermal
|
mwexec("{$toapply}");
|
| 59 |
d38bd840
|
Phil Davis
|
}
|
| 60 |
966780ad
|
Renato Botelho
|
|
| 61 |
e8471084
|
Ermal
|
@unlink("{$g['tmp_path']}/.system_routes.apply");
|
| 62 |
|
|
}
|
| 63 |
|
|
|
| 64 |
3851094f
|
Scott Ullrich
|
$retval = system_routing_configure();
|
| 65 |
|
|
$retval |= filter_configure();
|
| 66 |
13bbe450
|
Seth Mos
|
/* reconfigure our gateway monitor */
|
| 67 |
|
|
setup_gateways_monitor();
|
| 68 |
3851094f
|
Scott Ullrich
|
|
| 69 |
5b237745
|
Scott Ullrich
|
$savemsg = get_std_save_message($retval);
|
| 70 |
d38bd840
|
Phil Davis
|
if ($retval == 0) {
|
| 71 |
a368a026
|
Ermal Lu?i
|
clear_subsystem_dirty('staticroutes');
|
| 72 |
d38bd840
|
Phil Davis
|
}
|
| 73 |
5b237745
|
Scott Ullrich
|
}
|
| 74 |
|
|
}
|
| 75 |
|
|
|
| 76 |
70cb0375
|
Renato Botelho
|
function delete_static_route($id) {
|
| 77 |
|
|
global $config, $a_routes, $changedesc_prefix;
|
| 78 |
|
|
|
| 79 |
d38bd840
|
Phil Davis
|
if (!isset($a_routes[$id])) {
|
| 80 |
70cb0375
|
Renato Botelho
|
return;
|
| 81 |
d38bd840
|
Phil Davis
|
}
|
| 82 |
70cb0375
|
Renato Botelho
|
|
| 83 |
|
|
$targets = array();
|
| 84 |
|
|
if (is_alias($a_routes[$id]['network'])) {
|
| 85 |
|
|
foreach (filter_expand_alias_array($a_routes[$id]['network']) as $tgt) {
|
| 86 |
d38bd840
|
Phil Davis
|
if (is_ipaddrv4($tgt)) {
|
| 87 |
70cb0375
|
Renato Botelho
|
$tgt .= "/32";
|
| 88 |
d38bd840
|
Phil Davis
|
} else if (is_ipaddrv6($tgt)) {
|
| 89 |
70cb0375
|
Renato Botelho
|
$tgt .= "/128";
|
| 90 |
d38bd840
|
Phil Davis
|
}
|
| 91 |
|
|
if (!is_subnet($tgt)) {
|
| 92 |
70cb0375
|
Renato Botelho
|
continue;
|
| 93 |
d38bd840
|
Phil Davis
|
}
|
| 94 |
70cb0375
|
Renato Botelho
|
$targets[] = $tgt;
|
| 95 |
|
|
}
|
| 96 |
|
|
} else {
|
| 97 |
|
|
$targets[] = $a_routes[$id]['network'];
|
| 98 |
|
|
}
|
| 99 |
|
|
|
| 100 |
|
|
foreach ($targets as $tgt) {
|
| 101 |
|
|
$family = (is_subnetv6($tgt) ? "-inet6" : "-inet");
|
| 102 |
|
|
mwexec("/sbin/route delete {$family} " . escapeshellarg($tgt));
|
| 103 |
|
|
}
|
| 104 |
|
|
|
| 105 |
|
|
unset($targets);
|
| 106 |
|
|
}
|
| 107 |
|
|
|
| 108 |
5b237745
|
Scott Ullrich
|
if ($_GET['act'] == "del") {
|
| 109 |
|
|
if ($a_routes[$_GET['id']]) {
|
| 110 |
762faef5
|
Phil Davis
|
$changedesc = $changedesc_prefix . sprintf(gettext("removed route to %s"), $a_routes[$_GET['id']]['network']);
|
| 111 |
70cb0375
|
Renato Botelho
|
delete_static_route($_GET['id']);
|
| 112 |
|
|
unset($a_routes[$_GET['id']]);
|
| 113 |
|
|
write_config($changedesc);
|
| 114 |
|
|
header("Location: system_routes.php");
|
| 115 |
|
|
exit;
|
| 116 |
|
|
}
|
| 117 |
|
|
}
|
| 118 |
|
|
|
| 119 |
|
|
if (isset($_POST['del_x'])) {
|
| 120 |
|
|
/* delete selected routes */
|
| 121 |
|
|
if (is_array($_POST['route']) && count($_POST['route'])) {
|
| 122 |
762faef5
|
Phil Davis
|
$deleted_routes = "";
|
| 123 |
70cb0375
|
Renato Botelho
|
foreach ($_POST['route'] as $routei) {
|
| 124 |
762faef5
|
Phil Davis
|
$deleted_routes .= " " . $a_routes[$routei]['network'];
|
| 125 |
70cb0375
|
Renato Botelho
|
delete_static_route($routei);
|
| 126 |
|
|
unset($a_routes[$routei]);
|
| 127 |
|
|
}
|
| 128 |
762faef5
|
Phil Davis
|
$changedesc = $changedesc_prefix . sprintf(gettext("removed route to%s"), $deleted_routes);
|
| 129 |
70cb0375
|
Renato Botelho
|
write_config($changedesc);
|
| 130 |
|
|
header("Location: system_routes.php");
|
| 131 |
|
|
exit;
|
| 132 |
|
|
}
|
| 133 |
|
|
|
| 134 |
|
|
} else if ($_GET['act'] == "toggle") {
|
| 135 |
|
|
if ($a_routes[$_GET['id']]) {
|
| 136 |
028ff8f8
|
Phil Davis
|
$do_update_config = true;
|
| 137 |
d38bd840
|
Phil Davis
|
if (isset($a_routes[$_GET['id']]['disabled'])) {
|
| 138 |
028ff8f8
|
Phil Davis
|
// Do not enable a route whose gateway is disabled
|
| 139 |
|
|
if (isset($a_gateways[$a_routes[$_GET['id']]['gateway']]['disabled'])) {
|
| 140 |
|
|
$do_update_config = false;
|
| 141 |
762faef5
|
Phil Davis
|
$input_errors[] = $changedesc_prefix . sprintf(gettext("gateway is disabled, cannot enable route to %s"), $a_routes[$_GET['id']]['network']);
|
| 142 |
028ff8f8
|
Phil Davis
|
} else {
|
| 143 |
|
|
unset($a_routes[$_GET['id']]['disabled']);
|
| 144 |
762faef5
|
Phil Davis
|
$changedesc = $changedesc_prefix . sprintf(gettext("enabled route to %s"), $a_routes[$_GET['id']]['network']);
|
| 145 |
028ff8f8
|
Phil Davis
|
}
|
| 146 |
25c3f30c
|
Renato Botelho
|
} else {
|
| 147 |
70cb0375
|
Renato Botelho
|
delete_static_route($_GET['id']);
|
| 148 |
|
|
$a_routes[$_GET['id']]['disabled'] = true;
|
| 149 |
762faef5
|
Phil Davis
|
$changedesc = $changedesc_prefix . sprintf(gettext("disabled route to %s"), $a_routes[$_GET['id']]['network']);
|
| 150 |
9c115b40
|
Ermal
|
}
|
| 151 |
25c3f30c
|
Renato Botelho
|
|
| 152 |
028ff8f8
|
Phil Davis
|
if ($do_update_config) {
|
| 153 |
|
|
if (write_config($changedesc)) {
|
| 154 |
|
|
mark_subsystem_dirty('staticroutes');
|
| 155 |
|
|
}
|
| 156 |
|
|
header("Location: system_routes.php");
|
| 157 |
|
|
exit;
|
| 158 |
d38bd840
|
Phil Davis
|
}
|
| 159 |
70cb0375
|
Renato Botelho
|
}
|
| 160 |
|
|
} else {
|
| 161 |
|
|
/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
|
| 162 |
|
|
unset($movebtn);
|
| 163 |
|
|
foreach ($_POST as $pn => $pd) {
|
| 164 |
|
|
if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
|
| 165 |
|
|
$movebtn = $matches[1];
|
| 166 |
|
|
break;
|
| 167 |
25c3f30c
|
Renato Botelho
|
}
|
| 168 |
70cb0375
|
Renato Botelho
|
}
|
| 169 |
|
|
/* move selected routes before this route */
|
| 170 |
|
|
if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
|
| 171 |
|
|
$a_routes_new = array();
|
| 172 |
25c3f30c
|
Renato Botelho
|
|
| 173 |
70cb0375
|
Renato Botelho
|
/* copy all routes < $movebtn and not selected */
|
| 174 |
|
|
for ($i = 0; $i < $movebtn; $i++) {
|
| 175 |
d38bd840
|
Phil Davis
|
if (!in_array($i, $_POST['route'])) {
|
| 176 |
70cb0375
|
Renato Botelho
|
$a_routes_new[] = $a_routes[$i];
|
| 177 |
d38bd840
|
Phil Davis
|
}
|
| 178 |
70cb0375
|
Renato Botelho
|
}
|
| 179 |
|
|
|
| 180 |
|
|
/* copy all selected routes */
|
| 181 |
|
|
for ($i = 0; $i < count($a_routes); $i++) {
|
| 182 |
d38bd840
|
Phil Davis
|
if ($i == $movebtn) {
|
| 183 |
70cb0375
|
Renato Botelho
|
continue;
|
| 184 |
d38bd840
|
Phil Davis
|
}
|
| 185 |
|
|
if (in_array($i, $_POST['route'])) {
|
| 186 |
70cb0375
|
Renato Botelho
|
$a_routes_new[] = $a_routes[$i];
|
| 187 |
d38bd840
|
Phil Davis
|
}
|
| 188 |
70cb0375
|
Renato Botelho
|
}
|
| 189 |
|
|
|
| 190 |
|
|
/* copy $movebtn route */
|
| 191 |
d38bd840
|
Phil Davis
|
if ($movebtn < count($a_routes)) {
|
| 192 |
70cb0375
|
Renato Botelho
|
$a_routes_new[] = $a_routes[$movebtn];
|
| 193 |
d38bd840
|
Phil Davis
|
}
|
| 194 |
70cb0375
|
Renato Botelho
|
|
| 195 |
|
|
/* copy all routes > $movebtn and not selected */
|
| 196 |
|
|
for ($i = $movebtn+1; $i < count($a_routes); $i++) {
|
| 197 |
d38bd840
|
Phil Davis
|
if (!in_array($i, $_POST['route'])) {
|
| 198 |
70cb0375
|
Renato Botelho
|
$a_routes_new[] = $a_routes[$i];
|
| 199 |
d38bd840
|
Phil Davis
|
}
|
| 200 |
70cb0375
|
Renato Botelho
|
}
|
| 201 |
d38bd840
|
Phil Davis
|
if (count($a_routes_new) > 0) {
|
| 202 |
70cb0375
|
Renato Botelho
|
$a_routes = $a_routes_new;
|
| 203 |
d38bd840
|
Phil Davis
|
}
|
| 204 |
70cb0375
|
Renato Botelho
|
|
| 205 |
d38bd840
|
Phil Davis
|
if (write_config()) {
|
| 206 |
70cb0375
|
Renato Botelho
|
mark_subsystem_dirty('staticroutes');
|
| 207 |
d38bd840
|
Phil Davis
|
}
|
| 208 |
25c3f30c
|
Renato Botelho
|
header("Location: system_routes.php");
|
| 209 |
|
|
exit;
|
| 210 |
5b237745
|
Scott Ullrich
|
}
|
| 211 |
|
|
}
|
| 212 |
7f43ca88
|
Scott Ullrich
|
|
| 213 |
d036bc07
|
Stephen Beaver
|
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Static Routes"));
|
| 214 |
b32dd0a6
|
jim-p
|
$shortcut_section = "routing";
|
| 215 |
02ca24c9
|
jim-p
|
|
| 216 |
7f43ca88
|
Scott Ullrich
|
include("head.inc");
|
| 217 |
|
|
|
| 218 |
d61309a0
|
Phil Davis
|
if ($input_errors) {
|
| 219 |
f3bb71cf
|
Sjon Hortensius
|
print_input_errors($input_errors);
|
| 220 |
d61309a0
|
Phil Davis
|
}
|
| 221 |
|
|
if ($savemsg) {
|
| 222 |
f78bbe16
|
Phil Davis
|
print_info_box($savemsg, 'success');
|
| 223 |
d61309a0
|
Phil Davis
|
}
|
| 224 |
|
|
if (is_subsystem_dirty('staticroutes')) {
|
| 225 |
813c6673
|
NOYB
|
print_apply_box(gettext("The static route configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
|
| 226 |
d61309a0
|
Phil Davis
|
}
|
| 227 |
f3bb71cf
|
Sjon Hortensius
|
|
| 228 |
|
|
$tab_array = array();
|
| 229 |
|
|
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
|
| 230 |
c14798d0
|
heper
|
$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 |
f3bb71cf
|
Sjon Hortensius
|
display_top_tabs($tab_array);
|
| 233 |
0f282d7a
|
Scott Ullrich
|
|
| 234 |
f3bb71cf
|
Sjon Hortensius
|
?>
|
| 235 |
060ed238
|
Stephen Beaver
|
<div class="panel panel-default">
|
| 236 |
70dc5cd6
|
Phil Davis
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Static Routes')?></h2></div>
|
| 237 |
060ed238
|
Stephen Beaver
|
<div class="panel-body">
|
| 238 |
|
|
<div class="table-responsive">
|
| 239 |
1c10ce97
|
PiBa-NL
|
<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
|
| 240 |
060ed238
|
Stephen Beaver
|
<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 |
70cb0375
|
Renato Botelho
|
<?php
|
| 252 |
f3bb71cf
|
Sjon Hortensius
|
foreach ($a_routes as $i => $route):
|
| 253 |
d61309a0
|
Phil Davis
|
if (isset($route['disabled'])) {
|
| 254 |
1b7379f9
|
Jared Dillard
|
$icon = 'fa-ban';
|
| 255 |
d61309a0
|
Phil Davis
|
} else {
|
| 256 |
1b7379f9
|
Jared Dillard
|
$icon = 'fa-check-circle-o';
|
| 257 |
d61309a0
|
Phil Davis
|
}
|
| 258 |
70cb0375
|
Renato Botelho
|
?>
|
| 259 |
060ed238
|
Stephen Beaver
|
<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 |
4bfdf0be
|
Phil Davis
|
<a href="system_routes_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit route')?>"></a>
|
| 275 |
060ed238
|
Stephen Beaver
|
|
| 276 |
4bfdf0be
|
Phil Davis
|
<a href="system_routes_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy route')?>"></a>
|
| 277 |
060ed238
|
Stephen Beaver
|
|
| 278 |
|
|
<?php if (isset($route['disabled'])) {
|
| 279 |
|
|
?>
|
| 280 |
4bfdf0be
|
Phil Davis
|
<a href="?act=toggle&id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable route')?>"></a>
|
| 281 |
060ed238
|
Stephen Beaver
|
<?php } else {
|
| 282 |
|
|
?>
|
| 283 |
4bfdf0be
|
Phil Davis
|
<a href="?act=toggle&id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable route')?>"></a>
|
| 284 |
060ed238
|
Stephen Beaver
|
<?php }
|
| 285 |
|
|
?>
|
| 286 |
4bfdf0be
|
Phil Davis
|
<a href="system_routes.php?act=del&id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete route')?>"></a>
|
| 287 |
060ed238
|
Stephen Beaver
|
|
| 288 |
|
|
</td>
|
| 289 |
|
|
</tr>
|
| 290 |
fa172bc5
|
NewEraCracker
|
<?php endforeach; ?>
|
| 291 |
060ed238
|
Stephen Beaver
|
</table>
|
| 292 |
|
|
</div>
|
| 293 |
|
|
</div>
|
| 294 |
|
|
</div>
|
| 295 |
f3bb71cf
|
Sjon Hortensius
|
|
| 296 |
c10cb196
|
Stephen Beaver
|
<nav class="action-buttons">
|
| 297 |
f74457df
|
Stephen Beaver
|
<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
|
| 298 |
9d5a20cf
|
heper
|
<i class="fa fa-plus icon-embed-btn"></i>
|
| 299 |
f74457df
|
Stephen Beaver
|
<?=gettext("Add")?>
|
| 300 |
f3bb71cf
|
Sjon Hortensius
|
</a>
|
| 301 |
|
|
</nav>
|
| 302 |
|
|
<?php
|
| 303 |
|
|
|
| 304 |
5d339e8e
|
heper
|
include("foot.inc");
|