Project

General

Profile

Download (39.1 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

    
38
require("guiconfig.inc");
39

    
40
$pgtitle = array("OpenVPN", "Server");
41

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

    
45
$a_server = &$config['openvpn']['openvpn-server'];
46

    
47
$id = $_GET['id'];
48
if (isset($_POST['id']))
49
	$id = $_POST['id'];
50

    
51
$act = $_GET['act'];
52
if (isset($_POST['act']))
53
	$act = $_POST['act'];
54

    
55
if ($_GET['act'] == "del") {
56

    
57
	if (!$a_server[$id]) {
58
		pfSenseHeader("vpn_openvpn_server.php");
59
		exit;
60
	}
61

    
62
	openvpn_delete('server', $a_server[$id]);
63
	unset($a_server[$id]);
64
	write_config();
65
	$savemsg = gettext("Server successfully deleted")."<br/>";
66
}
67

    
68
if($_GET['act']=="new"){
69
	$pconfig['autokey_enable'] = "yes";
70
	$pconfig['tlsauth_enable'] = "yes";
71
	$pconfig['autotls_enable'] = "yes";
72
	$pconfig['dh_length'] = 1024;
73
	$pconfig['interface'] = "wan";
74
	$pconfig['local_port'] = openvpn_port_next('UDP');
75
	$pconfig['pool_enable'] = "yes";
76
}
77

    
78
if($_GET['act']=="edit"){
79

    
80
	if (isset($id) && $a_server[$id]) {
81

    
82
		$pconfig['disable'] = $a_server[$id]['disable'];
83
		$pconfig['mode'] = $a_server[$id]['mode'];
84
		$pconfig['protocol'] = $a_server[$id]['protocol'];
85
		$pconfig['interface'] = $a_server[$id]['interface'];
86
		$pconfig['local_port'] = $a_server[$id]['local_port'];
87
		$pconfig['description'] = $a_server[$id]['description'];
88

    
89
		if ($pconfig['mode'] != "p2p_shared_key") {
90
			if ($a_server[$id]['tls']) {
91
				$pconfig['tlsauth_enable'] = "yes";
92
				$pconfig['tls'] = base64_decode($a_server[$id]['tls']);
93
			}
94
			$pconfig['caref'] = $a_server[$id]['caref'];
95
			$pconfig['certref'] = $a_server[$id]['certref'];
96
			$pconfig['dh_length'] = $a_server[$id]['dh_length'];
97
		} else
98
			$pconfig['shared_key'] = base64_decode($a_server[$id]['shared_key']);
99
		$pconfig['crypto'] = $a_server[$id]['crypto'];
100

    
101
		$pconfig['tunnel_network'] = $a_server[$id]['tunnel_network'];
102
		$pconfig['remote_network'] = $a_server[$id]['remote_network'];
103
		$pconfig['gwredir'] = $a_server[$id]['gwredir'];
104
		$pconfig['local_network'] = $a_server[$id]['local_network'];
105
		$pconfig['maxclients'] = $a_server[$id]['maxclients'];
106
		$pconfig['compression'] = $a_server[$id]['compression'];
107
		$pconfig['passtos'] = $a_server[$id]['passtos'];
108
		$pconfig['client2client'] = $a_server[$id]['client2client'];
109

    
110
		$pconfig['pool_enable'] = $a_server[$id]['pool_enable'];
111

    
112
		$pconfig['dns_domain'] = $a_server[$id]['dns_domain'];
113
		if ($pconfig['dns_domain'])
114
			$pconfig['dns_domain_enable'] = true;
115

    
116
		$pconfig['dns_server1'] = $a_server[$id]['dns_server1'];
117
		$pconfig['dns_server2'] = $a_server[$id]['dns_server2'];
118
		$pconfig['dns_server3'] = $a_server[$id]['dns_server3'];
119
		$pconfig['dns_server4'] = $a_server[$id]['dns_server4'];
120
		if ($pconfig['dns_server1'] ||
121
			$pconfig['dns_server2'] ||
122
			$pconfig['dns_server3'] ||
123
			$pconfig['dns_server4'])
124
			$pconfig['dns_server_enable'] = true;
125

    
126
		$pconfig['ntp_server1'] = $a_server[$id]['ntp_server1'];
127
		$pconfig['ntp_server2'] = $a_server[$id]['ntp_server2'];
128
		if ($pconfig['ntp_server1'] ||
129
			$pconfig['ntp_server2'])
130
			$pconfig['ntp_server_enable'] = true;
131

    
132
		$pconfig['netbios_enable'] = $a_server[$id]['netbios_enable'];
133
		$pconfig['netbios_ntype'] = $a_server[$id]['netbios_ntype'];
134
		$pconfig['netbios_scope'] = $a_server[$id]['netbios_scope'];
135

    
136
		$pconfig['wins_server1'] = $a_server[$id]['wins_server1'];
137
		$pconfig['wins_server2'] = $a_server[$id]['wins_server2'];
138
		if ($pconfig['wins_server1'] ||
139
			$pconfig['wins_server2'])
140
			$pconfig['wins_server_enable'] = true;
141

    
142
		$pconfig['nbdd_server1'] = $a_server[$id]['nbdd_server1'];
143
		if ($pconfig['nbdd_server1'])
144
			$pconfig['nbdd_server_enable'] = true;
145

    
146
		// just in case the modes switch
147
		$pconfig['autokey_enable'] = "yes";
148
		$pconfig['autotls_enable'] = "yes";
149
	}
150
}
151

    
152
if ($_POST) {
153

    
154
	unset($input_errors);
155
	$pconfig = $_POST;
156

    
157
	if (isset($id) && $a_server[$id])
158
		$vpnid = $a_server[$id]['vpnid'];
159
	else
160
		$vpnid = 0;
161

    
162
	if ($server['mode'] != "p2p_shared_key")
163
		$tls_mode = true;
164
	else
165
		$tls_mode = false;
166

    
167
	/* input validation */
168
	if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
169
		$input_errors[] = $result;
170

    
171
	if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network'))
172
		$input_errors[] = $result;
173

    
174
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'Remote network'))
175
		$input_errors[] = $result;
