Project

General

Profile

Download (13.6 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

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

    
58
if ($_POST) {
59

    
60
	$pconfig = $_POST;
61

    
62
	if ($_POST['apply']) {
63

    
64
		$retval = 0;
65

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

    
72
			@unlink("{$g['tmp_path']}/.system_routes.apply");
73
		}
74

    
75
		$retval = system_routing_configure();
76
		$retval |= filter_configure();
77
		/* reconfigure our gateway monitor */
78
		setup_gateways_monitor();
79

    
80
		$savemsg = get_std_save_message($retval);
81
		if ($retval == 0) {
82
			clear_subsystem_dirty('staticroutes');
83
		}
84
	}
85
}
86

    
87
function delete_static_route($id) {
88
	global $config, $a_routes, $changedesc_prefix;
89

    
90
	if (!isset($a_routes[$id])) {
91
		return;
92
	}
93

    
94
	$targets = array();
95
	if (is_alias($a_routes[$id]['network'])) {
96
		foreach (filter_expand_alias_array($a_routes[$id]['network']) as $tgt) {
97
			if (is_ipaddrv4($tgt)) {
98
				$tgt .= "/32";
99
			} else if (is_ipaddrv6($tgt)) {
100
				$tgt .= "/128";
101
			}
102
			if (!is_subnet($tgt)) {
103
				continue;
104
			}
105
			$targets[] = $tgt;
106
		}
107
	} else {
108
		$targets[] = $a_routes[$id]['network'];
109
	}
110

    
111
	foreach ($targets as $tgt) {
112
		$family = (is_subnetv6($tgt) ? "-inet6" : "-inet");
113
		mwexec("/sbin/route delete {$family} " . escapeshellarg($tgt));
114
	}
115

    
116
	unset($targets);
117
}
118

    
119
if ($_GET['act'] == "del") {
120
	if ($a_routes[$_GET['id']]) {
121
		$changedesc = $changedesc_prefix . gettext("removed route to") . " " . $a_routes[$_GET['id']]['network'];
122
		delete_static_route($_GET['id']);
123
		unset($a_routes[$_GET['id']]);
124
		write_config($changedesc);
125
		header("Location: system_routes.php");
126
		exit;
127
	}
128
}
129

    
130
if (isset($_POST['del_x'])) {
131
	/* delete selected routes */
132
	if (is_array($_POST['route']) && count($_POST['route'])) {
133
		$changedesc = $changedesc_prefix . gettext("removed route to");
134
		foreach ($_POST['route'] as $routei) {
135
			$changedesc .= " " . $a_routes[$routei]['network'];
136
			delete_static_route($routei);
137
			unset($a_routes[$routei]);
138
		}
139
		write_config($changedesc);
140
		header("Location: system_routes.php");
141
		exit;
142
	}
143

    
144
} else if ($_GET['act'] == "toggle") {
145
	if ($a_routes[$_GET['id']]) {
146
		$do_update_config = true;
147
		if (isset($a_routes[$_GET['id']]['disabled'])) {
148
			// Do not enable a route whose gateway is disabled
149
			if (isset($a_gateways[$a_routes[$_GET['id']]['gateway']]['disabled'])) {
150
				$do_update_config = false;
151
				$input_errors[] = $changedesc_prefix . gettext("gateway is disabled, cannot enable route to") . " " . $a_routes[$_GET['id']]['network'];
152
			} else {
153
				unset($a_routes[$_GET['id']]['disabled']);
154
				$changedesc = $changedesc_prefix . gettext("enabled route to") . " " . $a_routes[$_GET['id']]['network'];
155
			}
156
		} else {
157
			delete_static_route($_GET['id']);
158
			$a_routes[$_GET['id']]['disabled'] = true;
159
			$changedesc = $changedesc_prefix . gettext("disabled route to") . " " . $a_routes[$_GET['id']]['network'];
160
		}
161

    
162
		if ($do_update_config) {
163
			if (write_config($changedesc)) {
164
				mark_subsystem_dirty('staticroutes');
165
			}
166
			header("Location: system_routes.php");
167
			exit;
168
		}
169
	}
170
} else {
171
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
172
	unset($movebtn);
173
	foreach ($_POST as $pn => $pd) {
174
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
175
			$movebtn = $matches[1];
176
			break;
177
		}
178
	}
