Project

General

Profile

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