Project

General

Profile

Download (9.82 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_routes.php
5
*/
6
/* ====================================================================
7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *
9
 *  Some or all of this file is based on the m0n0wall project which is
10
 *  Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
11
 *
12
 *	Redistribution and use in source and binary forms, with or without modification,
13
 *	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
20
 *		the documentation and/or other materials provided with the
21
 *		distribution.
22
 *
23
 *	3. All advertising materials mentioning features or use of this software
24
 *		must display the following acknowledgment:
25
 *		"This product includes software developed by the pfSense Project
26
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
27
 *
28
 *	4. The names "pfSense" and "pfSense Project" must not be used to
29
 *		 endorse or promote products derived from this software without
30
 *		 prior written permission. For written permission, please contact
31
 *		 coreteam@pfsense.org.
32
 *
33
 *	5. Products derived from this software may not be called "pfSense"
34
 *		nor may "pfSense" appear in their names without prior written
35
 *		permission of the Electric Sheep Fencing, LLC.
36
 *
37
 *	6. Redistributions of any form whatsoever must retain the following
38
 *		acknowledgment:
39
 *
40
 *	"This product includes software developed by the pfSense Project
41
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
42
 *
43
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
44
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
47
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
55
 *
56
 *	====================================================================
57
 *
58
 */
59
/*
60
	pfSense_MODULE:	routing
61
*/
62

    
63
##|+PRIV
64
##|*IDENT=page-system-staticroutes
65
##|*NAME=System: Static Routes page
66
##|*DESCR=Allow access to the 'System: Static Routes' page.
67
##|*MATCH=system_routes.php*
68
##|-PRIV
69

    
70
require("guiconfig.inc");
71
require_once("functions.inc");
72
require_once("filter.inc");
73
require_once("shaper.inc");
74

    
75
if (!is_array($config['staticroutes']['route'])) {
76
	$config['staticroutes']['route'] = array();
77
}
78

    
79
$a_routes = &$config['staticroutes']['route'];
80
$a_gateways = return_gateways_array(true, true, true);
81
$changedesc_prefix = gettext("Static Routes") . ": ";
82
unset($input_errors);
83

    
84
if ($_POST) {
85

    
86
	$pconfig = $_POST;
87

    
88
	if ($_POST['apply']) {
89

    
90
		$retval = 0;
91

    
92
		if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
93
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
94
			foreach ($toapplylist as $toapply) {
95
				mwexec("{$toapply}");
96
			}
97

    
98
			@unlink("{$g['tmp_path']}/.system_routes.apply");
99
		}
100

    
101
		$retval = system_routing_configure();
102
		$retval |= filter_configure();
103
		/* reconfigure our gateway monitor */
104
		setup_gateways_monitor();
105

    
106
		$savemsg = get_std_save_message($retval);
107
		if ($retval == 0) {
108
			clear_subsystem_dirty('staticroutes');
109
		}
110
	}
111
}
112

    
113
function delete_static_route($id) {
114
	global $config, $a_routes, $changedesc_prefix;
115

    
116
	if (!isset($a_routes[$id])) {
117
		return;
118
	}
119

    
120
	$targets = array();
121
	if (is_alias($a_routes[$id]['network'])) {
122
		foreach (filter_expand_alias_array($a_routes[$id]['network']) as $tgt) {
123
			if (is_ipaddrv4($tgt)) {
124
				$tgt .= "/32";
125
			} else if (is_ipaddrv6($tgt)) {
126
				$tgt .= "/128";
127
			}
128
			if (!is_subnet($tgt)) {
129
				continue;
130
			}
131
			$targets[] = $tgt;
132
		}
133
	} else {
134
		$targets[] = $a_routes[$id]['network'];
135
	}
136

    
137
	foreach ($targets as $tgt) {
138
		$family = (is_subnetv6($tgt) ? "-inet6" : "-inet");
139
		mwexec("/sbin/route delete {$family} " . escapeshellarg($tgt));
140
	}
141

    
142
	unset($targets);
143
}
144

    
145
if ($_GET['act'] == "del") {
146
	if ($a_routes[$_GET['id']]) {
147
		$changedesc = $changedesc_prefix . gettext("removed route to") . " " . $a_routes[$_GET['id']]['network'];
148
		delete_static_route($_GET['id']);
149
		unset($a_routes[$_GET['id']]);
150
		write_config($changedesc);
151
		header("Location: system_routes.php");
152
		exit;
153
	}
154
}
155

    
156
if (isset($_POST['del_x'])) {
157
	/* delete selected routes */
158
	if (is_array($_POST['route']) && count($_POST['route'])) {
159
		$changedesc = $changedesc_prefix . gettext("removed route to");
160
		foreach ($_POST['route'] as $routei) {
161
			$changedesc .= " " . $a_routes[$routei]['network'];
162
			delete_static_route($routei);
163
			unset($a_routes[$routei]);
164
		}
165
		write_config($changedesc);
166
		header("Location: system_routes.php");
167
		exit;
168
	}
169

    
170
} else if ($_GET['act'] == "toggle") {
171
	if ($a_routes[$_GET['id']]) {
172
		$do_update_config = true;
173
		if (isset($a_routes[$_GET['id']]['disabled'])) {
174
			// Do not enable a route whose gateway is disabled
175
			if (isset($a_gateways[$a_routes[$_GET['id']]['gateway']]['disabled'])) {
176
				$do_update_config = false;
177
				$input_errors[] = $changedesc_prefix . gettext("gateway is disabled, cannot enable route to") . " " . $a_routes[$_GET['id']]['network'];
178
			} else {
179
				unset($a_routes[$_GET['id']]['disabled']);
180
				$changedesc = $changedesc_prefix . gettext("enabled route to") . " " . $a_routes[$_GET['id']]['network'];
181
			}
182
		} else {
183
			delete_static_route($_GET['id']);
184
			$a_routes[$_GET['id']]['disabled'] = true;
185
			$changedesc = $changedesc_prefix . gettext("disabled route to") . " " . $a_routes[$_GET['id']]['network'];
186
		}
187

    
188
		if ($do_update_config) {
189
			if (write_config($changedesc)) {
190
				mark_subsystem_dirty('staticroutes');
191
			}
192
			header("Location: system_routes.php");
193
			exit;
194
		}
195
	}
196
} else {
197
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
198
	unset($movebtn);
199
	foreach ($_POST as $pn => $pd) {
200
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
201
			$movebtn = $matches[1];
202
			break;
203
		}
204
	}
