Project

General

Profile

Download (9.31 KB) Statistics
| Branch: | Tag: | Revision:
1 d173230c Seth Mos
<?php
2 124aee67 Chris Buechler
/* $Id$ */
3 d173230c Seth Mos
/*
4
	system_gateways.php
5 d1ec51ba Chris Buechler
	part of pfSense (https://www.pfsense.org)
6 d173230c Seth Mos
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 c795339e Ermal Lu?i
$a_gateways = return_gateways_array(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
        $config['gateways']['gateway_item'] = array();
55
56
$a_gateway_item = &$config['gateways']['gateway_item'];
57
58 d173230c Seth Mos
$changedesc = "Gateways: ";
59
60
if ($_POST) {
61
62
	$pconfig = $_POST;
63
64
	if ($_POST['apply']) {
65
66
		$retval = 0;
67
68
		$retval = system_routing_configure();
69
		$retval |= filter_configure();
70 13bbe450 Seth Mos
		/* reconfigure our gateway monitor */
71
		setup_gateways_monitor();
72 d173230c Seth Mos
73
		$savemsg = get_std_save_message($retval);
74 a368a026 Ermal Lu?i
		if ($retval == 0)
75
			clear_subsystem_dirty('staticroutes');
76 d173230c Seth Mos
	}
77
}
78
79
if ($_GET['act'] == "del") {
80
	if ($a_gateways[$_GET['id']]) {
81 124aee67 Chris Buechler
		/* remove the real entry */
82
		$realid = $a_gateways[$_GET['id']]['attribute'];
83 f78302e8 Ermal
		$remove = true;
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[$_GET['id']]['name']) {
89
						$input_errors[] = "Gateway cannot be deleted because it is in use on Gateway Group '{$group['name']}'";
90
						$remove = false;
91
						break;
92
					}
93
						
94
				}
95
			}
96
		}
97
		if (is_array($config['staticroutes']['route'])) {
98
			foreach ($config['staticroutes']['route'] as $route) {
99
				if ($route['gateway'] == $a_gateways[$_GET['id']]['name']) {
100
					$input_errors[] = "Gateway cannot be deleted because it is in use on Static Routes '{$route['network']}'";
101
						$remove = false;
102
					break;
103
				}
104
			}
105
		}
106
		if ($remove == true) {
107 c9d099d7 Ermal
			/* NOTE: Cleanup static routes for the monitor ip if any */
108
                        if (!empty($a_gateways[$_GET['id']]['monitor']) && $a_gateways[$_GET['id']]['monitor'] != "dynamic" && is_ipaddr($a_gateways[$_GET['id']]['monitor']) &&
109
                            $a_gateways[$_GET['id']]['monitor'] != $a_gateways[$_GET['id']]['monitor'] && $a_gateways[$_GET['id']]['gateway'] != $a_gateways[$_GET['id']]['monitor']) {
110
                                if (is_ipaddrv4($a_gateways[$_GET['id']]['monitor']))
111
                                        mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$_GET['id']]['monitor']));
112
                                else
113
                                        mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$_GET['id']]['monitor']));
114
                        }
115
116 f78302e8 Ermal
			if ($config['interfaces'][$a_gateways[$_GET['id']]['friendlyiface']]['gateway'] == $a_gateways[$_GET['id']]['name'])
117
				unset($config['interfaces'][$a_gateways[$_GET['id']]['friendlyiface']]['gateway']);
118
			$changedesc .= "removed gateway {$realid}";
119
			unset($a_gateway_item[$realid]);
120
			write_config($changedesc);
121
			mark_subsystem_dirty('staticroutes');
122
			header("Location: system_gateways.php");
123
			exit;
124
		}
125 d173230c Seth Mos
	}
126
}
127
128 124aee67 Chris Buechler
129 f8513409 Carlos Eduardo Ramos
$pgtitle = array(gettext("System"),gettext("Gateways"));
130 b32dd0a6 jim-p
$shortcut_section = "gateways";
131 02ca24c9 jim-p
132 d173230c Seth Mos
include("head.inc");
133
134
?>
135
136
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
137
<?php include("fbegin.inc"); ?>
138 f78302e8 Ermal
<?php if ($input_errors) print_input_errors($input_errors); ?>
139 d173230c Seth Mos
<form action="system_gateways.php" method="post">
140 0cabd5db Colin Fleming
<input type="hidden" name="y1" value="1" />
141 d173230c Seth Mos
<?php if ($savemsg) print_info_box($savemsg); ?>
142 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
143 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>
144 d173230c Seth Mos
<?php endif; ?>
145 0cabd5db Colin Fleming
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system gatewyas">
146 d173230c Seth Mos
		<tr>
147
		  <td>
148
<?php
149
			$tab_array = array();
150 f8513409 Carlos Eduardo Ramos
			$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
151
			$tab_array[1] = array(gettext("Routes"), false, "system_routes.php");
152
			$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
153 d173230c Seth Mos
			display_top_tabs($tab_array);
