Project

General

Profile

Download (7.87 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
if (!is_array($config['staticroutes']['route']))
50
	$config['staticroutes']['route'] = array();
51
52
$a_routes = &$config['staticroutes']['route'];
53 70cb0375 Renato Botelho
$a_gateways = return_gateways_array(true, true, true);
54
$changedesc_prefix = gettext("Static Routes") . ": ";
55 5b237745 Scott Ullrich
56
if ($_POST) {
57
58
	$pconfig = $_POST;
59
60
	if ($_POST['apply']) {
61 691dade5 Scott Ullrich
62 5b237745 Scott Ullrich
		$retval = 0;
63 3851094f Scott Ullrich
64 e8471084 Ermal
		if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
65 bfe407e5 Warren Baker
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
66 e8471084 Ermal
			foreach ($toapplylist as $toapply)
67
				mwexec("{$toapply}");
68 966780ad Renato Botelho
69 e8471084 Ermal
			@unlink("{$g['tmp_path']}/.system_routes.apply");
70
		}
71
72 3851094f Scott Ullrich
		$retval = system_routing_configure();
73
		$retval |= filter_configure();
74 13bbe450 Seth Mos
		/* reconfigure our gateway monitor */
75
		setup_gateways_monitor();
76 3851094f Scott Ullrich
77 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
78 a368a026 Ermal Lu?i
		if ($retval == 0)
79
			clear_subsystem_dirty('staticroutes');
80 5b237745 Scott Ullrich
	}
81
}
82
83 70cb0375 Renato Botelho
function delete_static_route($id) {
84
	global $config, $a_routes, $changedesc_prefix;
85
86
	if (!isset($a_routes[$id]))
87
		return;
88
89
	$targets = array();
90
	if (is_alias($a_routes[$id]['network'])) {
91
		foreach (filter_expand_alias_array($a_routes[$id]['network']) as $tgt) {
92
			if (is_ipaddrv4($tgt))
93
				$tgt .= "/32";
94
			else if (is_ipaddrv6($tgt))
95
				$tgt .= "/128";
96
			if (!is_subnet($tgt))
97
				continue;
98
			$targets[] = $tgt;
99
		}
100
	} else {
101
		$targets[] = $a_routes[$id]['network'];
102
	}
103
104
	foreach ($targets as $tgt) {
105
		$family = (is_subnetv6($tgt) ? "-inet6" : "-inet");
106
		mwexec("/sbin/route delete {$family} " . escapeshellarg($tgt));
107
	}
108
109
	unset($targets);
110
}
111
112 5b237745 Scott Ullrich
if ($_GET['act'] == "del") {
113
	if ($a_routes[$_GET['id']]) {
114 70cb0375 Renato Botelho
		$changedesc = $changedesc_prefix . gettext("removed route to") . " " . $a_routes[$_GET['id']]['network'];
115
		delete_static_route($_GET['id']);
116
		unset($a_routes[$_GET['id']]);
117
		write_config($changedesc);
118
		header("Location: system_routes.php");
119
		exit;
120
	}
121
}
122
123
if (isset($_POST['del_x'])) {
124
	/* delete selected routes */
125
	if (is_array($_POST['route']) && count($_POST['route'])) {
126
		$changedesc = $changedesc_prefix . gettext("removed route to");
127
		foreach ($_POST['route'] as $routei) {
128
			$changedesc .= " " . $a_routes[$routei]['network'];
129
			delete_static_route($routei);
130
			unset($a_routes[$routei]);
131
		}
132
		write_config($changedesc);
133
		header("Location: system_routes.php");
134
		exit;
135
	}
136
137
} else if ($_GET['act'] == "toggle") {
138
	if ($a_routes[$_GET['id']]) {
139
		if(isset($a_routes[$_GET['id']]['disabled'])) {
140
			unset($a_routes[$_GET['id']]['disabled']);
141
			$changedesc = $changedesc_prefix . gettext("enabled route to") . " " . $a_routes[$id]['network'];
142 25c3f30c Renato Botelho
		} else {
143 70cb0375 Renato Botelho
			delete_static_route($_GET['id']);
144
			$a_routes[$_GET['id']]['disabled'] = true;
145
			$changedesc = $changedesc_prefix . gettext("disabled route to") . " " . $a_routes[$id]['network'];
146 9c115b40 Ermal
		}
147 25c3f30c Renato Botelho
148 70cb0375 Renato Botelho
		if (write_config($changedesc))
149
			mark_subsystem_dirty('staticroutes');
150
		header("Location: system_routes.php");
151
		exit;
152
	}
153
} else {
154
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
155
	unset($movebtn);
156
	foreach ($_POST as $pn => $pd) {
157
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
158
			$movebtn = $matches[1];
159
			break;
160 25c3f30c Renato Botelho
		}
161 70cb0375 Renato Botelho
	}