176

    
177
	if ($result = openvpn_validate_cidr($pconfig['local_network'], 'Local network'))
178
		$input_errors[] = $result;
179

    
180
	if (openvpn_port_used($pconfig['protocol'], $pconfig['local_port']) != $vpnid)
181
		$input_errors[] = "The specified 'Local port' is in use. Please select another value";
182

    
183
	if (!$tls_mode && !$pconfig['autokey_enable'])
184
		if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
185
			!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
186
			$input_errors[] = "The field 'Shared Key' does not appear to be valid";
187

    
188
	if ($tls_mode && $pconfig['tlsauth_enable'] && !$pconfig['autotls_enable'])
189
		if (!strstr($pconfig['tls'], "-----BEGIN OpenVPN Static key V1-----") ||
190
			!strstr($pconfig['tls'], "-----END OpenVPN Static key V1-----"))
191
			$input_errors[] = "The field 'TLS Authentication Key' does not appear to be valid";
192

    
193
	if ($pconfig['dns_server_enable']) {
194
		if (!empty($pconfig['dns_server1']) && !is_ipaddr(trim($pconfig['dns_server1'])))
195
			$input_errors[] = "The field 'DNS Server #1' must contain a valid IP address";
196
		if (!empty($pconfig['dns_server2']) && !is_ipaddr(trim($pconfig['dns_server2'])))
197
			$input_errors[] = "The field 'DNS Server #2' must contain a valid IP address";
198
		if (!empty($pconfig['dns_server3']) && !is_ipaddr(trim($pconfig['dns_server3'])))
199
			$input_errors[] = "The field 'DNS Server #3' must contain a valid IP address";
200
		if (!empty($pconfig['dns_server4']) && !is_ipaddr(trim($pconfig['dns_server4'])))
201
			$input_errors[] = "The field 'DNS Server #4' must contain a valid IP address";
202
	}
203

    
204
	if ($pconfig['ntp_server_enable']) {
205
		if (!empty($pconfig['ntp_server1']) && !is_ipaddr(trim($pconfig['ntp_server1'])))
206
			$input_errors[] = "The field 'NTP Server #1' must contain a valid IP address";
207
		if (!empty($pconfig['ntp_server2']) && !is_ipaddr(trim($pconfig['ntp_server2'])))
208
			$input_errors[] = "The field 'NTP Server #2' must contain a valid IP address";
209
		if (!empty($pconfig['ntp_server3']) && !is_ipaddr(trim($pconfig['ntp_server3'])))
210
			$input_errors[] = "The field 'NTP Server #3' must contain a valid IP address";
211
		if (!empty($pconfig['ntp_server4']) && !is_ipaddr(trim($pconfig['ntp_server4'])))
212
			$input_errors[] = "The field 'NTP Server #4' must contain a valid IP address";
213
	}
214

    
215
	if ($pconfig['netbios_enable']) {
216
		if ($pconfig['wins_server_enable']) {
217
			if (!empty($pconfig['wins_server1']) && !is_ipaddr(trim($pconfig['wins_server1'])))
218
				$input_errors[] = "The field 'WINS Server #1' must contain a valid IP address";
219
			if (!empty($pconfig['wins_server2']) && !is_ipaddr(trim($pconfig['wins_server2'])))
220
				$input_errors[] = "The field 'WINS Server #2' must contain a valid IP address";
221
		}
222
		if ($pconfig['nbdd_server_enable'])
223
			if (!empty($pconfig['nbdd_server1']) && !is_ipaddr(trim($pconfig['nbdd_server1'])))
224
				$input_errors[] = "The field 'NetBIOS Data Distribution Server #1' must contain a valid IP address";
225
	}
226

    
227
	if ($pconfig['maxclients'] && !is_numeric($pconfig['maxclients']))
228
		$input_errors[] = "The field 'Concurrent connections' must be numeric.";
229

    
230
	if (!$tls_mode) {
231
		$reqdfields = array('shared_key');
232
		$reqfieldsn = array('Shared key');
233
    } else {
234
		$reqdfields = explode(" ", "caref certref");
235
		$reqdfieldsn = explode(",", "Certificate Authority,Certificate");;
236
	}
237

    
238
	$reqdfields[] = 'tunnel_network';
239
	$reqdfieldsn[] = 'Tunnel network';
240

    
241
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
242
	
