Project

General

Profile

Download (8.79 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 4a5ac5e0 Phil Davis
/*
3 c5d81585 Renato Botelho
 * system_routes.php
4 191cb31d Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 c0411930 Stephen Beaver
 *
11 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14 c0411930 Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18 c0411930 Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
20 c0411930 Stephen Beaver
 *
21 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26 c0411930 Stephen Beaver
 */
27 5b237745 Scott Ullrich
28 6b07c15a Matthew Grooms
##|+PRIV
29
##|*IDENT=page-system-staticroutes
30 5230f468 jim-p
##|*NAME=System: Static Routes
31 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'System: Static Routes' page.
32
##|*MATCH=system_routes.php*
33
##|-PRIV
34
35 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
36 7a927e67 Scott Ullrich
require_once("functions.inc");
37
require_once("filter.inc");
38
require_once("shaper.inc");
39 5b237745 Scott Ullrich
40 c6c398c6 jim-p
init_config_arr(array('staticroutes', 'route'));
41 5b237745 Scott Ullrich
$a_routes = &$config['staticroutes']['route'];
42 70cb0375 Renato Botelho
$a_gateways = return_gateways_array(true, true, true);
43
$changedesc_prefix = gettext("Static Routes") . ": ";
44 028ff8f8 Phil Davis
unset($input_errors);
45 5b237745 Scott Ullrich
46 ddd3ffaf Steve Beaver
if ($_POST['apply']) {
47 5b237745 Scott Ullrich
	$pconfig = $_POST;
48 ddd3ffaf Steve Beaver
	$retval = 0;
49 5b237745 Scott Ullrich
50 ddd3ffaf Steve Beaver
	if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
51
		$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
52
		foreach ($toapplylist as $toapply) {
53
			mwexec("{$toapply}");
54 e8471084 Ermal
		}
55
56 ddd3ffaf Steve Beaver
		@unlink("{$g['tmp_path']}/.system_routes.apply");
57
	}
58
59
	$retval |= system_routing_configure();
60
	$retval |= filter_configure();
61
	/* reconfigure our gateway monitor */
62
	setup_gateways_monitor();
63 3851094f Scott Ullrich
64 ddd3ffaf Steve Beaver
	if ($retval == 0) {
65
		clear_subsystem_dirty('staticroutes');
66 5b237745 Scott Ullrich
	}
67
}
68
69 ddd3ffaf Steve Beaver
if ($_POST['act'] == "del") {
70
	if ($a_routes[$_POST['id']]) {
71
		$changedesc = $changedesc_prefix . sprintf(gettext("removed route to %s"), $a_routes[$_POST['id']]['network']);
72 332052b8 Viktor G
		delete_static_route($_POST['id'], true);
73 ddd3ffaf Steve Beaver
		unset($a_routes[$_POST['id']]);
74 70cb0375 Renato Botelho
		write_config($changedesc);
75 332052b8 Viktor G
		mark_subsystem_dirty('staticroutes');
76 70cb0375 Renato Botelho
		header("Location: system_routes.php");
77
		exit;
78
	}
79
}
80
81
if (isset($_POST['del_x'])) {
82
	/* delete selected routes */
83
	if (is_array($_POST['route']) && count($_POST['route'])) {
84 762faef5 Phil Davis
		$deleted_routes = "";
85 70cb0375 Renato Botelho
		foreach ($_POST['route'] as $routei) {
86 762faef5 Phil Davis
			$deleted_routes .= " " . $a_routes[$routei]['network'];
87 332052b8 Viktor G
			delete_static_route($routei, true);
88 70cb0375 Renato Botelho
			unset($a_routes[$routei]);
89
		}
90 762faef5 Phil Davis
		$changedesc = $changedesc_prefix . sprintf(gettext("removed route to%s"), $deleted_routes);
91 70cb0375 Renato Botelho
		write_config($changedesc);
92 332052b8 Viktor G
		mark_subsystem_dirty('staticroutes');
93 70cb0375 Renato Botelho
		header("Location: system_routes.php");
94
		exit;
95
	}
96 4611e283 Steve Beaver
}
97
98
if ($_POST['act'] == "toggle") {
99 ddd3ffaf Steve Beaver
	if ($a_routes[$_POST['id']]) {
100 028ff8f8 Phil Davis
		$do_update_config = true;
101 ddd3ffaf Steve Beaver
		if (isset($a_routes[$_POST['id']]['disabled'])) {
102 028ff8f8 Phil Davis
			// Do not enable a route whose gateway is disabled
103 ddd3ffaf Steve Beaver
			if (isset($a_gateways[$a_routes[$_POST['id']]['gateway']]['disabled'])) {
104 028ff8f8 Phil Davis
				$do_update_config = false;
105 ddd3ffaf Steve Beaver
				$input_errors[] = $changedesc_prefix . sprintf(gettext("gateway is disabled, cannot enable route to %s"), $a_routes[$_POST['id']]['network']);
106 028ff8f8 Phil Davis
			} else {
107 ddd3ffaf Steve Beaver
				unset($a_routes[$_POST['id']]['disabled']);
108
				$changedesc = $changedesc_prefix . sprintf(gettext("enabled route to %s"), $a_routes[$_POST['id']]['network']);
109 028ff8f8 Phil Davis
			}
110 25c3f30c Renato Botelho
		} else {
111 ddd3ffaf Steve Beaver
			delete_static_route($_POST['id']);
112
			$a_routes[$_POST['id']]['disabled'] = true;
113
			$changedesc = $changedesc_prefix . sprintf(gettext("disabled route to %s"), $a_routes[$_POST['id']]['network']);
114 9c115b40 Ermal
		}
115 25c3f30c Renato Botelho
116 028ff8f8 Phil Davis
		if ($do_update_config) {
117
			if (write_config($changedesc)) {
118 332052b8 Viktor G
				mark_subsystem_dirty('staticroutes');
119 028ff8f8 Phil Davis
			}
120
			header("Location: system_routes.php");
121
			exit;
122 d38bd840 Phil Davis
		}
123 70cb0375 Renato Botelho
	}
124 4611e283 Steve Beaver
}
125
126
if($_POST['save']) {
127 70cb0375 Renato Botelho
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
128
	unset($movebtn);
129
	foreach ($_POST as $pn => $pd) {
130
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
131
			$movebtn = $matches[1];
132
			break;
133 25c3f30c Renato Botelho
		}
134 70cb0375 Renato Botelho
	}
