Project

General

Profile

Download (13.9 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
}
53
$a_gateways = $a_gateways_arr;
54

    
55
if (!is_array($config['gateways']['gateway_item'])) {
56
	$config['gateways']['gateway_item'] = array();
57
}
58

    
59
$a_gateway_item = &$config['gateways']['gateway_item'];
60

    
61
if ($_POST) {
62

    
63
	$pconfig = $_POST;
64

    
65
	if ($_POST['apply']) {
66

    
67
		$retval = 0;
68

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

    
74
		$savemsg = get_std_save_message($retval);
75
		if ($retval == 0) {
76
			clear_subsystem_dirty('staticroutes');
77
		}
78
	}
79
}
80

    
81
function can_delete_disable_gateway_item($id, $disable = false) {
82
	global $config, $input_errors, $a_gateways;
83

    
84
	if (!isset($a_gateways[$id])) {
85
		return false;
86
	}
87

    
88
	if (is_array($config['gateways']['gateway_group'])) {
89
		foreach ($config['gateways']['gateway_group'] as $group) {
90
			foreach ($group['item'] as $item) {
91
				$items = explode("|", $item);
92
				if ($items[0] == $a_gateways[$id]['name']) {
93
					if (!$disable) {
94
						$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Gateway Group '%s'"), $a_gateways[$id]['name'], $group['name']);
95
					} else {
96
						$input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Gateway Group '%s'"), $a_gateways[$id]['name'], $group['name']);
97
					}
98
				}
99
			}
100
		}
101
	}
102

    
103
	if (is_array($config['staticroutes']['route'])) {
104
		foreach ($config['staticroutes']['route'] as $route) {
105
			if ($route['gateway'] == $a_gateways[$id]['name']) {
106
				if (!$disable) {
107
					// The user wants to delete this gateway, but there is a static route (enabled or disabled) that refers to the gateway.
108
					$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Static Route '%s'"), $a_gateways[$id]['name'], $route['network']);
109
				} else if (!isset($route['disabled'])) {
110
					// The user wants to disable this gateway.
111
					// But there is a static route that uses this gateway and is enabled (not disabled).
112
					$input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Static Route '%s'"), $a_gateways[$id]['name'], $route['network']);
113
				}
114
			}
115
		}
116
	}
117

    
118
	if (isset($input_errors)) {
119
		return false;
120
	}
121

    
122
	return true;
123
}
124

    
125
function delete_gateway_item($id) {
126
	global $config, $a_gateways;
127

    
128
	if (!isset($a_gateways[$id])) {
129
		return;
130
	}
131

    
132
	/* NOTE: Cleanup static routes for the monitor ip if any */
133
	if (!empty($a_gateways[$id]['monitor']) &&
134
		$a_gateways[$id]['monitor'] != "dynamic" &&
135
		is_ipaddr($a_gateways[$id]['monitor']) &&
136
		$a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
137
		if (is_ipaddrv4($a_gateways[$id]['monitor'])) {
138
			mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']));
139
		} else {
140
			mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']));
141
		}
142
	}
143

    
144
	if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) {
145
		unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
146
	}
147
	unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
148
}
149

    
150
unset($input_errors);
151
if ($_GET['act'] == "del") {
152
	if (can_delete_disable_gateway_item($_GET['id'])) {
153
		$realid = $a_gateways[$_GET['id']]['attribute'];
154
		delete_gateway_item($_GET['id']);
155
		write_config("Gateways: removed gateway {$realid}");
156
		mark_subsystem_dirty('staticroutes');
157
		header("Location: system_gateways.php");
158
		exit;
159
	}
160
}
161

    
162
if (isset($_POST['del_x'])) {
163
	/* delete selected items */
164
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
165
		foreach ($_POST['rule'] as $rulei) {
166
			if (!can_delete_disable_gateway_item($rulei)) {
167
				break;
168
			}
169
		}
170

    
171
		if (!isset($input_errors)) {
172
			$items_deleted = "";
173
			foreach ($_POST['rule'] as $rulei) {
174
				delete_gateway_item($rulei);
175
				$items_deleted .= "{$rulei} ";
176
			}
177
			if (!empty($items_deleted)) {
178
				write_config("Gateways: removed gateways {$items_deleted}");
179
				mark_subsystem_dirty('staticroutes');
180
			}
181
			header("Location: system_gateways.php");
182
			exit;
183
		}
184
	}
