Project

General

Profile

Download (12.8 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
?>
188

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