Project

General

Profile

Download (10.2 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 . gettext("removed route to") . " " . $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
		$changedesc = $changedesc_prefix . gettext("removed route to");
156
		foreach ($_POST['route'] as $routei) {
157
			$changedesc .= " " . $a_routes[$routei]['network'];
158
			delete_static_route($routei);
159
			unset($a_routes[$routei]);
160
		}
161
		write_config($changedesc);
162
		header("Location: system_routes.php");
163
		exit;
164
	}
165

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

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

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

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

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

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

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

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

    
248
include("head.inc");
249

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

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

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

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

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

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

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

    
336
include("foot.inc");
(205-205/229)