Project

General

Profile

Download (11.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_gre_edit.php
5

    
6
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7
	Copyright (C) 2008 Ermal Luçi
8
	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
/*
32
	pfSense_MODULE:	interfaces
33
*/
34

    
35
##|+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
require("guiconfig.inc");
43
require_once("functions.inc");
44

    
45
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_gre.php');
46

    
47
if (!is_array($config['gres']['gre']))
48
	$config['gres']['gre'] = array();
49

    
50
$a_gres = &$config['gres']['gre'];
51

    
52
if (is_numericint($_GET['id']))
53
	$id = $_GET['id'];
54
if (isset($_POST['id']) && is_numericint($_POST['id']))
55
	$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
	$reqdfieldsn = array(gettext("Parent interface"),gettext("Local address"),gettext("Remote tunnel address"),gettext("Remote tunnel network"), gettext("Local tunnel address"));
78

    
79
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
80

    
81
	if ((!is_ipaddr($_POST['tunnel-local-addr'])) || (!is_ipaddr($_POST['tunnel-remote-addr'])) ||
82
			(!is_ipaddr($_POST['remote-addr']))) {
83
		$input_errors[] = gettext("The tunnel local and tunnel remote fields must have valid IP addresses.");
84
	}
85

    
86
	foreach ($a_gres as $gre) {
87
		if (isset($id) && ($a_gres[$id]) && ($a_gres[$id] === $gre))
88
			continue;
89

    
90
		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
			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
                        $input_errors[] = gettext("Error occurred creating interface, please retry.");
112
                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
			$confif = convert_real_interface_to_friendly_interface_name($gre['greif']);
121
                        if ($confif <> "")
122
                                interface_configure($confif);
123

    
124
			header("Location: interfaces_gre.php");
125
			exit;
126
		}
127
	}
128
}
129

    
130
$pgtitle = array(gettext("Interfaces"),gettext("GRE"),gettext("Edit"));
131
$shortcut_section = "interfaces";
132
include("head.inc");
133

    
134
?>
135

    
136
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
137
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
138
<?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
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces gre edit">
142
				<tr>
143
					<td colspan="2" valign="top" class="listtopic"><?=gettext("GRE configuration");?></td>
144
				</tr>
145
				<tr>
146
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
147
                  <td width="78%" class="vtable">
148
                    <select name="if" class="formselect">
149
                      <?php
150
						$portlist = get_configured_interface_with_descr();
151
						$carplist = get_configured_carp_interface_list();
152
						foreach ($carplist as $cif => $carpip)
153
							$portlist[$cif] = $carpip." (".get_vip_descr($carpip).")";
154
						$aliaslist = get_configured_ip_aliases_list();
155
						foreach ($aliaslist as $aliasip => $aliasif)
156
							$portlist[$aliasif.'|'.$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
157
					  	foreach ($portlist as $ifn => $ifinfo) {
158
							echo "<option value=\"{$ifn}\"";
159
							if ($ifn == $pconfig['if'])
160
								echo " selected=\"selected\"";
161
							echo ">" . htmlspecialchars($ifinfo) . "</option>\n";
162
						}
163
		      		?>
164
                    </select>
165
			<br />
166
			<span class="vexpl"><?=gettext("The interface here serves as the local address to be used for the GRE tunnel.");?></span></td>
167
                </tr>
168
				<tr>
169
                  <td valign="top" class="vncellreq"><?=gettext("Remote tunnel endpoint IP address");?></td>
170
                  <td class="vtable">
171
                    <input name="remote-addr" type="text" class="formfld unknown" id="remote-addr" size="16" value="<?=htmlspecialchars($pconfig['remote-addr']);?>" />
172
                    <br />
173
                    <span class="vexpl"><?=gettext("Peer address where encapsulated GRE packets will be sent ");?></span></td>
174
			    </tr>
175
				<tr>
176
                  <td valign="top" class="vncellreq"><?=gettext("Local tunnel IP address ");?></td>
177
                  <td class="vtable">
178
                    <input name="tunnel-local-addr" type="text" class="formfld unknown" id="tunnel-local-addr" size="16" value="<?=htmlspecialchars($pconfig['tunnel-local-addr']);?>" />
179
                    <br />
180
                    <span class="vexpl"><?=gettext("Local IP address assigned inside this tunnel");?></span></td>
181
			    </tr>
182
				<tr>
183
                  <td valign="top" class="vncellreq"><?=gettext("Remote tunnel IP address ");?></td>
184
                  <td class="vtable">
185
                    <input name="tunnel-remote-addr" type="text" class="formfld unknown ipv4v6" id="tunnel-remote-addr" size="16" value="<?=htmlspecialchars($pconfig['tunnel-remote-addr']);?>" />
186
                    <select name="tunnel-remote-net" class="formselect ipv4v6" id="tunnel-remote-net">
187
                                        <?php
188
                                        for ($i = 128; $i > 0; $i--) {
189
						echo "<option value=\"{$i}\"";
190
						if ($i == $pconfig['tunnel-remote-net'])
191
							echo " selected=\"selected\"";
192
						echo ">" . $i . "</option>";
193
                                        }
194
                                        ?>
195
                    </select>
196
                    <br />
197
                    <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>
198
			    </tr>
199
				<tr>
200
                  <td valign="top" class="vncell"><?=gettext("Mobile encapsulation");?></td>
201
                  <td class="vtable">
202
                    <input name="link0" type="checkbox" id="link0" <?if ($pconfig['link0']) echo "checked=\"checked\"";?> />
203
                    <br />
204
                    <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>
205
			    </tr>
206
				<tr>
207
                  <td valign="top" class="vncell"><?=gettext("Route search type");?></td>
208
                  <td class="vtable">
209
                    <input name="link1" type="checkbox" id="link1" <?if ($pconfig['link1']) echo "checked=\"checked\"";?> />
210
                    <br />
211
                    <span class="vexpl">
212
     <?=gettext("For correct operation, the GRE device needs a route to the destination".
213
    " that is less specific than the one over the tunnel.  (Basically, there".
214
    " needs to be a route to the decapsulating host that does not run over the".
215
    " tunnel, as this would be a loop.");?>
216
					 </span></td>
217
			    </tr>
218
				<tr>
219
                  <td valign="top" class="vncell"><?=gettext("WCCP version");?></td>
220
                  <td class="vtable">
221
                    <input name="link2" type="checkbox" id="link2" <?if ($pconfig['link2']) echo "checked=\"checked\"";?> />
222
                    <br />
223
                    <span class="vexpl"><?=gettext("Check this box for WCCP encapsulation version 2, or leave unchecked for version 1.");?></span></td>
224
			    </tr>
225
				<tr>
226
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
227
                  <td width="78%" class="vtable">
228
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
229
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here".
230
                    " for your reference (not parsed).");?></span></td>
231
                </tr>
232
                <tr>
233
                  <td width="22%" valign="top">&nbsp;</td>
234
                  <td width="78%">
235
		    <input type="hidden" name="greif" value="<?=htmlspecialchars($pconfig['greif']); ?>" />
236
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
237
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
238
                    <?php if (isset($id) && $a_gres[$id]): ?>
239
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
240
                    <?php endif; ?>
241
                  </td>
242
                </tr>
243
              </table>
244
</form>
245
<?php include("fend.inc"); ?>
246
</body>
247
</html>
(102-102/256)