Project

General

Profile

Download (10.3 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 4a5ac5e0 Phil Davis
/*
3
	system_routes.php
4
*/
5 c0411930 Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 191cb31d Stephen Beaver
 *
8 cb41dd63 Renato Botelho
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10 c0411930 Stephen Beaver
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13
 *
14
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16
 *
17
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21
 *
22
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31
 *
32
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *	====================================================================
56
 *
57
 */
58 5b237745 Scott Ullrich
59 6b07c15a Matthew Grooms
##|+PRIV
60
##|*IDENT=page-system-staticroutes
61 5230f468 jim-p
##|*NAME=System: Static Routes
62 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'System: Static Routes' page.
63
##|*MATCH=system_routes.php*
64
##|-PRIV
65
66 71d3c2f7 Phil Davis
require_once("guiconfig.inc");
67 7a927e67 Scott Ullrich
require_once("functions.inc");
68
require_once("filter.inc");
69
require_once("shaper.inc");
70 5b237745 Scott Ullrich
71 d38bd840 Phil Davis
if (!is_array($config['staticroutes']['route'])) {
72 5b237745 Scott Ullrich
	$config['staticroutes']['route'] = array();
73 d38bd840 Phil Davis
}
74 5b237745 Scott Ullrich
75
$a_routes = &$config['staticroutes']['route'];
76 70cb0375 Renato Botelho
$a_gateways = return_gateways_array(true, true, true);
77
$changedesc_prefix = gettext("Static Routes") . ": ";
78 028ff8f8 Phil Davis
unset($input_errors);
79 5b237745 Scott Ullrich
80
if ($_POST) {
81
82
	$pconfig = $_POST;
83
84
	if ($_POST['apply']) {
85 691dade5 Scott Ullrich
86 5b237745 Scott Ullrich
		$retval = 0;
87 3851094f Scott Ullrich
88 e8471084 Ermal
		if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
89 bfe407e5 Warren Baker
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
90 d38bd840 Phil Davis
			foreach ($toapplylist as $toapply) {
91 e8471084 Ermal
				mwexec("{$toapply}");
92 d38bd840 Phil Davis
			}
93 966780ad Renato Botelho
94 e8471084 Ermal
			@unlink("{$g['tmp_path']}/.system_routes.apply");
95
		}
96
97 3851094f Scott Ullrich
		$retval = system_routing_configure();
98
		$retval |= filter_configure();
99 13bbe450 Seth Mos
		/* reconfigure our gateway monitor */
100
		setup_gateways_monitor();
101 3851094f Scott Ullrich
102 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
103 d38bd840 Phil Davis
		if ($retval == 0) {
104 a368a026 Ermal Lu?i
			clear_subsystem_dirty('staticroutes');
105 d38bd840 Phil Davis
		}
106 5b237745 Scott Ullrich
	}
107
}
108
109 70cb0375 Renato Botelho
function delete_static_route($id) {
110
	global $config, $a_routes, $changedesc_prefix;
111
112 d38bd840 Phil Davis
	if (!isset($a_routes[$id])) {
113 70cb0375 Renato Botelho
		return;
114 d38bd840 Phil Davis
	}
115 70cb0375 Renato Botelho
116
	$targets = array();
117
	if (is_alias($a_routes[$id]['network'])) {
118
		foreach (filter_expand_alias_array($a_routes[$id]['network']) as $tgt) {
119 d38bd840 Phil Davis
			if (is_ipaddrv4($tgt)) {
120 70cb0375 Renato Botelho
				$tgt .= "/32";
121 d38bd840 Phil Davis
			} else if (is_ipaddrv6($tgt)) {
122 70cb0375 Renato Botelho
				$tgt .= "/128";
123 d38bd840 Phil Davis
			}
124
			if (!is_subnet($tgt)) {
125 70cb0375 Renato Botelho
				continue;
126 d38bd840 Phil Davis
			}
127 70cb0375 Renato Botelho
			$targets[] = $tgt;
128
		}
129
	} else {
130
		$targets[] = $a_routes[$id]['network'];
131
	}
132
133
	foreach ($targets as $tgt) {
134
		$family = (is_subnetv6($tgt) ? "-inet6" : "-inet");
135
		mwexec("/sbin/route delete {$family} " . escapeshellarg($tgt));
136
	}
137
138
	unset($targets);
139
}
140
141 5b237745 Scott Ullrich
if ($_GET['act'] == "del") {
142
	if ($a_routes[$_GET['id']]) {
143 762faef5 Phil Davis
		$changedesc = $changedesc_prefix . sprintf(gettext("removed route to %s"), $a_routes[$_GET['id']]['network']);
144 70cb0375 Renato Botelho
		delete_static_route($_GET['id']);
145
		unset($a_routes[$_GET['id']]);
146
		write_config($changedesc);
147
		header("Location: system_routes.php");
148
		exit;
149
	}
150
}
151
152
if (isset($_POST['del_x'])) {
153
	/* delete selected routes */
154
	if (is_array($_POST['route']) && count($_POST['route'])) {
155 762faef5 Phil Davis
		$deleted_routes = "";
156 70cb0375 Renato Botelho
		foreach ($_POST['route'] as $routei) {
157 762faef5 Phil Davis
			$deleted_routes .= " " . $a_routes[$routei]['network'];
158 70cb0375 Renato Botelho
			delete_static_route($routei);
159
			unset($a_routes[$routei]);
160
		}
161 762faef5 Phil Davis
		$changedesc = $changedesc_prefix . sprintf(gettext("removed route to%s"), $deleted_routes);
162 70cb0375 Renato Botelho
		write_config($changedesc);
163
		header("Location: system_routes.php");
164
		exit;
165
	}
166
167
} else if ($_GET['act'] == "toggle") {
168
	if ($a_routes[$_GET['id']]) {
169 028ff8f8 Phil Davis
		$do_update_config = true;
170 d38bd840 Phil Davis
		if (isset($a_routes[$_GET['id']]['disabled'])) {
171 028ff8f8 Phil Davis
			// Do not enable a route whose gateway is disabled
172
			if (isset($a_gateways[$a_routes[$_GET['id']]['gateway']]['disabled'])) {
173
				$do_update_config = false;
174 762faef5 Phil Davis
				$input_errors[] = $changedesc_prefix . sprintf(gettext("gateway is disabled, cannot enable route to %s"), $a_routes[$_GET['id']]['network']);
175 028ff8f8 Phil Davis
			} else {
176
				unset($a_routes[$_GET['id']]['disabled']);
177 762faef5 Phil Davis
				$changedesc = $changedesc_prefix . sprintf(gettext("enabled route to %s"), $a_routes[$_GET['id']]['network']);
178 028ff8f8 Phil Davis
			}
179 25c3f30c Renato Botelho
		} else {
180 70cb0375 Renato Botelho
			delete_static_route($_GET['id']);
181
			$a_routes[$_GET['id']]['disabled'] = true;
182 762faef5 Phil Davis
			$changedesc = $changedesc_prefix . sprintf(gettext("disabled route to %s"), $a_routes[$_GET['id']]['network']);
183 9c115b40 Ermal
		}
184 25c3f30c Renato Botelho
185 028ff8f8 Phil Davis
		if ($do_update_config) {
186
			if (write_config($changedesc)) {
187
				mark_subsystem_dirty('staticroutes');
188
			}
189
			header("Location: system_routes.php");
190
			exit;
191 d38bd840 Phil Davis
		}
192 70cb0375 Renato Botelho
	}
193
} else {
194
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
195
	unset($movebtn);
196
	foreach ($_POST as $pn => $pd) {
197
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
198
			$movebtn = $matches[1];
199
			break;
200 25c3f30c Renato Botelho
		}
201 70cb0375 Renato Botelho
	}
