Project

General

Profile

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

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

    
38
require("functions.inc");
39
require("guiconfig.inc");
40
require_once("ipsec.inc");
41
require_once("vpn.inc");
42
require_once("filter.inc");
43

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

    
47
$a_phase1 = &$config['ipsec']['phase1'];
48

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

    
52
$a_client = &$config['ipsec']['client'];
53

    
54
if (count($a_client)) {
55

    
56
	$pconfig['enable'] = $a_client['enable'];
57

    
58
	$pconfig['user_source'] = $a_client['user_source'];
59
	$pconfig['group_source'] = $a_client['group_source'];
60

    
61
	$pconfig['pool_address'] = $a_client['pool_address'];
62
	$pconfig['pool_netbits'] = $a_client['pool_netbits'];
63
	$pconfig['net_list'] = $a_client['net_list'];
64
	$pconfig['save_passwd'] = $a_client['save_passwd'];
65
	$pconfig['dns_domain'] = $a_client['dns_domain'];
66
	$pconfig['dns_split'] = $a_client['dns_split'];
67
	$pconfig['dns_server1'] = $a_client['dns_server1'];
68
	$pconfig['dns_server2'] = $a_client['dns_server2'];
69
	$pconfig['dns_server3'] = $a_client['dns_server3'];
70
	$pconfig['dns_server4'] = $a_client['dns_server4'];
71
	$pconfig['wins_server1'] = $a_client['wins_server1'];
72
	$pconfig['wins_server2'] = $a_client['wins_server2'];
73
	$pconfig['pfs_group'] = $a_client['pfs_group'];
74
	$pconfig['login_banner'] = $a_client['login_banner'];
75

    
76
	if (isset($pconfig['enable']))
77
		$pconfig['enable'] = true;
78

    
79
	if ($pconfig['pool_address']&&$pconfig['pool_netbits'])
80
		$pconfig['pool_enable'] = true;
81
	else
82
		$pconfig['pool_netbits'] = 24;
83

    
84
	if (isset($pconfig['net_list']))
85
		$pconfig['net_list_enable'] = true;
86

    
87
	if (isset($pconfig['save_passwd']))
88
		$pconfig['save_passwd_enable'] = true;
89

    
90
	if ($pconfig['dns_domain'])
91
		$pconfig['dns_domain_enable'] = true;
92

    
93
	if ($pconfig['dns_split'])
94
		$pconfig['dns_split_enable'] = true;
95

    
96
	if ($pconfig['dns_server1']||$pconfig['dns_server2']||$pconfig['dns_server3']||$pconfig['dns_server4'])
97
		$pconfig['dns_server_enable'] = true;
98

    
99
	if ($pconfig['wins_server1']||$pconfig['wins_server2'])
100
		$pconfig['wins_server_enable'] = true;
101

    
102
	if (isset($pconfig['pfs_group']))
103
		$pconfig['pfs_group_enable'] = true;
104

    
105
	if ($pconfig['login_banner'])
106
		$pconfig['login_banner_enable'] = true;
107
}
108

    
109
if ($_POST['create']) {
110
	header("Location: vpn_ipsec_phase1.php?mobile=true");
111
}
112

    
113
if ($_POST['apply']) {
114
	$retval = 0;
115
	$retval = vpn_ipsec_configure();
116
	$savemsg = get_std_save_message($retval);
117
	if ($retval >= 0)
118
		if (is_subsystem_dirty('ipsec'))
119
			clear_subsystem_dirty('ipsec');
120
}
121

    
122
if ($_POST['save']) {
123

    
124
	unset($input_errors);
125
	$pconfig = $_POST;
126

    
127
	/* input consolidation */
128

    
129

    
130

    
131
	/* input validation */
132

    
133
	$reqdfields = explode(" ", "user_source group_source");
134
	$reqdfieldsn =  array(gettext("User Authentication Source"),gettext("Group Authentication Source"));
135

    
136
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
137

    
138
	if ($pconfig['pool_enable'])
139
		if (!is_ipaddr($pconfig['pool_address']))
140
			$input_errors[] = gettext("A valid IP address for 'Virtual Address Pool Network' must be specified.");
141

    
142
	if ($pconfig['dns_domain_enable'])
143
		if (!is_domain($pconfig['dns_domain']))
144
			$input_errors[] = gettext("A valid value for 'DNS Default Domain' must be specified.");
145

    
146
	if ($pconfig['dns_split_enable']) {
147
		if (!empty($pconfig['dns_split'])) {
148
			$domain_array=preg_split("/[ ,]+/",$pconfig['dns_split']);
149
			foreach ($domain_array as $curdomain) {
150
				if (!is_domain($curdomain)) {
151
					$input_errors[] = gettext("A valid split DNS domain list must be specified.");
152
					break;
153
				}
154
			}
155
		}
156
	}
157

    
158
	if ($pconfig['dns_server_enable']) {
159
		if (!$pconfig['dns_server1'] && !$pconfig['dns_server2'] &&
160
			!$pconfig['dns_server3'] && !$pconfig['dns_server4'] )
161
			$input_errors[] = gettext("At least one DNS server must be specified to enable the DNS Server option.");
162
		if ($pconfig['dns_server1'] && !is_ipaddr($pconfig['dns_server1']))
163
			$input_errors[] = gettext("A valid IP address for 'DNS Server #1' must be specified.");
164
		if ($pconfig['dns_server2'] && !is_ipaddr($pconfig['dns_server2']))
165
			$input_errors[] = gettext("A valid IP address for 'DNS Server #2' must be specified.");
166
		if ($pconfig['dns_server3'] && !is_ipaddr($pconfig['dns_server3']))
167
			$input_errors[] = gettext("A valid IP address for 'DNS Server #3' must be specified.");
168
		if ($pconfig['dns_server4'] && !is_ipaddr($pconfig['dns_server4']))
169
			$input_errors[] = gettext("A valid IP address for 'DNS Server #4' must be specified.");
170
	}
171

    
172
	if ($pconfig['wins_server_enable']) {
173
		if (!$pconfig['wins_server1'] && !$pconfig['wins_server2'])
174
			$input_errors[] = gettext("At least one WINS server must be specified to enable the DNS Server option.");
175
		if ($pconfig['wins_server1'] && !is_ipaddr($pconfig['wins_server1']))
176
			$input_errors[] = gettext("A valid IP address for 'WINS Server #1' must be specified.");
177
		if ($pconfig['wins_server2'] && !is_ipaddr($pconfig['wins_server2']))
178
			$input_errors[] = gettext("A valid IP address for 'WINS Server #2' must be specified.");
179
	}
180

    
181
	if ($pconfig['login_banner_enable'])
182
		if (!strlen($pconfig['login_banner']))
183
			$input_errors[] = gettext("A valid value for 'Login Banner' must be specified.");
184

    
185
	if (!$input_errors) {
186
		$client = array();
187

    
188
		if ($pconfig['enable'])
189
			$client['enable'] = true;
190

    
191
		if (!empty($pconfig['user_source']))
192
			$client['user_source'] = implode(",", $pconfig['user_source']);
193
		$client['group_source'] = $pconfig['group_source'];
194

    
195
		if ($pconfig['pool_enable']) {
196
			$client['pool_address'] = $pconfig['pool_address'];
197
			$client['pool_netbits'] = $pconfig['pool_netbits'];
198
		}
199

    
200
		if ($pconfig['net_list_enable'])
201
			$client['net_list'] = true;
202

    
203
		if ($pconfig['save_passwd_enable'])
204
			$client['save_passwd'] = true;
205

    
206
		if ($pconfig['dns_domain_enable'])
207
			$client['dns_domain'] = $pconfig['dns_domain'];
208

    
209
		if ($pconfig['dns_split_enable'])
210
			$client['dns_split'] = $pconfig['dns_split'];
211

    
212
		if ($pconfig['dns_server_enable']) {
213
			$client['dns_server1'] = $pconfig['dns_server1'];
214
			$client['dns_server2'] = $pconfig['dns_server2'];
215
			$client['dns_server3'] = $pconfig['dns_server3'];
216
			$client['dns_server4'] = $pconfig['dns_server4'];
217
		}
218

    
219
		if ($pconfig['wins_server_enable']) {
220
			$client['wins_server1'] = $pconfig['wins_server1'];
221
			$client['wins_server2'] = $pconfig['wins_server2'];
222
		}
223

    
224
		if ($pconfig['pfs_group_enable'])
225
			$client['pfs_group'] = $pconfig['pfs_group'];
226

    
227
		if ($pconfig['login_banner_enable'])
228
			$client['login_banner'] = $pconfig['login_banner'];
229

    
230
//		$echo "login banner = {$pconfig['login_banner']}";
231

    
232
		$a_client = $client;
233

    
234
		write_config();
235
		mark_subsystem_dirty('ipsec');
236

    
237
		header("Location: vpn_ipsec_mobile.php");
238
		exit;
239
	}
240
}
241

    
242
$pgtitle = array(gettext("VPN"),gettext("IPsec"),gettext("Mobile"));
243
$shortcut_section = "ipsec";
244

    
245
include("head.inc");
246
?>
247

    
248
	<script type="text/javascript">
