Project

General

Profile

Feature #1222 » vpn_openvpn_server.php

Eino Efimov, 01/21/2011 06:09 PM

 
1
<?php 
2
/*
3
	vpn_openvpn_server.php
4

    
5
	Copyright (C) 2008 Shrew Soft Inc.
6
	All rights reserved. 
7

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

    
30
##|+PRIV
31
##|*IDENT=page-openvpn-server
32
##|*NAME=OpenVPN: Server page
33
##|*DESCR=Allow access to the 'OpenVPN: Server' page.
34
##|*MATCH=vpn_openvpn_server.php*
35
##|-PRIV
36

    
37
require("guiconfig.inc");
38
require_once("openvpn.inc");
39

    
40
$pgtitle = array(gettext("OpenVPN"), gettext("Server"));
41
$statusurl = "status_openvpn.php";
42
$logurl = "diag_logs_openvpn.php";
43

    
44
if (!is_array($config['openvpn']['openvpn-server']))
45
	$config['openvpn']['openvpn-server'] = array();
46

    
47
$a_server = &$config['openvpn']['openvpn-server'];
48

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

    
52
$a_ca =& $config['ca'];
53

    
54
if (!is_array($config['cert']))
55
	$config['cert'] = array();
56

    
57
$a_cert =& $config['cert'];
58

    
59
if (!is_array($config['crl']))
60
	$config['crl'] = array();
61

    
62
$a_crl =& $config['crl'];
63

    
64
foreach ($a_crl as $cid => $acrl)
65
	if (!isset($acrl['refid']))
66
		unset ($a_crl[$cid]);
67

    
68
$id = $_GET['id'];
69
if (isset($_POST['id']))
70
	$id = $_POST['id'];
71

    
72
$act = $_GET['act'];
73
if (isset($_POST['act']))
74
	$act = $_POST['act'];
75

    
76
if ($_GET['act'] == "del") {
77

    
78
	if (!$a_server[$id]) {
79
		pfSenseHeader("vpn_openvpn_server.php");
80
		exit;
81
	}
82

    
83
	openvpn_delete('server', $a_server[$id]);
84
	unset($a_server[$id]);
85
	write_config();
86
	$savemsg = gettext("Server successfully deleted")."<br/>";
87
}
88

    
89
if($_GET['act']=="new"){
90
	$pconfig['autokey_enable'] = "yes";
91
	$pconfig['tlsauth_enable'] = "yes";
92
	$pconfig['autotls_enable'] = "yes";
93
	$pconfig['dh_length'] = 1024;
94
	$pconfig['interface'] = "wan";
95
	$pconfig['local_port'] = openvpn_port_next('UDP');
96
	$pconfig['pool_enable'] = "yes";
97
}
98

    
99
if($_GET['act']=="edit"){
100

    
101
	if (isset($id) && $a_server[$id]) {
102

    
103
		$pconfig['disable'] = isset($a_server[$id]['disable']);
104
		$pconfig['mode'] = $a_server[$id]['mode'];
105
		$pconfig['protocol'] = $a_server[$id]['protocol'];
106
		$pconfig['authmode'] = $a_server[$id]['authmode'];
107
		$pconfig['interface'] = $a_server[$id]['interface'];
108
		if (!empty($a_server[$id]['ipaddr'])) {
109
			$pconfig['interface'] = $pconfig['interface'] . '|' . $a_server[$id]['ipaddr'];
110
		}
111
		$pconfig['local_port'] = $a_server[$id]['local_port'];
112
		$pconfig['description'] = $a_server[$id]['description'];
113
		$pconfig['custom_options'] = $a_server[$id]['custom_options'];
114
		$pconfig['dev_mode'] = $a_server[$id]['dev_mode'];
115
		
116
		if ($pconfig['mode'] != "p2p_shared_key") {
117
			if ($a_server[$id]['tls']) {
118
				$pconfig['tlsauth_enable'] = "yes";
119
				$pconfig['tls'] = base64_decode($a_server[$id]['tls']);
120
			}
121
			$pconfig['caref'] = $a_server[$id]['caref'];
122
			$pconfig['crlref'] = $a_server[$id]['crlref'];
123
			$pconfig['certref'] = $a_server[$id]['certref'];
124
			$pconfig['dh_length'] = $a_server[$id]['dh_length'];
125
			if ($pconfig['mode'] == "server_tls_user")
126
				$pconfig['strictusercn'] = $a_server[$id]['strictusercn'];
127
		} else
128
			$pconfig['shared_key'] = base64_decode($a_server[$id]['shared_key']);
129
		$pconfig['crypto'] = $a_server[$id]['crypto'];
130
		$pconfig['engine'] = $a_server[$id]['engine'];
131

    
132
		$pconfig['tunnel_network'] = $a_server[$id]['tunnel_network'];
133
		$pconfig['remote_network'] = $a_server[$id]['remote_network'];
134
		$pconfig['gwredir'] = $a_server[$id]['gwredir'];
135
		$pconfig['local_network'] = $a_server[$id]['local_network'];
136
		$pconfig['maxclients'] = $a_server[$id]['maxclients'];
137
		$pconfig['compression'] = $a_server[$id]['compression'];
138
		$pconfig['passtos'] = $a_server[$id]['passtos'];
139
		$pconfig['client2client'] = $a_server[$id]['client2client'];
140

    
141
		$pconfig['dynamic_ip'] = $a_server[$id]['dynamic_ip'];
142
		$pconfig['pool_enable'] = $a_server[$id]['pool_enable'];
143

    
144
		$pconfig['dns_domain'] = $a_server[$id]['dns_domain'];
145
		if ($pconfig['dns_domain'])
146
			$pconfig['dns_domain_enable'] = true;
147

    
148
		$pconfig['dns_server1'] = $a_server[$id]['dns_server1'];
149
		$pconfig['dns_server2'] = $a_server[$id]['dns_server2'];
150
		$pconfig['dns_server3'] = $a_server[$id]['dns_server3'];
151
		$pconfig['dns_server4'] = $a_server[$id]['dns_server4'];
152
		if ($pconfig['dns_server1'] ||
153
			$pconfig['dns_server2'] ||
154
			$pconfig['dns_server3'] ||
155
			$pconfig['dns_server4'])
156
			$pconfig['dns_server_enable'] = true;
157

    
158
		$pconfig['ntp_server1'] = $a_server[$id]['ntp_server1'];
159
		$pconfig['ntp_server2'] = $a_server[$id]['ntp_server2'];
160
		if ($pconfig['ntp_server1'] ||
161
			$pconfig['ntp_server2'])
162
			$pconfig['ntp_server_enable'] = true;
163

    
164
		$pconfig['netbios_enable'] = $a_server[$id]['netbios_enable'];
165
		$pconfig['netbios_ntype'] = $a_server[$id]['netbios_ntype'];
166
		$pconfig['netbios_scope'] = $a_server[$id]['netbios_scope'];
167

    
168
		$pconfig['wins_server1'] = $a_server[$id]['wins_server1'];
169
		$pconfig['wins_server2'] = $a_server[$id]['wins_server2'];
170
		if ($pconfig['wins_server1'] ||
171
			$pconfig['wins_server2'])
172
			$pconfig['wins_server_enable'] = true;
173

    
174
		$pconfig['nbdd_server1'] = $a_server[$id]['nbdd_server1'];
175
		if ($pconfig['nbdd_server1'])
176
			$pconfig['nbdd_server_enable'] = true;
177

    
178
		// just in case the modes switch
179
		$pconfig['autokey_enable'] = "yes";
180
		$pconfig['autotls_enable'] = "yes";
181

    
182
		$pconfig['duplicate_cn'] = isset($a_server[$id]['duplicate_cn']);
183
	}
184
}
185

    
186
if ($_POST) {
187

    
188
	unset($input_errors);
189
	$pconfig = $_POST;
190

    
191
	if (isset($id) && $a_server[$id])
192
		$vpnid = $a_server[$id]['vpnid'];
193
	else
194
		$vpnid = 0;
195

    
196
	if ($pconfig['mode'] != "p2p_shared_key")
197
		$tls_mode = true;
198
	else
199
		$tls_mode = false;
200

    
201
	if (!empty($pconfig['authmode'])) {
202
		foreach ($pconfig['authmode'] as $pauthmode) {
203
			if ($pauthmode != "Local Database" && $pconfig['mode'] == "server_tls_user") 
204
				$input_errors[] = gettext("Only 'Local authentication database'  is allowed with") . " " . $openvpn_server_modes[$pconfig['mode']];
205
		}
206
	}
207

    
208
	if (empty($pconfig['authmode']) && (($pconfig['mode'] == "server_user") || ($pconfig['mode'] == "server_tls_user")))
209
		$input_errors[] = gettext("You must select a Backend for Authentication if the server mode requires User Auth.");
210

    
211
	/* input validation */