185

    
186
} else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) {
187
	$realid = $a_gateways[$_GET['id']]['attribute'];
188
	$disable_gw = !isset($a_gateway_item[$realid]['disabled']);
189
	if ($disable_gw) {
190
		// The user wants to disable the gateway, so check if that is OK.
191
		$ok_to_toggle = can_delete_disable_gateway_item($_GET['id'], $disable_gw);
192
	} else {
193
		// The user wants to enable the gateway. That is always OK.
194
		$ok_to_toggle = true;
195
	}
196
	if ($ok_to_toggle) {
197
		if ($disable_gw) {
198
			$a_gateway_item[$realid]['disabled'] = true;
199
		} else {
200
			unset($a_gateway_item[$realid]['disabled']);
201
		}
202

    
203
		if (write_config("Gateways: enable/disable")) {
204
			mark_subsystem_dirty('staticroutes');
205
		}
206

    
207
		header("Location: system_gateways.php");
208
		exit;
209
	}
210
}
211

    
212
$pgtitle = array(gettext("System"), gettext("Gateways"));
213
$shortcut_section = "gateways";
214

    
215
include("head.inc");
216

    
217
?>
218

    
219
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
220
<?php include("fbegin.inc"); ?>
221
<?php if ($input_errors) print_input_errors($input_errors); ?>
222
<form action="system_gateways.php" method="post">
223
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
224
<?php if ($savemsg) print_info_box($savemsg); ?>
225
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
226
<?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>
227
<?php endif; ?>
228
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system gatewyas">
229
		<tr>
230
			<td>
231
<?php
232
			$tab_array = array();
233
			$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
234
			$tab_array[1] = array(gettext("Routes"), false, "system_routes.php");
235
			$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
236
			display_top_tabs($tab_array);
237
?>
238
			</td>
239
		</tr>
240
		<tr>
241
			<td>
242
				<div id="mainarea">
243
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
244
					<tr id="frheader">
245
						<td width="2%" class="list">&nbsp;</td>
246
						<td width="2%" class="list">&nbsp;</td>
247
						<td width="15%" class="listhdrr"><?=gettext("Name"); ?></td>
248
						<td width="10%" class="listhdrr"><?=gettext("Interface"); ?></td>
249
						<td width="15%" class="listhdrr"><?=gettext("Gateway"); ?></td>
250
						<td width="15%" class="listhdrr"><?=gettext("Monitor IP"); ?></td>
251
						<td width="31%" class="listhdr"><?=gettext("Description"); ?></td>
252
						<td width="10%" class="list">
253
							<table border="0" cellspacing="0" cellpadding="1" summary="add">
254
								<tr>
255
									<td width="17"></td>
256
									<td>
257
										<a href="system_gateways_edit.php">
258
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
259
										</a>
260
									</td>
261
								</tr>
262
							</table>
263
						</td>
264
					</tr>
265
<?php
266
				$textse = "</span>";
267
				$i = 0;
268
				foreach ($a_gateways as $gateway):
269
					if (isset($gateway['disabled']) || isset($gateway['inactive'])) {
270
						$textss = "<span class=\"gray\">";
271
						$iconfn = "pass_d";
272
					} else {
273
						$textss = "<span>";
274
						$iconfn = "pass";
275
					}
276
?>
277
					<tr valign="top" id="fr<?=$i;?>">
278
						<td class="listt">
279
<?php
280
						if (is_numeric($gateway['attribute'])):
281
?>
282
							<input type="checkbox" id="frc<?=$i;?>" name="rule[]" value="<?=$i;?>" onclick="fr_bgcolor('<?=$i;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;" />
