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
	part of pfSense (http://pfsense.com)
6
7 6216690b smos
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
8 d173230c Seth Mos
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, 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 the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 1d333258 Scott Ullrich
/*
32
	pfSense_MODULE:	routing
33
*/
34 d173230c Seth Mos
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-system-gateways
37
##|*NAME=System: Gateways page
38
##|*DESCR=Allow access to the 'System: Gateways' page.
39
##|*MATCH=system_gateways.php*
40
##|-PRIV
41
42 d173230c Seth Mos
require("guiconfig.inc");
43 7a927e67 Scott Ullrich
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46 d173230c Seth Mos
47 e97df865 Renato Botelho
$a_gateways = return_gateways_array(true, false, true);
48 b92305a6 --global
$a_gateways_arr = array();
49 f78302e8 Ermal
foreach ($a_gateways as $gw)
50 3df6d458 Seth Mos
	$a_gateways_arr[] = $gw;
51 b92305a6 --global
$a_gateways = $a_gateways_arr;
52 616e1956 Seth Mos
53
if (!is_array($config['gateways']['gateway_item']))
54 d251a8d4 Renato Botelho
	$config['gateways']['gateway_item'] = array();
55 616e1956 Seth Mos
56
$a_gateway_item = &$config['gateways']['gateway_item'];
57
58 d173230c Seth Mos
if ($_POST) {
59
60
	$pconfig = $_POST;
61
62
	if ($_POST['apply']) {
63
64
		$retval = 0;
65
66
		$retval = system_routing_configure();
67
		$retval |= filter_configure();
68 13bbe450 Seth Mos
		/* reconfigure our gateway monitor */
69
		setup_gateways_monitor();
70 d173230c Seth Mos
71
		$savemsg = get_std_save_message($retval);
72 a368a026 Ermal Lu?i
		if ($retval == 0)
73
			clear_subsystem_dirty('staticroutes');
74 d173230c Seth Mos
	}
75
}
76
77 e97df865 Renato Botelho
function can_delete_gateway_item($id) {
78
	global $config, $input_errors, $a_gateways;
79 d251a8d4 Renato Botelho
80 e97df865 Renato Botelho
	if (!isset($a_gateways[$id]))
81
		return false;
82
83
	if (is_array($config['gateways']['gateway_group'])) {
84
		foreach ($config['gateways']['gateway_group'] as $group) {
85
			foreach ($group['item'] as $item) {
86
				$items = explode("|", $item);
87
				if ($items[0] == $a_gateways[$id]['name']) {
88
					$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Gateway Group '%s'"), $a_gateways[$id]['name'], $group['name']);
89
					break;
90 f78302e8 Ermal
				}
91
			}
92
		}
93 e97df865 Renato Botelho
	}
94
95
	if (is_array($config['staticroutes']['route'])) {
96
		foreach ($config['staticroutes']['route'] as $route) {
97
			if ($route['gateway'] == $a_gateways[$id]['name']) {
98
				$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Static Route '%s'"), $a_gateways[$id]['name'], $route['network']);
99
				break;
100 f78302e8 Ermal
			}
101
		}
102 e97df865 Renato Botelho
	}
103
104
	if (isset($input_errors))
105
		return false;
106
107
	return true;
108
}
109
110
function delete_gateway_item($id) {
111 dde20226 Renato Botelho
	global $config, $a_gateways;
112
113 e97df865 Renato Botelho
	if (!isset($a_gateways[$id]))
114
		return;
115 32a9eb18 Ermal
116 e97df865 Renato Botelho
	/* NOTE: Cleanup static routes for the monitor ip if any */
117
	if (!empty($a_gateways[$id]['monitor']) &&
118
	    $a_gateways[$id]['monitor'] != "dynamic" &&
119
	    is_ipaddr($a_gateways[$id]['monitor']) &&
120
	    $a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
121
		if (is_ipaddrv4($a_gateways[$id]['monitor']))
122
			mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']));
123
		else
124
			mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']));
125
	}
126
127
	if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name'])
128
		unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
129
	unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
130
}
131
132
unset($input_errors);
133
if ($_GET['act'] == "del") {
134
	if (can_delete_gateway_item($_GET['id'])) {
135
		$realid = $a_gateways[$_GET['id']]['attribute'];
136
		delete_gateway_item($_GET['id']);
137
		write_config("Gateways: removed gateway {$realid}");
138
		mark_subsystem_dirty('staticroutes');
139
		header("Location: system_gateways.php");
140
		exit;
141
	}
142
}
143
144
if (isset($_POST['del_x'])) {
145
	/* delete selected items */
146
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
147
		foreach ($_POST['rule'] as $rulei)
148
			if(!can_delete_gateway_item($rulei))
149
				break;
150
151
		if (!isset($input_errors)) {
152
			$items_deleted = "";
153
			foreach ($_POST['rule'] as $rulei) {
154
				delete_gateway_item($rulei);
155
				$items_deleted .= "{$rulei} ";
156
			}
157
			if (!empty($items_deleted)) {
158
				write_config("Gateways: removed gateways {$items_deleted}");
159
				mark_subsystem_dirty('staticroutes');
160
			}
161 f78302e8 Ermal
			header("Location: system_gateways.php");
162
			exit;
163
		}
164 d173230c Seth Mos
	}
165
166 e97df865 Renato Botelho
} else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) {
167
	$realid = $a_gateways[$_GET['id']]['attribute'];
168
169
	if(isset($a_gateway_item[$realid]['disabled']))
170
		unset($a_gateway_item[$realid]['disabled']);
171
	else
172
		$a_gateway_item[$realid]['disabled'] = true;
173
174
	if (write_config("Gateways: enable/disable"))
175
		mark_subsystem_dirty('staticroutes');
176
177
	header("Location: system_gateways.php");
178
	exit;
179
}
180 124aee67 Chris Buechler
181 f8513409 Carlos Eduardo Ramos
$pgtitle = array(gettext("System"),gettext("Gateways"));
182 b32dd0a6 jim-p
$shortcut_section = "gateways";
183 02ca24c9 jim-p
184 d173230c Seth Mos
include("head.inc");
185
186
?>
187
188
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
189
<?php include("fbegin.inc"); ?>
190 f78302e8 Ermal
<?php if ($input_errors) print_input_errors($input_errors); ?>
191 d173230c Seth Mos
<form action="system_gateways.php" method="post">
192 e97df865 Renato Botelho
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js"></script>
193 d173230c Seth Mos
<?php if ($savemsg) print_info_box($savemsg); ?>
194 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
195 0cabd5db Colin Fleming
<?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>
196 d173230c Seth Mos
<?php endif; ?>
197 0cabd5db Colin Fleming
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system gatewyas">
198 d173230c Seth Mos
		<tr>
