Project

General

Profile

Download (13 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_routes.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	part of pfSense
7

    
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	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

    
22
	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
/*
34
	pfSense_MODULE:	routing
35
*/
36

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

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

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

    
56
if ($_POST) {
57

    
58
	$pconfig = $_POST;
59

    
60
	if ($_POST['apply']) {
61

    
62
		$retval = 0;
63

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

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

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

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

    
83
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
if ($_GET['act'] == "del") {
113
	if ($a_routes[$_GET['id']]) {
114
		$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
		} else {
143
			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
		}
147

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

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

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

    
202
include("head.inc");
203

    
204
?>
205

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

    
215
<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
					<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
						<td width="20%" class="listhdrr"><?=gettext("Gateway");?></td>
236
						<td width="15%" class="listhdrr"><?=gettext("Interface");?></td>
237
						<td width="29%" class="listhdr"><?=gettext("Description");?></td>
238
						<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
					<tr valign="top" id="fr<?=$i;?>">
249
					<?php
250
						$iconfn = "pass";
251
						if (isset($route['disabled'])) {
252
							$textss = "<span class=\"gray\">";
253
							$textse = "</span>";
254
							$iconfn .= "_d";
255
						} else
256
							$textss = $textse = "";
257
					?>
258
						<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
							<?=$textss;?><?=strtolower($route['network']);?><?=$textse;?>
269
						</td>
270
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
271
							<?=$textss;?>
272
							<?php
273
								echo htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway']);
274
							?>
275
							<?=$textse;?>
276
						</td>
277
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
278
							<?=$textss;?>
279
							<?php
280
								echo convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface']) . " ";
281
							?>
282
							<?=$textse;?>
283
						</td>
284
						<td class="listbg" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
285
							<?=$textss;?><?=htmlspecialchars($route['descr']);?>&nbsp;<?=$textse;?>
286
						</td>
287
						<td class="list nowrap" valign="middle">
288
							<table border="0" cellspacing="0" cellpadding="1" summary="move">
289
								<tr>
290
									<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
											title="<?=gettext("move selected routes before this route");?>"
294
											type="image" style="height:17;width:17;border:0" />
295
									</td>
296
									<td>
297
										<a href="system_routes_edit.php?id=<?=$i;?>">
298
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="<?=gettext("edit route");?>" alt="edit" />
299
										</a>
300
									</td>
301
								</tr>
302
								<tr>
303
									<td align="center" valign="middle">
304
										<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
										</a>
307
									</td>
308
									<td>
309
										<a href="system_routes_edit.php?dup=<?=$i;?>">
310
											<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
										</a>
312
									</td>
313
								</tr>
314
							</table>
315
						</td>
316
					</tr>
317
					<?php $i++; endforeach; ?>
318
					<tr>
319
						<td class="list" colspan="6"></td>
320
						<td class="list nowrap" valign="middle">
321
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
322
								<tr>
323
									<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
											title="<?=gettext("delete selected routes");?>" border="0" alt="delete" />
352
<?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
								</tr>
363
							</table>
364
						</td>
365
					</tr>
366
				</table>
367
			</div>
368
		</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
<?php include("fend.inc"); ?>
374
</body>
375
</html>
(227-227/256)