Project

General

Profile

Download (7.85 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_gateways.php
5
	part of pfSense (https://www.pfsense.org)
6

    
7
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, 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 the
19
	   documentation and/or other materials provided with the distribution.
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
/*
33
	pfSense_MODULE:	routing
34
*/
35

    
36
##|+PRIV
37
##|*IDENT=page-system-gateways
38
##|*NAME=System: Gateways page
39
##|*DESCR=Allow access to the 'System: Gateways' page.
40
##|*MATCH=system_gateways.php*
41
##|-PRIV
42

    
43
require("guiconfig.inc");
44
require_once("functions.inc");
45
require_once("filter.inc");
46
require_once("shaper.inc");
47

    
48
$a_gateways = return_gateways_array(true, false, true);
49
$a_gateways_arr = array();
50
foreach ($a_gateways as $gw)
51
	$a_gateways_arr[] = $gw;
52
$a_gateways = $a_gateways_arr;
53

    
54
if (!is_array($config['gateways']['gateway_item']))
55
	$config['gateways']['gateway_item'] = array();
56

    
57
$a_gateway_item = &$config['gateways']['gateway_item'];
58

    
59
if ($_POST) {
60

    
61
	$pconfig = $_POST;
62

    
63
	if ($_POST['apply']) {
64

    
65
		$retval = 0;
66

    
67
		$retval = system_routing_configure();
68
		$retval |= filter_configure();
69
		/* reconfigure our gateway monitor */
70
		setup_gateways_monitor();
71

    
72
		$savemsg = get_std_save_message($retval);
73
		if ($retval == 0)
74
			clear_subsystem_dirty('staticroutes');
75
	}
76
}
77

    
78
function can_delete_gateway_item($id) {
79
	global $config, $input_errors, $a_gateways;
80

    
81
	if (!isset($a_gateways[$id]))
82
		return false;
83

    
84
	if (is_array($config['gateways']['gateway_group'])) {
85
		foreach ($config['gateways']['gateway_group'] as $group) {
86
			foreach ($group['item'] as $item) {
87
				$items = explode("|", $item);
88
				if ($items[0] == $a_gateways[$id]['name']) {
89
					$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Gateway Group '%s'"), $a_gateways[$id]['name'], $group['name']);
90
					break;
91
				}
92
			}
93
		}
94
	}
95

    
96
	if (is_array($config['staticroutes']['route'])) {
97
		foreach ($config['staticroutes']['route'] as $route) {
98
			if ($route['gateway'] == $a_gateways[$id]['name']) {
99
				$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Static Route '%s'"), $a_gateways[$id]['name'], $route['network']);
100
				break;
101
			}
102
		}
103
	}
104

    
105
	if (isset($input_errors))
106
		return false;
107

    
108
	return true;
109
}
110

    
111
function delete_gateway_item($id) {
112
	global $config, $a_gateways;
113

    
114
	if (!isset($a_gateways[$id]))
115
		return;
116

    
117
	/* NOTE: Cleanup static routes for the monitor ip if any */
118
	if (!empty($a_gateways[$id]['monitor']) &&
119
		$a_gateways[$id]['monitor'] != "dynamic" &&
120
		is_ipaddr($a_gateways[$id]['monitor']) &&
121
		$a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
122
		if (is_ipaddrv4($a_gateways[$id]['monitor']))
123
			mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']));
124
		else
125
			mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']));
126
	}
127

    
128
	if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name'])
129
		unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
130
	unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
131
}
132

    
133
unset($input_errors);
134
if ($_GET['act'] == "del") {
135
	if (can_delete_gateway_item($_GET['id'])) {
136
		$realid = $a_gateways[$_GET['id']]['attribute'];
137
		delete_gateway_item($_GET['id']);
138
		write_config("Gateways: removed gateway {$realid}");
139
		mark_subsystem_dirty('staticroutes');
140
		header("Location: system_gateways.php");
141
		exit;
142
	}
143
}
144

    
145
if (isset($_POST['del_x'])) {
146
	/* delete selected items */
147
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
148
		foreach ($_POST['rule'] as $rulei)
149
			if(!can_delete_gateway_item($rulei))
150
				break;
151

    
152
		if (!isset($input_errors)) {
153
			$items_deleted = "";
154
			foreach ($_POST['rule'] as $rulei) {
155
				delete_gateway_item($rulei);
156
				$items_deleted .= "{$rulei} ";
157
			}
158
			if (!empty($items_deleted)) {
159
				write_config("Gateways: removed gateways {$items_deleted}");
160
				mark_subsystem_dirty('staticroutes');
161
			}
162
			header("Location: system_gateways.php");
163
			exit;
164
		}
165
	}
166

    
167
} else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) {
168
	$realid = $a_gateways[$_GET['id']]['attribute'];
169

    
170
	if(isset($a_gateway_item[$realid]['disabled']))
171
		unset($a_gateway_item[$realid]['disabled']);
172
	else
173
		$a_gateway_item[$realid]['disabled'] = true;
174

    
175
	if (write_config("Gateways: enable/disable"))
176
		mark_subsystem_dirty('staticroutes');
177

    
178
	header("Location: system_gateways.php");
179
	exit;
180
}
181

    
182
$pgtitle = array(gettext("System"),gettext("Gateways"));
183
$shortcut_section = "gateways";
184

    
185
include("head.inc");
186

    
187
if ($input_errors)
188
	print_input_errors($input_errors);