212
	if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
213
		$input_errors[] = $result;
214

    
215
	if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network'))
216
		$input_errors[] = $result;
217

    
218
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'Remote network'))
219
		$input_errors[] = $result;
220

    
221
	if ($result = openvpn_validate_cidr($pconfig['local_network'], 'Local network'))
222
		$input_errors[] = $result;
223

    
224
	$portused = openvpn_port_used($pconfig['protocol'], $pconfig['local_port']);
225
	if (($portused != $vpnid) && ($portused != 0))
226
		$input_errors[] = gettext("The specified 'Local port' is in use. Please select another value");
227

    
228
	if ($pconfig['autokey_enable'])
229
		$pconfig['shared_key'] = openvpn_create_key();
230

    
231
	if (!$tls_mode && !$pconfig['autokey_enable'])
232
		if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
233
			!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
234
			$input_errors[] = gettext("The field 'Shared Key' does not appear to be valid");
235

    
236
	if ($tls_mode && $pconfig['tlsauth_enable'] && !$pconfig['autotls_enable'])
237
		if (!strstr($pconfig['tls'], "-----BEGIN OpenVPN Static key V1-----") ||
238
			!strstr($pconfig['tls'], "-----END OpenVPN Static key V1-----"))
239
			$input_errors[] = gettext("The field 'TLS Authentication Key' does not appear to be valid");
240

    
241
	if ($pconfig['dns_server_enable']) {
242
		if (!empty($pconfig['dns_server1']) && !is_ipaddr(trim($pconfig['dns_server1'])))
243
			$input_errors[] = gettext("The field 'DNS Server #1' must contain a valid IP address");
244
		if (!empty($pconfig['dns_server2']) && !is_ipaddr(trim($pconfig['dns_server2'])))
245
			$input_errors[] = gettext("The field 'DNS Server #2' must contain a valid IP address");
246
		if (!empty($pconfig['dns_server3']) && !is_ipaddr(trim($pconfig['dns_server3'])))
247
			$input_errors[] = gettext("The field 'DNS Server #3' must contain a valid IP address");
248
		if (!empty($pconfig['dns_server4']) && !is_ipaddr(trim($pconfig['dns_server4'])))
249
			$input_errors[] = gettext("The field 'DNS Server #4' must contain a valid IP address");
250
	}
251

    
252
	if ($pconfig['ntp_server_enable']) {
253
		if (!empty($pconfig['ntp_server1']) && !is_ipaddr(trim($pconfig['ntp_server1'])))
254
			$input_errors[] = gettext("The field 'NTP Server #1' must contain a valid IP address");
255
		if (!empty($pconfig['ntp_server2']) && !is_ipaddr(trim($pconfig['ntp_server2'])))
256
			$input_errors[] = gettext("The field 'NTP Server #2' must contain a valid IP address");
257
		if (!empty($pconfig['ntp_server3']) && !is_ipaddr(trim($pconfig['ntp_server3'])))
258
			$input_errors[] = gettext("The field 'NTP Server #3' must contain a valid IP address");
259
		if (!empty($pconfig['ntp_server4']) && !is_ipaddr(trim($pconfig['ntp_server4'])))
260
			$input_errors[] = gettext("The field 'NTP Server #4' must contain a valid IP address");
261
	}
262

    
263
	if ($pconfig['netbios_enable']) {
264
		if ($pconfig['wins_server_enable']) {
265
			if (!empty($pconfig['wins_server1']) && !is_ipaddr(trim($pconfig['wins_server1'])))
266
				$input_errors[] = gettext("The field 'WINS Server #1' must contain a valid IP address");
267
			if (!empty($pconfig['wins_server2']) && !is_ipaddr(trim($pconfig['wins_server2'])))
268
				$input_errors[] = gettext("The field 'WINS Server #2' must contain a valid IP address");
269
		}
270
		if ($pconfig['nbdd_server_enable'])
271
			if (!empty($pconfig['nbdd_server1']) && !is_ipaddr(trim($pconfig['nbdd_server1'])))
272
				$input_errors[] = gettext("The field 'NetBIOS Data Distribution Server #1' must contain a valid IP address");
273
	}
274

    
275
	if ($pconfig['maxclients'] && !is_numeric($pconfig['maxclients']))
276
		$input_errors[] = gettext("The field 'Concurrent connections' must be numeric.");
277

    
278
	/* If we are not in shared key mode, then we need the CA/Cert. */
279
	if ($pconfig['mode'] != "p2p_shared_key") {
280
		$reqdfields = explode(" ", "caref certref");
281
		$reqdfieldsn = array(gettext("Certificate Authority"),gettext("Certificate"));
282
	} elseif (!$pconfig['autokey_enable']) {
283
		/* We only need the shared key filled in if we are in shared key mode and autokey is not selected. */
284
		$reqdfields = array('shared_key');
285
		$reqdfieldsn = array(gettext('Shared key'));
286
	}
287

    
288
	$reqdfields[] = 'tunnel_network';
289
	$reqdfieldsn[] = gettext('Tunnel network');
290

    
291
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
292
	
