Project

General

Profile

Download (8.69 KB) Statistics
| Branch: | Tag: | Revision:
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 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 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 ddd3ffaf Steve Beaver
if ($_POST['apply']) {
48 5b237745 Scott Ullrich
	$pconfig = $_POST;
49 ddd3ffaf Steve Beaver
	$retval = 0;
50 5b237745 Scott Ullrich
51 ddd3ffaf Steve Beaver
	if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
52
		$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
53
		foreach ($toapplylist as $toapply) {
54
			mwexec("{$toapply}");
55 e8471084 Ermal
		}
56
57 ddd3ffaf Steve Beaver
		@unlink("{$g['tmp_path']}/.system_routes.apply");
58
	}
59
60
	$retval |= system_routing_configure();
61
	$retval |= filter_configure();
62
	/* reconfigure our gateway monitor */
63
	setup_gateways_monitor();
64 3851094f Scott Ullrich
65 ddd3ffaf Steve Beaver
	if ($retval == 0) {
66
		clear_subsystem_dirty('staticroutes');
67 5b237745 Scott Ullrich
	}
68
}
69
70 70cb0375 Renato Botelho
function delete_static_route($id) {
71
	global $config, $a_routes, $changedesc_prefix;
72
73 d38bd840 Phil Davis
	if (!isset($a_routes[$id])) {
74 70cb0375 Renato Botelho
		return;
75 d38bd840 Phil Davis
	}
76 70cb0375 Renato Botelho
77
	$targets = array();
78
	if (is_alias($a_routes[$id]['network'])) {
79
		foreach (filter_expand_alias_array($a_routes[$id]['network']) as $tgt) {
80 d38bd840 Phil Davis
			if (is_ipaddrv4($tgt)) {
81 70cb0375 Renato Botelho
				$tgt .= "/32";
82 d38bd840 Phil Davis
			} else if (is_ipaddrv6($tgt)) {
83 70cb0375 Renato Botelho
				$tgt .= "/128";
84 d38bd840 Phil Davis
			}
85
			if (!is_subnet($tgt)) {
86 70cb0375 Renato Botelho
				continue;
87 d38bd840 Phil Davis
			}
88 70cb0375 Renato Botelho
			$targets[] = $tgt;
89
		}
90
	} else {
91
		$targets[] = $a_routes[$id]['network'];
92
	}
93
94
	foreach ($targets as $tgt) {
95
		$family = (is_subnetv6($tgt) ? "-inet6" : "-inet");
96
		mwexec("/sbin/route delete {$family} " . escapeshellarg($tgt));
97
	}
98
99
	unset($targets);
100
}
101
102 ddd3ffaf Steve Beaver
if ($_POST['act'] == "del") {
103
	if ($a_routes[$_POST['id']]) {
104
		$changedesc = $changedesc_prefix . sprintf(gettext("removed route to %s"), $a_routes[$_POST['id']]['network']);
105
		delete_static_route($_POST['id']);
106
		unset($a_routes[$_POST['id']]);
107 70cb0375 Renato Botelho
		write_config($changedesc);
108
		header("Location: system_routes.php");
109
		exit;
110
	}
111
}
112
113
if (isset($_POST['del_x'])) {
114
	/* delete selected routes */
115
	if (is_array($_POST['route']) && count($_POST['route'])) {
116 762faef5 Phil Davis
		$deleted_routes = "";
117 70cb0375 Renato Botelho
		foreach ($_POST['route'] as $routei) {
118 762faef5 Phil Davis
			$deleted_routes .= " " . $a_routes[$routei]['network'];
119 70cb0375 Renato Botelho
			delete_static_route($routei);
120
			unset($a_routes[$routei]);
121
		}
122 762faef5 Phil Davis
		$changedesc = $changedesc_prefix . sprintf(gettext("removed route to%s"), $deleted_routes);
123 70cb0375 Renato Botelho
		write_config($changedesc);
124
		header("Location: system_routes.php");
125
		exit;
126
	}
127
128 4611e283 Steve Beaver
}
129
130
if ($_POST['act'] == "toggle") {
131 ddd3ffaf Steve Beaver
	if ($a_routes[$_POST['id']]) {
132 028ff8f8 Phil Davis
		$do_update_config = true;
133 ddd3ffaf Steve Beaver
		if (isset($a_routes[$_POST['id']]['disabled'])) {
134 028ff8f8 Phil Davis
			// Do not enable a route whose gateway is disabled
135 ddd3ffaf Steve Beaver
			if (isset($a_gateways[$a_routes[$_POST['id']]['gateway']]['disabled'])) {
136 028ff8f8 Phil Davis
				$do_update_config = false;
137 ddd3ffaf Steve Beaver
				$input_errors[] = $changedesc_prefix . sprintf(gettext("gateway is disabled, cannot enable route to %s"), $a_routes[$_POST['id']]['network']);
138 028ff8f8 Phil Davis
			} else {
139 ddd3ffaf Steve Beaver
				unset($a_routes[$_POST['id']]['disabled']);
140
				$changedesc = $changedesc_prefix . sprintf(gettext("enabled route to %s"), $a_routes[$_POST['id']]['network']);
141 028ff8f8 Phil Davis
			}
142 25c3f30c Renato Botelho
		} else {
143 ddd3ffaf Steve Beaver
			delete_static_route($_POST['id']);
144
			$a_routes[$_POST['id']]['disabled'] = true;
145
			$changedesc = $changedesc_prefix . sprintf(gettext("disabled route to %s"), $a_routes[$_POST['id']]['network']);
146 9c115b40 Ermal
		}
147 25c3f30c Renato Botelho
148 028ff8f8 Phil Davis
		if ($do_update_config) {
149
			if (write_config($changedesc)) {
150
				mark_subsystem_dirty('staticroutes');
151
			}
152
			header("Location: system_routes.php");
153
			exit;
154 d38bd840 Phil Davis
		}
155 70cb0375 Renato Botelho
	}
156 4611e283 Steve Beaver
}
157
158
if($_POST['save']) {
159 70cb0375 Renato Botelho
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
160
	unset($movebtn);
161
	foreach ($_POST as $pn => $pd) {
162
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
163
			$movebtn = $matches[1];
164
			break;
165 25c3f30c Renato Botelho
		}
166 70cb0375 Renato Botelho
	}
