Project

General

Profile

Download (9.29 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 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f585441 Luiz Souza
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 c0411930 Stephen Beaver
 *
11 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14 c0411930 Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * 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 c0411930 Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
20 c0411930 Stephen Beaver
 *
21 b12ea3fb Renato Botelho
 * 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 c0411930 Stephen Beaver
 */
27 5b237745 Scott Ullrich
28 6b07c15a Matthew Grooms
##|+PRIV
29
##|*IDENT=page-system-staticroutes
30 5230f468 jim-p
##|*NAME=System: Static Routes
31 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'System: Static Routes' page.
32
##|*MATCH=system_routes.php*
33
##|-PRIV
34
35 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
36 7a927e67 Scott Ullrich
require_once("functions.inc");
37
require_once("filter.inc");
38
require_once("shaper.inc");
39 5b237745 Scott Ullrich
40 c6c398c6 jim-p
init_config_arr(array('staticroutes', 'route'));
41 5b237745 Scott Ullrich
$a_routes = &$config['staticroutes']['route'];
42 70cb0375 Renato Botelho
$a_gateways = return_gateways_array(true, true, true);
43
$changedesc_prefix = gettext("Static Routes") . ": ";
44 028ff8f8 Phil Davis
unset($input_errors);
45 5b237745 Scott Ullrich
46 ddd3ffaf Steve Beaver
if ($_POST['apply']) {
47 5b237745 Scott Ullrich
	$pconfig = $_POST;
48 ddd3ffaf Steve Beaver
	$retval = 0;
49 5b237745 Scott Ullrich
50 ddd3ffaf Steve Beaver
	if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
51
		$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
52
		foreach ($toapplylist as $toapply) {
53
			mwexec("{$toapply}");
54 e8471084 Ermal
		}
55
56 ddd3ffaf Steve Beaver
		@unlink("{$g['tmp_path']}/.system_routes.apply");
57
	}
58
59
	$retval |= system_routing_configure();
60
	$retval |= filter_configure();
61
	/* reconfigure our gateway monitor */
62
	setup_gateways_monitor();
63 3851094f Scott Ullrich
64 ddd3ffaf Steve Beaver
	if ($retval == 0) {
65
		clear_subsystem_dirty('staticroutes');
66 5b237745 Scott Ullrich
	}
67
}
68
69 70cb0375 Renato Botelho
function delete_static_route($id) {
70 3e20d175 Viktor Gurov
	global $config, $a_routes, $changedesc_prefix, $a_gateways;
71 70cb0375 Renato Botelho
72 d38bd840 Phil Davis
	if (!isset($a_routes[$id])) {
73 70cb0375 Renato Botelho
		return;
74 d38bd840 Phil Davis
	}
75 70cb0375 Renato Botelho
76
	$targets = array();
77
	if (is_alias($a_routes[$id]['network'])) {
78 c428cdf4 Renato Botelho do Couto
		foreach (filter_expand_alias_array($a_routes[$id]['network']) as
79
		    $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 c428cdf4 Renato Botelho do Couto
		route_del($tgt);
96 70cb0375 Renato Botelho
	}
97
98
	unset($targets);
99
}
100
101 ddd3ffaf Steve Beaver
if ($_POST['act'] == "del") {
102
	if ($a_routes[$_POST['id']]) {
103
		$changedesc = $changedesc_prefix . sprintf(gettext("removed route to %s"), $a_routes[$_POST['id']]['network']);
104
		delete_static_route($_POST['id']);
105
		unset($a_routes[$_POST['id']]);
106 70cb0375 Renato Botelho
		write_config($changedesc);
107
		header("Location: system_routes.php");
108
		exit;
109
	}
110
}
111
112
if (isset($_POST['del_x'])) {
113
	/* delete selected routes */
114
	if (is_array($_POST['route']) && count($_POST['route'])) {
115 762faef5 Phil Davis
		$deleted_routes = "";
116 70cb0375 Renato Botelho
		foreach ($_POST['route'] as $routei) {
117 762faef5 Phil Davis
			$deleted_routes .= " " . $a_routes[$routei]['network'];
118 70cb0375 Renato Botelho
			delete_static_route($routei);
119
			unset($a_routes[$routei]);
120
		}
121 762faef5 Phil Davis
		$changedesc = $changedesc_prefix . sprintf(gettext("removed route to%s"), $deleted_routes);
122 70cb0375 Renato Botelho
		write_config($changedesc);
123
		header("Location: system_routes.php");
124
		exit;
125
	}
126
127 4611e283 Steve Beaver
}
128
129
if ($_POST['act'] == "toggle") {
130 ddd3ffaf Steve Beaver
	if ($a_routes[$_POST['id']]) {
131 028ff8f8 Phil Davis
		$do_update_config = true;
132 ddd3ffaf Steve Beaver
		if (isset($a_routes[$_POST['id']]['disabled'])) {
133 028ff8f8 Phil Davis
			// Do not enable a route whose gateway is disabled
134 ddd3ffaf Steve Beaver
			if (isset($a_gateways[$a_routes[$_POST['id']]['gateway']]['disabled'])) {
135 028ff8f8 Phil Davis
				$do_update_config = false;
136 ddd3ffaf Steve Beaver
				$input_errors[] = $changedesc_prefix . sprintf(gettext("gateway is disabled, cannot enable route to %s"), $a_routes[$_POST['id']]['network']);
137 028ff8f8 Phil Davis
			} else {
138 ddd3ffaf Steve Beaver
				unset($a_routes[$_POST['id']]['disabled']);
139
				$changedesc = $changedesc_prefix . sprintf(gettext("enabled route to %s"), $a_routes[$_POST['id']]['network']);
140 028ff8f8 Phil Davis
			}
141 25c3f30c Renato Botelho
		} else {
142 ddd3ffaf Steve Beaver
			delete_static_route($_POST['id']);
143
			$a_routes[$_POST['id']]['disabled'] = true;
144
			$changedesc = $changedesc_prefix . sprintf(gettext("disabled route to %s"), $a_routes[$_POST['id']]['network']);
145 9c115b40 Ermal
		}
146 25c3f30c Renato Botelho
147 028ff8f8 Phil Davis
		if ($do_update_config) {
148
			if (write_config($changedesc)) {
149
				mark_subsystem_dirty('staticroutes');
150
			}
151
			header("Location: system_routes.php");
152
			exit;
153 d38bd840 Phil Davis
		}
154 70cb0375 Renato Botelho
	}
155 4611e283 Steve Beaver
}
156
157
if($_POST['save']) {
158 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... */
159
	unset($movebtn);
160
	foreach ($_POST as $pn => $pd) {
161
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
162
			$movebtn = $matches[1];
163
			break;
164 25c3f30c Renato Botelho
		}
165 70cb0375 Renato Botelho
	}
166
	/* move selected routes before this route */
167
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
168
		$a_routes_new = array();
169 25c3f30c Renato Botelho
170 70cb0375 Renato Botelho
		/* copy all routes < $movebtn and not selected */
171
		for ($i = 0; $i < $movebtn; $i++) {
172 d38bd840 Phil Davis
			if (!in_array($i, $_POST['route'])) {
173 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
174 d38bd840 Phil Davis
			}
175 70cb0375 Renato Botelho
		}
176
177
		/* copy all selected routes */
178
		for ($i = 0; $i < count($a_routes); $i++) {
179 d38bd840 Phil Davis
			if ($i == $movebtn) {
180 70cb0375 Renato Botelho
				continue;
181 d38bd840 Phil Davis
			}
182
			if (in_array($i, $_POST['route'])) {
183 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
184 d38bd840 Phil Davis
			}
185 70cb0375 Renato Botelho
		}
186
187
		/* copy $movebtn route */
188 d38bd840 Phil Davis
		if ($movebtn < count($a_routes)) {
189 70cb0375 Renato Botelho
			$a_routes_new[] = $a_routes[$movebtn];
190 d38bd840 Phil Davis
		}
191 70cb0375 Renato Botelho
192
		/* copy all routes > $movebtn and not selected */
193
		for ($i = $movebtn+1; $i < count($a_routes); $i++) {
194 d38bd840 Phil Davis
			if (!in_array($i, $_POST['route'])) {
195 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
196 d38bd840 Phil Davis
			}
197 70cb0375 Renato Botelho
		}
198 d38bd840 Phil Davis
		if (count($a_routes_new) > 0) {
199 70cb0375 Renato Botelho
			$a_routes = $a_routes_new;
200 d38bd840 Phil Davis
		}
201 70cb0375 Renato Botelho
202 b290e10e doktornotor
		if (write_config(gettext("Saved static routes configuration."))) {
203 70cb0375 Renato Botelho
			mark_subsystem_dirty('staticroutes');
204 d38bd840 Phil Davis
		}
205 25c3f30c Renato Botelho
		header("Location: system_routes.php");
206
		exit;
207 5b237745 Scott Ullrich
	}