293
	if (!$input_errors) {
294

    
295
		$server = array();
296

    
297
		if ($vpnid)
298
			$server['vpnid'] = $vpnid;
299
		else
300
			$server['vpnid'] = openvpn_vpnid_next();
301

    
302
		if ($_POST['disable'] == "yes")
303
			$server['disable'] = true;
304
		$server['mode'] = $pconfig['mode'];
305
		if (!empty($pconfig['authmode']))
306
			$server['authmode'] = implode(",", $pconfig['authmode']);
307
		$server['protocol'] = $pconfig['protocol'];
308
		$server['dev_mode'] = $pconfig['dev_mode'];
309
		list($server['interface'], $server['ipaddr']) = explode ("|",$pconfig['interface']);
310
		$server['local_port'] = $pconfig['local_port'];
311
		$server['description'] = $pconfig['description'];
312
		$server['custom_options'] = str_replace("\r\n", "\n", $pconfig['custom_options']);
313

    
314
		if ($tls_mode) {
315
			if ($pconfig['tlsauth_enable']) {
316
				if ($pconfig['autotls_enable'])
317
					$pconfig['tls'] = openvpn_create_key();
318
				$server['tls'] = base64_encode($pconfig['tls']);
319
			}
320
			$server['caref'] = $pconfig['caref'];
321
			$server['crlref'] = $pconfig['crlref'];
322
			$server['certref'] = $pconfig['certref'];
323
			$server['dh_length'] = $pconfig['dh_length'];
324
			if ($pconfig['mode'] == "server_tls_user")
325
				$server['strictusercn'] = $pconfig['strictusercn'];
326
		} else {
327
			$server['shared_key'] = base64_encode($pconfig['shared_key']);
328
		}
329
		$server['crypto'] = $pconfig['crypto'];
330
		$server['engine'] = $pconfig['engine'];
331

    
332
		$server['tunnel_network'] = $pconfig['tunnel_network'];
333
		$server['remote_network'] = $pconfig['remote_network'];
334
		$server['gwredir'] = $pconfig['gwredir'];
335
		$server['local_network'] = $pconfig['local_network'];
336
		$server['maxclients'] = $pconfig['maxclients'];
337
		$server['compression'] = $pconfig['compression'];
338
		$server['passtos'] = $pconfig['passtos'];
339
		$server['client2client'] = $pconfig['client2client'];
340

    
341
		$server['dynamic_ip'] = $pconfig['dynamic_ip'];
342
		$server['pool_enable'] = $pconfig['pool_enable'];
343

    
344
		if ($pconfig['dns_domain_enable'])
345
			$server['dns_domain'] = $pconfig['dns_domain'];
346

    
347
		if ($pconfig['dns_server_enable']) {
348
			$server['dns_server1'] = $pconfig['dns_server1'];
349
			$server['dns_server2'] = $pconfig['dns_server2'];
350
			$server['dns_server3'] = $pconfig['dns_server3'];
351
			$server['dns_server4'] = $pconfig['dns_server4'];
352
		}
353

    
354
		if ($pconfig['ntp_server_enable']) {
355
			$server['ntp_server1'] = $pconfig['ntp_server1'];
356
			$server['ntp_server2'] = $pconfig['ntp_server2'];
357
		}
358

    
359
		$server['netbios_enable'] = $pconfig['netbios_enable'];
360
		$server['netbios_ntype'] = $pconfig['netbios_ntype'];
361
		$server['netbios_scope'] = $pconfig['netbios_scope'];
362

    
363
		if ($pconfig['netbios_enable']) {
364

    
365
			if ($pconfig['wins_server_enable']) {
366
				$server['wins_server1'] = $pconfig['wins_server1'];
367
				$server['wins_server2'] = $pconfig['wins_server2'];
368
			}
369

    
370
			if ($pconfig['dns_server_enable'])
371
				$server['nbdd_server1'] = $pconfig['nbdd_server1'];
372
		}
373

    
374
		if ($_POST['duplicate_cn'] == "yes")
375
			$server['duplicate_cn'] = true;
376

    
377
		if (isset($id) && $a_server[$id])
378
			$a_server[$id] = $server;
379
		else
380
			$a_server[] = $server;
381

    
382
		openvpn_resync('server', $server);
383
		write_config();
384
		
385
		header("Location: vpn_openvpn_server.php");
386
		exit;
387
	}
388
	if (!empty($pconfig['authmode']))
389
		$pconfig['authmode'] = implode(",", $pconfig['authmode']);
390
}
391

    
392
include("head.inc");
393

    
394
?>
395

    
396
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
397
<?php include("fbegin.inc"); ?>
398
<script language="JavaScript">
399
<!--
400

    
401
function mode_change() {
402
	index = document.iform.mode.selectedIndex;
403
	value = document.iform.mode.options[index].value;
404
	switch(value) {
405
		case "p2p_tls":
406
		case "server_tls":
407
		case "server_user":
408
			document.getElementById("tls").style.display="";
409
			document.getElementById("tls_ca").style.display="";
410
			document.getElementById("tls_crl").style.display="";
411
			document.getElementById("tls_cert").style.display="";
412
			document.getElementById("tls_dh").style.display="";
413
			document.getElementById("strictusercn").style.display="none";
414
			document.getElementById("psk").style.display="none";
415
			break;
416
		case "server_tls_user":
417
			document.getElementById("tls").style.display="";
418
			document.getElementById("tls_ca").style.display="";
419
			document.getElementById("tls_crl").style.display="";
420
			document.getElementById("tls_cert").style.display="";
421
			document.getElementById("tls_dh").style.display="";
422
			document.getElementById("strictusercn").style.display="";
423
			document.getElementById("psk").style.display="none";
424
			break;
425
		case "p2p_shared_key":
426
			document.getElementById("tls").style.display="none";
427
			document.getElementById("tls_ca").style.display="none";
428
			document.getElementById("tls_crl").style.display="none";
429
			document.getElementById("tls_cert").style.display="none";
430
			document.getElementById("tls_dh").style.display="none";
431
			document.getElementById("strictusercn").style.display="none";
432
			document.getElementById("psk").style.display="";
433
			break;
434
	}
435
	switch(value) {
436
		case "p2p_shared_key":
437
			document.getElementById("client_opts").style.display="none";
438
			document.getElementById("remote_opts").style.display="";
439
			document.getElementById("gwredir_opts").style.display="none";
440
			document.getElementById("local_opts").style.display="none";
441
			document.getElementById("authmodetr").style.display="none";
442
			document.getElementById("inter_client_communication").style.display="none";
443
			break;
444
		case "p2p_tls":
445
			document.getElementById("client_opts").style.display="none";
446
			document.getElementById("remote_opts").style.display="";
447
			document.getElementById("gwredir_opts").style.display="";
448
			document.getElementById("local_opts").style.display="";
449
			document.getElementById("authmodetr").style.display="none";
450
			document.getElementById("inter_client_communication").style.display="none";
451
			break;
452
		case "server_user":
453
                case "server_tls_user":
454
			document.getElementById("authmodetr").style.display="";
455
			document.getElementById("client_opts").style.display="";
456
			document.getElementById("remote_opts").style.display="none";
457
			document.getElementById("gwredir_opts").style.display="";
458
			document.getElementById("local_opts").style.display="";
459
			document.getElementById("inter_client_communication").style.display="";
460
			break;
461
		case "server_tls":
462
			document.getElementById("authmodetr").style.display="none";
463
		default:
464
			document.getElementById("client_opts").style.display="";
465
			document.getElementById("remote_opts").style.display="none";
466
			document.getElementById("gwredir_opts").style.display="";
467
			document.getElementById("local_opts").style.display="";
468
			document.getElementById("inter_client_communication").style.display="";
469
			break;
470
	}
471
	gwredir_change();
472
}
473

    
474
function autokey_change() {
475

    
476
	if (document.iform.autokey_enable.checked)
477
		document.getElementById("autokey_opts").style.display="none";
478
	else
479
		document.getElementById("autokey_opts").style.display="";
480
}
481

    
482
function tlsauth_change() {
483

    
484
<?php if (!$pconfig['tls']): ?>
485
	if (document.iform.tlsauth_enable.checked)
486
		document.getElementById("tlsauth_opts").style.display="";
487
	else
488
		document.getElementById("tlsauth_opts").style.display="none";
489
<?php endif; ?>
490

    
491
	autotls_change();
492
}
493

    
494
function autotls_change() {
495

    
496
<?php if (!$pconfig['tls']): ?>
497
	autocheck = document.iform.autotls_enable.checked;
498
<?php else: ?>
499
	autocheck = false;
500
<?php endif; ?>
501

    
502
	if (document.iform.tlsauth_enable.checked && !autocheck)
503
		document.getElementById("autotls_opts").style.display="";
504
	else
505
		document.getElementById("autotls_opts").style.display="none";
506
}
507

    
508
function gwredir_change() {
509

    
510
	if (document.iform.gwredir.checked)
511
		document.getElementById("local_opts").style.display="none";
512
	else
513
		document.getElementById("local_opts").style.display="";
514
}
515

    
516
function dns_domain_change() {
517

    
518
	if (document.iform.dns_domain_enable.checked)
519
		document.getElementById("dns_domain_data").style.display="";
520
	else
521
		document.getElementById("dns_domain_data").style.display="none";
522
}
523

    
524
function dns_server_change() {
525

    
526
	if (document.iform.dns_server_enable.checked)
527
		document.getElementById("dns_server_data").style.display="";
528
	else
529
		document.getElementById("dns_server_data").style.display="none";
530
}
531

    
532
function wins_server_change() {
533

    
534
	if (document.iform.wins_server_enable.checked)
535
		document.getElementById("wins_server_data").style.display="";
536
	else
537
		document.getElementById("wins_server_data").style.display="none";
538
}
539

    
540
function ntp_server_change() {
541

    
542
	if (document.iform.ntp_server_enable.checked)
543
		document.getElementById("ntp_server_data").style.display="";
544
	else
545
		document.getElementById("ntp_server_data").style.display="none";
546
}
547

    
548
function netbios_change() {
549

    
550
	if (document.iform.netbios_enable.checked) {
551
		document.getElementById("netbios_data").style.display="";
552
		document.getElementById("wins_opts").style.display="";
553
	} else {
554
		document.getElementById("netbios_data").style.display="none";
555
		document.getElementById("wins_opts").style.display="none";
556
	}
557
}
558

    
559
//-->
560
</script>
561
<?php
562
if (!$savemsg)
563
	$savemsg = "";
