From cb7aaea59699a1a6dcb9d29771a2eae215996c2d Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Fri, 15 Jul 2016 12:27:55 +0200 Subject: [PATCH] openvpn client export, merge vpn_openvpn_export_shared.php into vpn_openvpn_export.php + small cleanups. --- src/etc/inc/openvpn-client-export.inc | 15 +- .../app/models/OPNsense/Base/Menu/Menu.xml | 1 - src/www/vpn_openvpn_export.php | 62 ++- src/www/vpn_openvpn_export_shared.php | 402 ------------------ 4 files changed, 53 insertions(+), 427 deletions(-) delete mode 100644 src/www/vpn_openvpn_export_shared.php diff --git a/src/etc/inc/openvpn-client-export.inc b/src/etc/inc/openvpn-client-export.inc index fb7292e53..58e19d4af 100644 --- a/src/etc/inc/openvpn-client-export.inc +++ b/src/etc/inc/openvpn-client-export.inc @@ -368,7 +368,7 @@ function openvpn_client_export_config($srvid, $usrid, $crtid, $useaddr, $verifys } } $command = "cd " . escapeshellarg("{$tempdir}/..") - . " && /usr/local/bin/7z -tzip -y -r a " + . " && /usr/local/bin/7z -tzip -y a " . escapeshellarg("/tmp/{$prefix}-config.zip") . " " . escapeshellarg($prefix); exec($command); @@ -678,7 +678,7 @@ EOF; } // Zip Viscosity file - exec("cd {$tempdir}/.. && /usr/local/bin/7z -tzip -y -r a {$zipfile} Viscosity.visc"); + exec("cd {$tempdir}/.. && /usr/local/bin/7z -tzip -y a {$zipfile} Viscosity.visc"); // Remove temporary directory exec("rm -rf {$tempdir}"); @@ -799,19 +799,16 @@ function openvpn_client_export_sharedkey_config($srvid, $useaddr, $proxy, $zipco // create template directory $tempdir = "/tmp/{$prefix}"; mkdir($tempdir, 0700, true); - file_put_contents("{$tempdir}/{$prefix}.ovpn", $conf); - $shkeyfile = "{$tempdir}/{$shkeyfile}"; file_put_contents("{$shkeyfile}", base64_decode($settings['shared_key'])); - - exec("cd {$tempdir}/.. && /usr/local/bin/7z -tzip -y -r a /tmp/{$prefix}-config.zip {$prefix}"); - + exec("cd {$tempdir}/.. && /usr/local/bin/7z -tzip -y a /tmp/{$prefix}-config.zip {$prefix}"); // Remove temporary directory exec("rm -rf {$tempdir}"); - return "{$prefix}-config.zip"; + return "/tmp/{$prefix}-config.zip"; } else { - return $conf; + file_put_contents("/tmp/{$prefix}.ovpn", $conf); + return "/tmp/{$prefix}.ovpn"; } } diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml b/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml index e65c4cb92..cb9b2b00f 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml @@ -325,7 +325,6 @@ - diff --git a/src/www/vpn_openvpn_export.php b/src/www/vpn_openvpn_export.php index b809936e7..14f6355f5 100644 --- a/src/www/vpn_openvpn_export.php +++ b/src/www/vpn_openvpn_export.php @@ -46,7 +46,7 @@ if (isset($config['openvpn']['openvpn-server'])) { } $ras_user = array(); $ras_certs = array(); - if (stripos($server['mode'], "server") === false) { + if (stripos($server['mode'], "server") === false && $server['mode'] != "p2p_shared_key") { continue; } if (($server['mode'] == "server_tls_user") && ($server['authmode'] == "Local Database")) { @@ -223,16 +223,18 @@ if (isset($config['openvpn']['openvpn-server'])) { $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") { + } elseif ($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") { + } elseif (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)); + } elseif ( $act == 'skconf') { + $exp_path = openvpn_client_export_sharedkey_config($srvid, $useaddr, $proxy, false); + $exp_name = urlencode($exp_name."-config.ovpn"); + } elseif ( $act == 'skzipconf') { + $exp_path = openvpn_client_export_sharedkey_config($srvid, $useaddr, $proxy, true); + $exp_name = urlencode(basename($exp_path)); } if (!$exp_path) { @@ -271,14 +273,26 @@ include("head.inc"); $("#server").change(function(){ $('.server_item').hide(); $('tr[data-server-index="'+$(this).val()+'"]').show(); + switch ($("#server :selected").data('mode')) { + case "p2p_shared_key": + $(".mode_server select,input").prop( "disabled", true ); + $(".mode_server").hide(); + break; + default: + $(".mode_server select,input").prop( "disabled", false ); + $(".mode_server").show(); + } + $(window).resize(); // force zebra re-stripe (opnsense_standard_table_form) }); $("#server").change(); $("#useaddr").change(function(){ if ($(this).val() == 'other') { $('#HostName').show(); + $("#useaddr_hostname").prop( "disabled", false ); } else { $('#HostName').hide(); + $("#useaddr_hostname").prop( "disabled", true ); } }); $("#pass,#conf").keyup(function(){ @@ -410,7 +424,7 @@ if (isset($savemsg)) { @@ -452,7 +466,7 @@ if (isset($savemsg)) { - + @@ -478,7 +492,7 @@ if (isset($savemsg)) { - +
@@ -533,7 +547,7 @@ if (isset($savemsg)) {
- + @@ -549,20 +563,20 @@ if (isset($savemsg)) {   - +
- +
@@ -678,6 +692,24 @@ if (isset($savemsg)) { + + + + + + diff --git a/src/www/vpn_openvpn_export_shared.php b/src/www/vpn_openvpn_export_shared.php deleted file mode 100644 index c60260da8..000000000 --- a/src/www/vpn_openvpn_export_shared.php +++ /dev/null @@ -1,402 +0,0 @@ - $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; - } -} - -if (isset($_GET['act'])) { - $input_errors = array(); - $act = $_GET['act']; - if (($act == "skconf") || ($act == "skzipconf")) { - $srvid = isset($_GET['srvid']) ? $_GET['srvid'] : false; - if ($srvid === false || !isset($config['openvpn']['openvpn-server'][$srvid]['mode']) || - $config['openvpn']['openvpn-server'][$srvid]['mode'] != "p2p_shared_key") { - header("Location: vpn_openvpn_export.php"); - exit; - } - - if (empty($_GET['useaddr'])) { - $input_errors[] = gettext("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'])) { - $input_errors[] = gettext("You need to specify an address for the proxy port."); - } else { - $proxy['ip'] = $_GET['proxy_addr']; - } - if (empty($_GET['proxy_port'])) { - $input_errors[] = gettext("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[] = gettext("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[] = gettext("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[] = gettext("Failed to export config files!"); - } - if (count($input_errors) == 0) { - if ($zipconf) { - $exp_name = urlencode($exp_data); - $exp_size = filesize("/tmp/{$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("/tmp/{$exp_data}"); - } else { - echo $exp_data; - } - - @unlink("/tmp/{$exp_data}"); - exit; - } - } -} - -include("head.inc"); -?> - - - - - 0) { - print_input_errors($input_errors); -} -if (isset($savemsg)) { - print_info_box($savemsg); -} -?> -
-
-
-
-
-
-
+ +
- - - - - - - - - - - - - - - - - - - - -
- - -
- -
- - -
- - - - -
- - - - - -
- -
- - - - - - - -