Project

General

Profile

Download (8.74 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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * 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
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * 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
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-system-staticroutes
30
##|*NAME=System: Static Routes
31
##|*DESCR=Allow access to the 'System: Static Routes' page.
32
##|*MATCH=system_routes.php*
33
##|-PRIV
34

    
35
require_once('guiconfig.inc');
36
require_once('functions.inc');
37
require_once('filter.inc');
38
require_once('shaper.inc');
39

    
40
init_config_arr(['staticroutes', 'route']);
41
$a_routes = &$config['staticroutes']['route'];
42
$a_gateways = return_gateways_array(true, true, true);
43
$changedesc_prefix = gettext('Static Routes') . ": ";
44

    
45
if ($_POST['apply']) {
46
	$pconfig = $_POST;
47
	$retval = 0;
48
	
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
		foreach ($toapplylist as $toapply) {
53
			mwexec($toapply);
54
		}
55

    
56
		unlink($routes_apply_file);
57
	}
58

    
59
	$retval |= system_routing_configure();
60
	$retval |= filter_configure();
61
	/* reconfigure our gateway monitor */
62
	setup_gateways_monitor();
63

    
64
	if ($retval == 0) {
65
		clear_subsystem_dirty('staticroutes');
66
	}
67
}
68

    
69
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
		delete_static_route($_POST['id'], true);
73
		unset($a_routes[$_POST['id']]);
74
		write_config($changedesc);
75
		mark_subsystem_dirty('staticroutes');
76
		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
		$deleted_routes = '';
85
		foreach ($_POST['route'] as $routei) {
86
			$deleted_routes .= ' ' . $a_routes[$routei]['network'];
87
			delete_static_route($routei, true);
88
			unset($a_routes[$routei]);
89
		}
90
		$changedesc = $changedesc_prefix . sprintf(gettext('removed route to %s'), $deleted_routes);
91
		write_config($changedesc);
92
		mark_subsystem_dirty('staticroutes');
93
		header('Location: system_routes.php');
94
		exit;
95
	}
96
}
97

    
98
if ($_POST['act'] === 'toggle') {
99
	if ($a_routes[$_POST['id']]) {
100
		$do_update_config = true;
101
		if (isset($a_routes[$_POST['id']]['disabled'])) {
102
			// Do not enable a route whose gateway is disabled
103
			if (isset($a_gateways[$a_routes[$_POST['id']]['gateway']]['disabled'])) {
104
				$do_update_config = false;
105
				$input_errors[] = $changedesc_prefix . sprintf(gettext('gateway is disabled, cannot enable route to %s'), $a_routes[$_POST['id']]['network']);
106
			} else {
107
				unset($a_routes[$_POST['id']]['disabled']);
108
				$changedesc = $changedesc_prefix . sprintf(gettext('enabled route to %s'), $a_routes[$_POST['id']]['network']);
109
			}
110
		} else {
111
			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
		}
115

    
116
		if ($do_update_config) {
117
			if (write_config($changedesc)) {
118
				mark_subsystem_dirty('staticroutes');
119
			}
120
			header('Location: system_routes.php');
121
			exit;
122
		}
123
	}
124
}
125

    
126
if($_POST['save']) {
127
	/* 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
		}
134
	}
135
	/* move selected routes before this route */
136
	if (isset($movebtn) && is_array($_POST['route']) && count($_POST['route'])) {
137
		$a_routes_new = array();
138

    
139
		/* copy all routes < $movebtn and not selected */
140
		for ($i = 0; $i < $movebtn; $i++) {
141
			if (!in_array($i, $_POST['route'])) {
142
				$a_routes_new[] = $a_routes[$i];
143
			}
144
		}
145

    
146
		/* copy all selected routes */
147
		for ($i = 0; $i < count($a_routes); $i++) {
148
			if ($i == $movebtn) {
149
				continue;
150
			}
151
			if (in_array($i, $_POST['route'])) {
152
				$a_routes_new[] = $a_routes[$i];
153
			}
154
		}
155

    
156
		/* copy $movebtn route */
157
		if ($movebtn < count($a_routes)) {
158
			$a_routes_new[] = $a_routes[$movebtn];
159
		}
160

    
161
		/* copy all routes > $movebtn and not selected */
162
		for ($i = $movebtn+1; $i < count($a_routes); $i++) {
163
			if (!in_array($i, $_POST['route'])) {
164
				$a_routes_new[] = $a_routes[$i];
165
			}
166
		}
167
		if (count($a_routes_new) > 0) {
168
			$a_routes = $a_routes_new;
169
		}
170

    
171
		if (write_config(gettext('Saved static routes configuration.'))) {
172
			mark_subsystem_dirty('staticroutes');
173
		}
174
		header('Location: system_routes.php');
175
		exit;
176
	}
177
}
178

    
179

    
180
$pgtitle = [gettext('System'), gettext('Routing'), gettext('Static Routes')];
181
$pglinks = ['', 'system_gateways.php', '@self'];
182
$shortcut_section = 'routing';
183

    
184
include('head.inc');
185

    
186
if ($input_errors) {
187
	print_input_errors($input_errors);
188
}
189
if ($_POST['apply']) {
190
	print_apply_result_box($retval);
191
}
192
if (is_subsystem_dirty('staticroutes')) {
193
	print_apply_box(gettext('The static route configuration has been changed.') . '<br />' . gettext('The changes must be applied for them to take effect.'));
194
}
195

    
196
$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
display_top_tabs($tab_array);
201

    
202
?>
203
<div class="panel panel-default">
204
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Static Routes')?></h2></div>
205
	<div class="panel-body">