179
	/* move selected routes before this route */
180
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
181
		$a_routes_new = array();
182

    
183
		/* copy all routes < $movebtn and not selected */
184
		for ($i = 0; $i < $movebtn; $i++) {
185
			if (!in_array($i, $_POST['route'])) {
186
				$a_routes_new[] = $a_routes[$i];
187
			}
188
		}
189

    
190
		/* copy all selected routes */
191
		for ($i = 0; $i < count($a_routes); $i++) {
192
			if ($i == $movebtn) {
193
				continue;
194
			}
195
			if (in_array($i, $_POST['route'])) {
196
				$a_routes_new[] = $a_routes[$i];
197
			}
198
		}
199

    
200
		/* copy $movebtn route */
201
		if ($movebtn < count($a_routes)) {
202
			$a_routes_new[] = $a_routes[$movebtn];
203
		}
204

    
205
		/* copy all routes > $movebtn and not selected */
206
		for ($i = $movebtn+1; $i < count($a_routes); $i++) {
207
			if (!in_array($i, $_POST['route'])) {
208
				$a_routes_new[] = $a_routes[$i];
209
			}
210
		}
211
		if (count($a_routes_new) > 0) {
212
			$a_routes = $a_routes_new;
213
		}
214

    
215
		if (write_config()) {
216
			mark_subsystem_dirty('staticroutes');
217
		}
218
		header("Location: system_routes.php");
219
		exit;
220
	}
221
}
222

    
223
$pgtitle = array(gettext("System"), gettext("Static Routes"));
224
$shortcut_section = "routing";
225

    
226
include("head.inc");
227

    
228
?>
229

    
230
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
231
<?php include("fbegin.inc"); ?>
232
<form action="system_routes.php" method="post">
233
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
234
<?php if ($savemsg) print_info_box($savemsg); ?>
235
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
236
<?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>
237
<?php endif; ?>
238
<?php if ($input_errors) print_input_errors($input_errors); ?>
239

    
240
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system routes">
241
	<tr>
242
		<td>
243
		<?php
244
			$tab_array = array();
245
			$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
246
			$tab_array[1] = array(gettext("Routes"), true, "system_routes.php");
247
			$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
248
			display_top_tabs($tab_array);
249
		?>
250
		</td>
251
	</tr>
252
	<tr>
253
		<td>
254
			<div id="mainarea">
255
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
256
					<tr id="frheader">
257
						<td width="2%" class="list">&nbsp;</td>
258
						<td width="2%" class="list">&nbsp;</td>
259
						<td width="22%" class="listhdrr"><?=gettext("Network");?></td>
260
						<td width="20%" class="listhdrr"><?=gettext("Gateway");?></td>
261
						<td width="15%" class="listhdrr"><?=gettext("Interface");?></td>
262
						<td width="29%" class="listhdr"><?=gettext("Description");?></td>
263
						<td width="10%" class="list">
264
							<table border="0" cellspacing="0" cellpadding="1" summary="add">
265
								<tr>
266
									<td width="17"></td>
267
									<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>
268
								</tr>
269
							</table>
270
						</td>
271
					</tr>
272
					<?php
273
					$i = 0;
274
					foreach ($a_routes as $route):
275
					?>
276
					<tr valign="top" id="fr<?=$i;?>">
277
					<?php
278
						$iconfn = "pass";
279
						if (isset($route['disabled'])) {
280
							$textss = "<span class=\"gray\">";
281
							$textse = "</span>";
282
							$iconfn .= "_d";
283
						} else {
284
							$textss = $textse = "";
285
						}