243
	if (!$input_errors) {
244

    
245
		$server = array();
246

    
247
		if ($vpnid)
248
			$server['vpnid'] = $vpnid;
249
		else
250
			$server['vpnid'] = openvpn_vpnid_next();
251

    
252
		$server['disable'] = $pconfig['disable'];
253
		$server['mode'] = $pconfig['mode'];
254
		$server['protocol'] = $pconfig['protocol'];
255
		$server['interface'] = $pconfig['interface'];
256
		$server['local_port'] = $pconfig['local_port'];
257
		$server['description'] = $pconfig['description'];
258

    
259
		if ($tls_mode) {
260
			if ($pconfig['tlsauth_enable']) {
261
				if ($pconfig['autotls_enable'])
262
					$pconfig['tls'] = openvpn_create_key();
263
				$server['tls'] = base64_encode($pconfig['tls']);
264
			}
265
			$server['caref'] = $pconfig['caref'];
266
			$server['certref'] = $pconfig['certref'];
267
			$server['dh_length'] = $pconfig['dh_length'];
268
		} else {
269
			if ($pconfig['autokey_enable'])
270
				$pconfig['shared_key'] = openvpn_create_key();
271
			$server['shared_key'] = base64_encode($pconfig['shared_key']);
272
		}
273
		$server['crypto'] = $pconfig['crypto'];
274

    
275
		$server['tunnel_network'] = $pconfig['tunnel_network'];
276
		$server['remote_network'] = $pconfig['remote_network'];
277
		$server['gwredir'] = $pconfig['gwredir'];
278
		$server['local_network'] = $pconfig['local_network'];
279
		$server['maxclients'] = $pconfig['maxclients'];
280
		$server['compression'] = $pconfig['compression'];
281
		$server['passtos'] = $pconfig['passtos'];
282
		$server['client2client'] = $pconfig['client2client'];
283

    
284
		$server['pool_enable'] = $pconfig['pool_enable'];
285

    
286
		if ($pconfig['dns_domain_enable'])
287
			$server['dns_domain'] = $pconfig['dns_domain'];
288

    
289
		if ($pconfig['dns_server_enable']) {
290
			$server['dns_server1'] = $pconfig['dns_server1'];
291
			$server['dns_server2'] = $pconfig['dns_server2'];
292
			$server['dns_server3'] = $pconfig['dns_server3'];
293
			$server['dns_server4'] = $pconfig['dns_server4'];
294
		}
295

    
296
		if ($pconfig['ntp_server_enable']) {
297
			$server['ntp_server1'] = $pconfig['ntp_server1'];
298
			$server['ntp_server2'] = $pconfig['ntp_server2'];
299
		}
300

    
301
		$server['netbios_enable'] = $pconfig['netbios_enable'];
302
		$server['netbios_ntype'] = $pconfig['netbios_ntype'];
303
		$server['netbios_scope'] = $pconfig['netbios_scope'];
304

    
305
		if ($pconfig['netbios_enable']) {
306

    
307
			if ($pconfig['wins_server_enable']) {
308
				$server['wins_server1'] = $pconfig['wins_server1'];
309
				$server['wins_server2'] = $pconfig['wins_server2'];
310
			}
311

    
312
			if ($pconfig['dns_server_enable'])
313
				$server['nbdd_server1'] = $pconfig['nbdd_server1'];
314
		}
315
	
316
		if (isset($id) && $a_server[$id])
317
			$a_server[$id] = $server;
318
		else
319
			$a_server[] = $server;
320

    
321
		openvpn_resync('server', $server);
322
		write_config();
323
		
324
		header("Location: vpn_openvpn_server.php");
325
		exit;
326
	}
327
}
328

    
329
include("head.inc");
330

    
331
?>
332

    
333
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
334
<?php include("fbegin.inc"); ?>
335
<script language="JavaScript">
336
<!--
337

    
338
function mode_change() {
339
	index = document.iform.mode.selectedIndex;
340
	value = document.iform.mode.options[index].value;
341
	switch(value) {
342
		case "p2p_tls":
343
		case "server_tls":
344
		case "server_user":
345
		case "server_tls_user":
346
			document.getElementById("tls").style.display="";
347
			document.getElementById("tls_ca").style.display="";
348
			document.getElementById("tls_cert").style.display="";
349
			document.getElementById("tls_dh").style.display="";
350
			document.getElementById("psk").style.display="none";
351
			break;
352
		case "p2p_shared_key":
353
			document.getElementById("tls").style.display="none";
354
			document.getElementById("tls_ca").style.display="none";
355
			document.getElementById("tls_cert").style.display="none";
356
			document.getElementById("tls_dh").style.display="none";
357
			document.getElementById("psk").style.display="";
358
			break;
359
	}
360
	switch(value) {
361
		case "p2p_tls":
362
		case "p2p_shared_key":
363
			document.getElementById("client_opts").style.display="none";
364
			document.getElementById("remote_opts").style.display="";
365
			break;
366
		default:
367
			document.getElementById("client_opts").style.display="";
368
			document.getElementById("remote_opts").style.display="none";
369
			break;
370
	}
371
}
372

    
373
function autokey_change() {
374

    
375
	if (document.iform.autokey_enable.checked)
376
		document.getElementById("autokey_opts").style.display="none";
377
	else
378
		document.getElementById("autokey_opts").style.display="";
379
}
380

    
381
function tlsauth_change() {
382

    
383
<?php if (!$pconfig['tls']): ?>
384
	if (document.iform.tlsauth_enable.checked)
385
		document.getElementById("tlsauth_opts").style.display="";
386
	else
387
		document.getElementById("tlsauth_opts").style.display="none";
388
<?php endif; ?>
389

    
390
	autotls_change();
391
}
392

    
393
function autotls_change() {
394

    
395
<?php if (!$pconfig['tls']): ?>
396
	autocheck = document.iform.autotls_enable.checked;
397
<?php else: ?>
398
	autocheck = false;
399
<?php endif; ?>
400

    
401
	if (document.iform.tlsauth_enable.checked && !autocheck)
402
		document.getElementById("autotls_opts").style.display="";
403
	else
404
		document.getElementById("autotls_opts").style.display="none";
405
}
406

    
407
function gwredir_change() {
408

    
409
	if (document.iform.gwredir.checked)
410
		document.getElementById("local_opts").style.display="none";
411
	else
412
		document.getElementById("local_opts").style.display="";
413
}
414

    
415
function dns_domain_change() {
416

    
417
	if (document.iform.dns_domain_enable.checked)
418
		document.getElementById("dns_domain_data").style.display="";
419
	else
420
		document.getElementById("dns_domain_data").style.display="none";
421
}
422

    
423
function dns_server_change() {
424

    
425
	if (document.iform.dns_server_enable.checked)
426
		document.getElementById("dns_server_data").style.display="";
427
	else
428
		document.getElementById("dns_server_data").style.display="none";
429
}
430

    
431
function wins_server_change() {
432

    
433
	if (document.iform.wins_server_enable.checked)
434
		document.getElementById("wins_server_data").style.display="";
435
	else
436
		document.getElementById("wins_server_data").style.display="none";
437
}
438

    
439
function ntp_server_change() {
440

    
441
	if (document.iform.ntp_server_enable.checked)
442
		document.getElementById("ntp_server_data").style.display="";
443
	else
444
		document.getElementById("ntp_server_data").style.display="none";
445
}
446

    
447
function netbios_change() {
448

    
449
	if (document.iform.netbios_enable.checked) {
450
		document.getElementById("netbios_data").style.display="";
451
		document.getElementById("wins_opts").style.display="";
452
	} else {
453
		document.getElementById("netbios_data").style.display="none";
454
		document.getElementById("wins_opts").style.display="none";
455
	}
456
}
457

    
458
//-->
459
</script>
460
<?php
461
	if ($input_errors)
