Project

General

Profile

Download (11.5 KB) Statistics
| Branch: | Tag: | Revision:
1 d173230c Seth Mos
<?php
2
/*
3
	system_gateways.php
4
*/
5 6ff05704 Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c)  2010 Seth Mos <seth.mos@dds.nl>
8
 *
9
 *	Redistribution and use in source and binary forms, with or without modification,
10
 *	are permitted provided that the following conditions are met:
11
 *
12
 *	1. Redistributions of source code must retain the above copyright notice,
13
 *		this list of conditions and the following disclaimer.
14
 *
15
 *	2. Redistributions in binary form must reproduce the above copyright
16
 *		notice, this list of conditions and the following disclaimer in
17
 *		the documentation and/or other materials provided with the
18
 *		distribution.
19
 *
20
 *	3. All advertising materials mentioning features or use of this software
21
 *		must display the following acknowledgment:
22
 *		"This product includes software developed by the pfSense Project
23
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
24
 *
25
 *	4. The names "pfSense" and "pfSense Project" must not be used to
26
 *		 endorse or promote products derived from this software without
27
 *		 prior written permission. For written permission, please contact
28
 *		 coreteam@pfsense.org.
29
 *
30
 *	5. Products derived from this software may not be called "pfSense"
31
 *		nor may "pfSense" appear in their names without prior written
32
 *		permission of the Electric Sheep Fencing, LLC.
33
 *
34
 *	6. Redistributions of any form whatsoever must retain the following
35
 *		acknowledgment:
36
 *
37
 *	"This product includes software developed by the pfSense Project
38
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
52
 *
53
 *	====================================================================
54
 *
55
 */
