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