Project

General

Profile

Download (8.38 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	system_routes.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 29aef6c4 Jim Thompson
	part of pfSense
7 8450bc24 Scott Ullrich
8 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
10 5b237745 Scott Ullrich
	All rights reserved.
11 8450bc24 Scott Ullrich
12 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 8450bc24 Scott Ullrich
15 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 8450bc24 Scott Ullrich
18 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21 8450bc24 Scott Ullrich
22 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33 1d333258 Scott Ullrich
/*
34
	pfSense_MODULE:	routing
35
*/
36 5b237745 Scott Ullrich
37 6b07c15a Matthew Grooms
##|+PRIV
38
##|*IDENT=page-system-staticroutes
39
##|*NAME=System: Static Routes page
40
##|*DESCR=Allow access to the 'System: Static Routes' page.
41
##|*MATCH=system_routes.php*
42
##|-PRIV
43
44 5b237745 Scott Ullrich
require("guiconfig.inc");
45 7a927e67 Scott Ullrich
require_once("functions.inc");
46
require_once("filter.inc");
47
require_once("shaper.inc");
48 5b237745 Scott Ullrich
49 d38bd840 Phil Davis
if (!is_array($config['staticroutes']['route'])) {
50 5b237745 Scott Ullrich
	$config['staticroutes']['route'] = array();
51 d38bd840 Phil Davis
}
52 5b237745 Scott Ullrich
53
$a_routes = &$config['staticroutes']['route'];
54 70cb0375 Renato Botelho
$a_gateways = return_gateways_array(true, true, true);
55
$changedesc_prefix = gettext("Static Routes") . ": ";
56 028ff8f8 Phil Davis
unset($input_errors);
57 5b237745 Scott Ullrich
58
if ($_POST) {
59
60
	$pconfig = $_POST;
61
62
	if ($_POST['apply']) {
63 691dade5 Scott Ullrich
64 5b237745 Scott Ullrich
		$retval = 0;
65 3851094f Scott Ullrich
66 e8471084 Ermal
		if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
67 bfe407e5 Warren Baker
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
68 d38bd840 Phil Davis
			foreach ($toapplylist as $toapply) {
69 e8471084 Ermal
				mwexec("{$toapply}");
70 d38bd840 Phil Davis
			}
71 966780ad Renato Botelho
72 e8471084 Ermal
			@unlink("{$g['tmp_path']}/.system_routes.apply");
73
		}
74
75 3851094f Scott Ullrich
		$retval = system_routing_configure();
76
		$retval |= filter_configure();
77 13bbe450 Seth Mos
		/* reconfigure our gateway monitor */
78
		setup_gateways_monitor();
79 3851094f Scott Ullrich
80 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
81 d38bd840 Phil Davis
		if ($retval == 0) {
82 a368a026 Ermal Lu?i
			clear_subsystem_dirty('staticroutes');
83 d38bd840 Phil Davis
		}
84 5b237745 Scott Ullrich
	}
85
}
86
87 70cb0375 Renato Botelho
function delete_static_route($id) {
88
	global $config, $a_routes, $changedesc_prefix;
89
90 d38bd840 Phil Davis
	if (!isset($a_routes[$id])) {
91 70cb0375 Renato Botelho
		return;
92 d38bd840 Phil Davis
	}
93 70cb0375 Renato Botelho
94
	$targets = array();
95
	if (is_alias($a_routes[$id]['network'])) {
96
		foreach (filter_expand_alias_array($a_routes[$id]['network']) as $tgt) {
97 d38bd840 Phil Davis
			if (is_ipaddrv4($tgt)) {
98 70cb0375 Renato Botelho
				$tgt .= "/32";
99 d38bd840 Phil Davis
			} else if (is_ipaddrv6($tgt)) {
100 70cb0375 Renato Botelho
				$tgt .= "/128";
101 d38bd840 Phil Davis
			}
102
			if (!is_subnet($tgt)) {
103 70cb0375 Renato Botelho
				continue;
104 d38bd840 Phil Davis
			}
105 70cb0375 Renato Botelho
			$targets[] = $tgt;
106
		}
107
	} else {
108
		$targets[] = $a_routes[$id]['network'];
109
	}
110
111
	foreach ($targets as $tgt) {
112
		$family = (is_subnetv6($tgt) ? "-inet6" : "-inet");
113
		mwexec("/sbin/route delete {$family} " . escapeshellarg($tgt));
114
	}
115
116
	unset($targets);
117
}
118
119 5b237745 Scott Ullrich
if ($_GET['act'] == "del") {
120
	if ($a_routes[$_GET['id']]) {
121 70cb0375 Renato Botelho
		$changedesc = $changedesc_prefix . gettext("removed route to") . " " . $a_routes[$_GET['id']]['network'];
122
		delete_static_route($_GET['id']);
123
		unset($a_routes[$_GET['id']]);
124
		write_config($changedesc);
125
		header("Location: system_routes.php");
126
		exit;
127
	}
128
}
129
130
if (isset($_POST['del_x'])) {
131
	/* delete selected routes */
132
	if (is_array($_POST['route']) && count($_POST['route'])) {
133
		$changedesc = $changedesc_prefix . gettext("removed route to");
134
		foreach ($_POST['route'] as $routei) {
135
			$changedesc .= " " . $a_routes[$routei]['network'];
136
			delete_static_route($routei);
137
			unset($a_routes[$routei]);
138
		}
139
		write_config($changedesc);
140
		header("Location: system_routes.php");
141
		exit;
142
	}
143
144
} else if ($_GET['act'] == "toggle") {
145
	if ($a_routes[$_GET['id']]) {
146 028ff8f8 Phil Davis
		$do_update_config = true;
147 d38bd840 Phil Davis
		if (isset($a_routes[$_GET['id']]['disabled'])) {
148 028ff8f8 Phil Davis
			// Do not enable a route whose gateway is disabled
149
			if (isset($a_gateways[$a_routes[$_GET['id']]['gateway']]['disabled'])) {
150
				$do_update_config = false;
151
				$input_errors[] = $changedesc_prefix . gettext("gateway is disabled, cannot enable route to") . " " . $a_routes[$_GET['id']]['network'];
152
			} else {
153
				unset($a_routes[$_GET['id']]['disabled']);
154
				$changedesc = $changedesc_prefix . gettext("enabled route to") . " " . $a_routes[$_GET['id']]['network'];
155
			}
156 25c3f30c Renato Botelho
		} else {
157 70cb0375 Renato Botelho
			delete_static_route($_GET['id']);
158
			$a_routes[$_GET['id']]['disabled'] = true;
159 6135a11f Phil Davis
			$changedesc = $changedesc_prefix . gettext("disabled route to") . " " . $a_routes[$_GET['id']]['network'];
160 9c115b40 Ermal
		}
161 25c3f30c Renato Botelho
162 028ff8f8 Phil Davis
		if ($do_update_config) {
163
			if (write_config($changedesc)) {
164
				mark_subsystem_dirty('staticroutes');
165
			}
166
			header("Location: system_routes.php");
167
			exit;
168 d38bd840 Phil Davis
		}
169 70cb0375 Renato Botelho
	}
170
} else {
171
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
172
	unset($movebtn);
173
	foreach ($_POST as $pn => $pd) {
174
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
175
			$movebtn = $matches[1];
176
			break;
177 25c3f30c Renato Botelho
		}
178 70cb0375 Renato Botelho
	}
