Project

General

Profile

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

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

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

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

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

    
79
if ($_POST) {
80

    
81
	$pconfig = $_POST;
82

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

    
85
		$retval = 0;
86

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

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

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

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

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

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

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

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

    
137
	unset($targets);
138
}
139

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

    
151
if (isset($_POST['del_x'])) {
152
	/* delete selected routes */
153
	if (is_array($_POST['route']) && count($_POST['route'])) {
154
		$deleted_routes = "";
155
		foreach ($_POST['route'] as $routei) {
156
			$deleted_routes .= " " . $a_routes[$routei]['network'];
157
			delete_static_route($routei);
158
			unset($a_routes[$routei]);
159
		}
160
		$changedesc = $changedesc_prefix . sprintf(gettext("removed route to%s"), $deleted_routes);
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 . sprintf(gettext("gateway is disabled, cannot enable route to %s"), $a_routes[$_GET['id']]['network']);
174
			} else {
175
				unset($a_routes[$_GET['id']]['disabled']);
176
				$changedesc = $changedesc_prefix . sprintf(gettext("enabled route to %s"), $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 . sprintf(gettext("disabled route to %s"), $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("The changes must be applied 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 table-rowdblclickedit">
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 route')?>"></a>
307

    
308
						<a href="system_routes_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy route')?>"></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 route')?>"></a>
313
				<?php } else {
314
				?>
315
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable route')?>"></a>
316
				<?php }
317
				?>
318
						<a href="system_routes.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete route')?>"></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");
(202-202/225)