openvpn client export, merge vpn_openvpn_export_shared.php into vpn_openvpn_export.php + small cleanups.

This commit is contained in:
Ad Schellevis 2016-07-15 12:27:55 +02:00
parent 0227b1231b
commit cb7aaea596
4 changed files with 53 additions and 427 deletions

View File

@ -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";
}
}

View File

@ -325,7 +325,6 @@
<ClientExport order="40" VisibleName="Client Export" url="/vpn_openvpn_export.php">
<Edit url="/vpn_openvpn_export.php?*" visibility="hidden"/>
</ClientExport>
<ClientSharedKeyExport order="50" VisibleName="Shared Key Export" url="/vpn_openvpn_export_shared.php"/>
<Status order="60" VisibleName="Connection Status" url="/status_openvpn.php"/>
<Log order="70" VisibleName="Log File" url="/diag_logs_openvpn.php"/>
</OpenVPN>

View File

@ -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)) {
<select name="server" id="server" class="formselect">
<?php
foreach ($ras_server as $server) :?>
<option value="<?=$server['index'];?>"><?=htmlspecialchars($server['name']);?></option>
<option value="<?=$server['index'];?>" data-mode="<?=$server['mode'];?>"><?=htmlspecialchars($server['name']);?></option>
<?php
endforeach; ?>
</select>
@ -452,7 +466,7 @@ if (isset($savemsg)) {
</div>
</td>
</tr>
<tr>
<tr class="mode_server">
<td valign="top"><a id="help_for_verify_server_cn" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Verify Server CN");?></td>
<td >
<select name="verifyservercn" id="verifyservercn" class="formselect">
@ -468,7 +482,7 @@ if (isset($savemsg)) {
</div>
</td>
</tr>
<tr>
<tr class="mode_server">
<td valign="top"><a id="help_for_random_local_port" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Use Random Local Port");?></td>
<td >
<input name="randomlocalport" id="randomlocalport" type="checkbox" value="yes" checked="CHECKED" />
@ -478,7 +492,7 @@ if (isset($savemsg)) {
<?=gettext("NOTE: Not supported on older clients. Automatically disabled for Yealink and Snom configurations."); ?>
</div>
</tr>
<tr>
<tr class="mode_server">
<td valign="top"><i class="fa fa-info-circle text-muted"></i> <?=gettext("Certificate Export Options");?></td>
<td >
<div>
@ -533,7 +547,7 @@ if (isset($savemsg)) {
</div>
</td>
</tr>
<tr>
<tr class="mode_server">
<td valign="top"><a id="help_for_openvpnmanager" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Management Interface OpenVPNManager");?></td>
<td >
<input name="openvpnmanager" id="openvpnmanager" type="checkbox" value="yes" />
@ -549,20 +563,20 @@ if (isset($savemsg)) {
<tr>
<td colspan="2" class="list" height="12">&nbsp;</td>
</tr>
<tr>
<tr class="mode_server">
<td valign="top"><a id="help_for_advancedoptions" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Additional configuration options");?></td>
<td >
<textarea rows="6" cols="68" name="advancedoptions" id="advancedoptions"></textarea><br/>
<div class="hidden" for="help_for_advancedoptions">
<?=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"); ?>;
<?=gettext("EXAMPLE: remote-random"); ?>;
</div>
</td>
</tr>
<tr>
<td><a id="help_for_clientpkg" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Client Install Packages");?></td>
<td>
<table id="export_users" class="table table-striped">
<table id="export_users" class="table table-striped table-condensed">
<thead>
<tr>
<td width="25%" ><b><?=gettext("User");?></b></td>
@ -678,6 +692,24 @@ if (isset($savemsg)) {
</select>
</td>
</tr>
<?php
endif;
if ($server['mode'] == 'p2p_shared_key'):?>
<tr class="server_item" data-server-index="<?=$server['index'];?>" data-server-mode="<?=$server['mode'];?>">
<td><?=gettext("Other Shared Key OS Client");?></td>
<td><?=gettext("none");?></td>
<td>
<select class="selectpicker export_select" data-type="server">
<optgroup label="">
<option value="">-</option>
</optgroup>
<optgroup label="<?=gettext("Standard Configurations");?>">
<option value="skconf"><?=gettext("Configuration");?></option>
<option value="skzipconf"><?=gettext("Configuration archive");?></option>
</optgroup>
</select>
</td>
</tr>
<?php
endif;
endforeach;?>

View File

@ -1,402 +0,0 @@
<?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.
*/
require_once("guiconfig.inc");
require_once("openvpn.inc");
require_once("services.inc");
require_once("filter.inc");
require_once("interfaces.inc");
require_once("openvpn-client-export.inc");
$ras_server = array();
if (isset($config['openvpn']['openvpn-server'])) {
foreach ($config['openvpn']['openvpn-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;
}
}
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");
?>
<body>
<?php include("fbegin.inc"); ?>
<script type="text/javascript">
//<![CDATA[
$( document ).ready(function() {
server_changed();
});
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("<?=gettext('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("<?=gettext('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("<?=gettext('Please fill the proxy username and password.') ?>");
return;
}
if (!proxypass || !proxyconf) {
alert("<?=gettext('The proxy password or confirm field is empty') ?>");
return;
}
if (proxypass != proxyconf) {
alert("<?=gettext('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.innerHTML = "Other Shared Key OS Client";
cell1.innerHTML += "<div>";
cell1.innerHTML += "<button type='button' class='btn btn-primary btn-xs' onclick='download_begin(\"skconf\")'>Configuration</button>";
cell1.innerHTML += "&nbsp;";
cell1.innerHTML += "<button type='button' class='btn btn-primary btn-xs' onclick='download_begin(\"skzipconf\")'>Configuration archive</button>";
cell1.innerHTML += "</div>";
}
}
function useaddr_changed(obj) {
if (obj.value == "other")
$('#HostName').show();
else
$('#HostName').hide();
}
function useproxy_changed(obj) {
if ($('#useproxy').prop( "checked" ) ){
$('#useproxy_opts').show();
} else {
$('#useproxy_opts').hide();
}
if ($( "#useproxypass option:selected" ).text() != 'none') {
$('#useproxypass_opts').show();
} else {
$('#useproxypass_opts').hide();
}
}
//]]>
</script>
<?php
if (isset($input_errors) && count($input_errors) > 0) {
print_input_errors($input_errors);
}
if (isset($savemsg)) {
print_info_box($savemsg);
}
?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<div class="table-responsive">
<table width="100%" border="0" class="table table-striped opnsense_standard_table_form" cellpadding="0" cellspacing="0">
<tr>
<td width="22%"></td>
<td width="78%" align="right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><i class="fa fa-info-circle text-muted"></i> <?=gettext("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="<?=htmlspecialchars($server['sindex']);
?>"><?=htmlspecialchars($server['name']);?></option>
<?php
endforeach; ?>
</select>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><i class="fa fa-info-circle text-muted"></i> <?=gettext("Host Name Resolution");?></td>
<td width="78%" class="vtable">
<select name="useaddr" id="useaddr" class="formselect" onchange="useaddr_changed(this)">
<option value="serveraddr" ><?=gettext("Interface IP Address");?></option>
<option value="serverhostname" ><?=gettext("Installation hostname");?></option>
<?php if (isset($config['dyndnses']['dyndns'])) :
?>
<?php foreach ($config['dyndnses']['dyndns'] as $ddns) :
?>
<option value="<?= htmlspecialchars($ddns["host"]);
?>"><?=gettext("Dynamic DNS:");
?> <?= htmlspecialchars($ddns["host"]);?></option>
<?php
endforeach; ?>
<?php
endif; ?>
<option value="other"><?=gettext("Other");?></option>
</select>
<div style="display:none;" id="HostName">
<?=gettext("Enter the hostname or IP address the client will use to connect to this server.");?>
<input name="useaddr_hostname" type="text" id="useaddr_hostname" size="40" />
</div>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><a id="help_for_use_proxy" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Use Proxy");?></td>
<td width="78%" class="vtable">
<input name="useproxy" id="useproxy" type="checkbox" value="yes" onclick="useproxy_changed(this)" />
<div id="useproxy_opts" style="display:none">
<?=gettext("Type");?> :
<select name="useproxytype" id="useproxytype" class="formselect">
<option value="http"><?=gettext("HTTP");?></option>
<option value="socks"><?=gettext("SOCKS");?></option>
</select>
<?=gettext("IP Address")?> :
<input name="proxyaddr" id="proxyaddr" type="text" class="formfld unknown" size="30" value="" />
<?=gettext("Port");?> :
<input name="proxyport" id="proxyport" type="text" class="formfld unknown" size="5" value="" />
<?=gettext("Choose proxy authentication if any.");?>
<select name="useproxypass" id="useproxypass" class="formselect" onchange="useproxy_changed(this)">
<option value="none"><?=gettext("none");?></option>
<option value="basic"><?=gettext("basic");?></option>
<option value="ntlm"><?=gettext("ntlm");?></option>
</select>
<div id="useproxypass_opts">
<?=gettext("Username")?> :
<input name="proxyuser" id="proxyuser" type="text" class="formfld unknown" size="20" value="" />
<?=gettext("Password");?> :
<input name="proxypass" id="proxypass" type="password" class="formfld pwd" size="20" value="" />
<?=gettext("Confirm");?> :
<input name="proxyconf" id="proxyconf" type="password" class="formfld pwd" size="20" value="" />
</div>
</div>
<div class="hidden" for="help_for_use_proxy">
<?= gettext("Use proxy to communicate with the server.");?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_client_conf_pkg" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Client Configuration Packages");?></td>
<td>
<table width="100%" id="clients" border="0" cellpadding="0" cellspacing="0" class="table table-striped table-bordered ">
<tr>
<td width="25%" class="listhdrr"><b><?=gettext("Client Type");?></b></td>
<td width="50%" class="listhdrr"><b><?=gettext("Export");?></b></td>
</tr>
</table>
<div class="hidden" for="help_for_client_conf_pkg">
<?= gettext("NOTE:") ?> <br/>
<?= 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.") ?>
</div>
</td>
</tr>
</table>
</div>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>