Project

General

Profile

Download (16.4 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
	/* NOTE: #4353 Always restart ipsec when mobile clients settings change */
116
	$retval = vpn_ipsec_configure(true);
117
	$savemsg = get_std_save_message($retval);
118
	if ($retval >= 0)
119
		if (is_subsystem_dirty('ipsec'))
120
			clear_subsystem_dirty('ipsec');
121
}
122

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

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

    
128
	/* input consolidation */
129

    
130

    
131

    
132
	/* input validation */
133

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

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

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

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

    
147
	if ($pconfig['dns_split_enable']) {
148
		if (!empty($pconfig['dns_split'])) {
149
			/* Replace multiple spaces by single */
150
			$pconfig['dns_split'] = preg_replace('/\s+/', ' ', trim($pconfig['dns_split']));
151
			$domain_array=explode(' ', $pconfig['dns_split']);
152
			foreach ($domain_array as $curdomain) {
153
				if (!is_domain($curdomain)) {
154
					$input_errors[] = gettext("A valid split DNS domain list must be specified.");
155
					break;
156
				}
157
			}
158
		}
159
	}
160

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

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

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

    
188
	if (!$input_errors) {
189
		$client = array();
190

    
191
		if ($pconfig['enable'])
192
			$client['enable'] = true;
193

    
194
		if (!empty($pconfig['user_source']))
195
			$client['user_source'] = implode(",", $pconfig['user_source']);
196
		$client['group_source'] = $pconfig['group_source'];
197

    
198
		if ($pconfig['pool_enable']) {
199
			$client['pool_address'] = $pconfig['pool_address'];
200
			$client['pool_netbits'] = $pconfig['pool_netbits'];
201
		}
202

    
203
		if ($pconfig['net_list_enable'])
204
			$client['net_list'] = true;
205

    
206
		if ($pconfig['save_passwd_enable'])
207
			$client['save_passwd'] = true;
208

    
209
		if ($pconfig['dns_domain_enable'])
210
			$client['dns_domain'] = $pconfig['dns_domain'];
211

    
212
		if ($pconfig['dns_split_enable'])
213
			$client['dns_split'] = $pconfig['dns_split'];
214

    
215
		if ($pconfig['dns_server_enable']) {
216
			$client['dns_server1'] = $pconfig['dns_server1'];
217
			$client['dns_server2'] = $pconfig['dns_server2'];
218
			$client['dns_server3'] = $pconfig['dns_server3'];
219
			$client['dns_server4'] = $pconfig['dns_server4'];
220
		}
221

    
222
		if ($pconfig['wins_server_enable']) {
223
			$client['wins_server1'] = $pconfig['wins_server1'];
224
			$client['wins_server2'] = $pconfig['wins_server2'];
225
		}
226

    
227
		if ($pconfig['pfs_group_enable'])
228
			$client['pfs_group'] = $pconfig['pfs_group'];
229

    
230
		if ($pconfig['login_banner_enable'])
231
			$client['login_banner'] = $pconfig['login_banner'];
232

    
233
		$a_client = $client;
234

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

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

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

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

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

    
252
		function pool_change() {
253

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

    
263
		function dns_domain_change() {
264

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

    
271
		function dns_split_change() {
272

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

    
279
		function dns_server_change() {
280

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

    
294
		function wins_server_change() {
295

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

    
305
		function pfs_group_change() {
306

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

    
313
		function login_banner_change() {
314

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

    
321
		//]]>
322
	</script>
323

    
324
<?php
325
if ($savemsg)
326
	print_info_box($savemsg);
327
if (isset($config['ipsec']['enable']) && is_subsystem_dirty('ipsec'))
328
	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."));
329
foreach ($a_phase1 as $ph1ent)
330
	if (isset($ph1ent['mobile']))
331
		$ph1found = true;
332
if ($pconfig['enable'] && !$ph1found)
333
	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"));
334
if ($input_errors)
335
	print_input_errors($input_errors);
336

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

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

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

    
355
$form->add($section);
356

    
357
$section = new Form_Section('Extended Authentication (Xauth)');
358

    
359
$authServers = array();
360

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

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

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

    
382
$form->add($section);
383

    
384
$section = new Form_Section('Client Configuration (mode-cfg)');
385

    
386
$section->addInput(new Form_Checkbox(
387
	'pool_enable',
388
	'Virtual Address Pool',
389
	'Provide a virtual IP address to clients',
390
	$pconfig['pool_enable']
391
))->toggles('.toggle-pool_enable');
392

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

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

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

    
407
$netBits = array();
408

    
409
for ($i = 32; $i >= 0; $i--)
410
	$netBits[$i] = $i;
411

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

    
419
$section->add($group);
420

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

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

    
435
$section->addInput(new Form_Checkbox(
436
	'dns_domain_enable',
437
	'DNS Default Domain',
438
	'Provide a default domain name to clients',
439
	$pconfig['dns_domain_enable']
440
))->toggles('.toggle-dns_domain');
441

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

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

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

    
455
$section->add($group);
456

    
457
$section->addInput(new Form_Checkbox(
458
	'dns_split_enable',
459
	'Split DNS',
460
	'Provide a list of split DNS domain names to clients. Enter a space separated list.',
461
	$pconfig['dns_split_enable']
462
))->toggles('.toggle-dns_split');
463

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

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

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

    
477
$section->add($group);
478

    
479
$section->addInput(new Form_Checkbox(
480
	'dns_server_enable',
481
	'DNS Servers',
482
	'Provide a DNS server list to clients',
483
	$pconfig['dns_server_enable']
484
))->toggles('.toggle-dns_server_enable');
485

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

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

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

    
501
	$section->add($group);
502
}
503

    
504
$section->addInput(new Form_Checkbox(
505
	'wins_server_enable',
506
	'WINS Servers',
507
	'Provide a WINS server list to clients',
508
	$pconfig['wins_server_enable']
509
))->toggles('.toggle-wins_server_enable');
510

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

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

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

    
527
	$section->add($group);
528
}
529

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

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

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

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

    
550
$section->add($group);
551

    
552
$section->addInput(new Form_Checkbox(
553
	'login_banner_enable',
554
	'Login Banner',
555
	'Provide a login banner to clients',
556
	$pconfig['login_banner_enable']
557
))->toggles('.toggle-login_banner');
558

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

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

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

    
573
$section->add($group);
574

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

    
577
print $form;
578

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