Project

General

Profile

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

    
30
##|+PRIV
31
##|*IDENT=page-vpn-ipsec-mobile
32
##|*NAME=VPN: IPsec: Mobile page
33
##|*DESCR=Allow access to the 'VPN: IPsec: Mobile' page.
34
##|*MATCH=vpn_ipsec_mobile.php*
35
##|-PRIV
36

    
37

    
38
require("guiconfig.inc");
39

    
40
if (!is_array($config['ipsec']['phase1']))
41
	$config['ipsec']['phase1'] = array();
42

    
43
$a_phase1 = &$config['ipsec']['phase1'];
44

    
45
if (!is_array($config['ipsec']['client']))
46
	$config['ipsec']['client'] = array();
47

    
48
$a_client = &$config['ipsec']['client'];
49

    
50
if (count($a_client)) {
51

    
52
	$pconfig['enable'] = $a_client['enable'];
53

    
54
	$pconfig['user_source'] = $a_client['user_source'];
55
	$pconfig['group_source'] = $a_client['group_source'];
56

    
57
	$pconfig['pool_address'] = $a_client['pool_address'];
58
	$pconfig['pool_netbits'] = $a_client['pool_netbits'];
59
	$pconfig['net_list'] = $a_client['net_list'];
60
	$pconfig['dns_domain'] = $a_client['dns_domain'];
61
	$pconfig['dns_server1'] = $a_client['dns_server1'];
62
	$pconfig['dns_server2'] = $a_client['dns_server2'];
63
	$pconfig['dns_server3'] = $a_client['dns_server3'];
64
	$pconfig['dns_server4'] = $a_client['dns_server4'];
65
	$pconfig['wins_server1'] = $a_client['wins_server1'];
66
	$pconfig['wins_server2'] = $a_client['wins_server2'];
67
	$pconfig['pfs_group'] = $a_client['pfs_group'];
68
	$pconfig['login_banner'] = $a_client['login_banner'];
69

    
70
	if (isset($pconfig['enable']))
71
		$pconfig['enable'] = true;
72

    
73
	if ($pconfig['pool_address']&&$pconfig['pool_netbits'])
74
		$pconfig['pool_enable'] = true;
75
	else
76
		$pconfig['pool_netbits'] = 24;
77

    
78
	if (isset($pconfig['net_list']))
79
		$pconfig['net_list_enable'] = true;
80

    
81
	if ($pconfig['dns_domain'])
82
		$pconfig['dns_domain_enable'] = true;
83

    
84
	if ($pconfig['dns_server1']||$pconfig['dns_server2']||$pconfig['dns_server3']||$pconfig['dns_server4'])
85
		$pconfig['dns_server_enable'] = true;
86

    
87
	if ($pconfig['wins_server1']||$pconfig['wins_server2'])
88
		$pconfig['wins_server_enable'] = true;
89

    
90
	if (isset($pconfig['pfs_group']))
91
		$pconfig['pfs_group_enable'] = true;
92

    
93
	if ($pconfig['login_banner'])
94
		$pconfig['login_banner_enable'] = true;
95
}
96

    
97
if ($_POST['create']) {
98
	header("Location: vpn_ipsec_phase1.php?mobile=true");
99
}
100

    
101
if ($_POST['apply']) {
102
	$retval = 0;
103
	$retval = vpn_ipsec_configure();
104
	$savemsg = get_std_save_message($retval);
105
	if ($retval == 0)
106
		if (file_exists($d_ipsecconfdirty_path))
107
			unlink($d_ipsecconfdirty_path);
108
}
109

    
110
if ($_POST['submit']) {
111

    
112
	unset($input_errors);
113
	$pconfig = $_POST;
114

    
115
	/* input consolidation */
116

    
117
	
118

    
119
	/* input validation */
120

    
121
	$reqdfields = explode(" ", "user_source group_source");
122
	$reqdfieldsn =  explode(",", "User Authentication Source,Group Authentication Source");
123

    
124
    do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
125

    
126
	if ($pconfig['pool_enable'])
127
		if (!is_ipaddr($pconfig['pool_address']))
128
			$input_errors[] = "A valid IP address for 'Virtual Address Pool Network' must be specified.";
129

    
130
	if ($pconfig['dns_domain_enable'])
131
		if (!is_domain($pconfig['dns_domain']))
132
			$input_errors[] = "A valid value for 'DNS Default Domain' must be specified.";
133

    
134
	if ($pconfig['dns_server_enable']) {
135
		if (!$pconfig['dns_server1'] && !$pconfig['dns_server2'] &&
136
			!$pconfig['dns_server3'] && !$pconfig['dns_server4'] )
137
			$input_errors[] = "At least one DNS server must be specified to enable the DNS Server option.";
138
		if ($pconfig['dns_server1'] && !is_ipaddr($pconfig['dns_server1']))
139
			$input_errors[] = "A valid IP address for 'DNS Server #1' must be specified.";
140
		if ($pconfig['dns_server2'] && !is_ipaddr($pconfig['dns_server2']))
141
			$input_errors[] = "A valid IP address for 'DNS Server #2' must be specified.";
142
		if ($pconfig['dns_server3'] && !is_ipaddr($pconfig['dns_server3']))
143
			$input_errors[] = "A valid IP address for 'DNS Server #3' must be specified.";
144
		if ($pconfig['dns_server4'] && !is_ipaddr($pconfig['dns_server4']))
145
			$input_errors[] = "A valid IP address for 'DNS Server #4' must be specified.";
146
	}
147

    
148
	if ($pconfig['wins_server_enable']) {
149
		if (!$pconfig['wins_server1'] && !$pconfig['wins_server2'])
150
			$input_errors[] = "At least one WINS server must be specified to enable the DNS Server option.";
151
		if ($pconfig['wins_server1'] && !is_ipaddr($pconfig['wins_server1']))
152
			$input_errors[] = "A valid IP address for 'WINS Server #1' must be specified.";
153
		if ($pconfig['wins_server2'] && !is_ipaddr($pconfig['wins_server2']))
154
			$input_errors[] = "A valid IP address for 'WINS Server #2' must be specified.";
155
	}
156

    
157
	if ($pconfig['login_banner_enable'])
158
		if (!strlen($pconfig['login_banner']))
159
			$input_errors[] = "A valid value for 'Login Banner' must be specified.";
160

    
161
	if (!$input_errors) {
162
		$client = array();
163
		
164
		if ($pconfig['enable'])
165
			$client['enable'] = true;
166

    
167
		$client['user_source'] = $pconfig['user_source'];
168
		$client['group_source'] = $pconfig['group_source'];
169

    
170
		if ($pconfig['pool_enable']) {
171
			$client['pool_address'] = $pconfig['pool_address'];
172
			$client['pool_netbits'] = $pconfig['pool_netbits'];
173
		}
174

    
175
		if ($pconfig['net_list_enable'])
176
			$client['net_list'] = true;
177

    
178
		if ($pconfig['dns_domain_enable'])
179
			$client['dns_domain'] = $pconfig['dns_domain'];
180

    
181
		if ($pconfig['dns_server_enable']) {
182
			$client['dns_server1'] = $pconfig['dns_server1'];
183
			$client['dns_server2'] = $pconfig['dns_server2'];
184
			$client['dns_server3'] = $pconfig['dns_server3'];
185
			$client['dns_server4'] = $pconfig['dns_server4'];
186
		}
187

    
188
		if ($pconfig['wins_server_enable']) {
189
			$client['wins_server1'] = $pconfig['wins_server1'];
190
			$client['wins_server2'] = $pconfig['wins_server2'];
191
		}
192

    
193
		if ($pconfig['pfs_group_enable'])
194
			$client['pfs_group'] = $pconfig['pfs_group'];
195

    
196
		if ($pconfig['login_banner_enable'])
197
			$client['login_banner'] = $pconfig['login_banner'];
198

    
199
//		$echo "login banner = {$pconfig['login_banner']}";
200

    
201
		$a_client = $client;
202
		
203
		write_config();
204
		touch($d_ipsecconfdirty_path);
205
		
206
		header("Location: vpn_ipsec_mobile.php");
207
		exit;
208
	}
209
}
210

    
211
$pgtitle = array("VPN","IPsec","Mobile");
212
include("head.inc");
213
?>
214

    
215
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
216
<?php include("fbegin.inc"); ?>
217

    
218
<script language="JavaScript">
219
<!--
220

    
221
function pool_change() {
222

    
223
	if (document.iform.pool_enable.checked) {
224
		document.iform.pool_address.disabled = 0;
225
		document.iform.pool_netbits.disabled = 0;
226
	} else {
227
		document.iform.pool_address.disabled = 1;
228
		document.iform.pool_netbits.disabled = 1;
229
	}
230
}
231

    
232
function dns_domain_change() {
233

    
234
	if (document.iform.dns_domain_enable.checked)
235
		document.iform.dns_domain.disabled = 0;
236
	else
237
		document.iform.dns_domain.disabled = 1;
238
}
239

    
240
function dns_server_change() {
241

    
242
	if (document.iform.dns_server_enable.checked) {
243
		document.iform.dns_server1.disabled = 0;
244
		document.iform.dns_server2.disabled = 0;
245
		document.iform.dns_server3.disabled = 0;
246
		document.iform.dns_server4.disabled = 0;
247
	} else {
248
		document.iform.dns_server1.disabled = 1;
249
		document.iform.dns_server2.disabled = 1;
250
		document.iform.dns_server3.disabled = 1;
251
		document.iform.dns_server4.disabled = 1;
252
	}
253
}
254

    
255
function wins_server_change() {
256

    
257
	if (document.iform.wins_server_enable.checked) {
258
		document.iform.wins_server1.disabled = 0;
259
		document.iform.wins_server2.disabled = 0;
260
	} else {
261
		document.iform.wins_server1.disabled = 1;
262
		document.iform.wins_server2.disabled = 1;
263
	}
264
}
265

    
266
function pfs_group_change() {
267

    
268
	if (document.iform.pfs_group_enable.checked)
269
		document.iform.pfs_group.disabled = 0;
270
	else
271
		document.iform.pfs_group.disabled = 1;
272
}
273

    
274
function login_banner_change() {
275

    
276
	if (document.iform.login_banner_enable.checked)
277
		document.iform.login_banner.disabled = 0;
278
	else
279
		document.iform.login_banner.disabled = 1;
280
}
281

    
282
//-->
283
</script>
284

    
285
<form action="vpn_ipsec_mobile.php" method="post" name="iform" id="iform">
286

    
287
<?php
288
	if ($savemsg)