167
	/* move selected routes before this route */
168
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
169
		$a_routes_new = array();
170 25c3f30c Renato Botelho
171 70cb0375 Renato Botelho
		/* copy all routes < $movebtn and not selected */
172
		for ($i = 0; $i < $movebtn; $i++) {
173 d38bd840 Phil Davis
			if (!in_array($i, $_POST['route'])) {
174 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
175 d38bd840 Phil Davis
			}
176 70cb0375 Renato Botelho
		}
177
178
		/* copy all selected routes */
179
		for ($i = 0; $i < count($a_routes); $i++) {
180 d38bd840 Phil Davis
			if ($i == $movebtn) {
181 70cb0375 Renato Botelho
				continue;
182 d38bd840 Phil Davis
			}
183
			if (in_array($i, $_POST['route'])) {
184 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
185 d38bd840 Phil Davis
			}
186 70cb0375 Renato Botelho
		}
187
188
		/* copy $movebtn route */
189 d38bd840 Phil Davis
		if ($movebtn < count($a_routes)) {
190 70cb0375 Renato Botelho
			$a_routes_new[] = $a_routes[$movebtn];
191 d38bd840 Phil Davis
		}
192 70cb0375 Renato Botelho
193
		/* copy all routes > $movebtn and not selected */
194
		for ($i = $movebtn+1; $i < count($a_routes); $i++) {
195 d38bd840 Phil Davis
			if (!in_array($i, $_POST['route'])) {
196 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
197 d38bd840 Phil Davis
			}
198 70cb0375 Renato Botelho
		}
199 d38bd840 Phil Davis
		if (count($a_routes_new) > 0) {
200 70cb0375 Renato Botelho
			$a_routes = $a_routes_new;
201 d38bd840 Phil Davis
		}
202 70cb0375 Renato Botelho
203 b290e10e doktornotor
		if (write_config(gettext("Saved static routes configuration."))) {
204 70cb0375 Renato Botelho
			mark_subsystem_dirty('staticroutes');
205 d38bd840 Phil Davis
		}
206 25c3f30c Renato Botelho
		header("Location: system_routes.php");
207
		exit;
208 5b237745 Scott Ullrich
	}
