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
	$portused = openvpn_port_used($pconfig['protocol'], $pconfig['local_port']);
181
	if (($portused != $vpnid) && ($portused != 0))
182
		$input_errors[] = "The specified 'Local port' is in use. Please select another value";
183

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

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

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

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

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

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

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

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

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

    
246
		$server = array();
247

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

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

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

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

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

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

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

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

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

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

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

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

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

    
330
include("head.inc");
331

    
332
?>
333

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

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

    
374
function autokey_change() {
375

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

    
382
function tlsauth_change() {
383

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

    
391
	autotls_change();
392
}
393

    
394
function autotls_change() {
395

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

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

    
408
function gwredir_change() {
409

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

    
416
function dns_domain_change() {
417

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

    
424
function dns_server_change() {
425

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

    
432
function wins_server_change() {
433

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

    
440
function ntp_server_change() {
441

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

    
448
function netbios_change() {
449

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

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

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

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

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

    
1082
				<table width="100%" border="0" cellpadding="6" cellspacing="0" id="client_opts">
1083
					<tr>
1084
						<td width="22%" valign="top">&nbsp;</td>
1085
						<td width="78%"> 
1086
							<input name="save" type="submit" class="formbtn" value="Save"> 
1087
							<input name="act" type="hidden" value="<?=$act;?>">
1088
							<?php if (isset($id) && $a_server[$id]): ?>
1089
							<input name="id" type="hidden" value="<?=$id;?>">
1090
							<?php endif; ?>
1091
						</td>
1092
					</tr>
1093
				</table>
1094
			</form>
1095

    
1096
			<?php else: ?>
1097

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

    
1156
			<? endif; ?>
1157

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

    
1177
<?php
1178

    
1179
/* local utility functions */
1180

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

    
1188
?>
1189

    
(198-198/206)