Project

General

Profile

Download (12.8 KB) Statistics
| Branch: | Tag: | Revision:
1 d173230c Seth Mos
<?php
2 124aee67 Chris Buechler
/* $Id$ */
3 d173230c Seth Mos
/*
4
	system_gateways.php
5 5721595b Chris Buechler
	part of pfSense (https://www.pfsense.org)
6 d173230c Seth Mos
7 6216690b smos
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
8 29aef6c4 Jim Thompson
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
9 d173230c Seth Mos
	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 1d333258 Scott Ullrich
/*
33
	pfSense_MODULE:	routing
34
*/
35 d173230c Seth Mos
36 6b07c15a Matthew Grooms
##|+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 d173230c Seth Mos
require("guiconfig.inc");
44 7a927e67 Scott Ullrich
require_once("functions.inc");
45
require_once("filter.inc");
46
require_once("shaper.inc");
47 d173230c Seth Mos
48 e97df865 Renato Botelho
$a_gateways = return_gateways_array(true, false, true);
49 b92305a6 --global
$a_gateways_arr = array();
50 f78302e8 Ermal
foreach ($a_gateways as $gw)
51 3df6d458 Seth Mos
	$a_gateways_arr[] = $gw;
52 b92305a6 --global
$a_gateways = $a_gateways_arr;
53 616e1956 Seth Mos
54
if (!is_array($config['gateways']['gateway_item']))
55 d251a8d4 Renato Botelho
	$config['gateways']['gateway_item'] = array();
56 616e1956 Seth Mos
57
$a_gateway_item = &$config['gateways']['gateway_item'];
58
59 d173230c Seth Mos
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 13bbe450 Seth Mos
		/* reconfigure our gateway monitor */
70
		setup_gateways_monitor();
71 d173230c Seth Mos
72
		$savemsg = get_std_save_message($retval);
73 a368a026 Ermal Lu?i
		if ($retval == 0)
74
			clear_subsystem_dirty('staticroutes');
75 d173230c Seth Mos
	}
76
}
77
78 e97df865 Renato Botelho
function can_delete_gateway_item($id) {
79
	global $config, $input_errors, $a_gateways;
80 d251a8d4 Renato Botelho
81 e97df865 Renato Botelho
	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 f78302e8 Ermal
				}
92
			}
93
		}
94 e97df865 Renato Botelho
	}
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 f78302e8 Ermal
			}
102
		}
103 e97df865 Renato Botelho
	}
104
105
	if (isset($input_errors))
106
		return false;
107
108
	return true;
