Projet

Général

Profil

Télécharger (11 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / interfaces_gre_edit.php @ 62424bdb

1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_gre_edit.php
5

    
6
	Copyright (C) 2008 Ermal Luçi
7
	All rights reserved.
8

    
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11

    
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14

    
15
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18

    
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/*
31
	pfSense_MODULE:	interfaces
32
*/
33

    
34
##|+PRIV
35
##|*IDENT=page-interfaces-gre-edit
36
##|*NAME=Interfaces: GRE: Edit page
37
##|*DESCR=Allow access to the 'Interfaces: GRE: Edit' page.
38
##|*MATCH=interfaces_gre_edit.php*
39
##|-PRIV
40

    
41
require("guiconfig.inc");
42
require_once("functions.inc");
43

    
44
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_gre.php');
45

    
46
if (!is_array($config['gres']['gre']))
47
	$config['gres']['gre'] = array();
48

    
49
$a_gres = &$config['gres']['gre'];
50

    
51
if (is_numericint($_GET['id']))
52
	$id = $_GET['id'];
53
if (isset($_POST['id']) && is_numericint($_POST['id']))
54
	$id = $_POST['id'];
55

    
56
if (isset($id) && $a_gres[$id]) {
57
	$pconfig['if'] = $a_gres[$id]['if'];
58
	$pconfig['greif'] = $a_gres[$id]['greif'];
59
	$pconfig['remote-addr'] = $a_gres[$id]['remote-addr'];
60
	$pconfig['tunnel-remote-net'] = $a_gres[$id]['tunnel-remote-net'];
61
	$pconfig['tunnel-local-addr'] = $a_gres[$id]['tunnel-local-addr'];
62
	$pconfig['tunnel-remote-addr'] = $a_gres[$id]['tunnel-remote-addr'];
63
	$pconfig['link1'] = isset($a_gres[$id]['link1']);
64
	$pconfig['link2'] = isset($a_gres[$id]['link2']);
65
	$pconfig['link0'] = isset($a_gres[$id]['link0']);
66
	$pconfig['descr'] = $a_gres[$id]['descr'];
67
}
68

    
69
if ($_POST) {
70

    
71
	unset($input_errors);
72
	$pconfig = $_POST;
73

    
74
	/* input validation */
75
	$reqdfields = explode(" ", "if tunnel-remote-addr tunnel-remote-net tunnel-local-addr");
76
	$reqdfieldsn = array(gettext("Parent interface"),gettext("Local address"),gettext("Remote tunnel address"),gettext("Remote tunnel network"), gettext("Local tunnel address"));
77

    
78
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
79

    
80
	if ((!is_ipaddr($_POST['tunnel-local-addr'])) || (!is_ipaddr($_POST['tunnel-remote-addr'])) ||
81
			(!is_ipaddr($_POST['remote-addr']))) {
82
		$input_errors[] = gettext("The tunnel local and tunnel remote fields must have valid IP addresses.");
83
	}
84

    
85
	foreach ($a_gres as $gre) {
86
		if (isset($id) && ($a_gres[$id]) && ($a_gres[$id] === $gre))
87
			continue;
88

    
89
		if (($gre['if'] == $_POST['if']) && ($gre['tunnel-remote-addr'] == $_POST['tunnel-remote-addr'])) {
90
			$input_errors[] = sprintf(gettext("A GRE tunnel with the network %s is already defined."),$gre['remote-network']);
91
			break;
92
		}
93
	}
94

    
95
	if (!$input_errors) {
96
		$gre = array();
97
		$gre['if'] = $_POST['if'];
98
		$gre['tunnel-local-addr'] = $_POST['tunnel-local-addr'];
99
		$gre['tunnel-remote-addr'] = $_POST['tunnel-remote-addr'];
100
		$gre['tunnel-remote-net'] = $_POST['tunnel-remote-net'];
101
		$gre['remote-addr'] = $_POST['remote-addr'];
102
		$gre['descr'] = $_POST['descr'];
103
		$gre['link1'] = isset($_POST['link1']);
104
		$gre['link2'] = isset($_POST['link2']);
105
		$gre['link0'] = isset($_POST['link0']);
106
		$gre['greif'] = $_POST['greif'];
107

    
108
                $gre['greif'] = interface_gre_configure($gre);
109
                if ($gre['greif'] == "" || !stristr($gre['greif'], "gre"))
110
                        $input_errors[] = gettext("Error occurred creating interface, please retry.");
111
                else {
112
                        if (isset($id) && $a_gres[$id])
113
                                $a_gres[$id] = $gre;
114
                        else
115
                                $a_gres[] = $gre;
116

    
117
                        write_config();
118

    
119
			$confif = convert_real_interface_to_friendly_interface_name($gre['greif']);
120
                        if ($confif <> "")
121
                                interface_configure($confif);
122

    
123
			header("Location: interfaces_gre.php");
124
			exit;
125
		}
126
	}
127
}
128

    
129
$pgtitle = array(gettext("Interfaces"),gettext("GRE"),gettext("Edit"));
130
$shortcut_section = "interfaces";
131
include("head.inc");
132

    
133
?>
134

    
135
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
136
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
137
<?php include("fbegin.inc"); ?>
138
<?php if ($input_errors) print_input_errors($input_errors); ?>
139
            <form action="interfaces_gre_edit.php" method="post" name="iform" id="iform">
140
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces gre edit">
141
				<tr>
142
					<td colspan="2" valign="top" class="listtopic"><?=gettext("GRE configuration");?></td>
143
				</tr>
144
				<tr>
145
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
146
                  <td width="78%" class="vtable">
147
                    <select name="if" class="formselect">
148
                      <?php
149
						$portlist = get_configured_interface_with_descr();
150
						$carplist = get_configured_carp_interface_list();
151
						foreach ($carplist as $cif => $carpip)
152
							$portlist[$cif] = $carpip." (".get_vip_descr($carpip).")";
153
						$aliaslist = get_configured_ip_aliases_list();
154
						foreach ($aliaslist as $aliasip => $aliasif)
155
							$portlist[$aliasif.'|'.$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
156
					  	foreach ($portlist as $ifn => $ifinfo) {
157
							echo "<option value=\"{$ifn}\"";
158
							if ($ifn == $pconfig['if'])
159
								echo " selected=\"selected\"";
160
							echo ">" . htmlspecialchars($ifinfo) . "</option>\n";
161
						}
162
		      		?>
163
                    </select>
164
			<br />
165
			<span class="vexpl"><?=gettext("The interface here serves as the local address to be used for the GRE tunnel.");?></span></td>
166
                </tr>
167
				<tr>
168
                  <td valign="top" class="vncellreq"><?=gettext("GRE remote address");?></td>
169
                  <td class="vtable">
170
                    <input name="remote-addr" type="text" class="formfld unknown" id="remote-addr" size="16" value="<?=htmlspecialchars($pconfig['remote-addr']);?>" />
171
                    <br />
172
                    <span class="vexpl"><?=gettext("Peer address where encapsulated GRE packets will be sent ");?></span></td>
173
			    </tr>
174
				<tr>
175
                  <td valign="top" class="vncellreq"><?=gettext("GRE tunnel local address ");?></td>
176
                  <td class="vtable">
177
                    <input name="tunnel-local-addr" type="text" class="formfld unknown" id="tunnel-local-addr" size="16" value="<?=htmlspecialchars($pconfig['tunnel-local-addr']);?>" />
178
                    <br />
179
                    <span class="vexpl"><?=gettext("Local GRE tunnel endpoint");?></span></td>
180
			    </tr>
181
				<tr>
182
                  <td valign="top" class="vncellreq"><?=gettext("GRE tunnel remote address ");?></td>
183
                  <td class="vtable">
184
                    <input name="tunnel-remote-addr" type="text" class="formfld unknown ipv4v6" id="tunnel-remote-addr" size="16" value="<?=htmlspecialchars($pconfig['tunnel-remote-addr']);?>" />
185
                    <select name="tunnel-remote-net" class="formselect ipv4v6" id="tunnel-remote-net">
186
                                        <?php
187
                                        for ($i = 128; $i > 0; $i--) {
188
						echo "<option value=\"{$i}\"";
189
						if ($i == $pconfig['tunnel-remote-net'])
190
							echo " selected=\"selected\"";
191
						echo ">" . $i . "</option>";
192
                                        }
193
                                        ?>
194
                    </select>
195
                    <br />
196
                    <span class="vexpl"><?=gettext("Remote GRE address endpoint. The subnet part is used for the determining the network that is tunneled.");?></span></td>
197
			    </tr>
198
				<tr>
199
                  <td valign="top" class="vncell"><?=gettext("Mobile tunnel");?></td>
200
                  <td class="vtable">
201
                    <input name="link0" type="checkbox" id="link0" <?if ($pconfig['link0']) echo "checked=\"checked\"";?> />
202
                    <br />
203
                    <span class="vexpl"><?=gettext("Specify which encapsulation method the tunnel should use. ");?></span></td>
204
			    </tr>
205
				<tr>
206
                  <td valign="top" class="vncell"><?=gettext("Route search type");?></td>
207
                  <td class="vtable">
208
                    <input name="link1" type="checkbox" id="link1" <?if ($pconfig['link1']) echo "checked=\"checked\"";?> />
209
                    <br />
210
                    <span class="vexpl">
211
     <?=gettext("For correct operation, the GRE device needs a route to the destination".
212
    " that is less specific than the one over the tunnel.  (Basically, there".
213
    " needs to be a route to the decapsulating host that does not run over the".
214
    " tunnel, as this would be a loop.");?>
215
					 </span></td>
216
			    </tr>
217
				<tr>
218
                  <td valign="top" class="vncell"><?=gettext("WCCP version");?></td>
219
                  <td class="vtable">
220
                    <input name="link2" type="checkbox" id="link2" <?if ($pconfig['link2']) echo "checked=\"checked\"";?> />
221
                    <br />
222
                    <span class="vexpl"><?=gettext("Check this box for WCCP encapsulation version 2, or leave unchecked for version 1.");?></span></td>
223
			    </tr>
224
				<tr>
225
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
226
                  <td width="78%" class="vtable">
227
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
228
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here".
229
                    " for your reference (not parsed).");?></span></td>
230
                </tr>
231
                <tr>
232
                  <td width="22%" valign="top">&nbsp;</td>
233
                  <td width="78%">
234
		    <input type="hidden" name="greif" value="<?=htmlspecialchars($pconfig['greif']); ?>" />
235
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
236
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
237
                    <?php if (isset($id) && $a_gres[$id]): ?>
238
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
239
                    <?php endif; ?>
240
                  </td>
241
                </tr>
242
              </table>
243
</form>
244
<?php include("fend.inc"); ?>
245
</body>
246
</html>
(102-102/256)