Project

General

Profile

Download (14.9 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	vpn_ipsec_mobile.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7
	
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10
	
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
	
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
	
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
	
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32

    
33
require("guiconfig.inc");
34

    
35
if (!is_array($config['ipsec']['mobileclients'])) {
36
	$config['ipsec']['mobileclients'] = array();
37
}
38
$a_ipsec = &$config['ipsec']['mobileclients'];
39

    
40
if (count($a_ipsec) == 0) {
41
	/* defaults */
42
	$pconfig['p1mode'] = "aggressive";
43
	$pconfig['p1myidentt'] = "myaddress";
44
	$pconfig['p1ealgo'] = "3des";
45
	$pconfig['p1halgo'] = "sha1";
46
	$pconfig['p1dhgroup'] = "2";
47
	$pconfig['p2proto'] = "esp";
48
	$pconfig['p2ealgos'] = explode(",", "3des,blowfish,cast128,rijndael");
49
	$pconfig['p2halgos'] = explode(",", "hmac_sha1,hmac_md5");
50
	$pconfig['p2pfsgroup'] = "0";
51
} else {
52
	$pconfig['enable'] = isset($a_ipsec['enable']);
53
	$pconfig['p1mode'] = $a_ipsec['p1']['mode'];
54
		
55
	if (isset($a_ipsec['p1']['myident']['myaddress']))
56
		$pconfig['p1myidentt'] = 'myaddress';
57
	else if (isset($a_ipsec['p1']['myident']['address'])) {
58
		$pconfig['p1myidentt'] = 'address';
59
		$pconfig['p1myident'] = $a_ipsec['p1']['myident']['address'];
60
	} else if (isset($a_ipsec['p1']['myident']['fqdn'])) {
61
		$pconfig['p1myidentt'] = 'fqdn';
62
		$pconfig['p1myident'] = $a_ipsec['p1']['myident']['fqdn'];
63
	} else if (isset($a_ipsec['p1']['myident']['ufqdn'])) {
64
		$pconfig['p1myidentt'] = 'user_fqdn';
65
		$pconfig['p1myident'] = $a_ipsec['p1']['myident']['ufqdn'];
66
 	}
67
	
68
	$pconfig['p1ealgo'] = $a_ipsec['p1']['encryption-algorithm'];
69
	$pconfig['p1halgo'] = $a_ipsec['p1']['hash-algorithm'];
70
	$pconfig['p1dhgroup'] = $a_ipsec['p1']['dhgroup'];
71
	$pconfig['p1lifetime'] = $a_ipsec['p1']['lifetime'];
72
	$pconfig['p2proto'] = $a_ipsec['p2']['protocol'];
73
	$pconfig['p2ealgos'] = $a_ipsec['p2']['encryption-algorithm-option'];
74
	$pconfig['p2halgos'] = $a_ipsec['p2']['hash-algorithm-option'];
75
	$pconfig['p2pfsgroup'] = $a_ipsec['p2']['pfsgroup'];
76
	$pconfig['p2lifetime'] = $a_ipsec['p2']['lifetime'];
77
}
78

    
79
if ($_POST) {
80
	unset($input_errors);
81
	$pconfig = $_POST;
82

    
83
	/* input validation */
84
	$reqdfields = explode(" ", "p2ealgos p2halgos");
85
	$reqdfieldsn = explode(",", "P2 Encryption Algorithms,P2 Hash Algorithms");
86
	
87
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
88
	
89
	if (($_POST['p1lifetime'] && !is_numeric($_POST['p1lifetime']))) {
90
		$input_errors[] = "The P1 lifetime must be an integer.";
91
	}
92
	if (($_POST['p2lifetime'] && !is_numeric($_POST['p2lifetime']))) {
93
		$input_errors[] = "The P2 lifetime must be an integer.";
94
	}
95
	if ((($_POST['p1myidentt'] == "address") && !is_ipaddr($_POST['p1myident']))) {
96
		$input_errors[] = "A valid IP address for 'My identifier' must be specified.";
97
	}
98
	if ((($_POST['p1myidentt'] == "fqdn") && !is_domain($_POST['p1myident']))) {
99
		$input_errors[] = "A valid domain name for 'My identifier' must be specified.";
100
	}
101
	if ($_POST['p1myidentt'] == "user_fqdn") {
102
		$ufqdn = explode("@",$_POST['p1myident']);
103
		if (!is_domain($ufqdn[1])) 
104
			$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.";
105
	}
106
	
107
	if ($_POST['p1myidentt'] == "myaddress")
108
		$_POST['p1myident'] = "";
109

    
110
	if (!$input_errors) {
111
		$ipsecent = array();
112
		$ipsecent['enable'] = $_POST['enable'] ? true : false;
113
		$ipsecent['p1']['mode'] = $_POST['p1mode'];
114
		
115
		$ipsecent['p1']['myident'] = array();
116
		switch ($_POST['p1myidentt']) {
117
			case 'myaddress':
118
				$ipsecent['p1']['myident']['myaddress'] = true;
119
				break;
120
			case 'address':
121
				$ipsecent['p1']['myident']['address'] = $_POST['p1myident'];
122
				break;
123
			case 'fqdn':
124
				$ipsecent['p1']['myident']['fqdn'] = $_POST['p1myident'];
125
				break;
126
			case 'user_fqdn':
127
				$ipsecent['p1']['myident']['ufqdn'] = $_POST['p1myident'];
128
				break;
129
		}
130
		
131
		$ipsecent['p1']['encryption-algorithm'] = $_POST['p1ealgo'];
132
		$ipsecent['p1']['hash-algorithm'] = $_POST['p1halgo'];
133
		$ipsecent['p1']['dhgroup'] = $_POST['p1dhgroup'];
134
		$ipsecent['p1']['lifetime'] = $_POST['p1lifetime'];
135
		$ipsecent['p2']['protocol'] = $_POST['p2proto'];
136
		$ipsecent['p2']['encryption-algorithm-option'] = $_POST['p2ealgos'];
137
		$ipsecent['p2']['hash-algorithm-option'] = $_POST['p2halgos'];
138
		$ipsecent['p2']['pfsgroup'] = $_POST['p2pfsgroup'];
139
		$ipsecent['p2']['lifetime'] = $_POST['p2lifetime'];
140
		
141
		$a_ipsec = $ipsecent;
142
		
143
		write_config();
144
		touch($d_ipsecconfdirty_path);
145
		
146
		header("Location: vpn_ipsec_mobile.php");
147
		exit;
148
	}
149
}
150
?>
151
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
152
<html>
153
<head>
154
<title><?=gentitle("VPN: IPsec");?></title>
155
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
156
<link href="gui.css" rel="stylesheet" type="text/css">
157
</head>
158

    
159
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
160
<?php include("fbegin.inc"); ?>
161
<p class="pgtitle">VPN: IPsec</p>
162
<form action="vpn_ipsec.php" method="post">
163
<?php if ($input_errors) print_input_errors($input_errors); ?>
164
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
165
<?php print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
166
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
167
<?php endif; ?>
168
</form>
169
<form action="vpn_ipsec_mobile.php" method="post" name="iform" id="iform">
170
<table width="100%" border="0" cellpadding="0" cellspacing="0">
171
  <tr><td>
172
  <ul id="tabnav">
173
    <li class="tabinact"><a href="vpn_ipsec.php">Tunnels</a></li>
174
    <li class="tabact">Mobile clients</li>
175
    <li class="tabinact"><a href="vpn_ipsec_keys.php">Pre-shared keys</a></li>
176
  </ul>
177
  </td></tr>
178
  <tr> 
179
    <td class="tabcont">
180
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
181
			  <tr> 
182
                        <td width="22%" valign="top">&nbsp;</td>
183
                        <td width="78%"> 
184
                    <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?>>
185
                    <strong>Allow mobile clients</strong></td>
186
                </tr>
187
                <tr> 
188
                  <td colspan="2" valign="top" class="listtopic">Phase 1 proposal 
189
                    (Authentication)</td>
190
                </tr>
191
                <tr> 
192
                  <td width="22%" valign="top" class="vncellreq">Negotiation mode</td>
193
                        <td width="78%" bgcolor="#FFFFFF" class="vtable">
194
<select name="p1mode" class="formfld">
195
                      <?php $modes = explode(" ", "main aggressive"); foreach ($modes as $mode): ?>
196
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1mode']) echo "selected"; ?>> 
197
                      <?=htmlspecialchars($mode);?>
198
                      </option>
199
                      <?php endforeach; ?>
200
                    </select> <br> <span class="vexpl">Aggressive is faster, but 
201
                    less secure.</span></td>
202
                </tr>
203
                <tr> 
204
                  <td width="22%" valign="top" class="vncellreq">My identifier</td>
205
                        <td width="78%" bgcolor="#FFFFFF" class="vtable">
206
<select name="p1myidentt" class="formfld">
207
                      <?php foreach ($my_identifier_list as $mode => $modename): ?>
208
                      <option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1myidentt']) echo "selected"; ?>> 
209
                      <?=htmlspecialchars($modename);?>
210
                      </option>
211
                      <?php endforeach; ?>
212
                    </select> <input name="p1myident" type="text" class="formfld" id="p1myident" size="30" value="<?=$pconfig['p1myident'];?>"> 
213
                  </td>
214
                </tr>
215
                <tr> 
216
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
217
                        <td width="78%" bgcolor="#FFFFFF" class="vtable">
218
<select name="p1ealgo" class="formfld">
219
                      <?php foreach ($p1_ealgos as $algo => $algoname): ?>
220
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1ealgo']) echo "selected"; ?>> 
221
                      <?=htmlspecialchars($algoname);?>
222
                      </option>
223
                      <?php endforeach; ?>
224
                    </select> <br> <span class="vexpl">Must match the setting 
225
                    chosen on the remote side. </span></td>
226
                </tr>
227
                <tr> 
228
                  <td width="22%" valign="top" class="vncellreq">Hash algorithm</td>
229
                        <td width="78%" bgcolor="#FFFFFF" class="vtable">
230
<select name="p1halgo" class="formfld">
231
                      <?php foreach ($p1_halgos as $algo => $algoname): ?>
232
                      <option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1halgo']) echo "selected"; ?>> 
233
                      <?=htmlspecialchars($algoname);?>
234
                      </option>
235
                      <?php endforeach; ?>
236
                    </select> <br> <span class="vexpl">Must match the setting 
237
                    chosen on the remote side. </span></td>
238
                </tr>
239
                <tr> 
240
                  <td width="22%" valign="top" class="vncellreq">DH key group</td>
241
                        <td width="78%" bgcolor="#FFFFFF" class="vtable">
242
<select name="p1dhgroup" class="formfld">
243
                      <?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
244
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p1dhgroup']) echo "selected"; ?>> 
245
                      <?=htmlspecialchars($keygroup);?>
246
                      </option>
247
                      <?php endforeach; ?>
248
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024 
249
                    bit, 5 = 1536 bit</em><br>
250
                    Must match the setting chosen on the remote side. </span></td>
251
                </tr>
252
                <tr> 
253
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
254
                        <td width="78%" bgcolor="#FFFFFF" class="vtable"> 
255
                    <input name="p1lifetime" type="text" class="formfld" id="p1lifetime" size="20" value="<?=$pconfig['p1lifetime'];?>">
256
                    seconds</td>
257
                </tr>
258
                <tr> 
259
                  <td colspan="2" class="list" height="12"></td>
260
                </tr>
261
                <tr> 
262
                  <td colspan="2" valign="top" class="listtopic">Phase 2 proposal 
263
                    (SA/Key Exchange)</td>
264
                </tr>
265
                <tr> 
266
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
267
                        <td width="78%" bgcolor="#FFFFFF" class="vtable">
268
<select name="p2proto" class="formfld">
269
                      <?php foreach ($p2_protos as $proto => $protoname): ?>
270
                      <option value="<?=$proto;?>" <?php if ($proto == $pconfig['p2proto']) echo "selected"; ?>> 
271
                      <?=htmlspecialchars($protoname);?>
272
                      </option>
273
                      <?php endforeach; ?>
274
                    </select> <br> <span class="vexpl">ESP is encryption, AH is 
275
                    authentication only </span></td>
276
                </tr>
277
                <tr> 
278
                  <td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
279
                        <td width="78%" bgcolor="#FFFFFF" class="vtable"> 
280
                          <?php foreach ($p2_ealgos as $algo => $algoname): ?>
281
                    <input type="checkbox" name="p2ealgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2ealgos'])) echo "checked"; ?>> 
282
                    <?=htmlspecialchars($algoname);?>
283
                    <br> 
284
                    <?php endforeach; ?>
285
                    <br>
286
                    Hint: use 3DES for best compatibility or if you have a hardware 
287
                    crypto accelerator card. Blowfish is usually the fastest in 
288
                    software encryption. </td>
289
                </tr>
290
                <tr> 
291
                  <td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
292
                        <td width="78%" bgcolor="#FFFFFF" class="vtable"> 
293
                          <?php foreach ($p2_halgos as $algo => $algoname): ?>
294
                    <input type="checkbox" name="p2halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2halgos'])) echo "checked"; ?>> 
295
                    <?=htmlspecialchars($algoname);?>
296
                    <br> 
297
                    <?php endforeach; ?>
298
                  </td>
299
                </tr>
300
                <tr> 
301
                  <td width="22%" valign="top" class="vncellreq">PFS key group</td>
302
                        <td width="78%" bgcolor="#FFFFFF" class="vtable">
303
<select name="p2pfsgroup" class="formfld">
304
                      <?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
305
                      <option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p2pfsgroup']) echo "selected"; ?>> 
306
                      <?=htmlspecialchars($keygroupname);?>
307
                      </option>
308
                      <?php endforeach; ?>
309
                    </select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024 
310
                    bit, 5 = 1536 bit</em></span></td>
311
                </tr>
312
                <tr> 
313
                  <td width="22%" valign="top" class="vncell">Lifetime</td>
314
                        <td width="78%" bgcolor="#FFFFFF" class="vtable"> 
315
                    <input name="p2lifetime" type="text" class="formfld" id="p2lifetime" size="20" value="<?=$pconfig['p2lifetime'];?>">
316
                    seconds</td>
317
                </tr>
318
                <tr> 
319
                  <td width="22%" valign="top">&nbsp;</td>
320
                  <td width="78%"> 
321
                    <input name="Submit" type="submit" class="formbtn" value="Save">
322
                  </td>
323
                </tr>
324
              </table>
325
			 </td>
326
			</tr>
327
		</table>
328
</form>
329
<?php include("fend.inc"); ?>
330
</body>
331
</html>
(100-100/109)