Project

General

Profile

Download (54.2 KB) Statistics
| Branch: | Tag: | Revision:
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['dev_mode'] = "tun";
95
	$pconfig['interface'] = "wan";
96
	$pconfig['local_port'] = openvpn_port_next('UDP');
97
	$pconfig['pool_enable'] = "yes";
98
}
99

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

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

    
104
		$pconfig['disable'] = isset($a_server[$id]['disable']);
105
		$pconfig['mode'] = $a_server[$id]['mode'];
106
		$pconfig['protocol'] = $a_server[$id]['protocol'];
107
		$pconfig['authmode'] = $a_server[$id]['authmode'];
108
		$pconfig['dev_mode'] = $a_server[$id]['dev_mode'];
109
		$pconfig['interface'] = $a_server[$id]['interface'];
110
		if (!empty($a_server[$id]['ipaddr'])) {
111
			$pconfig['interface'] = $pconfig['interface'] . '|' . $a_server[$id]['ipaddr'];
112
		}
113
		$pconfig['local_port'] = $a_server[$id]['local_port'];
114
		$pconfig['description'] = $a_server[$id]['description'];
115
		$pconfig['custom_options'] = $a_server[$id]['custom_options'];
116

    
117
		if ($pconfig['mode'] != "p2p_shared_key") {
118
			if ($a_server[$id]['tls']) {
119
				$pconfig['tlsauth_enable'] = "yes";
120
				$pconfig['tls'] = base64_decode($a_server[$id]['tls']);
121
			}
122
			$pconfig['caref'] = $a_server[$id]['caref'];
123
			$pconfig['crlref'] = $a_server[$id]['crlref'];
124
			$pconfig['certref'] = $a_server[$id]['certref'];
125
			$pconfig['dh_length'] = $a_server[$id]['dh_length'];
126
			if ($pconfig['mode'] == "server_tls_user")
127
				$pconfig['strictusercn'] = $a_server[$id]['strictusercn'];
128
		} else
129
			$pconfig['shared_key'] = base64_decode($a_server[$id]['shared_key']);
130
		$pconfig['crypto'] = $a_server[$id]['crypto'];
131
		$pconfig['engine'] = $a_server[$id]['engine'];
132

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

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

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

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

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

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

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

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

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

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

    
187
if ($_POST) {
188

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
296
		$server = array();
297

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
393
include("head.inc");
394

    
395
?>
396

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

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

    
475
function autokey_change() {
476

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

    
483
function tlsauth_change() {
484

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

    
492
	autotls_change();
493
}
494

    
495
function autotls_change() {
496

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

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

    
509
function gwredir_change() {
510

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

    
517
function dns_domain_change() {
518

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

    
525
function dns_server_change() {
526

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

    
533
function wins_server_change() {
534

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

    
541
function ntp_server_change() {
542

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

    
549
function netbios_change() {
550

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

    
560
//-->
561
</script>
562
<?php
563
if (!$savemsg)
564
	$savemsg = "";
565
if (count($a_ca) == 0)
566
	$savemsg .= "You have no Certificate Authorities defined. You can visit the <a href=\"system_camanager.php\">Certificate Manager</a> or use the <a href=\"wizard.php?xml=openvpn_wizard.xml\">Wizard.</a> to create one. ";
567
if (count($a_cert) == 0)
568
	$savemsg .= "<br/>You have no Certificates defined. You can visit the <a href=\"system_camanager.php\">Certificate Manager</a> or use the <a href=\"wizard.php?xml=openvpn_wizard.xml\">Wizard.</a> to create one. ";
569

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

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

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

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

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

    
1358
				<br/>
1359

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

    
1374
			<?php else: ?>
1375

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

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

    
1435
			<?php endif; ?>
1436

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

    
1456
<?php
1457

    
1458
/* local utility functions */
1459

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

    
1467
?>
(218-218/225)