249
		//<![CDATA[
250

    
251
		function pool_change() {
252

    
253
			if (document.iform.pool_enable.checked) {
254
				document.iform.pool_address.disabled = 0;
255
				document.iform.pool_netbits.disabled = 0;
256
			} else {
257
				document.iform.pool_address.disabled = 1;
258
				document.iform.pool_netbits.disabled = 1;
259
			}
260
		}
261

    
262
		function dns_domain_change() {
263

    
264
			if (document.iform.dns_domain_enable.checked)
265
				document.iform.dns_domain.disabled = 0;
266
			else
267
				document.iform.dns_domain.disabled = 1;
268
		}
269

    
270
		function dns_split_change() {
271

    
272
			if (document.iform.dns_split_enable.checked)
273
				document.iform.dns_split.disabled = 0;
274
			else
275
				document.iform.dns_split.disabled = 1;
276
		}
277

    
278
		function dns_server_change() {
279

    
280
			if (document.iform.dns_server_enable.checked) {
281
				document.iform.dns_server1.disabled = 0;
282
				document.iform.dns_server2.disabled = 0;
283
				document.iform.dns_server3.disabled = 0;
284
				document.iform.dns_server4.disabled = 0;
285
			} else {
286
				document.iform.dns_server1.disabled = 1;
287
				document.iform.dns_server2.disabled = 1;
288
				document.iform.dns_server3.disabled = 1;
289
				document.iform.dns_server4.disabled = 1;
290
			}
291
		}
