Project

General

Profile

Download (10.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_gateways.php
5
*/
6
/* ====================================================================
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
/*
58
	pfSense_MODULE: routing
59
*/
60

    
61
##|+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
require("guiconfig.inc");
69
require_once("functions.inc");
70
require_once("filter.inc");
71
require_once("shaper.inc");
72

    
73
$a_gateways = return_gateways_array(true, false, true);
74
$a_gateways_arr = array();
75
foreach ($a_gateways as $gw) {
76
	$a_gateways_arr[] = $gw;
77
}
78
$a_gateways = $a_gateways_arr;
79

    
80
if (!is_array($config['gateways']['gateway_item'])) {
81
	$config['gateways']['gateway_item'] = array();
82
}
83

    
84
$a_gateway_item = &$config['gateways']['gateway_item'];
85

    
86
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
		/* reconfigure our gateway monitor */
97
		setup_gateways_monitor();
98
		/* Dynamic DNS on gw groups may have changed */
99
		send_event("service reload dyndnsall");
100

    
101
		$savemsg = get_std_save_message($retval);
102
		if ($retval == 0) {
103
			clear_subsystem_dirty('staticroutes');
104
		}
105
	}
106
}
107

    
108
function can_delete_disable_gateway_item($id, $disable = false) {
109
	global $config, $input_errors, $a_gateways;
110

    
111
	if (!isset($a_gateways[$id])) {
112
		return false;
113
	}
114

    
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
					if (!$disable) {
121
						$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
					} 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
					}
125
				}
126
			}
127
		}
128
	}
129

    
130
	if (is_array($config['staticroutes']['route'])) {
131
		foreach ($config['staticroutes']['route'] as $route) {
132
			if ($route['gateway'] == $a_gateways[$id]['name']) {
133
				if (!$disable) {
134
					// 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
				} 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
				}
141
			}
142
		}
143
	}
144

    
145
	if (isset($input_errors)) {
146
		return false;
147
	}
148

    
149
	return true;
150
}
151

    
152
function delete_gateway_item($id) {
153
	global $config, $a_gateways;
154

    
155
	if (!isset($a_gateways[$id])) {
156
		return;
157
	}
158

    
159
	/* NOTE: Cleanup static routes for the monitor ip if any */
160
	if (!empty($a_gateways[$id]['monitor']) &&
161
		$a_gateways[$id]['monitor'] != "dynamic" &&
162
		is_ipaddr($a_gateways[$id]['monitor']) &&
163
		$a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
164
		if (is_ipaddrv4($a_gateways[$id]['monitor'])) {
165
			mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']));
166
		} else {
167
			mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']));
168
		}
169
	}
170

    
171
	if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) {
172
		unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
173
	}
174
	unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
175
}
176

    
177
unset($input_errors);
178
if ($_GET['act'] == "del") {
179
	if (can_delete_disable_gateway_item($_GET['id'])) {
180
		$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
		foreach ($_POST['rule'] as $rulei) {
193
			if (!can_delete_disable_gateway_item($rulei)) {
194
				break;
195
			}
196
		}
197

    
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
			header("Location: system_gateways.php");
209
			exit;
210
		}
211
	}
212

    
213
} else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) {
214
	$realid = $a_gateways[$_GET['id']]['attribute'];
215
	$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
	} else {
220
		// The user wants to enable the gateway. That is always OK.
221
		$ok_to_toggle = true;
222
	}
223
	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

    
230
		if (write_config("Gateways: enable/disable")) {
231
			mark_subsystem_dirty('staticroutes');
232
		}
233

    
234
		header("Location: system_gateways.php");
235
		exit;
236
	}
237
}
238

    
239
$pgtitle = array(gettext("System"), gettext("Gateways"));
240
$shortcut_section = "gateways";
241

    
242
include("head.inc");
243

    
244
if ($input_errors)
245
	print_input_errors($input_errors);
246
if ($savemsg)
247
	print_info_box($savemsg, 'success');
248

    
249
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

    
258
?>
259
<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
		<th><?=gettext("Actions")?></th>
269
	</tr>
270
</thead>
271
<tbody>
272
<?php
273
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
?>
286
	<tr<?=($icon != 'icon-ok-circle')? ' class="disabled"' : ''?>>
287
		<td title="<?=$title?>"><i class="icon <?=$icon?>"></i></td>
288
		<td>
289
			<?=$gateway['name']?>
290
<?php
291
			if (isset($gateway['defaultgw']))
292
				echo " <strong>(default)</strong>";
293
?>
294
		</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
			<a href="system_gateways_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit');?>"></a>
309
			<a href="system_gateways_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
310

    
311
<? if (is_numeric($gateway['attribute'])): ?>
312
	<?php if (isset($gateway['disabled'])) {
313
	?>
314
			<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
	?>
320
			<a href="system_gateways.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete')?>"></a>
321

    
322
<? endif?>
323
		</td>
324
	</tr>
325
<? endforeach?>
326
</tbody>
327
</table>
328

    
329
<nav class="action-buttons">
330
	<a href="system_gateways_edit.php" role="button" class="btn btn-success">
331
		<i class="fa fa-plus icon-embed-btn"></i>
332
		<?=gettext("Add");?>
333
	</a>
334
</nav>
335
<?php
336

    
337
include("foot.inc");
(204-204/234)