208
}
209 7f43ca88 Scott Ullrich
210 d036bc07 Stephen Beaver
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Static Routes"));
211 edcd7535 Phil Davis
$pglinks = array("", "system_gateways.php", "@self");
212 b32dd0a6 jim-p
$shortcut_section = "routing";
213 02ca24c9 jim-p
214 7f43ca88 Scott Ullrich
include("head.inc");
215
216 d61309a0 Phil Davis
if ($input_errors) {
217 f3bb71cf Sjon Hortensius
	print_input_errors($input_errors);
218 d61309a0 Phil Davis
}
219 44c42356 Phil Davis
if ($_POST['apply']) {
220
	print_apply_result_box($retval);
221 d61309a0 Phil Davis
}
222
if (is_subsystem_dirty('staticroutes')) {
223 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."));
224 d61309a0 Phil Davis
}
225 f3bb71cf Sjon Hortensius
226
$tab_array = array();
227
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
228 c14798d0 heper
$tab_array[1] = array(gettext("Static Routes"), true, "system_routes.php");
229
$tab_array[2] = array(gettext("Gateway Groups"), false, "system_gateway_groups.php");
230 f3bb71cf Sjon Hortensius
display_top_tabs($tab_array);
231 0f282d7a Scott Ullrich
232 f3bb71cf Sjon Hortensius
?>
233 060ed238 Stephen Beaver
<div class="panel panel-default">
234 70dc5cd6 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Static Routes')?></h2></div>
235 060ed238 Stephen Beaver
	<div class="panel-body">