56 d173230c Seth Mos
57 6b07c15a Matthew Grooms
##|+PRIV
58
##|*IDENT=page-system-gateways
59 5230f468 jim-p
##|*NAME=System: Gateways
60 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'System: Gateways' page.
61
##|*MATCH=system_gateways.php*
62
##|-PRIV
63
64 aceaf18c Phil Davis
require_once("guiconfig.inc");
65 7a927e67 Scott Ullrich
require_once("functions.inc");
66
require_once("filter.inc");
67
require_once("shaper.inc");
68 d173230c Seth Mos
69 e97df865 Renato Botelho
$a_gateways = return_gateways_array(true, false, true);
70 b92305a6 --global
$a_gateways_arr = array();
71 e0c7b2fe Phil Davis
foreach ($a_gateways as $gw) {
72 3df6d458 Seth Mos
	$a_gateways_arr[] = $gw;
73 e0c7b2fe Phil Davis
}
74 b92305a6 --global
$a_gateways = $a_gateways_arr;
75 616e1956 Seth Mos
76 e0c7b2fe Phil Davis
if (!is_array($config['gateways']['gateway_item'])) {
77 d251a8d4 Renato Botelho
	$config['gateways']['gateway_item'] = array();
78 e0c7b2fe Phil Davis
}
79 616e1956 Seth Mos
80
$a_gateway_item = &$config['gateways']['gateway_item'];
81
82 d173230c Seth Mos
if ($_POST) {
83
84
	$pconfig = $_POST;
85
86
	if ($_POST['apply']) {
87
88
		$retval = 0;
89
90
		$retval = system_routing_configure();
91 138e4140 Renato Botelho
		$retval |= system_resolvconf_generate();
92 d173230c Seth Mos
		$retval |= filter_configure();
93 13bbe450 Seth Mos
		/* reconfigure our gateway monitor */
94
		setup_gateways_monitor();
95 acda1403 Chris Buechler
		/* Dynamic DNS on gw groups may have changed */
96
		send_event("service reload dyndnsall");
97 d173230c Seth Mos
98
		$savemsg = get_std_save_message($retval);
99 e0c7b2fe Phil Davis
		if ($retval == 0) {
100 a368a026 Ermal Lu?i
			clear_subsystem_dirty('staticroutes');
101 e0c7b2fe Phil Davis
		}
102 d173230c Seth Mos
	}
103
}
104
105 028ff8f8 Phil Davis
function can_delete_disable_gateway_item($id, $disable = false) {
106 e97df865 Renato Botelho
	global $config, $input_errors, $a_gateways;
107 d251a8d4 Renato Botelho
108 e0c7b2fe Phil Davis
	if (!isset($a_gateways[$id])) {
109 e97df865 Renato Botelho
		return false;
110 e0c7b2fe Phil Davis
	}
111 e97df865 Renato Botelho
112
	if (is_array($config['gateways']['gateway_group'])) {
113
		foreach ($config['gateways']['gateway_group'] as $group) {
114
			foreach ($group['item'] as $item) {
115
				$items = explode("|", $item);
116
				if ($items[0] == $a_gateways[$id]['name']) {
117 205178aa Phil Davis
					if (!$disable) {
118 762faef5 Phil Davis
						$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be deleted because it is in use on Gateway Group "%2$s"'), $a_gateways[$id]['name'], $group['name']);
119 205178aa Phil Davis
					} else {
120 762faef5 Phil Davis
						$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be disabled because it is in use on Gateway Group "%2$s"'), $a_gateways[$id]['name'], $group['name']);
121 028ff8f8 Phil Davis
					}
122 f78302e8 Ermal
				}
123
			}
124
		}
125 e97df865 Renato Botelho
	}
126
127
	if (is_array($config['staticroutes']['route'])) {
128
		foreach ($config['staticroutes']['route'] as $route) {
129
			if ($route['gateway'] == $a_gateways[$id]['name']) {
130 205178aa Phil Davis
				if (!$disable) {
131 028ff8f8 Phil Davis
					// The user wants to delete this gateway, but there is a static route (enabled or disabled) that refers to the gateway.
132 762faef5 Phil Davis
					$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be deleted because it is in use on Static Route "%2$s"'), $a_gateways[$id]['name'], $route['network']);
133 205178aa Phil Davis
				} else if (!isset($route['disabled'])) {
134
					// The user wants to disable this gateway.
135
					// But there is a static route that uses this gateway and is enabled (not disabled).
136 762faef5 Phil Davis
					$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be disabled because it is in use on Static Route "%2$s"'), $a_gateways[$id]['name'], $route['network']);
137 028ff8f8 Phil Davis
				}
138 f78302e8 Ermal
			}
139
		}
140 e97df865 Renato Botelho
	}
141
142 e0c7b2fe Phil Davis
	if (isset($input_errors)) {
143 e97df865 Renato Botelho
		return false;
144 e0c7b2fe Phil Davis
	}
145 e97df865 Renato Botelho
146
	return true;
147
}
148
149
function delete_gateway_item($id) {
150 dde20226 Renato Botelho
	global $config, $a_gateways;
151
152 e0c7b2fe Phil Davis
	if (!isset($a_gateways[$id])) {
153 e97df865 Renato Botelho
		return;
154 e0c7b2fe Phil Davis
	}
155 32a9eb18 Ermal
156 e75f0e7d PiBa-NL
	/* NOTE: Cleanup static routes for the interface route if any */
157 d61309a0 Phil Davis
	if (!empty($a_gateways[$id]) && is_ipaddr($a_gateways[$id]['gateway']) &&
158
	    $gateway['gateway'] != $a_gateways[$id]['gateway'] &&
159
	    isset($a_gateways[$id]["nonlocalgateway"])) {
160 e75f0e7d PiBa-NL
		$realif = get_real_interface($a_gateways[$id]['interface']);
161
		$inet = (!is_ipaddrv4($a_gateways[$id]['gateway']) ? "-inet6" : "-inet");
162
		$cmd = "/sbin/route delete $inet " . escapeshellarg($a_gateways[$id]['gateway']) . " -iface " . escapeshellarg($realif);
163
		mwexec($cmd);
164
	}
165 e97df865 Renato Botelho
	/* NOTE: Cleanup static routes for the monitor ip if any */
166
	if (!empty($a_gateways[$id]['monitor']) &&
167 d61309a0 Phil Davis
	    $a_gateways[$id]['monitor'] != "dynamic" &&
168
	    is_ipaddr($a_gateways[$id]['monitor']) &&
169
	    $a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
170 e0c7b2fe Phil Davis
		if (is_ipaddrv4($a_gateways[$id]['monitor'])) {
171 e97df865 Renato Botelho
			mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']));
172 e0c7b2fe Phil Davis
		} else {
173 e97df865 Renato Botelho
			mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']));
174 e0c7b2fe Phil Davis
		}
175 e97df865 Renato Botelho
	}
176
177 e0c7b2fe Phil Davis
	if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) {
178 e97df865 Renato Botelho
		unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
179 e0c7b2fe Phil Davis
	}
180 e97df865 Renato Botelho
	unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