283
<?php
284
						else:
285
?>
286
							&nbsp;
287
<?php
288
						endif;
289
?>
290
						</td>
291
						<td class="listt" align="center">
292
<?php
293
						if (isset($gateway['inactive'])):
294
?>
295
							<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject_d.gif" width="11" height="11" border="0"
296
								title="<?=gettext("This gateway is inactive because interface is missing");?>" alt="icon" />
297
<?php
298
						elseif (is_numeric($gateway['attribute'])):
299
?>
300
							<a href="?act=toggle&amp;id=<?=$i;?>">
301
								<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0"
302
									title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" />
303
							</a>
304
<?php
305
						else:
306
?>
307
							<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0"
308
								title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" />
309
<?php
310
						endif;
311
?>
312
						</td>
313
						<td class="listlr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
314
<?php
315
							echo $textss;
316
							echo $gateway['name'];
317
							if (isset($gateway['defaultgw'])) {
318
								echo " <strong>(default)</strong>";
319
							}
320
							echo $textse;
321
?>
322
						</td>
323
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
324
<?php
325
							echo $textss;
326
							echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']));
327
							echo $textse;
328
?>
329
						</td>
330
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
331
<?php
332
							echo $textss;
333
							echo $gateway['gateway'] . " ";
334
							echo $textse;
335
?>
336
						</td>
337
						<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
338
<?php
339
							echo $textss;
340
							echo htmlspecialchars($gateway['monitor']) . " ";
341
							echo $textse;
342
?>
343
						</td>
344
<?php
345
					if (is_numeric($gateway['attribute'])):
346
?>
347
						<td class="listbg" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
348
<?php
349
					else:
350
?>
351
						<td class="listbgns" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
352
<?php
353
					endif;
354
							echo $textss;
355
							echo htmlspecialchars($gateway['descr']) . "&nbsp;";
356
							echo $textse;
357
?>
358
						</td>
359
						<td valign="middle" class="list nowrap">
360
							<table border="0" cellspacing="0" cellpadding="1" summary="icons">
361
								<tr>
362
									<td>
363
										<a href="system_gateways_edit.php?id=<?=$i;?>">
364
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="edit" />
365
										</a>
366
									</td>
367
<?php
368
								if (is_numeric($gateway['attribute'])):
369
?>
370
									<td>
371
										<a href="system_gateways.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this gateway?"); ?>')">
372
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" />
373
										</a>
374
									</td>
375
<?php
376
								else:
377
?>
378
									<td width='17'></td>
379
<?php
380
								endif;
381
?>
382
								</tr>
383
								<tr>
384
									<td width="17"></td>
385
									<td>
386
										<a href="system_gateways_edit.php?dup=<?=$i;?>">
387
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
388
										</a>
389
									</td>
390
								</tr>
391
							</table>
392
						</td>
393
					</tr>
394
<?php
395
					$i++;
396
				endforeach;
397
?>
398
					<tr>
399
						<td class="list" colspan="7"></td>
400
						<td class="list">
401
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
402
								<tr>
403
									<td>
404
<?php
405
									if ($i == 0):
406
?>
407
										<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17"
408
											title="<?=gettext("delete selected items");?>" border="0" alt="delete" />
409
<?php
410
									else:
411
?>
412
										<input name="del" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif"
413
											style="width:17;height:17" title="<?=gettext("delete selected items");?>"
414
											onclick="return confirm('<?=gettext("Do you really want to delete the selected gateway items?");?>')" />
415
<?php
416
									endif;
417
?>
418
									</td>
419
									<td>
420
										<a href="system_gateways_edit.php">
421
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="edit" />
422
										</a>
423
									</td>
424
								</tr>
425
							</table>
426
						</td>
427
					</tr>
428
				</table>
429
				</div>
430
			</td>
431
		</tr>
432
	</table>
433
</form>
434
<?php include("fend.inc"); ?>
435
</body>
436
</html>
(218-218/252)