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 |
|