289
		print_info_box($savemsg);
290
	if (isset($config['ipsec']['enable']) && file_exists($d_ipsecconfdirty_path))
291
		print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes in order for them to take effect.");
292
	foreach ($a_phase1 as $ph1ent)
293
		if (isset($ph1ent['mobile']))
294
			$ph1found = true;
295
	if ($pconfig['enable'] && !$ph1found)
296
		print_info_box_np("Support for IPsec Mobile clients is enabled but a Phase1 definition was not found.<br>Please click Create to define one.","create","Create Phase1");
297
	if ($input_errors)
298
		print_input_errors($input_errors);
299
?>
300

    
301
<table width="100%" border="0" cellpadding="0" cellspacing="0">
302
	<tr>
303
		<td class="tabnavtbl">
304
			<?php
305
				$tab_array = array();
306
				$tab_array[0] = array("Tunnels", false, "vpn_ipsec.php");
307
				$tab_array[1] = array("Mobile clients", true, "vpn_ipsec_mobile.php");
308
				display_top_tabs($tab_array);
309
			?>
310
		</td>
311
	</tr>
312
	<tr> 
313
		<td id="mainarea">
314
			<div class="tabcont">
315
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
316
					<tr>
317
						<td width="22%" valign="top" class="vncellreq">IKE Extensions</td>