135
	/* move selected routes before this route */
136
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
137
		$a_routes_new = array();
138 25c3f30c Renato Botelho
139 70cb0375 Renato Botelho
		/* copy all routes < $movebtn and not selected */
140
		for ($i = 0; $i < $movebtn; $i++) {
141 d38bd840 Phil Davis
			if (!in_array($i, $_POST['route'])) {
142 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
143 d38bd840 Phil Davis
			}
144 70cb0375 Renato Botelho
		}
145
146
		/* copy all selected routes */
147
		for ($i = 0; $i < count($a_routes); $i++) {
148 d38bd840 Phil Davis
			if ($i == $movebtn) {
149 70cb0375 Renato Botelho
				continue;
150 d38bd840 Phil Davis
			}
151
			if (in_array($i, $_POST['route'])) {
152 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
153 d38bd840 Phil Davis
			}
154 70cb0375 Renato Botelho
		}
155
156
		/* copy $movebtn route */
157 d38bd840 Phil Davis
		if ($movebtn < count($a_routes)) {
158 70cb0375 Renato Botelho
			$a_routes_new[] = $a_routes[$movebtn];
159 d38bd840 Phil Davis
		}
160 70cb0375 Renato Botelho
161
		/* copy all routes > $movebtn and not selected */
162
		for ($i = $movebtn+1; $i < count($a_routes); $i++) {
163 d38bd840 Phil Davis
			if (!in_array($i, $_POST['route'])) {
164 70cb0375 Renato Botelho
				$a_routes_new[] = $a_routes[$i];
165 d38bd840 Phil Davis
			}
166 70cb0375 Renato Botelho
		}
167 d38bd840 Phil Davis
		if (count($a_routes_new) > 0) {
168 70cb0375 Renato Botelho
			$a_routes = $a_routes_new;
169 d38bd840 Phil Davis
		}
170 70cb0375 Renato Botelho
171 b290e10e doktornotor
		if (write_config(gettext("Saved static routes configuration."))) {
172 70cb0375 Renato Botelho
			mark_subsystem_dirty('staticroutes');
173 d38bd840 Phil Davis
		}
174 25c3f30c Renato Botelho
		header("Location: system_routes.php");
175
		exit;
176 5b237745 Scott Ullrich
	}
