Project

General

Profile

Download (10.9 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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_gif.php');
45

    
46
if (!is_array($config['gifs']['gif']))
47
	$config['gifs']['gif'] = array();
48

    
49
$a_gifs = &$config['gifs']['gif'];
50

    
51
if (is_numericint($_GET['id']))
52
	$id = $_GET['id'];
53
if (isset($_POST['id']) && is_numericint($_POST['id']))
54
	$id = $_POST['id'];
55

    
56
if (isset($id) && $a_gifs[$id]) {
57
	$pconfig['if'] = $a_gifs[$id]['if'];
58
	if (!empty($a_gifs[$id]['ipaddr'])) {
59
		$pconfig['if'] = $pconfig['if'] . '|' . $a_gifs[$id]['ipaddr'];
60
	}
61
	$pconfig['gifif'] = $a_gifs[$id]['gifif'];
62
	$pconfig['remote-addr'] = $a_gifs[$id]['remote-addr'];
63
	$pconfig['tunnel-remote-net'] = $a_gifs[$id]['tunnel-remote-net'];
64
	$pconfig['tunnel-local-addr'] = $a_gifs[$id]['tunnel-local-addr'];
65
	$pconfig['tunnel-remote-addr'] = $a_gifs[$id]['tunnel-remote-addr'];
66
	$pconfig['link1'] = isset($a_gifs[$id]['link1']);
67
	$pconfig['link0'] = isset($a_gifs[$id]['link0']);
68
	$pconfig['descr'] = $a_gifs[$id]['descr'];
69
}
70

    
71
if ($_POST) {
72

    
73
	unset($input_errors);
74
	$pconfig = $_POST;
75

    
76
	/* input validation */
77
	$reqdfields = explode(" ", "if tunnel-remote-addr tunnel-remote-net tunnel-local-addr");
78
	$reqdfieldsn = array(gettext("Parent interface,Local address, Remote tunnel address, Remote tunnel network, Local tunnel address"));
79

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

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

    
87
	$alias = strstr($_POST['if'],'|');
88
	if ((is_ipaddrv4($alias) && !is_ipaddrv4($_POST['remote-addr'])) ||
89
			(is_ipaddrv6($alias) && !is_ipaddrv6($_POST['remote-addr'])))
90
		$input_errors[] = gettext("The alias IP address family has to match the family of the remote peer address.");
91

    
92
	foreach ($a_gifs as $gif) {
93
		if (isset($id) && ($a_gifs[$id]) && ($a_gifs[$id] === $gif))
94
			continue;
95

    
96
		/* FIXME: needs to perform proper subnet checks in the feature */
97
		if (($gif['if'] == $interface) && ($gif['tunnel-remote-addr'] == $_POST['tunnel-remote-addr'])) {
98
			$input_errors[] = sprintf(gettext("A gif with the network %s is already defined."), $gif['tunnel-remote-addr']);
99
			break;
100
		}
101
	}
102

    
103
	if (!$input_errors) {
104
		$gif = array();
105
		list($gif['if'], $gif['ipaddr']) = explode("|",$_POST['if']);
106
		$gif['tunnel-local-addr'] = $_POST['tunnel-local-addr'];
107
		$gif['tunnel-remote-addr'] = $_POST['tunnel-remote-addr'];
108
		$gif['tunnel-remote-net'] = $_POST['tunnel-remote-net'];
109
		$gif['remote-addr'] = $_POST['remote-addr'];
110
		$gif['descr'] = $_POST['descr'];
111
		$gif['link1'] = isset($_POST['link1']);
112
		$gif['link0'] = isset($_POST['link0']);
113
		$gif['gifif'] = $_POST['gifif'];
114

    
115
                $gif['gifif'] = interface_gif_configure($gif);
116
                if ($gif['gifif'] == "" || !stristr($gif['gifif'], "gif"))
117
                        $input_errors[] = gettext("Error occurred creating interface, please retry.");
118
                else {
119
                        if (isset($id) && $a_gifs[$id])
120
                                $a_gifs[$id] = $gif;
121
                        else
122
                                $a_gifs[] = $gif;
123

    
124
                        write_config();
125

    
126
			$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
127
                        if ($confif <> "")
128
                                interface_configure($confif);
129

    
130
			header("Location: interfaces_gif.php");
131
			exit;
132
		}
133
	}
134
}
135

    
136
$pgtitle = array(gettext("Interfaces"),gettext("GIF"),gettext("Edit"));
137
$shortcut_section = "interfaces";
138
include("head.inc");
139

    
140
?>
141

    
142
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
143
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
144
<?php include("fbegin.inc"); ?>
145
<?php if ($input_errors) print_input_errors($input_errors); ?>
146
            <form action="interfaces_gif_edit.php" method="post" name="iform" id="iform">
147
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces gif edit">
148
				<tr>
149
					<td colspan="2" valign="top" class="listtopic"><?=gettext("GIF configuration"); ?></td>
150
				</tr>
151
				<tr>
152
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface"); ?></td>
153
                  <td width="78%" class="vtable">
154
                    <select name="if" class="formselect">
155
                      <?php
156
						$portlist = get_configured_interface_with_descr();
157
						$carplist = get_configured_carp_interface_list();
158
						foreach ($carplist as $cif => $carpip)
159
							$portlist[$cif] = $carpip." (".get_vip_descr($carpip).")";
160
						$aliaslist = get_configured_ip_aliases_list();
161
						foreach ($aliaslist as $aliasip => $aliasif)
162
							$portlist[$aliasif.'|'.$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
163
						foreach ($portlist as $ifn => $ifinfo) {
164
							echo "<option value=\"{$ifn}\"";
165
							if ($ifn == $pconfig['if'])
166
								echo " selected=\"selected\"";
167
							echo ">" . htmlspecialchars($ifinfo) . "</option>\n";
168
						}
169
		      		?>
170
                    </select>
171
			<br />
172
			<span class="vexpl"><?=gettext("The interface here serves as the local address to be used for the gif tunnel."); ?></span></td>
173
                </tr>
174
				<tr>
175
                  <td valign="top" class="vncellreq"><?=gettext("gif remote address"); ?></td>
176
                  <td class="vtable">
177
                    <input name="remote-addr" type="text" class="formfld unknown" id="remote-addr" size="24" value="<?=htmlspecialchars($pconfig['remote-addr']);?>" />
178
                    <br />
179
                    <span class="vexpl"><?=gettext("Peer address where encapsulated gif packets will be sent. "); ?></span></td>
180
			    </tr>
181
				<tr>
182
                  <td valign="top" class="vncellreq"><?=gettext("gif tunnel local address"); ?></td>
183
                  <td class="vtable">
184
                    <input name="tunnel-local-addr" type="text" class="formfld unknown" id="tunnel-local-addr" size="24" value="<?=htmlspecialchars($pconfig['tunnel-local-addr']);?>" />
185
                    <br />
186
                    <span class="vexpl"><?=gettext("Local gif tunnel endpoint"); ?></span></td>
187
			    </tr>
188
				<tr>
189
                  <td valign="top" class="vncellreq"><?=gettext("gif tunnel remote address "); ?></td>
190
                  <td class="vtable">
191
                    <input name="tunnel-remote-addr" type="text" class="formfld unknown ipv4v6" id="tunnel-remote-addr" size="24" value="<?=htmlspecialchars($pconfig['tunnel-remote-addr']);?>" />
192
                    <select name="tunnel-remote-net" class="formselect ipv4v6" id="tunnel-remote-net">
193
                                        <?php
194
                                        for ($i = 128; $i > 0; $i--) {
195
						echo "<option value=\"{$i}\"";
196
						if ($i == $pconfig['tunnel-remote-net'])
197
							echo " selected=\"selected\"";
198
						echo ">" . $i . "</option>";
199
                                        }
200
                                        ?>
201
                    </select>
202
                    <br />
203
                    <span class="vexpl"><?=gettext("Remote gif address endpoint. The subnet part is used for determining the network that is tunnelled."); ?></span></td>
204
			    </tr>
205
				<tr>
206
                  <td valign="top" class="vncell"><?=gettext("Route caching  "); ?></td>
207
                  <td class="vtable">
208
                    <input name="link0" type="checkbox" id="link0" <?if ($pconfig['link0']) echo "checked=\"checked\"";?> />
209
                    <br />
210
                    <span class="vexpl"><?=gettext("Specify if route caching can be enabled. Be careful with these settings on dynamic networks. "); ?></span></td>
211
			    </tr>
212
				<tr>
213
                  <td valign="top" class="vncell"><?=gettext("ECN friendly behavior"); ?></td>
214
                  <td class="vtable">
215
                    <input name="link1" type="checkbox" id="link1" <?if ($pconfig['link1']) echo "checked=\"checked\"";?> />
216
                    <br />
217
                    <span class="vexpl">
218
     <?=gettext("Note that the ECN friendly behavior violates RFC2893.  This should be " .
219
     "used in mutual agreement with the peer."); ?>					
220
					 </span></td>
221
			    </tr>
222
				<tr>
223
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
224
                  <td width="78%" class="vtable">
225
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
226
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here " .
227
                    "for your reference (not parsed)."); ?></span></td>
228
                </tr>
229
                <tr>
230
                  <td width="22%" valign="top">&nbsp;</td>
231
                  <td width="78%">
232
		    <input type="hidden" name="gifif" value="<?=htmlspecialchars($pconfig['gifif']); ?>" />
233
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
234
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
235
                    <?php if (isset($id) && $a_gifs[$id]): ?>
236
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
237
                    <?php endif; ?>
238
                  </td>
239
                </tr>
240
              </table>
241
</form>
242
<?php include("fend.inc"); ?>
243
</body>
244
</html>
(100-100/256)