Project

General

Profile

Download (18.9 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
require("functions.inc");
38
require("guiconfig.inc");
39
require_once("ipsec.inc");
40
require_once("vpn.inc");
41

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

    
45
$a_phase1 = &$config['ipsec']['phase1'];
46

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

    
50
$a_client = &$config['ipsec']['client'];
51

    
52
if (count($a_client)) {
53

    
54
	$pconfig['enable'] = $a_client['enable'];
55

    
56
	$pconfig['user_source'] = $a_client['user_source'];
57
	$pconfig['group_source'] = $a_client['group_source'];
58

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

    
72
	if (isset($pconfig['enable']))
73
		$pconfig['enable'] = true;
74

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

    
80
	if (isset($pconfig['net_list']))
81
		$pconfig['net_list_enable'] = true;
82

    
83
	if ($pconfig['dns_domain'])
84
		$pconfig['dns_domain_enable'] = true;
85

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

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

    
92
	if (isset($pconfig['pfs_group']))
93
		$pconfig['pfs_group_enable'] = true;
94

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

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

    
103
if ($_POST['apply']) {
104
	$retval = 0;
105
	$retval = vpn_ipsec_configure();
106
	$savemsg = get_std_save_message($retval);
107
	if ($retval == 0)
108
		if (is_subsystem_dirty('ipsec'))
109
			clear_subsystem_dirty('ipsec');
110
}
111

    
112
if ($_POST['submit']) {
113

    
114
	unset($input_errors);
115
	$pconfig = $_POST;
116

    
117
	/* input consolidation */
118

    
119
	
120

    
121
	/* input validation */
122

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

    
126
    do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
127

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

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

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

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

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

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

    
169
		$client['user_source'] = $pconfig['user_source'];
170
		$client['group_source'] = $pconfig['group_source'];
171

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

    
177
		if ($pconfig['net_list_enable'])
178
			$client['net_list'] = true;
179

    
180
		if ($pconfig['dns_domain_enable'])
181
			$client['dns_domain'] = $pconfig['dns_domain'];
182

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

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

    
195
		if ($pconfig['pfs_group_enable'])
196
			$client['pfs_group'] = $pconfig['pfs_group'];
197

    
198
		if ($pconfig['login_banner_enable'])
199
			$client['login_banner'] = $pconfig['login_banner'];
200

    
201
//		$echo "login banner = {$pconfig['login_banner']}";
202

    
203
		$a_client = $client;
204
		
205
		write_config();
206
		mark_subsystem_dirty('ipsec');
207
		
208
		header("Location: vpn_ipsec_mobile.php");
209
		exit;
210
	}
211
}
212

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

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

    
220
<script language="JavaScript">
221
<!--
222

    
223
function pool_change() {
224

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

    
234
function dns_domain_change() {
235

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

    
242
function dns_server_change() {
243

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

    
257
function wins_server_change() {
258

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

    
268
function pfs_group_change() {
269

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

    
276
function login_banner_change() {
277

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

    
284
//-->
285
</script>
286

    
287
<form action="vpn_ipsec_mobile.php" method="post" name="iform" id="iform">
288

    
289
<?php
290
	if ($savemsg)
291
		print_info_box($savemsg);
292
	if (isset($config['ipsec']['enable']) && is_subsystem_dirty('ipsec'))
293
		print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes in order for them to take effect.");
294
	foreach ($a_phase1 as $ph1ent)
295
		if (isset($ph1ent['mobile']))
296
			$ph1found = true;
297
	if ($pconfig['enable'] && !$ph1found)
298
		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");
299
	if ($input_errors)
300
		print_input_errors($input_errors);
301
?>
302

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

    
591
<?php
592

    
593
/* local utility functions */
594

    
595
function set_checked($var,& $chk) {
596
	if($var)
597
		$chk = 'checked';
598
	else
599
		$chk = '';
600
}
601

    
602
?>
603

    
(200-200/216)