Projet

Général

Profil

Télécharger (23,8 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / wizards / openvpn_wizard.inc @ a03943d2

1
<?php
2
/*
3
	Copyright (C) 2010 Ermal Luçi
4
	All rights reserved.
5

    
6
	Redistribution and use in source and binary forms, with or without
7
	modification, are permitted provided that the following conditions are met:
8

    
9
	1. Redistributions of source code must retain the above copyright notice,
10
	   this list of conditions and the following disclaimer.
11

    
12
	2. Redistributions in binary form must reproduce the above copyright
13
	   notice, this list of conditions and the following disclaimer in the
14
	   documentation and/or other materials provided with the distribution.
15

    
16
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
20
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
	POSSIBILITY OF SUCH DAMAGE.
26

    
27
	pfSense_MODULE: openvpn
28
*/
29
require_once("openvpn.inc");
30

    
31
function has_special_chars($text) {
32
	return preg_match('/[^A-Za-z0-9 _-]/', $text);
33
}
34

    
35
function step1_submitphpaction() {
36
	global $stepid, $config;
37
	if ($_POST['authtype'] == "local") {
38
		$stepid = 4;
39
		$config['ovpnserver']['step1']['type'] = "local";
40
	} else if ($_POST['authtype'] == "ldap") {
41
		$stepid = 0;
42
	} else if ($_POST['authtype'] == "radius") {
43
		$stepid = 2;
44
		$config['ovpnserver']['step1']['type'] = "radius";
45
		unset($config['ovpnserver']['step1']['uselist']);
46
	}
47
}
48

    
49
function step2_stepbeforeformdisplay() {
50
	global $pkg, $stepid;
51

    
52
	$fields =& $pkg['step'][1]['fields']['field'];
53

    
54
	$found = false;
55
	$authlist = auth_get_authserver_list();
56
	$fields[1]['options']['option'] = array();
57
	foreach ($authlist as $i => $auth) {
58
		if ($auth['type'] != "ldap")
59
			continue;
60
		$found = true;
61
		$opts = array();
62
		$opts['name'] = $auth['name'];
63
		$opts['value'] = $auth['name'];
64
		$fields[1]['options']['option'][] = $opts;
65
	}
66
	if ($found == false) {
67
		$stepid = 2;
68
	}
69
}
70

    
71
function step2_submitphpaction() {
72
	global $stepid;
73

    
74
	if (isset($_POST['next'])) {
75
		$_POST['uselist'] = "";
76
		$stepid +=3;
77
	}
78
}
79

    
80
function step3_submitphpaction() {
81
	global $stepid, $savemsg, $config;
82

    
83
	/* Default LDAP port is 389 for TCP and 636 for SSL */
84
	if (empty($_POST['port'])) {
85
		if ($_POST['transport'] == "tcp")
86
			$config['ovpnserver']['step2']['port'] = 389;
87
		elseif ($_POST['transport'] == "ssl")
88
			$config['ovpnserver']['step2']['port'] = 636;
89
	} elseif (!is_port($_POST['port'])) {
90
		$stepid--;
91
		$savemsg = "Please enter a valid port number.";
92
	}
93

    
94
	if (empty($_POST['name']) || empty($_POST['ip']) ||empty($_POST['transport']) ||
95
	     empty($_POST['scope']) || empty($_POST['basedn']) || empty($_POST['authscope']) || empty($_POST['nameattr'])) {
96
		$stepid--;
97
		$savemsg = "Please enter all information for authentication server.";
98
	} else if (count(($authcfg = auth_get_authserver($_POST['name']))) > 0) {
99
		$stepid--;
100
		$savemsg = "Please choose a different name because an authentication server with this name already exists.";
101
	} elseif (!is_fqdn($_POST['ip']) && !is_ipaddr($_POST['ip'])) {
102
		$stepid--;
103
		$savemsg = "Please enter a valid IP address or hostname for the authentication server.";
104
	} else {
105
		$config['ovpnserver']['step2']['uselist'] = "on";
106
		$_POST['uselist'] = "on";
107
		$stepid += 2;
108
	}
109
}
110

    
111
function step4_stepbeforeformdisplay() {
112
	global $pkg, $stepid;
113

    
114
	$fields =& $pkg['step'][3]['fields']['field'];
115

    
116
	$found = false;
117
	$authlist = auth_get_authserver_list();
118
	$fields[1]['options']['option'] = array();
119
	foreach ($authlist as $i => $auth) {
120
		if ($auth['type'] != "radius")
121
			continue;
122
		$found = true;
123
		$opts = array();
124
		$opts['name'] = $auth['name'];
125
		$opts['value'] = $auth['name'];
126
		$fields[1]['options']['option'][] = $opts;
127
	}
128
	if ($found == false)
129
		$stepid = 4;
130
}
131

    
132
function step4_submitphpaction() {
133
	global $stepid;
134

    
135
	if (isset($_POST['next'])) {
136
		$_POST['uselist'] = "";
137
		$stepid++;
138
	}
139
}
140

    
141
function step5_submitphpaction() {
142
	global $stepid, $savemsg, $config;
143

    
144
	/* Default RADIUS Auth port = 1812 */
145
	if (empty($_POST['port'])) {
146
		$config['ovpnserver']['step2']['port'] = 1812;
147
	} elseif (!is_port($_POST['port'])) {
148
		$stepid--;
149
		$savemsg = "Please enter a valid port number.";
150
	}
151

    
152
	if (empty($_POST['name']) || empty($_POST['ip']) || empty($_POST['secret'])) {
153
		$stepid--;
154
		$savemsg = "Please enter all information for authentication server.";
155
	} else if (count(($authcfg = auth_get_authserver($_POST['name']))) > 0) {
156
		$stepid--;
157
		$savemsg = "Please choose a different name because an authentication server with this name already exists.";
158
	} elseif (!is_fqdn($_POST['ip']) && !is_ipaddr($_POST['ip'])) {
159
		$stepid--;
160
		$savemsg = "Please enter a valid IP address or hostname for the authentication server.";
161
	} else {
162
		$config['ovpnserver']['step2']['uselist'] = "on";
163
		$_POST['uselist'] = "on";
164
	}
165
}
166

    
167
function step6_stepbeforeformdisplay() {
168
	global $stepid, $config;
169

    
170
	if (count($config['ca']) < 1) {
171
		$stepid++;
172
	}
173
}
174

    
175
function step6_submitphpaction() {
176
	global $stepid, $config;
177

    
178
	if (isset($_POST['next'])) {
179
		$_POST['uselist'] = "";
180
		unset($config['ovpnserver']['step6']['uselist']);
181
		$stepid++;
182
	} else {
183
		$config['ovpnserver']['step6']['uselist'] = "on";
184
		$_POST['uselist'] = "on";
185
	}
186
}
187

    
188
function step7_submitphpaction() {
189
	global $input_errors, $stepid, $savemsg, $_POST, $config;
190

    
191
	$canames = array();
192
	$cacns = array();
193
	if (is_array($config['ca'])) {
194
		foreach($config['ca'] as $ca) {
195
			$canames[] = $ca['descr'];
196
			$cainfo = cert_get_subject_hash($ca['crt']);
197
			$cacns[] = $cainfo["CN"];
198
		}
199
	}
200

    
201
	if (empty($_POST['descr']) || empty($_POST['keylength']) || empty($_POST['lifetime']) ||
202
	    empty($_POST['country']) || empty($_POST['state']) || empty($_POST['city']) ||
203
	    empty($_POST['organization']) || empty($_POST['email'])) {
204
		$stepid--;
205
		$savemsg = "Please enter all information for the new Certificate Authority.";
206
	} elseif (has_special_chars($_POST['country']) || has_special_chars($_POST['state']) || 
207
	    has_special_chars($_POST['city']) || has_special_chars($_POST['organization'])) {
208
		$stepid--;
209
		$input_errors[] = "Please do not use special characters in Certificate field names.";
210
	} elseif (in_array($_POST['descr'], $canames) || in_array($_POST['descr'], $cacns)) {
211
		$stepid--;
212
		$savemsg = "Please enter a different name for the Certicicate Authority. A Certificate Authority with that name already exists.";
213
	} elseif (strlen($_POST['country']) != 2) {
214
		$stepid--;
215
		$savemsg = "Please enter only a two-letter ISO country code";
216
	} else {
217
		$config['ovpnserver']['step6']['uselist'] = "on";
218
		$_POST['uselist'] = "on";
219
	}
220
}
221

    
222
function step8_stepbeforeformdisplay() {
223
	global $stepid, $config;
224

    
225
	if (count($config['cert']) < 1 ||
226
		(count($config['cert']) == 1 && stristr($config['cert'][0]['descr'], "webconf"))) {
227
		$stepid++;
228
	}
229
}
230

    
231
function step8_submitphpaction() {
232
	global $stepid, $config, $_POST;
233

    
234
	if (isset($_POST['next'])) {
235
		$_POST['uselist'] = "";
236
		unset($config['ovpnserver']['step9']['uselist']);
237
		$stepid++;
238
	} else {
239
		$config['ovpnserver']['step6']['uselist'] = "on";
240
		$_POST['uselist'] = "on";
241
	}
242
}
243

    
244
function step9_stepbeforeformdisplay() {
245
	global $config, $pkg, $stepid;
246

    
247
	$pconfig = $config['ovpnserver'];
248

    
249
	if (isset($pconfig['step6']['uselist'])) {
250
		$country = $pconfig['step6']['country'];
251
		$state = $pconfig['step6']['state'];
252
		$city = $pconfig['step6']['city'];
253
		$org = $pconfig['step6']['organization'];
254
		$email = $pconfig['step6']['email'];
255
	} else {
256
		$ca = lookup_ca($pconfig['step6']['authcertca']);
257
		$cavl = cert_get_subject_array($ca['crt']);
258
		$country = $cavl[0]['v'];
259
		$state = $cavl[1]['v'];
260
		$city = $cavl[2]['v'];
261
		$org = $cavl[3]['v'];
262
		$email = $cavl[4]['v'];
263
	}
264
	$fields =& $pkg['step'][$stepid]['fields']['field'];
265

    
266
	foreach ($fields as $idx => $field) {
267
		switch ($field['name']) {
268
		case 'country':
269
			$fields[$idx]['value'] = $country;
270
			break;
271
		case 'state':
272
			$fields[$idx]['value'] = $state;
273
			break;
274
		case 'city':
275
			$fields[$idx]['value'] = $city;
276
			break;
277
		case 'organization':
278
			$fields[$idx]['value'] = $org;
279
			break;
280
		case 'email':
281
			$fields[$idx]['value'] = $email;
282
			break;
283
		}
284
	}
285
}
286

    
287
function step9_submitphpaction() {
288
	global $input_errors, $stepid, $savemsg, $_POST, $config;
289

    
290
	$certnames = array();
291
	$certcns = array();
292
	if (is_array($config['cert'])) {
293
		foreach($config['cert'] as $cert) {
294
			$certnames[] = $cert['descr'];
295
			$certinfo = cert_get_subject_hash($cert['crt']);
296
			$certcns[] = $certinfo["CN"];
297
		}	
298
	}
299

    
300
	if (empty($_POST['descr']) || empty($_POST['keylength']) || empty($_POST['lifetime']) ||
301
	    empty($_POST['country']) || empty($_POST['state']) || empty($_POST['city']) ||
302
	    empty($_POST['organization']) || empty($_POST['email'])) {
303
		$stepid--;
304
		$savemsg = "Please enter all information for the new certificate.";
305
	} elseif (has_special_chars($_POST['country']) || has_special_chars($_POST['state']) || 
306
	    has_special_chars($_POST['city']) || has_special_chars($_POST['organization'])) {
307
		$stepid--;
308
		$input_errors[] = "Please do not use special characters in Certificate field names.";
309
	} elseif (in_array($_POST['descr'], $certnames) || in_array($_POST['descr'], $certcns)) {
310
		$stepid--;
311
		$savemsg = "Please enter a different name for the Certicicate. A Certificate with that name/common name already exists.";	
312
	} elseif (strlen($_POST['country']) != 2) {
313
		$stepid--;
314
		$savemsg = "Please enter only a two-letter ISO country code";
315
	} else {
316
		$config['ovpnserver']['step9']['uselist'] = "on";
317
		$_POST['uselist'] = "on";
318
	}
319
}
320

    
321
function step10_stepbeforeformdisplay() {
322
	global $pkg, $stepid, $netbios_nodetypes;
323

    
324
	foreach ($pkg['step'][$stepid]['fields']['field'] as $idx => $field) {
325
		if ($field['name'] == "crypto") {
326
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'] = array();
327
			$cipherlist = openvpn_get_cipherlist();
328
			foreach ($cipherlist as $name => $desc) {
329
				$opt = array();
330
				$opt['name'] = $desc;
331
				$opt['value'] = $name;
332
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'][] = $opt;
333
			}
334
		} else if ($field['name'] == "digest") {
335
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'] = array();
336
			$digestlist = openvpn_get_digestlist();
337
			foreach ($digestlist as $name => $desc) {
338
				$opt = array();
339
				$opt['name'] = $desc;
340
				$opt['value'] = $name;
341
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'][] = $opt;
342
			}
343
		} else if ($field['name'] == "compression") {
344
			global $openvpn_compression_modes;
345
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'] = array();
346
			foreach ($openvpn_compression_modes as $name => $desc) {
347
				$opt = array();
348
				$opt['name'] = $desc;
349
				$opt['value'] = $name;
350
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'][] = $opt;
351
			}
352
		} else if ($field['name'] == "engine") {
353
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'] = array();
354
			$engines = openvpn_get_engines();
355
			foreach ($engines as $name => $desc) {
356
				$opt = array();
357
				$opt['name'] = $desc;
358
				$opt['value'] = $name;
359
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'][] = $opt;
360
			}
361
		} else if ($field['name'] == "nbttype") {
362
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'] = array();
363
			foreach ($netbios_nodetypes as $type => $name) {
364
				$opt = array();
365
				$opt['name'] = $name;
366
				$opt['value'] = $type;
367
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'][] = $opt;
368
			}
369
		} else if ($field['name'] == "localport") {
370
			$pkg['step'][$stepid]['fields']['field'][$idx]['value'] = openvpn_port_next('UDP');
371
		}
372
	}
373
}
374

    
375
function step10_submitphpaction() {
376
	global $savemsg, $stepid;
377

    
378
	/* Default OpenVPN port to next available port if left empty. */
379
	if (empty($_POST['localport']))
380
		$pconfig["step10"]["localport"] = openvpn_port_next('UDP');
381

    
382
	/* input validation */
383
	if ($result = openvpn_validate_port($_POST['localport'], 'Local port'))
384
		$input_errors[] = $result;
385

    
386
	if ($result = openvpn_validate_cidr($_POST['tunnelnet'], 'Tunnel Network', false, "ipv4"))
387
		$input_errors[] = $result;
388

    
389
	if ($result = openvpn_validate_cidr($_POST['localnet'], 'Local Network', true, "ipv4"))
390
		$input_errors[] = $result;
391

    
392
	$portused = openvpn_port_used($_POST['protocol'], $_POST['interface'], $_POST['localport']);
393
	if ($portused != 0)
394
		$input_errors[] = "The specified 'Local port' is in use. Please select another value";
395

    
396
	if (!isset($_POST['generatetlskey']) && isset($_POST['tlsauthentication']))
397
		if (!strstr($_POST['tlssharedkey'], "-----BEGIN OpenVPN Static key V1-----") ||
398
			!strstr($_POST['tlssharedkey'], "-----END OpenVPN Static key V1-----"))
399
			$input_errors[] = "The field 'TLS Authentication Key' does not appear to be valid";
400

    
401
	if (!empty($_POST['dnsserver1']) && !is_ipaddr(trim($_POST['dnsserver1'])))
402
		$input_errors[] = "The field 'DNS Server #1' must contain a valid IP address";
403
	if (!empty($_POST['dnsserver2']) && !is_ipaddr(trim($_POST['dnsserver2'])))
404
		$input_errors[] = "The field 'DNS Server #2' must contain a valid IP address";
405
	if (!empty($_POST['dnsserver3']) && !is_ipaddr(trim($_POST['dnsserver3'])))
406
		$input_errors[] = "The field 'DNS Server #3' must contain a valid IP address";
407
	if (!empty($_POST['dnsserver4']) && !is_ipaddr(trim($_POST['dnsserver4'])))
408
		$input_errors[] = "The field 'DNS Server #4' must contain a valid IP address";
409

    
410
	if (!empty($_POST['ntpserver1']) && !is_ipaddr(trim($_POST['ntpserver1'])))
411
		$input_errors[] = "The field 'NTP Server #1' must contain a valid IP address";
412
	if (!empty($_POST['ntpserver2']) && !is_ipaddr(trim($_POST['ntpserver2'])))
413
		$input_errors[] = "The field 'NTP Server #2' must contain a valid IP address";
414

    
415
	if (!empty($_POST['winsserver1']) && !is_ipaddr(trim($_POST['winsserver1'])))
416
		$input_errors[] = "The field 'WINS Server #1' must contain a valid IP address";
417
	if (!empty($_POST['winsserver2']) && !is_ipaddr(trim($_POST['winsserver2'])))
418
		$input_errors[] = "The field 'WINS Server #2' must contain a valid IP address";
419

    
420
	if ($_POST['concurrentcon'] && !is_numeric($_POST['concurrentcon']))
421
		$input_errors[] = "The field 'Concurrent connections' must be numeric.";
422

    
423
	if (empty($_POST['tunnelnet']))
424
		$input_errors[] = "You must specify a 'Tunnel network'.";
425

    
426
	if (count($input_errors) > 0) {
427
		$savemsg = $input_errors[0];
428
		$stepid = $stepid - 1;
429
	}
430
}
431

    
432
function step12_submitphpaction() {
433
	global $config;
434

    
435
	$pconfig = $config['ovpnserver'];
436

    
437
	if (!is_array($config['ovpnserver'])) {
438
		$message = "No configuration found please retry again.";
439
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=1&message={$message}");
440
		exit;
441
	}
442

    
443
	if ($pconfig['step1']['type'] == "local") {
444
		$auth = array();
445
		$auth['name'] = "Local Database";
446
		$auth['type'] = "local";
447
	} else if (isset($pconfig['step2']['uselist'])) {
448
		$auth = array();
449
		$auth['type'] = $pconfig['step1']['type'];
450
		$auth['refid'] = uniqid();
451
		$auth['name'] = $pconfig['step2']['authtype'];
452

    
453
		if ($auth['type'] == "ldap") {
454
			$auth['host'] = $pconfig['step2']['ip'];
455
			$auth['ldap_port'] = $pconfig['step2']['port'];
456
			if ($pconfig['step1']['transport'] == "tcp")
457
				$auth['ldap_urltype'] = 'TCP - Standard';
458
			else
459
				$auth['ldap_urltype'] = 'SSL - Encrypted';
460
			$auth['ldap_protver'] = 3;
461
			$auth['ldap_scope'] = $pconfig['step2']['scope'];
462
			$auth['ldap_basedn'] = $pconfig['step2']['basedn'];
463
			$auth['ldap_authcn'] = $pconfig['step2']['authscope'];
464
			$auth['ldap_binddn'] = $pconfig['step2']['userdn'];
465
			$auth['ldap_bindpw'] = $pconfig['step2']['passdn'];
466
			$auth['ldap_attr_user'] = $pconfig['step1']['nameattr'];
467
			$auth['ldap_attr_member'] = $pconfig['step1']['memberattr'];
468
			$auth['ldap_attr_group'] = $pconfig['step1']['groupattr'];
469
		} else if ($auth['type'] == "radius") {
470
			$auth['host'] = $pconfig['step2']['ip'];
471
			$auth['radius_auth_port'] = $pconfig['step2']['port'];
472
			$auth['radius_secret'] = $pconfig['step2']['password'];
473
			$auth['radius_srvcs'] = "auth";
474
		}
475
		if (!is_array($config['system']['authserver']))
476
			$config['system']['authserver'] = array();
477

    
478
		$config['system']['authserver'][] = $auth;
479
	} else if (!isset($pconfig['step2']['uselist']) && empty($pconfig['step2']['authserv'])) {
480
		$message = "Please choose an authentication server .";
481
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=1&message={$message}");
482
		exit;
483
	} else if (!($auth = auth_get_authserver($pconfig['step2']['authserv']))) {
484
		$message = "Not a valid authentication server has been specified.";
485
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=1&message={$message}");
486
		exit;
487
	}
488

    
489
	if (isset($pconfig['step6']['uselist']) && !empty($pconfig['step6']['certca'])) {
490
		$ca = array();
491
		$ca['refid'] = uniqid();
492
		$ca['descr'] = $pconfig['step6']['certca'];
493
		$dn = array(
494
			'countryName' => $pconfig['step6']['country'],
495
			'stateOrProvinceName' => $pconfig['step6']['state'],
496
			'localityName' => $pconfig['step6']['city'],
497
			'organizationName' => $pconfig['step6']['organization'],
498
			'emailAddress' => $pconfig['step6']['email'],
499
			'commonName' => $pconfig['step6']['certca']);
500

    
501
		ca_create($ca, $pconfig['step6']['keylength'], $pconfig['step6']['lifetime'], $dn, "sha256");
502
		if (!is_array($config['ca']))
503
			$config['ca'] = array();
504

    
505
		$config['ca'][] = $ca;
506
	} else if (!isset($pconfig['step6']['uselist']) && empty($pconfig['step6']['authcertca'])) {
507
		$message = "Please choose a Certificate Authority.";
508
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=5&message={$message}");
509
		exit;
510
	} else if (!($ca = lookup_ca($pconfig['step6']['authcertca']))) {
511
		$message = "Not a valid Certificate Authority specified.";
512
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=5&message={$message}");
513
		exit;
514
	}
515

    
516
	if (isset($pconfig['step9']['uselist'])) {
517
		$cert = array();
518
		$cert['refid'] = uniqid();
519
		$cert['descr'] = $pconfig['step9']['certname'];
520
		$dn = array(
521
			'countryName' => $pconfig['step9']['country'],
522
			'stateOrProvinceName' => $pconfig['step9']['state'],
523
			'localityName' => $pconfig['step9']['city'],
524
			'organizationName' => $pconfig['step9']['organization'],
525
			'emailAddress' => $pconfig['step9']['email'],
526
			'commonName' => $pconfig['step9']['certname']);
527

    
528
		cert_create($cert, $ca['refid'], $pconfig['step9']['keylength'], $pconfig['step9']['lifetime'], $dn, 'server', "sha256");
529
		if (!is_array($config['cert']))
530
			$config['cert'] = array();
531

    
532
		$config['cert'][] = $cert;
533
	} else if (!isset($pconfig['step9']['uselist']) && empty($pconfig['step9']['authcertname'])) {
534
		$message = "Please choose a Certificate.";
535
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=7&message={$message}");
536
		exit;
537
	} else if (!($cert = lookup_cert($pconfig['step9']['authcertname']))) {
538
		$message = "Not a valid Certificate specified.";
539
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=7&message={$message}");
540
		exit;
541
	}
542
	$server = array();
543
	$server['vpnid'] = openvpn_vpnid_next();
544
	switch ($auth['type']) {
545
		case "ldap":
546
			$server['authmode'] = $auth['name'];
547
			$server['mode'] = "server_user";
548
			break;
549
		case "radius":
550
			$server['authmode'] = $auth['name'];
551
			$server['mode'] = "server_user";
552
			break;
553
		default:
554
			$server['authmode'] = "Local Database";
555
			$server['mode'] = "server_tls_user";
556
			break;
557
	}
558
	$server['caref'] = $ca['refid'];
559
	$server['certref'] = $cert['refid'];
560
	$server['protocol'] = $pconfig['step10']['protocol'];
561
	$server['interface'] = $pconfig['step10']['interface'];
562
	if (isset($pconfig['step10']['localport']))
563
		$server['local_port'] = $pconfig['step10']['localport'];
564

    
565
	if (strlen($pconfig['step10']['descr']) > 30)
566
		$pconfig['step10']['descr'] = substr($pconfig['step10']['descr'], 0, 30);
567
	$server['description'] = $pconfig['step10']['descr'];
568
	$server['custom_options'] = $pconfig['step10']['advanced'];
569
	if (isset($pconfig['step10']['tlsauth'])) {
570
		if (isset($pconfig['step10']['gentlskey']))
571
			$tlskey = openvpn_create_key();
572
		else
573
			$tlskey = $pconfig['step10']['tlskey'];
574
		$server['tls'] = base64_encode($tlskey);
575
	}
576
	$server['dh_length'] = $pconfig['step10']['dhkey'];
577
	$server['tunnel_network'] = $pconfig['step10']['tunnelnet'];
578
	if (isset($pconfig['step10']['rdrgw']))
579
		$server['gwredir'] = $pconfig['step10']['rdrgw'];
580
	if (isset($pconfig['step10']['localnet']))
581
		$server['local_network'] = $pconfig['step10']['localnet'];
582
	if (isset($pconfig['step10']['concurrentcon']))
583
		$server['maxclients'] = $pconfig['step10']['concurrentcon'];
584
	if (isset($pconfig['step10']['compression']))
585
		$server['compression'] = $pconfig['step10']['compression'];
586
	if (isset($pconfig['step10']['tos']))
587
		$server['passtos'] = $pconfig['step10']['tos'];
588
	if (isset($pconfig['step10']['interclient']))
589
		$server['client2client'] = $pconfig['step10']['interclient'];
590
	if (isset($pconfig['step10']['duplicate_cn']))
591
		$server['duplicate_cn'] = $pconfig['step10']['duplicate_cn'];
592
	if (isset($pconfig['step10']['dynip']))
593
		$server['dynamic_ip'] = $pconfig['step10']['dynip'];
594
	if (isset($pconfig['step10']['addrpool']))
595
		$server['pool_enable'] = $pconfig['step10']['addrpool'];
596
	if (isset($pconfig['step10']['defaultdomain']))
597
		$server['dns_domain'] = $pconfig['step10']['defaultdomain'];
598
	if (isset($pconfig['step10']['dns1']))
599
		$server['dns_server1'] = $pconfig['step10']['dns1'];
600
	if (isset($pconfig['step10']['dns2']))
601
		$server['dns_server2'] = $pconfig['step10']['dns2'];
602
	if (isset($pconfig['step10']['dns3']))
603
		$server['dns_server3'] = $pconfig['step10']['dns3'];
604
	if (isset($pconfig['step10']['dns4']))
605
		$server['dns_server4'] = $pconfig['step10']['dns4'];
606
	if (isset($pconfig['step10']['ntp1']))
607
		$server['ntp_server1'] = $pconfig['step10']['ntp1'];
608
	if (isset($pconfig['step10']['ntp2']))
609
		$server['ntp_server2'] = $pconfig['step10']['ntp2'];
610
	if (isset($pconfig['step10']['wins1']))
611
		$server['wins_server1'] = $pconfig['step10']['wins1'];
612
	if (isset($pconfig['step10']['wins2']))
613
		$server['wins_server2'] = $pconfig['step10']['wins2'];
614
	if (isset($pconfig['step10']['nbtenable'])) {
615
		$server['netbios_ntype'] = $pconfig['step10']['nbttype'];
616
		if (isset($pconfig['step10']['nbtscope']))
617
			$server['netbios_scope'] = $pconfig['step10']['nbtscope'];
618
		$server['netbios_enable'] = $pconfig['step10']['nbtenable'];
619
	}
620
	$server['crypto'] = $pconfig['step10']['crypto'];
621
	$server['digest'] = $pconfig['step10']['digest'];
622
	$server['engine'] = $pconfig['step10']['engine'];
623

    
624
	if (isset($pconfig['step11']['ovpnrule'])) {
625
		$rule = array();
626
		$rule['descr'] = sprintf(gettext("OpenVPN %s wizard"),$server['description']);
627
		/* Ensure the rule descr is not too long for pf to handle */
628
		if (strlen($rule['descr']) > 52)
629
			$rule['descr'] = substr($rule['descr'], 0, 52);
630
		$rule['direction'] = "in";
631
		$rule['source']['any'] = TRUE;
632
		$rule['destination']['network'] = $server['interface'] . "ip";
633
		$rule['destination']['port'] = $server['local_port'];
634
		$rule['interface'] = $server['interface'];
635
		$rule['protocol'] = strtolower($server['protocol']);
636
		$rule['type'] = "pass";
637
		$rule['enabled'] = "on";
638
		$rule['created'] = make_config_revision_entry(null, gettext("OpenVPN Wizard"));
639
		$config['filter']['rule'][] = $rule;
640
	}
641
	if (isset($pconfig['step11']['ovpnallow'])) {
642
		$rule = array();
643
		$rule['descr'] = sprintf(gettext("OpenVPN %s wizard"),$server['description']);
644
		/* Ensure the rule descr is not too long for pf to handle */
645
		if (strlen($rule['descr']) > 52)
646
			$rule['descr'] = substr($rule['descr'], 0, 52);
647
		$rule['source']['any'] = TRUE;
648
		$rule['destination']['any'] = TRUE;
649
		$rule['interface'] = "openvpn";
650
		//$rule['protocol'] = $server['protocol'];
651
		$rule['type'] = "pass";
652
		$rule['enabled'] = "on";
653
		$rule['created'] = make_config_revision_entry(null, gettext("OpenVPN Wizard"));
654
		$config['filter']['rule'][] = $rule;
655
	}
656

    
657
	if (!is_array($config['openvpn']['openvpn-server']))
658
		$config['openvpn']['openvpn-server'] = array();
659

    
660
	$config['openvpn']['openvpn-server'][] = $server;
661

    
662
	openvpn_resync('server', $server);
663
	write_config();
664
	header("Location: vpn_openvpn_server.php");
665
	exit;
666
}
667

    
668
?>
(1-1/7)