462
		print_input_errors($input_errors);
463
	if ($savemsg)
464
		print_info_box($savemsg);
465
?>
466
<table width="100%" border="0" cellpadding="0" cellspacing="0">
467
	<tr>
468
		<td class="tabnavtbl">
469
			<ul id="tabnav">
470
			<?php 
471
				$tab_array = array();
472
				$tab_array[] = array(gettext("Server"), true, "vpn_openvpn_server.php");
473
				$tab_array[] = array(gettext("Client"), false, "vpn_openvpn_client.php");
474
				$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
475
				add_package_tabs("OpenVPN", $tab_array);
476
				display_top_tabs($tab_array);
477
			?>
478
			</ul>
479
		</td>
480
	</tr>    
481
	<tr>
482
		<td class="tabcont">
483

    
484
			<?php if($act=="new" || $act=="edit"): ?>
485

    
486
			<form action="vpn_openvpn_server.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
487
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
488
					<tr>
489
						<td colspan="2" valign="top" class="listtopic">General information</td>
490
					</tr>
491
					<tr>
492
						<td width="22%" valign="top" class="vncellreq">Disabled</td>
493
						<td width="78%" class="vtable">
494
							<table border="0" cellpadding="0" cellspacing="0">
495
								<tr>
496
									<td>
497
										<?php set_checked($pconfig['disable'],$chk); ?>
498
										<input name="disable" type="checkbox" value="yes" <?=$chk;?>/>
499
									</td>
500
									<td>
501
										&nbsp;
502
										<span class="vexpl">
503
											<strong>Disable this server</strong><br>
504
										</span>
505
									</td>
506
								</tr>
507
							</table>
508
							Set this option to disable this server without removing it from the list.
509
						</td>
510
					</tr>
511
					<tr>
512
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Server Mode");?></td>
513
							<td width="78%" class="vtable">
514
							<select name='mode' id='mode' class="formselect" onchange='mode_change()'>
515
							<?php
516
								foreach ($openvpn_server_modes as $name => $desc):
517
									$selected = "";
518
									if ($pconfig['mode'] == $name)
519
										$selected = "selected";
520
							?>
521
								<option value="<?=$name;?>" <?=$selected;?>><?=$desc;?></option>
522
							<?php endforeach; ?>
523
							</select>
524
						</td>
525
					</tr>
526
					<tr>
527
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
528
							<td width="78%" class="vtable">
529
							<select name='protocol' class="formselect">
530
							<?php
531
								foreach ($openvpn_prots as $prot):
532
									$selected = "";
533
									if ($pconfig['protocol'] == $prot)
534
										$selected = "selected";
535
							?>
536
								<option value="<?=$prot;?>" <?=$selected;?>><?=$prot;?></option>
537
							<?php endforeach; ?>
538
							</select>
539
							</td>
540
					</tr>
541
					<tr>
542
						<td width="22%" valign="top" class="vncellreq">Interface</td>
543
						<td width="78%" class="vtable">
544
							<select name="interface" class="formselect">
545
								<?php
546
									$interfaces = get_configured_interface_with_descr();
547
									foreach ($interfaces as $iface => $ifacename):
548
										$selected = "";
549
										if ($iface == $pconfig['interface'])
550
											$selected = "selected";
551
								?>
552
									<option value="<?=$iface;?>" <?=$selected;?>>
553
										<?=htmlspecialchars($ifacename);?>
554
									</option>
555
								<?php endforeach; ?>
556
							</select> <br>
557
						</td>
558
					</tr>
559
					<tr>
560
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Local port");?></td>
561
						<td width="78%" class="vtable">
562
							<input name="local_port" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['local_port']);?>"/>
563
						</td>
564
					</tr>
565
					<tr> 
566
						<td width="22%" valign="top" class="vncell">Description</td>
567
						<td width="78%" class="vtable"> 
568
							<input name="description" type="text" class="formfld unknown" size="30" value="<?=htmlspecialchars($pconfig['description']);?>">
569
							<br>
570
							You may enter a description here for your reference (not parsed).
571
						</td>
572
					</tr>
573
					<tr>
574
						<td colspan="2" class="list" height="12"></td>
575
					</tr>
576
					<tr>
577
						<td colspan="2" valign="top" class="listtopic">Cryptographic Settings</td>
578
					</tr>
579
					<tr id="tls">
580
						<td width="22%" valign="top" class="vncellreq">TLS Authentication</td>
581
						<td width="78%" class="vtable">
582
							<table border="0" cellpadding="2" cellspacing="0">
583
								<tr>
584
									<td>
585
										<?php set_checked($pconfig['tlsauth_enable'],$chk); ?>