564
if (count($a_ca) == 0)
565
	$savemsg .= "You have no Certificate Authorities defined. You must visit the <a href=\"system_camanager.php\">Certificate Manager</a> to make one.";
566
if (count($a_cert) == 0)
567
	$savemsg .= "<br/>You have no Certificates defined. You must visit the <a href=\"system_camanager.php\">Certificate Manager</a> to make one.";
568

    
569
if ($input_errors)
570
	print_input_errors($input_errors);
571
if ($savemsg)
572
	print_info_box_np($savemsg);
573
?>
574
<table width="100%" border="0" cellpadding="0" cellspacing="0">
575
	<tr>
576
		<td class="tabnavtbl">
577
			<ul id="tabnav">
578
			<?php 
579
				$tab_array = array();
580
				$tab_array[] = array(gettext("Server"), true, "vpn_openvpn_server.php");
581
				$tab_array[] = array(gettext("Client"), false, "vpn_openvpn_client.php");
582
				$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
583
				$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
584
				add_package_tabs("OpenVPN", $tab_array);
585
				display_top_tabs($tab_array);
586
			?>
587
			</ul>
588
		</td>
589
	</tr>    
590
	<tr>
591
		<td class="tabcont">
592

    
593
			<?php if($act=="new" || $act=="edit"): ?>
594

    
595
			<form action="vpn_openvpn_server.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
596
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
597
					<tr>
598
						<td colspan="2" valign="top" class="listtopic"><?=gettext("General information"); ?></td>
599
					</tr>
600
					<tr>
601
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
602
						<td width="78%" class="vtable">
603
							<table border="0" cellpadding="0" cellspacing="0">
604
								<tr>
605
									<td>
606
										<?php set_checked($pconfig['disable'],$chk); ?>
607
										<input name="disable" type="checkbox" value="yes" <?=$chk;?>/>
608
									</td>
609
									<td>
610
										&nbsp;
611
										<span class="vexpl">
612
											<strong><?=gettext("Disable this server"); ?></strong><br>
613
										</span>
614
									</td>
615
								</tr>
616
							</table>
617
							<?=gettext("Set this option to disable this server without removing it from the list"); ?>.
618
						</td>
619
					</tr>
620
					<tr>
621
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Server Mode");?></td>
622
							<td width="78%" class="vtable">
623
							<select name='mode' id='mode' class="formselect" onchange='mode_change()'>
624
							<?php
625
								foreach ($openvpn_server_modes as $name => $desc):
626
									$selected = "";
627
									if ($pconfig['mode'] == $name)
628
										$selected = "selected";
629
							?>
630
								<option value="<?=$name;?>" <?=$selected;?>><?=$desc;?></option>
631
							<?php endforeach; ?>
632
							</select>
633
						</td>
634
					</tr>
635
					<tr id="authmodetr" style="display:none">
636
                                                <td width="22%" valign="top" class="vncellreq"><?=gettext("Backend for authentication");?></td>
637
                                                        <td width="78%" class="vtable">
638
                                                        <select name='authmode[]' id='authmode' class="formselect" multiple="true" size="<?php echo count($auth_servers); ?>">
639
							<?php $authmodes = explode(",", $pconfig['authmode']); ?>
640
                                                        <?php
641
								$auth_servers = auth_get_authserver_list();
642
                                                                foreach ($auth_servers as $auth_server):
643
                                                                        $selected = "";
644
                                                                        if (in_array($auth_server['name'], $authmodes))
645
                                                                                $selected = "selected";
646
                                                        ?>
647
                                                                <option value="<?=$auth_server['name'];?>" <?=$selected;?>><?=$auth_server['name'];?></option>
648
                                                        <?php 	endforeach; ?>
649
                                                        </select>
650
                                                </td>
651
                                        </tr>
652
					<tr>
653
						
654
						                                        <tr>
655
                                                <td width="22%" valign="top" class="vncellreq"><?=gettext("Device mode");?></td>
656
                                                        <td width="78%" class="vtable">
657
                                                        <select name='dev_mode' class="formselect">
658
                                                        <?php
659
                                                                foreach ($openvpn_dev_mode as $mode):
660
                                                                        $selected = "";
661
                                                                        if ($pconfig['dev_mode'] == $mode)
662
                                                                                $selected = "selected";
663
                                                        ?>
664
                                                                <option value="<?=$mode;?>" <?=$selected;?>><?=$mode;?></option>
665
                                                        <?php endforeach; ?>
666
                                                        </select>
667
                                                        </td>
668
                                        </tr>
669
						
670
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
671
							<td width="78%" class="vtable">
672
							<select name='protocol' class="formselect">
673
							<?php
674
								foreach ($openvpn_prots as $prot):
675
									$selected = "";
676
									if ($pconfig['protocol'] == $prot)
677
										$selected = "selected";
678
							?>
679
								<option value="<?=$prot;?>" <?=$selected;?>><?=$prot;?></option>
680
							<?php endforeach; ?>
681
							</select>
682
							</td>
683
					</tr>
684
					<tr>
685
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
686
						<td width="78%" class="vtable">
687
							<select name="interface" class="formselect">
688
								<?php
689
									$interfaces = get_configured_interface_with_descr();
690
									$carplist = get_configured_carp_interface_list();
691
									foreach ($carplist as $cif => $carpip)
692
										$interfaces[$cif.'|'.$carpip] = $carpip." (".get_vip_descr($carpip).")";
693
									$aliaslist = get_configured_ip_aliases_list();
694
									foreach ($aliaslist as $aliasip => $aliasif)
695
										$interfaces[$aliasif.'|'.$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
696
									$interfaces['any'] = "any";
697
									foreach ($interfaces as $iface => $ifacename):
698
										$selected = "";
699
										if ($iface == $pconfig['interface'])
700
											$selected = "selected";
701
								?>
702
									<option value="<?=$iface;?>" <?=$selected;?>>
703
										<?=htmlspecialchars($ifacename);?>
704
									</option>
705
								<?php endforeach; ?>
706
							</select> <br>
707
						</td>
708
					</tr>
709
					<tr>
710
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Local port");?></td>
711
						<td width="78%" class="vtable">
712
							<input name="local_port" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['local_port']);?>"/>
713
						</td>
714
					</tr>
715
					<tr> 
716
						<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
717
						<td width="78%" class="vtable"> 
718
							<input name="description" type="text" class="formfld unknown" size="30" value="<?=htmlspecialchars($pconfig['description']);?>">
719
							<br>
720
							<?=gettext("You may enter a description here for your reference (not parsed)"); ?>.
721
						</td>
722
					</tr>
723
					<tr>
724
						<td colspan="2" class="list" height="12"></td>
725
					</tr>
726
					<tr>
727
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Cryptographic Settings"); ?></td>
728
					</tr>
729
					<tr id="tls">
