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 8450bc24 Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 8450bc24 Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 8450bc24 Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 8450bc24 Scott Ullrich
16 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19 8450bc24 Scott Ullrich
20 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 1d333258 Scott Ullrich
/*
32
	pfSense_MODULE:	routing
33
*/
34 5b237745 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-system-staticroutes
37
##|*NAME=System: Static Routes page
38
##|*DESCR=Allow access to the 'System: Static Routes' page.
39
##|*MATCH=system_routes.php*
40
##|-PRIV
41
42 5b237745 Scott Ullrich
require("guiconfig.inc");
43 7a927e67 Scott Ullrich
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46 5b237745 Scott Ullrich
47
if (!is_array($config['staticroutes']['route']))
48
	$config['staticroutes']['route'] = array();
49
50
$a_routes = &$config['staticroutes']['route'];
51 70cb0375 Renato Botelho
$a_gateways = return_gateways_array(true, true, true);
52
$changedesc_prefix = gettext("Static Routes") . ": ";
53 5b237745 Scott Ullrich
54
if ($_POST) {
55
56
	$pconfig = $_POST;
57
58
	if ($_POST['apply']) {
59 691dade5 Scott Ullrich
60 5b237745 Scott Ullrich
		$retval = 0;
61 3851094f Scott Ullrich
62 e8471084 Ermal
		if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
63 bfe407e5 Warren Baker
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
64 e8471084 Ermal
			foreach ($toapplylist as $toapply)
65
				mwexec("{$toapply}");
66 966780ad Renato Botelho
67 e8471084 Ermal
			@unlink("{$g['tmp_path']}/.system_routes.apply");
68
		}
69
70 3851094f Scott Ullrich
		$retval = system_routing_configure();
71
		$retval |= filter_configure();
72 13bbe450 Seth Mos
		/* reconfigure our gateway monitor */
73
		setup_gateways_monitor();
74 3851094f Scott Ullrich
75 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
76 a368a026 Ermal Lu?i
		if ($retval == 0)
77
			clear_subsystem_dirty('staticroutes');
78 5b237745 Scott Ullrich
	}
79
}
80
81 70cb0375 Renato Botelho
function delete_static_route($id) {
82
	global $config, $a_routes, $changedesc_prefix;
83
84
	if (!isset($a_routes[$id]))
85
		return;
86
87
	$targets = array();
88
	if (is_alias($a_routes[$id]['network'])) {
89
		foreach (filter_expand_alias_array($a_routes[$id]['network']) as $tgt) {
90
			if (is_ipaddrv4($tgt))
91
				$tgt .= "/32";
92
			else if (is_ipaddrv6($tgt))
93
				$tgt .= "/128";
94
			if (!is_subnet($tgt))
95
				continue;
96
			$targets[] = $tgt;
97
		}
98
	} else {
99
		$targets[] = $a_routes[$id]['network'];
100
	}
101
102
	foreach ($targets as $tgt) {
103
		$family = (is_subnetv6($tgt) ? "-inet6" : "-inet");
104
		mwexec("/sbin/route delete {$family} " . escapeshellarg($tgt));
105
	}
106
107
	unset($targets);
108
}
109
110 5b237745 Scott Ullrich
if ($_GET['act'] == "del") {
111
	if ($a_routes[$_GET['id']]) {
112 70cb0375 Renato Botelho
		$changedesc = $changedesc_prefix . gettext("removed route to") . " " . $a_routes[$_GET['id']]['network'];
113
		delete_static_route($_GET['id']);
114
		unset($a_routes[$_GET['id']]);
115
		write_config($changedesc);
116
		header("Location: system_routes.php");
117
		exit;
118
	}
119
}
120
121
if (isset($_POST['del_x'])) {
122
	/* delete selected routes */
123
	if (is_array($_POST['route']) && count($_POST['route'])) {
124
		$changedesc = $changedesc_prefix . gettext("removed route to");
125
		foreach ($_POST['route'] as $routei) {
126
			$changedesc .= " " . $a_routes[$routei]['network'];
127
			delete_static_route($routei);
128
			unset($a_routes[$routei]);
129
		}
130
		write_config($changedesc);
131
		header("Location: system_routes.php");
132
		exit;
133
	}
134
135
} else if ($_GET['act'] == "toggle") {
136
	if ($a_routes[$_GET['id']]) {
137
		if(isset($a_routes[$_GET['id']]['disabled'])) {
138
			unset($a_routes[$_GET['id']]['disabled']);
139
			$changedesc = $changedesc_prefix . gettext("enabled route to") . " " . $a_routes[$id]['network'];
140 25c3f30c Renato Botelho
		} else {
141 70cb0375 Renato Botelho
			delete_static_route($_GET['id']);
142
			$a_routes[$_GET['id']]['disabled'] = true;
143
			$changedesc = $changedesc_prefix . gettext("disabled route to") . " " . $a_routes[$id]['network'];
144 9c115b40 Ermal
		}
145 25c3f30c Renato Botelho
146 70cb0375 Renato Botelho
		if (write_config($changedesc))
147
			mark_subsystem_dirty('staticroutes');
148
		header("Location: system_routes.php");
149
		exit;
150
	}
151
} else {
152
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
153
	unset($movebtn);
154
	foreach ($_POST as $pn => $pd) {
155
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
156
			$movebtn = $matches[1];
157
			break;
158 25c3f30c Renato Botelho
		}
159 70cb0375 Renato Botelho
	}