586
										<input name="tlsauth_enable" id="tlsauth_enable" type="checkbox" value="yes" <?=$chk;?> onClick="tlsauth_change()">
587
									</td>
588
									<td>
589
										<span class="vexpl">
590
											Enable authentication of TLS packets.
591
										</span>
592
									</td>
593
								</tr>
594
							</table>
595
							<?php if (!$pconfig['tls']): ?>
596
							<table border="0" cellpadding="2" cellspacing="0" id='tlsauth_opts'>
597
								<tr>
598
									<td>
599
										<?php set_checked($pconfig['autotls_enable'],$chk); ?>
600
										<input name="autotls_enable" id="autotls_enable" type="checkbox" value="yes" <?=$chk;?> onClick="autotls_change()">
601
									</td>
602
									<td>
603
										<span class="vexpl">
604
											Automatically generate a shared TLS authentication key.
605
										</span>
606
									</td>
607
								</tr>
608
							</table>
609
							<?php endif; ?>
610
							<table border="0" cellpadding="2" cellspacing="0" id='autotls_opts'>
611
								<tr>
612
									<td>
613
										<textarea name="tls" cols="65" rows="7" class="formpre"><?=htmlspecialchars($pconfig['tls']);?></textarea>
614
										<br/>
615
										Paste your shared key here.
616
									</td>
617
								</tr>
618
							</table>
619
						</td>
620
					</tr>
621
					<tr id="tls_ca">
622
						<td width="22%" valign="top" class="vncellreq">Peer Certificate Authority</td>
623
							<td width="78%" class="vtable">
624
							<select name='caref' class="formselect">
625
							<?php
626
								foreach ($config['system']['ca'] as $ca):
627
									$selected = "";
628
									if ($pconfig['caref'] == $ca['refid'])
629
										$selected = "selected";
630
							?>
631
								<option value="<?=$ca['refid'];?>" <?=$selected;?>><?=$ca['name'];?></option>
632
							<?php endforeach; ?>
633
							</select>
634
							</td>
635
					</tr>
636
					<tr id="tls_cert">
637
						<td width="22%" valign="top" class="vncellreq">Server Certificate</td>
638
							<td width="78%" class="vtable">
639
							<select name='certref' class="formselect">
640
							<?php
641
								foreach ($config['system']['cert'] as $cert):
642
									$selected = "";
643
									if ($pconfig['certref'] == $cert['refid'])
644
										$selected = "selected";
645
							?>
646
								<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['name'];?></option>
647
							<?php endforeach; ?>
648
							</select>
649
						</td>
650
					</tr>
651
					<tr id="tls_dh">
652
						<td width="22%" valign="top" class="vncellreq">DH Parameters Length</td>
653
						<td width="78%" class="vtable">
654
							<select name="dh_length" class="formselect">
655
								<?php
656
									foreach ($openvpn_dh_lengths as $length):
657
									$selected = '';
658
									if ($length == $pconfig['dh_length'])
659
										$selected = ' selected';
660
								?>
661
								<option<?=$selected?>><?=$length;?></option>
662
								<?php endforeach; ?>
663
							</select>
664
							<span class="vexpl">
665
								bits
666
							</span>
667
						</td>
668
					</tr>
669
					<tr id="psk">
670
						<td width="22%" valign="top" class="vncellreq">Shared Key</td>
671
						<td width="78%" class="vtable">
672
							<?php if (!$pconfig['shared_key']): ?>
673
							<table border="0" cellpadding="2" cellspacing="0">
674
								<tr>
675
									<td>
676
										<?php set_checked($pconfig['autokey_enable'],$chk); ?>
677
										<input name="autokey_enable" type="checkbox" value="yes" <?=$chk;?> onClick="autokey_change()">
678
									</td>
679
									<td>
680
										<span class="vexpl">
681
											Automatically generate a shared key.
682
										</span>
683
									</td>
684
								</tr>
685
							</table>
686
							<?php endif; ?>
687
							<table border="0" cellpadding="2" cellspacing="0" id='autokey_opts'>
688
								<tr>
689
									<td>
690
										<textarea name="shared_key" cols="65" rows="7" class="formpre"><?=htmlspecialchars($pconfig['shared_key']);?></textarea>
691
										<br/>
692
										Paste your shared key here.
693
									</td>
694
								</tr>
695
							</table>
696
						</td>
697
					</tr>
698
					<tr>
699
						<td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
700
						<td width="78%" class="vtable">
701
							<select name="crypto" class="formselect">
702
								<?php
703
									$cipherlist = openvpn_get_cipherlist();
704
									foreach ($cipherlist as $name => $desc):
705
									$selected = '';
706
									if ($name == $pconfig['crypto'])
707
										$selected = ' selected';
708
								?>
709
								<option value="<?=$name;?>"<?=$selected?>>
710
									<?=htmlspecialchars($desc);?>
711
								</option>
712
								<?php endforeach; ?>
713
							</select>
714
						</td>
715
					</tr>
716
					<tr>
717
						<td colspan="2" class="list" height="12"></td>
718
					</tr>
719
					<tr>
720
						<td colspan="2" valign="top" class="listtopic">Tunnel Settings</td>
721
					</tr>
722
					<tr>
723
						<td width="22%" valign="top" class="vncellreq">Tunnel Network</td>
724
						<td width="78%" class="vtable">
725
							<input name="tunnel_network" type="text" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['tunnel_network']);?>">
726
							<br>
727
							This is the virtual network used for private
728
							communications between this server and client
729
							hosts expressed using CIDR (eg. 10.0.8.0/24).
730
							The first network address will be assigned to
731
							the	server virtual interface. The remaining
732
							network addresses can optionally be assigned
733
							to connecting clients. (see Address Pool)
