Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
1 ead45104 Ermal Luçi
<?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 7ac5a4cb Scott Ullrich
/*
31
	pfSense_MODULE:	interfaces
32
*/
33 ead45104 Ermal Luçi
34 6b07c15a Matthew Grooms
##|+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 ead45104 Ermal Luçi
require("guiconfig.inc");
42 517dcde7 Carlos Eduardo Ramos
require_once("functions.inc");
43 ead45104 Ermal Luçi
44
if (!is_array($config['gres']['gre']))
45
	$config['gres']['gre'] = array();
46
47
$a_gres = &$config['gres']['gre'];
48
49 0e6cf71b Renato Botelho
if (is_numericint($_GET['id']))
50
	$id = $_GET['id'];
51
if (isset($_POST['id']) && is_numericint($_POST['id']))
52 ead45104 Ermal Luçi
	$id = $_POST['id'];
53
54
if (isset($id) && $a_gres[$id]) {
55
	$pconfig['if'] = $a_gres[$id]['if'];
56
	$pconfig['greif'] = $a_gres[$id]['greif'];
57
	$pconfig['remote-addr'] = $a_gres[$id]['remote-addr'];
58
	$pconfig['tunnel-remote-net'] = $a_gres[$id]['tunnel-remote-net'];
59
	$pconfig['tunnel-local-addr'] = $a_gres[$id]['tunnel-local-addr'];
60
	$pconfig['tunnel-remote-addr'] = $a_gres[$id]['tunnel-remote-addr'];
61
	$pconfig['link1'] = isset($a_gres[$id]['link1']);
62
	$pconfig['link2'] = isset($a_gres[$id]['link2']);
63
	$pconfig['link0'] = isset($a_gres[$id]['link0']);
64
	$pconfig['descr'] = $a_gres[$id]['descr'];
65
}
66
67
if ($_POST) {
68
69
	unset($input_errors);
70
	$pconfig = $_POST;
71
72
	/* input validation */
73
	$reqdfields = explode(" ", "if tunnel-remote-addr tunnel-remote-net tunnel-local-addr");
74 93bcbb6a Renato Botelho
	$reqdfieldsn = array(gettext("Parent interface"),gettext("Local address"),gettext("Remote tunnel address"),gettext("Remote tunnel network"), gettext("Local tunnel address"));
75 ead45104 Ermal Luçi
76
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
77
78
	if ((!is_ipaddr($_POST['tunnel-local-addr'])) || (!is_ipaddr($_POST['tunnel-remote-addr'])) ||
79
			(!is_ipaddr($_POST['remote-addr']))) {
80 517dcde7 Carlos Eduardo Ramos
		$input_errors[] = gettext("The tunnel local and tunnel remote fields must have valid IP addresses.");
81 ead45104 Ermal Luçi
	}
82
83
	foreach ($a_gres as $gre) {
84
		if (isset($id) && ($a_gres[$id]) && ($a_gres[$id] === $gre))
85
			continue;
86
87 58685470 Chris Buechler
		if (($gre['if'] == $_POST['if']) && ($gre['tunnel-remote-addr'] == $_POST['tunnel-remote-addr'])) {
88
			$input_errors[] = sprintf(gettext("A GRE tunnel with the network %s is already defined."),$gre['remote-network']);
89 ead45104 Ermal Luçi
			break;
90
		}
91
	}
92
93
	if (!$input_errors) {
94
		$gre = array();
95
		$gre['if'] = $_POST['if'];
96
		$gre['tunnel-local-addr'] = $_POST['tunnel-local-addr'];
97
		$gre['tunnel-remote-addr'] = $_POST['tunnel-remote-addr'];
98
		$gre['tunnel-remote-net'] = $_POST['tunnel-remote-net'];
99
		$gre['remote-addr'] = $_POST['remote-addr'];
100
		$gre['descr'] = $_POST['descr'];
101
		$gre['link1'] = isset($_POST['link1']);
102
		$gre['link2'] = isset($_POST['link2']);
103
		$gre['link0'] = isset($_POST['link0']);
104
		$gre['greif'] = $_POST['greif'];
105
106
                $gre['greif'] = interface_gre_configure($gre);
107
                if ($gre['greif'] == "" || !stristr($gre['greif'], "gre"))
108 e2967ba6 Chris Buechler
                        $input_errors[] = gettext("Error occurred creating interface, please retry.");
109 ead45104 Ermal Luçi
                else {
110
                        if (isset($id) && $a_gres[$id])
111
                                $a_gres[$id] = $gre;
112
                        else
113
                                $a_gres[] = $gre;
114
115
                        write_config();
116
117 a2ec32a9 Ermal
			$confif = convert_real_interface_to_friendly_interface_name($gre['greif']);
118
                        if ($confif <> "")
119
                                interface_configure($confif);
120
121 ead45104 Ermal Luçi
			header("Location: interfaces_gre.php");
122
			exit;
123
		}
124
	}
125
}
126
127 baca83aa gnhb
$pgtitle = array(gettext("Interfaces"),gettext("GRE"),gettext("Edit"));
128 b32dd0a6 jim-p
$shortcut_section = "interfaces";
129 ead45104 Ermal Luçi
include("head.inc");
130
131
?>
132
133
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
134 de304598 Renato Botelho
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
135 ead45104 Ermal Luçi
<?php include("fbegin.inc"); ?>
136
<?php if ($input_errors) print_input_errors($input_errors); ?>
137
            <form action="interfaces_gre_edit.php" method="post" name="iform" id="iform">