205
	/* move selected routes before this route */
206
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
207
		$a_routes_new = array();
208

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

    
216
		/* copy all selected routes */
217
		for ($i = 0; $i < count($a_routes); $i++) {
218
			if ($i == $movebtn) {
219
				continue;
220
			}
221
			if (in_array($i, $_POST['route'])) {
222
				$a_routes_new[] = $a_routes[$i];
223
			}
224
		}
225

    
226
		/* copy $movebtn route */
227
		if ($movebtn < count($a_routes)) {
228
			$a_routes_new[] = $a_routes[$movebtn];
229
		}
230

    
231
		/* copy all routes > $movebtn and not selected */
232
		for ($i = $movebtn+1; $i < count($a_routes); $i++) {
233
			if (!in_array($i, $_POST['route'])) {
234
				$a_routes_new[] = $a_routes[$i];
235
			}
236
		}
237
		if (count($a_routes_new) > 0) {
238
			$a_routes = $a_routes_new;
239
		}
240

    
241
		if (write_config()) {
242
			mark_subsystem_dirty('staticroutes');
243
		}
244
		header("Location: system_routes.php");
245
		exit;
246
	}
247
}
248

    
249
$pgtitle = array(gettext("System"), gettext("Static Routes"));
250
$shortcut_section = "routing";
251

    
252
include("head.inc");
253

    
254
if ($input_errors)
255
	print_input_errors($input_errors);
256
if ($savemsg)
257
	print_info_box($savemsg);
258
if (is_subsystem_dirty('staticroutes'))
259
	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."));
260

    
261
$tab_array = array();
262
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
263
$tab_array[1] = array(gettext("Routes"), true, "system_routes.php");
264
$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
265
display_top_tabs($tab_array);
266

    
267
?>
268
<table class="table">
269
<thead>
270
	<tr>
271
		<th></th>
272
		<th><?=gettext("Network")?></th>
273
		<th><?=gettext("Gateway")?></th>
274
		<th><?=gettext("Interface")?></th>
275
		<th><?=gettext("Description")?></th>
276
		<th><?=gettext("Actions")?></th>
277
	</tr>
278
</thead>
279
<tbody>
280
<?php
281
foreach ($a_routes as $i => $route):
282
	if (isset($route['disabled']))
283
		$icon = 'icon-ban-circle';
284
	else
285
		$icon = 'icon-ok-circle';
286
?>
287
	<tr<?=($icon != 'icon-ok-circle')? ' class="disabled"' : ''?>>
288
		<td><i class="icon <?=$icon?>"></i></td>
289
		<td>
290
			<?=strtolower($route['network'])?>
291
		</td>
292
		<td>
293
			<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
294
		</td>
295
		<td>
296
			<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
297
		</td>
298
		<td>
299
			<?=htmlspecialchars($route['descr'])?>
300
		</td>
301
		<td>
302
			<a href="system_routes_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
303

    
304
			<a href="system_routes_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
305

    
306
	<?php if (isset($route['disabled'])) {
307
	?>
308
			<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
309
	<?php } else {
310
	?>
311
			<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
312
	<?php }
313
	?>
314
			<a href="system_routes.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete')?>"></a>
315

    
316
		</td>
317
<? endforeach?>
318
	</tr>
319
</table>
320

    
321
<nav class="action-buttons">
322
	<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
323
		<i class="fa fa-plus icon-embed-btn"></i>
324
		<?=gettext("Add")?>
325
	</a>
326
</nav>
327
<?php
328

    
329
include("foot.inc");
(209-209/234)