202
	/* move selected routes before this route */
203
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
204
		$a_routes_new = array();
205 25c3f30c Renato Botelho
206 70cb0375 Renato Botelho
		/* copy all routes < $movebtn and not selected */
207
		for ($i = 0; $i < $movebtn; $i++) {
208 d38bd840 Phil Davis
			if (!in_array($i, $_POST['route'])) {
209 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
210 d38bd840 Phil Davis
			}
211 70cb0375 Renato Botelho
		}
212
213
		/* copy all selected routes */
214
		for ($i = 0; $i < count($a_routes); $i++) {
215 d38bd840 Phil Davis
			if ($i == $movebtn) {
216 70cb0375 Renato Botelho
				continue;
217 d38bd840 Phil Davis
			}
218
			if (in_array($i, $_POST['route'])) {
219 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
220 d38bd840 Phil Davis
			}
221 70cb0375 Renato Botelho
		}
222
223
		/* copy $movebtn route */
224 d38bd840 Phil Davis
		if ($movebtn < count($a_routes)) {
225 70cb0375 Renato Botelho
			$a_routes_new[] = $a_routes[$movebtn];
226 d38bd840 Phil Davis
		}
227 70cb0375 Renato Botelho
228
		/* copy all routes > $movebtn and not selected */
229
		for ($i = $movebtn+1; $i < count($a_routes); $i++) {
230 d38bd840 Phil Davis
			if (!in_array($i, $_POST['route'])) {
231 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
232 d38bd840 Phil Davis
			}
233 70cb0375 Renato Botelho
		}
234 d38bd840 Phil Davis
		if (count($a_routes_new) > 0) {
235 70cb0375 Renato Botelho
			$a_routes = $a_routes_new;
236 d38bd840 Phil Davis
		}
