Project

General

Profile

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

    
586
<?php
587

    
588
/* local utility functions */
589

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

    
597
?>
598

    
(196-196/209)