Project

General

Profile

Download (9.83 KB) Statistics
| Branch: | Tag: | Revision:
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
##|+PRIV
32
##|*IDENT=page-interfaces-gre-edit
33
##|*NAME=Interfaces: GRE: Edit page
34
##|*DESCR=Allow access to the 'Interfaces: GRE: Edit' page.
35
##|*MATCH=interfaces_gre_edit.php*
36
##|-PRIV
37

    
38

    
39
require("guiconfig.inc");
40

    
41
if (!is_array($config['gres']['gre']))
42
	$config['gres']['gre'] = array();
43

    
44
$a_gres = &$config['gres']['gre'];
45

    
46

    
47
$id = $_GET['id'];
48
if (isset($_POST['id']))
49
	$id = $_POST['id'];
50

    
51
if (isset($id) && $a_gres[$id]) {
52
	$pconfig['if'] = $a_gres[$id]['if'];
53
	$pconfig['greif'] = $a_gres[$id]['greif'];
54
	$pconfig['remote-addr'] = $a_gres[$id]['remote-addr'];
55
	$pconfig['tunnel-remote-net'] = $a_gres[$id]['tunnel-remote-net'];
56
	$pconfig['tunnel-local-addr'] = $a_gres[$id]['tunnel-local-addr'];
57
	$pconfig['tunnel-remote-addr'] = $a_gres[$id]['tunnel-remote-addr'];
58
	$pconfig['link1'] = isset($a_gres[$id]['link1']);
59
	$pconfig['link2'] = isset($a_gres[$id]['link2']);
60
	$pconfig['link0'] = isset($a_gres[$id]['link0']);
61
	$pconfig['descr'] = $a_gres[$id]['descr'];
62
}
63

    
64
if ($_POST) {
65

    
66
	unset($input_errors);
67
	$pconfig = $_POST;
68

    
69
	/* input validation */
70
	$reqdfields = explode(" ", "if tunnel-remote-addr tunnel-remote-net tunnel-local-addr");
71
	$reqdfieldsn = explode(",", "Parent interface,Local address, Remote tunnel address, Remote tunnel network, Local tunnel address");
72

    
73
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
74

    
75
	if ((!is_ipaddr($_POST['tunnel-local-addr'])) || (!is_ipaddr($_POST['tunnel-remote-addr'])) ||
76
			(!is_ipaddr($_POST['remote-addr']))) {
77
		$input_errors[] = "All fildes must have valid ip addresses.";
78
	}
79

    
80
	foreach ($a_gres as $gre) {
81
		if (isset($id) && ($a_gres[$id]) && ($a_gres[$id] === $gre))
82
			continue;
83

    
84
		if (($gre['if'] == $_POST['if']) && ($gre['tunnel-remote-net'] == $_POST['tunnel-remote-net'])) {
85
			$input_errors[] = "A gre with the network {$gre['remote-network']} is already defined.";
86
			break;
87
		}
88
	}
89

    
90
	if (!$input_errors) {
91
		$gre = array();
92
		$gre['if'] = $_POST['if'];
93
		$gre['tunnel-local-addr'] = $_POST['tunnel-local-addr'];
94
		$gre['tunnel-remote-addr'] = $_POST['tunnel-remote-addr'];
95
		$gre['tunnel-remote-net'] = $_POST['tunnel-remote-net'];
96
		$gre['remote-addr'] = $_POST['remote-addr'];
97
		$gre['descr'] = $_POST['descr'];
98
		$gre['link1'] = isset($_POST['link1']);
99
		$gre['link2'] = isset($_POST['link2']);
100
		$gre['link0'] = isset($_POST['link0']);
101
		$gre['greif'] = $_POST['greif'];
102

    
103
                $gre['greif'] = interface_gre_configure($gre);
104
                if ($gre['greif'] == "" || !stristr($gre['greif'], "gre"))
105
                        $input_errors[] = "Error occured creating interface, please retry.";
106
                else {
107
                        if (isset($id) && $a_gres[$id])
108
                                $a_gres[$id] = $gre;
109
                        else
110
                                $a_gres[] = $gre;
111

    
112
                        write_config();
113

    
114
			header("Location: interfaces_gre.php");
115
			exit;
116
		}
117
	}
118
}
119

    
120
$pgtitle = array("Firewall","GRE","Edit");
121
include("head.inc");
122

    
123
?>
124

    
125
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
126
<?php include("fbegin.inc"); ?>
127
<?php if ($input_errors) print_input_errors($input_errors); ?>
128
            <form action="interfaces_gre_edit.php" method="post" name="iform" id="iform">
129
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
130
				<tr>
