Project

General

Profile

Download (9.67 KB) Statistics
| Branch: | Tag: | Revision:
1 ead45104 Ermal Luçi
<?php
2
/* $Id$ */
3
/*
4
	interfaces_gif_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-gif-edit
37
##|*NAME=Interfaces: GIF: Edit page
38
##|*DESCR=Allow access to the 'Interfaces: GIF: Edit' page.
39
##|*MATCH=interfaces_gif_edit.php*
40
##|-PRIV
41
42 ead45104 Ermal Luçi
require("guiconfig.inc");
43
44 5eabad3d Phil Davis
if (isset($_POST['referer'])) {
45
	$referer = $_POST['referer'];
46
} else {
47
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_gif.php');
48
}
49 62424bdb Renato Botelho
50 2af86dda Phil Davis
if (!is_array($config['gifs']['gif'])) {
51 ead45104 Ermal Luçi
	$config['gifs']['gif'] = array();
52 2af86dda Phil Davis
}
53 ead45104 Ermal Luçi
54
$a_gifs = &$config['gifs']['gif'];
55
56 2af86dda Phil Davis
if (is_numericint($_GET['id'])) {
57 e41ec584 Renato Botelho
	$id = $_GET['id'];
58 2af86dda Phil Davis
}
59
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
60 ead45104 Ermal Luçi
	$id = $_POST['id'];
61 2af86dda Phil Davis
}
62 ead45104 Ermal Luçi
63
if (isset($id) && $a_gifs[$id]) {
64
	$pconfig['if'] = $a_gifs[$id]['if'];
65 8436caa7 bcyrill
	if (!empty($a_gifs[$id]['ipaddr'])) {
66
		$pconfig['if'] = $pconfig['if'] . '|' . $a_gifs[$id]['ipaddr'];
67
	}
68 ead45104 Ermal Luçi
	$pconfig['gifif'] = $a_gifs[$id]['gifif'];
69
	$pconfig['remote-addr'] = $a_gifs[$id]['remote-addr'];
70
	$pconfig['tunnel-remote-net'] = $a_gifs[$id]['tunnel-remote-net'];
71
	$pconfig['tunnel-local-addr'] = $a_gifs[$id]['tunnel-local-addr'];
72
	$pconfig['tunnel-remote-addr'] = $a_gifs[$id]['tunnel-remote-addr'];
73
	$pconfig['link1'] = isset($a_gifs[$id]['link1']);
74
	$pconfig['link0'] = isset($a_gifs[$id]['link0']);
75
	$pconfig['descr'] = $a_gifs[$id]['descr'];
76
}
77
78
if ($_POST) {
79
80
	unset($input_errors);
81
	$pconfig = $_POST;
82
83
	/* input validation */
84 e2db25cc Phil Davis
	$reqdfields = explode(" ", "if remote-addr tunnel-local-addr tunnel-remote-addr tunnel-remote-net");
85
	$reqdfieldsn = array(gettext("Parent interface"), gettext("gif remote address"), gettext("gif tunnel local address"), gettext("gif tunnel remote address"), gettext("gif tunnel remote netmask"));
86 ead45104 Ermal Luçi
87 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
88 ead45104 Ermal Luçi
89 2af86dda Phil Davis
	if ((!is_ipaddr($_POST['tunnel-local-addr'])) ||
90
	    (!is_ipaddr($_POST['tunnel-remote-addr'])) ||
91
	    (!is_ipaddr($_POST['remote-addr']))) {
92 a2418a80 Neriberto C.Prado
		$input_errors[] = gettext("The tunnel local and tunnel remote fields must have valid IP addresses.");
93 ead45104 Ermal Luçi
	}
94 0e22dda5 Ermal
95 6c07db48 Phil Davis
	$alias = strstr($_POST['if'], '|');
96 8436caa7 bcyrill
	if ((is_ipaddrv4($alias) && !is_ipaddrv4($_POST['remote-addr'])) ||
97 2af86dda Phil Davis
	    (is_ipaddrv6($alias) && !is_ipaddrv6($_POST['remote-addr']))) {
98 8436caa7 bcyrill
		$input_errors[] = gettext("The alias IP address family has to match the family of the remote peer address.");
99 2af86dda Phil Davis
	}