734
						</td>
735
					</tr>
736
					<tr>
737
						<td width="22%" valign="top" class="vncell">Redirect Gateway</td>
738
						<td width="78%" class="vtable">
739
							<table border="0" cellpadding="2" cellspacing="0">
740
								<tr>
741
									<td>
742
										<?php set_checked($pconfig['gwredir'],$chk); ?>
743
										<input name="gwredir" type="checkbox" value="yes" <?=$chk;?> onClick="gwredir_change()"/>
744
									</td>
745
									<td>
746
										<span class="vexpl">
747
											Force all client generated traffic through the tunnel.
748
										</span>
749
									</td>
750
								</tr>
751
							</table>
752
						</td>
753
					</tr>
754
					<tr id="local_opts">
755
						<td width="22%" valign="top" class="vncell">Local Network</td>
756
						<td width="78%" class="vtable">
757
							<input name="local_network" type="text" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['local_network']);?>">
758
							<br>
759
							This is the network that will be accessable
760
							from the remote endpoint. Expressed as a CIDR
761
							range. You may leave this blank if you don't
762
							want to add a route to the local network
763
							through this tunnel on the remote machine.
764
							This is generally set to your LAN network.
765
						</td>
766
					</tr>
767
					<tr id="remote_opts">
768
						<td width="22%" valign="top" class="vncell">Remote Network</td>
769
						<td width="78%" class="vtable">
770
							<input name="remote_network" type="text" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['remote_network']);?>">
771
							<br>
772
							This is a network that will be routed through
773
							the tunnel, so that a site-to-site VPN can be
774
							established without manually changing the
775
							routing tables. Expressed as a CIDR range. If
776
							this is a site-to-site VPN, enter here the
777
							remote LAN here. You may leave this blank if
778
							you don't want a site-to-site VPN.
779
						</td>
780
					</tr>
781
					<tr>
782
						<td width="22%" valign="top" class="vncell"><?=gettext("Concurrent connections");?></td>
783
						<td width="78%" class="vtable">
784
							<input name="maxclients" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['maxclients']);?>"/>
785
							<br/>
786
							Specify the maximum number of clients allowed to concurrently connect to this server.
787
						</td>
788
					</tr>
789
					<tr>
790
						<td width="22%" valign="top" class="vncell">Compression</td>
791
						<td width="78%" class="vtable">
792
							<table border="0" cellpadding="2" cellspacing="0">
793
								<tr>
794
									<td>
795
										<?php set_checked($pconfig['compression'],$chk); ?>
796
										<input name="compression" type="checkbox" value="yes" <?=$chk;?>>
797
									</td>
798
									<td>
799
										<span class="vexpl">
800
											Compress tunnel packets using the LZO algorithm.
801
										</span>
802
									</td>
803
								</tr>
804
							</table>
805
						</td>
806
					</tr>
807
					<tr>
808
						<td width="22%" valign="top" class="vncell">Type-of-Service</td>
809
						<td width="78%" class="vtable">
810
							<table border="0" cellpadding="2" cellspacing="0">
811
								<tr>
812
									<td>
813
										<?php set_checked($pconfig['passtos'],$chk); ?>
814
										<input name="passtos" type="checkbox" value="yes" <?=$chk;?>>
815
									</td>
816
									<td>
817
										<span class="vexpl">
818
											Set the TOS IP header value of tunnel packets to match the encapsulated packet value.
819
										</span>
820
									</td>
821
								</tr>
822
							</table>
823
						</td>
824
					</tr>
825
					<tr>
826
						<td width="22%" valign="top" class="vncell">Inter-client communication</td>
827
						<td width="78%" class="vtable">
828
							<table border="0" cellpadding="2" cellspacing="0">
829
								<tr>
830
									<td>
831
										<?php set_checked($pconfig['client2client'],$chk); ?>
832
										<input name="client2client" type="checkbox" value="yes" <?=$chk;?>/>
833
									</td>
834
									<td>
835
										<span class="vexpl">
836
											Allow communication between clients connected to this server
837
										</span>
838
									</td>
839
								</tr>
840
							</table>
841
						</td>
842
					</tr>
843
				</table>
844

    
845
				<table width="100%" border="0" cellpadding="6" cellspacing="0" id="client_opts">
846
					<tr>
847
						<td colspan="2" class="list" height="12"></td>
848
					</tr>
849
					<tr>
850
						<td colspan="2" valign="top" class="listtopic">Client Settings</td>
851
					</tr>
852
					<tr>
853
						<td width="22%" valign="top" class="vncell">Address Pool</td>
854
						<td width="78%" class="vtable">
855
							<table border="0" cellpadding="2" cellspacing="0">
856
								<tr>
857
									<td>
858
										<?php set_checked($pconfig['pool_enable'],$chk); ?>
859
										<input name="pool_enable" type="checkbox" id="pool_enable" value="yes" <?=$chk;?>">
860
									</td>
861
									<td>
862
										<span class="vexpl">
863
											Provide a virtual adapter IP address to clients (see Tunnel Network)<br>
864
										</span>
865
									</td>
866
								</tr>
867
							</table>
868
						</td>
869
					</tr>
870
					<tr>
871
						<td width="22%" valign="top" class="vncell">DNS Default Domain</td>
872
						<td width="78%" class="vtable">
873
							<table border="0" cellpadding="2" cellspacing="0">
874
								<tr>
875
									<td>
876
										<?php set_checked($pconfig['dns_domain_enable'],$chk); ?>
877
										<input name="dns_domain_enable" type="checkbox" id="dns_domain_enable" value="yes" <?=$chk;?> onClick="dns_domain_change()">
878
									</td>
879
									<td>
880
										<span class="vexpl">
