Project

General

Profile

Download (13 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 5b237745 Scott Ullrich
?>
205
206
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
207
<?php include("fbegin.inc"); ?>
208
<form action="system_routes.php" method="post">
209 07130afe ayvis
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
210 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
211 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
212 8cd558b6 ayvis
<?php print_info_box_np(sprintf(gettext("The static route configuration has been changed.%sYou must apply the changes in order for them to take effect."), "<br />"));?><br /></p>
213 5b237745 Scott Ullrich
<?php endif; ?>
214 0f282d7a Scott Ullrich
215 966780ad Renato Botelho
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system routes">
216
	<tr>
217
		<td>
218
		<?php
219
			$tab_array = array();
220
			$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
221
			$tab_array[1] = array(gettext("Routes"), true, "system_routes.php");
222
			$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
223
			display_top_tabs($tab_array);
224
		?>
225
		</td>
226
	</tr>
227
	<tr>
228
		<td>
229
			<div id="mainarea">
230
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
231 70cb0375 Renato Botelho
					<tr id="frheader">
232
						<td width="2%" class="list">&nbsp;</td>
233
						<td width="2%" class="list">&nbsp;</td>
234
						<td width="22%" class="listhdrr"><?=gettext("Network");?></td>
235 966780ad Renato Botelho
						<td width="20%" class="listhdrr"><?=gettext("Gateway");?></td>
236
						<td width="15%" class="listhdrr"><?=gettext("Interface");?></td>
237 70cb0375 Renato Botelho
						<td width="29%" class="listhdr"><?=gettext("Description");?></td>
238 966780ad Renato Botelho
						<td width="10%" class="list">
239
							<table border="0" cellspacing="0" cellpadding="1" summary="add">
240
								<tr>
241
									<td width="17"></td>
242
									<td><a href="system_routes_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" /></a></td>
243
								</tr>
244
							</table>
245
						</td>
246
					</tr>
247
					<?php $i = 0; foreach ($a_routes as $route): ?>
248 70cb0375 Renato Botelho
					<tr valign="top" id="fr<?=$i;?>">
249 966780ad Renato Botelho
					<?php
250 70cb0375 Renato Botelho
						$iconfn = "pass";
251 966780ad Renato Botelho
						if (isset($route['disabled'])) {
252
							$textss = "<span class=\"gray\">";
253
							$textse = "</span>";
254 70cb0375 Renato Botelho
							$iconfn .= "_d";
255 966780ad Renato Botelho
						} else
256 70cb0375 Renato Botelho
							$textss = $textse = "";
257 966780ad Renato Botelho
					?>
258 70cb0375 Renato Botelho
						<td class="listt">
259
							<input type="checkbox" id="frc<?=$i;?>" name="route[]" value="<?=$i;?>" onclick="fr_bgcolor('<?=$i;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;" />
260
						</td>
261
						<td class="listt" align="center">
262
							<a href="?act=toggle&amp;id=<?=$i;?>">
263
								<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0"
264
									title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" />
265
							</a>
266
						</td>
267
						<td class="listlr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
268 966780ad Renato Botelho
							<?=$textss;?><?=strtolower($route['network']);?><?=$textse;?>
269
						</td>
270 70cb0375 Renato Botelho
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
271 966780ad Renato Botelho
							<?=$textss;?>
272
							<?php
273
								echo htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway']);
274
							?>
275
							<?=$textse;?>
276
						</td>
277 70cb0375 Renato Botelho
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
278 966780ad Renato Botelho
							<?=$textss;?>
279
							<?php
280
								echo convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface']) . " ";
281
							?>
282
							<?=$textse;?>
283
						</td>
284 70cb0375 Renato Botelho
						<td class="listbg" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
285 966780ad Renato Botelho
							<?=$textss;?><?=htmlspecialchars($route['descr']);?>&nbsp;<?=$textse;?>
286
						</td>
287 70cb0375 Renato Botelho
						<td class="list nowrap" valign="middle">
288
							<table border="0" cellspacing="0" cellpadding="1" summary="move">
289 966780ad Renato Botelho
								<tr>
290 70cb0375 Renato Botelho
									<td>
291
										<input onmouseover="fr_insline(<?=$i;?>, true)" onmouseout="fr_insline(<?=$i;?>, false)" name="move_<?=$i;?>"
292
											src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif"
293 f4d094b4 Phil Davis
											title="<?=gettext("move selected routes before this route");?>"
294 70cb0375 Renato Botelho
											type="image" style="height:17;width:17;border:0" />
295
									</td>
296
									<td>
297
										<a href="system_routes_edit.php?id=<?=$i;?>">
298 f4d094b4 Phil Davis
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="<?=gettext("edit route");?>" alt="edit" />
299 70cb0375 Renato Botelho
										</a>
300
									</td>
301 966780ad Renato Botelho
								</tr>
302
								<tr>
303 70cb0375 Renato Botelho
									<td align="center" valign="middle">
304 f4d094b4 Phil Davis
										<a href="system_routes.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this route?");?>')">
305
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("delete route");?>" alt="delete" />
306 70cb0375 Renato Botelho
										</a>
307
									</td>
308
									<td>
309
										<a href="system_routes_edit.php?dup=<?=$i;?>">
310 f4d094b4 Phil Davis
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add a new route based on this one");?>" width="17" height="17" border="0" alt="duplicate" />
311 70cb0375 Renato Botelho
										</a>
312
									</td>
313 966780ad Renato Botelho
								</tr>
314
							</table>
315
						</td>
316
					</tr>
317
					<?php $i++; endforeach; ?>
318
					<tr>
319 70cb0375 Renato Botelho
						<td class="list" colspan="6"></td>
320
						<td class="list nowrap" valign="middle">
321 966780ad Renato Botelho
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
322
								<tr>
323 70cb0375 Renato Botelho
									<td>
324
<?php
325
									if ($i == 0):
326
?>
327
										<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17"
328
											title="<?=gettext("move selected routes to end");?>" border="0" alt="move" />
329
<?php
330
									else:
331
?>
332
										<input name="move_<?=$i;?>" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif"
333
											style="width:17;height:17;border:0" title="<?=gettext("move selected routes to end");?>" />
334
<?php
335
									endif;
336
?>
337
									</td>
338
									<td>
339
										<a href="system_routes_edit.php">
340
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"
341
											title="<?=gettext("add new route");?>" alt="add" />
342
										</a>
343
									</td>
344
								</tr>
345
								<tr>
346
									<td>
347
<?php
348
									if ($i == 0):
349
?>
350
										<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17"
351 f4d094b4 Phil Davis
											title="<?=gettext("delete selected routes");?>" border="0" alt="delete" />
352 70cb0375 Renato Botelho
<?php
353
									else:
354
?>
355
										<input name="del" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif"
356
											style="width:17;height:17" title="<?=gettext("delete selected routes");?>"
357
											onclick="return confirm('<?=gettext("Do you really want to delete the selected routes?");?>')" />
358
<?php
359
									endif;
360
?>
361
									</td>
362 966780ad Renato Botelho
								</tr>
363
							</table>
364
						</td>
365
					</tr>
366
				</table>
367 8e830f0f Scott Ullrich
			</div>
368 966780ad Renato Botelho
		</td>
369
	</tr>
370
</table>
371
</form>
372
<p><b><?=gettext("Note:");?></b>  <?=gettext("Do not enter static routes for networks assigned on any interface of this firewall.  Static routes are only used for networks reachable via a different router, and not reachable via your default gateway.");?></p>
373 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
374
</body>
375
</html>