Project

General

Profile

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