237 70cb0375 Renato Botelho
238 d38bd840 Phil Davis
		if (write_config()) {
239 70cb0375 Renato Botelho
			mark_subsystem_dirty('staticroutes');
240 d38bd840 Phil Davis
		}
241 25c3f30c Renato Botelho
		header("Location: system_routes.php");
242
		exit;
243 5b237745 Scott Ullrich
	}
244
}
245 7f43ca88 Scott Ullrich
246 d036bc07 Stephen Beaver
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Static Routes"));
247 b32dd0a6 jim-p
$shortcut_section = "routing";
248 02ca24c9 jim-p
249 7f43ca88 Scott Ullrich
include("head.inc");
250
251 d61309a0 Phil Davis
if ($input_errors) {
252 f3bb71cf Sjon Hortensius
	print_input_errors($input_errors);
253 d61309a0 Phil Davis
}
254
if ($savemsg) {
255 f78bbe16 Phil Davis
	print_info_box($savemsg, 'success');
256 d61309a0 Phil Davis
}
257
if (is_subsystem_dirty('staticroutes')) {
258 73ff9530 Stephen Beaver
	print_apply_box(gettext("The static route configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
259 d61309a0 Phil Davis
}
260 f3bb71cf Sjon Hortensius
261
$tab_array = array();
262
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
263 c14798d0 heper
$tab_array[1] = array(gettext("Static Routes"), true, "system_routes.php");
264
$tab_array[2] = array(gettext("Gateway Groups"), false, "system_gateway_groups.php");
265 f3bb71cf Sjon Hortensius
display_top_tabs($tab_array);
266 0f282d7a Scott Ullrich
267 f3bb71cf Sjon Hortensius
?>
268 060ed238 Stephen Beaver
<div class="panel panel-default">
269 70dc5cd6 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Static Routes')?></h2></div>
270 060ed238 Stephen Beaver
	<div class="panel-body">
271
		<div class="table-responsive">
272
			<table class="table table-striped table-hover table-condensed">
273
				<thead>
274
					<tr>
275
						<th></th>
276
						<th><?=gettext("Network")?></th>
277
						<th><?=gettext("Gateway")?></th>
278
						<th><?=gettext("Interface")?></th>
279
						<th><?=gettext("Description")?></th>
280
						<th><?=gettext("Actions")?></th>
281
					</tr>
282
				</thead>
283
				<tbody>
284 70cb0375 Renato Botelho
<?php
285 f3bb71cf Sjon Hortensius
foreach ($a_routes as $i => $route):
286 d61309a0 Phil Davis
	if (isset($route['disabled'])) {
287 1b7379f9 Jared Dillard
		$icon = 'fa-ban';
288 d61309a0 Phil Davis
	} else {
289 1b7379f9 Jared Dillard
		$icon = 'fa-check-circle-o';
290 d61309a0 Phil Davis
	}
291 70cb0375 Renato Botelho
?>
292 060ed238 Stephen Beaver
				<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
293
					<td><i class="fa <?=$icon?>"></i></td>
294
					<td>
295
						<?=strtolower($route['network'])?>
296
					</td>
297
					<td>
298
						<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
299
					</td>
300
					<td>
301
						<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
302
					</td>
303
					<td>
304
						<?=htmlspecialchars($route['descr'])?>
305
					</td>
306
					<td>
307 4bfdf0be Phil Davis
						<a href="system_routes_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit route')?>"></a>
308 060ed238 Stephen Beaver
309 4bfdf0be Phil Davis
						<a href="system_routes_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy route')?>"></a>
310 060ed238 Stephen Beaver
311
				<?php if (isset($route['disabled'])) {
312
				?>
313 4bfdf0be Phil Davis
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable route')?>"></a>
314 060ed238 Stephen Beaver
				<?php } else {
315
				?>
316 4bfdf0be Phil Davis
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable route')?>"></a>
317 060ed238 Stephen Beaver
				<?php }
318
				?>
319 4bfdf0be Phil Davis
						<a href="system_routes.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete route')?>"></a>
320 060ed238 Stephen Beaver
321
					</td>
322
				</tr>
323 fa172bc5 NewEraCracker
<?php endforeach; ?>
324 060ed238 Stephen Beaver
			</table>
325
		</div>
326
	</div>
327
</div>
328 f3bb71cf Sjon Hortensius
329 c10cb196 Stephen Beaver
<nav class="action-buttons">
330 f74457df Stephen Beaver
	<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
331 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
332 f74457df Stephen Beaver
		<?=gettext("Add")?>
333 f3bb71cf Sjon Hortensius
	</a>
334
</nav>
335
<?php
336
337 5d339e8e heper
include("foot.inc");