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 disabled 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 deleted 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 disable this gateway.
108
					if (!isset($route['disabled'])) {
109
						// But there is a static route that uses this gateway and is enabled (not disabled).
110
						$input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Static Route '%s'"), $a_gateways[$id]['name'], $route['network']);
111
					}
112
				} else {
113
					// The user wants to delete this gateway, but there is a static route (enabled or disabled) that refers to the gateway.
114
					$input_errors[] = sprintf(gettext("Gateway '%s' cannot be deleted because it is in use on Static Route '%s'"), $a_gateways[$id]['name'], $route['network']);
115
				}
116
			}
117
		}
118
	}
119

    
120
	if (isset($input_errors)) {
121
		return false;
122
	}
123

    
124
	return true;
125
}
126

    
127
function delete_gateway_item($id) {
128
	global $config, $a_gateways;
129

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

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

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

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

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

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

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

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

    
209
		header("Location: system_gateways.php");
210
		exit;
211
	}
212
}
213

    
214
$pgtitle = array(gettext("System"), gettext("Gateways"));
215
$shortcut_section = "gateways";
216

    
217
include("head.inc");
218

    
219
?>
220

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