181
}
182
183
unset($input_errors);
184
if ($_GET['act'] == "del") {
185 028ff8f8 Phil Davis
	if (can_delete_disable_gateway_item($_GET['id'])) {
186 e97df865 Renato Botelho
		$realid = $a_gateways[$_GET['id']]['attribute'];
187
		delete_gateway_item($_GET['id']);
188
		write_config("Gateways: removed gateway {$realid}");
189
		mark_subsystem_dirty('staticroutes');
190
		header("Location: system_gateways.php");
191
		exit;
192
	}
193
}
194
195
if (isset($_POST['del_x'])) {
196
	/* delete selected items */
197
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
198 e0c7b2fe Phil Davis
		foreach ($_POST['rule'] as $rulei) {
199 028ff8f8 Phil Davis
			if (!can_delete_disable_gateway_item($rulei)) {
200 e97df865 Renato Botelho
				break;
201 e0c7b2fe Phil Davis
			}
202
		}
203 e97df865 Renato Botelho
204
		if (!isset($input_errors)) {
205
			$items_deleted = "";
206
			foreach ($_POST['rule'] as $rulei) {
207
				delete_gateway_item($rulei);
208
				$items_deleted .= "{$rulei} ";
209
			}
210
			if (!empty($items_deleted)) {
211 762faef5 Phil Davis
				write_config(sprintf(gettext("Gateways: removed gateways %s", $items_deleted)));
212 e97df865 Renato Botelho
				mark_subsystem_dirty('staticroutes');
213
			}
214 f78302e8 Ermal
			header("Location: system_gateways.php");
215
			exit;
216
		}
217 d173230c Seth Mos
	}