177
}
178 7f43ca88 Scott Ullrich
179 d036bc07 Stephen Beaver
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Static Routes"));
180 edcd7535 Phil Davis
$pglinks = array("", "system_gateways.php", "@self");
181 b32dd0a6 jim-p
$shortcut_section = "routing";
182 02ca24c9 jim-p
183 7f43ca88 Scott Ullrich
include("head.inc");
184
185 d61309a0 Phil Davis
if ($input_errors) {
186 f3bb71cf Sjon Hortensius
	print_input_errors($input_errors);
187 d61309a0 Phil Davis
}
188 44c42356 Phil Davis
if ($_POST['apply']) {
189
	print_apply_result_box($retval);
190 d61309a0 Phil Davis
}
191
if (is_subsystem_dirty('staticroutes')) {
192 813c6673 NOYB
	print_apply_box(gettext("The static route configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
193 d61309a0 Phil Davis
}
194 f3bb71cf Sjon Hortensius
195
$tab_array = array();
196
$tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php");
197 c14798d0 heper
$tab_array[1] = array(gettext("Static Routes"), true, "system_routes.php");
198
$tab_array[2] = array(gettext("Gateway Groups"), false, "system_gateway_groups.php");
199 f3bb71cf Sjon Hortensius
display_top_tabs($tab_array);
200 0f282d7a Scott Ullrich
201 f3bb71cf Sjon Hortensius
?>
202 060ed238 Stephen Beaver
<div class="panel panel-default">
203 70dc5cd6 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Static Routes')?></h2></div>
204 060ed238 Stephen Beaver
	<div class="panel-body">
205
		<div class="table-responsive">
206 1c10ce97 PiBa-NL
			<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
207 060ed238 Stephen Beaver
				<thead>
208
					<tr>
209
						<th></th>
210
						<th><?=gettext("Network")?></th>
211
						<th><?=gettext("Gateway")?></th>
212
						<th><?=gettext("Interface")?></th>
213
						<th><?=gettext("Description")?></th>
214
						<th><?=gettext("Actions")?></th>
215
					</tr>
216
				</thead>
217
				<tbody>
218 70cb0375 Renato Botelho
<?php
219 f3bb71cf Sjon Hortensius
foreach ($a_routes as $i => $route):
220 6639718c Viktor G
	if (isset($a_gateways[$route['gateway']]['inactive'])) {
221
		$icon = 'fa-times-circle-o';
222
		$title = gettext("Route inactive, gateway interface is missing");
223
	} elseif (isset($route['disabled'])) {
224 1b7379f9 Jared Dillard
		$icon = 'fa-ban';
225 6639718c Viktor G
		$title = gettext("Route disabled");
226 d61309a0 Phil Davis
	} else {
227 1b7379f9 Jared Dillard
		$icon = 'fa-check-circle-o';
228 6639718c Viktor G
		$title = gettext("Route enabled");
229 d61309a0 Phil Davis
	}
230 70cb0375 Renato Botelho
?>
231 060ed238 Stephen Beaver
				<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
232 6639718c Viktor G
					<td title="<?=$title?>"><i class="fa <?=$icon?>"></i></td>
233 060ed238 Stephen Beaver
					<td>
234
						<?=strtolower($route['network'])?>
235
					</td>
236
					<td>
237
						<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
238
					</td>
239
					<td>
240
						<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
241
					</td>
242
					<td>
243
						<?=htmlspecialchars($route['descr'])?>
244
					</td>
245
					<td>
246 4611e283 Steve Beaver
						<a href="system_routes_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit route')?>"></a>
247 060ed238 Stephen Beaver
248 4611e283 Steve Beaver
						<a href="system_routes_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy route')?>"></a>
249 060ed238 Stephen Beaver
250
				<?php if (isset($route['disabled'])) {
251
				?>
252 ddd3ffaf Steve Beaver
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable route')?>" usepost></a>
253 060ed238 Stephen Beaver
				<?php } else {
254
				?>
255 ddd3ffaf Steve Beaver
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable route')?>" usepost></a>
256 060ed238 Stephen Beaver
				<?php }
257
				?>
258 ddd3ffaf Steve Beaver
						<a href="system_routes.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete route')?>" usepost></a>
259 060ed238 Stephen Beaver
260
					</td>
261
				</tr>
262 fa172bc5 NewEraCracker
<?php endforeach; ?>
263 060ed238 Stephen Beaver
			</table>
264
		</div>
265
	</div>
266
</div>
267 f3bb71cf Sjon Hortensius
268 c10cb196 Stephen Beaver
<nav class="action-buttons">
269 4611e283 Steve Beaver
	<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
270 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
271 f74457df Stephen Beaver
		<?=gettext("Add")?>
272 f3bb71cf Sjon Hortensius
	</a>
273
</nav>
274 6639718c Viktor G
<div class="infoblock">
275
<?php
276
print_info_box(
277
	sprintf(gettext('%1$s Route is inactive, gateway interface is missing'), '<br /><strong><i class="fa fa-times-circle-o"></i></strong>') .
278
	sprintf(gettext('%1$s Route disabled'), '<br /><strong><i class="fa fa-ban"></i></strong>') .
279
	sprintf(gettext('%1$s Route enabled'), '<br /><strong><i class="fa fa-check-circle-o"></i></strong>')
280
	);
281
?>
282
</div>
283 f3bb71cf Sjon Hortensius
<?php
284
285 5d339e8e heper
include("foot.inc");