Project

General

Profile

Feature #4687 ยป 872.patch

David Young, 05/07/2015 10:05 PM

View differences:

config/openvpn-client-export/openvpn-client-export.inc
44 44

  
45 45
function openvpn_client_export_install() {
46 46
	global $current_openvpn_version;
47
	conf_mount_rw();
48
	$tarpath = "/usr/local/pkg/openvpn-client-export-{$current_openvpn_version}.tgz";
49
	$phpfile = "vpn_openvpn_export.php";
50
	$ovpndir = "/usr/local/share/openvpn";
51
	$workdir = "{$ovpndir}/client-export";
47 52

  
48
	$pfs_version = substr(trim(file_get_contents("/etc/version")),0,3);
49
	if ($pfs_version == "2.1" || $pfs_version == "2.2") {
50
		conf_mount_rw();
51
		$tarpath = "/usr/local/pkg/openvpn-client-export-{$current_openvpn_version}.tgz";
52
		$ovpndir = "/usr/local/share/openvpn";
53
		$workdir = "{$ovpndir}/client-export";
54

  
55
		if (!is_dir($workdir))
56
			mkdir($workdir, 0777, true);
53
	if (!is_dir($workdir))
54
		mkdir($workdir, 0777, true);
57 55

  
58
		exec("/usr/bin/tar zxf {$tarpath} -C {$ovpndir}");
59
		conf_mount_ro();
60
	}
56
	exec("/usr/bin/tar zxf {$tarpath} -C {$ovpndir}");
57
	conf_mount_ro();
61 58
}
62 59

  
63 60
function openvpn_client_export_deinstall() {
......
75 72
	conf_mount_ro();
76 73
}
77 74

  
78
function openvpn_client_export_prefix($srvid, $usrid = null, $crtid = null) {
75
function openvpn_client_export_prefix($srvid, $usrid = null, $crtid = null, $usevpndescription) {
79 76
	global $config;
80 77

  
81 78
	// lookup server settings
......
88 85
	$host = empty($config['system']['hostname']) ? "openvpn" : $config['system']['hostname'];
89 86
	$prot = ($settings['protocol'] == 'UDP' ? 'udp' : $settings['protocol']);
90 87
	$port = $settings['local_port'];
91
	
88
	$description = $settings['description'];
89

  
90
	// strip out unwanted characters from the description (spaces etc make for bad filenames)
91
	$description = $string = preg_replace('/[^\d\-a-z]/i', '', $description);
92

  
92 93
	$filename_addition = "";
93 94
	if ($usrid && is_numeric($usrid))
94 95
		$filename_addition = "-".$config['system']['user'][$usrid]['name'];
95 96
	elseif ($crtid && is_numeric($crtid) && function_exists("cert_get_cn"))
96 97
		$filename_addition = "-" . str_replace(' ', '_', cert_get_cn($config['cert'][$crtid]['crt']));
97 98

  
98
	return "{$host}-{$prot}-{$port}{$filename_addition}";
99
	// if the usevpndescription variable is set, use the VPN description instead of the host-proto-port combination
100
	if ($usevpndescription) {
101
		return "{$description}{$filename_addition}";
102
	} else {
103
		return "{$host}-{$prot}-{$port}{$filename_addition}";
104
	}
99 105
}
100 106

  
101 107
function openvpn_client_pem_to_pk12($outpath, $outpass, $crtpath, $keypath, $capath = false) {
......
180 186
	return array($settings, $server_cert, $server_ca, $servercn, $user, $cert, $nokeys);
181 187
}
182 188

  
183
function openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $nokeys = false, $proxy, $expformat = "baseconf", $outpass = "", $skiptls=false, $doslines=false, $openvpnmanager, $advancedoptions = "") {
189
function openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usevpndescription, $usetoken, $nokeys = false, $proxy, $expformat = "baseconf", $outpass = "", $skiptls=false, $doslines=false, $openvpnmanager, $advancedoptions = "") {
184 190
	global $config, $input_errors, $g;
185 191
	$pfs_version = substr(trim(file_get_contents("/etc/version")),0,3);
186 192

  
......
257 263
			$conf .= "socks-proxy {$proxy['ip']} {$proxy['port']} ";
258 264
		if ($proxy['proxy_authtype'] != "none") {
259 265
			if (!isset($proxy['passwdfile']))
260
				$proxy['passwdfile'] = openvpn_client_export_prefix($srvid, $usrid, $crtid) . "-proxy";
266
				$proxy['passwdfile'] = openvpn_client_export_prefix($srvid, $usrid, $crtid, $usevpndescription) . "-proxy";
261 267
			$conf .= " {$proxy['passwdfile']} {$proxy['proxy_authtype']}";
262 268
		}
263 269
		$conf .= "{$nl}";
......
272 278
	}
