Project

General

Profile

Download (11 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 d173230c Seth Mos
require("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
		$retval |= filter_configure();
92 13bbe450 Seth Mos
		/* reconfigure our gateway monitor */
93
		setup_gateways_monitor();
94 acda1403 Chris Buechler
		/* Dynamic DNS on gw groups may have changed */
95
		send_event("service reload dyndnsall");
96 d173230c Seth Mos
97
		$savemsg = get_std_save_message($retval);
98 e0c7b2fe Phil Davis
		if ($retval == 0) {
99 a368a026 Ermal Lu?i
			clear_subsystem_dirty('staticroutes');
100 e0c7b2fe Phil Davis
		}
101 d173230c Seth Mos
	}
102
}
103
104 028ff8f8 Phil Davis
function can_delete_disable_gateway_item($id, $disable = false) {
105 e97df865 Renato Botelho
	global $config, $input_errors, $a_gateways;
106 d251a8d4 Renato Botelho
107 e0c7b2fe Phil Davis
	if (!isset($a_gateways[$id])) {
108 e97df865 Renato Botelho
		return false;
109 e0c7b2fe Phil Davis
	}
110 e97df865 Renato Botelho
111
	if (is_array($config['gateways']['gateway_group'])) {
112
		foreach ($config['gateways']['gateway_group'] as $group) {
113
			foreach ($group['item'] as $item) {
114
				$items = explode("|", $item);
115
				if ($items[0] == $a_gateways[$id]['name']) {
116 205178aa Phil Davis
					if (!$disable) {
117 028ff8f8 Phil Davis
						$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Gateway Group '%s'"), $a_gateways[$id]['name'], $group['name']);
118 205178aa Phil Davis
					} else {
119
						$input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Gateway Group '%s'"), $a_gateways[$id]['name'], $group['name']);
120 028ff8f8 Phil Davis
					}
121 f78302e8 Ermal
				}
122
			}
123
		}
124 e97df865 Renato Botelho
	}
125
126
	if (is_array($config['staticroutes']['route'])) {
127
		foreach ($config['staticroutes']['route'] as $route) {
128
			if ($route['gateway'] == $a_gateways[$id]['name']) {
129 205178aa Phil Davis
				if (!$disable) {
130 028ff8f8 Phil Davis
					// The user wants to delete this gateway, but there is a static route (enabled or disabled) that refers to the gateway.
131
					$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Static Route '%s'"), $a_gateways[$id]['name'], $route['network']);
132 205178aa Phil Davis
				} else if (!isset($route['disabled'])) {
133
					// The user wants to disable this gateway.
134
					// But there is a static route that uses this gateway and is enabled (not disabled).
135
					$input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Static Route '%s'"), $a_gateways[$id]['name'], $route['network']);
136 028ff8f8 Phil Davis
				}
137 f78302e8 Ermal
			}
138
		}
139 e97df865 Renato Botelho
	}
140
141 e0c7b2fe Phil Davis
	if (isset($input_errors)) {
142 e97df865 Renato Botelho
		return false;
143 e0c7b2fe Phil Davis
	}
144 e97df865 Renato Botelho
145
	return true;
146
}
147
148
function delete_gateway_item($id) {
149 dde20226 Renato Botelho
	global $config, $a_gateways;
150
151 e0c7b2fe Phil Davis
	if (!isset($a_gateways[$id])) {
152 e97df865 Renato Botelho
		return;
153 e0c7b2fe Phil Davis
	}
154 32a9eb18 Ermal
155 e75f0e7d PiBa-NL
	/* NOTE: Cleanup static routes for the interface route if any */
156 d61309a0 Phil Davis
	if (!empty($a_gateways[$id]) && is_ipaddr($a_gateways[$id]['gateway']) &&
157
	    $gateway['gateway'] != $a_gateways[$id]['gateway'] &&
158
	    isset($a_gateways[$id]["nonlocalgateway"])) {
159 e75f0e7d PiBa-NL
		$realif = get_real_interface($a_gateways[$id]['interface']);
160
		$inet = (!is_ipaddrv4($a_gateways[$id]['gateway']) ? "-inet6" : "-inet");
161
		$cmd = "/sbin/route delete $inet " . escapeshellarg($a_gateways[$id]['gateway']) . " -iface " . escapeshellarg($realif);
162
		mwexec($cmd);
163
	}
164 e97df865 Renato Botelho
	/* NOTE: Cleanup static routes for the monitor ip if any */
165
	if (!empty($a_gateways[$id]['monitor']) &&
166 d61309a0 Phil Davis
	    $a_gateways[$id]['monitor'] != "dynamic" &&
167
	    is_ipaddr($a_gateways[$id]['monitor']) &&
168
	    $a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
169 e0c7b2fe Phil Davis
		if (is_ipaddrv4($a_gateways[$id]['monitor'])) {
170 e97df865 Renato Botelho
			mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']));
171 e0c7b2fe Phil Davis
		} else {
172 e97df865 Renato Botelho
			mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']));
173 e0c7b2fe Phil Davis
		}
174 e97df865 Renato Botelho
	}
175
176 e0c7b2fe Phil Davis
	if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) {
177 e97df865 Renato Botelho
		unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
178 e0c7b2fe Phil Davis
	}