318
						<td width="78%" class="vtable">
319
							<table border="0" cellspacing="2" cellpadding="0">
320
								<tr>
321
									<td>
322
										<?php set_checked($pconfig['enable'],$chk); ?>
323
										<input name="enable" type="checkbox" id="enable" value="yes" <?=$chk;?>>
324
									</td>
325
									<td>
326
										<strong>Enable IPsec Mobile Client Support</strong>
327
									</td>
328
								</tr>
329
							</table>
330
						</td>
331
					</tr>
332
					<tr>
333
						<td colspan="2" class="list" height="12"></td>
334
					</tr>
335
					<tr>
336
						<td colspan="2" valign="top" class="listtopic">
337
							Extended Authentication (Xauth)
338
						</td>
339
					</tr>
340
					<tr>
341
						<td width="22%" valign="top" class="vncellreq">User Authentication</td>
342
						<td width="78%" class="vtable">
343
							Source:&nbsp;&nbsp;
344
							<select name="user_source" class="formselect" id="user_source">
345
								<option value="system">system</option>
346
							</select>
347
						</td>
348
					</tr>
349
					<tr>
350
						<td width="22%" valign="top" class="vncellreq">Group Authentication</td>
351
						<td width="78%" class="vtable">
352
							Source:&nbsp;&nbsp;
353
							<select name="group_source" class="formselect" id="group_source">
354
								<option value="system">system</option>
355
							</select>
356
						</td>
357
					</tr>
358
					<tr>
359
						<td colspan="2" class="list" height="12"></td>
360
					</tr>
361
					<tr> 
362
						<td colspan="2" valign="top" class="listtopic">
363
							Client Configuration (mode-cfg)
364
						</td>
365
					</tr>
366
					<tr> 
367
						<td width="22%" valign="top" class="vncell">Virtual Address Pool</td>