273 279

  
274 280
	// add key settings
275
	$prefix = openvpn_client_export_prefix($srvid, $usrid, $crtid);
281
	$prefix = openvpn_client_export_prefix($srvid, $usrid, $crtid, $usevpndescription);
276 282
	$cafile = "{$prefix}-ca.crt";
277 283
	if($nokeys == false) {
278 284
		if ($expformat == "yealink_t28") {
......
488 494
	}
489 495
}
490 496

  
491
function openvpn_client_export_installer($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $outpass, $proxy, $openvpnmanager, $advancedoptions, $openvpn_version = "x86-xp") {
497
function openvpn_client_export_installer($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usevpndescription, $usetoken, $outpass, $proxy, $openvpnmanager, $advancedoptions, $openvpn_version = "x86-xp") {
492 498
	global $config, $g, $input_errors, $current_openvpn_version, $current_openvpn_version_rev;
493 499
	$uname_p = trim(exec("uname -p"));
494 500

  
......
538 544
		rename("{$tempdir}/openvpn-postinstall64.exe", "{$tempdir}/openvpn-postinstall.exe");
539 545

  
540 546
	// write configuration file
541
	$prefix = openvpn_client_export_prefix($srvid, $usrid, $crtid);
547
	$prefix = openvpn_client_export_prefix($srvid, $usrid, $crtid, $usevpndescription);
542 548
	$cfgfile = "{$confdir}/{$prefix}-config.ovpn";
543 549
	if (!empty($proxy) && $proxy['proxy_authtype'] != "none") {
544 550
		$proxy['passwdfile'] = "{$prefix}-password";
......
546 552
		$pwdfle .= "{$proxy['password']}\r\n";
547 553
		file_put_contents("{$confdir}/{$proxy['passwdfile']}", $pwdfle);
548 554
	}
549
	$conf = openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken,  $nokeys, $proxy, "", "baseconf", false, true, $openvpnmanager, $advancedoptions);
555
	$conf = openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usevpndescription, $usetoken,  $nokeys, $proxy, "", "baseconf", false, true, $openvpnmanager, $advancedoptions);
550 556
	if (!$conf) {
551 557
		$input_errors[] = "Could not create a config to export.";
552 558
		return false;
......
611 617
	return $outfile;
612 618
}
613 619

  
614
function viscosity_openvpn_client_config_exporter($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $outpass, $proxy, $openvpnmanager, $advancedoptions) {
620
function viscosity_openvpn_client_config_exporter($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usevpndescription, $usetoken, $outpass, $proxy, $openvpnmanager, $advancedoptions) {
615 621
	global $config, $g;
616 622
	$uname_p = trim(exec("uname -p"));
617 623

  
......
638 644
	$tempdir = $tempdir . "/Viscosity.visc/";
639 645

  
640 646
	// write cofiguration file
641
	$prefix = openvpn_client_export_prefix($srvid, $usrid, $crtid);
647
	$prefix = openvpn_client_export_prefix($srvid, $usrid, $crtid, $usevpndescription);
642 648
	if (!empty($proxy) && $proxy['proxy_authtype'] != "none") {
643 649
		$proxy['passwdfile'] = "config-password";
644 650
		$pwdfle = "{$proxy['user']}\n";
......
646 652
		file_put_contents("{$tempdir}/{$proxy['passwdfile']}", $pwdfle);
647 653
	}
648 654

  
649
	$conf = openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, true, $proxy, "baseconf", $outpass, true, true, $openvpnmanager, $advancedoptions);
655
	$conf = openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usevpndescription, $usetoken, true, $proxy, "baseconf", $outpass, true, true, $openvpnmanager, $advancedoptions);
650 656
	if (!$conf)
651 657
		return false;
652 658

  
config/openvpn-client-export/vpn_openvpn_export.php
146 146

  
147 147
	$verifyservercn = $_GET['verifyservercn'];
148 148
	$randomlocalport = $_GET['randomlocalport'];
149
	$usevpndescription = $_GET['usevpndescription'];