218
219 e97df865 Renato Botelho
} else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) {
220
	$realid = $a_gateways[$_GET['id']]['attribute'];
221 028ff8f8 Phil Davis
	$disable_gw = !isset($a_gateway_item[$realid]['disabled']);
222
	if ($disable_gw) {
223
		// The user wants to disable the gateway, so check if that is OK.
224
		$ok_to_toggle = can_delete_disable_gateway_item($_GET['id'], $disable_gw);
225 e0c7b2fe Phil Davis
	} else {
226 028ff8f8 Phil Davis
		// The user wants to enable the gateway. That is always OK.
227
		$ok_to_toggle = true;
228 e0c7b2fe Phil Davis
	}
229 028ff8f8 Phil Davis
	if ($ok_to_toggle) {
230
		if ($disable_gw) {
231
			$a_gateway_item[$realid]['disabled'] = true;
232
		} else {
233
			unset($a_gateway_item[$realid]['disabled']);
234
		}
235 e97df865 Renato Botelho
236 028ff8f8 Phil Davis
		if (write_config("Gateways: enable/disable")) {
237
			mark_subsystem_dirty('staticroutes');
238
		}
239 e97df865 Renato Botelho
240 028ff8f8 Phil Davis
		header("Location: system_gateways.php");
241
		exit;
242
	}
243 e97df865 Renato Botelho
}
244 124aee67 Chris Buechler
245 d036bc07 Stephen Beaver
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Gateways"));
246 b32dd0a6 jim-p
$shortcut_section = "gateways";
247 02ca24c9 jim-p
248 d173230c Seth Mos
include("head.inc");
249
250 d61309a0 Phil Davis
if ($input_errors) {
251 c3c692a9 Sjon Hortensius
	print_input_errors($input_errors);
252 d61309a0 Phil Davis
}
253
if ($savemsg) {
254 a9929d56 Stephen Beaver
	print_info_box($savemsg, 'success');
255 d61309a0 Phil Davis
}
256 f74457df Stephen Beaver
257 d61309a0 Phil Davis
if (is_subsystem_dirty('staticroutes')) {
258 7fdca5ff NOYB
	print_apply_box(gettext("The gateway configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
259 d61309a0 Phil Davis
}
260 c3c692a9 Sjon Hortensius
261
$tab_array = array();
262
$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
263 80b4d0c5 heper
$tab_array[1] = array(gettext("Static Routes"), false, "system_routes.php");
264
$tab_array[2] = array(gettext("Gateway Groups"), false, "system_gateway_groups.php");
265 c3c692a9 Sjon Hortensius
display_top_tabs($tab_array);
266 d173230c Seth Mos
267 d251a8d4 Renato Botelho
?>
268 060ed238 Stephen Beaver
<div class="panel panel-default">
269
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Gateways')?></h2></div>
270
	<div class="panel-body">
271
		<div class="table-responsive">
272
			<table class="table table-striped tabel-hover table-condensed">
273
				<thead>
274
					<tr>
275
						<th></th>
276
						<th><?=gettext("Name")?></th>
277
						<th><?=gettext("Interface")?></th>
278
						<th><?=gettext("Gateway")?></th>
279
						<th><?=gettext("Monitor IP")?></th>
280
						<th><?=gettext("Description")?></th>
281
						<th><?=gettext("Actions")?></th>
282
					</tr>
283
				</thead>
284
				<tbody>
285 e97df865 Renato Botelho
<?php
286 c3c692a9 Sjon Hortensius
foreach ($a_gateways as $i => $gateway):
287 d61309a0 Phil Davis
	if (isset($gateway['inactive'])) {
288 1b7379f9 Jared Dillard
		$icon = 'fa-times-circle-o';
289 d61309a0 Phil Davis
	} elseif (isset($gateway['disabled'])) {
290 1b7379f9 Jared Dillard
		$icon = 'fa-ban';
291 d61309a0 Phil Davis
	} else {
292 1b7379f9 Jared Dillard
		$icon = 'fa-check-circle-o';
293 d61309a0 Phil Davis
	}
294 c3c692a9 Sjon Hortensius
295 d61309a0 Phil Davis
	if (isset($gateway['inactive'])) {
296 c3c692a9 Sjon Hortensius
		$title = gettext("This gateway is inactive because interface is missing");
297 d61309a0 Phil Davis
	} else {
298 c3c692a9 Sjon Hortensius
		$title = '';
299 d61309a0 Phil Davis
	}
300 e97df865 Renato Botelho
?>
301 060ed238 Stephen Beaver
				<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
302
					<td title="<?=$title?>"><i class="fa <?=$icon?>"></i></td>
303
					<td>
304
						<?=htmlspecialchars($gateway['name'])?>
305 e97df865 Renato Botelho
<?php
306 d61309a0 Phil Davis
			if (isset($gateway['defaultgw'])) {
307 c3c692a9 Sjon Hortensius
				echo " <strong>(default)</strong>";
308 d61309a0 Phil Davis
			}
309 e97df865 Renato Botelho
?>
310 060ed238 Stephen Beaver
						</td>
311
						<td>
312
							<?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']))?>
313
						</td>
314
						<td>
315
							<?=htmlspecialchars($gateway['gateway'])?>
316
						</td>
317
						<td>
318
							<?=htmlspecialchars($gateway['monitor'])?>
319
						</td>
320
						<td>
321
							<?=htmlspecialchars($gateway['descr'])?>
322
						</td>
323
						<td>
324 5154b00d Phil Davis
							<a href="system_gateways_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit gateway');?>"></a>
325
							<a href="system_gateways_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy gateway')?>"></a>
326 f74457df Stephen Beaver
327 fa172bc5 NewEraCracker
<?php if (is_numeric($gateway['attribute'])): ?>
328 1629e8ea heper
	<?php if (isset($gateway['disabled'])) {
329 f74457df Stephen Beaver
	?>
330 5154b00d Phil Davis
							<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable gateway')?>"></a>
331 1629e8ea heper
	<?php } else {
332
	?>
333 5154b00d Phil Davis
							<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable gateway')?>"></a>
334 1629e8ea heper
	<?php }
335 f74457df Stephen Beaver
	?>
336 5154b00d Phil Davis
							<a href="system_gateways.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete gateway')?>"></a>
337 f74457df Stephen Beaver
338 fa172bc5 NewEraCracker
<?php endif; ?>
339 060ed238 Stephen Beaver
						</td>
340
					</tr>
341 fa172bc5 NewEraCracker
<?php endforeach; ?>
342 060ed238 Stephen Beaver
				</tbody>
343
			</table>
344
		</div>
345
	</div>
346
</div>
347 c3c692a9 Sjon Hortensius
348 c10cb196 Stephen Beaver
<nav class="action-buttons">
349 c3c692a9 Sjon Hortensius
	<a href="system_gateways_edit.php" role="button" class="btn btn-success">
350 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
351 f74457df Stephen Beaver
		<?=gettext("Add");?>
352 c3c692a9 Sjon Hortensius
	</a>
353
</nav>
354 e97df865 Renato Botelho
<?php
355 c3c692a9 Sjon Hortensius
356 1629e8ea heper
include("foot.inc");