Project

General

Profile

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