Projet

Général

Profil

Télécharger (10,7 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / interfaces_gif_edit.php @ c3e77841

1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_gif_edit.php
5

    
6
	Copyright (C) 2008 Ermal Luçi
7
	All rights reserved.
8

    
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11

    
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14

    
15
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18

    
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/*
31
	pfSense_MODULE:	interfaces
32
*/
33

    
34
##|+PRIV
35
##|*IDENT=page-interfaces-gif-edit
36
##|*NAME=Interfaces: GIF: Edit page
37
##|*DESCR=Allow access to the 'Interfaces: GIF: Edit' page.
38
##|*MATCH=interfaces_gif_edit.php*
39
##|-PRIV
40

    
41
require("guiconfig.inc");
42

    
43
if (!is_array($config['gifs']['gif']))
44
	$config['gifs']['gif'] = array();
45

    
46
$a_gifs = &$config['gifs']['gif'];
47

    
48
if (is_numericint($_GET['id']))
49
	$id = $_GET['id'];
50
if (isset($_POST['id']) && is_numericint($_POST['id']))
51
	$id = $_POST['id'];
52

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

    
68
if ($_POST) {
69

    
70
	unset($input_errors);
71
	$pconfig = $_POST;
72

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

    
77
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
78

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

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

    
89
	foreach ($a_gifs as $gif) {
90
		if (isset($id) && ($a_gifs[$id]) && ($a_gifs[$id] === $gif))
91
			continue;
92

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

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

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

    
121
                        write_config();
122

    
123
			$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
124
                        if ($confif <> "")
125
                                interface_configure($confif);
126

    
127
			header("Location: interfaces_gif.php");
128
			exit;
129
		}
130
	}
131
}
132

    
133
$pgtitle = array(gettext("Interfaces"),gettext("GIF"),gettext("Edit"));
134
$shortcut_section = "interfaces";
135
include("head.inc");
136

    
137
?>
138

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