149 150
	$usetoken = $_GET['usetoken'];
150 151
	if ($usetoken && (substr($act, 0, 10) == "confinline"))
151 152
		$input_errors[] = "You cannot use Microsoft Certificate Storage with an Inline configuration.";
......
180 181
		}
181 182
	}
182 183

  
183
	$exp_name = openvpn_client_export_prefix($srvid, $usrid, $crtid);
184
	$exp_name = openvpn_client_export_prefix($srvid, $usrid, $crtid, $usevpndescription);
184 185

  
185 186
	if(substr($act, 0, 4) == "conf") {
186 187
		switch ($act) {
......
220 221
				$exp_name = urlencode($exp_name."-config.ovpn");
221 222
				$expformat = "baseconf";
222 223
		}
223
		$exp_path = openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $nokeys, $proxy, $expformat, $password, false, false, $openvpnmanager, $advancedoptions);
224
		$exp_path = openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usevpndescription, $usetoken, $nokeys, $proxy, $expformat, $password, false, false, $openvpnmanager, $advancedoptions);
224 225
	}
225 226

  
226 227
	if($act == "visc") {
227 228
		$exp_name = urlencode($exp_name."-Viscosity.visc.zip");
228
		$exp_path = viscosity_openvpn_client_config_exporter($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $password, $proxy, $openvpnmanager, $advancedoptions);
229
		$exp_path = viscosity_openvpn_client_config_exporter($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usevpndescription, $usetoken, $password, $proxy, $openvpnmanager, $advancedoptions);
229 230
	}
230 231

  
231 232
	if(substr($act, 0, 4) == "inst") {
232 233
		$exp_name = urlencode($exp_name."-install.exe");
233
		$exp_path = openvpn_client_export_installer($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $password, $proxy, $openvpnmanager, $advancedoptions, substr($act, 5));
234
		$exp_path = openvpn_client_export_installer($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usevpndescription, $usetoken, $password, $proxy, $openvpnmanager, $advancedoptions, substr($act, 5));
234 235
	}
235 236

  
236 237
	if (!$exp_path) {
......
317 318
	var randomlocalport = 0;
318 319
	if (document.getElementById("randomlocalport").checked)
319 320
		randomlocalport = 1;
321
	var usevpndescription = 0;
322
	if (document.getElementById("usevpndescription").checked)
323
		usevpndescription = 1;
320 324
	var usetoken = 0;
321 325
	if (document.getElementById("usetoken").checked)
322 326
		usetoken = 1;
......
392 396
	dlurl += "&useaddr=" + escape(useaddr);
393 397
	dlurl += "&verifyservercn=" + escape(verifyservercn);
394 398
	dlurl += "&randomlocalport=" + escape(randomlocalport);
399
	dlurl += "&usevpndescription=" + escape(usevpndescription);
395 400
	dlurl += "&openvpnmanager=" + escape(openvpnmanager);
396 401
	dlurl += "&usetoken=" + escape(usetoken);
397 402
	if (usepass)
......
686 691
							</table>
687 692
					</tr>
688 693
					<tr>
694
						<td width="22%" valign="top" class="vncell">Use VPN description for export</td>
695
						<td width="78%" class="vtable">
696
							 <table border="0" cellpadding="2" cellspacing="0" summary="use vpn description">
697
								<tr>
698
									<td valign=top>
699
										<input name="usevpndescription" id="usevpndescription" type="checkbox" value="yes" checked="CHECKED" />
700
									</td>
701
									<td>
702
										<span class="vexpl">
703
										Use the VPN description (as defined in VPN settings) as the prefix for exported configuration files, rather than an auto-generated combination of hostname, protocol, and port. This makes the client install package more consistent and user-friendly. The username or certificate name will still be appended to the generated filename, e.g. <i><b>acme-inc-wiley.ovpn</b></i></span>
704
									</td>
705
								</tr>
706
								<tr>
707
									<td colspan="2">
708
										<span class="vexpl"><br/>NOTE: Non-alphanumeric characters will be stripped from the description prior to export.</span>
709
									</td>
710
								</tr>
711
							</table>
712
					</tr>
713
					<tr>
689 714
						<td width="22%" valign="top" class="vncell">Certificate Export Options</td>
690 715
						<td width="78%" class="vtable">
691 716
							<table border="0" cellpadding="2" cellspacing="0" summary="export options">
    (1-1/1)