368
						<td width="78%" class="vtable">
369
							<table border="0" cellspacing="2" cellpadding="0">
370
								<tr>
371
									<td>
372
										<?php set_checked($pconfig['pool_enable'],$chk); ?>
373
										<input name="pool_enable" type="checkbox" id="pool_enable" value="yes" <?=$chk;?> onClick="pool_change()">
374
									</td>
375
									<td>
376
										Provide a vitual IP address to clients<br>
377
									</td>
378
								</tr>
379
							</table>
380
							<table border="0" cellspacing="2" cellpadding="0">
381
								<tr>
382
									<td>
383
										Network:&nbsp;
384
										<input name="pool_address" type="text" class="formfld unknown" id="pool_address" size="20" value="<?=$pconfig['pool_address'];?>">
385
										/
386
										<select name="pool_netbits" class="formselect" id="pool_netbits">
387
											<?php for ($i = 32; $i >= 0; $i--): ?>
388
											<option value="<?=$i;?>" <?php if ($i == $pconfig['pool_netbits']) echo "selected"; ?>>
389
												<?=$i;?>
390
											</option>
391
											<?php endfor; ?>
392
										</select>
393
									</td>
394
								</tr>
395
							</table>
396
						</td>
397
					</tr>
398
					<tr>
399
						<td width="22%" valign="top" class="vncell">Network List</td>
400
						<td width="78%" class="vtable">
401
							<table border="0" cellspacing="2" cellpadding="0">
402
								<tr>
403
									<td>
404
										<?php set_checked($pconfig['net_list_enable'],$chk); ?>
405
										<input name="net_list_enable" type="checkbox" id="net_list_enable" value="yes" <?=$chk;?>>
406
									</td>
407
									<td>
408
										Provide a list of accessible networks to clients<br>
409
									</td>
410
								</tr>
411
							</table>
412
						</td>
413
					</tr>
414
					<tr> 
415
						<td width="22%" valign="top" class="vncell">DNS Default Domain</td>
416
						<td width="78%" class="vtable">
417
							<table border="0" cellspacing="2" cellpadding="0">
418
								<tr>
419
									<td>
420
										<?php set_checked($pconfig['dns_domain_enable'],$chk); ?>
421
										<input name="dns_domain_enable" type="checkbox" id="dns_domain_enable" value="yes" <?=$chk;?> onClick="dns_domain_change()">
422
									</td>
423
									<td>
424
										Provide a default domain name to clients<br>
425
									</td>
426
								</tr>
427
							</table>
428
							<table border="0" cellspacing="2" cellpadding="0">
429
								<tr>
430
									<td>
431
										<input name="dns_domain" type="text" class="formfld unknown" id="dns_domain" size="30" value="<?=htmlspecialchars($pconfig['dns_domain']);?>">
432
									</td>
433
								</tr>
434
							</table>
435
						</td>
436
					</tr>
437
					<tr> 
438
						<td width="22%" valign="top" class="vncell">DNS Servers</td>
439
						<td width="78%" class="vtable">
440
							<table border="0" cellspacing="2" cellpadding="0">
441
								<tr>
442
									<td>
443
										<?php set_checked($pconfig['dns_server_enable'],$chk); ?>
444
										<input name="dns_server_enable" type="checkbox" id="dns_server_enable" value="yes" <?=$chk;?> onClick="dns_server_change()">
445
									</td>
446
									<td>
447
										Provide a DNS server list to clients<br>
448
									</td>
449
								</tr>
450
							</table>
451
							<table border="0" cellspacing="2" cellpadding="0">
452
								<tr>
453
									<td>
454
										Server #1:&nbsp;
455
										<input name="dns_server1" type="text" class="formfld unknown" id="dns_server1" size="20" value="<?=$pconfig['dns_server1'];?>">
456
									</td>
457
								</tr>
458
								<tr>
459
									<td>
460
										Server #2:&nbsp;
461
										<input name="dns_server2" type="text" class="formfld unknown" id="dns_server2" size="20" value="<?=$pconfig['dns_server2'];?>">
462
									</td>
463
								</tr>
464
								<tr>
465
									<td>
466
										Server #3:&nbsp;
467
										<input name="dns_server3" type="text" class="formfld unknown" id="dns_server3" size="20" value="<?=$pconfig['dns_server3'];?>">
468
									</td>
469
								</tr>
470
								<tr>
471
									<td>
472
										Server #4:&nbsp;
473
										<input name="dns_server4" type="text" class="formfld unknown" id="dns_server4" size="20" value="<?=$pconfig['dns_server4'];?>">
474
									</td>
