Project

General

Profile

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