Project

General

Profile

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

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

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

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

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

    
82
if ($_POST) {
83

    
84
	$pconfig = $_POST;
85

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

    
88
		$retval = 0;
89

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

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

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

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

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

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

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

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

    
140
	unset($targets);
141
}
142

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

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

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

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

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

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

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

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

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

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

    
250
include("head.inc");
251

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

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

    
265
?>
266
<table class="table">
267
<thead>
268
	<tr>
269
		<th></th>
270
		<th><?=gettext("Network")?></th>
271
		<th><?=gettext("Gateway")?></th>
272
		<th><?=gettext("Interface")?></th>
273
		<th><?=gettext("Description")?></th>
274
		<th><?=gettext("Actions")?></th>
275
	</tr>
276
</thead>
277
<tbody>
278
<?php
279
foreach ($a_routes as $i => $route):
280
	if (isset($route['disabled']))
281
		$icon = 'icon-ban-circle';
282
	else
283
		$icon = 'icon-ok-circle';
284
?>
285
	<tr<?=($icon != 'icon-ok-circle')? ' class="disabled"' : ''?>>
286
		<td><i class="icon <?=$icon?>"></i></td>
287
		<td>
288
			<?=strtolower($route['network'])?>
289
		</td>
290
		<td>
291
			<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
292
		</td>
293
		<td>
294
			<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
295
		</td>
296
		<td>
297
			<?=htmlspecialchars($route['descr'])?>
298
		</td>
299
		<td>
300
			<a href="system_routes_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
301
			
302
			<a href="system_routes_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
303
			
304
	<?php if (isset($route['disabled'])) {
305
	?>	
306
			<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
307
	<?php } else {
308
	?>
309
			<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
310
	<?php }
311
	?>		
312
			<a href="system_routes.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete')?>" onclick="return confirm('<?=gettext("Are you sure you want to delete this route?")?>')"></a>
313

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

    
319
<nav class="action-buttons">
320
	<a href="system_routes_edit.php" role="button" class="btn btn-success">
321
		<?=gettext("add new route")?>
322
	</a>
323
</nav>
324
<?php
325

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