160
	/* move selected routes before this route */
161
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
162
		$a_routes_new = array();
163 25c3f30c Renato Botelho
164 70cb0375 Renato Botelho
		/* copy all routes < $movebtn and not selected */
165
		for ($i = 0; $i < $movebtn; $i++) {
166
			if (!in_array($i, $_POST['route']))
167
				$a_routes_new[] = $a_routes[$i];
168
		}
169
170
		/* copy all selected routes */
171
		for ($i = 0; $i < count($a_routes); $i++) {
172
			if ($i == $movebtn)
173
				continue;
174
			if (in_array($i, $_POST['route']))
175
				$a_routes_new[] = $a_routes[$i];
176
		}
177
178
		/* copy $movebtn route */
179
		if ($movebtn < count($a_routes))
180
			$a_routes_new[] = $a_routes[$movebtn];
181
182
		/* copy all routes > $movebtn and not selected */
183
		for ($i = $movebtn+1; $i < count($a_routes); $i++) {
184
			if (!in_array($i, $_POST['route']))
185
				$a_routes_new[] = $a_routes[$i];
186
		}
187
		if (count($a_routes_new) > 0)
188
			$a_routes = $a_routes_new;
189
190
		if (write_config())
191
			mark_subsystem_dirty('staticroutes');
192 25c3f30c Renato Botelho
		header("Location: system_routes.php");
193
		exit;
194 5b237745 Scott Ullrich
	}
195
}
196 7f43ca88 Scott Ullrich
197 a2927ebf Vinicius Coque
$pgtitle = array(gettext("System"),gettext("Static Routes"));
198 b32dd0a6 jim-p
$shortcut_section = "routing";
199 02ca24c9 jim-p
200 7f43ca88 Scott Ullrich
include("head.inc");
201
202 5b237745 Scott Ullrich
?>
203
204
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
205
<?php include("fbegin.inc"); ?>
206
<form action="system_routes.php" method="post">
207 70cb0375 Renato Botelho
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js"></script>
208 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
209 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
210 1bc92a15 Colin Fleming
<?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>
211 5b237745 Scott Ullrich
<?php endif; ?>
212 0f282d7a Scott Ullrich
213 966780ad Renato Botelho
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system routes">
214
	<tr>
215
		<td>
216
		<?php
217
			$tab_array = array();
218
			$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
219
			$tab_array[1] = array(gettext("Routes"), true, "system_routes.php");
220
			$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
221
			display_top_tabs($tab_array);
222
		?>
223
		</td>
224
	</tr>
225
	<tr>
226
		<td>
227
			<div id="mainarea">
228
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
229 70cb0375 Renato Botelho
					<tr id="frheader">
230
						<td width="2%" class="list">&nbsp;</td>
231
						<td width="2%" class="list">&nbsp;</td>
232
						<td width="22%" class="listhdrr"><?=gettext("Network");?></td>
233 966780ad Renato Botelho
						<td width="20%" class="listhdrr"><?=gettext("Gateway");?></td>
234
						<td width="15%" class="listhdrr"><?=gettext("Interface");?></td>
235 70cb0375 Renato Botelho
						<td width="29%" class="listhdr"><?=gettext("Description");?></td>
236 966780ad Renato Botelho
						<td width="10%" class="list">
237
							<table border="0" cellspacing="0" cellpadding="1" summary="add">
238
								<tr>
239
									<td width="17"></td>
240
									<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>
241
								</tr>
242
							</table>
243
						</td>
244
					</tr>
245
					<?php $i = 0; foreach ($a_routes as $route): ?>
246 70cb0375 Renato Botelho
					<tr valign="top" id="fr<?=$i;?>">
247 966780ad Renato Botelho
					<?php
248 70cb0375 Renato Botelho
						$iconfn = "pass";