162
	/* move selected routes before this route */
163
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
164
		$a_routes_new = array();
165 25c3f30c Renato Botelho
166 70cb0375 Renato Botelho
		/* copy all routes < $movebtn and not selected */
167
		for ($i = 0; $i < $movebtn; $i++) {
168
			if (!in_array($i, $_POST['route']))
169
				$a_routes_new[] = $a_routes[$i];
170
		}
171
172
		/* copy all selected routes */
173
		for ($i = 0; $i < count($a_routes); $i++) {
174
			if ($i == $movebtn)
175
				continue;
176
			if (in_array($i, $_POST['route']))
177
				$a_routes_new[] = $a_routes[$i];
178
		}
179
180
		/* copy $movebtn route */
181
		if ($movebtn < count($a_routes))
182
			$a_routes_new[] = $a_routes[$movebtn];
183
184
		/* copy all routes > $movebtn and not selected */
185
		for ($i = $movebtn+1; $i < count($a_routes); $i++) {
186
			if (!in_array($i, $_POST['route']))
187
				$a_routes_new[] = $a_routes[$i];
188
		}
189
		if (count($a_routes_new) > 0)
190
			$a_routes = $a_routes_new;
191
192
		if (write_config())
193
			mark_subsystem_dirty('staticroutes');
194 25c3f30c Renato Botelho
		header("Location: system_routes.php");
195
		exit;
196 5b237745 Scott Ullrich
	}
197
}
198 7f43ca88 Scott Ullrich
199 a2927ebf Vinicius Coque
$pgtitle = array(gettext("System"),gettext("Static Routes"));
200 b32dd0a6 jim-p
$shortcut_section = "routing";
201 02ca24c9 jim-p
202 7f43ca88 Scott Ullrich
include("head.inc");
203
204 f3bb71cf Sjon Hortensius
if ($input_errors)
205
	print_input_errors($input_errors);
206
if ($savemsg)
207
	print_info_box($savemsg);
208
if (is_subsystem_dirty('staticroutes'))
209
	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."));
210
211
$tab_array = array();
212
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
213
$tab_array[1] = array(gettext("Routes"), true, "system_routes.php");
214
$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
215
display_top_tabs($tab_array);
216 0f282d7a Scott Ullrich
217 f3bb71cf Sjon Hortensius
?>
218
<table class="table">
219
<thead>
220 966780ad Renato Botelho
	<tr>
221 f3bb71cf Sjon Hortensius
		<th></th>
222
		<th><?=gettext("Network")?></th>
223
		<th><?=gettext("Gateway")?></th>
224
		<th><?=gettext("Interface")?></th>
225
		<th><?=gettext("Description")?></th>
226
		<th></th>
227 966780ad Renato Botelho
	</tr>
228 f3bb71cf Sjon Hortensius
</thead>
229
<tbody>
230 70cb0375 Renato Botelho
<?php
231 f3bb71cf Sjon Hortensius
foreach ($a_routes as $i => $route):
232
	if (isset($route['disabled']))
233
		$icon = 'icon-ban-circle';
234
	else
235
		$icon = 'icon-ok-circle';
236 70cb0375 Renato Botelho
?>
237 f3bb71cf Sjon Hortensius
	<tr<?=($icon != 'icon-ok-circle')? ' class="disabled"' : ''?>>
238
		<td><i class="icon <?=$icon?>"></i></td>
239
		<td>
240
			<?=strtolower($route['network'])?>
241
		</td>
242
		<td>
243
			<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
244
		</td>
245
		<td>
246
			<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
247
		</td>
248
		<td>
249
			<?=htmlspecialchars($route['descr'])?>
250 966780ad Renato Botelho
		</td>
251 f3bb71cf Sjon Hortensius
		<td>
252
			<a class="btn btn-xs btn-primary" href="system_routes_edit.php?id=<?=$i?>">
253
				edit
254
			</a>
255
256
			<a class="btn btn-xs btn-default" href="system_routes_edit.php?dup=<?=$i?>">
257
				copy
258
			</a>
259
260
			<a class="btn btn-xs btn-danger" href="system_routes.php?act=del&amp;id=<?=$i?>">
261
				delete
262
			</a>
263
264
			<a class="btn btn-xs btn-default" href="?act=toggle&amp;id=<?=$i?>">
265
				toggle
266
			</a>
267
		</td>
268
<? endforeach?>
269 966780ad Renato Botelho
	</tr>
270
</table>
271 f3bb71cf Sjon Hortensius
272
<nav class="action-buttons">
273
	<a href="system_routes_edit.php" role="button" class="btn btn-success">
274
		<?=gettext("add new route")?>
275
	</a>
276
</nav>
277
<?php
278
279
include("foot.inc");