881
	                                        Provide a default domain name to clients<br>
882
										</span>
883
									</td>
884
								</tr>
885
							</table>
886
							<table border="0" cellpadding="2" cellspacing="0" id="dns_domain_data">
887
								<tr>
888
									<td>
889
										<input name="dns_domain" type="text" class="formfld unknown" id="dns_domain" size="30" value="<?=htmlspecialchars($pconfig['dns_domain']);?>">
890
									</td>
891
								</tr>
892
							</table>
893
						</td>
894
					</tr>
895
					<tr>
896
						<td width="22%" valign="top" class="vncell">DNS Servers</td>
897
						<td width="78%" class="vtable">
898
							<table border="0" cellpadding="2" cellspacing="0">
899
								<tr>
900
									<td>
901
										<?php set_checked($pconfig['dns_server_enable'],$chk); ?>
902
										<input name="dns_server_enable" type="checkbox" id="dns_server_enable" value="yes" <?=$chk;?> onClick="dns_server_change()">
903
									</td>
904
									<td>
905
										<span class="vexpl">
906
											Provide a DNS server list to clients<br>
907
										</span>
908
									</td>
909
								</tr>
910
							</table>
911
							<table border="0" cellpadding="2" cellspacing="0" id="dns_server_data">
912
								<tr>
913
									<td>
914
										<span class="vexpl">
915
											Server #1:&nbsp;
916
										</span>
917
										<input name="dns_server1" type="text" class="formfld unknown" id="dns_server1" size="20" value="<?=$pconfig['dns_server1'];?>">
918
									</td>
919
								</tr>
920
								<tr>
921
									<td>
922
										<span class="vexpl">
923
											Server #2:&nbsp;
924
										</span>
925
										<input name="dns_server2" type="text" class="formfld unknown" id="dns_server2" size="20" value="<?=$pconfig['dns_server2'];?>">
926
									</td>
927
								</tr>
928
								<tr>
929
									<td>
930
										<span class="vexpl">
931
											Server #3:&nbsp;
932
										</span>
933
										<input name="dns_server3" type="text" class="formfld unknown" id="dns_server3" size="20" value="<?=$pconfig['dns_server3'];?>">
934
									</td>
935
								</tr>
936
								<tr>
937
									<td>
938
										<span class="vexpl">
939
											Server #4:&nbsp;
940
										</span>
941
										<input name="dns_server4" type="text" class="formfld unknown" id="dns_server4" size="20" value="<?=$pconfig['dns_server4'];?>">
942
									</td>
943
								</tr>
944
							</table>
945
						</td>
946
					</tr>
947
					<tr>
948
						<td width="22%" valign="top" class="vncell">NTP Servers</td>
949
						<td width="78%" class="vtable">
950
							<table border="0" cellpadding="2" cellspacing="0">
951
								<tr>
952
									<td>
953
										<?php set_checked($pconfig['ntp_server_enable'],$chk); ?>
954
										<input name="ntp_server_enable" type="checkbox" id="ntp_server_enable" value="yes" <?=$chk;?> onClick="ntp_server_change()">
955
									</td>
956
									<td>
957
										<span class="vexpl">
958
											Provide a NTP server list to clients<br>
959
										</span>
960
									</td>
961
								</tr>
962
							</table>
963
							<table border="0" cellpadding="2" cellspacing="0" id="ntp_server_data">
964
								<tr>
965
									<td>
966
										<span class="vexpl">
967
											Server #1:&nbsp;
968
										</span>
969
										<input name="ntp_server1" type="text" class="formfld unknown" id="ntp_server1" size="20" value="<?=$pconfig['ntp_server1'];?>">
970
									</td>
971
								</tr>
972
								<tr>
973
									<td>
974
										<span class="vexpl">
975
											Server #2:&nbsp;
976
										</span>
977
										<input name="ntp_server2" type="text" class="formfld unknown" id="ntp_server2" size="20" value="<?=$pconfig['ntp_server2'];?>">
978
									</td>
979
								</tr>
980
							</table>
981
						</td>
982
					</tr>
983
					<tr>
984
						<td width="22%" valign="top" class="vncell">NetBIOS Options</td>
985
						<td width="78%" class="vtable">
986
							<table border="0" cellpadding="2" cellspacing="0">
987
								<tr>
988
									<td>
989
										<?php set_checked($pconfig['netbios_enable'],$chk); ?>
990
										<input name="netbios_enable" type="checkbox" id="netbios_enable" value="yes" <?=$chk;?> onClick="netbios_change()">
991
									</td>
992
									<td>
993
										<span class="vexpl">
994
											Enable NetBIOS over TCP/IP<br>
995
										</span>
996
									</td>
997
								</tr>
998
							</table>
999
							If this option is not set, all Netbios-over-TCP/IP options (includeing WINS) will be disabled.
1000
							<br/>
1001
							<table border="0" cellpadding="2" cellspacing="0" id="netbios_data">
1002
								<tr>
1003
									<td>
1004
										<br/>
1005
										<span class="vexpl">
1006
											Node Type:&nbsp;
1007
										</span>
1008
										<select name='netbios_ntype' class="formselect">
1009
										<?php
1010
											foreach ($netbios_nodetypes as $type => $name):
1011
												$selected = "";
1012
												if ($pconfig['netbios_ntype'] == $type)
1013
													$selected = "selected";
1014
										?>
1015
											<option value="<?=$type;?>" <?=$selected;?>><?=$name;?></option>
1016
										<?php endforeach; ?>
1017
										</select>
1018
										<br/>
1019
										Possible options: b-node (broadcasts), p-node
1020
										(point-to-point name queries to a WINS server),
1021
										m-node (broadcast then query name server), and
1022
										h-node (query name server, then broadcast).
1023
									</td>