730
						<td width="22%" valign="top" class="vncellreq"><?=gettext("TLS Authentication"); ?></td>
731
						<td width="78%" class="vtable">
732
							<table border="0" cellpadding="2" cellspacing="0">
733
								<tr>
734
									<td>
735
										<?php set_checked($pconfig['tlsauth_enable'],$chk); ?>
736
										<input name="tlsauth_enable" id="tlsauth_enable" type="checkbox" value="yes" <?=$chk;?> onClick="tlsauth_change()">
737
									</td>
738
									<td>
739
										<span class="vexpl">
740
											<?=gettext("Enable authentication of TLS packets"); ?>.
741
										</span>
742
									</td>
743
								</tr>
744
							</table>
745
							<?php if (!$pconfig['tls']): ?>
746
							<table border="0" cellpadding="2" cellspacing="0" id='tlsauth_opts'>
747
								<tr>
748
									<td>
749
										<?php set_checked($pconfig['autotls_enable'],$chk); ?>
750
										<input name="autotls_enable" id="autotls_enable" type="checkbox" value="yes" <?=$chk;?> onClick="autotls_change()">
751
									</td>
752
									<td>
753
										<span class="vexpl">
754
											<?=gettext("Automatically generate a shared TLS authentication key"); ?>.
755
										</span>
756
									</td>
757
								</tr>
758
							</table>
759
							<?php endif; ?>
760
							<table border="0" cellpadding="2" cellspacing="0" id='autotls_opts'>
761
								<tr>
762
									<td>
763
										<textarea name="tls" cols="65" rows="7" class="formpre"><?=htmlspecialchars($pconfig['tls']);?></textarea>
764
										<br/>
765
										<?=gettext("Paste your shared key here"); ?>.
766
									</td>
767
								</tr>
768
							</table>
769
						</td>
770
					</tr>
771
					<tr id="tls_ca">
772
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Peer Certificate Authority"); ?></td>
773
							<td width="78%" class="vtable">
774
							<select name='caref' class="formselect">
775
							<?php
776
								foreach ($a_ca as $ca):
777
									$selected = "";
778
									if ($pconfig['caref'] == $ca['refid'])
779
										$selected = "selected";
780
							?>
781
								<option value="<?=$ca['refid'];?>" <?=$selected;?>><?=$ca['descr'];?></option>
782
							<?php endforeach; ?>
783
							</select>
784
							</td>
785
					</tr>
786
					<tr id="tls_crl">
787
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Peer Certificate Revocation List"); ?></td>
788
							<td width="78%" class="vtable">
789
							<select name='crlref' class="formselect">
790
								<option value="">None</option>
791
							<?php
792
								foreach ($a_crl as $crl):
793
									if (is_crl_internal($crl) && (count($crl['cert']) <= 0))
794
										continue;
795
									$selected = "";
796
									if ($pconfig['crlref'] == $crl['refid'])
797
										$selected = "selected";
798
							?>
799
								<option value="<?=$crl['refid'];?>" <?=$selected;?>><?=$crl['descr'];?></option>
800
							<?php endforeach; ?>
801
							</select>
802
							</td>
803
					</tr>
804
					<tr id="tls_cert">
805
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Server Certificate"); ?></td>
806
							<td width="78%" class="vtable">
807
							<select name='certref' class="formselect">
808
							<?php
809
							foreach ($a_cert as $cert):
810
								$selected = "";
811
								$caname = "";
812
								$inuse = "";
813
								$revoked = "";
814
								if (is_user_cert($cert['refid']))
815
									continue;
816
								$ca = lookup_ca($cert['caref']);
817
								if ($ca)
818
									$caname = " (CA: {$ca['descr']})";
819
								if ($pconfig['certref'] == $cert['refid'])
820
									$selected = "selected";
821
								if (cert_in_use($cert['refid']))
822
									$inuse = " *In Use";
823
								if (is_cert_revoked($cert))
824
								$revoked = " *Revoked";
825
							?>
826
								<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'] . $caname . $inuse . $revoked;?></option>
827
							<?php endforeach; ?>
828
							</select>
829
						</td>
830
					</tr>
831
					<tr id="tls_dh">
832
						<td width="22%" valign="top" class="vncellreq"><?=gettext("DH Parameters Length"); ?></td>
833
						<td width="78%" class="vtable">
834
							<select name="dh_length" class="formselect">
835
								<?php
836
									foreach ($openvpn_dh_lengths as $length):
837
									$selected = '';
838
									if ($length == $pconfig['dh_length'])
839
										$selected = ' selected';
840
								?>
841
								<option<?=$selected?>><?=$length;?></option>
842
								<?php endforeach; ?>
843
							</select>
844
							<span class="vexpl">
845
								<?=gettext("bits"); ?>
846
							</span>
847
						</td>
848
					</tr>
849
					<tr id="psk">
850
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Shared Key"); ?></td>
851
						<td width="78%" class="vtable">
852
							<?php if (!$pconfig['shared_key']): ?>
853
							<table border="0" cellpadding="2" cellspacing="0">
854
								<tr>
855
									<td>
856
										<?php set_checked($pconfig['autokey_enable'],$chk); ?>
857
										<input name="autokey_enable" type="checkbox" value="yes" <?=$chk;?> onClick="autokey_change()">
858
									</td>
859
									<td>
860
										<span class="vexpl">
861
											<?=gettext("Automatically generate a shared key"); ?>.
862
										</span>
863
									</td>
864
								</tr>
865
							</table>
866
							<?php endif; ?>
867
							<table border="0" cellpadding="2" cellspacing="0" id='autokey_opts'>
868
								<tr>
869
									<td>
870
										<textarea name="shared_key" cols="65" rows="7" class="formpre"><?=htmlspecialchars($pconfig['shared_key']);?></textarea>
871
										<br/>
872
										<?=gettext("Paste your shared key here"); ?>.
873
									</td>
874
								</tr>
875
							</table>
876
						</td>
877
					</tr>
878
					<tr>
879
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Encryption algorithm"); ?></td>
880
						<td width="78%" class="vtable">
881
							<select name="crypto" class="formselect">
882
								<?php
883
									$cipherlist = openvpn_get_cipherlist();
884
									foreach ($cipherlist as $name => $desc):
885
									$selected = '';
886
									if ($name == $pconfig['crypto'])
887
										$selected = ' selected';
888
								?>
889
								<option value="<?=$name;?>"<?=$selected?>>
890
									<?=htmlspecialchars($desc);?>
891
								</option>
892
								<?php endforeach; ?>
893
							</select>
894
						</td>
895
					</tr>
896
					<tr id="engine">
897
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Hardware Crypto"); ?></td>
898
						<td width="78%" class="vtable">
899
							<select name="engine" class="formselect">
900
								<?php
901
									$engines = openvpn_get_engines();
902
									foreach ($engines as $name => $desc):
903
									$selected = '';
904
									if ($name == $pconfig['engine'])
905
										$selected = ' selected';
906
								?>
907
								<option value="<?=$name;?>"<?=$selected?>>
908
									<?=htmlspecialchars($desc);?>
909
								</option>
910
								<?php endforeach; ?>
911
							</select>
912
						</td>
913
					</tr>
914
					<tr id="strictusercn">
915
						<td width="22%" valign="top" class="vncell"><?=gettext("Strict User/CN Matching"); ?></td>
916
						<td width="78%" class="vtable">
917
							<table border="0" cellpadding="2" cellspacing="0">
918
								<tr>
919
									<td>
920
										<?php set_checked($pconfig['strictusercn'],$chk); ?>
921
										<input name="strictusercn" type="checkbox" value="yes" <?=$chk;?>/>
922
									</td>
923
									<td>
924
										<span class="vexpl">
925
											<?=gettext("When authenticating users, enforce a match between the common name of the client certificate and the username given at login."); ?>
926
										</span>
927
									</td>