131
					<td colspan="2" valign="top" class="listtopic">GRE configuration</td>
132
				</tr>
133
				<tr>
134
                  <td width="22%" valign="top" class="vncellreq">Parent interface</td>
135
                  <td width="78%" class="vtable">
136
                    <select name="if" class="formselect">
137
                      <?php
138
						$portlist = get_configured_interface_with_descr();
139
					  	foreach ($portlist as $ifn => $ifinfo) {
140
							echo "<option value=\"{$ifn}\"";
141
							if ($ifn == $pconfig['if'])
142
								echo "selected";
143
							echo ">{$ifinfo}</option>";
144
						}
145
		      		?>
146
                    </select>
147
			<br/>
148
			<span class="vexpl">The interface here servers as the local address to be used for the GRE tunnel.</span></td>
149
                </tr>
150
				<tr>
151
                  <td valign="top" class="vncellreq">GRE remote address.  </td>
152
                  <td class="vtable">
153
                    <input name="remote-addr" type="text" class="formfld unknown" id="remote-addr" size="16" value="<?=$pconfig['remote-addr'];?>">
154
                    <br>
155
                    <span class="vexpl">Peer address where encapsulated GRE packets will be sent. </span></td>
156
			    </tr>
157
				<tr>
158
                  <td valign="top" class="vncellreq">GRE tunnel local address.  </td>
159
                  <td class="vtable">
160
                    <input name="tunnel-local-addr" type="text" class="formfld unknown" id="tunnel-local-addr" size="16" value="<?=$pconfig['tunnel-local-addr'];?>">
161
                    <br>
162
                    <span class="vexpl">Local GRE tunnel endpoint. </span></td>
163
			    </tr>
164
				<tr>
165
                  <td valign="top" class="vncellreq">GRE tunnel remote address.  </td>
166
                  <td class="vtable">
167
                    <input name="tunnel-remote-addr" type="text" class="formfld unknown" id="tunnel-remote-addr" size="16" value="<?=$pconfig['tunnel-remote-addr'];?>">
168
                    <select name="tunnel-remote-net" class="formselect" id="tunnel-remote-net">
169
                                        <?php
170
                                        for ($i = 32; $i > 0; $i--) {
171
                                                if($i <> 31) {
172
                                                        echo "<option value=\"{$i}\" ";
173
                                                        if ($i == $pconfig['tunnel-remote-net']) echo "selected";
174
                                                        echo ">" . $i . "</option>";
175
                                                }
176
                                        }
177
                                        ?>
178
                    </select>					
179
                    <br/>
180
                    <span class="vexpl">Remote GRE address endpoint. The subnet part is used for the determinig the network that is tunneled.</span></td>
181
			    </tr>
182
				<tr>
183
                  <td valign="top" class="vncellreq">Mobile tunnel.  </td>
184
                  <td class="vtable">
185
                    <input name="link0" type="checkbox" id="link0" <?if ($pconfig['link0']) echo "checked";?>>
186
                    <br>
187
                    <span class="vexpl">Specify which encapsulation method the tunnel should do. </span></td>
188
			    </tr>
189
				<tr>
190
                  <td valign="top" class="vncellreq">Route search type.  </td>
191
                  <td class="vtable">
192
                    <input name="link1" type="checkbox" id="link1" <?if ($pconfig['link1']) echo "checked";?>>
193
                    <br>
194
                    <span class="vexpl">
195
     For correct operation, the gre device needs a route to the destination
196
     that is less specific than the one over the tunnel.  (Basically, there
197
     needs to be a route to the decapsulating host that does not run over the
198
     tunnel, as this would be a loop.)	If the addresses are ambiguous, doing
199
     the ifconfig tunnel step before the ifconfig(8) call to set the gre IP
200
     addresses will help to find a route outside the tunnel.
201
					 </span></td>
202
			    </tr>
203
				<tr>
204
                  <td valign="top" class="vncellreq">WCCP version.  </td>
205
                  <td class="vtable">
206
                    <input name="link2" type="checkbox" id="link2" <?if ($pconfig['link2']) echo "checked";?>>
207
                    <br>
208
                    <span class="vexpl">Specify which WCCP encapsulation(version 1 or 2) method the tunnel should do. </span></td>
209
			    </tr>
210
				<tr>
211
                  <td width="22%" valign="top" class="vncell">Description</td>
212
                  <td width="78%" class="vtable">
213
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
214
                    <br> <span class="vexpl">You may enter a description here
215
                    for your reference (not parsed).</span></td>
216
                </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
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" onclick="history.back()">
222
                    <?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>
(79-79/203)