Project

General

Profile

Download (12.8 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / system_gateways.php @ a1b66bec

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
	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
/*
32
	pfSense_MODULE:	routing
33
*/
34

    
35
##|+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
require("guiconfig.inc");
43
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46

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

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

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

    
58
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
		/* reconfigure our gateway monitor */
69
		setup_gateways_monitor();
70

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

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

    
80
	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
				}
91
			}
92
		}
93
	}
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
			}
101
		}
102
	}
103

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

    
107
	return true;
108
}
109

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

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

    
116
	/* 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
			header("Location: system_gateways.php");
162
			exit;
163
		}
164
	}
165

    
166
} 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

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

    
184
include("head.inc");
185

    
186
?>
187

    
188
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
189
<?php include("fbegin.inc"); ?>
190
<?php if ($input_errors) print_input_errors($input_errors); ?>
191
<form action="system_gateways.php" method="post">
192
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
193
<?php if ($savemsg) print_info_box($savemsg); ?>
194
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
195
<?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
<?php endif; ?>
197
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system gatewyas">
198
		<tr>
199
			<td>
200
<?php
201
			$tab_array = array();
202
			$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
			display_top_tabs($tab_array);
206
?>
207
			</td>
208
		</tr>
209
		<tr>
210
			<td>
211
				<div id="mainarea">
212
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
213
					<tr id="frheader">
214
						<td width="2%" class="list">&nbsp;</td>
215
						<td width="2%" class="list">&nbsp;</td>
216
						<td width="15%" class="listhdrr"><?=gettext("Name"); ?></td>
217
						<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
						<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
				$textse = "</span>";
236
				$i = 0;
237
				foreach ($a_gateways as $gateway):
238
					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
?>
246
					<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
<?php
284
							echo $textss;
285
							echo $gateway['name'];
286
							if(isset($gateway['defaultgw']))
287
								echo " <strong>(default)</strong>";
288
							echo $textse;
289
?>
290
						</td>
291
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
292
<?php
293
							echo $textss;
294
							echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']));
295
							echo $textse;
296
?>
297
						</td>
298
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
299
<?php
300
							echo $textss;
301
							echo $gateway['gateway'] . " ";
302
							echo $textse;
303
?>
304
						</td>
305
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
306
<?php
307
							echo $textss;
308
							echo htmlspecialchars($gateway['monitor']) . " ";
309
							echo $textse;
310
?>
311
						</td>
312
<?php
313
					if (is_numeric($gateway['attribute'])):
314
?>
315
						<td class="listbg" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
316
<?php
317
					else:
318
?>
319
						<td class="listbgns" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
320
<?php
321
					endif;
322
							echo $textss;
323
							echo htmlspecialchars($gateway['descr']) . "&nbsp;";
324
							echo $textse;
325
?>
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
						<td class="list" colspan="7"></td>
368
						<td class="list">
369
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
370
								<tr>
371
									<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
									<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
			</td>
399
		</tr>
400
	</table>
401
</form>
402
<?php include("fend.inc"); ?>
403
</body>
404
</html>
(222-222/256)