Project

General

Profile

Download (7.87 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
if ($input_errors)
205
	print_input_errors($input_errors);
206
if ($savemsg)
207
	print_info_box($savemsg);
208
if (is_subsystem_dirty('staticroutes'))
209
	print_info_box_np(gettext("The static route configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
210

    
211
$tab_array = array();
212
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
213
$tab_array[1] = array(gettext("Routes"), true, "system_routes.php");
214
$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
215
display_top_tabs($tab_array);
216

    
217
?>
218
<table class="table">
219
<thead>
220
	<tr>
221
		<th></th>
222
		<th><?=gettext("Network")?></th>
223
		<th><?=gettext("Gateway")?></th>
224
		<th><?=gettext("Interface")?></th>
225
		<th><?=gettext("Description")?></th>
226
		<th></th>
227
	</tr>
228
</thead>
229
<tbody>
230
<?php
231
foreach ($a_routes as $i => $route):
232
	if (isset($route['disabled']))
233
		$icon = 'icon-ban-circle';
234
	else
235
		$icon = 'icon-ok-circle';
236
?>
237
	<tr<?=($icon != 'icon-ok-circle')? ' class="disabled"' : ''?>>
238
		<td><i class="icon <?=$icon?>"></i></td>
239
		<td>
240
			<?=strtolower($route['network'])?>
241
		</td>
242
		<td>
243
			<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
244
		</td>
245
		<td>
246
			<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
247
		</td>
248
		<td>
249
			<?=htmlspecialchars($route['descr'])?>
250
		</td>
251
		<td>
252
			<a class="btn btn-xs btn-primary" href="system_routes_edit.php?id=<?=$i?>">
253
				edit
254
			</a>
255

    
256
			<a class="btn btn-xs btn-default" href="system_routes_edit.php?dup=<?=$i?>">
257
				copy
258
			</a>
259

    
260
			<a class="btn btn-xs btn-danger" href="system_routes.php?act=del&amp;id=<?=$i?>">
261
				delete
262
			</a>
263

    
264
			<a class="btn btn-xs btn-default" href="?act=toggle&amp;id=<?=$i?>">
265
				toggle
266
			</a>
267
		</td>
268
<? endforeach?>
269
	</tr>
270
</table>
271

    
272
<nav class="action-buttons">
273
	<a href="system_routes_edit.php" role="button" class="btn btn-success">
274
		<?=gettext("add new route")?>
275
	</a>
276
</nav>
277
<?php
278

    
279
include("foot.inc");
(213-213/241)