Commit c7d388a8 authored by Ad Schellevis's avatar Ad Schellevis

add OpenVPN client export

reference : https://forum.opnsense.org/index.php?topic=132.msg754#msg754
parent 541318e7
......@@ -1392,6 +1392,12 @@ $priv_list['page-firewall-easyrule']['descr'] = gettext("Allow access to the 'Fi
$priv_list['page-firewall-easyrule']['match'] = array();
$priv_list['page-firewall-easyrule']['match'][] = "easyrule.php*";
$priv_list['page-openvpn-client-export'] = array();
$priv_list['page-openvpn-client-export']['name'] = "WebCfg - OpenVPN: Client Export Utility";
$priv_list['page-openvpn-client-export']['descr'] = "Allow access to the OpenVPN: Client Export Utility page.";
$priv_list['page-openvpn-client-export']['match'] = array();
$priv_list['page-openvpn-client-export']['match'][] = "vpn_openvpn_export.php*";
$priv_rmvd = array();
?>
<?php
/*
openvpn-client-export.inc
Copyright (C) 2009 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2008 Shrew Soft Inc
Copyright (C) 2010 Ermal Luci
All rights reserved.
Parts of this code was originally based on vpn_ipsec_sad.php
Copyright (C) 2003-2004 Manuel Kasper
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("globals.inc");
require_once("openvpn.inc");
require_once("filter.inc");
require_once("shaper.inc");
require_once("util.inc");
require_once("pfsense-utils.inc");
global $current_openvpn_version, $current_openvpn_version_rev;
$current_openvpn_version = "2.3.6";
$current_openvpn_version_rev = "01";
function openvpn_client_export_install() {
global $current_openvpn_version;
conf_mount_rw();
$tarpath = "/usr/local/pkg/openvpn-client-export-{$current_openvpn_version}.tgz";
$phpfile = "vpn_openvpn_export.php";
$ovpndir = "/usr/local/share/openvpn";
$workdir = "{$ovpndir}/client-export";
if (!is_dir($workdir))
mkdir($workdir, 0777, true);
exec("/usr/bin/tar zxf {$tarpath} -C {$ovpndir}");
conf_mount_ro();
}
function openvpn_client_export_deinstall() {
global $current_openvpn_version;
conf_mount_rw();
$phpfile = "vpn_openvpn_export.php";
$phpfile2 = "vpn_openvpn_export_shared.php";
$ovpndir = "/usr/local/share/openvpn";
$workdir = "{$ovpndir}/client-export";
unlink_if_exists("/usr/local/www/{$phpfile}");
unlink_if_exists("/usr/local/www/{$phpfile2}");
unlink_if_exists("/usr/local/pkg/openvpn-client-export-{$current_openvpn_version}.tgz");
exec("/bin/rm -r {$workdir}");
conf_mount_ro();
}
function openvpn_client_export_prefix($srvid, $usrid = null, $crtid = null) {
global $config;
// lookup server settings
$settings = $config['openvpn']['openvpn-server'][$srvid];
if (empty($settings))
return false;
if ($settings['disable'])
return false;
$host = empty($config['system']['hostname']) ? "openvpn" : $config['system']['hostname'];
$prot = ($settings['protocol'] == 'UDP' ? 'udp' : $settings['protocol']);
$port = $settings['local_port'];
$filename_addition = "";
if ($usrid && is_numeric($usrid))
$filename_addition = "-".$config['system']['user'][$usrid]['name'];
elseif ($crtid && is_numeric($crtid) && function_exists("cert_get_cn"))
$filename_addition = "-" . str_replace(' ', '_', cert_get_cn($config['cert'][$crtid]['crt']));
return "{$host}-{$prot}-{$port}{$filename_addition}";
}
function openvpn_client_pem_to_pk12($outpath, $outpass, $crtpath, $keypath, $capath = false) {
$eoutpath = escapeshellarg($outpath);
$eoutpass = escapeshellarg($outpass);
$ecrtpath = escapeshellarg($crtpath);
$ekeypath = escapeshellarg($keypath);
if ($capath) {
$ecapath = escapeshellarg($capath);
exec("/usr/bin/openssl pkcs12 -export -in {$ecrtpath} -inkey {$ekeypath} -certfile {$ecapath} -out {$eoutpath} -passout pass:{$eoutpass}");
} else
exec("/usr/bin/openssl pkcs12 -export -in {$ecrtpath} -inkey {$ekeypath} -out {$eoutpath} -passout pass:{$eoutpass}");
unlink($crtpath);
unlink($keypath);
if ($capath)
unlink($capath);
}
function openvpn_client_export_validate_config($srvid, $usrid, $crtid) {
global $config, $g, $input_errors;
// lookup server settings
$settings = $config['openvpn']['openvpn-server'][$srvid];
if (empty($settings)) {
$input_errors[] = "Could not locate server configuration.";
return false;
}
if ($settings['disable']) {
$input_errors[] = "You cannot export for disabled servers.";
return false;
}
// lookup server certificate info
$server_cert = lookup_cert($settings['certref']);
if (!$server_cert)
{
$input_errors[] = "Could not locate server certificate.";
} else {
$server_ca = lookup_ca($server_cert['caref']);
if (!$server_ca) {
$input_errors[] = "Could not locate the CA reference for the server certificate.";
}
if (function_exists("cert_get_cn")) {
$servercn = cert_get_cn($server_cert['crt']);
}
}
// lookup user info
if (is_numeric($usrid)) {
$user = $config['system']['user'][$usrid];
if (!$user) {
$input_errors[] = "Could not find user settings.";
}
}
// lookup user certificate info
if ($settings['mode'] == "server_tls_user") {
if ($settings['authmode'] == "Local Database") {
$cert = $user['cert'][$crtid];
} else {
$cert = $config['cert'][$crtid];
}
if (!$cert)
{
$input_errors[] = "Could not find client certificate.";
} else {
// If $cert is not an array, it's a certref not a cert.
if (!is_array($cert))
$cert = lookup_cert($cert);
}
} elseif (($settings['mode'] == "server_tls") || (($settings['mode'] == "server_tls_user") && ($settings['authmode'] != "Local Database"))) {
$cert = $config['cert'][$crtid];
if (!$cert)
$input_errors[] = "Could not find client certificate.";
} else
$nokeys = true;
if ($input_errors)
return false;
return array($settings, $server_cert, $server_ca, $servercn, $user, $cert, $nokeys);
}
function openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $nokeys = false, $proxy, $expformat = "baseconf", $outpass = "", $skiptls=false, $doslines=false, $openvpnmanager, $advancedoptions = "") {
global $config, $input_errors, $g;
$pfs_version = substr(trim(file_get_contents("/etc/version")),0,3);
$nl = ($doslines) ? "\r\n" : "\n";
$conf = "";
$validconfig = openvpn_client_export_validate_config($srvid, $usrid, $crtid);
if ($validconfig) {
list($settings, $server_cert, $server_ca, $servercn, $user, $cert, $nokeys) = $validconfig;
} else {
return false;
}
// determine basic variables
$remotes = openvpn_client_export_build_remote_lines($settings, $useaddr, $interface, $expformat, $nl);
$server_port = $settings['local_port'];
$cipher = $settings['crypto'];
$digest = !empty($settings['digest']) ? $settings['digest'] : "SHA1";
// add basic settings
$devmode = empty($settings['dev_mode']) ? "tun" : $settings['dev_mode'];
if (($expformat != "inlinedroid") && ($expformat != "inlineios"))
$conf .= "dev {$devmode}{$nl}";
if(!empty($settings['tunnel_networkv6']) && ($expformat != "inlinedroid") && ($expformat != "inlineios")) {
$conf .= "tun-ipv6{$nl}";
}
$conf .= "persist-tun{$nl}";
$conf .= "persist-key{$nl}";
// if ((($expformat != "inlinedroid") && ($expformat != "inlineios")) && ($proto == "tcp"))
// $conf .= "proto tcp-client{$nl}";
$conf .= "cipher {$cipher}{$nl}";
$conf .= "auth {$digest}{$nl}";
$conf .= "tls-client{$nl}";
$conf .= "client{$nl}";
if (($expformat != "inlinedroid") && ($expformat != "inlineios"))
$conf .= "resolv-retry infinite{$nl}";
$conf .= "$remotes{$nl}";
/* Use a random local port, otherwise two clients will conflict if they run at the same time.
May not be supported on older clients (Released before May 2010) */
if (($randomlocalport != 0) && (substr($expformat, 0, 7) != "yealink") && ($expformat != "snom"))
$conf .= "lport 0{$nl}";
/* This line can cause problems with auth-only setups and also with Yealink/Snom phones
since they are stuck on an older OpenVPN version that does not support this feature. */
if (!empty($servercn) && !$nokeys) {
switch ($verifyservercn) {
case "none":
break;
case "tls-remote":
$conf .= "tls-remote {$servercn}{$nl}";
break;
case "tls-remote-quote":
$conf .= "tls-remote \"{$servercn}\"{$nl}";
break;
default:
if ((substr($expformat, 0, 7) != "yealink") && ($expformat != "snom")) {
$conf .= "verify-x509-name \"{$servercn}\" name{$nl}";
}
}
}
if (!empty($proxy)) {
if ($proxy['proxy_type'] == "http") {
if (strtoupper(substr($settings['protocol'], 0, 3)) == "UDP") {
$input_errors[] = "This server uses UDP protocol and cannot communicate with HTTP proxy.";
return;
}
$conf .= "http-proxy {$proxy['ip']} {$proxy['port']} ";
}
if ($proxy['proxy_type'] == "socks")
$conf .= "socks-proxy {$proxy['ip']} {$proxy['port']} ";
if ($proxy['proxy_authtype'] != "none") {
if (!isset($proxy['passwdfile']))
$proxy['passwdfile'] = openvpn_client_export_prefix($srvid, $usrid, $crtid) . "-proxy";
$conf .= " {$proxy['passwdfile']} {$proxy['proxy_authtype']}";
}
$conf .= "{$nl}";
}
// add user auth settings
switch($settings['mode']) {
case 'server_user':
case 'server_tls_user':
$conf .= "auth-user-pass{$nl}";
break;
}
// add key settings
$prefix = openvpn_client_export_prefix($srvid, $usrid, $crtid);
$cafile = "{$prefix}-ca.crt";
if($nokeys == false) {
if ($expformat == "yealink_t28") {
$conf .= "ca /yealink/config/openvpn/keys/ca.crt{$nl}";
$conf .= "cert /yealink/config/openvpn/keys/client1.crt{$nl}";
$conf .= "key /yealink/config/openvpn/keys/client1.key{$nl}";
} elseif ($expformat == "yealink_t38g") {
$conf .= "ca /phone/config/openvpn/keys/ca.crt{$nl}";
$conf .= "cert /phone/config/openvpn/keys/client1.crt{$nl}";
$conf .= "key /phone/config/openvpn/keys/client1.key{$nl}";
} elseif ($expformat == "yealink_t38g2") {
$conf .= "ca /config/openvpn/keys/ca.crt{$nl}";
$conf .= "cert /config/openvpn/keys/client1.crt{$nl}";
$conf .= "key /config/openvpn/keys/client1.key{$nl}";
} elseif ($expformat == "snom") {
$conf .= "ca /openvpn/ca.crt{$nl}";
$conf .= "cert /openvpn/phone1.crt{$nl}";
$conf .= "key /openvpn/phone1.key{$nl}";
} elseif ($usetoken) {
$conf .= "ca {$cafile}{$nl}";
$conf .= "cryptoapicert \"SUBJ:{$user['name']}\"{$nl}";
} elseif (substr($expformat, 0, 6) != "inline") {
$conf .= "pkcs12 {$prefix}.p12{$nl}";
}
} else if ($settings['mode'] == "server_user") {
if (substr($expformat, 0, 6) != "inline")
$conf .= "ca {$cafile}{$nl}";
}
if ($settings['tls'] && !$skiptls) {
if ($expformat == "yealink_t28")
$conf .= "tls-auth /yealink/config/openvpn/keys/ta.key 1{$nl}";
elseif ($expformat == "yealink_t38g")
$conf .= "tls-auth /phone/config/openvpn/keys/ta.key 1{$nl}";
elseif ($expformat == "yealink_t38g2")
$conf .= "tls-auth /config/openvpn/keys/ta.key 1{$nl}";
elseif ($expformat == "snom")
$conf .= "tls-auth /openvpn/ta.key 1{$nl}";
elseif (substr($expformat, 0, 6) != "inline")
$conf .= "tls-auth {$prefix}-tls.key 1{$nl}";
}
// Prevent MITM attacks by verifying the server certificate.
// - Disable for now, it requires the server cert to include special options
//$conf .= "remote-cert-tls server{$nl}";
// Extra protection for the server cert, if it's supported
if (function_exists("cert_get_purpose")) {
if (is_array($server_cert) && ($server_cert['crt'])) {
$purpose = cert_get_purpose($server_cert['crt'], true);
if ($purpose['server'] == 'Yes')
$conf .= "ns-cert-type server{$nl}";
}
}
// add optional settings
if (!empty($settings['compression'])) {
if ($pfs_version > 2.1)
$conf .= "comp-lzo {$settings['compression']}{$nl}";
else
$conf .= "comp-lzo{$nl}";
}
if ($settings['passtos'])
$conf .= "passtos{$nl}";
if ($openvpnmanager)
{
if (!empty($settings['client_mgmt_port'])) {
$client_mgmt_port = $settings['client_mgmt_port'];
} else {
$client_mgmt_port = 166;
}
$conf .= $nl;
$conf .= "# dont terminate service process on wrong password, ask again{$nl}";
$conf .= "auth-retry interact{$nl}";
$conf .= "# open management channel{$nl}";
$conf .= "management 127.0.0.1 {$client_mgmt_port}{$nl}";
$conf .= "# wait for management to explicitly start connection{$nl}";
$conf .= "management-hold{$nl}";
$conf .= "# query management channel for user/pass{$nl}";
$conf .= "management-query-passwords{$nl}";
$conf .= "# disconnect VPN when management program connection is closed{$nl}";
$conf .= "management-signal{$nl}";
$conf .= "# forget password when management disconnects{$nl}";
$conf .= "management-forget-disconnect{$nl}";
$conf .= $nl;
};
// add advanced options
$advancedoptions = str_replace("\r\n", "\n", $advancedoptions);
$advancedoptions = str_replace("\n", $nl, $advancedoptions);
$advancedoptions = str_replace(";", $nl, $advancedoptions);
$conf .= $advancedoptions;
$conf .= $nl;
switch ($expformat) {
case "zip":
// create template directory
$tempdir = "{$g['tmp_path']}/{$prefix}";
@mkdir($tempdir, 0700, true);
file_put_contents("{$tempdir}/{$prefix}.ovpn", $conf);
$cafile = "{$tempdir}/{$cafile}";
file_put_contents("{$cafile}", base64_decode($server_ca['crt']));
if ($settings['tls']) {
$tlsfile = "{$tempdir}/{$prefix}-tls.key";
file_put_contents($tlsfile, base64_decode($settings['tls']));
}
// write key files
if ($settings['mode'] != "server_user") {
$crtfile = "{$tempdir}/{$prefix}-cert.crt";
file_put_contents($crtfile, base64_decode($cert['crt']));
$keyfile = "{$tempdir}/{$prefix}.key";
file_put_contents($keyfile, base64_decode($cert['prv']));
// convert to pkcs12 format
$p12file = "{$tempdir}/{$prefix}.p12";
if ($usetoken)
openvpn_client_pem_to_pk12($p12file, $outpass, $crtfile, $keyfile);
else
openvpn_client_pem_to_pk12($p12file, $outpass, $crtfile, $keyfile, $cafile);
}
$command = "cd " . escapeshellarg("{$tempdir}/..")
. " && /usr/local/bin/zip -r "
. escapeshellarg("{$g['tmp_path']}/{$prefix}-config.zip")
. " " . escapeshellarg($prefix);
exec($command);
// Remove temporary directory
exec("rm -rf " . escapeshellarg($tempdir));
return "{$g['tmp_path']}/{$prefix}-config.zip";
break;
case "inline":
case "inlinedroid":
case "inlineios":
// Inline CA
$conf .= "<ca>{$nl}" . trim(base64_decode($server_ca['crt'])) . "{$nl}</ca>{$nl}";
if ($settings['mode'] != "server_user") {
// Inline Cert
$conf .= "<cert>{$nl}" . trim(base64_decode($cert['crt'])) . "{$nl}</cert>{$nl}";
// Inline Key
$conf .= "<key>{$nl}" . trim(base64_decode($cert['prv'])) . "{$nl}</key>{$nl}";
} else {
// Work around OpenVPN Connect assuming you have a client cert even when you don't need one
$conf .= "setenv CLIENT_CERT 0{$nl}";
}
// Inline TLS
if ($settings['tls']) {
$conf .= "<tls-auth>{$nl}" . trim(base64_decode($settings['tls'])) . "{$nl}</tls-auth>{$nl} key-direction 1{$nl}";
}
return $conf;
break;
case "yealink_t28":
case "yealink_t38g":
case "yealink_t38g2":
// create template directory
$tempdir = "{$g['tmp_path']}/{$prefix}";
$keydir = "{$tempdir}/keys";
mkdir($tempdir, 0700, true);
mkdir($keydir, 0700, true);
file_put_contents("{$tempdir}/vpn.cnf", $conf);
$cafile = "{$keydir}/ca.crt";
file_put_contents("{$cafile}", base64_decode($server_ca['crt']));
if ($settings['tls']) {
$tlsfile = "{$keydir}/ta.key";
file_put_contents($tlsfile, base64_decode($settings['tls']));
}
// write key files
if ($settings['mode'] != "server_user") {
$crtfile = "{$keydir}/client1.crt";
file_put_contents($crtfile, base64_decode($cert['crt']));
$keyfile = "{$keydir}/client1.key";
file_put_contents($keyfile, base64_decode($cert['prv']));
}
exec("tar -C {$tempdir} -cf {$g['tmp_path']}/client.tar ./keys ./vpn.cnf");
// Remove temporary directory
exec("rm -rf {$tempdir}");
return $g['tmp_path'] . "/client.tar";
break;
case "snom":
// create template directory
$tempdir = "{$g['tmp_path']}/{$prefix}";
mkdir($tempdir, 0700, true);
file_put_contents("{$tempdir}/vpn.cnf", $conf);
$cafile = "{$tempdir}/ca.crt";
file_put_contents("{$cafile}", base64_decode($server_ca['crt']));
if ($settings['tls']) {
$tlsfile = "{$tempdir}/ta.key";
file_put_contents($tlsfile, base64_decode($settings['tls']));
}
// write key files
if ($settings['mode'] != "server_user") {
$crtfile = "{$tempdir}/phone1.crt";
file_put_contents($crtfile, base64_decode($cert['crt']));
$keyfile = "{$tempdir}/phone1.key";
file_put_contents($keyfile, base64_decode($cert['prv']));
}
exec("cd {$tempdir}/ && tar -cf {$g['tmp_path']}/vpnclient.tar *");
// Remove temporary directory
exec("rm -rf {$tempdir}");
return $g['tmp_path'] . "/vpnclient.tar";
break;
default:
return $conf;
}
}
function openvpn_client_export_installer($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $outpass, $proxy, $openvpnmanager, $advancedoptions, $openvpn_version = "x86-xp") {
global $config, $g, $input_errors, $current_openvpn_version, $current_openvpn_version_rev;
$uname_p = trim(exec("uname -p"));
switch ($openvpn_version) {
case "x86-xp":
$client_install_exe = "openvpn-install-{$current_openvpn_version}-I0{$current_openvpn_version_rev}-i686.exe";
break;
case "x64-xp":
$client_install_exe = "openvpn-install-{$current_openvpn_version}-I0{$current_openvpn_version_rev}-x86_64.exe";
break;
case "x86-win6":
$client_install_exe = "openvpn-install-{$current_openvpn_version}-I6{$current_openvpn_version_rev}-i686.exe";
break;
case "x64-win6":
$client_install_exe = "openvpn-install-{$current_openvpn_version}-I6{$current_openvpn_version_rev}-x86_64.exe";
break;
default:
$client_install_exe = "openvpn-install-{$current_openvpn_version}-I0{$current_openvpn_version_rev}-i686.exe";
}
$ovpndir = "/usr/local/share/openvpn";
$workdir = "{$ovpndir}/client-export";
if (!file_exists($workdir . "/template/{$client_install_exe}"))
openvpn_client_export_install();
$validconfig = openvpn_client_export_validate_config($srvid, $usrid, $crtid);
if ($validconfig) {
list($settings, $server_cert, $server_ca, $servercn, $user, $cert, $nokeys) = $validconfig;
} else {
return false;
}
// create template directory
$tempdir = $g['tmp_path'] . "/openvpn-export-".uniqid();
mkdir($tempdir, 0700, true);
// create config directory
$confdir = "{$tempdir}/config";
if (!is_dir($conf_dir))
mkdir($confdir, 0700, true);
// copy the template directory
exec("cp -r {$workdir}/template/* {$tempdir}");
// and put the required installer exe in place
exec("/bin/cp {$tempdir}/{$client_install_exe} {$tempdir}/openvpn-install.exe");
if (stristr($openvpn_version, "x64"))
rename("{$tempdir}/openvpn-postinstall64.exe", "{$tempdir}/openvpn-postinstall.exe");
// write configuration file
$prefix = openvpn_client_export_prefix($srvid, $usrid, $crtid);
$cfgfile = "{$confdir}/{$prefix}-config.ovpn";
if (!empty($proxy) && $proxy['proxy_authtype'] != "none") {
$proxy['passwdfile'] = "{$prefix}-password";
$pwdfle = "{$proxy['user']}\r\n";
$pwdfle .= "{$proxy['password']}\r\n";
file_put_contents("{$confdir}/{$proxy['passwdfile']}", $pwdfle);
}
$conf = openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $nokeys, $proxy, "", "baseconf", false, true, $openvpnmanager, $advancedoptions);
if (!$conf) {
$input_errors[] = "Could not create a config to export.";
return false;
}
file_put_contents($cfgfile, $conf);
$cafile = "{$tempdir}/config/{$prefix}-ca.crt";
file_put_contents($cafile, base64_decode($server_ca['crt']));
if ($settings['tls']) {
$tlsfile = "{$tempdir}/config/{$prefix}-tls.key";
file_put_contents($tlsfile, base64_decode($settings['tls']));
}
// write key files
if ($settings['mode'] != "server_user") {
$crtfile = "{$tempdir}/config/{$prefix}-{$user['name']}.crt";
file_put_contents($crtfile, base64_decode($cert['crt']));
$keyfile = "{$tempdir}/config/{$prefix}-{$user['name']}.key";
file_put_contents($keyfile, base64_decode($cert['prv']));
// convert to pkcs12 format
$p12file = "{$tempdir}/config/{$prefix}.p12";
if ($usetoken)
openvpn_client_pem_to_pk12($p12file, $outpass, $crtfile, $keyfile);
else
openvpn_client_pem_to_pk12($p12file, $outpass, $crtfile, $keyfile, $cafile);
}
// 7zip the configuration data
chdir($tempdir);
$files = "config ";
if ($openvpnmanager)
$files .= "openvpnmanager ";
$files .= "openvpn-install.exe ";
$files .= "openvpn-postinstall.exe ";
if ($usetoken)
$procchain = ';!@Install@!UTF-8!
RunProgram="openvpn-postinstall.exe /Import"
;!@InstallEnd@!'
;
else
$procchain = ';!@Install@!UTF-8!
RunProgram="openvpn-postinstall.exe"
;!@InstallEnd@!'
;
file_put_contents("{$tempdir}/7zipConfig",$procchain);
if(file_exists("/usr/pbi/p7zip-{$uname_p}/bin/7z"))
exec("/usr/pbi/p7zip-{$uname_p}/bin/7z -y a archive.7z {$files}");
else
exec("/usr/local/libexec/p7zip/7z -y a archive.7z {$files}");
// create the final installer
$outfile = "{$tempdir}-install.exe";
chdir($g['tmp_path']);
exec("/bin/cat {$tempdir}/7zS.sfx {$tempdir}/7zipConfig {$tempdir}/archive.7z > {$outfile}");
// cleanup
exec("/bin/rm -r {$tempdir}");
return $outfile;
}
function viscosity_openvpn_client_config_exporter($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $outpass, $proxy, $openvpnmanager, $advancedoptions) {
global $config, $g;
$uname_p = trim(exec("uname -p"));
$ovpndir = "/usr/local/share/openvpn/";
if (!file_exists($workdir . "/template/openvpn-install.exe"))
openvpn_client_export_install();
$uniq = uniqid();
$tempdir = $g['tmp_path'] . "/openvpn-export-" . $uniq;
$zipfile = $g['tmp_path'] . "/{$uniq}-Viscosity.visc.zip";
$validconfig = openvpn_client_export_validate_config($srvid, $usrid, $crtid);
if ($validconfig) {
list($settings, $server_cert, $server_ca, $servercn, $user, $cert, $nokeys) = $validconfig;
} else {
return false;
}
// create template directory
mkdir($tempdir, 0700, true);
mkdir($tempdir . "/Viscosity.visc", 0700, true);
// Append new Viscosity.visc directory on top
$tempdir = $tempdir . "/Viscosity.visc/";
// write cofiguration file
$prefix = openvpn_client_export_prefix($srvid, $usrid, $crtid);
if (!empty($proxy) && $proxy['proxy_authtype'] != "none") {
$proxy['passwdfile'] = "config-password";
$pwdfle = "{$proxy['user']}\n";
$pwdfle .= "{$proxy['password']}\n";
file_put_contents("{$tempdir}/{$proxy['passwdfile']}", $pwdfle);
}
$conf = openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, true, $proxy, "baseconf", $outpass, true, true, $openvpnmanager, $advancedoptions);
if (!$conf)
return false;
// We need to nuke the ca line from the above config if it exists.
$conf = explode("\n", $conf);
for ($i=0; $i < count($conf); $i++) {
if ((substr($conf[$i], 0, 3) == "ca ") || (substr($conf[$i], 0, 7) == "pkcs12 "))
unset($conf[$i]);
}
$conf = implode("\n", $conf);
$friendly_name = $settings['description'];
$visc_settings = <<<EOF
#-- Config Auto Generated By pfSense for Viscosity --#
#viscosity startonopen false
#viscosity dhcp true
#viscosity dnssupport true
#viscosity name {$friendly_name}
EOF;
$configfile = "{$tempdir}/config.conf";
$conf .= "ca ca.crt\n";
$conf .= "tls-auth ta.key 1\n";
if ($settings['mode'] != "server_user") {
$conf .= <<<EOF
cert cert.crt
key key.key
EOF;
}
file_put_contents($configfile, $visc_settings . "\n" . $conf);
// ca.crt cert.crt config.conf key.key ta.key
// write ca
$cafile = "{$tempdir}/ca.crt";
file_put_contents($cafile, base64_decode($server_ca['crt']));
if ($settings['mode'] != "server_user") {
// write user .crt
$crtfile = "{$tempdir}/cert.crt";
file_put_contents($crtfile, base64_decode($cert['crt']));
// write user .key
if (!empty($outpass)) {
$keyfile = "{$tempdir}/key.key";
$clearkeyfile = "{$tempdir}/key-clear.key";
file_put_contents($clearkeyfile, base64_decode($cert['prv']));
$eoutpass = escapeshellarg($outpass);
$ekeyfile = escapeshellarg($keyfile);
$eclearkeyfile = escapeshellarg($clearkeyfile);
exec("/usr/bin/openssl rsa -in ${eclearkeyfile} -out ${ekeyfile} -des3 -passout pass:${eoutpass}");
unlink($clearkeyfile);
} else {
$keyfile = "{$tempdir}/key.key";
file_put_contents($keyfile, base64_decode($cert['prv']));
}
}
// TLS support?
if ($settings['tls']) {
$tlsfile = "{$tempdir}/ta.key";
file_put_contents($tlsfile, base64_decode($settings['tls']));
}
// Zip Viscosity file
if(file_exists("/usr/pbi/zip-{$uname_p}/bin/zip"))
exec("cd {$tempdir}/.. && /usr/pbi/zip-{$uname_p}/bin/zip -r {$zipfile} Viscosity.visc");
else
exec("cd {$tempdir}/.. && /usr/local/bin/zip -r {$zipfile} Viscosity.visc");
// Remove temporary directory
exec("rm -rf {$tempdir}");
return $zipfile;
}
function openvpn_client_export_sharedkey_config($srvid, $useaddr, $proxy, $zipconf = false) {
global $config, $input_errors, $g;
// lookup server settings
$settings = $config['openvpn']['openvpn-server'][$srvid];
if (empty($settings)) {
$input_errors[] = "Could not locate server configuration.";
return false;
}
if ($settings['disable']) {
$input_errors[] = "You cannot export for disabled servers.";
return false;
}
// determine basic variables
if ($useaddr == "serveraddr") {
$interface = $settings['interface'];
if (!empty($settings['ipaddr']) && is_ipaddr($settings['ipaddr'])) {
$server_host = $settings['ipaddr'];
} else {
if (!$interface)
$interface = "wan";
if (in_array(strtolower($settings['protocol']), array("udp6", "tcp6")))
$server_host = get_interface_ipv6($interface);
else
$server_host = get_interface_ip($interface);
}
} else if ($useaddr == "serverhostname" || empty($useaddr)) {
$server_host = empty($config['system']['hostname']) ? "" : "{$config['system']['hostname']}.";
$server_host .= "{$config['system']['domain']}";
} else
$server_host = $useaddr;
$server_port = $settings['local_port'];
$proto = strtolower($settings['protocol']);
if (strtolower(substr($settings['protocol'], 0, 3)) == "tcp")
$proto .= "-client";
$cipher = $settings['crypto'];
$digest = !empty($settings['digest']) ? $settings['digest'] : "SHA1";
// add basic settings
$conf = "dev tun\n";
if(! empty($settings['tunnel_networkv6'])) {
$conf .= "tun-ipv6\n";
}
$conf .= "persist-tun\n";
$conf .= "persist-key\n";
$conf .= "proto {$proto}\n";
$conf .= "cipher {$cipher}\n";
$conf .= "auth {$digest}\n";
$conf .= "pull\n";
$conf .= "resolv-retry infinite\n";
$conf .= "remote {$server_host} {$server_port}\n";
if ($settings['local_network']) {
list($ip, $mask) = explode('/', $settings['local_network']);
$mask = gen_subnet_mask($mask);
$conf .= "route $ip $mask\n";
}
if (!empty($settings['tunnel_network'])) {
list($ip, $mask) = explode('/', $settings['tunnel_network']);
$mask = gen_subnet_mask($mask);
$baselong = ip2long32($ip) & ip2long($mask);
$ip1 = long2ip32($baselong + 1);
$ip2 = long2ip32($baselong + 2);
$conf .= "ifconfig $ip2 $ip1\n";
}
$conf .= "keepalive 10 60\n";
$conf .= "ping-timer-rem\n";
if (!empty($proxy)) {
if ($proxy['proxy_type'] == "http") {
if ($proto == "udp") {
$input_errors[] = "This server uses UDP protocol and cannot communicate with HTTP proxy.";
return;
}
$conf .= "http-proxy {$proxy['ip']} {$proxy['port']} ";
}
if ($proxy['proxy_type'] == "socks")
$conf .= "socks-proxy {$proxy['ip']} {$proxy['port']} ";
if ($proxy['proxy_authtype'] != "none") {
if (!isset($proxy['passwdfile']))
$proxy['passwdfile'] = openvpn_client_export_prefix($srvid) . "-proxy";
$conf .= " {$proxy['passwdfile']} {$proxy['proxy_authtype']}";
}
$conf .= "\n";
}
// add key settings
$prefix = openvpn_client_export_prefix($srvid);
$shkeyfile = "{$prefix}.secret";
$conf .= "secret {$shkeyfile}\n";
// add optional settings
if ($settings['compression'])
$conf .= "comp-lzo\n";
if ($settings['passtos'])
$conf .= "passtos\n";
if ($zipconf == true) {
// create template directory
$tempdir = "{$g['tmp_path']}/{$prefix}";
mkdir($tempdir, 0700, true);
file_put_contents("{$tempdir}/{$prefix}.ovpn", $conf);
$shkeyfile = "{$tempdir}/{$shkeyfile}";
file_put_contents("{$shkeyfile}", base64_decode($settings['shared_key']));
if(file_exists("/usr/pbi/zip-{$uname_p}/bin/zip"))
exec("cd {$tempdir}/.. && /usr/pbi/zip-{$uname_p}/bin/zip -r {$g['tmp_path']}/{$prefix}-config.zip {$prefix}");
else
exec("cd {$tempdir}/.. && /usr/local/bin/zip -r {$g['tmp_path']}/{$prefix}-config.zip {$prefix}");
// Remove temporary directory
exec("rm -rf {$tempdir}");
return "{$prefix}-config.zip";
} else
return $conf;
}
function openvpn_client_export_build_remote_lines($settings, $useaddr, $interface, $expformat, $nl) {
global $config;
$remotes = array();
if (($useaddr == "serveraddr") || ($useaddr == "servermagic") || ($useaddr == "servermagichost")) {
$interface = $settings['interface'];
if (!empty($settings['ipaddr']) && is_ipaddr($settings['ipaddr'])) {
$server_host = $settings['ipaddr'];
} else {
if (!$interface || ($interface == "any"))
$interface = "wan";
if (in_array(strtolower($settings['protocol']), array("udp6", "tcp6")))
$server_host = get_interface_ipv6($interface);
else
$server_host = get_interface_ip($interface);
}
} else if ($useaddr == "serverhostname" || empty($useaddr)) {
$server_host = empty($config['system']['hostname']) ? "" : "{$config['system']['hostname']}.";
$server_host .= "{$config['system']['domain']}";
} else
$server_host = $useaddr;
$proto = strtolower($settings['protocol']);
if (strtolower(substr($settings['protocol'], 0, 3)) == "tcp")
$proto .= "-client";
if (($expformat == "inlineios") && ($proto == "tcp-client"))
$proto = "tcp";
if (($useaddr == "servermagic") || ($useaddr == "servermagichost")) {
$destinations = openvpn_client_export_find_port_forwards($server_host, $settings['local_port'], $proto, true, ($useaddr == "servermagichost"));
foreach ($destinations as $dest) {
$remotes[] = "remote {$dest['host']} {$dest['port']} {$dest['proto']}";
}
} else {
$remotes[] = "remote {$server_host} {$settings['local_port']} {$proto}";
}
return implode($nl, $remotes);
}
function openvpn_client_export_find_port_forwards($targetip, $targetport, $targetproto, $skipprivate, $findhostname=false) {
global $config, $FilterIflist;
if (empty($FilterIflist))
filter_generate_optcfg_array();
$destinations = array();
if (!is_array($config['nat']) || !is_array($config['nat']['rule']))
return $destinations;
foreach ($config['nat']['rule'] as $natent) {
$dest = array();
if (!isset($natent['disabled'])
&& ($natent['target'] == $targetip)
&& ($natent['local-port'] == $targetport)
&& ($natent['protocol'] == $targetproto)) {
$dest['proto'] = $natent['protocol'];
// Could be multiple ports... But we can only use one.
$dports = is_port($natent['destination']['port']) ? array($natent['destination']['port']) : filter_expand_alias_array($natent['destination']['port']);
$dest['port'] = $dports[0];
// Could be network or address ...
$natif = (!$natent['interface']) ? "wan" : $natent['interface'];
if (!isset($FilterIflist[$natif]))
continue; // Skip if there is no interface
$dstaddr = trim(filter_generate_address($natent, 'destination', true));
if(!$dstaddr)
$dstaddr = $FilterIflist[$natif]['ip'];
$dstaddr_port = explode(" ", $dstaddr);
if(empty($dstaddr_port[0]) || strtolower(trim($dstaddr_port[0])) == "port")
continue; // Skip port forward if no destination address found
if (!is_ipaddr($dstaddr_port[0]))
continue; // We can only work with single IPs, not subnets!
if ($skipprivate && is_private_ip($dstaddr_port[0]))
continue; // Skipping a private IP destination!
$dest['host'] = $dstaddr_port[0];
if ($findhostname) {
$hostname = openvpn_client_export_find_hostname($natif);
if (!empty($hostname))
$dest['host'] = $hostname;
}
$destinations[] = $dest;
}
}
return $destinations;
}
function openvpn_client_export_find_hostname($interface) {
global $config;
$hostname = "";
if (is_array($config['dyndnses']['dyndns'])) {
foreach ($config['dyndnses']['dyndns'] as $ddns) {
if (($ddns['interface'] == $interface) && isset($ddns['enable']) && !empty($ddns['host']) && !is_numeric($ddns['host']) && is_hostname($ddns['host']))
return $ddns['host'];
}
}
if (is_array($config['dnsupdates']['dnsupdate'])) {
foreach ($config['dnsupdates']['dnsupdate'] as $ddns) {
if (($ddns['interface'] == $interface) && isset($ddns['enable']) && !empty($ddns['host']) && !is_numeric($ddns['host']) && is_hostname($ddns['host']))
return $ddns['host'];
}
}
}
?>
......@@ -973,28 +973,6 @@ function display_top_tabs(& $tab_array, $no_drop_down = false) {
}
function add_package_tabs($tabgroup, & $tab_array) {
global $config, $g;
if(!is_array($config['installedpackages']))
return;
if(!is_array($config['installedpackages']['tab']))
return;
foreach($config['installedpackages']['tab'] as $tab) {
if ($tab['group'] !== $group)
continue;
$tab_entry = array();
if($tab['name']) {
$tab_entry[] = $tab['name'];
$tab_entry[] = false;
$tab_entry[] = $tab['url'];
$tab_array[] = $tab_entry;
}
}
}
function alias_info_popup($alias_id){
global $config;
$maxlength = 60;
......
......@@ -446,7 +446,8 @@ function autotls_change() {
$tab_array[] = array(gettext("Client"), true, "vpn_openvpn_client.php");
$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
add_package_tabs("OpenVPN", $tab_array);
$tab_array[] = array(gettext("Client Export"), false, "vpn_openvpn_export.php");
$tab_array[] = array(gettext("Shared Key Export"), false, "vpn_openvpn_export_shared.php");
display_top_tabs($tab_array);
?>
......
......@@ -326,7 +326,8 @@ if($act!="new" && $act!="edit") {
$tab_array[] = array(gettext("Client"), false, "vpn_openvpn_client.php");
$tab_array[] = array(gettext("Client Specific Overrides"), true, "vpn_openvpn_csc.php");
$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
add_package_tabs("OpenVPN", $tab_array);
$tab_array[] = array(gettext("Client Export"), false, "vpn_openvpn_export.php");
$tab_array[] = array(gettext("Shared Key Export"), false, "vpn_openvpn_export_shared.php");
display_top_tabs($tab_array);
?>
......
<?php
/*
vpn_openvpn_export.php
Copyright (C) 2008 Shrew Soft Inc.
Copyright (C) 2010 Ermal Luçi
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
DISABLE_PHP_LINT_CHECKING
*/
require("globals.inc");
require("guiconfig.inc");
require("openvpn-client-export.inc");
global $current_openvpn_version, $current_openvpn_version_rev;
$pgtitle = array("OpenVPN", "Client Export Utility");
if (!is_array($config['openvpn']['openvpn-server']))
$config['openvpn']['openvpn-server'] = array();
$a_server = $config['openvpn']['openvpn-server'];
if (!is_array($config['system']['user']))
$config['system']['user'] = array();
$a_user = $config['system']['user'];
if (!is_array($config['cert']))
$config['cert'] = array();
$a_cert = $config['cert'];
$ras_server = array();
foreach($a_server as $sindex => $server) {
if (isset($server['disable']))
continue;
$ras_user = array();
$ras_certs = array();
if (stripos($server['mode'], "server") === false)
continue;
if (($server['mode'] == "server_tls_user") && ($server['authmode'] == "Local Database")) {
foreach($a_user as $uindex => $user) {
if (!is_array($user['cert']))
continue;
foreach($user['cert'] as $cindex => $cert) {
// If $cert is not an array, it's a certref not a cert.
if (!is_array($cert))
$cert = lookup_cert($cert);
if ($cert['caref'] != $server['caref'])
continue;
$ras_userent = array();
$ras_userent['uindex'] = $uindex;
$ras_userent['cindex'] = $cindex;
$ras_userent['name'] = $user['name'];
$ras_userent['certname'] = $cert['descr'];
$ras_user[] = $ras_userent;
}
}
} elseif (($server['mode'] == "server_tls") || (($server['mode'] == "server_tls_user") && ($server['authmode'] != "Local Database"))) {
foreach($a_cert as $cindex => $cert) {
if (($cert['caref'] != $server['caref']) || ($cert['refid'] == $server['certref']))
continue;
$ras_cert_entry['cindex'] = $cindex;
$ras_cert_entry['certname'] = $cert['descr'];
$ras_cert_entry['certref'] = $cert['refid'];
$ras_certs[] = $ras_cert_entry;
}
}
$ras_serverent = array();
$prot = $server['protocol'];
$port = $server['local_port'];
if ($server['description'])
$name = "{$server['description']} {$prot}:{$port}";
else
$name = "Server {$prot}:{$port}";
$ras_serverent['index'] = $sindex;
$ras_serverent['name'] = $name;
$ras_serverent['users'] = $ras_user;
$ras_serverent['certs'] = $ras_certs;
$ras_serverent['mode'] = $server['mode'];
$ras_server[] = $ras_serverent;
}
$id = $_GET['id'];
if (isset($_POST['id']))
$id = $_POST['id'];
$act = $_GET['act'];
if (isset($_POST['act']))
$act = $_POST['act'];
if (!empty($act)) {
$srvid = $_GET['srvid'];
$usrid = $_GET['usrid'];
$crtid = $_GET['crtid'];
if ($srvid === false) {
pfSenseHeader("vpn_openvpn_export.php");
exit;
} else if (($config['openvpn']['openvpn-server'][$srvid]['mode'] != "server_user") &&
(($usrid === false) || ($crtid === false))) {
pfSenseHeader("vpn_openvpn_export.php");
exit;
}
if ($config['openvpn']['openvpn-server'][$srvid]['mode'] == "server_user")
$nokeys = true;
else
$nokeys = false;
$useaddr = '';
if (isset($_GET['useaddr']) && !empty($_GET['useaddr']))
$useaddr = trim($_GET['useaddr']);
if (!(is_ipaddr($useaddr) || is_hostname($useaddr) ||
in_array($useaddr, array("serveraddr", "servermagic", "servermagichost", "serverhostname"))))
$input_errors[] = "You need to specify an IP or hostname.";
$advancedoptions = $_GET['advancedoptions'];
$openvpnmanager = $_GET['openvpnmanager'];
$verifyservercn = $_GET['verifyservercn'];
$randomlocalport = $_GET['randomlocalport'];
$usetoken = $_GET['usetoken'];
if ($usetoken && (substr($act, 0, 10) == "confinline"))
$input_errors[] = "You cannot use Microsoft Certificate Storage with an Inline configuration.";
if ($usetoken && (($act == "conf_yealink_t28") || ($act == "conf_yealink_t38g") || ($act == "conf_yealink_t38g2") || ($act == "conf_snom")))
$input_errors[] = "You cannot use Microsoft Certificate Storage with a Yealink or SNOM configuration.";
$password = "";
if ($_GET['password'])
$password = $_GET['password'];
$proxy = "";
if (!empty($_GET['proxy_addr']) || !empty($_GET['proxy_port'])) {
$proxy = array();
if (empty($_GET['proxy_addr'])) {
$input_errors[] = "You need to specify an address for the proxy port.";
} else
$proxy['ip'] = $_GET['proxy_addr'];
if (empty($_GET['proxy_port'])) {
$input_errors[] = "You need to specify a port for the proxy ip.";
} else
$proxy['port'] = $_GET['proxy_port'];
$proxy['proxy_type'] = $_GET['proxy_type'];
$proxy['proxy_authtype'] = $_GET['proxy_authtype'];
if ($_GET['proxy_authtype'] != "none") {
if (empty($_GET['proxy_user'])) {
$input_errors[] = "You need to specify a username with the proxy config.";
} else
$proxy['user'] = $_GET['proxy_user'];
if (!empty($_GET['proxy_user']) && empty($_GET['proxy_password'])) {
$input_errors[] = "You need to specify a password with the proxy user.";
} else
$proxy['password'] = $_GET['proxy_password'];
}
}
$exp_name = openvpn_client_export_prefix($srvid, $usrid, $crtid);
if(substr($act, 0, 4) == "conf") {
switch ($act) {
case "confzip":
$exp_name = urlencode($exp_name."-config.zip");
$expformat = "zip";
break;
case "conf_yealink_t28":
$exp_name = urlencode("client.tar");
$expformat = "yealink_t28";
break;
case "conf_yealink_t38g":
$exp_name = urlencode("client.tar");
$expformat = "yealink_t38g";
break;
case "conf_yealink_t38g2":
$exp_name = urlencode("client.tar");
$expformat = "yealink_t38g2";
break;
case "conf_snom":
$exp_name = urlencode("vpnclient.tar");
$expformat = "snom";
break;
case "confinline":
$exp_name = urlencode($exp_name."-config.ovpn");
$expformat = "inline";
break;
case "confinlinedroid":
$exp_name = urlencode($exp_name."-android-config.ovpn");
$expformat = "inlinedroid";
break;
case "confinlineios":
$exp_name = urlencode($exp_name."-ios-config.ovpn");
$expformat = "inlineios";
break;
default:
$exp_name = urlencode($exp_name."-config.ovpn");
$expformat = "baseconf";
}
$exp_path = openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $nokeys, $proxy, $expformat, $password, false, false, $openvpnmanager, $advancedoptions);
}
if($act == "visc") {
$exp_name = urlencode($exp_name."-Viscosity.visc.zip");
$exp_path = viscosity_openvpn_client_config_exporter($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $password, $proxy, $openvpnmanager, $advancedoptions);
}
if(substr($act, 0, 4) == "inst") {
$exp_name = urlencode($exp_name."-install.exe");
$exp_path = openvpn_client_export_installer($srvid, $usrid, $crtid, $useaddr, $verifyservercn, $randomlocalport, $usetoken, $password, $proxy, $openvpnmanager, $advancedoptions, substr($act, 5));
}
if (!$exp_path) {
$input_errors[] = "Failed to export config files!";
}
if (empty($input_errors)) {
if (($act == "conf") || (substr($act, 0, 10) == "confinline")) {
$exp_size = strlen($exp_path);
} else {
$exp_size = filesize($exp_path);
}
header('Pragma: ');
header('Cache-Control: ');
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$exp_name}");
header("Content-Length: $exp_size");
if (($act == "conf") || (substr($act, 0, 10) == "confinline")) {
echo $exp_path;
} else {
readfile($exp_path);
@unlink($exp_path);
}
exit;
}
}
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<script type="text/javascript">
//<![CDATA[
var viscosityAvailable = false;
var servers = new Array();
<?php foreach ($ras_server as $sindex => $server): ?>
servers[<?=$sindex;?>] = new Array();
servers[<?=$sindex;?>][0] = '<?=$server['index'];?>';
servers[<?=$sindex;?>][1] = new Array();
servers[<?=$sindex;?>][2] = '<?=$server['mode'];?>';
servers[<?=$sindex;?>][3] = new Array();
<?php foreach ($server['users'] as $uindex => $user): ?>
servers[<?=$sindex;?>][1][<?=$uindex;?>] = new Array();
servers[<?=$sindex;?>][1][<?=$uindex;?>][0] = '<?=$user['uindex'];?>';
servers[<?=$sindex;?>][1][<?=$uindex;?>][1] = '<?=$user['cindex'];?>';
servers[<?=$sindex;?>][1][<?=$uindex;?>][2] = '<?=$user['name'];?>';
servers[<?=$sindex;?>][1][<?=$uindex;?>][3] = '<?=str_replace("'", "\\'", $user['certname']);?>';
<? endforeach; ?>
<?php $c=0;
foreach ($server['certs'] as $cert): ?>
servers[<?=$sindex;?>][3][<?=$c;?>] = new Array();
servers[<?=$sindex;?>][3][<?=$c;?>][0] = '<?=$cert['cindex'];?>';
servers[<?=$sindex;?>][3][<?=$c;?>][1] = '<?=str_replace("'", "\\'", $cert['certname']);?>';
<? $c++;
endforeach; ?>
<? endforeach; ?>
function download_begin(act, i, j) {
var index = document.getElementById("server").selectedIndex;
var users = servers[index][1];
var certs = servers[index][3];
var useaddr;
var advancedoptions;
if (document.getElementById("useaddr").value == "other") {
if (document.getElementById("useaddr_hostname").value == "") {
alert("Please specify an IP address or hostname.");
return;
}
useaddr = document.getElementById("useaddr_hostname").value;
} else
useaddr = document.getElementById("useaddr").value;
advancedoptions = document.getElementById("advancedoptions").value;
var verifyservercn;
verifyservercn = document.getElementById("verifyservercn").value;
var randomlocalport = 0;
if (document.getElementById("randomlocalport").checked)
randomlocalport = 1;
var usetoken = 0;
if (document.getElementById("usetoken").checked)
usetoken = 1;
var usepass = 0;
if (document.getElementById("usepass").checked)
usepass = 1;
var openvpnmanager = 0;
if (document.getElementById("openvpnmanager").checked)
openvpnmanager = 1;
var pass = document.getElementById("pass").value;
var conf = document.getElementById("conf").value;
if (usepass && (act.substring(0,4) == "inst")) {
if (!pass || !conf) {
alert("The password or confirm field is empty");
return;
}
if (pass != conf) {
alert("The password and confirm fields must match");
return;
}
}
var useproxy = 0;
var useproxypass = 0;
if (document.getElementById("useproxy").checked)
useproxy = 1;
var proxyaddr = document.getElementById("proxyaddr").value;
var proxyport = document.getElementById("proxyport").value;
if (useproxy) {
if (!proxyaddr || !proxyport) {
alert("The proxy ip and port cannot be empty");
return;
}
if (document.getElementById("useproxypass").value != 'none')
useproxypass = 1;
var proxytype = document.getElementById("useproxytype").value;
var proxyauth = document.getElementById("useproxypass").value;
var proxyuser = document.getElementById("proxyuser").value;
var proxypass = document.getElementById("proxypass").value;
var proxyconf = document.getElementById("proxyconf").value;
if (useproxypass) {
if (!proxyuser) {
alert("Please fill the proxy username and password.");
return;
}
if (!proxypass || !proxyconf) {
alert("The proxy password or confirm field is empty");
return;
}
if (proxypass != proxyconf) {
alert("The proxy password and confirm fields must match");
return;
}
}
}
var dlurl;
dlurl = "/vpn_openvpn_export.php?act=" + act;
dlurl += "&srvid=" + escape(servers[index][0]);
if (users[i]) {
dlurl += "&usrid=" + escape(users[i][0]);
dlurl += "&crtid=" + escape(users[i][1]);
}
if (certs[j]) {
dlurl += "&usrid=";
dlurl += "&crtid=" + escape(certs[j][0]);
}
dlurl += "&useaddr=" + escape(useaddr);
dlurl += "&verifyservercn=" + escape(verifyservercn);
dlurl += "&randomlocalport=" + escape(randomlocalport);
dlurl += "&openvpnmanager=" + escape(openvpnmanager);
dlurl += "&usetoken=" + escape(usetoken);
if (usepass)
dlurl += "&password=" + escape(pass);
if (useproxy) {
dlurl += "&proxy_type=" + escape(proxytype);
dlurl += "&proxy_addr=" + escape(proxyaddr);
dlurl += "&proxy_port=" + escape(proxyport);
dlurl += "&proxy_authtype=" + escape(proxyauth);
if (useproxypass) {
dlurl += "&proxy_user=" + escape(proxyuser);
dlurl += "&proxy_password=" + escape(proxypass);
}
}
dlurl += "&advancedoptions=" + escape(advancedoptions);
window.open(dlurl,"_self");
}
function server_changed() {
var table = document.getElementById("users");
while (table.rows.length > 1 )
table.deleteRow(1);
var index = document.getElementById("server").selectedIndex;
var users = servers[index][1];
var certs = servers[index][3];
for (i=0; i < users.length; i++) {
var row = table.insertRow(table.rows.length);
var cell0 = row.insertCell(0);
var cell1 = row.insertCell(1);
var cell2 = row.insertCell(2);
cell0.className = "listlr";
cell0.innerHTML = users[i][2];
cell1.className = "listr";
cell1.innerHTML = users[i][3];
cell2.className = "listr";
cell2.innerHTML = "- Standard Configurations:<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confzip\"," + i + ", -1)'>Archive<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"conf\"," + i + ", -1)'>Config Only<\/a>";
cell2.innerHTML += "<br\/>- Inline Configurations:<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confinlinedroid\"," + i + ", -1)'>Android<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confinlineios\"," + i + ", -1)'>OpenVPN Connect (iOS/Android)<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confinline\"," + i + ", -1)'>Others<\/a>";
cell2.innerHTML += "<br\/>- Windows Installers (<?php echo $current_openvpn_version . '-Ix' . $current_openvpn_version_rev;?>):<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x86-xp\"," + i + ", -1)'>x86-xp<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x64-xp\"," + i + ", -1)'>x64-xp<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x86-win6\"," + i + ", -1)'>x86-win6<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x64-win6\"," + i + ", -1)'>x64-win6<\/a>";
cell2.innerHTML += "<br\/>- Mac OSX:<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"visc\"," + i + ", -1)'>Viscosity Bundle<\/a>";
}
for (j=0; j < certs.length; j++) {
var row = table.insertRow(table.rows.length);
var cell0 = row.insertCell(0);
var cell1 = row.insertCell(1);
var cell2 = row.insertCell(2);
cell0.className = "listlr";
if (servers[index][2] == "server_tls") {
cell0.innerHTML = "Certificate (SSL/TLS, no Auth)";
} else {
cell0.innerHTML = "Certificate with External Auth";
}
cell1.className = "listr";
cell1.innerHTML = certs[j][1];
cell2.className = "listr";
cell2.innerHTML = "- Standard Configurations:<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confzip\", -1," + j + ")'>Archive<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"conf\", -1," + j + ")'>File Only<\/a>";
cell2.innerHTML += "<br\/>- Inline Configurations:<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confinlinedroid\", -1," + j + ")'>Android<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confinlineios\", -1," + j + ")'>OpenVPN Connect (iOS/Android)<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confinline\", -1," + j + ")'>Others<\/a>";
cell2.innerHTML += "<br\/>- Windows Installers (<?php echo $current_openvpn_version . '-Ix' . $current_openvpn_version_rev;?>):<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x86-xp\", -1," + j + ")'>x86-xp<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x64-xp\", -1," + j + ")'>x64-xp<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x86-win6\", -1," + j + ")'>x86-win6<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x64-win6\", -1," + j + ")'>x64-win6<\/a>";
cell2.innerHTML += "<br\/>- Mac OSX:<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"visc\", -1," + j + ")'>Viscosity Bundle<\/a>";
if (servers[index][2] == "server_tls") {
cell2.innerHTML += "<br\/>- Yealink SIP Handsets: <br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"conf_yealink_t28\", -1," + j + ")'>T28<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"conf_yealink_t38g\", -1," + j + ")'>T38G (1)<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"conf_yealink_t38g2\", -1," + j + ")'>T38G (2)<\/a>";
cell2.innerHTML += "<br\/>";
cell2.innerHTML += "- <a href='javascript:download_begin(\"conf_snom\", -1," + j + ")'>SNOM SIP Handset<\/a>";
}
}
if (servers[index][2] == 'server_user') {
var row = table.insertRow(table.rows.length);
var cell0 = row.insertCell(0);
var cell1 = row.insertCell(1);
var cell2 = row.insertCell(2);
cell0.className = "listlr";
cell0.innerHTML = "Authentication Only (No Cert)";
cell1.className = "listr";
cell1.innerHTML = "none";
cell2.className = "listr";
cell2.innerHTML = "- Standard Configurations:<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confzip\"," + i + ")'>Archive<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"conf\"," + i + ")'>File Only<\/a>";
cell2.innerHTML += "<br\/>- Inline Configurations:<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confinlinedroid\"," + i + ")'>Android<\a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confinlineios\"," + i + ")'>OpenVPN Connect (iOS/Android)<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"confinline\"," + i + ")'>Others<\/a>";
cell2.innerHTML += "<br\/>- Windows Installers (<?php echo $current_openvpn_version . '-Ix' . $current_openvpn_version_rev;?>):<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x86-xp\"," + i + ")'>x86-xp<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x64-xp\"," + i + ")'>x64-xp<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x86-win6\"," + i + ")'>x86-win6<\/a>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"inst-x64-win6\"," + i + ")'>x64-win6<\/a>";
cell2.innerHTML += "<br\/>- Mac OSX:<br\/>";
cell2.innerHTML += "&nbsp;&nbsp; ";
cell2.innerHTML += "<a href='javascript:download_begin(\"visc\"," + i + ")'>Viscosity Bundle<\/a>";
}
}
function useaddr_changed(obj) {
if (obj.value == "other")
$('HostName').show();
else
$('HostName').hide();
}
function usepass_changed() {
if (document.getElementById("usepass").checked)
document.getElementById("usepass_opts").style.display = "";
else
document.getElementById("usepass_opts").style.display = "none";
}
function useproxy_changed(obj) {
if ((obj.id == "useproxy" && obj.checked) ||
(obj.id == "useproxypass" && (obj.value != 'none'))) {
$(obj.id + '_opts').show();
} else {
$(obj.id + '_opts').hide();
}
}
//]]>
</script>
<?php
if ($input_errors)
print_input_errors($input_errors);
if ($savemsg)
print_info_box($savemsg);
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="openvpn export">
<tr>
<td>
<?php
$tab_array = array();
$tab_array[] = array(gettext("Server"), false, "vpn_openvpn_server.php");
$tab_array[] = array(gettext("Client"), false, "vpn_openvpn_client.php");
$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
$tab_array[] = array(gettext("Client Export"), true, "vpn_openvpn_export.php");
$tab_array[] = array(gettext("Shared Key Export"), false, "vpn_openvpn_export_shared.php");
display_top_tabs($tab_array);
?>
</td>
</tr>
<tr>
<td id="mainarea">
<div class="tabcont">
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
<tr>
<td width="22%" valign="top" class="vncellreq">Remote Access Server</td>
<td width="78%" class="vtable">
<select name="server" id="server" class="formselect" onchange="server_changed()">
<?php foreach($ras_server as & $server): ?>
<option value="<?=$server['index'];?>"><?=$server['name'];?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Host Name Resolution</td>
<td width="78%" class="vtable">
<table border="0" cellpadding="2" cellspacing="0" summary="name resolution">
<tr>
<td>
<select name="useaddr" id="useaddr" class="formselect" onchange="useaddr_changed(this)">
<option value="serveraddr" >Interface IP Address</option>
<option value="servermagic" >Automagic Multi-WAN IPs (port forward targets)</option>
<option value="servermagichost" >Automagic Multi-WAN DDNS Hostnames (port forward targets)</option>
<option value="serverhostname" >Installation hostname</option>
<?php if (is_array($config['dyndnses']['dyndns'])): ?>
<?php foreach ($config['dyndnses']['dyndns'] as $ddns): ?>
<option value="<?php echo $ddns["host"] ?>">DynDNS: <?php echo $ddns["host"] ?></option>
<?php endforeach; ?>
<?php endif; ?>
<?php if (is_array($config['dnsupdates']['dnsupdate'])): ?>
<?php foreach ($config['dnsupdates']['dnsupdate'] as $ddns): ?>
<option value="<?php echo $ddns["host"] ?>">DynDNS: <?php echo $ddns["host"] ?></option>
<?php endforeach; ?>
<?php endif; ?>
<option value="other">Other</option>
</select>
<br />
<div style="display:none;" id="HostName">
<input name="useaddr_hostname" id="useaddr_hostname" size="40" />
<span class="vexpl">
Enter the hostname or IP address the client will use to connect to this server.
</span>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Verify Server CN</td>
<td width="78%" class="vtable">
<table border="0" cellpadding="2" cellspacing="0" summary="verify server cn">
<tr>
<td>
<select name="verifyservercn" id="verifyservercn" class="formselect">
<option value="auto">Automatic - Use verify-x509-name (OpenVPN 2.3+) where possible</option>
<option value="tls-remote">Use tls-remote (Deprecated, use only on old clients &lt;= OpenVPN 2.2.x)</option>
<option value="tls-remote-quote">Use tls-remote and quote the server CN</option>
<option value="none">Do not verify the server CN</option>
</select>
<br/>
<span class="vexpl">
Optionally verify the server certificate Common Name (CN) when the client connects. Current clients, including the most recent versions of Windows, Viscosity, Tunnelblick, OpenVPN on iOS and Android and so on should all work at the default automatic setting.
<br/><br/>Only use tls-remote if you must use an older client that you cannot control. The option has been deprecated by OpenVPN and will be removed in the next major version.
<br/><br/>With tls-remote the server CN may optionally be enclosed in quotes. This can help if the server CN contains spaces and certain clients cannot parse the server CN. Some clients have problems parsing the CN with quotes. Use only as needed.
</span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Use Random Local Port</td>
<td width="78%" class="vtable">
<table border="0" cellpadding="2" cellspacing="0" summary="random local port">
<tr>
<td>
<input name="randomlocalport" id="randomlocalport" type="checkbox" value="yes" checked="CHECKED" />
</td>
<td>
<span class="vexpl">
Use a random local source port (lport) for traffic from the client. Without this set, two clients may not run concurrently.
</span>
</td>
</tr>
<tr>
<td colspan="2">
<span class="vexpl"><br/>NOTE: Not supported on older clients. Automatically disabled for Yealink and Snom configurations.</span>
</td>
</tr>
</table>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Certificate Export Options</td>
<td width="78%" class="vtable">
<table border="0" cellpadding="2" cellspacing="0" summary="export options">
<tr>
<td>
<input name="usetoken" id="usetoken" type="checkbox" value="yes" />
</td>
<td>
<span class="vexpl">
Use Microsoft Certificate Storage instead of local files.
</span>
</td>
</tr>
</table>
<table border="0" cellpadding="2" cellspacing="0" summary="checkbox for password">
<tr>
<td>
<input name="usepass" id="usepass" type="checkbox" value="yes" onclick="usepass_changed()" />
</td>
<td>
<span class="vexpl">
Use a password to protect the pkcs12 file contents or key in Viscosity bundle.
</span>
</td>
</tr>
</table>
<table border="0" cellpadding="2" cellspacing="0" id="usepass_opts" style="display:none" summary="password">
<tr>
<td align="right">
<span class="vexpl">
&nbsp;Password :&nbsp;
</span>
</td>
<td>
<input name="pass" id="pass" type="password" class="formfld pwd" size="20" value="" />
</td>
</tr>
<tr>
<td align="right">
<span class="vexpl">
&nbsp;Confirm :&nbsp;
</span>
</td>
<td>
<input name="conf" id="conf" type="password" class="formfld pwd" size="20" value="" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Use Proxy</td>
<td width="78%" class="vtable">
<table border="0" cellpadding="2" cellspacing="0" summary="http proxy">
<tr>
<td>
<input name="useproxy" id="useproxy" type="checkbox" value="yes" onclick="useproxy_changed(this)" />
</td>
<td>
<span class="vexpl">
Use proxy to communicate with the server.
</span>
</td>
</tr>
</table>
<table border="0" cellpadding="2" cellspacing="0" id="useproxy_opts" style="display:none" summary="user options">
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp; Type :&nbsp;
</span>
</td>
<td>
<select name="useproxytype" id="useproxytype" class="formselect">
<option value="http">HTTP</option>
<option value="socks">Socks</option>
</select>
</td>
</tr>
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp; IP Address :&nbsp;
</span>
</td>
<td>
<input name="proxyaddr" id="proxyaddr" class="formfld unknown" size="30" value="" />
</td>
</tr>
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp; Port :&nbsp;
</span>
</td>
<td>
<input name="proxyport" id="proxyport" class="formfld unknown" size="5" value="" />
</td>
</tr>
<tr>
<td width="25%">
<br />
</td>
<td>
<select name="useproxypass" id="useproxypass" class="formselect" onchange="useproxy_changed(this)">
<option value="none">none</option>
<option value="basic">basic</option>
<option value="ntlm">ntlm</option>
</select>
<span class="vexpl">
Choose proxy authentication if any.
</span>
<br />
<table border="0" cellpadding="2" cellspacing="0" id="useproxypass_opts" style="display:none" summary="name and password">
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp;Username :&nbsp;
</span>
</td>
<td>
<input name="proxyuser" id="proxyuser" class="formfld unknown" size="20" value="" />
</td>
</tr>
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp;Password :&nbsp;
</span>
</td>
<td>
<input name="proxypass" id="proxypass" type="password" class="formfld pwd" size="20" value="" />
</td>
</tr>
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp;Confirm :&nbsp;
</span>
</td>
<td>
<input name="proxyconf" id="proxyconf" type="password" class="formfld pwd" size="20" value="" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Management&nbsp;Interface<br/>OpenVPNManager</td>
<td width="78%" class="vtable">
<table border="0" cellpadding="2" cellspacing="0" summary="openvpn manager">
<tr>
<td>
<input name="openvpnmanager" id="openvpnmanager" type="checkbox" value="yes" />
</td>
<td>
<span class="vexpl">
This will change the generated .ovpn configuration to allow for usage of the management interface.
And include the OpenVPNManager program in the "Windows Installers". With this OpenVPN can be used also by non-administrator users.
This is also useful for Windows Vista/7/8 systems where elevated permissions are needed to add routes to the system.
</span>
</td>
</tr>
<tr>
<td colspan="2">
<span class="vexpl"><br/>NOTE: This is not currently compatible with the 64-bit OpenVPN installer. It will work with the 32-bit installer on a 64-bit system.</span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" class="list" height="12">&nbsp;</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Additional configuration options</td>
<td width="78%" class="vtable">
<textarea rows="6" cols="68" name="advancedoptions" id="advancedoptions"></textarea><br/>
<?=gettext("Enter any additional options you would like to add to the OpenVPN client export configuration here, separated by a line break or semicolon"); ?><br/>
<?=gettext("EXAMPLE: remote-random"); ?>;
</td>
</tr>
<tr>
<td colspan="2" valign="top" class="listtopic">Client Install Packages</td>
</tr>
</table>
<table width="100%" id="users" border="0" cellpadding="0" cellspacing="0" summary="heading">
<tr>
<td width="25%" class="listhdrr"><?=gettext("User");?></td>
<td width="35%" class="listhdrr"><?=gettext("Certificate Name");?></td>
<td width="40%" class="listhdrr"><?=gettext("Export");?></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="5" summary="note">
<tr>
<td align="right" valign="top" width="5%"><?= gettext("NOTES:") ?></td>
<td><?= gettext("The &quot;XP&quot; Windows installers work on Windows XP and later versions. The &quot;win6&quot; Windows installers include a new tap-windows6 driver that works only on Windows Vista and later.") ?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><?= gettext("If you expect to see a certain client in the list but it is not there, it is usually due to a CA mismatch between the OpenVPN server instance and the client certificates found in the User Manager.") ?></td>
</tr>
<tr>
<td colspan="2"><br/><strong><?= gettext("Links to OpenVPN clients for various platforms:") ?></strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<a href="http://openvpn.net/index.php/open-source/downloads.html"><?= gettext("OpenVPN Community Client") ?></a> - <?=gettext("Binaries for Windows, Source for other platforms. Packaged above in the Windows Installers")?>
<br/><a href="https://play.google.com/store/apps/details?id=de.blinkt.openvpn"><?= gettext("OpenVPN For Android") ?></a> - <?=gettext("Recommended client for Android")?>
<br/><a href="http://www.featvpn.com/"><?= gettext("FEAT VPN For Android") ?></a> - <?=gettext("For older versions of Android")?>
<br/><?= gettext("OpenVPN Connect") ?>: <a href="https://play.google.com/store/apps/details?id=net.openvpn.openvpn"><?=gettext("Android (Google Play)")?></a> or <a href="https://itunes.apple.com/us/app/openvpn-connect/id590379981"><?=gettext("iOS (App Store)")?></a> - <?= gettext("Recommended client for iOS") ?>
<br/><a href="http://www.sparklabs.com/viscosity/"><?= gettext("Viscosity") ?></a> - <?= gettext("Recommended client for Mac OSX") ?>
<br/><a href="http://code.google.com/p/tunnelblick/"><?= gettext("Tunnelblick") ?></a> - <?= gettext("Free client for OSX") ?>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<script type="text/javascript">
//<![CDATA[
server_changed();
//]]>
</script>
<?php include("fend.inc"); ?>
</body>
</html>
<?php
/*
vpn_openvpn_export_shared.php
Copyright (C) 2008 Shrew Soft Inc.
Copyright (C) 2010 Ermal Luçi
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
DISABLE_PHP_LINT_CHECKING
*/
require("globals.inc");
require("guiconfig.inc");
require("openvpn-client-export.inc");
$pgtitle = array("OpenVPN", "Client Export Utility");
if (!is_array($config['openvpn']['openvpn-server']))
$config['openvpn']['openvpn-server'] = array();
$a_server = $config['openvpn']['openvpn-server'];
$ras_server = array();
foreach($a_server as $sindex => $server) {
if (isset($server['disable']))
continue;
$ras_user = array();
if ($server['mode'] != "p2p_shared_key")
continue;
$ras_serverent = array();
$prot = $server['protocol'];
$port = $server['local_port'];
if ($server['description'])
$name = "{$server['description']} {$prot}:{$port}";
else
$name = "Shared Key Server {$prot}:{$port}";
$ras_serverent['index'] = $sindex;
$ras_serverent['name'] = $name;
$ras_serverent['mode'] = $server['mode'];
$ras_server[] = $ras_serverent;
}
$id = $_GET['id'];
if (isset($_POST['id']))
$id = $_POST['id'];
$act = $_GET['act'];
if (isset($_POST['act']))
$act = $_POST['act'];
$error = false;
if(($act == "skconf") || ($act == "skzipconf")) {
$srvid = $_GET['srvid'];
if (($srvid === false) || ($config['openvpn']['openvpn-server'][$srvid]['mode'] != "p2p_shared_key")) {
pfSenseHeader("vpn_openvpn_export.php");
exit;
}
if (empty($_GET['useaddr'])) {
$error = true;
$input_errors[] = "You need to specify an IP or hostname.";
} else
$useaddr = $_GET['useaddr'];
$proxy = "";
if (!empty($_GET['proxy_addr']) || !empty($_GET['proxy_port'])) {
$proxy = array();
if (empty($_GET['proxy_addr'])) {
$error = true;
$input_errors[] = "You need to specify an address for the proxy port.";
} else
$proxy['ip'] = $_GET['proxy_addr'];
if (empty($_GET['proxy_port'])) {
$error = true;
$input_errors[] = "You need to specify a port for the proxy ip.";
} else
$proxy['port'] = $_GET['proxy_port'];
$proxy['proxy_type'] = $_GET['proxy_type'];
$proxy['proxy_authtype'] = $_GET['proxy_authtype'];
if ($_GET['proxy_authtype'] != "none") {
if (empty($_GET['proxy_user'])) {
$error = true;
$input_errors[] = "You need to specify a username with the proxy config.";
} else
$proxy['user'] = $_GET['proxy_user'];
if (!empty($_GET['proxy_user']) && empty($_GET['proxy_password'])) {
$error = true;
$input_errors[] = "You need to specify a password with the proxy user.";
} else
$proxy['password'] = $_GET['proxy_password'];
}
}
$exp_name = openvpn_client_export_prefix($srvid);
if ($act == "skzipconf")
$zipconf = true;
$exp_data = openvpn_client_export_sharedkey_config($srvid, $useaddr, $proxy, $zipconf);
if (!$exp_data) {
$input_errors[] = "Failed to export config files!";
$error = true;
}
if (!$error) {
if ($zipconf) {
$exp_name = urlencode($exp_data);
$exp_size = filesize("{$g['tmp_path']}/{$exp_data}");
} else {
$exp_name = urlencode($exp_name."-config.ovpn");
$exp_size = strlen($exp_data);
}
header('Pragma: ');
header('Cache-Control: ');
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$exp_name}");
header("Content-Length: $exp_size");
if ($zipconf)
readfile("{$g['tmp_path']}/{$exp_data}");
else
echo $exp_data;
@unlink("{$g['tmp_path']}/{$exp_data}");
exit;
}
}
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<script type="text/javascript">
//<![CDATA[
var viscosityAvailable = false;
var servers = new Array();
<?php foreach ($ras_server as $sindex => $server): ?>
servers[<?=$sindex;?>] = new Array();
servers[<?=$sindex;?>][0] = '<?=$server['index'];?>';
servers[<?=$sindex;?>][1] = new Array();
servers[<?=$sindex;?>][2] = '<?=$server['mode'];?>';
<? endforeach; ?>
function download_begin(act) {
var index = document.getElementById("server").selectedIndex;
var useaddr;
if (document.getElementById("useaddr").value == "other") {
if (document.getElementById("useaddr_hostname").value == "") {
alert("Please specify an IP address or hostname.");
return;
}
useaddr = document.getElementById("useaddr_hostname").value;
} else
useaddr = document.getElementById("useaddr").value;
var useproxy = 0;
var useproxypass = 0;
if (document.getElementById("useproxy").checked)
useproxy = 1;
var proxyaddr = document.getElementById("proxyaddr").value;
var proxyport = document.getElementById("proxyport").value;
if (useproxy) {
if (!proxyaddr || !proxyport) {
alert("The proxy ip and port cannot be empty");
return;
}
if (document.getElementById("useproxypass").value != 'none')
useproxypass = 1;
var proxytype = document.getElementById("useproxytype").value;
var proxyauth = document.getElementById("useproxypass").value;
var proxyuser = document.getElementById("proxyuser").value;
var proxypass = document.getElementById("proxypass").value;
var proxyconf = document.getElementById("proxyconf").value;
if (useproxypass) {
if (!proxyuser) {
alert("Please fill the proxy username and password.");
return;
}
if (!proxypass || !proxyconf) {
alert("The proxy password or confirm field is empty");
return;
}
if (proxypass != proxyconf) {
alert("The proxy password and confirm fields must match");
return;
}
}
}
var dlurl;
dlurl = "/vpn_openvpn_export_shared.php?act=" + act;
dlurl += "&srvid=" + servers[index][0];
dlurl += "&useaddr=" + useaddr;
if (useproxy) {
dlurl += "&proxy_type=" + escape(proxytype);
dlurl += "&proxy_addr=" + proxyaddr;
dlurl += "&proxy_port=" + proxyport;
dlurl += "&proxy_authtype=" + proxyauth;
if (useproxypass) {
dlurl += "&proxy_user=" + proxyuser;
dlurl += "&proxy_password=" + proxypass;
}
}
window.open(dlurl,"_self");
}
function server_changed() {
var table = document.getElementById("clients");
while (table.rows.length > 1 )
table.deleteRow(1);
var index = document.getElementById("server").selectedIndex;
if (servers[index][2] == 'p2p_shared_key') {
var row = table.insertRow(table.rows.length);
var cell0 = row.insertCell(0);
var cell1 = row.insertCell(1);
cell0.className = "listlr";
cell0.innerHTML = "Other Shared Key OS Client";
cell1.className = "listr";
cell1.innerHTML = "<a href='javascript:download_begin(\"skconf\")'>Configuration<\/a>";
cell1.innerHTML += "<br\/>";
cell1.innerHTML += "<a href='javascript:download_begin(\"skzipconf\")'>Configuration archive<\/a>";
}
}
function useaddr_changed(obj) {
if (obj.value == "other")
$('HostName').show();
else
$('HostName').hide();
}
function useproxy_changed(obj) {
if ((obj.id == "useproxy" && obj.checked) ||
(obj.id == "useproxypass" && (obj.value != 'none'))) {
$(obj.id + '_opts').show();
} else {
$(obj.id + '_opts').hide();
}
}
//]]>
</script>
<?php
if ($input_errors)
print_input_errors($input_errors);
if ($savemsg)
print_info_box($savemsg);
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="openvpn export shared">
<tr>
<td>
<?php
$tab_array = array();
$tab_array[] = array(gettext("Server"), false, "vpn_openvpn_server.php");
$tab_array[] = array(gettext("Client"), false, "vpn_openvpn_client.php");
$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
$tab_array[] = array(gettext("Client Export"), false, "vpn_openvpn_export.php");
$tab_array[] = array(gettext("Shared Key Export"), true, "vpn_openvpn_export_shared.php");
display_top_tabs($tab_array);
?>
</td>
</tr>
<tr>
<td id="mainarea">
<div class="tabcont">
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
<tr>
<td width="22%" valign="top" class="vncellreq">Shared Key Server</td>
<td width="78%" class="vtable">
<select name="server" id="server" class="formselect" onchange="server_changed()">
<?php foreach($ras_server as & $server): ?>
<option value="<?=$server['sindex'];?>"><?=$server['name'];?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Host Name Resolution</td>
<td width="78%" class="vtable">
<table border="0" cellpadding="2" cellspacing="0" summary="host name resolution">
<tr>
<td>
<select name="useaddr" id="useaddr" class="formselect" onchange="useaddr_changed(this)">
<option value="serveraddr" >Interface IP Address</option>
<option value="serverhostname" >Installation hostname</option>
<?php if (is_array($config['dyndnses']['dyndns'])): ?>
<?php foreach ($config['dyndnses']['dyndns'] as $ddns): ?>
<option value="<?php echo $ddns["host"] ?>">DynDNS: <?php echo $ddns["host"] ?></option>
<?php endforeach; ?>
<?php endif; ?>
<option value="other">Other</option>
</select>
<br />
<div style="display:none;" id="HostName">
<input name="useaddr_hostname" id="useaddr_hostname" size="40" />
<span class="vexpl">
Enter the hostname or IP address the client will use to connect to this server.
</span>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Use Proxy</td>
<td width="78%" class="vtable">
<table border="0" cellpadding="2" cellspacing="0" summary="http proxy">
<tr>
<td>
<input name="useproxy" id="useproxy" type="checkbox" value="yes" onclick="useproxy_changed(this)" />
</td>
<td>
<span class="vexpl">
Use proxy to communicate with the server.
</span>
</td>
</tr>
</table>
<table border="0" cellpadding="2" cellspacing="0" id="useproxy_opts" style="display:none" summary="user options">
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp; Type :&nbsp;
</span>
</td>
<td>
<select name="useproxytype" id="useproxytype" class="formselect">
<option value="http">HTTP</option>
<option value="socks">Socks</option>
</select>
</td>
</tr>
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp; IP Address :&nbsp;
</span>
</td>
<td>
<input name="proxyaddr" id="proxyaddr" class="formfld unknown" size="30" value="" />
</td>
</tr>
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp; Port :&nbsp;
</span>
</td>
<td>
<input name="proxyport" id="proxyport" class="formfld unknown" size="5" value="" />
</td>
</tr>
<tr>
<td width="25%">
<br />
</td>
<td>
<select name="useproxypass" id="useproxypass" class="formselect" onchange="useproxy_changed(this)">
<option value="none">none</option>
<option value="basic">basic</option>
<option value="ntlm">ntlm</option>
</select>
<span class="vexpl">
Choose proxy authentication if any.
</span>
<br />
<table border="0" cellpadding="2" cellspacing="0" id="useproxypass_opts" style="display:none" summary="name and password">
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp;Username :&nbsp;
</span>
</td>
<td>
<input name="proxyuser" id="proxyuser" class="formfld unknown" size="20" value="" />
</td>
</tr>
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp;Password :&nbsp;
</span>
</td>
<td>
<input name="proxypass" id="proxypass" type="password" class="formfld pwd" size="20" value="" />
</td>
</tr>
<tr>
<td align="right" width="25%">
<span class="vexpl">
&nbsp;Confirm :&nbsp;
</span>
</td>
<td>
<input name="proxyconf" id="proxyconf" type="password" class="formfld pwd" size="20" value="" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" class="list" height="12">&nbsp;</td>
</tr>
<tr>
<td colspan="2" valign="top" class="listtopic">Client Configuration Packages</td>
</tr>
</table>
<table width="100%" id="clients" border="0" cellpadding="0" cellspacing="0" summary="heading">
<tr>
<td width="25%" class="listhdrr"><?=gettext("Client Type");?></td>
<td width="50%" class="listhdrr"><?=gettext("Export");?></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="5" cellspacing="10" summary="note">
<tr>
<td align="right" valign="top" width="5%"><?= gettext("NOTE:") ?></td>
<td><?= gettext("These are shared key configurations for use in site-to-site tunnels with other routers. Shared key tunnels are not normally used for remote access connections to end users.") ?></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<script type="text/javascript">
//<![CDATA[
server_changed();
//]]>
</script>
<?php include("fend.inc"); ?>
</body>
</html>
......@@ -745,7 +745,8 @@ function tuntap_change() {
$tab_array[] = array(gettext("Client"), false, "vpn_openvpn_client.php");
$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
add_package_tabs("OpenVPN", $tab_array);
$tab_array[] = array(gettext("Client Export"), false, "vpn_openvpn_export.php");
$tab_array[] = array(gettext("Shared Key Export"), false, "vpn_openvpn_export_shared.php");
display_top_tabs($tab_array);
?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment