Project

General

Profile

Download (11.1 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
$a_gifs = &$config['gifs']['gif'];
54

    
55
if (is_numericint($_GET['id']))
56
	$id = $_GET['id'];
57
if (isset($_POST['id']) && is_numericint($_POST['id']))
58
	$id = $_POST['id'];
59

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

    
75
if ($_POST) {
76

    
77
	unset($input_errors);
78
	$pconfig = $_POST;
79

    
80
	/* input validation */
81
	$reqdfields = explode(" ", "if remote-addr tunnel-local-addr tunnel-remote-addr tunnel-remote-net");
82
	$reqdfieldsn = array(gettext("Parent interface"), gettext("gif remote address"), gettext("gif tunnel local address"), gettext("gif tunnel remote address"), gettext("gif tunnel remote netmask"));
83

    
84
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
85

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

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

    
96
	foreach ($a_gifs as $gif) {
97
		if (isset($id) && ($a_gifs[$id]) && ($a_gifs[$id] === $gif))
98
			continue;
99

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

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

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

    
128
                        write_config();
129

    
130
			$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
131
                        if ($confif <> "")
132
                                interface_configure($confif);
133

    
134
			header("Location: interfaces_gif.php");
135
			exit;
136
		}
137
	}
138
}
139

    
140
$pgtitle = array(gettext("Interfaces"),gettext("GIF"),gettext("Edit"));
141
$shortcut_section = "interfaces";
142
include("head.inc");
143

    
144
?>
145

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