154
?>
155 40e59dbf Scott Ullrich
</td></tr>
156
 <tr>
157
   <td>
158
	<div id="mainarea">
159 0cabd5db Colin Fleming
             <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
160 d173230c Seth Mos
                <tr>
161 f8513409 Carlos Eduardo Ramos
                  <td width="15%" class="listhdrr"><?=gettext("Name"); ?></td>
162
                  <td width="15%" class="listhdrr"><?=gettext("Interface"); ?></td>
163
                  <td width="20%" class="listhdrr"><?=gettext("Gateway"); ?></td>
164
                  <td width="20%" class="listhdrr"><?=gettext("Monitor IP"); ?></td>
165
                  <td width="30%" class="listhdr"><?=gettext("Description"); ?></td>
166 d173230c Seth Mos
                  <td width="10%" class="list">
167 0cabd5db Colin Fleming
			<table border="0" cellspacing="0" cellpadding="1" summary="add">
168 d173230c Seth Mos
			   <tr>
169
				<td width="17"></td>
170 0cabd5db Colin Fleming
				<td><a href="system_gateways_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" /></a></td>
171 d173230c Seth Mos
			   </tr>
172
			</table>
173
		  </td>
174
		</tr>
175
			  <?php $i = 0; foreach ($a_gateways as $gateway): ?>
176
                <tr>
177
                  <td class="listlr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
178 ef05ae5f Ermal
		<?php
179 81203d1d Ermal Lu?i
			echo $gateway['name'];
180 ef05ae5f Ermal
			if(isset($gateway['defaultgw']))
181 0cabd5db Colin Fleming
				echo " <strong>(default)</strong>";
182 ef05ae5f Ermal
		?>
183 d173230c Seth Mos
                  </td>
184
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
185 ef05ae5f Ermal
		<?php
186
			echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']));
187
		?>
188 d173230c Seth Mos
                  </td>
189
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
190 ef05ae5f Ermal
		<?php
191
			echo $gateway['gateway'] . " ";
192
		?>
193 d173230c Seth Mos
                  </td>
194
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
195 ef05ae5f Ermal
		<?php
196
			echo htmlspecialchars($gateway['monitor']) . " ";
197
		?>
198 d173230c Seth Mos
                  </td>
199 ef05ae5f Ermal
		<?php if (is_numeric($gateway['attribute'])) : ?>
200 137ea11c Seth Mos
                  <td class="listbg" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
201 ef05ae5f Ermal
		<?php else : ?>
202
                  <td class="listbgns" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
203 295ff120 Seth Mos
		<?php endif; ?>
204 33300c73 Scott Ullrich
                    <?=htmlspecialchars($gateway['descr']);?>&nbsp;
205 d173230c Seth Mos
                  </td>
206 295ff120 Seth Mos
207 0cabd5db Colin Fleming
                  <td valign="middle" class="list nowrap">
208
			<table border="0" cellspacing="0" cellpadding="1" summary="icons">
209 d173230c Seth Mos
			   <tr>
210 0cabd5db Colin Fleming
				<td><a href="system_gateways_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="edit" /></a></td>
211 295ff120 Seth Mos
				<?php
212 2f36abb8 Ermal
				if (is_numeric($gateway['attribute'])) : ?>
213 0e94685b Renato Botelho
					<td>
214 0cabd5db Colin Fleming
						<a href="system_gateways.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this gateway?"); ?>')">
215
							<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" />
216 0e94685b Renato Botelho
						</a>
217
					</td>
218 295ff120 Seth Mos
				<?php else : ?>
219
					<td width='17'></td>
220
				<?php endif; ?>
221 d173230c Seth Mos
			   </tr>
222
			   <tr>
223
				<td width="17"></td>
224 0cabd5db Colin Fleming
				<td><a href="system_gateways_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" /></a></td>
225 d173230c Seth Mos
			   </tr>
226
			</table>
227 0cabd5db Colin Fleming
			</td>
228 d173230c Seth Mos
		</tr>
229 ef05ae5f Ermal
		  <?php $i++; endforeach; ?>
230 d173230c Seth Mos
                <tr>
231
                  <td class="list" colspan="5"></td>
232
                  <td class="list">
233 0cabd5db Colin Fleming
			<table border="0" cellspacing="0" cellpadding="1" summary="edit">
234 d173230c Seth Mos
			   <tr>
235
				<td width="17"></td>
236 0cabd5db Colin Fleming
				<td><a href="system_gateways_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="edit" /></a></td>
237 d173230c Seth Mos
			   </tr>
238 40e59dbf Scott Ullrich
		                    </table>
239
				  </td>
240
		                </tr>
241 d173230c Seth Mos
			</table>
242 40e59dbf Scott Ullrich
			</div>
243
			</td>
244
		  </tr>
245
		</table>
246 d173230c Seth Mos
            </form>
247
<?php include("fend.inc"); ?>
248
</body>
249
</html>