199 d251a8d4 Renato Botelho
			<td>
200 d173230c Seth Mos
<?php
201
			$tab_array = array();
202 f8513409 Carlos Eduardo Ramos
			$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
203
			$tab_array[1] = array(gettext("Routes"), false, "system_routes.php");
204
			$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
205 d173230c Seth Mos
			display_top_tabs($tab_array);
206
?>
207 0cabd5db Colin Fleming
			</td>
208 d173230c Seth Mos
		</tr>
209 d251a8d4 Renato Botelho
		<tr>
210
			<td>
211
				<div id="mainarea">
212
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
213 e97df865 Renato Botelho
					<tr id="frheader">
214
						<td width="2%" class="list">&nbsp;</td>
215
						<td width="2%" class="list">&nbsp;</td>
216 d251a8d4 Renato Botelho
						<td width="15%" class="listhdrr"><?=gettext("Name"); ?></td>
217 e97df865 Renato Botelho
						<td width="10%" class="listhdrr"><?=gettext("Interface"); ?></td>
218
						<td width="15%" class="listhdrr"><?=gettext("Gateway"); ?></td>
219
						<td width="15%" class="listhdrr"><?=gettext("Monitor IP"); ?></td>
220
						<td width="31%" class="listhdr"><?=gettext("Description"); ?></td>
221 d251a8d4 Renato Botelho
						<td width="10%" class="list">
222
							<table border="0" cellspacing="0" cellpadding="1" summary="add">
223
								<tr>
224
									<td width="17"></td>
225
									<td>
226
										<a href="system_gateways_edit.php">
227
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
228
										</a>
229
									</td>
230
								</tr>
231
							</table>
232
						</td>
233
					</tr>
234
<?php
235 e97df865 Renato Botelho
				$textse = "</span>";
236 d251a8d4 Renato Botelho
				$i = 0;
237
				foreach ($a_gateways as $gateway):
238 e97df865 Renato Botelho
					if (isset($gateway['disabled']) || isset($gateway['inactive'])) {
239
						$textss = "<span class=\"gray\">";
240
						$iconfn = "pass_d";
241
					} else {
242
						$textss = "<span>";
243
						$iconfn = "pass";
244
					}
245 d251a8d4 Renato Botelho
?>
246 e97df865 Renato Botelho
					<tr valign="top" id="fr<?=$i;?>">
247
						<td class="listt">
248
<?php
249
						if (is_numeric($gateway['attribute'])):
250
?>
251
							<input type="checkbox" id="frc<?=$i;?>" name="rule[]" value="<?=$i;?>" onclick="fr_bgcolor('<?=$i;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;" />
252
<?php
253
						else:
254
?>
255
							&nbsp;
256
<?php
257
						endif;
258
?>
259
						</td>
260
						<td class="listt" align="center">
261
<?php
262
						if (isset($gateway['inactive'])):
263
?>
264
							<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject_d.gif" width="11" height="11" border="0"
