Project

General

Profile

Download (8.82 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_gateways.php
5
	part of pfSense (http://pfsense.com)
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);
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
$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
		/* reconfigure our gateway monitor */
71
		setup_gateways_monitor();
72

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

    
79
if ($_GET['act'] == "del") {
80
	if ($a_gateways[$_GET['id']]) {
81
		/* remove the real entry */
82
		$realid = $a_gateways[$_GET['id']]['attribute'];
83
		$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
			if ($config['interfaces'][$a_gateways[$_GET['id']]['friendlyiface']]['gateway'] == $a_gateways[$_GET['id']]['name'])
108
				unset($config['interfaces'][$a_gateways[$_GET['id']]['friendlyiface']]['gateway']);
109
			$changedesc .= "removed gateway {$realid}";
110
			unset($a_gateway_item[$realid]);
111
			write_config($changedesc);
112
			mark_subsystem_dirty('staticroutes');
113
			header("Location: system_gateways.php");
114
			exit;
115
		}
116
	}
117
}
118

    
119

    
120
$pgtitle = array(gettext("System"),gettext("Gateways"));
121
$statusurl = "status_gateways.php";
122

    
123
include("head.inc");
124

    
125
?>
126

    
127
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
128
<?php include("fbegin.inc"); ?>
129
<?php if ($input_errors) print_input_errors($input_errors); ?>
130
<form action="system_gateways.php" method="post">
131
<input type="hidden" name="y1" value="1">
132
<?php if ($savemsg) print_info_box($savemsg); ?>
133
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
134
<?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>
135
<?php endif; ?>
136
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
137
		<tr>
138
		  <td>
139
<?php
140
			$tab_array = array();
141
			$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
142
			$tab_array[1] = array(gettext("Routes"), false, "system_routes.php");
143
			$tab_array[2] = array(gettext("Groups"), false, "system_gateway_groups.php");
144
			display_top_tabs($tab_array);
145
?>
146
</td></tr>
147
 <tr>
148
   <td>
149
	<div id="mainarea">
150
             <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
151
                <tr>
152
                  <td width="15%" class="listhdrr"><?=gettext("Name"); ?></td>
153
                  <td width="15%" class="listhdrr"><?=gettext("Interface"); ?></td>
154
                  <td width="20%" class="listhdrr"><?=gettext("Gateway"); ?></td>
155
                  <td width="20%" class="listhdrr"><?=gettext("Monitor IP"); ?></td>
156
                  <td width="30%" class="listhdr"><?=gettext("Description"); ?></td>
157
                  <td width="10%" class="list">
158
			<table border="0" cellspacing="0" cellpadding="1">
159
			   <tr>
160
				<td width="17"></td>
161
				<td><a href="system_gateways_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
162
			   </tr>
163
			</table>
164
		  </td>
165
		</tr>
166
			  <?php $i = 0; foreach ($a_gateways as $gateway): ?>
167
                <tr>
168
                  <td class="listlr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
169
                    <?php
170
			echo $gateway['name'];
171
			if(isset($gateway['defaultgw'])) {
172
				echo " <strong>(default)<strong>";
173
			}
174
			?>
175
			
176
                  </td>
177
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
178
                    <?php
179
				echo htmlspecialchars(convert_real_interface_to_friendly_descr($gateway['interface']));
180
			?>
181
                  </td>
182
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
183
				  <?php
184
					if(isset($gateway['interfacegateway'])) {
185
						echo strtoupper($gateway['interface']) . " ";
186
					} else {
187
						if(is_numeric($gateway['attribute']) && ($a_gateway_item[$gateway['attribute']]['gateway'] == "dynamic")) {
188
							echo "dynamic";
189
						} else {
190
							echo $gateway['gateway'] . " ";
191
						}
192
					}
193
				  ?>
194
                  </td>
195
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
196
                    <?php
197
			if(is_numeric($gateway['attribute']) && ($a_gateway_item[$gateway['attribute']]['monitor'] == "dynamic")) {
198
				echo "dynamic";
199
			} else {
200
				echo htmlspecialchars($gateway['monitor']) . " ";
201
			}
202
		    ?>
203
                  </td>
204
		<?php if($gateway['attribute'] == "system") : ?>
205
                  <td class="listbgns" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
206
		<?php else : ?>
207
                  <td class="listbg" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
208
		<?php endif; ?>
209
                    <?=htmlspecialchars($gateway['descr']);?>&nbsp;
210
                  </td>
211

    
212
                  <td valign="middle" nowrap class="list">
213
			<table border="0" cellspacing="0" cellpadding="1">
214
			   <tr>
215
				<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"></a>
216
				<?php
217
				if ($gateway['attribute'] != "system") : ?>
218
					<td>
219
						<a href="system_gateways.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this gateway?"); ?>')">
220
							<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0">
221
						</a>
222
					</td>
223
				<?php else : ?>
224
					<td width='17'></td>
225
				<?php endif; ?>
226
			   </tr>
227
			   <tr>
228
				<td width="17"></td>
229
				<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"></a></td>
230
			   </tr>
231
			</table>
232

    
233
		</tr>
234
			  <?php $i++; endforeach; ?>
235
                <tr>
236
                  <td class="list" colspan="5"></td>
237
                  <td class="list">
238
			<table border="0" cellspacing="0" cellpadding="1">
239
			   <tr>
240
				<td width="17"></td>
241
				<td><a href="system_gateways_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
242
			   </tr>
243
		                    </table>
244
				  </td>
245
		                </tr>
246
			</table>
247
			</div>
248
			</td>
249
		  </tr>
250
		</table>
251
            </form>
252
<?php include("fend.inc"); ?>
253
</body>
254
</html>
(188-188/222)