206
		<div class="table-responsive">
207
			<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
208
				<thead>
209
					<tr>
210
						<th></th>
211
						<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
					</tr>
217
				</thead>
218
				<tbody>
219
<?php
220
foreach ($a_routes as $i => $route):
221
	if (isset($a_gateways[$route['gateway']]['inactive'])) {
222
		$icon = 'fa-times-circle-o';
223
		$title = gettext('Route inactive, gateway interface is missing');
224
	} elseif (isset($route['disabled'])) {
225
		$icon = 'fa-ban';
226
		$title = gettext('Route disabled');
227
	} else {
228
		$icon = 'fa-check-circle-o';
229
		$title = gettext('Route enabled');
230
	}
231
?>
232
				<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
233
					<td title="<?=$title?>"><i class="fa <?=$icon?>"></i></td>
234
					<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
						<a href="system_routes_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit route')?>"></a>
248

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

    
251
				<?php if (isset($route['disabled'])) {
252
				?>
253
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable route')?>" usepost></a>
254
				<?php } else {
255
				?>
256
						<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable route')?>" usepost></a>
257
				<?php }
258
				?>
259
						<a href="system_routes.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete route')?>" usepost></a>
260

    
261
					</td>
262
				</tr>
263
<?php endforeach; ?>
264
			</table>
265
		</div>
266
	</div>
267
</div>
268

    
269
<nav class="action-buttons">
270
	<a href="system_routes_edit.php" role="button" class="btn btn-success btn-sm">
271
		<i class="fa fa-plus icon-embed-btn"></i>
272
		<?=gettext('Add')?>
273
	</a>
274
</nav>
275
<div class="infoblock">
276
<?php
277
print_info_box(
278
	sprintf(gettext('%1$s Route is inactive, gateway interface is missing'), '<br /><strong><i class="fa fa-times-circle-o"></i></strong>') .
279
	sprintf(gettext('%1$s Route disabled'), '<br /><strong><i class="fa fa-ban"></i></strong>') .
280
	sprintf(gettext('%1$s Route enabled'), '<br /><strong><i class="fa fa-check-circle-o"></i></strong>')
281
	);
282
?>
283
</div>
284
<?php
285

    
286
include('foot.inc');
(204-204/228)