236
		<div class="table-responsive">
237 1c10ce97 PiBa-NL
			<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
238 060ed238 Stephen Beaver
				<thead>
239
					<tr>
240
						<th></th>
241
						<th><?=gettext("Network")?></th>
242
						<th><?=gettext("Gateway")?></th>
243
						<th><?=gettext("Interface")?></th>
244
						<th><?=gettext("Description")?></th>
245
						<th><?=gettext("Actions")?></th>
246
					</tr>
247
				</thead>
248
				<tbody>
249 70cb0375 Renato Botelho
<?php
250 f3bb71cf Sjon Hortensius
foreach ($a_routes as $i => $route):
251 6639718c Viktor G
	if (isset($a_gateways[$route['gateway']]['inactive'])) {
252
		$icon = 'fa-times-circle-o';
253
		$title = gettext("Route inactive, gateway interface is missing");
254
	} elseif (isset($route['disabled'])) {
255 1b7379f9 Jared Dillard
		$icon = 'fa-ban';
256 6639718c Viktor G
		$title = gettext("Route disabled");
257 d61309a0 Phil Davis
	} else {
258 1b7379f9 Jared Dillard
		$icon = 'fa-check-circle-o';
259 6639718c Viktor G
		$title = gettext("Route enabled");
260 d61309a0 Phil Davis
	}
261 70cb0375 Renato Botelho
?>
262 060ed238 Stephen Beaver
				<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
263 6639718c Viktor G
					<td title="<?=$title?>"><i class="fa <?=$icon?>"></i></td>
264 060ed238 Stephen Beaver
					<td>
265
						<?=strtolower($route['network'])?>
266
					</td>
267
					<td>
268
						<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
269
					</td>
270
					<td>
271
						<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
272
					</td>
273
					<td>
274
						<?=htmlspecialchars($route['descr'])?>
275
					</td>
276
					<td>
277 4611e283 Steve Beaver
						<a href="system_routes_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit route')?>"></a>
278 060ed238 Stephen Beaver
279 4611e283 Steve Beaver
						<a href="system_routes_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy route')?>"></a>
280 060ed238 Stephen Beaver
281
				<?php if (isset($route['disabled'])) {
282
				?>
283 ddd3ffaf Steve Beaver
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable route')?>" usepost></a>
284 060ed238 Stephen Beaver
				<?php } else {
285
				?>
286 ddd3ffaf Steve Beaver
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable route')?>" usepost></a>
287 060ed238 Stephen Beaver
				<?php }
288
				?>
289 ddd3ffaf Steve Beaver
						<a href="system_routes.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete route')?>" usepost></a>
290 060ed238 Stephen Beaver
291
					</td>
292
				</tr>
293 fa172bc5 NewEraCracker
<?php endforeach; ?>
294 060ed238 Stephen Beaver
			</table>
295
		</div>
296
	</div>
297
</div>
298 f3bb71cf Sjon Hortensius
299 c10cb196 Stephen Beaver
<nav class="action-buttons">
300 4611e283 Steve Beaver
	<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
301 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
302 f74457df Stephen Beaver
		<?=gettext("Add")?>
303 f3bb71cf Sjon Hortensius
	</a>
304
</nav>
305 6639718c Viktor G
<div class="infoblock">
306
<?php
307
print_info_box(
308
	sprintf(gettext('%1$s Route is inactive, gateway interface is missing'), '<br /><strong><i class="fa fa-times-circle-o"></i></strong>') .
309
	sprintf(gettext('%1$s Route disabled'), '<br /><strong><i class="fa fa-ban"></i></strong>') .
310
	sprintf(gettext('%1$s Route enabled'), '<br /><strong><i class="fa fa-check-circle-o"></i></strong>')
311
	);
312
?>
313
</div>
314 f3bb71cf Sjon Hortensius
<?php
315
316 5d339e8e heper
include("foot.inc");