1024
								</tr>
1025
								<tr>
1026
									<td>
1027
										<br/>
1028
										<span class="vexpl">
1029
											Scope ID:&nbsp;
1030
										</span>
1031
										<input name="netbios_scope" type="text" class="formfld unknown" id="netbios_scope" size="30" value="<?=htmlspecialchars($pconfig['netbios_scope']);?>">
1032
										<br/>
1033
										A NetBIOS Scope	ID provides an extended naming
1034
										service for	NetBIOS over TCP/IP. The NetBIOS
1035
										scope ID isolates NetBIOS traffic on a single
1036
										network to only those nodes with the same
1037
										NetBIOS scope ID.
1038
									</td>
1039
								</tr>
1040
							</table>
1041
						</td>
1042
					</tr>
1043
					<tr id="wins_opts">
1044
						<td width="22%" valign="top" class="vncell">WINS Servers</td>
1045
						<td width="78%" class="vtable">
1046
							<table border="0" cellpadding="2" cellspacing="0">
1047
								<tr>
1048
									<td>
1049
										<?php set_checked($pconfig['wins_server_enable'],$chk); ?>
1050
										<input name="wins_server_enable" type="checkbox" id="wins_server_enable" value="yes" <?=$chk;?> onClick="wins_server_change()">
1051
									</td>
1052
									<td>
1053
										<span class="vexpl">
1054
											Provide a WINS server list to clients<br>
1055
										</span>
1056
									</td>
1057
								</tr>
1058
							</table>
1059
							<table border="0" cellpadding="2" cellspacing="0" id="wins_server_data">
1060
								<tr>
1061
									<td>
1062
										<span class="vexpl">
1063
											Server #1:&nbsp;
1064
										</span>
1065
										<input name="wins_server1" type="text" class="formfld unknown" id="wins_server1" size="20" value="<?=$pconfig['wins_server1'];?>">
1066
									</td>
1067
								</tr>
1068
								<tr>
1069
									<td>
1070
										<span class="vexpl">
1071
											Server #2:&nbsp;
1072
										</span>
1073
										<input name="wins_server2" type="text" class="formfld unknown" id="wins_server2" size="20" value="<?=$pconfig['wins_server2'];?>">
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 width="22%" valign="top">&nbsp;</td>
1084
						<td width="78%"> 
1085
							<input name="save" type="submit" class="formbtn" value="Save"> 
1086
							<input name="act" type="hidden" value="<?=$act;?>">
1087
							<?php if (isset($id) && $a_server[$id]): ?>
1088
							<input name="id" type="hidden" value="<?=$id;?>">
1089
							<?php endif; ?>
1090
						</td>
1091
					</tr>
1092
				</table>
1093
			</form>
1094

    
1095
			<?php else: ?>
1096

    
1097
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
1098
				<tr>
1099
					<td width="10%" class="listhdrr">Disabled</td>
1100
					<td width="10%" class="listhdrr">Protocol</td>
1101
					<td width="30%" class="listhdrr">Tunnel Network</td>
1102
					<td width="40%" class="listhdrr">Description</td>
1103
					<td width="10%" class="list"></td>
1104
				</tr>
1105
				<?php
1106
					$i = 0;
1107
					foreach($a_server as $server):
1108
						$disabled = "NO";
1109
						if ($server['disable'])
1110
							$disabled = "YES";
1111
				?>
1112
				<tr>
1113
					<td class="listlr">
1114
						<?=$disabled;?>
1115
					</td>
1116
					<td class="listr">
1117
						<?=htmlspecialchars($server['protocol']);?>
1118
					</td>
1119
					<td class="listr">
1120
						<?=htmlspecialchars($server['tunnel_network']);?>
1121
					</td>
1122
					<td class="listbg">
1123
						<?=htmlspecialchars($server['description']);?>
1124
					</td>
1125
					<td valign="middle" nowrap class="list">
1126
						<a href="vpn_openvpn_server.php?act=edit&id=<?=$i;?>">
1127
							<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="edit server" width="17" height="17" border="0">
1128
						</a>
1129
						&nbsp;
1130
						<a href="vpn_openvpn_server.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this server?')">
1131
							<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="delete server" width="17" height="17" border="0">
1132
						</a>
1133
					</td>
1134
				</tr>
1135
				<?php
1136
					$i++;
1137
					endforeach;
1138
				?>
1139
				<tr>
1140
					<td class="list" colspan="4"></td>
1141
					<td class="list">
1142
						<a href="vpn_openvpn_server.php?act=new"><img src="./themes/<?=$g['theme'];?>/images/icons/icon_plus.gif" title="add server" width="17" height="17" border="0">
1143
						</a>
1144
					</td>
1145
				</tr>
1146
				<tr>
1147
					<td colspan="4">
1148
						<p>
1149
							<?=gettext("Additional OpenVPN servers can be added here.");?>
1150
						</p>
1151
					</td>
1152
				</tr>
1153
			</table>
1154

    
1155
			<? endif; ?>
1156

    
1157
		</td>
1158
	</tr>
1159
</table>
1160
<script language="JavaScript">
1161
<!--
1162
mode_change();
1163
autokey_change();
1164
tlsauth_change();
1165
gwredir_change();
1166
dns_domain_change();
1167
dns_server_change();
1168
wins_server_change();
1169
ntp_server_change();
1170
netbios_change();
1171
//-->
1172
</script>
1173
</body>
1174
<?php include("fend.inc"); ?>
1175

    
1176
<?php
1177

    
1178
/* local utility functions */
1179

    
1180
function set_checked($var,& $chk) {
1181
    if($var)
1182
        $chk = 'checked';
1183
    else
1184
        $chk = '';
1185
}
1186

    
1187
?>
1188

    
(208-208/216)