Project

General

Profile

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

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

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

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

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

    
83
if ($_POST) {
84

    
85
	$pconfig = $_POST;
86

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

    
89
		$retval = 0;
90

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

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

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

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

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

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

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

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

    
141
	unset($targets);
142
}
143

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

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

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

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

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

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

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

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

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

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

    
251
include("head.inc");
252

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

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

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

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

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

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

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

    
328
include("foot.inc");
(202-202/228)