928
								</tr>
929
							</table>
930
						</td>
931
					</tr>
932
					<tr>
933
						<td colspan="2" class="list" height="12"></td>
934
					</tr>
935
					<tr>
936
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Tunnel Settings"); ?></td>
937
					</tr>
938
					<tr>
939
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Tunnel Network"); ?></td>
940
						<td width="78%" class="vtable">
941
							<input name="tunnel_network" type="text" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['tunnel_network']);?>">
942
							<br>
943
							<?=gettext("This is the virtual network used for private " .
944
							"communications between this server and client " .
945
							"hosts expressed using CIDR (eg. 10.0.8.0/24). " .
946
							"The first network address will be assigned to " .
947
							"the	server virtual interface. The remaining " .
948
							"network addresses can optionally be assigned " .
949
							"to connecting clients. (see Address Pool)"); ?>
950
						</td>
951
					</tr>
952
					<tr id="gwredir_opts">
953
						<td width="22%" valign="top" class="vncell"><?=gettext("Redirect Gateway"); ?></td>
954
						<td width="78%" class="vtable">
955
							<table border="0" cellpadding="2" cellspacing="0">
956
								<tr>
957
									<td>
958
										<?php set_checked($pconfig['gwredir'],$chk); ?>
959
										<input name="gwredir" type="checkbox" value="yes" <?=$chk;?> onClick="gwredir_change()"/>
960
									</td>
961
									<td>
962
										<span class="vexpl">
963
											<?=gettext("Force all client generated traffic through the tunnel"); ?>.
964
										</span>
965
									</td>
966
								</tr>
967
							</table>
968
						</td>
969
					</tr>
970
					<tr id="local_opts">
971
						<td width="22%" valign="top" class="vncell"><?=gettext("Local Network"); ?></td>
972
						<td width="78%" class="vtable">
973
							<input name="local_network" type="text" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['local_network']);?>">
974
							<br>
975
							<?=gettext("This is the network that will be accessible " .
976
							"from the remote endpoint. Expressed as a CIDR " .
977
							"range. You may leave this blank if you don't " .
978
							"want to add a route to the local network " .
979
							"through this tunnel on the remote machine. " .
980
							"This is generally set to your LAN network"); ?>.
981
						</td>
982
					</tr>
983
					<tr id="remote_opts">
984
						<td width="22%" valign="top" class="vncell"><?=gettext("Remote Network"); ?></td>
985
						<td width="78%" class="vtable">
986
							<input name="remote_network" type="text" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['remote_network']);?>">
987
							<br>
988
							<?=gettext("This is a network that will be routed through " .
989
							"the tunnel, so that a site-to-site VPN can be " .
990
							"established without manually changing the " .
991
							"routing tables. Expressed as a CIDR range. If " .
992
							"this is a site-to-site VPN, enter here the " .
993
							"remote LAN here. You may leave this blank if " .
994
							"you don't want a site-to-site VPN"); ?>.
995
						</td>
996
					</tr>
997
					<tr>
998
						<td width="22%" valign="top" class="vncell"><?=gettext("Concurrent connections");?></td>
999
						<td width="78%" class="vtable">
1000
							<input name="maxclients" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['maxclients']);?>"/>
1001
							<br/>
1002
							<?=gettext("Specify the maximum number of clients allowed to concurrently connect to this server"); ?>.
1003
						</td>
1004
					</tr>
1005
					<tr>
1006
						<td width="22%" valign="top" class="vncell"><?=gettext("Compression"); ?></td>
1007
						<td width="78%" class="vtable">
1008
							<table border="0" cellpadding="2" cellspacing="0">
1009
								<tr>
1010
									<td>
1011
										<?php set_checked($pconfig['compression'],$chk); ?>
1012
										<input name="compression" type="checkbox" value="yes" <?=$chk;?>>
1013
									</td>
1014
									<td>
1015
										<span class="vexpl">
1016
											<?=gettext("Compress tunnel packets using the LZO algorithm"); ?>.
1017
										</span>
1018
									</td>
1019
								</tr>
1020
							</table>
1021
						</td>
1022
					</tr>
1023
					<tr>
1024
						<td width="22%" valign="top" class="vncell"><?=gettext("Type-of-Service"); ?></td>
1025
						<td width="78%" class="vtable">
1026
							<table border="0" cellpadding="2" cellspacing="0">
1027
								<tr>
1028
									<td>
1029
										<?php set_checked($pconfig['passtos'],$chk); ?>
1030
										<input name="passtos" type="checkbox" value="yes" <?=$chk;?>>
1031
									</td>
1032
									<td>
1033
										<span class="vexpl">
1034
											<?=gettext("Set the TOS IP header value of tunnel packets to match the encapsulated packet value"); ?>.
1035
										</span>
1036
									</td>
1037
								</tr>
1038
							</table>
1039
						</td>
1040
					</tr>
1041
					<tr id="inter_client_communication">
1042
						<td width="22%" valign="top" class="vncell"><?=gettext("Inter-client communication"); ?></td>
1043
						<td width="78%" class="vtable">
1044
							<table border="0" cellpadding="2" cellspacing="0">
1045
								<tr>
1046
									<td>
1047
										<?php set_checked($pconfig['client2client'],$chk); ?>
1048
										<input name="client2client" type="checkbox" value="yes" <?=$chk;?>/>
1049
									</td>
1050
									<td>
1051
										<span class="vexpl">
1052
											<?=gettext("Allow communication between clients connected to this server"); ?>
1053
										</span>
1054
									</td>
1055
								</tr>
1056
							</table>
1057
						</td>
1058
					</tr>
1059
					<tr id="duplicate_cn">
1060
						<td width="22%" valign="top" class="vncell"><?=gettext("Duplicate Connections"); ?></td>
1061
						<td width="78%" class="vtable">
1062
							<table border="0" cellpadding="2" cellspacing="0">
1063
								<tr>
1064
									<td>
1065
										<?php set_checked($pconfig['duplicate_cn'],$chk); ?>
1066
										<input name="duplicate_cn" type="checkbox" value="yes" <?=$chk;?>/>
1067
									</td>
1068
									<td>
1069
										<span class="vexpl">
1070
											<?=gettext("Allow multiple concurrent connections from clients using the same Common Name.<br/>NOTE: This is not generally recommended, but may be needed for some scenarios."); ?>
1071
										</span>
1072
									</td>
1073
								</tr>
1074
							</table>
1075
						</td>
1076
					</tr>
1077
				</table>
1078

    
1079
				<table width="100%" border="0" cellpadding="6" cellspacing="0" id="client_opts">
1080
					<tr>
1081
						<td colspan="2" class="list" height="12"></td>
1082
					</tr>
1083
					<tr>
1084
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Client Settings"); ?></td>
1085
					</tr>
1086
					<tr>
1087
						<td width="22%" valign="top" class="vncell"><?=gettext("Dynamic IP"); ?></td>
1088
						<td width="78%" class="vtable">
1089
							<table border="0" cellpadding="2" cellspacing="0">
1090
								<tr>
1091
									<td>
1092
										<?php set_checked($pconfig['dynamic_ip'],$chk); ?>
1093
										<input name="dynamic_ip" type="checkbox" id="dynamic_ip" value="yes" <?=$chk;?>/>
1094
									</td>
1095
									<td>
1096
										<span class="vexpl">
1097
											<?=gettext("Allow connected clients to retain their connections if their IP address changes"); ?>.<br>
1098
										</span>
1099
									</td>
1100
								</tr>
1101
							</table>
1102
						</td>
1103
					</tr>
1104
					<tr>
1105
						<td width="22%" valign="top" class="vncell"><?=gettext("Address Pool"); ?></td>
1106
						<td width="78%" class="vtable">
1107
							<table border="0" cellpadding="2" cellspacing="0">
1108
								<tr>
