Projet

Général

Profil

Télécharger (9,31 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / system_gateways.php @ 2d1e985d

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
	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
			/* 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
			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
	}
126
}
127

    
128

    
129
$pgtitle = array(gettext("System"),gettext("Gateways"));
130
$shortcut_section = "gateways";
131

    
132
include("head.inc");
133

    
134
?>
135

    
136
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
137
<?php include("fbegin.inc"); ?>
138
<?php if ($input_errors) print_input_errors($input_errors); ?>
139
<form action="system_gateways.php" method="post">
140
<input type="hidden" name="y1" value="1" />
141
<?php if ($savemsg) print_info_box($savemsg); ?>
142
<?php if (is_subsystem_dirty('staticroutes')): ?><p>
143
<?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
<?php endif; ?>
145
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system gatewyas">
146
		<tr>
147
		  <td>
148
<?php
149
			$tab_array = array();
150
			$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
			display_top_tabs($tab_array);
154
?>
155
</td></tr>
156
 <tr>
157
   <td>
158
	<div id="mainarea">
159
             <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
160
                <tr>
161
                  <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
                  <td width="10%" class="list">
167
			<table border="0" cellspacing="0" cellpadding="1" summary="add">
168
			   <tr>
169
				<td width="17"></td>
170
				<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
			   </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
		<?php
179
			echo $gateway['name'];
180
			if(isset($gateway['defaultgw']))
181
				echo " <strong>(default)</strong>";
182
		?>
183
                  </td>
184
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
185
		<?php
186
			echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']));
187
		?>
188
                  </td>
189
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
190
		<?php
191
			echo $gateway['gateway'] . " ";
192
		?>
193
                  </td>
194
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
195
		<?php
196
			echo htmlspecialchars($gateway['monitor']) . " ";
197
		?>
198
                  </td>
199
		<?php if (is_numeric($gateway['attribute'])) : ?>
200
                  <td class="listbg" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
201
		<?php else : ?>
202
                  <td class="listbgns" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
203
		<?php endif; ?>
204
                    <?=htmlspecialchars($gateway['descr']);?>&nbsp;
205
                  </td>
206

    
207
                  <td valign="middle" class="list nowrap">
208
			<table border="0" cellspacing="0" cellpadding="1" summary="icons">
209
			   <tr>
210
				<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
				<?php
212
				if (is_numeric($gateway['attribute'])) : ?>
213
					<td>
214
						<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
						</a>
217
					</td>
218
				<?php else : ?>
219
					<td width='17'></td>
220
				<?php endif; ?>
221
			   </tr>
222
			   <tr>
223
				<td width="17"></td>
224
				<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
			   </tr>
226
			</table>
227
			</td>
228
		</tr>
229
		  <?php $i++; endforeach; ?>
230
                <tr>
231
                  <td class="list" colspan="5"></td>
232
                  <td class="list">
233
			<table border="0" cellspacing="0" cellpadding="1" summary="edit">
234
			   <tr>
235
				<td width="17"></td>
236
				<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
			   </tr>
238
		                    </table>
239
				  </td>
240
		                </tr>
241
			</table>
242
			</div>
243
			</td>
244
		  </tr>
245
		</table>
246
            </form>
247
<?php include("fend.inc"); ?>
248
</body>
249
</html>
(213-213/246)