Project

General

Profile

Download (11.2 KB) Statistics
| Branch: | Tag: | Revision:
1 ead45104 Ermal Luçi
<?php
2
/* $Id$ */
3
/*
4
	interfaces_gre_edit.php
5
6 1d7ba683 ayvis
	Copyright (C) 2008 Ermal Luçi
7 ead45104 Ermal Luçi
	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 62424bdb Renato Botelho
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_gre.php');
45
46 ead45104 Ermal Luçi
if (!is_array($config['gres']['gre']))
47
	$config['gres']['gre'] = array();
48
49
$a_gres = &$config['gres']['gre'];
50
51 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
52
	$id = $_GET['id'];
53
if (isset($_POST['id']) && is_numericint($_POST['id']))
54 ead45104 Ermal Luçi
	$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 93bcbb6a Renato Botelho
	$reqdfieldsn = array(gettext("Parent interface"),gettext("Local address"),gettext("Remote tunnel address"),gettext("Remote tunnel network"), gettext("Local tunnel address"));
77 ead45104 Ermal Luçi
78 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
79 ead45104 Ermal Luçi
80
	if ((!is_ipaddr($_POST['tunnel-local-addr'])) || (!is_ipaddr($_POST['tunnel-remote-addr'])) ||
81
			(!is_ipaddr($_POST['remote-addr']))) {
82 517dcde7 Carlos Eduardo Ramos
		$input_errors[] = gettext("The tunnel local and tunnel remote fields must have valid IP addresses.");
83 ead45104 Ermal Luçi
	}
84
85
	foreach ($a_gres as $gre) {
86
		if (isset($id) && ($a_gres[$id]) && ($a_gres[$id] === $gre))
87
			continue;
88
89 58685470 Chris Buechler
		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 ead45104 Ermal Luçi
			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 ab9dc5be Chris Buechler
                        $input_errors[] = gettext("Error occurred creating interface, please retry.");
111 ead45104 Ermal Luçi
                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 a2ec32a9 Ermal
			$confif = convert_real_interface_to_friendly_interface_name($gre['greif']);
120
                        if ($confif <> "")
121
                                interface_configure($confif);
122
123 ead45104 Ermal Luçi
			header("Location: interfaces_gre.php");
124
			exit;
125
		}
126
	}
127
}
128
129 baca83aa gnhb
$pgtitle = array(gettext("Interfaces"),gettext("GRE"),gettext("Edit"));
130 b32dd0a6 jim-p
$shortcut_section = "interfaces";
131 ead45104 Ermal Luçi
include("head.inc");
132
133
?>
134
135
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
136 dd8722db Renato Botelho
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
137 ead45104 Ermal Luçi
<?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 f8b41933 Colin Fleming
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces gre edit">
141 ead45104 Ermal Luçi
				<tr>
142 93bcbb6a Renato Botelho
					<td colspan="2" valign="top" class="listtopic"><?=gettext("GRE configuration");?></td>
143 16dcce2a Scott Ullrich
				</tr>
144
				<tr>
145 93bcbb6a Renato Botelho
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
146 ead45104 Ermal Luçi
                  <td width="78%" class="vtable">
147
                    <select name="if" class="formselect">
148
                      <?php
149
						$portlist = get_configured_interface_with_descr();
150 11decf6e Ermal
						$carplist = get_configured_carp_interface_list();
151
						foreach ($carplist as $cif => $carpip)
152
							$portlist[$cif] = $carpip." (".get_vip_descr($carpip).")";
153 c3e77841 jim-p
						$aliaslist = get_configured_ip_aliases_list();
154
						foreach ($aliaslist as $aliasip => $aliasif)
155
							$portlist[$aliasif.'|'.$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
156 ead45104 Ermal Luçi
					  	foreach ($portlist as $ifn => $ifinfo) {
157
							echo "<option value=\"{$ifn}\"";
158
							if ($ifn == $pconfig['if'])
159 f8b41933 Colin Fleming
								echo " selected=\"selected\"";
160 c3e77841 jim-p
							echo ">" . htmlspecialchars($ifinfo) . "</option>\n";
161 ead45104 Ermal Luçi
						}
162
		      		?>
163
                    </select>
164 1d7ba683 ayvis
			<br />
165 93bcbb6a Renato Botelho
			<span class="vexpl"><?=gettext("The interface here serves as the local address to be used for the GRE tunnel.");?></span></td>
166 ead45104 Ermal Luçi
                </tr>
167
				<tr>
168 5046435d Chris Buechler
                  <td valign="top" class="vncellreq"><?=gettext("Remote tunnel endpoint IP address");?></td>
169 ead45104 Ermal Luçi
                  <td class="vtable">
170 f8b41933 Colin Fleming
                    <input name="remote-addr" type="text" class="formfld unknown" id="remote-addr" size="16" value="<?=htmlspecialchars($pconfig['remote-addr']);?>" />
171 1d7ba683 ayvis
                    <br />
172 93bcbb6a Renato Botelho
                    <span class="vexpl"><?=gettext("Peer address where encapsulated GRE packets will be sent ");?></span></td>
173 ead45104 Ermal Luçi
			    </tr>
174
				<tr>
175 5046435d Chris Buechler
                  <td valign="top" class="vncellreq"><?=gettext("Local tunnel IP address ");?></td>
176 ead45104 Ermal Luçi
                  <td class="vtable">
177 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']);?>" />
178 1d7ba683 ayvis
                    <br />
179 5046435d Chris Buechler
                    <span class="vexpl"><?=gettext("Local IP address assigned inside this tunnel");?></span></td>
180 ead45104 Ermal Luçi
			    </tr>
181
				<tr>
182 5046435d Chris Buechler
                  <td valign="top" class="vncellreq"><?=gettext("Remote tunnel IP address ");?></td>
183 ead45104 Ermal Luçi
                  <td class="vtable">
184 dd8722db 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']);?>" />
185
                    <select name="tunnel-remote-net" class="formselect ipv4v6" id="tunnel-remote-net">
186 ead45104 Ermal Luçi
                                        <?php
187 2d107ad5 smos
                                        for ($i = 128; $i > 0; $i--) {
188 f8b41933 Colin Fleming
						echo "<option value=\"{$i}\"";
189 2d107ad5 smos
						if ($i == $pconfig['tunnel-remote-net'])
190 f8b41933 Colin Fleming
							echo " selected=\"selected\"";
191 2d107ad5 smos
						echo ">" . $i . "</option>";
192 ead45104 Ermal Luçi
                                        }
193
                                        ?>
194 2d107ad5 smos
                    </select>
195 1d7ba683 ayvis
                    <br />
196 5046435d Chris Buechler
                    <span class="vexpl"><?=gettext("IP address inside this tunnel on the remote end. The subnet part is used for the determining the network that is tunneled.");?></span></td>
197 ead45104 Ermal Luçi
			    </tr>
198
				<tr>
199 5046435d Chris Buechler
                  <td valign="top" class="vncell"><?=gettext("Mobile encapsulation");?></td>
200 ead45104 Ermal Luçi
                  <td class="vtable">
201 f8b41933 Colin Fleming
                    <input name="link0" type="checkbox" id="link0" <?if ($pconfig['link0']) echo "checked=\"checked\"";?> />
202 1d7ba683 ayvis
                    <br />
203 5046435d Chris Buechler
                    <span class="vexpl"><?=gettext("Check this box to use mobile encapsulation (IP protocol 55, RFC 2004). When unchecked, uses GRE encapsulation (IP protocol 47, RFCs 1701, 1702).");?></span></td>
204 ead45104 Ermal Luçi
			    </tr>
205
				<tr>
206 93bcbb6a Renato Botelho
                  <td valign="top" class="vncell"><?=gettext("Route search type");?></td>
207 ead45104 Ermal Luçi
                  <td class="vtable">
208 f8b41933 Colin Fleming
                    <input name="link1" type="checkbox" id="link1" <?if ($pconfig['link1']) echo "checked=\"checked\"";?> />
209 1d7ba683 ayvis
                    <br />
210 ead45104 Ermal Luçi
                    <span class="vexpl">
211 93bcbb6a Renato Botelho
     <?=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 ead45104 Ermal Luçi
					 </span></td>
216
			    </tr>
217
				<tr>
218 93bcbb6a Renato Botelho
                  <td valign="top" class="vncell"><?=gettext("WCCP version");?></td>
219 ead45104 Ermal Luçi
                  <td class="vtable">
220 f8b41933 Colin Fleming
                    <input name="link2" type="checkbox" id="link2" <?if ($pconfig['link2']) echo "checked=\"checked\"";?> />
221 1d7ba683 ayvis
                    <br />
222 ff6c9852 Chris Buechler
                    <span class="vexpl"><?=gettext("Check this box for WCCP encapsulation version 2, or leave unchecked for version 1.");?></span></td>
223 ead45104 Ermal Luçi
			    </tr>
224
				<tr>
225 93bcbb6a Renato Botelho
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
226 ead45104 Ermal Luçi
                  <td width="78%" class="vtable">
227 f8b41933 Colin Fleming
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
228 1d7ba683 ayvis
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here".
229 93bcbb6a Renato Botelho
                    " for your reference (not parsed).");?></span></td>
230 ead45104 Ermal Luçi
                </tr>
231
                <tr>
232
                  <td width="22%" valign="top">&nbsp;</td>
233
                  <td width="78%">
234 f8b41933 Colin Fleming
		    <input type="hidden" name="greif" value="<?=htmlspecialchars($pconfig['greif']); ?>" />
235 62424bdb Renato Botelho
                    <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 ead45104 Ermal Luçi
                    <?php if (isset($id) && $a_gres[$id]): ?>
238 f8b41933 Colin Fleming
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
239 ead45104 Ermal Luçi
                    <?php endif; ?>
240
                  </td>
241
                </tr>
242
              </table>
243
</form>
244
<?php include("fend.inc"); ?>
245
</body>
246
</html>