265
								title="<?=gettext("This gateway is inactive because interface is missing");?>" alt="icon" />
266
<?php
267
						elseif (is_numeric($gateway['attribute'])):
268
?>
269
							<a href="?act=toggle&amp;id=<?=$i;?>">
270
								<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0"
271
									title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" />
272
							</a>
273
<?php
274
						else:
275
?>
276
							<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0"
277
								title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" />
278
<?php
279
						endif;
280
?>
281
						</td>
282
						<td class="listlr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
283 d251a8d4 Renato Botelho
<?php
284 e97df865 Renato Botelho
							echo $textss;
285 d251a8d4 Renato Botelho
							echo $gateway['name'];
286
							if(isset($gateway['defaultgw']))
287
								echo " <strong>(default)</strong>";
288 e97df865 Renato Botelho
							echo $textse;
289 d251a8d4 Renato Botelho
?>
290
						</td>
291 e97df865 Renato Botelho
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
292 d251a8d4 Renato Botelho
<?php
293 e97df865 Renato Botelho
							echo $textss;
294 d251a8d4 Renato Botelho
							echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']));
295 e97df865 Renato Botelho
							echo $textse;
296 d251a8d4 Renato Botelho
?>
297
						</td>
298 e97df865 Renato Botelho
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
299 d251a8d4 Renato Botelho
<?php
300 e97df865 Renato Botelho
							echo $textss;
301 d251a8d4 Renato Botelho
							echo $gateway['gateway'] . " ";
302 e97df865 Renato Botelho
							echo $textse;
303 d251a8d4 Renato Botelho
?>
304
						</td>
305 e97df865 Renato Botelho
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
306 d251a8d4 Renato Botelho
<?php
307 e97df865 Renato Botelho
							echo $textss;
308 d251a8d4 Renato Botelho
							echo htmlspecialchars($gateway['monitor']) . " ";
309 e97df865 Renato Botelho
							echo $textse;
310 d251a8d4 Renato Botelho
?>
311
						</td>
312
<?php
313
					if (is_numeric($gateway['attribute'])):
314
?>
315 e97df865 Renato Botelho
						<td class="listbg" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
316 d251a8d4 Renato Botelho
<?php
317
					else:
318
?>
319 e97df865 Renato Botelho
						<td class="listbgns" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
320 d251a8d4 Renato Botelho
<?php
321
					endif;
322 e97df865 Renato Botelho
							echo $textss;
323
							echo htmlspecialchars($gateway['descr']) . "&nbsp;";
324
							echo $textse;
325 d251a8d4 Renato Botelho
?>
326
						</td>
327
						<td valign="middle" class="list nowrap">
328
							<table border="0" cellspacing="0" cellpadding="1" summary="icons">
329
								<tr>
330
									<td>
331
										<a href="system_gateways_edit.php?id=<?=$i;?>">
332
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="edit" />
333
										</a>
334
									</td>
335
<?php
336
								if (is_numeric($gateway['attribute'])):
337
?>
338
									<td>
339
										<a href="system_gateways.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this gateway?"); ?>')">
340
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" />
341
										</a>
342
									</td>
343
<?php
344
								else:
345
?>
346
									<td width='17'></td>
347
<?php
348
								endif;
349
?>
350
								</tr>
351
								<tr>
352
									<td width="17"></td>
353
									<td>
354
										<a href="system_gateways_edit.php?dup=<?=$i;?>">
355
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
356
										</a>
357
									</td>
358
								</tr>
359
							</table>
360
						</td>
361
					</tr>
362
<?php
363
					$i++;
364
				endforeach;
365
?>
366
					<tr>
367 e97df865 Renato Botelho
						<td class="list" colspan="7"></td>
368 d251a8d4 Renato Botelho
						<td class="list">
369
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
370
								<tr>
371 e97df865 Renato Botelho
									<td>
372
<?php
373
									if ($i == 0):
374
?>
375
										<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17"
376
											title="<?=gettext("delete selected items");?>" border="0" alt="delete" />
377
<?php
378
									else:
379
?>
380
										<input name="del" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif"
381
											style="width:17;height:17" title="<?=gettext("delete selected items");?>"
382
											onclick="return confirm('<?=gettext("Do you really want to delete the selected gateway items?");?>')" />
383
<?php
384
									endif;
385
?>
386
									</td>
387 d251a8d4 Renato Botelho
									<td>
388
										<a href="system_gateways_edit.php">
389
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="edit" />
390
										</a>
391
									</td>
392
								</tr>
393
							</table>
394
						</td>
395
					</tr>
396
				</table>
397
				</div>
398 40e59dbf Scott Ullrich
			</td>
399 d251a8d4 Renato Botelho
		</tr>
400
	</table>
401
</form>
402 d173230c Seth Mos
<?php include("fend.inc"); ?>
403
</body>
404
</html>