179 e97df865 Renato Botelho
	unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
180
}
181
182
unset($input_errors);
183
if ($_GET['act'] == "del") {
184 028ff8f8 Phil Davis
	if (can_delete_disable_gateway_item($_GET['id'])) {
185 e97df865 Renato Botelho
		$realid = $a_gateways[$_GET['id']]['attribute'];
186
		delete_gateway_item($_GET['id']);
187
		write_config("Gateways: removed gateway {$realid}");
188
		mark_subsystem_dirty('staticroutes');
189
		header("Location: system_gateways.php");
190
		exit;
191
	}
192
}
193
194
if (isset($_POST['del_x'])) {
195
	/* delete selected items */
196
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
197 e0c7b2fe Phil Davis
		foreach ($_POST['rule'] as $rulei) {
198 028ff8f8 Phil Davis
			if (!can_delete_disable_gateway_item($rulei)) {
199 e97df865 Renato Botelho
				break;
200 e0c7b2fe Phil Davis
			}
201
		}
202 e97df865 Renato Botelho
203
		if (!isset($input_errors)) {
204
			$items_deleted = "";
205
			foreach ($_POST['rule'] as $rulei) {
206
				delete_gateway_item($rulei);
207
				$items_deleted .= "{$rulei} ";
208
			}
209
			if (!empty($items_deleted)) {
210
				write_config("Gateways: removed gateways {$items_deleted}");
211
				mark_subsystem_dirty('staticroutes');
212
			}
213 f78302e8 Ermal
			header("Location: system_gateways.php");
214
			exit;
215
		}
216 d173230c Seth Mos
	}