189
if ($savemsg)
190
	print_info_box($savemsg);
191
if (is_subsystem_dirty('staticroutes'))
192
	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."));
193

    
194
$tab_array = array();
195
$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
196
$tab_array[1] = array(gettext("Routes"), false, "system_routes.php");
197
$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
198
display_top_tabs($tab_array);
199

    
200
?>
201
<table class="table">
202
<thead>
203
	<tr>
204
		<th></th>
205
		<th><?=gettext("Name")?></th>
206
		<th><?=gettext("Interface")?></th>
207
		<th><?=gettext("Gateway")?></th>
208
		<th><?=gettext("Monitor IP")?></th>
209
		<th><?=gettext("Description")?></th>
210
		<th></th>
211
	</tr>
212
</thead>
213
<tbody>
214
<?php
215
foreach ($a_gateways as $i => $gateway):
216
	if (isset($gateway['inactive']))
217
		$icon = 'icon-remove-circle';
218
	elseif (isset($gateway['disabled']))
219
		$icon = 'icon-ban-circle';
220
	else
221
		$icon = 'icon-ok-circle';
222

    
223
	if (isset($gateway['inactive']))
224
		$title = gettext("This gateway is inactive because interface is missing");
225
	else
226
		$title = '';
227
?>
228
	<tr<?=($icon != 'icon-ok-circle')? ' class="disabled"' : ''?>>
229
		<td title="<?=$title?>"><i class="icon <?=$icon?>"></i></td>
230
		<td>
231
			<?=$gateway['name']?>
232
<?php
233
			if (isset($gateway['defaultgw']))
234
				echo " <strong>(default)</strong>";
235
?>
236
		</td>
237
		<td>
238
			<?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']))?>
239
		</td>
240
		<td>
241
			<?=$gateway['gateway']?>
242
		</td>
243
		<td>
244
			<?=htmlspecialchars($gateway['monitor'])?>
245
		</td>
246
		<td>
247
			<?=htmlspecialchars($gateway['descr'])?>
248
		</td>
249
		<td>
250
			<a class="btn btn-xs btn-primary" href="system_gateways_edit.php?id=<?=$i?>">
251
				edit
252
			</a>
253
			<a class="btn btn-xs btn-default" href="system_gateways_edit.php?dup=<?=$i?>">
254
				copy
255
			</a>
256
<? if (is_numeric($gateway['attribute'])): ?>
257
			<a class="btn btn-xs btn-danger" href="system_gateways.php?act=del&amp;id=<?=$i?>">
258
				delete
259
			</a>
260
			<a class="btn btn-xs btn-default" href="?act=toggle&amp;id=<?=$i?>">
261
				toggle
262
			</a>
263
<? endif?>
264
		</td>
265
	</tr>
266
<? endforeach?>
267
</tbody>
268
</table>
269

    
270
<nav class="action-buttons">
271
	<a href="system_gateways_edit.php" role="button" class="btn btn-success">
272
		<?=gettext("edit default");?>
273
	</a>
274
</nav>
275
<?php
276

    
277
include("foot.inc");
(208-208/241)