Project

General

Profile

Download (10.3 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
##|+PRIV
60
##|*IDENT=page-system-staticroutes
61
##|*NAME=System: Static Routes
62
##|*DESCR=Allow access to the 'System: Static Routes' page.
63
##|*MATCH=system_routes.php*
64
##|-PRIV
65

    
66
require("guiconfig.inc");
67
require_once("functions.inc");
68
require_once("filter.inc");
69
require_once("shaper.inc");
70

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

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

    
80
if ($_POST) {
81

    
82
	$pconfig = $_POST;
83

    
84
	if ($_POST['apply']) {
85

    
86
		$retval = 0;
87

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

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

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

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

    
109
function delete_static_route($id) {
110
	global $config, $a_routes, $changedesc_prefix;
111

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

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

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

    
138
	unset($targets);
139
}
140

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

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

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

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

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

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

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

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

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

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

    
249
include("head.inc");
250

    
251
if ($input_errors) {
252
	print_input_errors($input_errors);
253
}
254
if ($savemsg) {
255
	print_info_box($savemsg, 'success');
256
}
257
if (is_subsystem_dirty('staticroutes')) {
258
	print_apply_box(gettext("The static route configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
259
}
260

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

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

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

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

    
321
					</td>
322
				</tr>
323
<?php endforeach; ?>
324
			</table>
325
		</div>
326
	</div>
327
</div>
328

    
329
<nav class="action-buttons">
330
	<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
331
		<i class="fa fa-plus icon-embed-btn"></i>
332
		<?=gettext("Add")?>
333
	</a>
334
</nav>
335
<?php
336

    
337
include("foot.inc");
(203-203/225)