286
					?>
287
						<td class="listt">
288
							<input type="checkbox" id="frc<?=$i;?>" name="route[]" value="<?=$i;?>" onclick="fr_bgcolor('<?=$i;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;" />
289
						</td>
290
						<td class="listt" align="center">
291
							<a href="?act=toggle&amp;id=<?=$i;?>">
292
								<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0"
293
									title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" />
294
							</a>
295
						</td>
296
						<td class="listlr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
297
							<?=$textss;?><?=strtolower($route['network']);?><?=$textse;?>
298
						</td>
299
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
300
							<?=$textss;?>
301
							<?php
302
								echo htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway']);
303
							?>
304
							<?=$textse;?>
305
						</td>
306
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
307
							<?=$textss;?>
308
							<?php
309
								echo convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface']) . " ";
310
							?>
311
							<?=$textse;?>
312
						</td>
313
						<td class="listbg" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
314
							<?=$textss;?><?=htmlspecialchars($route['descr']);?>&nbsp;<?=$textse;?>
315
						</td>
316
						<td class="list nowrap" valign="middle">
317
							<table border="0" cellspacing="0" cellpadding="1" summary="move">
318
								<tr>
319
									<td>
320
										<input onmouseover="fr_insline(<?=$i;?>, true)" onmouseout="fr_insline(<?=$i;?>, false)" name="move_<?=$i;?>"
321
											src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif"
322
											title="<?=gettext("move selected routes before this route");?>"
323
											type="image" style="height:17;width:17;border:0" />
324
									</td>
325
									<td>
326
										<a href="system_routes_edit.php?id=<?=$i;?>">
327
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="<?=gettext("edit route");?>" alt="edit" />
328
										</a>
329
									</td>
330
								</tr>
331
								<tr>
332
									<td align="center" valign="middle">
333
										<a href="system_routes.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this route?");?>')">
334
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("delete route");?>" alt="delete" />
335
										</a>
336
									</td>
337
									<td>
338
										<a href="system_routes_edit.php?dup=<?=$i;?>">
339
											<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" />
340
										</a>
341
									</td>
342
								</tr>
343
							</table>
344
						</td>
345
					</tr>
346
					<?php
347
						$i++;
348
					endforeach;
349
					?>
350
					<tr>
351
						<td class="list" colspan="6"></td>
352
						<td class="list nowrap" valign="middle">
353
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
354
								<tr>
355
									<td>
356
<?php
357
									if ($i == 0):
358
?>
359
										<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17"
360
											title="<?=gettext("move selected routes to end");?>" border="0" alt="move" />
361
<?php
362
									else:
363
?>
364
										<input name="move_<?=$i;?>" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif"
365
											style="width:17;height:17;border:0" title="<?=gettext("move selected routes to end");?>" />
366
<?php
367
									endif;
368
?>
369
									</td>
370
									<td>
371
										<a href="system_routes_edit.php">
372
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"
373
											title="<?=gettext("add new route");?>" alt="add" />
374
										</a>
375
									</td>
376
								</tr>
377
								<tr>
378
									<td>
379
<?php
380
									if ($i == 0):
381
?>
382
										<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17"
383
											title="<?=gettext("delete selected routes");?>" border="0" alt="delete" />
384
<?php
385
									else:
386
?>
387
										<input name="del" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif"
388
											style="width:17;height:17" title="<?=gettext("delete selected routes");?>"
389
											onclick="return confirm('<?=gettext("Do you really want to delete the selected routes?");?>')" />
390
<?php
391
									endif;
392
?>
393
									</td>
394
								</tr>
395
							</table>
396
						</td>
397
					</tr>
398
				</table>
399
			</div>
400
		</td>
401
	</tr>
402
</table>
403
</form>
404
<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>
405
<?php include("fend.inc"); ?>
406
</body>
407
</html>
(223-223/252)