1109
									<td>
1110
										<?php set_checked($pconfig['pool_enable'],$chk); ?>
1111
										<input name="pool_enable" type="checkbox" id="pool_enable" value="yes" <?=$chk;?>/>
1112
									</td>
1113
									<td>
1114
										<span class="vexpl">
1115
											<?=gettext("Provide a virtual adapter IP address to clients (see Tunnel Network)"); ?><br>
1116
										</span>
1117
									</td>
1118
								</tr>
1119
							</table>
1120
						</td>
1121
					</tr>
1122
					<tr>
1123
						<td width="22%" valign="top" class="vncell"><?=gettext("DNS Default Domain"); ?></td>
1124
						<td width="78%" class="vtable">
1125
							<table border="0" cellpadding="2" cellspacing="0">
1126
								<tr>
1127
									<td>
1128
										<?php set_checked($pconfig['dns_domain_enable'],$chk); ?>
1129
										<input name="dns_domain_enable" type="checkbox" id="dns_domain_enable" value="yes" <?=$chk;?> onClick="dns_domain_change()">
1130
									</td>
1131
									<td>
1132
										<span class="vexpl">
1133
	                                        <?=gettext("Provide a default domain name to clients"); ?><br>
1134
										</span>
1135
									</td>
1136
								</tr>
1137
							</table>
1138
							<table border="0" cellpadding="2" cellspacing="0" id="dns_domain_data">
1139
								<tr>
1140
									<td>
1141
										<input name="dns_domain" type="text" class="formfld unknown" id="dns_domain" size="30" value="<?=htmlspecialchars($pconfig['dns_domain']);?>">
1142
									</td>
1143
								</tr>
1144
							</table>
1145
						</td>
1146
					</tr>
1147
					<tr>
1148
						<td width="22%" valign="top" class="vncell"><?=gettext("DNS Servers"); ?></td>
1149
						<td width="78%" class="vtable">
1150
							<table border="0" cellpadding="2" cellspacing="0">
1151
								<tr>
1152
									<td>
1153
										<?php set_checked($pconfig['dns_server_enable'],$chk); ?>
1154
										<input name="dns_server_enable" type="checkbox" id="dns_server_enable" value="yes" <?=$chk;?> onClick="dns_server_change()">
1155
									</td>
1156
									<td>
1157
										<span class="vexpl">
1158
											<?=gettext("Provide a DNS server list to clients"); ?><br>
1159
										</span>
1160
									</td>
1161
								</tr>
1162
							</table>
1163
							<table border="0" cellpadding="2" cellspacing="0" id="dns_server_data">
1164
								<tr>
1165
									<td>
1166
										<span class="vexpl">
1167
											<?=gettext("Server"); ?> #1:&nbsp;
1168
										</span>
1169
										<input name="dns_server1" type="text" class="formfld unknown" id="dns_server1" size="20" value="<?=htmlspecialchars($pconfig['dns_server1']);?>">
1170
									</td>
1171
								</tr>
1172
								<tr>
1173
									<td>
1174
										<span class="vexpl">
1175
											<?=gettext("Server"); ?> #2:&nbsp;
1176
										</span>
1177
										<input name="dns_server2" type="text" class="formfld unknown" id="dns_server2" size="20" value="<?=htmlspecialchars($pconfig['dns_server2']);?>">
1178
									</td>
1179
								</tr>
1180
								<tr>
1181
									<td>
1182
										<span class="vexpl">
1183
											<?=gettext("Server"); ?> #3:&nbsp;
1184
										</span>
1185
										<input name="dns_server3" type="text" class="formfld unknown" id="dns_server3" size="20" value="<?=htmlspecialchars($pconfig['dns_server3']);?>">
1186
									</td>
1187
								</tr>
1188
								<tr>
1189
									<td>
1190
										<span class="vexpl">
1191
											<?=gettext("Server"); ?> #4:&nbsp;
1192
										</span>
1193
										<input name="dns_server4" type="text" class="formfld unknown" id="dns_server4" size="20" value="<?=htmlspecialchars($pconfig['dns_server4']);?>">
1194
									</td>
1195
								</tr>
1196
							</table>
1197
						</td>
1198
					</tr>
1199
					<tr>
1200
						<td width="22%" valign="top" class="vncell"><?=gettext("NTP Servers"); ?></td>
1201
						<td width="78%" class="vtable">
1202
							<table border="0" cellpadding="2" cellspacing="0">
1203
								<tr>
1204
									<td>
1205
										<?php set_checked($pconfig['ntp_server_enable'],$chk); ?>
1206
										<input name="ntp_server_enable" type="checkbox" id="ntp_server_enable" value="yes" <?=$chk;?> onClick="ntp_server_change()">
1207
									</td>
1208
									<td>
1209
										<span class="vexpl">
1210
											<?=gettext("Provide a NTP server list to clients"); ?><br>
1211
										</span>
1212
									</td>
1213
								</tr>
1214
							</table>
1215
							<table border="0" cellpadding="2" cellspacing="0" id="ntp_server_data">
1216
								<tr>
1217
									<td>
1218
										<span class="vexpl">
1219
											<?=gettext("Server"); ?> #1:&nbsp;
1220
										</span>
1221
										<input name="ntp_server1" type="text" class="formfld unknown" id="ntp_server1" size="20" value="<?=htmlspecialchars($pconfig['ntp_server1']);?>">
1222
									</td>
1223
								</tr>
1224
								<tr>
1225
									<td>
1226
										<span class="vexpl">
1227
											<?=gettext("Server"); ?> #2:&nbsp;
1228
										</span>
1229
										<input name="ntp_server2" type="text" class="formfld unknown" id="ntp_server2" size="20" value="<?=htmlspecialchars($pconfig['ntp_server2']);?>">
1230
									</td>
1231
								</tr>
1232
							</table>
1233
						</td>
1234
					</tr>
1235
					<tr>
1236
						<td width="22%" valign="top" class="vncell"><?=gettext("NetBIOS Options"); ?></td>
1237
						<td width="78%" class="vtable">
1238
							<table border="0" cellpadding="2" cellspacing="0">
1239
								<tr>
1240
									<td>
1241
										<?php set_checked($pconfig['netbios_enable'],$chk); ?>
1242
										<input name="netbios_enable" type="checkbox" id="netbios_enable" value="yes" <?=$chk;?> onClick="netbios_change()">
1243
									</td>
1244
									<td>
1245
										<span class="vexpl">
1246
											<?=gettext("Enable NetBIOS over TCP/IP"); ?><br>
1247
										</span>
1248
									</td>
1249
								</tr>
1250
							</table>
1251
							<?=gettext("If this option is not set, all NetBIOS-over-TCP/IP options (including WINS) will be disabled"); ?>.
1252
							<br/>
1253
							<table border="0" cellpadding="2" cellspacing="0" id="netbios_data">
1254
								<tr>
1255
									<td>
1256
										<br/>
1257
										<span class="vexpl">
1258
											<?=gettext("Node Type"); ?>:&nbsp;
1259
										</span>
1260
										<select name='netbios_ntype' class="formselect">
1261
										<?php
1262
											foreach ($netbios_nodetypes as $type => $name):
1263
												$selected = "";
1264
												if ($pconfig['netbios_ntype'] == $type)
1265
													$selected = "selected";
1266
										?>
1267
											<option value="<?=$type;?>" <?=$selected;?>><?=$name;?></option>
1268
										<?php endforeach; ?>
1269
										</select>
1270
										<br/>
1271
										<?=gettext("Possible options: b-node (broadcasts), p-node " .
1272
										"(point-to-point name queries to a WINS server), " .
1273
										"m-node (broadcast then query name server), and " .
1274
										"h-node (query name server, then broadcast)"); ?>.
1275
									</td>
1276
								</tr>
1277
								<tr>
1278
									<td>
1279
										<br/>