209
}
210 7f43ca88 Scott Ullrich
211 d036bc07 Stephen Beaver
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Static Routes"));
212 edcd7535 Phil Davis
$pglinks = array("", "system_gateways.php", "@self");
213 b32dd0a6 jim-p
$shortcut_section = "routing";
214 02ca24c9 jim-p
215 7f43ca88 Scott Ullrich
include("head.inc");
216
217 d61309a0 Phil Davis
if ($input_errors) {
218 f3bb71cf Sjon Hortensius
	print_input_errors($input_errors);
219 d61309a0 Phil Davis
}
220 44c42356 Phil Davis
if ($_POST['apply']) {
221
	print_apply_result_box($retval);
222 d61309a0 Phil Davis
}
223
if (is_subsystem_dirty('staticroutes')) {
224 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."));
225 d61309a0 Phil Davis
}
226 f3bb71cf Sjon Hortensius
227
$tab_array = array();
228
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
229 c14798d0 heper
$tab_array[1] = array(gettext("Static Routes"), true, "system_routes.php");
230
$tab_array[2] = array(gettext("Gateway Groups"), false, "system_gateway_groups.php");
231 f3bb71cf Sjon Hortensius
display_top_tabs($tab_array);
232 0f282d7a Scott Ullrich
233 f3bb71cf Sjon Hortensius
?>
234 060ed238 Stephen Beaver
<div class="panel panel-default">
235 70dc5cd6 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Static Routes')?></h2></div>
236 060ed238 Stephen Beaver
	<div class="panel-body">
237
		<div class="table-responsive">
238 1c10ce97 PiBa-NL
			<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
239 060ed238 Stephen Beaver
				<thead>
240
					<tr>
241
						<th></th>
242
						<th><?=gettext("Network")?></th>
243
						<th><?=gettext("Gateway")?></th>
244
						<th><?=gettext("Interface")?></th>
245
						<th><?=gettext("Description")?></th>
246
						<th><?=gettext("Actions")?></th>
247
					</tr>
248
				</thead>
249
				<tbody>
250 70cb0375 Renato Botelho
<?php
251 f3bb71cf Sjon Hortensius
foreach ($a_routes as $i => $route):
252 d61309a0 Phil Davis
	if (isset($route['disabled'])) {
253 1b7379f9 Jared Dillard
		$icon = 'fa-ban';
254 d61309a0 Phil Davis
	} else {
255 1b7379f9 Jared Dillard
		$icon = 'fa-check-circle-o';
256 d61309a0 Phil Davis
	}
257 70cb0375 Renato Botelho
?>
258 060ed238 Stephen Beaver
				<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
259
					<td><i class="fa <?=$icon?>"></i></td>
260
					<td>
261
						<?=strtolower($route['network'])?>
262
					</td>
263
					<td>
264
						<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
265
					</td>
266
					<td>
267
						<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
268
					</td>
269
					<td>
270
						<?=htmlspecialchars($route['descr'])?>
271
					</td>
272
					<td>
273 4611e283 Steve Beaver
						<a href="system_routes_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit route')?>"></a>
274 060ed238 Stephen Beaver
275 4611e283 Steve Beaver
						<a href="system_routes_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy route')?>"></a>
276 060ed238 Stephen Beaver
277
				<?php if (isset($route['disabled'])) {
278
				?>
279 ddd3ffaf Steve Beaver
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable route')?>" usepost></a>
280 060ed238 Stephen Beaver
				<?php } else {
281
				?>
282 ddd3ffaf Steve Beaver
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable route')?>" usepost></a>
283 060ed238 Stephen Beaver
				<?php }
284
				?>
285 ddd3ffaf Steve Beaver
						<a href="system_routes.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete route')?>" usepost></a>
286 060ed238 Stephen Beaver
287
					</td>
288
				</tr>
289 fa172bc5 NewEraCracker
<?php endforeach; ?>
290 060ed238 Stephen Beaver
			</table>
291
		</div>
292
	</div>
293
</div>
294 f3bb71cf Sjon Hortensius
295 c10cb196 Stephen Beaver
<nav class="action-buttons">
296 4611e283 Steve Beaver
	<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
297 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
298 f74457df Stephen Beaver
		<?=gettext("Add")?>
299 f3bb71cf Sjon Hortensius
	</a>
300
</nav>
301
<?php
302
303 5d339e8e heper
include("foot.inc");