Project

General

Profile

Download (9.67 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_gif_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-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
require("guiconfig.inc");
43

    
44
if (isset($_POST['referer'])) {
45
	$referer = $_POST['referer'];
46
} else {
47
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_gif.php');
48
}
49

    
50
if (!is_array($config['gifs']['gif'])) {
51
	$config['gifs']['gif'] = array();
52
}
53

    
54
$a_gifs = &$config['gifs']['gif'];
55

    
56
if (is_numericint($_GET['id'])) {
57
	$id = $_GET['id'];
58
}
59
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
60
	$id = $_POST['id'];
61
}
62

    
63
if (isset($id) && $a_gifs[$id]) {
64
	$pconfig['if'] = $a_gifs[$id]['if'];
65
	if (!empty($a_gifs[$id]['ipaddr'])) {
66
		$pconfig['if'] = $pconfig['if'] . '|' . $a_gifs[$id]['ipaddr'];
67
	}
68
	$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
	$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

    
87
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
88

    
89
	if ((!is_ipaddr($_POST['tunnel-local-addr'])) ||
90
	    (!is_ipaddr($_POST['tunnel-remote-addr'])) ||
91
	    (!is_ipaddr($_POST['remote-addr']))) {
92
		$input_errors[] = gettext("The tunnel local and tunnel remote fields must have valid IP addresses.");
93
	}
94

    
95
	$alias = strstr($_POST['if'], '|');
96
	if ((is_ipaddrv4($alias) && !is_ipaddrv4($_POST['remote-addr'])) ||
97
	    (is_ipaddrv6($alias) && !is_ipaddrv6($_POST['remote-addr']))) {
98
		$input_errors[] = gettext("The alias IP address family has to match the family of the remote peer address.");
99
	}
100

    
101
	foreach ($a_gifs as $gif) {
102
		if (isset($id) && ($a_gifs[$id]) && ($a_gifs[$id] === $gif)) {
103
			continue;
104
		}
105

    
106
		/* FIXME: needs to perform proper subnet checks in the future */
107
		if (($gif['if'] == $interface) && ($gif['tunnel-remote-addr'] == $_POST['tunnel-remote-addr'])) {
108
			$input_errors[] = sprintf(gettext("A gif with the network %s is already defined."), $gif['tunnel-remote-addr']);
109
			break;
110
		}
111
	}
112

    
113
	if (!$input_errors) {
114
		$gif = array();
115
		list($gif['if'], $gif['ipaddr']) = explode("|", $_POST['if']);
116
		$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
		$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

    
135
			write_config();
136

    
137
			$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
138
			if ($confif <> "") {
139
				interface_configure($confif);
140
			}
141

    
142
			header("Location: interfaces_gif.php");
143
			exit;
144
		}
145
	}
146
}
147

    
148
$pgtitle = array(gettext("Interfaces"), gettext("GIF"), gettext("Edit"));
149
$shortcut_section = "interfaces";
150
include("head.inc");
151

    
152
?>
153

    
154
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
155
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
156
<?php include("fbegin.inc"); ?>
157
<?php if ($input_errors) print_input_errors($input_errors); ?>
158
<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
						}
174
						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
						echo "<option value=\"{$i}\"";
212
						if ($i == $pconfig['tunnel-remote-net']) {
213
							echo " selected=\"selected\"";
214
						}
215
						echo ">" . $i . "</option>";
216
					}
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
				<input name="referer" type="hidden" value="<?=$referer;?>" />
263
				<?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
</form>
270
<?php include("fend.inc"); ?>
271
</body>
272
</html>
(100-100/252)