475
								</tr>
476
							</table>
477
						</td>
478
					</tr>
479
					<tr> 
480
						<td width="22%" valign="top" class="vncell">WINS Servers</td>
481
						<td width="78%" class="vtable">
482
							<table border="0" cellspacing="2" cellpadding="0">
483
								<tr>
484
									<td>
485
										<?php set_checked($pconfig['wins_server_enable'],$chk); ?>
486
										<input name="wins_server_enable" type="checkbox" id="wins_server_enable" value="yes" <?=$chk;?> onClick="wins_server_change()">
487
									</td>
488
									<td>
489
										Provide a WINS server list to clients<br>
490
									</td>
491
								</tr>
492
							</table>
493
							<table border="0" cellspacing="2" cellpadding="0">
494
								<tr>
495
									<td>
496
										Server #1:&nbsp;
497
										<input name="wins_server1" type="text" class="formfld unknown" id="wins_server1" size="20" value="<?=$pconfig['wins_server1'];?>">
498
									</td>
499
								</tr>
500
								<tr>
501
									<td>
502
										Server #2:&nbsp;
503
										<input name="wins_server2" type="text" class="formfld unknown" id="wins_server2" size="20" value="<?=$pconfig['wins_server2'];?>">
504
									</td>
505
								</tr>
506
							</table>
507
						</td>
508
					</tr>
509
					<tr>
510
						<td width="22%" valign="top" class="vncell">Phase2 PFS Group</td>
511
						<td width="78%" class="vtable">
512
							<table border="0" cellspacing="2" cellpadding="0">
513
								<tr>
514
									<td>
515
										<?php set_checked($pconfig['pfs_group_enable'],$chk); ?>
516
										<input name="pfs_group_enable" type="checkbox" id="pfs_group_enable" value="yes" <?=$chk;?> onClick="pfs_group_change()">
517
									</td>
518
									<td>
519
										Provide the Phase2 PFS group to clients ( overrides all mobile phase2 settings )<br>
520
									</td>
521
								</tr>
522
							</table>
523
							<table border="0" cellspacing="2" cellpadding="0">
524
								<tr>
525
									<td>
526
										Group:&nbsp;&nbsp;
527
										<select name="pfs_group" class="formselect" id="pfs_group">
528
										<?php foreach ($p2_pfskeygroups as $keygroup => $keygroupname): ?>
529
											<option value="<?=$keygroup;?>" <?php if ($pconfig['pfs_group'] == $keygroup) echo "selected"; ?>>
530
												<?=htmlspecialchars($keygroupname);?>
531
											</option>
532
										<?php endforeach; ?>
533
										</select>
534
									</td>
535
								</tr>
536
							</table>
537
						</td>
538
					</tr>
539
					<tr> 
540
						<td width="22%" valign="top" class="vncell">Login Banner</td>
541
						<td width="78%" class="vtable">
542
							<table border="0" cellspacing="2" cellpadding="0">
543
								<tr>
544
									<td>
545
										<?php set_checked($pconfig['login_banner_enable'],$chk); ?>
546
										<input name="login_banner_enable" type="checkbox" id="login_banner_enable" value="yes" <?=$chk;?> onClick="login_banner_change()">
547
									</td>
548
									<td>
549
										Provide a login banner to clients<br>
550
									</td>
551
								</tr>
552
							</table>
553
							<table border="0" cellspacing="2" cellpadding="0">
554
								<tr>
555
									<td>
556
										<?php $banner = htmlspecialchars($pconfig['login_banner']); ?>
557
										<textarea name="login_banner" cols="65" rows="7" id="login_banner" class="formpre"><?=$banner;?></textarea>
558
									</td>
559
								</tr>
560
							</table>
561
						</td>
562
					</tr>
563
					<tr>
564
						<td width="22%" valign="top">&nbsp;</td>
565
						<td width="78%">
566
							<input name="submit" type="submit" class="formbtn" value="Save">
567
						</td>
568
					</tr>
569
				</table>
570
			</div>
571
		</td>
572
	</tr>
573
</table>
574
</form>
575
<script language="JavaScript">
576
pool_change();
577
dns_domain_change();
578
dns_server_change();
579
wins_server_change();
580
pfs_group_change();
581
login_banner_change();
582
//-->
583
</script>
584
<?php include("fend.inc"); ?>
585
</body>
586
</html>
587

    
588
<?php
589

    
590
/* local utility functions */
591

    
592
function set_checked($var,& $chk) {
593
	if($var)
594
		$chk = 'checked';
595
	else
596
		$chk = '';
597
}
598

    
599
?>
600

    
(189-189/205)