100 ead45104 Ermal Luçi
101
	foreach ($a_gifs as $gif) {
102 2af86dda Phil Davis
		if (isset($id) && ($a_gifs[$id]) && ($a_gifs[$id] === $gif)) {
103 ead45104 Ermal Luçi
			continue;
104 2af86dda Phil Davis
		}
105 ead45104 Ermal Luçi
106 2af86dda Phil Davis
		/* FIXME: needs to perform proper subnet checks in the future */
107 5b3bd46c bcyrill
		if (($gif['if'] == $interface) && ($gif['tunnel-remote-addr'] == $_POST['tunnel-remote-addr'])) {
108 404e0009 Seth Mos
			$input_errors[] = sprintf(gettext("A gif with the network %s is already defined."), $gif['tunnel-remote-addr']);
109 ead45104 Ermal Luçi
			break;
110
		}
111
	}
112
113
	if (!$input_errors) {
114
		$gif = array();
115 6c07db48 Phil Davis
		list($gif['if'], $gif['ipaddr']) = explode("|", $_POST['if']);
116 ead45104 Ermal Luçi
		$gif['tunnel-local-addr'] = $_POST['tunnel-local-addr'];
117
		$gif['tunnel-remote-addr'] = $_POST['tunnel-remote-addr'];
118
		$gif['tunnel-remote-net'] = $_POST['tunnel-remote-net'];
119
		$gif['remote-addr'] = $_POST['remote-addr'];
120
		$gif['descr'] = $_POST['descr'];
121
		$gif['link1'] = isset($_POST['link1']);
122
		$gif['link0'] = isset($_POST['link0']);
123
		$gif['gifif'] = $_POST['gifif'];
124
125 2af86dda Phil Davis
		$gif['gifif'] = interface_gif_configure($gif);
126
		if ($gif['gifif'] == "" || !stristr($gif['gifif'], "gif")) {
127
			$input_errors[] = gettext("Error occurred creating interface, please retry.");
128
		} else {
129
			if (isset($id) && $a_gifs[$id]) {
130
				$a_gifs[$id] = $gif;
131
			} else {
132
				$a_gifs[] = $gif;
133
			}
134 ead45104 Ermal Luçi
135 2af86dda Phil Davis
			write_config();
136 ead45104 Ermal Luçi
137 a2ec32a9 Ermal
			$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
138 2af86dda Phil Davis
			if ($confif <> "") {
139
				interface_configure($confif);
140
			}
141 a2ec32a9 Ermal
142 ead45104 Ermal Luçi
			header("Location: interfaces_gif.php");
143
			exit;
144
		}
145
	}
146
}
147
148 6c07db48 Phil Davis
$pgtitle = array(gettext("Interfaces"), gettext("GIF"), gettext("Edit"));
149 b32dd0a6 jim-p
$shortcut_section = "interfaces";
150 ead45104 Ermal Luçi
include("head.inc");
151
152
?>
153
154
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
155 f51d5d57 Darren Embry
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
156 ead45104 Ermal Luçi
<?php include("fbegin.inc"); ?>
157
<?php if ($input_errors) print_input_errors($input_errors); ?>
158 2af86dda Phil Davis
<form action="interfaces_gif_edit.php" method="post" name="iform" id="iform">
159
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces gif edit">
160
		<tr>
161
			<td colspan="2" valign="top" class="listtopic"><?=gettext("GIF configuration"); ?></td>
162
		</tr>
163
		<tr>
164
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface"); ?></td>
165
			<td width="78%" class="vtable">
166
				<select name="if" class="formselect">
167
				<?php
168
					$portlist = get_possible_listen_ips();
169
					foreach ($portlist as $ifn => $ifinfo) {
170
						echo "<option value=\"{$ifn}\"";
171
						if ($ifn == $pconfig['if']) {
172
							echo " selected=\"selected\"";
173 ead45104 Ermal Luçi
						}
174 2af86dda Phil Davis
						echo ">" . htmlspecialchars($ifinfo) . "</option>\n";
175
					}
176
				?>
177
				</select>
178
				<br />
179
				<span class="vexpl">
180
					<?=gettext("The interface here serves as the local address to be used for the gif tunnel."); ?>
181
				</span>
182
			</td>
183
		</tr>
184
		<tr>
