Project

General

Profile

Download (8.38 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
if ($input_errors)
229
	print_input_errors($input_errors);
230
if ($savemsg)
231
	print_info_box($savemsg);
232
if (is_subsystem_dirty('staticroutes'))
233
	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."));
234

    
235
$tab_array = array();
236
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
237
$tab_array[1] = array(gettext("Routes"), true, "system_routes.php");
238
$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
239
display_top_tabs($tab_array);
240

    
241
?>
242
<table class="table">
243
<thead>
244
	<tr>
245
		<th></th>
246
		<th><?=gettext("Network")?></th>
247
		<th><?=gettext("Gateway")?></th>
248
		<th><?=gettext("Interface")?></th>
249
		<th><?=gettext("Description")?></th>
250
		<th></th>
251
	</tr>
252
</thead>
253
<tbody>
254
<?php
255
foreach ($a_routes as $i => $route):
256
	if (isset($route['disabled']))
257
		$icon = 'icon-ban-circle';
258
	else
259
		$icon = 'icon-ok-circle';
260
?>
261
	<tr<?=($icon != 'icon-ok-circle')? ' class="disabled"' : ''?>>
262
		<td><i class="icon <?=$icon?>"></i></td>
263
		<td>
264
			<?=strtolower($route['network'])?>
265
		</td>
266
		<td>
267
			<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
268
		</td>
269
		<td>
270
			<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
271
		</td>
272
		<td>
273
			<?=htmlspecialchars($route['descr'])?>
274
		</td>
275
		<td>
276
			<a class="btn btn-xs btn-primary" href="system_routes_edit.php?id=<?=$i?>">
277
				edit
278
			</a>
279

    
280
			<a class="btn btn-xs btn-default" href="system_routes_edit.php?dup=<?=$i?>">
281
				copy
282
			</a>
283

    
284
			<a class="btn btn-xs btn-danger" href="system_routes.php?act=del&amp;id=<?=$i?>">
285
				delete
286
			</a>
287

    
288
			<a class="btn btn-xs btn-default" href="?act=toggle&amp;id=<?=$i?>">
289
				toggle
290
			</a>
291
		</td>
292
<? endforeach?>
293
	</tr>
294
</table>
295

    
296
<nav class="action-buttons">
297
	<a href="system_routes_edit.php" role="button" class="btn btn-success">
298
		<?=gettext("add new route")?>
299
	</a>
300
</nav>
301
<?php
302

    
303
include("foot.inc");
(210-210/235)