Project

General

Profile

Download (8.82 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 a68f7a3d Luiz Otavio O Souza
 * Copyright (c) 2014-2024 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 8a9e2bfb Christian McDonald
require_once('guiconfig.inc');
36
require_once('functions.inc');
37
require_once('filter.inc');
38
require_once('shaper.inc');
39 5b237745 Scott Ullrich
40 8a9e2bfb Christian McDonald
init_config_arr(['staticroutes', 'route']);
41 5b237745 Scott Ullrich
$a_routes = &$config['staticroutes']['route'];
42 4bbbcc36 Marcos Mendoza
$a_gateways = get_gateways(GW_CACHE_ALL);
43 8a9e2bfb Christian McDonald
$changedesc_prefix = gettext('Static Routes') . ": ";
44 5b237745 Scott Ullrich
45 ddd3ffaf Steve Beaver
if ($_POST['apply']) {
46 5b237745 Scott Ullrich
	$pconfig = $_POST;
47 ddd3ffaf Steve Beaver
	$retval = 0;
48 8a9e2bfb Christian McDonald
	
49
	$routes_apply_file = g_get('tmp_path') . '/.system_routes.apply';
50
	if (file_exists($routes_apply_file)) {
51
		$toapplylist = unserialize(file_get_contents($routes_apply_file));
52 ddd3ffaf Steve Beaver
		foreach ($toapplylist as $toapply) {
53 8a9e2bfb Christian McDonald
			mwexec($toapply);
54 e8471084 Ermal
		}
55
56 8a9e2bfb Christian McDonald
		unlink($routes_apply_file);
57 ddd3ffaf Steve Beaver
	}
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 8a9e2bfb Christian McDonald
if ($_POST['act'] === 'del') {
70 ddd3ffaf Steve Beaver
	if ($a_routes[$_POST['id']]) {
71 8a9e2bfb Christian McDonald
		$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 8a9e2bfb Christian McDonald
		header('Location: system_routes.php');
77 70cb0375 Renato Botelho
		exit;
78
	}
79
}
80
81
if (isset($_POST['del_x'])) {
82
	/* delete selected routes */
83
	if (is_array($_POST['route']) && count($_POST['route'])) {
84 8a9e2bfb Christian McDonald
		$deleted_routes = '';
85 70cb0375 Renato Botelho
		foreach ($_POST['route'] as $routei) {
86 8a9e2bfb Christian McDonald
			$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 8a9e2bfb Christian McDonald
		$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 8a9e2bfb Christian McDonald
		header('Location: system_routes.php');
94 70cb0375 Renato Botelho
		exit;
95
	}
96 4611e283 Steve Beaver
}
97
98 8a9e2bfb Christian McDonald
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 8a9e2bfb Christian McDonald
				$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 8a9e2bfb Christian McDonald
				$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 8a9e2bfb Christian McDonald
			$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 8a9e2bfb Christian McDonald
			header('Location: system_routes.php');
121 028ff8f8 Phil Davis
			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 8a9e2bfb Christian McDonald
		if (write_config(gettext('Saved static routes configuration.'))) {
172 70cb0375 Renato Botelho
			mark_subsystem_dirty('staticroutes');
173 d38bd840 Phil Davis
		}
174 8a9e2bfb Christian McDonald
		header('Location: system_routes.php');
175 25c3f30c Renato Botelho
		exit;
176 5b237745 Scott Ullrich
	}
177
}
178 7f43ca88 Scott Ullrich
179 02ca24c9 jim-p
180 8a9e2bfb Christian McDonald
$pgtitle = [gettext('System'), gettext('Routing'), gettext('Static Routes')];
181
$pglinks = ['', 'system_gateways.php', '@self'];
182
$shortcut_section = 'routing';
183
184
include('head.inc');
185 7f43ca88 Scott Ullrich
186 d61309a0 Phil Davis
if ($input_errors) {
187 f3bb71cf Sjon Hortensius
	print_input_errors($input_errors);
188 d61309a0 Phil Davis
}
189 44c42356 Phil Davis
if ($_POST['apply']) {
190
	print_apply_result_box($retval);
191 d61309a0 Phil Davis
}
192
if (is_subsystem_dirty('staticroutes')) {
193 8a9e2bfb Christian McDonald
	print_apply_box(gettext('The static route configuration has been changed.') . '<br />' . gettext('The changes must be applied for them to take effect.'));
194 d61309a0 Phil Davis
}
195 f3bb71cf Sjon Hortensius
196 8a9e2bfb Christian McDonald
$tab_array = [];
197
$tab_array[0] = [gettext('Gateways'), false, 'system_gateways.php'];
198
$tab_array[1] = [gettext('Static Routes'), true, 'system_routes.php'];
199
$tab_array[2] = [gettext('Gateway Groups'), false, 'system_gateway_groups.php'];
200 f3bb71cf Sjon Hortensius
display_top_tabs($tab_array);
201 0f282d7a Scott Ullrich
202 f3bb71cf Sjon Hortensius
?>
203 060ed238 Stephen Beaver
<div class="panel panel-default">
204 70dc5cd6 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Static Routes')?></h2></div>
205 060ed238 Stephen Beaver
	<div class="panel-body">
206
		<div class="table-responsive">
207 1c10ce97 PiBa-NL
			<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
208 060ed238 Stephen Beaver
				<thead>
209
					<tr>
210
						<th></th>
211 8a9e2bfb Christian McDonald
						<th><?=gettext('Network')?></th>
212
						<th><?=gettext('Gateway')?></th>
213
						<th><?=gettext('Interface')?></th>
214
						<th><?=gettext('Description')?></th>
215
						<th><?=gettext('Actions')?></th>
216 060ed238 Stephen Beaver
					</tr>
217
				</thead>
218
				<tbody>
219 70cb0375 Renato Botelho
<?php
220 f3bb71cf Sjon Hortensius
foreach ($a_routes as $i => $route):
221 6639718c Viktor G
	if (isset($a_gateways[$route['gateway']]['inactive'])) {
222 91c4768b Marcos Mendoza
		$icon = 'fa-regular fa-circle-xmark';
223 8a9e2bfb Christian McDonald
		$title = gettext('Route inactive, gateway interface is missing');
224 6639718c Viktor G
	} elseif (isset($route['disabled'])) {
225 91c4768b Marcos Mendoza
		$icon = 'fa-solid fa-ban';
226 8a9e2bfb Christian McDonald
		$title = gettext('Route disabled');
227 d61309a0 Phil Davis
	} else {
228 91c4768b Marcos Mendoza
		$icon = 'fa-regular fa-circle-check';
229 8a9e2bfb Christian McDonald
		$title = gettext('Route enabled');
230 d61309a0 Phil Davis
	}
231 70cb0375 Renato Botelho
?>
232 b8c13d95 Marcos Mendoza
				<tr<?=($icon != 'fa-regular fa-circle-check')? ' class="disabled"' : ''?>>
233 91c4768b Marcos Mendoza
					<td title="<?=$title?>"><i class="<?=$icon?>"></i></td>
234 060ed238 Stephen Beaver
					<td>
235
						<?=strtolower($route['network'])?>
236
					</td>
237
					<td>
238
						<?=htmlentities($a_gateways[$route['gateway']]['name']) . " - " . htmlentities($a_gateways[$route['gateway']]['gateway'])?>
239
					</td>
240
					<td>
241
						<?=convert_friendly_interface_to_friendly_descr($a_gateways[$route['gateway']]['friendlyiface'])?>
242
					</td>
243
					<td>
244
						<?=htmlspecialchars($route['descr'])?>
245
					</td>
246
					<td>
247 e0cb987c Marcos Mendoza
						<a href="system_routes_edit.php?id=<?=$i?>" class="fa-solid fa-pencil" title="<?=gettext('Edit route')?>"></a>
248 060ed238 Stephen Beaver
249 c1d304b3 Marcos Mendoza
						<a href="system_routes_edit.php?dup=<?=$i?>" class="fa-regular fa-clone" title="<?=gettext('Copy route')?>"></a>
250 060ed238 Stephen Beaver
251
				<?php if (isset($route['disabled'])) {
252
				?>
253 c1d304b3 Marcos Mendoza
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa-regular fa-square-check" title="<?=gettext('Enable route')?>" usepost></a>
254 060ed238 Stephen Beaver
				<?php } else {
255
				?>
256 e0cb987c Marcos Mendoza
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa-solid fa-ban" title="<?=gettext('Disable route')?>" usepost></a>
257 060ed238 Stephen Beaver
				<?php }
258
				?>
259 c1d304b3 Marcos Mendoza
						<a href="system_routes.php?act=del&amp;id=<?=$i?>" class="fa-solid fa-trash-can" title="<?=gettext('Delete route')?>" usepost></a>
260 060ed238 Stephen Beaver
261
					</td>
262
				</tr>
263 fa172bc5 NewEraCracker
<?php endforeach; ?>
264 060ed238 Stephen Beaver
			</table>
265
		</div>
266
	</div>
267
</div>
268 f3bb71cf Sjon Hortensius
269 c10cb196 Stephen Beaver
<nav class="action-buttons">
270 4611e283 Steve Beaver
	<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
271 e0cb987c Marcos Mendoza
		<i class="fa-solid fa-plus icon-embed-btn"></i>
272 8a9e2bfb Christian McDonald
		<?=gettext('Add')?>
273 f3bb71cf Sjon Hortensius
	</a>
274
</nav>
275 6639718c Viktor G
<div class="infoblock">
276
<?php
277
print_info_box(
278 c1d304b3 Marcos Mendoza
	sprintf(gettext('%1$s Route is inactive, gateway interface is missing'), '<br /><strong><i class="fa-regular fa-circle-xmark"></i></strong>') .
279 e0cb987c Marcos Mendoza
	sprintf(gettext('%1$s Route disabled'), '<br /><strong><i class="fa-solid fa-ban"></i></strong>') .
280 c1d304b3 Marcos Mendoza
	sprintf(gettext('%1$s Route enabled'), '<br /><strong><i class="fa-regular fa-circle-check"></i></strong>')
281 6639718c Viktor G
	);
282
?>
283
</div>
284 f3bb71cf Sjon Hortensius
<?php
285
286 8a9e2bfb Christian McDonald
include('foot.inc');