Project

General

Profile

Download (13 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / system_routes.php @ a1b66bec

1
<?php
2
/* $Id$ */
3
/*
4
	system_routes.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, 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 the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	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
/*
32
	pfSense_MODULE:	routing
33
*/
34

    
35
##|+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
require("guiconfig.inc");
43
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46

    
47
if (!is_array($config['staticroutes']['route']))
48
	$config['staticroutes']['route'] = array();
49

    
50
$a_routes = &$config['staticroutes']['route'];
51
$a_gateways = return_gateways_array(true, true, true);
52
$changedesc_prefix = gettext("Static Routes") . ": ";
53

    
54
if ($_POST) {
55

    
56
	$pconfig = $_POST;
57

    
58
	if ($_POST['apply']) {
59

    
60
		$retval = 0;
61

    
62
		if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
63
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
64
			foreach ($toapplylist as $toapply)
65
				mwexec("{$toapply}");
66

    
67
			@unlink("{$g['tmp_path']}/.system_routes.apply");
68
		}
69

    
70
		$retval = system_routing_configure();
71
		$retval |= filter_configure();
72
		/* reconfigure our gateway monitor */
73
		setup_gateways_monitor();
74

    
75
		$savemsg = get_std_save_message($retval);
76
		if ($retval == 0)
77
			clear_subsystem_dirty('staticroutes');
78
	}
79
}
80

    
81
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
if ($_GET['act'] == "del") {
111
	if ($a_routes[$_GET['id']]) {
112
		$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
		} else {
141
			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
		}
145

    
146
		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
		}
159
	}
160
	/* move selected routes before this route */
161
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
162
		$a_routes_new = array();
163

    
164
		/* 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
		header("Location: system_routes.php");
193
		exit;
194
	}
195
}
196

    
197
$pgtitle = array(gettext("System"),gettext("Static Routes"));
198
$shortcut_section = "routing";
199

    
200
include("head.inc");
201

    
202
?>
203

    
204
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
205
<?php include("fbegin.inc"); ?>
206
<form action="system_routes.php" method="post">
207
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
208
<?php if ($savemsg) print_info_box($savemsg); ?>
209
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
210
<?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
<?php endif; ?>
212

    
213
<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
					<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
						<td width="20%" class="listhdrr"><?=gettext("Gateway");?></td>
234
						<td width="15%" class="listhdrr"><?=gettext("Interface");?></td>
235
						<td width="29%" class="listhdr"><?=gettext("Description");?></td>
236
						<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
					<tr valign="top" id="fr<?=$i;?>">
247
					<?php
248
						$iconfn = "pass";
249
						if (isset($route['disabled'])) {
250
							$textss = "<span class=\"gray\">";
251
							$textse = "</span>";
252
							$iconfn .= "_d";
253
						} else
254
							$textss = $textse = "";
255
					?>
256
						<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
							<?=$textss;?><?=strtolower($route['network']);?><?=$textse;?>
267
						</td>
268
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
269
							<?=$textss;?>
270
							<?php
271
								echo htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway']);
272
							?>
273
							<?=$textse;?>
274
						</td>
275
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
276
							<?=$textss;?>
277
							<?php
278
								echo convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface']) . " ";
279
							?>
280
							<?=$textse;?>
281
						</td>
282
						<td class="listbg" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
283
							<?=$textss;?><?=htmlspecialchars($route['descr']);?>&nbsp;<?=$textse;?>
284
						</td>
285
						<td class="list nowrap" valign="middle">
286
							<table border="0" cellspacing="0" cellpadding="1" summary="move">
287
								<tr>
288
									<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
								</tr>
300
								<tr>
301
									<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
								</tr>
312
							</table>
313
						</td>
314
					</tr>
315
					<?php $i++; endforeach; ?>
316
					<tr>
317
						<td class="list" colspan="6"></td>
318
						<td class="list nowrap" valign="middle">
319
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
320
								<tr>
321
									<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
								</tr>
361
							</table>
362
						</td>
363
					</tr>
364
				</table>
365
			</div>
366
		</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
<?php include("fend.inc"); ?>
372
</body>
373
</html>
(227-227/256)