109
}
110
111
function delete_gateway_item($id) {
112 dde20226 Renato Botelho
	global $config, $a_gateways;
113
114 e97df865 Renato Botelho
	if (!isset($a_gateways[$id]))
115
		return;
116 32a9eb18 Ermal
117 e97df865 Renato Botelho
	/* 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 f78302e8 Ermal
			header("Location: system_gateways.php");
163
			exit;
164
		}
165 d173230c Seth Mos
	}
166
167 e97df865 Renato Botelho
} 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 124aee67 Chris Buechler
182 f8513409 Carlos Eduardo Ramos
$pgtitle = array(gettext("System"),gettext("Gateways"));
183 b32dd0a6 jim-p
$shortcut_section = "gateways";
184 02ca24c9 jim-p
185 d173230c Seth Mos
include("head.inc");
186
187
?>
188
189
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
190
<?php include("fbegin.inc"); ?>
191 f78302e8 Ermal
<?php if ($input_errors) print_input_errors($input_errors); ?>
192 d173230c Seth Mos
<form action="system_gateways.php" method="post">
193 07130afe ayvis
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
194 d173230c Seth Mos
<?php if ($savemsg) print_info_box($savemsg); ?>
195 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
196 8cd558b6 ayvis
<?php 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."));?><br /></p>
197 d173230c Seth Mos
<?php endif; ?>
198 0cabd5db Colin Fleming
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system gatewyas">
199 d173230c Seth Mos
		<tr>
200 d251a8d4 Renato Botelho
			<td>
201 d173230c Seth Mos
<?php
202
			$tab_array = array();
203 f8513409 Carlos Eduardo Ramos
			$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
204
			$tab_array[1] = array(gettext("Routes"), false, "system_routes.php");
205
			$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
206 d173230c Seth Mos
			display_top_tabs($tab_array);
207
?>
208 0cabd5db Colin Fleming
			</td>
209 d173230c Seth Mos
		</tr>
210 d251a8d4 Renato Botelho
		<tr>
211
			<td>
212
				<div id="mainarea">
213
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
214 e97df865 Renato Botelho
					<tr id="frheader">
215
						<td width="2%" class="list">&nbsp;</td>
216
						<td width="2%" class="list">&nbsp;</td>
217 d251a8d4 Renato Botelho
						<td width="15%" class="listhdrr"><?=gettext("Name"); ?></td>
218 e97df865 Renato Botelho
						<td width="10%" class="listhdrr"><?=gettext("Interface"); ?></td>
219
						<td width="15%" class="listhdrr"><?=gettext("Gateway"); ?></td>
220
						<td width="15%" class="listhdrr"><?=gettext("Monitor IP"); ?></td>
221
						<td width="31%" class="listhdr"><?=gettext("Description"); ?></td>
222 d251a8d4 Renato Botelho
						<td width="10%" class="list">
223
							<table border="0" cellspacing="0" cellpadding="1" summary="add">
224
								<tr>
225
									<td width="17"></td>
226
									<td>
227
										<a href="system_gateways_edit.php">
228
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
229
										</a>
230
									</td>
231
								</tr>
232
							</table>
233
						</td>
234
					</tr>
235
<?php
236 e97df865 Renato Botelho
				$textse = "</span>";
237 d251a8d4 Renato Botelho
				$i = 0;
238
				foreach ($a_gateways as $gateway):
239 e97df865 Renato Botelho
					if (isset($gateway['disabled']) || isset($gateway['inactive'])) {
240
						$textss = "<span class=\"gray\">";
241
						$iconfn = "pass_d";
242
					} else {
243
						$textss = "<span>";
244
						$iconfn = "pass";
245
					}
246 d251a8d4 Renato Botelho
?>
247 e97df865 Renato Botelho
					<tr valign="top" id="fr<?=$i;?>">
248
						<td class="listt">
249
<?php
250
						if (is_numeric($gateway['attribute'])):
251
?>
252
							<input type="checkbox" id="frc<?=$i;?>" name="rule[]" value="<?=$i;?>" onclick="fr_bgcolor('<?=$i;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;" />
253
<?php
254
						else:
255
?>
256
							&nbsp;
257
<?php
258
						endif;
259
?>
260
						</td>
261
						<td class="listt" align="center">
262
<?php
263
						if (isset($gateway['inactive'])):
264
?>
265
							<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject_d.gif" width="11" height="11" border="0"
266
								title="<?=gettext("This gateway is inactive because interface is missing");?>" alt="icon" />
267
<?php
268
						elseif (is_numeric($gateway['attribute'])):
269
?>
270
							<a href="?act=toggle&amp;id=<?=$i;?>">
271
								<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0"
272
									title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" />
273
							</a>
274
<?php
275
						else:
276
?>
277
							<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0"
278
								title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" />
279
<?php
280
						endif;
281
?>
282
						</td>
283
						<td class="listlr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
284 d251a8d4 Renato Botelho
<?php
285 e97df865 Renato Botelho
							echo $textss;
286 d251a8d4 Renato Botelho
							echo $gateway['name'];
287
							if(isset($gateway['defaultgw']))
288
								echo " <strong>(default)</strong>";
289 e97df865 Renato Botelho
							echo $textse;
290 d251a8d4 Renato Botelho
?>
291
						</td>
292 e97df865 Renato Botelho
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
293 d251a8d4 Renato Botelho
<?php
294 e97df865 Renato Botelho
							echo $textss;
295 d251a8d4 Renato Botelho
							echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']));
296 e97df865 Renato Botelho
							echo $textse;
297 d251a8d4 Renato Botelho
?>
298
						</td>
299 e97df865 Renato Botelho
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
300 d251a8d4 Renato Botelho
<?php
301 e97df865 Renato Botelho
							echo $textss;
302 d251a8d4 Renato Botelho
							echo $gateway['gateway'] . " ";
303 e97df865 Renato Botelho
							echo $textse;
304 d251a8d4 Renato Botelho
?>
305
						</td>
306 e97df865 Renato Botelho
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
307 d251a8d4 Renato Botelho
<?php
308 e97df865 Renato Botelho
							echo $textss;
309 d251a8d4 Renato Botelho
							echo htmlspecialchars($gateway['monitor']) . " ";
310 e97df865 Renato Botelho
							echo $textse;
311 d251a8d4 Renato Botelho
?>
312
						</td>
313
<?php
314
					if (is_numeric($gateway['attribute'])):
315
?>
316 e97df865 Renato Botelho
						<td class="listbg" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
317 d251a8d4 Renato Botelho
<?php
318
					else:
319
?>
320 e97df865 Renato Botelho
						<td class="listbgns" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
321 d251a8d4 Renato Botelho
<?php
322
					endif;
323 e97df865 Renato Botelho
							echo $textss;
324
							echo htmlspecialchars($gateway['descr']) . "&nbsp;";
325
							echo $textse;
326 d251a8d4 Renato Botelho
?>
327
						</td>
328
						<td valign="middle" class="list nowrap">
329
							<table border="0" cellspacing="0" cellpadding="1" summary="icons">
330
								<tr>
331
									<td>
332
										<a href="system_gateways_edit.php?id=<?=$i;?>">
333
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="edit" />
334
										</a>
335
									</td>
336
<?php
337
								if (is_numeric($gateway['attribute'])):
338
?>
339
									<td>
340
										<a href="system_gateways.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this gateway?"); ?>')">
341
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" />
342
										</a>
343
									</td>
344
<?php
345
								else:
346
?>
347
									<td width='17'></td>
348
<?php
349
								endif;
350
?>
351
								</tr>
352
								<tr>
353
									<td width="17"></td>
354
									<td>
355
										<a href="system_gateways_edit.php?dup=<?=$i;?>">
356
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
357
										</a>
358
									</td>
359
								</tr>
360
							</table>
361
						</td>
362
					</tr>
363
<?php
364
					$i++;
365
				endforeach;
366
?>
367
					<tr>
368 e97df865 Renato Botelho
						<td class="list" colspan="7"></td>
369 d251a8d4 Renato Botelho
						<td class="list">
370
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
371
								<tr>
372 e97df865 Renato Botelho
									<td>
373
<?php
374
									if ($i == 0):
375
?>
376
										<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17"
377
											title="<?=gettext("delete selected items");?>" border="0" alt="delete" />
378
<?php
379
									else:
380
?>
381
										<input name="del" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif"
382
											style="width:17;height:17" title="<?=gettext("delete selected items");?>"
383
											onclick="return confirm('<?=gettext("Do you really want to delete the selected gateway items?");?>')" />
384
<?php
385
									endif;
386
?>
387
									</td>
388 d251a8d4 Renato Botelho
									<td>
389
										<a href="system_gateways_edit.php">
390
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="edit" />
391
										</a>
392
									</td>
393
								</tr>
394
							</table>
395
						</td>
396
					</tr>
397
				</table>
398
				</div>
399 40e59dbf Scott Ullrich
			</td>
400 d251a8d4 Renato Botelho
		</tr>
401
	</table>
402
</form>
403 d173230c Seth Mos
<?php include("fend.inc"); ?>
404
</body>
405
</html>