Project

General

Profile

Download (22.5 KB) Statistics
| Branch: | Tag: | Revision:
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 ereg('[^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
		$stepid++;
181
	} else {
182
		$config['ovpnserver']['step6']['uselist'] = "on";
183
		$_POST['uselist'] = "on";
184
	}
185
}
186

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

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

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

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

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

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

    
233
	if (isset($_POST['next'])) {
234
		$_POST['uselist'] = "";
235
		$stepid++;
236
	}
237
}
238

    
239
function step9_stepbeforeformdisplay() {
240
	global $config, $pkg, $stepid;
241

    
242
	$pconfig = $config['ovpnserver'];
243

    
244
	if (isset($pconfig['step6']['uselist'])) {
245
		$country = $pconfig['step6']['country'];
246
		$state = $pconfig['step6']['state'];
247
		$city = $pconfig['step6']['city'];
248
		$org = $pconfig['step6']['organization'];
249
	} else {
250
		$ca = lookup_ca($pconfig['step6']['authcertca']);
251
		$cavl = cert_get_subject_array($ca['crt']);
252
		$country = $cavl[0]['v'];
253
		$state = $cavl[1]['v'];
254
		$city = $cavl[2]['v'];
255
		$org = $cavl[3]['v'];
256
	}
257
	$fields =& $pkg['step'][$stepid]['fields']['field'];
258

    
259
	foreach ($fields as $idx => $field) {
260
		switch ($field['name']) {
261
		case 'country':
262
			$fields[$idx]['value'] = $country;
263
			break;
264
		case 'state':
265
			$fields[$idx]['value'] = $state;
266
			break;
267
		case 'city':
268
			$fields[$idx]['value'] = $city;
269
			break;
270
		case 'organization':
271
			$fields[$idx]['value'] = $org;
272
			break;
273
		}
274
	}
275
}
276

    
277
function step9_submitphpaction() {
278
	global $input_errors, $stepid, $savemsg, $_POST, $config;
279

    
280
	$certnames = array();
281
	$certcns = array();
282
	if (is_array($config['cert'])) {
283
		foreach($config['cert'] as $cert) {
284
			$certnames[] = $cert['descr'];
285
			$certinfo = cert_get_subject_hash($cert['crt']);
286
			$certcns[] = $certinfo["CN"];
287
		}	
288
	}
289

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

    
311
function step10_stepbeforeformdisplay() {
312
	global $pkg, $stepid, $netbios_nodetypes;
313

    
314
	foreach ($pkg['step'][$stepid]['fields']['field'] as $idx => $field) {
315
		if ($field['name'] == "crypto") {
316
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'] = array();
317
			$cipherlist = openvpn_get_cipherlist();
318
			foreach ($cipherlist as $name => $desc) {
319
				$opt = array();
320
				$opt['name'] = $desc;
321
				$opt['value'] = $name;
322
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'][] = $opt;
323
			}
324
		} else if ($field['name'] == "engine") {
325
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'] = array();
326
			$engines = openvpn_get_engines();
327
			foreach ($engines as $name => $desc) {
328
				$opt = array();
329
				$opt['name'] = $desc;
330
				$opt['value'] = $name;
331
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'][] = $opt;
332
			}
333
		} else if ($field['name'] == "nbttype") {
334
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'] = array();
335
			foreach ($netbios_nodetypes as $type => $name) {
336
				$opt = array();
337
				$opt['name'] = $name;
338
				$opt['value'] = $type;
339
			$pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'][] = $opt;
340
			}
341
		} else if ($field['name'] == "localport") {
342
			$pkg['step'][$stepid]['fields']['field'][$idx]['value'] = openvpn_port_next('UDP');
343
		}
344
	}
345
}
346

    
347
function step10_submitphpaction() {
348
	global $savemsg, $stepid;
349

    
350
	/* Default OpenVPN port to next available port if left empty. */
351
	if (empty($_POST['localport']))
352
		$pconfig["step10"]["localport"] = openvpn_port_next('UDP');
353

    
354
	/* input validation */
355
	if ($result = openvpn_validate_port($_POST['localport'], 'Local port'))
356
		$input_errors[] = $result;
357

    
358
	if ($result = openvpn_validate_cidr($_POST['tunnelnet'], 'Tunnel network'))
359
		$input_errors[] = $result;
360

    
361
	if ($result = openvpn_validate_cidr($_POST['localnet'], 'Local network'))
362
		$input_errors[] = $result;
363

    
364
	$portused = openvpn_port_used($_POST['protocol'], $_POST['localport']);
365
	if ($portused != 0)
366
		$input_errors[] = "The specified 'Local port' is in use. Please select another value";
367

    
368
	if (!isset($_POST['generatetlskey']) && isset($_POST['tlsauthentication']))
369
		if (!strstr($_POST['tlssharedkey'], "-----BEGIN OpenVPN Static key V1-----") ||
370
			!strstr($_POST['tlssharedkey'], "-----END OpenVPN Static key V1-----"))
371
			$input_errors[] = "The field 'TLS Authentication Key' does not appear to be valid";
372

    
373
	if (!empty($_POST['dnsserver1']) && !is_ipaddr(trim($_POST['dnsserver1'])))
374
		$input_errors[] = "The field 'DNS Server #1' must contain a valid IP address";
375
	if (!empty($_POST['dnsserver2']) && !is_ipaddr(trim($_POST['dnsserver2'])))
376
		$input_errors[] = "The field 'DNS Server #2' must contain a valid IP address";
377
	if (!empty($_POST['dnsserver3']) && !is_ipaddr(trim($_POST['dnsserver3'])))
378
		$input_errors[] = "The field 'DNS Server #3' must contain a valid IP address";
379
	if (!empty($_POST['dnsserver4']) && !is_ipaddr(trim($_POST['dnsserver4'])))
380
		$input_errors[] = "The field 'DNS Server #4' must contain a valid IP address";
381

    
382
	if (!empty($_POST['ntpserver1']) && !is_ipaddr(trim($_POST['ntpserver1'])))
383
		$input_errors[] = "The field 'NTP Server #1' must contain a valid IP address";
384
	if (!empty($_POST['ntpserver2']) && !is_ipaddr(trim($_POST['ntpserver2'])))
385
		$input_errors[] = "The field 'NTP Server #2' must contain a valid IP address";
386

    
387
	if (!empty($_POST['winsserver1']) && !is_ipaddr(trim($_POST['winsserver1'])))
388
		$input_errors[] = "The field 'WINS Server #1' must contain a valid IP address";
389
	if (!empty($_POST['winsserver2']) && !is_ipaddr(trim($_POST['winsserver2'])))
390
		$input_errors[] = "The field 'WINS Server #2' must contain a valid IP address";
391

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

    
395
	if (empty($_POST['tunnelnet']))
396
		$input_errors[] = "You must specify a 'Tunnel network'.";
397

    
398
	if (count($input_errors) > 0) {
399
		$savemsg = $input_errors[0];
400
		$stepid = $stepid - 1;
401
	}
402
}
403

    
404
function step12_submitphpaction() {
405
	global $config;
406

    
407
	$pconfig = $config['ovpnserver'];
408

    
409
	if (!is_array($config['ovpnserver'])) {
410
		$message = "No configuration found please retry again.";
411
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=1&message={$message}");
412
		exit;
413
	}
414

    
415
	if ($pconfig['step1']['type'] == "local") {
416
		$auth = array();
417
		$auth['name'] = "Local Database";
418
		$auth['type'] = "local";
419
	} else if (isset($pconfig['step2']['uselist'])) {
420
		$auth = array();
421
		$auth['type'] = $pconfig['step1']['type'];
422
		$auth['refid'] = uniqid();
423
		$auth['name'] = $pconfig['step2']['authtype'];
424

    
425
		if ($auth['type'] == "ldap") {
426
			$auth['host'] = $pconfig['step2']['ip'];
427
			$auth['ldap_port'] = $pconfig['step2']['port'];
428
			if ($pconfig['step1']['transport'] == "tcp")
429
				$auth['ldap_urltype'] = 'TCP - Standard';
430
			else
431
				$auth['ldap_urltype'] = 'SSL - Encrypted';
432
			$auth['ldap_protver'] = 3;
433
			$auth['ldap_scope'] = $pconfig['step2']['scope'];
434
			$auth['ldap_basedn'] = $pconfig['step2']['basedn'];
435
			$auth['ldap_authcn'] = $pconfig['step2']['authscope'];
436
			$auth['ldap_binddn'] = $pconfig['step2']['userdn'];
437
			$auth['ldap_bindpw'] = $pconfig['step2']['passdn'];
438
			$auth['ldap_attr_user'] = $pconfig['step1']['nameattr'];
439
			$auth['ldap_attr_member'] = $pconfig['step1']['memberattr'];
440
			$auth['ldap_attr_group'] = $pconfig['step1']['groupattr'];
441
		} else if ($auth['type'] == "radius") {
442
			$auth['host'] = $pconfig['step2']['ip'];
443
			$auth['radius_auth_port'] = $pconfig['step2']['port'];
444
			$auth['radius_secret'] = $pconfig['step2']['password'];
445
			$auth['radius_srvcs'] = "auth";
446
		}
447
		if (!is_array($config['system']['authserver']))
448
			$config['system']['authserver'] = array();
449

    
450
		$config['system']['authserver'][] = $auth;
451
	} else if (!isset($pconfig['step2']['uselist']) && empty($pconfig['step2']['authserv'])) {
452
		$message = "Please choose an authentication server .";
453
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=1&message={$message}");
454
		exit;
455
	} else if (!($auth = auth_get_authserver($pconfig['step2']['authserv']))) {
456
		$message = "Not a valid authentication server has been specified.";
457
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=1&message={$message}");
458
		exit;
459
	}
460

    
461
	if (isset($pconfig['step6']['uselist']) && !empty($pconfig['step6']['certca'])) {
462
		$ca = array();
463
		$ca['refid'] = uniqid();
464
		$ca['descr'] = $pconfig['step6']['certca'];
465
		$dn = array(
466
			'countryName' => $pconfig['step6']['country'],
467
			'stateOrProvinceName' => $pconfig['step6']['state'],
468
			'localityName' => $pconfig['step6']['city'],
469
			'organizationName' => $pconfig['step6']['organization'],
470
			'emailAddress' => $pconfig['step6']['email'],
471
			'commonName' => $pconfig['step6']['certca']);
472

    
473
		ca_create($ca, $pconfig['step6']['keylength'], $pconfig['step6']['lifetime'], $dn);
474
		if (!is_array($config['ca']))
475
			$config['ca'] = array();
476

    
477
		$config['ca'][] = $ca;
478
	} else if (!isset($pconfig['step6']['uselist']) && empty($pconfig['step6']['authcertca'])) {
479
		$message = "Please choose a Certificate Authority.";
480
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=5&message={$message}");
481
		exit;
482
	} else if (!($ca = lookup_ca($pconfig['step6']['authcertca']))) {
483
		$message = "Not a valid Certificate Authority specified.";
484
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=5&message={$message}");
485
		exit;
486
	}
487

    
488
	if (isset($pconfig['step9']['uselist'])) {
489
		$cert = array();
490
		$cert['refid'] = uniqid();
491
		$cert['descr'] = $pconfig['step9']['certname'];
492
		$dn = array(
493
			'countryName' => $pconfig['step9']['country'],
494
			'stateOrProvinceName' => $pconfig['step9']['state'],
495
			'localityName' => $pconfig['step9']['city'],
496
			'organizationName' => $pconfig['step9']['organization'],
497
			'emailAddress' => $pconfig['step9']['email'],
498
			'commonName' => $pconfig['step9']['certname']);
499

    
500
		cert_create($cert, $ca['refid'], $pconfig['step9']['keylength'], $pconfig['step9']['lifetime'], $dn);
501
		if (!is_array($config['cert']))
502
			$config['cert'] = array();
503

    
504
		$config['cert'][] = $cert;
505
	} else if (!isset($pconfig['step6']['uselist']) && empty($pconfig['step9']['authcertname'])) {
506
		$message = "Please choose a Certificate.";
507
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=7&message={$message}");
508
		exit;
509
	} else if (!($cert = lookup_cert($pconfig['step9']['authcertname']))) {
510
		$message = "Not a valid Certificate specified.";
511
		header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=7&message={$message}");
512
		exit;
513
	}
514
	$server = array();
515
	$server['vpnid'] = openvpn_vpnid_next();
516
	switch ($auth['type']) {
517
		case "ldap":
518
			$server['authmode'] = $auth['name'];
519
			$server['mode'] = "server_user";
520
			break;
521
		case "radius":
522
			$server['authmode'] = $auth['name'];
523
			$server['mode'] = "server_user";
524
			break;
525
		default:
526
			$server['authmode'] = "Local Database";
527
			$server['mode'] = "server_tls_user";
528
			break;
529
	}
530
	$server['caref'] = $ca['refid'];
531
	$server['certref'] = $cert['refid'];
532
	$server['protocol'] = $pconfig['step10']['protocol'];
533
	$server['interface'] = $pconfig['step10']['interface'];
534
	if (isset($pconfig['step10']['localport']))
535
		$server['local_port'] = $pconfig['step10']['localport'];
536

    
537
	if (strlen($pconfig['step10']['descr']) > 30)
538
		$pconfig['step10']['descr'] = substr($pconfig['step10']['descr'], 0, 30);
539
	$server['description'] = $pconfig['step10']['descr'];
540
	$server['custom_options'] = $pconfig['step10']['advanced'];
541
	if (isset($pconfig['step10']['tlsauth'])) {
542
		if (isset($pconfig['step10']['gentlskey']))
543
			$tlskey = openvpn_create_key();
544
		else
545
			$tlskey = $pconfig['step10']['tlskey'];
546
		$server['tls'] = base64_encode($tlskey);
547
	}
548
	$server['dh_length'] = $pconfig['step10']['dhkey'];
549
	$server['tunnel_network'] = $pconfig['step10']['tunnelnet'];
550
	if (isset($pconfig['step10']['rdrgw']))
551
		$server['gwredir'] = $pconfig['step10']['rdrgw'];
552
	if (isset($pconfig['step10']['localnet']))
553
		$server['local_network'] = $pconfig['step10']['localnet'];
554
	if (isset($pconfig['step10']['concurrentcon']))
555
		$server['maxclients'] = $pconfig['step10']['concurrentcon'];
556
	if (isset($pconfig['step10']['compression']))
557
		$server['compression'] = $pconfig['step10']['compression'];
558
	if (isset($pconfig['step10']['tos']))
559
		$server['passtos'] = $pconfig['step10']['tos'];
560
	if (isset($pconfig['step10']['interclient']))
561
		$server['client2client'] = $pconfig['step10']['interclient'];
562
	if (isset($pconfig['step10']['duplicate_cn']))
563
		$server['duplicate_cn'] = $pconfig['step10']['duplicate_cn'];
564
	if (isset($pconfig['step10']['dynip']))
565
		$server['dynamic_ip'] = $pconfig['step10']['dynip'];
566
	if (isset($pconfig['step10']['addrpool']))
567
		$server['pool_enable'] = $pconfig['step10']['addrpool'];
568
	if (isset($pconfig['step10']['defaultdomain']))
569
		$server['dns_domain'] = $pconfig['step10']['defaultdomain'];
570
	if (isset($pconfig['step10']['dns1']))
571
		$server['dns_server1'] = $pconfig['step10']['dns1'];
572
	if (isset($pconfig['step10']['dns2']))
573
		$server['dns_server2'] = $pconfig['step10']['dns2'];
574
	if (isset($pconfig['step10']['dns3']))
575
		$server['dns_server3'] = $pconfig['step10']['dns3'];
576
	if (isset($pconfig['step10']['dns4']))
577
		$server['dns_server4'] = $pconfig['step10']['dns4'];
578
	if (isset($pconfig['step10']['ntp1']))
579
		$server['ntp_server1'] = $pconfig['step10']['ntp1'];
580
	if (isset($pconfig['step10']['ntp2']))
581
		$server['ntp_server2'] = $pconfig['step10']['ntp2'];
582
	if (isset($pconfig['step10']['wins1']))
583
		$server['wins_server1'] = $pconfig['step10']['wins1'];
584
	if (isset($pconfig['step10']['wins2']))
585
		$server['wins_server2'] = $pconfig['step10']['wins2'];
586
	if (isset($pconfig['step10']['nbtenable'])) {
587
		$server['netbios_ntype'] = $pconfig['step10']['nbttype'];
588
		if (isset($pconfig['step10']['nbtscope']))
589
			$server['netbios_scope'] = $pconfig['step10']['nbtscope'];
590
		$server['netbios_enable'] = $pconfig['step10']['nbtenable'];
591
	}
592
	$server['crypto'] = $pconfig['step10']['crypto'];
593
	$server['engine'] = $pconfig['step10']['engine'];
594

    
595
	if (isset($pconfig['step11']['ovpnrule'])) {
596
		$rule = array();
597
		$rule['descr'] = gettext("OpenVPN {$server['description']} wizard");
598
		/* Ensure the rule descr is not too long for pf to handle */
599
		if (strlen($rule['descr']) > 52)
600
			$rule['descr'] = substr($rule['descr'], 0, 52);
601
		$rule['direction'] = "in";
602
		$rule['source']['any'] = TRUE;
603
		$rule['destination']['network'] = $server['interface'] . "ip";
604
		$rule['destination']['port'] = $server['local_port'];
605
		$rule['interface'] = $server['interface'];
606
		$rule['protocol'] = strtolower($server['protocol']);
607
		$rule['type'] = "pass";
608
		$rule['enabled'] = "on";
609
		$config['filter']['rule'][] = $rule;
610
	}
611
	if (isset($pconfig['step11']['ovpnallow'])) {
612
		$rule = array();
613
		$rule['descr'] = gettext("OpenVPN {$server['description']} wizard");
614
		/* Ensure the rule descr is not too long for pf to handle */
615
		if (strlen($rule['descr']) > 52)
616
			$rule['descr'] = substr($rule['descr'], 0, 52);
617
		$rule['source']['any'] = TRUE;
618
		$rule['destination']['any'] = TRUE;
619
		$rule['interface'] = "openvpn";
620
		//$rule['protocol'] = $server['protocol'];
621
		$rule['type'] = "pass";
622
		$rule['enabled'] = "on";
623
		$config['filter']['rule'][] = $rule;
624
	}
625

    
626
	if (!is_array($config['openvpn']['openvpn-server']))
627
		$config['openvpn']['openvpn-server'] = array();
628

    
629
	$config['openvpn']['openvpn-server'][] = $server;
630

    
631
	openvpn_resync('server', $server);
632
	write_config();
633
	header("Location: vpn_openvpn_server.php");
634
	exit;
635
}
636

    
637
?>
(1-1/11)