185
			<td valign="top" class="vncellreq"><?=gettext("gif remote address"); ?></td>
186
			<td class="vtable">
187
				<input name="remote-addr" type="text" class="formfld unknown" id="remote-addr" size="24" value="<?=htmlspecialchars($pconfig['remote-addr']);?>" />
188
				<br />
189
				<span class="vexpl">
190
					<?=gettext("Peer address where encapsulated gif packets will be sent. "); ?>
191
				</span>
192
			</td>
193
		</tr>
194
		<tr>
195
			<td valign="top" class="vncellreq"><?=gettext("gif tunnel local address"); ?></td>
196
			<td class="vtable">
197
				<input name="tunnel-local-addr" type="text" class="formfld unknown" id="tunnel-local-addr" size="24" value="<?=htmlspecialchars($pconfig['tunnel-local-addr']);?>" />
198
				<br />
199
				<span class="vexpl">
200
					<?=gettext("Local gif tunnel endpoint"); ?>
201
				</span>
202
			</td>
203
		</tr>
204
		<tr>
205
			<td valign="top" class="vncellreq"><?=gettext("gif tunnel remote address "); ?></td>
206
			<td class="vtable">
207
				<input name="tunnel-remote-addr" type="text" class="formfld unknown ipv4v6" id="tunnel-remote-addr" size="24" value="<?=htmlspecialchars($pconfig['tunnel-remote-addr']);?>" />
208
				<select name="tunnel-remote-net" class="formselect ipv4v6" id="tunnel-remote-net">
209
				<?php
210
					for ($i = 128; $i > 0; $i--) {
211 a20a972d Colin Fleming
						echo "<option value=\"{$i}\"";
212 2af86dda Phil Davis
						if ($i == $pconfig['tunnel-remote-net']) {
213 a20a972d Colin Fleming
							echo " selected=\"selected\"";
214 2af86dda Phil Davis
						}
215 2d107ad5 smos
						echo ">" . $i . "</option>";
216 2af86dda Phil Davis
					}
217
				?>
218
				</select>
219
				<br />
220
				<span class="vexpl">
221
					<?=gettext("Remote gif address endpoint. The subnet part is used for determining the network that is tunnelled."); ?>
222
				</span>
223
			</td>
224
		</tr>
225
		<tr>
226
			<td valign="top" class="vncell"><?=gettext("Route caching  "); ?></td>
227
			<td class="vtable">
228
				<input name="link0" type="checkbox" id="link0" <?if ($pconfig['link0']) echo "checked=\"checked\"";?> />
229
				<br />
230
				<span class="vexpl">
231
					<?=gettext("Specify if route caching can be enabled. Be careful with these settings on dynamic networks. "); ?>
232
				</span>
233
			</td>
234
		</tr>
235
		<tr>
236
			<td valign="top" class="vncell"><?=gettext("ECN friendly behavior"); ?></td>
237
			<td class="vtable">
238
				<input name="link1" type="checkbox" id="link1" <?if ($pconfig['link1']) echo "checked=\"checked\"";?> />
239
				<br />
240
				<span class="vexpl">
241
					<?=gettext("Note that the ECN friendly behavior violates RFC2893.  This should be " .
242
					"used in mutual agreement with the peer."); ?>
243
				</span>
244
			</td>
245
		</tr>
246
		<tr>
247
			<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
248
			<td width="78%" class="vtable">
249
				<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
250
				<br />
251
				<span class="vexpl">
252
					<?=gettext("You may enter a description here for your reference (not parsed)."); ?>
253
				</span>
254
			</td>
255
		</tr>
256
		<tr>
257
			<td width="22%" valign="top">&nbsp;</td>
258
			<td width="78%">
259
				<input type="hidden" name="gifif" value="<?=htmlspecialchars($pconfig['gifif']); ?>" />
260
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
261
				<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
262 5eabad3d Phil Davis
				<input name="referer" type="hidden" value="<?=$referer;?>" />
263 2af86dda Phil Davis
				<?php if (isset($id) && $a_gifs[$id]): ?>
264
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
265
				<?php endif; ?>
266
			</td>
267
		</tr>
268
	</table>
269 ead45104 Ermal Luçi
</form>
270
<?php include("fend.inc"); ?>
271
</body>
272
</html>