249 966780ad Renato Botelho
						if (isset($route['disabled'])) {
250
							$textss = "<span class=\"gray\">";
251
							$textse = "</span>";
252 70cb0375 Renato Botelho
							$iconfn .= "_d";
253 966780ad Renato Botelho
						} else
254 70cb0375 Renato Botelho
							$textss = $textse = "";
255 966780ad Renato Botelho
					?>
256 70cb0375 Renato Botelho
						<td class="listt">
257
							<input type="checkbox" id="frc<?=$i;?>" name="route[]" value="<?=$i;?>" onclick="fr_bgcolor('<?=$i;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;" />
258
						</td>
259
						<td class="listt" align="center">
260
							<a href="?act=toggle&amp;id=<?=$i;?>">
261
								<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0"
262
									title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" />
263
							</a>
264
						</td>
265
						<td class="listlr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
266 966780ad Renato Botelho
							<?=$textss;?><?=strtolower($route['network']);?><?=$textse;?>
267
						</td>
268 70cb0375 Renato Botelho
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
269 966780ad Renato Botelho
							<?=$textss;?>
270
							<?php
271
								echo htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway']);
272
							?>
273
							<?=$textse;?>
274
						</td>
275 70cb0375 Renato Botelho
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
276 966780ad Renato Botelho
							<?=$textss;?>
277
							<?php
278
								echo convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface']) . " ";
279
							?>
280
							<?=$textse;?>
281
						</td>
282 70cb0375 Renato Botelho
						<td class="listbg" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
283 966780ad Renato Botelho
							<?=$textss;?><?=htmlspecialchars($route['descr']);?>&nbsp;<?=$textse;?>
284
						</td>
285 70cb0375 Renato Botelho
						<td class="list nowrap" valign="middle">
286
							<table border="0" cellspacing="0" cellpadding="1" summary="move">
287 966780ad Renato Botelho
								<tr>
288 70cb0375 Renato Botelho
									<td>
289
										<input onmouseover="fr_insline(<?=$i;?>, true)" onmouseout="fr_insline(<?=$i;?>, false)" name="move_<?=$i;?>"
290
											src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif"
291
											title="<?=gettext("move selected rules before this rule");?>"
292
											type="image" style="height:17;width:17;border:0" />
293
									</td>
294
									<td>
295
										<a href="system_routes_edit.php?id=<?=$i;?>">
296
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="<?=gettext("edit rule");?>" alt="edit" />
297
										</a>
298
									</td>
299 966780ad Renato Botelho
								</tr>
300
								<tr>
301 70cb0375 Renato Botelho
									<td align="center" valign="middle">
302
										<a href="system_routes.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this rule?");?>')">
303
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("delete rule");?>" alt="delete" />
304
										</a>
305
									</td>
306
									<td>
307
										<a href="system_routes_edit.php?dup=<?=$i;?>">
308
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0" alt="duplicate" />
309
										</a>
310
									</td>
311 966780ad Renato Botelho
								</tr>
312
							</table>
313
						</td>
314
					</tr>
315
					<?php $i++; endforeach; ?>
316
					<tr>
317 70cb0375 Renato Botelho
						<td class="list" colspan="6"></td>
318
						<td class="list nowrap" valign="middle">
319 966780ad Renato Botelho
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
320
								<tr>
321 70cb0375 Renato Botelho
									<td>
322
<?php
323
									if ($i == 0):
324
?>
325
										<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17"
326
											title="<?=gettext("move selected routes to end");?>" border="0" alt="move" />
327
<?php
328
									else:
329
?>
330
										<input name="move_<?=$i;?>" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif"
331
											style="width:17;height:17;border:0" title="<?=gettext("move selected routes to end");?>" />
332
<?php
333
									endif;
334
?>
335
									</td>
336
									<td>
337
										<a href="system_routes_edit.php">
338
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"
339
											title="<?=gettext("add new route");?>" alt="add" />
340
										</a>
341
									</td>
342
								</tr>
343
								<tr>
344
									<td>
345
<?php
346
									if ($i == 0):
347
?>
348
										<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17"
349
											title="<?=gettext("delete selected rules");?>" border="0" alt="delete" />
350
<?php
351
									else:
352
?>
353
										<input name="del" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif"
354
											style="width:17;height:17" title="<?=gettext("delete selected routes");?>"
355
											onclick="return confirm('<?=gettext("Do you really want to delete the selected routes?");?>')" />
356
<?php
357
									endif;
358
?>
359
									</td>
360 966780ad Renato Botelho
								</tr>
361
							</table>
362
						</td>
363
					</tr>
364
				</table>
365 8e830f0f Scott Ullrich
			</div>
366 966780ad Renato Botelho
		</td>
367
	</tr>
368
</table>
369
</form>
370
<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>
371 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
372
</body>
373
</html>