Project

General

Profile

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