Project

General

Profile

Download (18.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
require_once("openvpn.inc");
3

    
4
function step1_submitphpaction() {
5
	global $stepid, $config;
6
	if ($_POST['authtype'] == "local") {
7
		$stepid = 5;
8
		$config['ovpnserver']['step1']['type'] = "local";
9
	} else if ($_POST['authtype'] == "ldap") {
10
		$stepid = 0;
11
	} else if ($_POST['authtype'] == "radius") {
12
		$stepid = 2;
13
		$config['ovpnserver']['step1']['type'] = "radius";
14
		unset($config['ovpnserver']['step1']['uselist']);
15
	}
16
}
17

    
18
function step2_stepbeforeformdisplay() {
19
	global $pkg, $stepid;
20

    
21
	$fields =& $pkg['step'][1]['fields']['field'];
22
	
23
	$found = false;
24
	$authlist = auth_get_authserver_list();
25
	$fields[1]['options']['option'] = array();
26
	foreach ($authlist as $i => $auth) {
27
		if ($auth['type'] != "ldap")
28
			continue;
29
		$found = true;
30
               	$opts = array();
31
               	$opts['name'] = $auth['name'];
32
               	$opts['value'] = $auth['name'];
33
               	$fields[1]['options']['option'][] = $opts;
34
	}
35
	if ($found == false) {
36
                $stepid = 2;
37
	}
38
}
39

    
40
function step2_submitphpaction() {
41
	global $stepid;
42

    
43
	if (isset($_POST['next'])) {
44
		$_POST['uselist'] = "";
45
		$stepid++;
46
	}
47
}
48

    
49
function step3_submitphpaction() {
50
	global $stepid, $savemsg, $config;
51

    
52
	if (empty($_POST['name']) || empty($_POST['ip']) || empty($_POST['port']) ||
53
	    empty($_POST['transport']) || empty($_POST['scope']) || empty($_POST['authscope']) || empty($_POST['nameattr'])) {
54
		$stepid--;
55
		$savemsg = "Please enter all information for authentication server.";
56
	} else if (count(($authcfg = auth_get_authserver($_POST['name']))) > 0) {
57
		$stepid--;
58
		$savemsg = "Please choose a different name because an authentication server with this name already exists.";
59
	} else {
60
		$config['ovpnserver']['step2']['uselist'] = "on";
61
		$_POST['uselist'] = "on";
62
		$stepid += 2;
63
	}
64
}
65

    
66
function step4_stepbeforeformdisplay() {
67
        global $pkg, $stepid;
68

    
69
        $fields =& $pkg['step'][3]['fields']['field'];
70

    
71
	$found = false;
72
        $authlist = auth_get_authserver_list();
73
       	$fields[1]['options']['option'] = array();
74
       	foreach ($authlist as $i => $auth) {
75
               	if ($auth['type'] != "radius")
76
                       	continue;
77
		$found = true;
78
               	$opts = array();
79
               	$opts['name'] = $auth['name'];
80
               	$opts['value'] = $auth['name'];
81
               	$fields[1]['options']['option'][] = $opts;
82
        }
83
	if ($found == false)
84
                $stepid = 4;
85
}
86

    
87
function step4_submitphpaction() {
88
        global $stepid;
89

    
90
	if (isset($_POST['next'])) {
91
                $_POST['uselist'] = "";
92
                $stepid++;
93
        }
94
}
95

    
96
function step5_submitphpaction() {
97
	global $stepid, $savemsg, $config;
98

    
99
        if (empty($_POST['name']) || empty($_POST['ip']) || empty($_POST['port']) ||
100
            empty($_POST['secret'])) {
101
		$stepid--;
102
                $savemsg = "Please enter all information for authentication server.";
103
	} else if (count(($authcfg = auth_get_authserver($_POST['name']))) > 0) {
104
		$stepid--;
105
		$savemsg = "Please choose a different name because an authentication server with this name already exists.";
106
        } else {
107
		$config['ovpnserver']['step2']['uselist'] = "on";
108
		$_POST['uselist'] = "on";
109
	}
110
}
111

    
112
function step6_stepbeforeformdisplay() {
113
	global $stepid, $config;
114

    
115
	if (count($config['system']['ca']) < 1) {
116
		$stepid++;
117
	}
118
}
119

    
120
function step6_submitphpaction() {
121
	global $stepid, $config;
122

    
123
	if (isset($_POST['next'])) {
124
                $_POST['uselist'] = "";
125
                $stepid++;
126
        } else {
127
		$config['ovpnserver']['step6']['uselist'] = "on";
128
                $_POST['uselist'] = "on";
129
	}
130
}
131

    
132
function step7_submitphpaction() {
133
	global $stepid, $savemsg, $_POST, $config;
134

    
135
	if (empty($_POST['name']) || empty($_POST['keylength']) || empty($_POST['lifetime']) ||
136
            empty($_POST['country']) || empty($_POST['state']) || empty($_POST['city']) ||
137
            empty($_POST['organization']) || empty($_POST['email']) || empty($_POST['cn'])) {
138
		$stepid--;
139
                $savemsg = "Please enter all information for the new CA authority.";
140
        } else {
141
		$config['ovpnserver']['step7']['uselist'] = "on";
142
		$_POST['uselist'] = "on";
143
	}
144
}
145

    
146
function step8_stepbeforeformdisplay() {
147
        global $stepid, $config;
148

    
149
        if (count($config['system']['cert']) < 1 ||
150
		(count($config['system']['cert']) == 1 && stristr($config['system']['cert'][0]['name'], "webconf"))) {
151
		$stepid++;
152
        }
153
}
154

    
155
function step8_submitphpaction() {
156
	global $stepid, $_POST;
157

    
158
	if (isset($_POST['next'])) {
159
                $_POST['uselist'] = "";
160
                $stepid++;
161
        }
162
}
163

    
164
function step9_submitphpaction() {
165
	global $stepid, $savemsg, $_POST, $config;
166

    
167
        if (empty($_POST['name']) || empty($_POST['keylength']) || empty($_POST['lifetime']) ||
168
	    empty($_POST['country']) || empty($_POST['state']) || empty($_POST['city']) ||
169
	    empty($_POST['organization']) || empty($_POST['email']) || empty($_POST['cn'])) {
170
		$stepid--;
171
                $savemsg = "Please enter all information for the new certificate.";
172
        } else {
173
		$config['ovpnserver']['step9']['uselist'] = "on";
174
		$_POST['uselist'] = "on";
175
	}
176
}
177

    
178
function step10_stepbeforeformdisplay() {
179
	global $pkg, $stepid, $netbios_nodetypes;
180

    
181
	foreach ($pkg['step'][$stepid]['fields']['field'] as $idx => $field) {
182
		if ($field['name'] == "crypto") {
183
                        $pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'] = array();
184
			$cipherlist = openvpn_get_cipherlist();
185
			foreach ($cipherlist as $name => $desc)
186
				$opt = array();
187
                                $opt['name'] = $desc;
188
                                $opt['value'] = $name;
189
                        $pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'][] = $opt;
190
		} else if ($field['name'] == "nbttype") {
191
                        $pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'] = array();
192
			foreach ($netbios_nodetypes as $type => $name) {
193
				$opt = array();
194
				$opt['name'] = $name;
195
				$opt['value'] = $type;
196
                        $pkg['step'][$stepid]['fields']['field'][$idx]['options']['option'][] = $opt;
197
			}
198
		}
199
	}
200
}
201

    
202
function step10_submitphpaction() {
203
	global $savemsg, $stepid;
204

    
205
	/* input validation */
206
        if ($result = openvpn_validate_port($_POST['localport'], 'Local port'))
207
                $input_errors[] = $result;
208

    
209
        if ($result = openvpn_validate_cidr($_POST['tunnelnet'], 'Tunnel network'))
210
                $input_errors[] = $result;
211

    
212
        if ($result = openvpn_validate_cidr($_POST['remotenet'], 'Remote network'))
213
                $input_errors[] = $result;
214

    
215
        if ($result = openvpn_validate_cidr($_POST['localnet'], 'Local network'))
216
                $input_errors[] = $result;
217

    
218
	$portused = openvpn_port_used($_POST['protocol'], $_POST['localport']);
219
	if ($portused != 0)
220
                $input_errors[] = "The specified 'Local port' is in use. Please select another value";
221
	
222
	if (!isset($_POST['generatetlskey']) && isset($_POST['tlsauthentication']))
223
		if (!strstr($_POST['tlssharedkey'], "-----BEGIN OpenVPN Static key V1-----") ||
224
			!strstr($_POST['tlssharedkey'], "-----END OpenVPN Static key V1-----"))
225
                        $input_errors[] = "The field 'TLS Authentication Key' does not appear to be valid";
226

    
227
	if (!empty($_POST['dnsserver1']) && !is_ipaddr(trim($_POST['dnsserver1'])))
228
		$input_errors[] = "The field 'DNS Server #1' must contain a valid IP address";
229
	if (!empty($_POST['dnsserver2']) && !is_ipaddr(trim($_POST['dnsserver2'])))
230
		$input_errors[] = "The field 'DNS Server #2' must contain a valid IP address";
231
	if (!empty($_POST['dnsserver3']) && !is_ipaddr(trim($_POST['dnsserver3'])))
232
		$input_errors[] = "The field 'DNS Server #3' must contain a valid IP address";
233
	if (!empty($_POST['dnsserver4']) && !is_ipaddr(trim($_POST['dnsserver4'])))
234
		$input_errors[] = "The field 'DNS Server #4' must contain a valid IP address";
235

    
236
	if (!empty($_POST['ntpserver1']) && !is_ipaddr(trim($_POST['ntpserver1'])))
237
		$input_errors[] = "The field 'NTP Server #1' must contain a valid IP address";
238
	if (!empty($_POST['ntpserver2']) && !is_ipaddr(trim($_POST['ntpserver2'])))
239
		$input_errors[] = "The field 'NTP Server #2' must contain a valid IP address";
240

    
241
	if (!empty($_POST['winsserver1']) && !is_ipaddr(trim($_POST['winsserver1'])))
242
		$input_errors[] = "The field 'WINS Server #1' must contain a valid IP address";
243
	if (!empty($_POST['winsserver2']) && !is_ipaddr(trim($_POST['winsserver2'])))
244
		$input_errors[] = "The field 'WINS Server #2' must contain a valid IP address";
245

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

    
249
	if (empty($_POST['tunnelnet']))
250
		$input_errors[] = "You must specify a 'Tunnel network'.";
251

    
252
	if (count($input_errors) > 0) {
253
		$savemsg = $input_errors[0];
254
		$stepid = $stepid - 1;
255
	}
256
}
257

    
258
function step12_submitphpaction() {
259
	global $config;
260

    
261
	$pconfig = $config['ovpnserver'];
262

    
263
	if (!is_array($config['ovpnserver'])) {
264
		$message = "No configuration found please retry again.";
265
                header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=1&message={$message}");
266
                exit;
267
	}
268

    
269
	if ($pconfig['step1']['type'] == "local") {
270
		$auth = array();
271
		$auth['name'] = "Local Database";
272
		$auth['type'] = "local";
273
	} else if (isset($pconfig['step2']['uselist'])) {
274
		$auth = array();
275
		$auth['type'] = $pconfig['step1']['type'];
276
		$auth['refid'] = uniqid();
277
		$auth['name'] = $pconfig['step2']['authtype'];
278
		
279
		if ($auth['type'] == "ldap") {
280
			$auth['host'] = $pconfig['step2']['ip'];
281
			$auth['ldap_port'] = $pconfig['step2']['port'];
282
			if ($pconfig['step1']['transport'] == "tcp")
283
				$auth['ldap_urltype'] = 'TCP - Standard';
284
			else
285
				$auth['ldap_urltype'] = 'SSL - Encrypted';
286
			$auth['ldap_protver'] = 3;
287
			$auth['ldap_scope'] = $pconfig['step2']['scope'];
288
			$auth['ldap_authcn'] = $pconfig['step2']['authscope'];
289
			$auth['ldap_binddn'] = $pconfig['step2']['userdn'];
290
			$auth['ldap_bindpw'] = $pconfig['step2']['passdn'];
291
			$auth['ldap_attr_user'] = $pconfig['step1']['nameattr'];
292
			$auth['ldap_attr_member'] = $pconfig['step1']['memberattr'];
293
			$auth['ldap_attr_group'] = $pconfig['step1']['groupattr'];
294
		} else if ($auth['type'] == "radius") {
295
			$auth['host'] = $pconfig['step2']['ip'];
296
			$auth['radius_auth_port'] = $pconfig['step2']['port'];
297
			$auth['radius_secret'] = $pconfig['step2']['password'];
298
			$auth['radius_srvcs'] = "auth";
299
		}
300
		if (!is_array($config['system']['authserver']))
301
			$config['system']['authserver'] = array();
302

    
303
		$config['system']['authserver'][] = $auth;
304
	} else if (!isset($pconfig['step2']['uselist']) && empty($pconfig['step2']['authserv'])) {
305
		$message = "Please choose an authentication server .";
306
                header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=1&message={$message}");
307
                exit;
308
	} else if (!($auth = auth_get_authserver($pconfig['step2']['authserv']))) {
309
		$message = "Not a valid authentication server has been specified.";
310
                header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=1&message={$message}");
311
                exit;
312
	}
313

    
314
	if (isset($pconfig['step6']['uselist'])) {
315
		$ca = array();
316
		$ca['refid'] = uniqid();
317
		$ca['name'] = $pconfig['step6']['certname'];
318
		$dn = array(
319
			'countryName' => $pconfig['step6']['country'],
320
			'stateOrProvinceName' => $pconfig['step6']['state'],
321
			'localityName' => $pconfig['step6']['city'],
322
			'organizationName' => $pconfig['step6']['organization'],
323
			'emailAddress' => $pconfig['step6']['email'],
324
			'commonName' => $pconfig['step6']['cn']);
325

    
326
		ca_create($ca, $pconfig['step6']['keylength'], $pconfig['step6']['lifetime'], $dn);
327
		if (!is_array($config['system']['ca']))
328
			$config['system']['ca'] = array();
329

    
330
		$config['system']['ca'][] = $ca;
331
	} else if (!isset($pconfig['step6']['uselist']) && empty($pconfig['step6']['authcertca'])) {
332
		$message = "Please choose a CA authority.";
333
                header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=5&message={$message}");
334
                exit;
335
	} else if (!($ca = lookup_ca($pconfig['step6']['authcertca']))) {
336
		$message = "Not a valid CA authority specified.";
337
                header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=5&message={$message}");
338
                exit;
339
	}
340

    
341
	if (isset($pconfig['step9']['uselist'])) {
342
                $cert = array();
343
                $cert['refid'] = uniqid();
344
                $cert['name'] = $pconfig['step9']['certname'];
345
                $dn = array(
346
                        'countryName' => $pconfig['step9']['country'],
347
                        'stateOrProvinceName' => $pconfig['step9']['state'],
348
                        'localityName' => $pconfig['step9']['city'],
349
                        'organizationName' => $pconfig['step9']['organization'],
350
                        'emailAddress' => $pconfig['step9']['email'],
351
                        'commonName' => $pconfig['step9']['cn']);
352

    
353
                cert_create($cert, $ca['refid'], $pconfig['step9']['keylength'], $pconfig['step9']['lifetime'], $dn);
354
                if (!is_array($config['system']['cert']))
355
                        $config['system']['cert'] = array();
356

    
357
                $config['system']['cert'][] = $cert;
358
	} else if (!isset($pconfig['step6']['uselist']) && empty($pconfig['step9']['authcertname'])) {
359
		$message = "Please choose a Certificate.";
360
                header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=7&message={$message}");
361
                exit;
362
	} else if (!($cert = lookup_cert($pconfig['step9']['authcertname']))) {
363
                $message = "Not a valid Certificate specified.";
364
                header("Location:wizard.php?xml=openvpn_wizard.xml&stepid=7&message={$message}");
365
                exit;
366
        }
367
	$server = array();
368
	$server['vpnid'] = openvpn_vpnid_next();
369
	switch ($auth['type']) {
370
		case "ldap":
371
                	$server['authmode'] = $auth['name'];
372
                        $server['mode'] = "server_user";
373
                        break;
374
                case "radius":
375
                        $server['authmode'] = $auth['name'];
376
                        $server['mode'] = "server_user";
377
                        break;
378
                default:
379
                        $server['authmode'] = "Local Database";
380
                        $server['mode'] = "server_tls_user";
381
                        break;
382
	}
383
	$server['caref'] = $ca['refid'];
384
	$server['certref'] = $cert['refid'];
385
	$server['protocol'] = $pconfig['step10']['protocol'];
386
	$server['interface'] = $pconfig['step10']['interface'];
387
	if (isset($pconfig['step10']['localport']))
388
		$server['local_port'] = $pconfig['step10']['localport'];
389
	$server['description'] = $pconfig['step10']['descr'];
390
	$server['custom_options'] = $pconfig['step10']['advanced'];
391
	if (isset($pconfig['step10']['tlsauth'])) {
392
		if (isset($pconfig['step10']['gentlskey']))
393
			$tlskey = openvpn_create_key();
394
		else
395
			$tlskey = $pconfig['step10']['tlskey'];
396
		$server['tls'] = base64_encode($tlskey);
397
	}
398
	$server['dh_length'] = $pconfig['step10']['dhkey'];
399
	$server['tunnel_network'] = $pconfig['step10']['tunnelnet'];
400
	if (isset($pconfig['step10']['rdrgw']))
401
		$server['gwredir'] = $pconfig['step10']['rdrgw'];
402
	if (isset($pconfig['step10']['localnet']))
403
		$server['local_network'] = $pconfig['step10']['localnet'];
404
	if (isset($pconfig['step10']['remotenet']))
405
		$server['remote_network'] = $pconfig['step10']['remotenet'];
406
	if (isset($pconfig['step10']['concurrentcon']))
407
		$server['maxclients'] = $pconfig['step10']['concurrentcon'];
408
	if (isset($pconfig['step10']['compression']))
409
		$server['compression'] = $pconfig['step10']['compression'];
410
	if (isset($pconfig['step10']['tos']))
411
		$server['passtos'] = $pconfig['step10']['tos'];
412
	if (isset($pconfig['step10']['interclient']))
413
		$server['client2client'] = $pconfig['step10']['interclient'];
414
	if (isset($pconfig['step10']['addrpool']))
415
		$server['pool_enable'] = $pconfig['step10']['addrpool'];
416
	if (isset($pconfig['step10']['defaultdomain']))
417
		$server['dns_domain'] = $pconfig['step10']['defaultdomain'];
418
	if (isset($pconfig['step10']['dns1']))
419
		$server['dns_server1'] = $pconfig['step10']['dns1'];
420
	if (isset($pconfig['step10']['dns2']))
421
		$server['dns_server2'] = $pconfig['step10']['dns2'];
422
	if (isset($pconfig['step10']['dns3']))
423
		$server['dns_server3'] = $pconfig['step10']['dns3'];
424
	if (isset($pconfig['step10']['dns4']))
425
		$server['dns_server4'] = $pconfig['step10']['dns4'];
426
	if (isset($pconfig['step10']['ntp1']))
427
		$server['ntp_server1'] = $pconfig['step10']['ntp1'];
428
	if (isset($pconfig['step10']['ntp2']))
429
		$server['ntp_server2'] = $pconfig['step10']['ntp2'];
430
	if (isset($pconfig['step10']['wins1']))
431
		$server['wins_server1'] = $pconfig['step10']['wins1'];
432
	if (isset($pconfig['step10']['wins2']))
433
		$server['wins_server2'] = $pconfig['step10']['wins2'];
434
	if (isset($pconfig['step10']['nbtenable'])) {
435
		$server['netbios_ntype'] = $pconfig['step10']['nbttype'];
436
		if (isset($pconfig['step10']['nbtscope']))
437
			$server['netbios_scope'] = $pconfig['step10']['nbtscope'];
438
		$server['netbios_enable'] = $pconfig['step10']['nbtenable'];
439
	}
440
	$server['crypto'] = $pconfig['step10']['crypto'];
441

    
442
	if (isset($pconfig['step11']['ovpnrule'])) {
443
		$rule = array();
444
		$rule['descr'] = gettext("OpenVPN {$server['description']} wizard rules.");
445
		$rule['direction'] = "in";
446
		$rule['source']['any'] = TRUE;
447
		$rule['source']['address']['any'] = TRUE;
448
		$rule['destination']['network'] = $server['interface'] . "ip";
449
		$rule['destination']['port'] = $server['local_port'];
450
		$rule['interface'] = $server['interface'];
451
		$rule['protocol'] = $server['protocol'];
452
		$rule['type'] = "pass";
453
		$rule['enabled'] = "on";
454
		$config['filter']['rule'][] = $rule;
455
	}
456
	if (isset($pconfig['step11']['ovpnallow'])) {
457
                $rule = array();
458
                $rule['descr'] = gettext("OpenVPN {$server['description']} wizard rules.");
459
                $rule['source']['any'] = TRUE;
460
                $rule['destination']['any'] = TRUE;
461
                $rule['interface'] = "openvpn";
462
                $rule['protocol'] = "any";
463
                $rule['type'] = "pass";
464
                $rule['enabled'] = "on";
465
                $config['filter']['rule'][] = $rule;
466
        }
467
	
468
	if (!is_array($config['openvpn']['openvpn-server']))
469
		$config['openvpn']['openvpn-server'] = array();
470

    
471
	$config['openvpn']['openvpn-server'][] = $server;
472

    
473
	openvpn_resync('server', $server);
474
	write_config();
475
	header("Location: vpn_openvpn_server.php");
476
	exit;
477
}
478

    
479
?>
(1-1/11)