138 f8b41933 Colin Fleming
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces gre edit">
139 ead45104 Ermal Luçi
				<tr>
140 93bcbb6a Renato Botelho
					<td colspan="2" valign="top" class="listtopic"><?=gettext("GRE configuration");?></td>
141 16dcce2a Scott Ullrich
				</tr>
142
				<tr>
143 93bcbb6a Renato Botelho
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
144 ead45104 Ermal Luçi
                  <td width="78%" class="vtable">
145
                    <select name="if" class="formselect">
146
                      <?php
147
						$portlist = get_configured_interface_with_descr();
148 11decf6e Ermal
						$carplist = get_configured_carp_interface_list();
149
						foreach ($carplist as $cif => $carpip)
150
							$portlist[$cif] = $carpip." (".get_vip_descr($carpip).")";
151 978c71d2 jim-p
						$aliaslist = get_configured_ip_aliases_list();
152
						foreach ($aliaslist as $aliasip => $aliasif)
153
							$portlist[$aliasif.'|'.$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
154 ead45104 Ermal Luçi
					  	foreach ($portlist as $ifn => $ifinfo) {
155
							echo "<option value=\"{$ifn}\"";
156
							if ($ifn == $pconfig['if'])
157 f8b41933 Colin Fleming
								echo " selected=\"selected\"";
158 978c71d2 jim-p
							echo ">" . htmlspecialchars($ifinfo) . "</option>\n";
159 ead45104 Ermal Luçi
						}
160
		      		?>
161
                    </select>
162
			<br/>
163 93bcbb6a Renato Botelho
			<span class="vexpl"><?=gettext("The interface here serves as the local address to be used for the GRE tunnel.");?></span></td>
164 ead45104 Ermal Luçi
                </tr>
165
				<tr>
166 93bcbb6a Renato Botelho
                  <td valign="top" class="vncellreq"><?=gettext("GRE remote address");?></td>
167 ead45104 Ermal Luçi
                  <td class="vtable">
168 f8b41933 Colin Fleming
                    <input name="remote-addr" type="text" class="formfld unknown" id="remote-addr" size="16" value="<?=htmlspecialchars($pconfig['remote-addr']);?>" />
169
                    <br/>
170 93bcbb6a Renato Botelho
                    <span class="vexpl"><?=gettext("Peer address where encapsulated GRE packets will be sent ");?></span></td>
171 ead45104 Ermal Luçi
			    </tr>
172
				<tr>
173 93bcbb6a Renato Botelho
                  <td valign="top" class="vncellreq"><?=gettext("GRE tunnel local address ");?></td>
174 ead45104 Ermal Luçi
                  <td class="vtable">
175 f8b41933 Colin Fleming
                    <input name="tunnel-local-addr" type="text" class="formfld unknown" id="tunnel-local-addr" size="16" value="<?=htmlspecialchars($pconfig['tunnel-local-addr']);?>" />
176
                    <br/>
177 93bcbb6a Renato Botelho
                    <span class="vexpl"><?=gettext("Local GRE tunnel endpoint");?></span></td>
178 ead45104 Ermal Luçi
			    </tr>
179
				<tr>
180 93bcbb6a Renato Botelho
                  <td valign="top" class="vncellreq"><?=gettext("GRE tunnel remote address ");?></td>
181 ead45104 Ermal Luçi
                  <td class="vtable">
182 de304598 Renato Botelho
                    <input name="tunnel-remote-addr" type="text" class="formfld unknown ipv4v6" id="tunnel-remote-addr" size="16" value="<?=htmlspecialchars($pconfig['tunnel-remote-addr']);?>" />
183
                    <select name="tunnel-remote-net" class="formselect ipv4v6" id="tunnel-remote-net">
184 ead45104 Ermal Luçi
                                        <?php
185 2d107ad5 smos
                                        for ($i = 128; $i > 0; $i--) {
186 f8b41933 Colin Fleming
						echo "<option value=\"{$i}\"";
187 2d107ad5 smos
						if ($i == $pconfig['tunnel-remote-net'])
188 f8b41933 Colin Fleming
							echo " selected=\"selected\"";
189 2d107ad5 smos
						echo ">" . $i . "</option>";
190 ead45104 Ermal Luçi
                                        }
191
                                        ?>
192 2d107ad5 smos
                    </select>
193 ead45104 Ermal Luçi
                    <br/>
194 93bcbb6a Renato Botelho
                    <span class="vexpl"><?=gettext("Remote GRE address endpoint. The subnet part is used for the determining the network that is tunneled.");?></span></td>
195 ead45104 Ermal Luçi
			    </tr>
196
				<tr>
197 93bcbb6a Renato Botelho
                  <td valign="top" class="vncell"><?=gettext("Mobile tunnel");?></td>
198 ead45104 Ermal Luçi
                  <td class="vtable">
199 f8b41933 Colin Fleming
                    <input name="link0" type="checkbox" id="link0" <?if ($pconfig['link0']) echo "checked=\"checked\"";?> />
200
                    <br/>
201 93bcbb6a Renato Botelho
                    <span class="vexpl"><?=gettext("Specify which encapsulation method the tunnel should use. ");?></span></td>
202 ead45104 Ermal Luçi
			    </tr>
203
				<tr>
204 93bcbb6a Renato Botelho
                  <td valign="top" class="vncell"><?=gettext("Route search type");?></td>
205 ead45104 Ermal Luçi
                  <td class="vtable">
206 f8b41933 Colin Fleming
                    <input name="link1" type="checkbox" id="link1" <?if ($pconfig['link1']) echo "checked=\"checked\"";?> />
207
                    <br/>
208 ead45104 Ermal Luçi
                    <span class="vexpl">
209 93bcbb6a Renato Botelho
     <?=gettext("For correct operation, the GRE device needs a route to the destination".
210
    " that is less specific than the one over the tunnel.  (Basically, there".
211
    " needs to be a route to the decapsulating host that does not run over the".
212
    " tunnel, as this would be a loop.");?>
213 ead45104 Ermal Luçi
					 </span></td>
214
			    </tr>
215
				<tr>
216 93bcbb6a Renato Botelho
                  <td valign="top" class="vncell"><?=gettext("WCCP version");?></td>
217 ead45104 Ermal Luçi
                  <td class="vtable">
218 f8b41933 Colin Fleming
                    <input name="link2" type="checkbox" id="link2" <?if ($pconfig['link2']) echo "checked=\"checked\"";?> />
219
                    <br/>
220 174e151d Chris Buechler
                    <span class="vexpl"><?=gettext("Check this box for WCCP encapsulation version 2, or leave unchecked for version 1.");?></span></td>
221 ead45104 Ermal Luçi
			    </tr>
222
				<tr>
223 93bcbb6a Renato Botelho
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
224 ead45104 Ermal Luçi
                  <td width="78%" class="vtable">
225 f8b41933 Colin Fleming
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
226
                    <br/> <span class="vexpl"><?=gettext("You may enter a description here".
227 93bcbb6a Renato Botelho
                    " for your reference (not parsed).");?></span></td>
228 ead45104 Ermal Luçi
                </tr>
229
                <tr>
230
                  <td width="22%" valign="top">&nbsp;</td>
231
                  <td width="78%">
232 f8b41933 Colin Fleming
		    <input type="hidden" name="greif" value="<?=htmlspecialchars($pconfig['greif']); ?>" />
233
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> <input type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
234 ead45104 Ermal Luçi
                    <?php if (isset($id) && $a_gres[$id]): ?>
235 f8b41933 Colin Fleming
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
236 ead45104 Ermal Luçi
                    <?php endif; ?>
237
                  </td>
238
                </tr>
239
              </table>
240
</form>
241
<?php include("fend.inc"); ?>
242
</body>
243
</html>