217
218 e97df865 Renato Botelho
} else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) {
219
	$realid = $a_gateways[$_GET['id']]['attribute'];
220 028ff8f8 Phil Davis
	$disable_gw = !isset($a_gateway_item[$realid]['disabled']);
221
	if ($disable_gw) {
222
		// The user wants to disable the gateway, so check if that is OK.
223
		$ok_to_toggle = can_delete_disable_gateway_item($_GET['id'], $disable_gw);
224 e0c7b2fe Phil Davis
	} else {
225 028ff8f8 Phil Davis
		// The user wants to enable the gateway. That is always OK.
226
		$ok_to_toggle = true;
227 e0c7b2fe Phil Davis
	}
228 028ff8f8 Phil Davis
	if ($ok_to_toggle) {
229
		if ($disable_gw) {
230
			$a_gateway_item[$realid]['disabled'] = true;
231
		} else {
232
			unset($a_gateway_item[$realid]['disabled']);
233
		}
234 e97df865 Renato Botelho
235 028ff8f8 Phil Davis
		if (write_config("Gateways: enable/disable")) {
236
			mark_subsystem_dirty('staticroutes');
237
		}
238 e97df865 Renato Botelho
239 028ff8f8 Phil Davis
		header("Location: system_gateways.php");
240
		exit;
241
	}
242 e97df865 Renato Botelho
}
243 124aee67 Chris Buechler
244 d036bc07 Stephen Beaver
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Gateways"));
245 b32dd0a6 jim-p
$shortcut_section = "gateways";
246 02ca24c9 jim-p
247 d173230c Seth Mos
include("head.inc");
248
249 d61309a0 Phil Davis
if ($input_errors) {
250 c3c692a9 Sjon Hortensius
	print_input_errors($input_errors);
251 d61309a0 Phil Davis
}
252
if ($savemsg) {
253 a9929d56 Stephen Beaver
	print_info_box($savemsg, 'success');
254 d61309a0 Phil Davis
}
255 f74457df Stephen Beaver
256 d61309a0 Phil Davis
if (is_subsystem_dirty('staticroutes')) {
257 c3c692a9 Sjon Hortensius
	print_info_box_np(gettext("The gateway configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
258 d61309a0 Phil Davis
}
259 c3c692a9 Sjon Hortensius
260
$tab_array = array();
261
$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
262
$tab_array[1] = array(gettext("Routes"), false, "system_routes.php");
263
$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
264
display_top_tabs($tab_array);
265 d173230c Seth Mos
266 d251a8d4 Renato Botelho
?>
267 c3c692a9 Sjon Hortensius
<table class="table">
268
<thead>
269
	<tr>
270
		<th></th>
271
		<th><?=gettext("Name")?></th>
272
		<th><?=gettext("Interface")?></th>
273
		<th><?=gettext("Gateway")?></th>
274
		<th><?=gettext("Monitor IP")?></th>
275
		<th><?=gettext("Description")?></th>
276 329b5c49 Phil Davis
		<th><?=gettext("Actions")?></th>
277 c3c692a9 Sjon Hortensius
	</tr>
278
</thead>
279
<tbody>
280 e97df865 Renato Botelho
<?php
281 c3c692a9 Sjon Hortensius
foreach ($a_gateways as $i => $gateway):
282 d61309a0 Phil Davis
	if (isset($gateway['inactive'])) {
283 1b7379f9 Jared Dillard
		$icon = 'fa-times-circle-o';
284 d61309a0 Phil Davis
	} elseif (isset($gateway['disabled'])) {
285 1b7379f9 Jared Dillard
		$icon = 'fa-ban';
286 d61309a0 Phil Davis
	} else {
287 1b7379f9 Jared Dillard
		$icon = 'fa-check-circle-o';
288 d61309a0 Phil Davis
	}
289 c3c692a9 Sjon Hortensius
290 d61309a0 Phil Davis
	if (isset($gateway['inactive'])) {
291 c3c692a9 Sjon Hortensius
		$title = gettext("This gateway is inactive because interface is missing");
292 d61309a0 Phil Davis
	} else {
293 c3c692a9 Sjon Hortensius
		$title = '';
294 d61309a0 Phil Davis
	}
295 e97df865 Renato Botelho
?>
296 1b7379f9 Jared Dillard
	<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?>>
297
		<td title="<?=$title?>"><i class="fa <?=$icon?>"></i></td>
298 c3c692a9 Sjon Hortensius
		<td>
299 8ebf884f jim-p
			<?=htmlspecialchars($gateway['name'])?>
300 e97df865 Renato Botelho
<?php
301 d61309a0 Phil Davis
			if (isset($gateway['defaultgw'])) {
302 c3c692a9 Sjon Hortensius
				echo " <strong>(default)</strong>";
303 d61309a0 Phil Davis
			}
304 e97df865 Renato Botelho
?>
305 c3c692a9 Sjon Hortensius
		</td>
306
		<td>
307
			<?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']))?>
308
		</td>
309
		<td>
310 8ebf884f jim-p
			<?=htmlspecialchars($gateway['gateway'])?>
311 c3c692a9 Sjon Hortensius
		</td>
312
		<td>
313
			<?=htmlspecialchars($gateway['monitor'])?>
314
		</td>
315
		<td>
316
			<?=htmlspecialchars($gateway['descr'])?>
317
		</td>
318
		<td>
319 bbfa7874 Phil Davis
			<a href="system_gateways_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit');?>"></a>
320 1629e8ea heper
			<a href="system_gateways_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
321 f74457df Stephen Beaver
322 c3c692a9 Sjon Hortensius
<? if (is_numeric($gateway['attribute'])): ?>
323 1629e8ea heper
	<?php if (isset($gateway['disabled'])) {
324 f74457df Stephen Beaver
	?>
325 1629e8ea heper
			<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
326
	<?php } else {
327
	?>
328
			<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
329
	<?php }
330 f74457df Stephen Beaver
	?>
331 33f0b0d5 Stephen Beaver
			<a href="system_gateways.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete')?>"></a>
332 f74457df Stephen Beaver
333 c3c692a9 Sjon Hortensius
<? endif?>
334
		</td>
335
	</tr>
336
<? endforeach?>
337
</tbody>
338
</table>
339
340 c10cb196 Stephen Beaver
<nav class="action-buttons">
341 c3c692a9 Sjon Hortensius
	<a href="system_gateways_edit.php" role="button" class="btn btn-success">
342 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
343 f74457df Stephen Beaver
		<?=gettext("Add");?>
344 c3c692a9 Sjon Hortensius
	</a>
345
</nav>
346 e97df865 Renato Botelho
<?php
347 c3c692a9 Sjon Hortensius
348 1629e8ea heper
include("foot.inc");