179
	/* move selected routes before this route */
180
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
181
		$a_routes_new = array();
182 25c3f30c Renato Botelho
183 70cb0375 Renato Botelho
		/* copy all routes < $movebtn and not selected */
184
		for ($i = 0; $i < $movebtn; $i++) {
185 d38bd840 Phil Davis
			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 all selected routes */
191
		for ($i = 0; $i < count($a_routes); $i++) {
192 d38bd840 Phil Davis
			if ($i == $movebtn) {
193 70cb0375 Renato Botelho
				continue;
194 d38bd840 Phil Davis
			}
195
			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
200
		/* copy $movebtn route */
201 d38bd840 Phil Davis
		if ($movebtn < count($a_routes)) {
202 70cb0375 Renato Botelho
			$a_routes_new[] = $a_routes[$movebtn];
203 d38bd840 Phil Davis
		}
204 70cb0375 Renato Botelho
205
		/* copy all routes > $movebtn and not selected */
206
		for ($i = $movebtn+1; $i < count($a_routes); $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 d38bd840 Phil Davis
		if (count($a_routes_new) > 0) {
212 70cb0375 Renato Botelho
			$a_routes = $a_routes_new;
213 d38bd840 Phil Davis
		}
214 70cb0375 Renato Botelho
215 d38bd840 Phil Davis
		if (write_config()) {
216 70cb0375 Renato Botelho
			mark_subsystem_dirty('staticroutes');
217 d38bd840 Phil Davis
		}
218 25c3f30c Renato Botelho
		header("Location: system_routes.php");
219
		exit;
220 5b237745 Scott Ullrich
	}
221
}
222 7f43ca88 Scott Ullrich
223 d38bd840 Phil Davis
$pgtitle = array(gettext("System"), gettext("Static Routes"));
224 b32dd0a6 jim-p
$shortcut_section = "routing";
225 02ca24c9 jim-p
226 7f43ca88 Scott Ullrich
include("head.inc");
227
228 f3bb71cf Sjon Hortensius
if ($input_errors)
229
	print_input_errors($input_errors);
230
if ($savemsg)
231
	print_info_box($savemsg);
232
if (is_subsystem_dirty('staticroutes'))
233
	print_info_box_np(gettext("The static route configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
234
235
$tab_array = array();
236
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
237
$tab_array[1] = array(gettext("Routes"), true, "system_routes.php");
238
$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
239
display_top_tabs($tab_array);
240 0f282d7a Scott Ullrich
241 f3bb71cf Sjon Hortensius
?>
242
<table class="table">
243
<thead>
244 966780ad Renato Botelho
	<tr>
245 f3bb71cf Sjon Hortensius
		<th></th>
246
		<th><?=gettext("Network")?></th>
247
		<th><?=gettext("Gateway")?></th>
248
		<th><?=gettext("Interface")?></th>
249
		<th><?=gettext("Description")?></th>
250
		<th></th>
251 966780ad Renato Botelho
	</tr>
252 f3bb71cf Sjon Hortensius
</thead>
253
<tbody>
254 70cb0375 Renato Botelho
<?php
255 f3bb71cf Sjon Hortensius
foreach ($a_routes as $i => $route):
256
	if (isset($route['disabled']))
257
		$icon = 'icon-ban-circle';
258
	else
259
		$icon = 'icon-ok-circle';
260 70cb0375 Renato Botelho
?>
261 f3bb71cf Sjon Hortensius
	<tr<?=($icon != 'icon-ok-circle')? ' class="disabled"' : ''?>>
262
		<td><i class="icon <?=$icon?>"></i></td>
263
		<td>
264
			<?=strtolower($route['network'])?>
265
		</td>
266
		<td>
267
			<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
268
		</td>
269
		<td>
270
			<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
271
		</td>
272
		<td>
273
			<?=htmlspecialchars($route['descr'])?>
274 966780ad Renato Botelho
		</td>
275 f3bb71cf Sjon Hortensius
		<td>
276
			<a class="btn btn-xs btn-primary" href="system_routes_edit.php?id=<?=$i?>">
277
				edit
278
			</a>
279
280
			<a class="btn btn-xs btn-default" href="system_routes_edit.php?dup=<?=$i?>">
281
				copy
282
			</a>
283
284
			<a class="btn btn-xs btn-danger" href="system_routes.php?act=del&amp;id=<?=$i?>">
285
				delete
286
			</a>
287
288
			<a class="btn btn-xs btn-default" href="?act=toggle&amp;id=<?=$i?>">
289
				toggle
290
			</a>
291
		</td>
292
<? endforeach?>
293 966780ad Renato Botelho
	</tr>
294
</table>
295 f3bb71cf Sjon Hortensius
296
<nav class="action-buttons">
297
	<a href="system_routes_edit.php" role="button" class="btn btn-success">
298
		<?=gettext("add new route")?>
299
	</a>
300
</nav>
301
<?php
302
303
include("foot.inc");