292

    
293
		function wins_server_change() {
294

    
295
			if (document.iform.wins_server_enable.checked) {
296
				document.iform.wins_server1.disabled = 0;
297
				document.iform.wins_server2.disabled = 0;
298
			} else {
299
				document.iform.wins_server1.disabled = 1;
300
				document.iform.wins_server2.disabled = 1;
301
			}
302
		}
303

    
304
		function pfs_group_change() {
305

    
306
			if (document.iform.pfs_group_enable.checked)
307
				document.iform.pfs_group.disabled = 0;
308
			else
309
				document.iform.pfs_group.disabled = 1;
310
		}
311

    
312
		function login_banner_change() {
313

    
314
			if (document.iform.login_banner_enable.checked)
315
				document.iform.login_banner.disabled = 0;
316
			else
317
				document.iform.login_banner.disabled = 1;
318
		}
319

    
320
		//]]>
321
	</script>
322

    
323
<?php
324
if ($savemsg)
325
	print_info_box($savemsg);
326
if (isset($config['ipsec']['enable']) && is_subsystem_dirty('ipsec'))
327
	print_info_box_np(gettext("The IPsec tunnel configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));
328
foreach ($a_phase1 as $ph1ent)
329
	if (isset($ph1ent['mobile']))
330
		$ph1found = true;
331
if ($pconfig['enable'] && !$ph1found)
332
	print_info_box_np(gettext("Support for IPsec Mobile clients is enabled but a Phase1 definition was not found") . ".<br />" . gettext("Please click Create to define one."),gettext("create"),gettext("Create Phase1"));
333
if ($input_errors)
334
	print_input_errors($input_errors);
335
?>
336

    
337
<?php
338

    
339
$tab_array = array();
340
$tab_array[0] = array(gettext("Tunnels"), false, "vpn_ipsec.php");
341
$tab_array[1] = array(gettext("Mobile clients"), true, "vpn_ipsec_mobile.php");
342
$tab_array[2] = array(gettext("Pre-Shared Key"), false, "vpn_ipsec_keys.php");
343
$tab_array[3] = array(gettext("Advanced Settings"), false, "vpn_ipsec_settings.php");
344
display_top_tabs($tab_array, false, 'pills');
345

    
346
require('classes/Form.class.php');
347
$form = new Form;
348

    
349
$section = new Form_Section('Enable IPsec Mobile Client Support');
350
$section->addInput(new Form_Checkbox(
351
	'enable',
352
	'IKE Extensions',
353
	'Enable IPsec Mobile Client Support',
354
	$pconfig['enable']
355
));
356

    
357
$form->add($section);
358

    
359
$section = new Form_Section('Extended Authentication (Xauth)');
360

    
361
$authServers = array();
362

    
363
foreach (auth_get_authserver_list() as $authServer)
364
	$authServers[$authServer['name']] = $authServer['name']; // Value == name
365

    
366
$section->addInput(new Form_Select(
367
	'user_source',
368
	'User Authentication',
369
	explode(",", $pconfig['user_source']),
370
	$authServers,
371
	true
372
))->setHelp('Source');
373

    
374
$section->addInput(new Form_Select(
375
	'group_source',
376
	'Group Authentication',
377
	$pconfig['group_source'],
378
	array(
379
		'none' => 'none',
380
		'system' => 'system',
381
	)
382
))->setHelp('Source');
383

    
384
$form->add($section);
385

    
386
$section = new Form_Section('Client Configuration (mode-cfg)');
387

    
388
$section->addInput(new Form_Checkbox(
389
	'pool_enable',
390
	'Virtual Address Pool',
391
	'Provide a virtual IP address to clients',
392
	$pconfig['pool_enable']
393
))->setAttribute('data-toggle', 'collapse')->setAttribute('data-target', '.toggle-pool_enable');
394

    
395
// TODO: Refactor this manual setup
396
$group = new Form_Group('');
397
$group->addClass('toggle-pool_enable collapse');
398

    
399
if (!empty($pconfig['pool_enable']))
400
	$group->addClass('in');
401

    
402
$group->add(new Form_Input(
403
	'pool_address',
404
	'Network',
405
	'text',
406
	htmlspecialchars($pconfig['pool_address'])
407
))->setWidth(4)->setHelp('Network configuration for Virtual Address Pool');
408

    
409
$netBits = array();
410

    
411
for ($i = 32; $i >= 0; $i--)
412
	$netBits[$i] = $i;
413

    
414
$group->add(new Form_Select(
415
	'pool_netbits',
416
	'',
417
	$pconfig['pool_netbits'],
418
	$netBits
419
))->setWidth(2);
420

    
421
$section->add($group);
422

    
423
$section->addInput(new Form_Checkbox(
424
	'net_list_enable',
425
	'Network List',
426
	'Provide a list of accessible networks to clients',
427
	$pconfig['net_list_enable']
428
));
429

    
430
$section->addInput(new Form_Checkbox(
431
	'save_passwd_enable',
432
	'Save Xauth Password',
433
	'Allow clients to save Xauth passwords (Cisco VPN client only).',
434
	$pconfig['save_passwd_enable']
435
))->setHelp('NOTE: With iPhone clients, this does not work when deployed via the iPhone configuration utility, only by manual entry.');
436

    
437
$section->addInput(new Form_Checkbox(
438
	'dns_domain_enable',
439
	'DNS Default Domain',
440
	'Provide a default domain name to clients',
441
	$pconfig['dns_domain_enable']
442
))->setAttribute('data-toggle', 'collapse')->setAttribute('data-target', '.toggle-dns_domain');
443

    
444
$group = new Form_Group('');
445
$group->addClass('toggle-dns_domain collapse');
446

    
447
if (!empty($pconfig['dns_domain_enable']))
448
	$group->addClass('in');
449

    
450
$group->add(new Form_Input(
451
	'dns_domain',
452
	'',
453
	'text',
454
	htmlspecialchars($pconfig['dns_domain'])
455
))->setHelp('Specify domain as DNS Default Domain');
456

    
457
$section->add($group);
458

    
459
$section->addInput(new Form_Checkbox(
460
	'dns_split_enable',
461
	'Split DNS',
462
	'Provide a list of split DNS domain names to clients. Enter a comma separated list.',
463
	$pconfig['dns_split_enable']
464
))->setAttribute('data-toggle', 'collapse')->setAttribute('data-target', '.toggle-dns_split');
465

    
466
$group = new Form_Group('');
467
$group->addClass('toggle-dns_split collapse');
468

    
469
if (!empty($pconfig['dns_split_enable']))
470
	$group->addClass('in');
471

    
472
$group->add(new Form_Input(
473
	'dns_split',
474
	'',
475
	'text',
476
	htmlspecialchars($pconfig['dns_split'])
477
))->setHelp('NOTE: If left blank, and a default domain is set, it will be used for this value.');
478

    
479
$section->add($group);
480

    
481
$section->addInput(new Form_Checkbox(
482
	'dns_server_enable',
483
	'DNS Servers',
484
	'Provide a DNS server list to clients',
485
	$pconfig['dns_server_enable']
486
))->setAttribute('data-toggle', 'collapse')->setAttribute('data-target', '.toggle-dns_server_enable');
487

    
488
for ($i = 1; $i <= 4; $i++)
489
{
490
	$group = new Form_Group('Server #' . $i);
491
	$group->addClass('toggle-dns_server_enable collapse');
492

    
493
	if (!empty($pconfig['dns_server_enable']))
494
		$group->addClass('in');
495

    
496
	$group->add(new Form_Input(
497
		'dns_server' . $i,
498
		'Server #' . $i,
499
		'text',
500
		htmlspecialchars($pconfig['dns_server' . $i])
501
	));
502

    
503
	$section->add($group);
504
}
505

    
506
$section->addInput(new Form_Checkbox(
507
	'wins_server_enable',
508
	'WINS Servers',
509
	'Provide a WINS server list to clients',
510
	$pconfig['wins_server_enable']
511
))->setAttribute('data-toggle', 'collapse')->setAttribute('data-target', '.toggle-wins_server_enable');
512

    
513
for ($i = 1; $i <= 2; $i++)
514
{
515
	$group = new Form_Group('Server #' . $i);
516
	$group->addClass('toggle-wins_server_enable collapse');
517

    
518
	if (!empty($pconfig['wins_server_enable']))
519
		$group->addClass('in');
520

    
521
	$group->add(new Form_Input(
522
		'wins_server' . $i,
523
		'Server #' . $i,
524
		'text',
525
		htmlspecialchars($pconfig['wins_server' . $i]),
526
		array('size' => 20)
527
	));
528

    
529
	$section->add($group);
530
}
531

    
532
$section->addInput(new Form_Checkbox(
533
	'pfs_group_enable',
534
	'Phase2 PFS Group',
535
	'Provide the Phase2 PFS group to clients ( overrides all mobile phase2 settings )',
536
	$pconfig['pfs_group_enable']
537
))->setAttribute('data-toggle', 'collapse')->setAttribute('data-target', '.toggle-pfs_group');
538

    
539
$group = new Form_Group('Group');
540
$group->addClass('toggle-pfs_group collapse');
541

    
542
if (!empty($pconfig['pfs_group_enable']))
543
	$group->addClass('in');
544

    
545
$group->add(new Form_Select(
546
	'pfs_group',
547
	'Group',
548
	$pconfig['pfs_group'],
549
	$p2_pfskeygroups
550
))->setWidth(2);
551

    
552
$section->add($group);
553

    
554
$section->addInput(new Form_Checkbox(
555
	'login_banner_enable',
556
	'Login Banner',
557
	'Provide a login banner to clients',
558
	$pconfig['login_banner_enable']
559
))->setAttribute('data-toggle', 'collapse')->setAttribute('data-target', '.toggle-login_banner');
560

    
561
$group = new Form_Group('');
562
$group->addClass('toggle-login_banner collapse');
563

    
564
if (!empty($pconfig['login_banner_enable']))
565
	$group->addClass('in');
566

    
567
// TODO: should be a textarea
568
$group->add(new Form_Input(
569
	'login_banner',
570
	'',
571
	'text',
572
	htmlspecialchars($pconfig['login_banner'])
573
));
574

    
575
$section->add($group);
576

    
577
$form->add($section);
578

    
579
print $form;
580

    
581
include("foot.inc");
(236-236/252)