1280
										<span class="vexpl">
1281
											<?=gettext("Scope ID"); ?>:&nbsp;
1282
										</span>
1283
										<input name="netbios_scope" type="text" class="formfld unknown" id="netbios_scope" size="30" value="<?=htmlspecialchars($pconfig['netbios_scope']);?>">
1284
										<br/>
1285
										<?=gettext("A NetBIOS Scope	ID provides an extended naming " .
1286
										"service for	NetBIOS over TCP/IP. The NetBIOS " .
1287
										"scope ID isolates NetBIOS traffic on a single " .
1288
										"network to only those nodes with the same " .
1289
										"NetBIOS scope ID"); ?>.
1290
									</td>
1291
								</tr>
1292
							</table>
1293
						</td>
1294
					</tr>
1295
					<tr id="wins_opts">
1296
						<td width="22%" valign="top" class="vncell"><?=gettext("WINS Servers"); ?></td>
1297
						<td width="78%" class="vtable">
1298
							<table border="0" cellpadding="2" cellspacing="0">
1299
								<tr>
1300
									<td>
1301
										<?php set_checked($pconfig['wins_server_enable'],$chk); ?>
1302
										<input name="wins_server_enable" type="checkbox" id="wins_server_enable" value="yes" <?=$chk;?> onClick="wins_server_change()">
1303
									</td>
1304
									<td>
1305
										<span class="vexpl">
1306
											<?=gettext("Provide a WINS server list to clients"); ?><br>
1307
										</span>
1308
									</td>
1309
								</tr>
1310
							</table>
1311
							<table border="0" cellpadding="2" cellspacing="0" id="wins_server_data">
1312
								<tr>
1313
									<td>
1314
										<span class="vexpl">
1315
											<?=gettext("Server"); ?> #1:&nbsp;
1316
										</span>
1317
										<input name="wins_server1" type="text" class="formfld unknown" id="wins_server1" size="20" value="<?=htmlspecialchars($pconfig['wins_server1']);?>">
1318
									</td>
1319
								</tr>
1320
								<tr>
1321
									<td>
1322
										<span class="vexpl">
1323
											<?=gettext("Server"); ?> #2:&nbsp;
1324
										</span>
1325
										<input name="wins_server2" type="text" class="formfld unknown" id="wins_server2" size="20" value="<?=htmlspecialchars($pconfig['wins_server2']);?>">
1326
									</td>
1327
								</tr>
1328
							</table>
1329
						</td>
1330
					</tr>
1331
				</table>
1332

    
1333
				<table width="100%" border="0" cellpadding="6" cellspacing="0" id="client_opts">
1334
					<tr>
1335
						<td colspan="2" class="list" height="12"></td>
1336
					</tr>
1337
					<tr>
1338
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced configuration"); ?></td>
1339
					</tr>
1340
					<tr>
1341
						<td width="22%" valign="top" class="vncell"><?=gettext("Advanced"); ?></td>
1342
						<td width="78%" class="vtable">
1343
							<table border="0" cellpadding="2" cellspacing="0">
1344
								<tr>
1345
									<td>
1346
										<textarea rows="6" cols="78" name="custom_options" id="custom_options"><?=htmlspecialchars($pconfig['custom_options']);?></textarea><br/>
1347
										<?=gettext("Enter any additional options you would like to add to the OpenVPN server configuration here, separated by a semicolon"); ?><br/>
1348
										<?=gettext("EXAMPLE: push \"route 10.0.0.0 255.255.255.0\""); ?>;
1349
									</td>
1350
								</tr>
1351
							</table>
1352
						</td>
1353
					</tr>
1354
				</table>
1355

    
1356
				<br/>
1357

    
1358
				<table width="100%" border="0" cellpadding="6" cellspacing="0" id="client_opts">
1359
					<tr>
1360
						<td width="22%" valign="top">&nbsp;</td>
1361
						<td width="78%"> 
1362
							<input name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> 
1363
							<input name="act" type="hidden" value="<?=$act;?>">
1364
							<?php if (isset($id) && $a_server[$id]): ?>
1365
							<input name="id" type="hidden" value="<?=$id;?>">
1366
							<?php endif; ?>
1367
						</td>
1368
					</tr>
1369
				</table>
1370
			</form>
1371

    
1372
			<?php else: ?>
1373

    
1374
			<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
1375
				<thead>
1376
				<tr>
1377
					<td width="10%" class="listhdrr"><?=gettext("Disabled"); ?></td>
1378
					<td width="10%" class="listhdrr"><?=gettext("Protocol / Port"); ?></td>
1379
					<td width="30%" class="listhdrr"><?=gettext("Tunnel Network"); ?></td>
1380
					<td width="40%" class="listhdrr"><?=gettext("Description"); ?></td>
1381
					<td width="10%" class="list"></td>
1382
				</tr>
1383
				</thead>
1384
				<tbody>
1385
				<?php
1386
					$i = 0;
1387
					foreach($a_server as $server):
1388
						$disabled = "NO";
1389
						if (isset($server['disable']))
1390
							$disabled = "YES";
1391
				?>
1392
				<tr>
1393
					<td class="listlr" ondblclick="document.location='vpn_openvpn_server.php?act=edit&id=<?=$i;?>'">
1394
						<?=$disabled;?>
1395
					</td>
1396
					<td class="listr" ondblclick="document.location='vpn_openvpn_server.php?act=edit&id=<?=$i;?>'">
1397
						<?=htmlspecialchars($server['protocol']);?> / <?=htmlspecialchars($server['local_port']);?>
1398
					</td>
1399
					<td class="listr" ondblclick="document.location='vpn_openvpn_server.php?act=edit&id=<?=$i;?>'">
1400
						<?=htmlspecialchars($server['tunnel_network']);?>
1401
					</td>
1402
					<td class="listbg" ondblclick="document.location='vpn_openvpn_server.php?act=edit&id=<?=$i;?>'">
1403
						<?=htmlspecialchars($server['description']);?>
1404
					</td>
1405
					<td valign="middle" nowrap class="list">
1406
						<a href="vpn_openvpn_server.php?act=edit&id=<?=$i;?>">
1407
							<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit server"); ?>" width="17" height="17" border="0">
1408
						</a>
1409
						&nbsp;
1410
						<a href="vpn_openvpn_server.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this server?"); ?>')">
1411
							<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete server"); ?>" width="17" height="17" border="0">
1412
						</a>
1413
					</td>
1414
				</tr>
1415
				<?php
1416
					$i++;
1417
					endforeach;
1418
				?>
1419
				</tbody>
1420
				<tfoot>
1421
				<tr>
1422
					<td class="list" colspan="4"></td>
1423
					<td class="list">
1424
						<a href="vpn_openvpn_server.php?act=new"><img src="./themes/<?=$g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("add server"); ?>" width="17" height="17" border="0">
1425
						</a>
1426
					</td>
1427
				</tr>
1428
				</tfoot>
1429
			</table>
1430

    
1431
			<?=gettext("Additional OpenVPN servers can be added here.");?>
1432

    
1433
			<?php endif; ?>
1434

    
1435
		</td>
1436
	</tr>
1437
</table>
1438
<script language="JavaScript">
1439
<!--
1440
mode_change();
1441
autokey_change();
1442
tlsauth_change();
1443
gwredir_change();
1444
dns_domain_change();
1445
dns_server_change();
1446
wins_server_change();
1447
ntp_server_change();
1448
netbios_change();
1449
//-->
1450
</script>
1451
</body>
1452
<?php include("fend.inc"); ?>
1453

    
1454
<?php
1455

    
1456
/* local utility functions */
1457

    
1458
function set_checked($var,& $chk) {
1459
    if($var)
1460
        $chk = 'checked';
1461
    else
1462
        $chk = '';
1463
}
1464

    
1465
?>
(1-1/2)