1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
vpn_ipsec_mobile.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
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
|
require("guiconfig.inc");
|
33
|
|
34
|
if (!is_array($config['ipsec']['mobileclients'])) {
|
35
|
$config['ipsec']['mobileclients'] = array();
|
36
|
}
|
37
|
$a_ipsec = &$config['ipsec']['mobileclients'];
|
38
|
|
39
|
if (count($a_ipsec) == 0) {
|
40
|
/* defaults */
|
41
|
$pconfig['p1mode'] = "aggressive";
|
42
|
$pconfig['p1myidentt'] = "myaddress";
|
43
|
$pconfig['p1ealgo'] = "3des";
|
44
|
$pconfig['p1halgo'] = "sha1";
|
45
|
$pconfig['p1dhgroup'] = "2";
|
46
|
$pconfig['p2proto'] = "esp";
|
47
|
$pconfig['p2ealgos'] = explode(",", "3des,blowfish,cast128,rijndael");
|
48
|
$pconfig['p2halgos'] = explode(",", "hmac_sha1,hmac_md5");
|
49
|
$pconfig['p2pfsgroup'] = "0";
|
50
|
} else {
|
51
|
$pconfig['enable'] = isset($a_ipsec['enable']);
|
52
|
$pconfig['p1mode'] = $a_ipsec['p1']['mode'];
|
53
|
|
54
|
if (isset($a_ipsec['p1']['myident']['myaddress']))
|
55
|
$pconfig['p1myidentt'] = 'myaddress';
|
56
|
else if (isset($a_ipsec['p1']['myident']['address'])) {
|
57
|
$pconfig['p1myidentt'] = 'address';
|
58
|
$pconfig['p1myident'] = $a_ipsec['p1']['myident']['address'];
|
59
|
} else if (isset($a_ipsec['p1']['myident']['fqdn'])) {
|
60
|
$pconfig['p1myidentt'] = 'fqdn';
|
61
|
$pconfig['p1myident'] = $a_ipsec['p1']['myident']['fqdn'];
|
62
|
} else if (isset($a_ipsec['p1']['myident']['ufqdn'])) {
|
63
|
$pconfig['p1myidentt'] = 'user_fqdn';
|
64
|
$pconfig['p1myident'] = $a_ipsec['p1']['myident']['ufqdn'];
|
65
|
}
|
66
|
|
67
|
$pconfig['p1ealgo'] = $a_ipsec['p1']['encryption-algorithm'];
|
68
|
$pconfig['p1halgo'] = $a_ipsec['p1']['hash-algorithm'];
|
69
|
$pconfig['p1dhgroup'] = $a_ipsec['p1']['dhgroup'];
|
70
|
$pconfig['p1lifetime'] = $a_ipsec['p1']['lifetime'];
|
71
|
$pconfig['p2proto'] = $a_ipsec['p2']['protocol'];
|
72
|
$pconfig['p2ealgos'] = $a_ipsec['p2']['encryption-algorithm-option'];
|
73
|
$pconfig['p2halgos'] = $a_ipsec['p2']['hash-algorithm-option'];
|
74
|
$pconfig['p2pfsgroup'] = $a_ipsec['p2']['pfsgroup'];
|
75
|
$pconfig['p2lifetime'] = $a_ipsec['p2']['lifetime'];
|
76
|
}
|
77
|
|
78
|
if ($_POST) {
|
79
|
unset($input_errors);
|
80
|
$pconfig = $_POST;
|
81
|
|
82
|
/* input validation */
|
83
|
$reqdfields = explode(" ", "p2ealgos p2halgos");
|
84
|
$reqdfieldsn = explode(",", "P2 Encryption Algorithms,P2 Hash Algorithms");
|
85
|
|
86
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
87
|
|
88
|
if (($_POST['p1lifetime'] && !is_numeric($_POST['p1lifetime']))) {
|
89
|
$input_errors[] = "The P1 lifetime must be an integer.";
|
90
|
}
|
91
|
if (($_POST['p2lifetime'] && !is_numeric($_POST['p2lifetime']))) {
|
92
|
$input_errors[] = "The P2 lifetime must be an integer.";
|
93
|
}
|
94
|
if ((($_POST['p1myidentt'] == "address") && !is_ipaddr($_POST['p1myident']))) {
|
95
|
$input_errors[] = "A valid IP address for 'My identifier' must be specified.";
|
96
|
}
|
97
|
if ((($_POST['p1myidentt'] == "fqdn") && !is_domain($_POST['p1myident']))) {
|
98
|
$input_errors[] = "A valid domain name for 'My identifier' must be specified.";
|
99
|
}
|
100
|
if ($_POST['p1myidentt'] == "user_fqdn") {
|
101
|
$ufqdn = explode("@",$_POST['p1myident']);
|
102
|
if (!is_domain($ufqdn[1]))
|
103
|
$input_errors[] = "A valid User FQDN in the form of user@my.domain.com for 'My identifier' must be specified.";
|
104
|
}
|
105
|
|
106
|
if ($_POST['p1myidentt'] == "myaddress")
|
107
|
$_POST['p1myident'] = "";
|
108
|
|
109
|
if (!$input_errors) {
|
110
|
$ipsecent = array();
|
111
|
$ipsecent['enable'] = $_POST['enable'] ? true : false;
|
112
|
$ipsecent['p1']['mode'] = $_POST['p1mode'];
|
113
|
|
114
|
$ipsecent['p1']['myident'] = array();
|
115
|
switch ($_POST['p1myidentt']) {
|
116
|
case 'myaddress':
|
117
|
$ipsecent['p1']['myident']['myaddress'] = true;
|
118
|
break;
|
119
|
case 'address':
|
120
|
$ipsecent['p1']['myident']['address'] = $_POST['p1myident'];
|
121
|
break;
|
122
|
case 'fqdn':
|
123
|
$ipsecent['p1']['myident']['fqdn'] = $_POST['p1myident'];
|
124
|
break;
|
125
|
case 'user_fqdn':
|
126
|
$ipsecent['p1']['myident']['ufqdn'] = $_POST['p1myident'];
|
127
|
break;
|
128
|
}
|
129
|
|
130
|
$ipsecent['p1']['encryption-algorithm'] = $_POST['p1ealgo'];
|
131
|
$ipsecent['p1']['hash-algorithm'] = $_POST['p1halgo'];
|
132
|
$ipsecent['p1']['dhgroup'] = $_POST['p1dhgroup'];
|
133
|
$ipsecent['p1']['lifetime'] = $_POST['p1lifetime'];
|
134
|
$ipsecent['p2']['protocol'] = $_POST['p2proto'];
|
135
|
$ipsecent['p2']['encryption-algorithm-option'] = $_POST['p2ealgos'];
|
136
|
$ipsecent['p2']['hash-algorithm-option'] = $_POST['p2halgos'];
|
137
|
$ipsecent['p2']['pfsgroup'] = $_POST['p2pfsgroup'];
|
138
|
$ipsecent['p2']['lifetime'] = $_POST['p2lifetime'];
|
139
|
|
140
|
$a_ipsec = $ipsecent;
|
141
|
|
142
|
write_config();
|
143
|
touch($d_ipsecconfdirty_path);
|
144
|
|
145
|
header("Location: vpn_ipsec_mobile.php");
|
146
|
exit;
|
147
|
}
|
148
|
}
|
149
|
?>
|
150
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
151
|
<html>
|
152
|
<head>
|
153
|
<title><?=gentitle("VPN: IPsec");?></title>
|
154
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
155
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
156
|
</head>
|
157
|
|
158
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
159
|
<?php include("fbegin.inc"); ?>
|
160
|
<p class="pgtitle">VPN: IPsec</p>
|
161
|
<form action="vpn_ipsec.php" method="post">
|
162
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
163
|
<?php if (file_exists($d_ipsecconfdirty_path)): ?><p>
|
164
|
<?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>
|
165
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
166
|
<?php endif; ?>
|
167
|
</form>
|
168
|
<form action="vpn_ipsec_mobile.php" method="post" name="iform" id="iform">
|
169
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
170
|
<tr><td>
|
171
|
<ul id="tabnav">
|
172
|
<li class="tabinact"><a href="vpn_ipsec.php">Tunnels</a></li>
|
173
|
<li class="tabact">Mobile clients</li>
|
174
|
<li class="tabinact"><a href="vpn_ipsec_keys.php">Pre-shared keys</a></li>
|
175
|
</ul>
|
176
|
</td></tr>
|
177
|
<tr>
|
178
|
<td class="tabcont">
|
179
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
180
|
<tr>
|
181
|
<td width="22%" valign="top"> </td>
|
182
|
<td width="78%">
|
183
|
<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?>>
|
184
|
<strong>Allow mobile clients</strong></td>
|
185
|
</tr>
|
186
|
<tr>
|
187
|
<td colspan="2" valign="top" class="listtopic">Phase 1 proposal
|
188
|
(Authentication)</td>
|
189
|
</tr>
|
190
|
<tr>
|
191
|
<td width="22%" valign="top" class="vncellreq">Negotiation mode</td>
|
192
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
193
|
<select name="p1mode" class="formfld">
|
194
|
<?php $modes = explode(" ", "main aggressive"); foreach ($modes as $mode): ?>
|
195
|
<option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1mode']) echo "selected"; ?>>
|
196
|
<?=htmlspecialchars($mode);?>
|
197
|
</option>
|
198
|
<?php endforeach; ?>
|
199
|
</select> <br> <span class="vexpl">Aggressive is faster, but
|
200
|
less secure.</span></td>
|
201
|
</tr>
|
202
|
<tr>
|
203
|
<td width="22%" valign="top" class="vncellreq">My identifier</td>
|
204
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
205
|
<select name="p1myidentt" class="formfld">
|
206
|
<?php foreach ($my_identifier_list as $mode => $modename): ?>
|
207
|
<option value="<?=$mode;?>" <?php if ($mode == $pconfig['p1myidentt']) echo "selected"; ?>>
|
208
|
<?=htmlspecialchars($modename);?>
|
209
|
</option>
|
210
|
<?php endforeach; ?>
|
211
|
</select> <input name="p1myident" type="text" class="formfld" id="p1myident" size="30" value="<?=$pconfig['p1myident'];?>">
|
212
|
</td>
|
213
|
</tr>
|
214
|
<tr>
|
215
|
<td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
|
216
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
217
|
<select name="p1ealgo" class="formfld">
|
218
|
<?php foreach ($p1_ealgos as $algo => $algoname): ?>
|
219
|
<option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1ealgo']) echo "selected"; ?>>
|
220
|
<?=htmlspecialchars($algoname);?>
|
221
|
</option>
|
222
|
<?php endforeach; ?>
|
223
|
</select> <br> <span class="vexpl">Must match the setting
|
224
|
chosen on the remote side. </span></td>
|
225
|
</tr>
|
226
|
<tr>
|
227
|
<td width="22%" valign="top" class="vncellreq">Hash algorithm</td>
|
228
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
229
|
<select name="p1halgo" class="formfld">
|
230
|
<?php foreach ($p1_halgos as $algo => $algoname): ?>
|
231
|
<option value="<?=$algo;?>" <?php if ($algo == $pconfig['p1halgo']) echo "selected"; ?>>
|
232
|
<?=htmlspecialchars($algoname);?>
|
233
|
</option>
|
234
|
<?php endforeach; ?>
|
235
|
</select> <br> <span class="vexpl">Must match the setting
|
236
|
chosen on the remote side. </span></td>
|
237
|
</tr>
|
238
|
<tr>
|
239
|
<td width="22%" valign="top" class="vncellreq">DH key group</td>
|
240
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
241
|
<select name="p1dhgroup" class="formfld">
|
242
|
<?php $keygroups = explode(" ", "1 2 5"); foreach ($keygroups as $keygroup): ?>
|
243
|
<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p1dhgroup']) echo "selected"; ?>>
|
244
|
<?=htmlspecialchars($keygroup);?>
|
245
|
</option>
|
246
|
<?php endforeach; ?>
|
247
|
</select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024
|
248
|
bit, 5 = 1536 bit</em><br>
|
249
|
Must match the setting chosen on the remote side. </span></td>
|
250
|
</tr>
|
251
|
<tr>
|
252
|
<td width="22%" valign="top" class="vncell">Lifetime</td>
|
253
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
254
|
<input name="p1lifetime" type="text" class="formfld" id="p1lifetime" size="20" value="<?=$pconfig['p1lifetime'];?>">
|
255
|
seconds</td>
|
256
|
</tr>
|
257
|
<tr>
|
258
|
<td colspan="2" class="list" height="12"></td>
|
259
|
</tr>
|
260
|
<tr>
|
261
|
<td colspan="2" valign="top" class="listtopic">Phase 2 proposal
|
262
|
(SA/Key Exchange)</td>
|
263
|
</tr>
|
264
|
<tr>
|
265
|
<td width="22%" valign="top" class="vncellreq">Protocol</td>
|
266
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
267
|
<select name="p2proto" class="formfld">
|
268
|
<?php foreach ($p2_protos as $proto => $protoname): ?>
|
269
|
<option value="<?=$proto;?>" <?php if ($proto == $pconfig['p2proto']) echo "selected"; ?>>
|
270
|
<?=htmlspecialchars($protoname);?>
|
271
|
</option>
|
272
|
<?php endforeach; ?>
|
273
|
</select> <br> <span class="vexpl">ESP is encryption, AH is
|
274
|
authentication only </span></td>
|
275
|
</tr>
|
276
|
<tr>
|
277
|
<td width="22%" valign="top" class="vncellreq">Encryption algorithms</td>
|
278
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
279
|
<?php foreach ($p2_ealgos as $algo => $algoname): ?>
|
280
|
<input type="checkbox" name="p2ealgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2ealgos'])) echo "checked"; ?>>
|
281
|
<?=htmlspecialchars($algoname);?>
|
282
|
<br>
|
283
|
<?php endforeach; ?>
|
284
|
<br>
|
285
|
Hint: use 3DES for best compatibility or if you have a hardware
|
286
|
crypto accelerator card. Blowfish is usually the fastest in
|
287
|
software encryption. </td>
|
288
|
</tr>
|
289
|
<tr>
|
290
|
<td width="22%" valign="top" class="vncellreq">Hash algorithms</td>
|
291
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
292
|
<?php foreach ($p2_halgos as $algo => $algoname): ?>
|
293
|
<input type="checkbox" name="p2halgos[]" value="<?=$algo;?>" <?php if (in_array($algo, $pconfig['p2halgos'])) echo "checked"; ?>>
|
294
|
<?=htmlspecialchars($algoname);?>
|
295
|
<br>
|
296
|
<?php endforeach; ?>
|
297
|
</td>
|
298
|
</tr>
|
299
|
<tr>
|
300
|
<td width="22%" valign="top" class="vncellreq">PFS key group</td>
|
301
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
302
|
<select name="p2pfsgroup" class="formfld">
|
303
|
<?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
|
304
|
<option value="<?=$keygroup;?>" <?php if ($keygroup == $pconfig['p2pfsgroup']) echo "selected"; ?>>
|
305
|
<?=htmlspecialchars($keygroupname);?>
|
306
|
</option>
|
307
|
<?php endforeach; ?>
|
308
|
</select> <br> <span class="vexpl"><em>1 = 768 bit, 2 = 1024
|
309
|
bit, 5 = 1536 bit</em></span></td>
|
310
|
</tr>
|
311
|
<tr>
|
312
|
<td width="22%" valign="top" class="vncell">Lifetime</td>
|
313
|
<td width="78%" bgcolor="#FFFFFF" class="vtable">
|
314
|
<input name="p2lifetime" type="text" class="formfld" id="p2lifetime" size="20" value="<?=$pconfig['p2lifetime'];?>">
|
315
|
seconds</td>
|
316
|
</tr>
|
317
|
<tr>
|
318
|
<td width="22%" valign="top"> </td>
|
319
|
<td width="78%">
|
320
|
<input name="Submit" type="submit" class="formbtn" value="Save">
|
321
|
</td>
|
322
|
</tr>
|
323
|
</table>
|
324
|
</td>
|
325
|
</tr>
|
326
|
</table>
|
327
|
</form>
|
328
|
<?php include("fend.inc"); ?>
|
329
|
</body>
|
330
|
</html>
|