Release 1.0 (#4)
* Crash fix in management server * Openvpn scripts fixes some refactoring * deploy fix * Scripts fix for macos * OpenVpn runtime error codes handling * MacOS deploy script fix * easyrsa scripts for MacOS * Refactoring Ui improvements Bug fixes * new server page fix
This commit is contained in:
parent
f0e5fbeda0
commit
c2a7d66cb4
35 changed files with 3758 additions and 231 deletions
|
@ -44,11 +44,16 @@ enum ErrorCode
|
|||
FailedToSaveConfigData,
|
||||
OpenVpnConfigMissing,
|
||||
OpenVpnManagementServerError,
|
||||
EasyRsaError,
|
||||
|
||||
// Distro errors
|
||||
AmneziaServiceConnectionFailed,
|
||||
OpenVpnExecutableMissing,
|
||||
EasyRsaExecutableMissing
|
||||
EasyRsaExecutableMissing,
|
||||
AmneziaServiceConnectionFailed,
|
||||
|
||||
// VPN errors
|
||||
OpenVpnAdaptersInUseError,
|
||||
OpenVpnUnknownError
|
||||
};
|
||||
|
||||
} // namespace amnezia
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "defs.h"
|
||||
using namespace amnezia;
|
||||
|
||||
QString errorString(ErrorCode code){
|
||||
static QString errorString(ErrorCode code){
|
||||
switch (code) {
|
||||
|
||||
// General error codes
|
||||
|
@ -31,12 +31,17 @@ QString errorString(ErrorCode code){
|
|||
// Local errors
|
||||
case (FailedToSaveConfigData): return QObject::tr("Failed to save config to disk");
|
||||
case (OpenVpnConfigMissing): return QObject::tr("OpenVPN config missing");
|
||||
case (OpenVpnManagementServerError): return QObject::tr("OpenVpn management server error");
|
||||
case (OpenVpnManagementServerError): return QObject::tr("OpenVPN management server error");
|
||||
case (EasyRsaError): return QObject::tr("EasyRSA runtime error");
|
||||
|
||||
// Distro errors
|
||||
case (OpenVpnExecutableMissing): return QObject::tr("OpenVPN executable missing");
|
||||
case (EasyRsaExecutableMissing): return QObject::tr("EasyRsa executable missing");
|
||||
case (AmneziaServiceConnectionFailed): return QObject::tr("Amnezia helper service error");
|
||||
|
||||
// VPN errors
|
||||
case (OpenVpnAdaptersInUseError): return QObject::tr("Can't connect: another VPN connection is active");
|
||||
|
||||
case(InternalError):
|
||||
default:
|
||||
return QObject::tr("Internal error");
|
||||
|
|
|
@ -21,72 +21,101 @@ QString OpenVpnConfigurator::getRandomString(int len)
|
|||
|
||||
QString OpenVpnConfigurator::getEasyRsaShPath()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
// easyrsa sh path should looks like
|
||||
// "/Program Files (x86)/AmneziaVPN/easyrsa/easyrsa"
|
||||
QString easyRsaShPath = QDir::toNativeSeparators(QApplication::applicationDirPath()) + "\\easyrsa\\easyrsa";
|
||||
easyRsaShPath.replace(":", "");
|
||||
easyRsaShPath.replace("C:\\", "");
|
||||
easyRsaShPath.replace("\\", "/");
|
||||
easyRsaShPath.prepend("/");
|
||||
|
||||
return easyRsaShPath;
|
||||
//return "\"" + easyRsaShPath + "\"";
|
||||
return "\"/Program Files (x86)/AmneziaVPN/easyrsa/easyrsa\"";
|
||||
#else
|
||||
return QDir::toNativeSeparators(QApplication::applicationDirPath()) + "/easyrsa";
|
||||
#endif
|
||||
}
|
||||
|
||||
QProcessEnvironment OpenVpnConfigurator::prepareEnv()
|
||||
{
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
QString pathEnvVar = env.value("PATH");
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
pathEnvVar.prepend(QDir::toNativeSeparators(QApplication::applicationDirPath()) + "\\easyrsa\\bin;");
|
||||
pathEnvVar.prepend(QDir::toNativeSeparators(QApplication::applicationDirPath()) + "\\openvpn\\i386;");
|
||||
pathEnvVar.prepend(QDir::toNativeSeparators(QApplication::applicationDirPath()) + "\\openvpn\\x64;");
|
||||
#else
|
||||
pathEnvVar.prepend(QDir::toNativeSeparators(QApplication::applicationDirPath()) + "/Contents/MacOS");
|
||||
#endif
|
||||
|
||||
env.insert("PATH", pathEnvVar);
|
||||
return env;
|
||||
}
|
||||
|
||||
void OpenVpnConfigurator::initPKI(const QString &path)
|
||||
ErrorCode OpenVpnConfigurator::initPKI(const QString &path)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
QProcess p;
|
||||
p.setProcessChannelMode(QProcess::MergedChannels);
|
||||
p.setProcessEnvironment(prepareEnv());
|
||||
|
||||
QString command = QString("sh.exe");
|
||||
#ifdef Q_OS_WIN
|
||||
//p.setProgram("sh.exe");
|
||||
//p.setNativeArguments(getEasyRsaShPath() + " init-pki");
|
||||
|
||||
p.setNativeArguments(getEasyRsaShPath() + " init-pki");
|
||||
p.setProgram("cmd.exe");
|
||||
p.setNativeArguments(QString("/C \"sh.exe %1\"").arg(getEasyRsaShPath() + " init-pki"));
|
||||
#else
|
||||
p.setProgram(getEasyRsaShPath());
|
||||
p.setArguments(QStringList() << "init-pki");
|
||||
#endif
|
||||
|
||||
p.setWorkingDirectory(path);
|
||||
|
||||
p.start(command);
|
||||
p.waitForFinished();
|
||||
qDebug().noquote() << p.readAll();
|
||||
// QObject::connect(&p, &QProcess::channelReadyRead, [&](){
|
||||
// qDebug().noquote() << p.readAll();
|
||||
// });
|
||||
|
||||
#endif
|
||||
p.start();
|
||||
p.waitForFinished();
|
||||
|
||||
if (p.exitCode() == 0) return ErrorCode::NoError;
|
||||
else return ErrorCode::EasyRsaError;
|
||||
}
|
||||
|
||||
QString OpenVpnConfigurator::genReq(const QString &path, const QString &clientId)
|
||||
ErrorCode OpenVpnConfigurator::genReq(const QString &path, const QString &clientId)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
QProcess p;
|
||||
p.setProcessChannelMode(QProcess::MergedChannels);
|
||||
p.setProcessEnvironment(prepareEnv());
|
||||
|
||||
QString command = QString("sh.exe");
|
||||
#ifdef Q_OS_WIN
|
||||
//p.setProgram("sh.exe");
|
||||
//p.setNativeArguments(getEasyRsaShPath() + " gen-req " + clientId + " nopass");
|
||||
|
||||
p.setNativeArguments(getEasyRsaShPath() + " gen-req " + clientId + " nopass");
|
||||
p.setProgram("cmd.exe");
|
||||
p.setNativeArguments(QString("/C \"sh.exe %1\"").arg(getEasyRsaShPath() + " gen-req " + clientId + " nopass"));
|
||||
#else
|
||||
p.setArguments(QStringList() << "gen-req" << clientId << "nopass");
|
||||
p.setProgram(getEasyRsaShPath());
|
||||
#endif
|
||||
|
||||
p.setWorkingDirectory(path);
|
||||
|
||||
QObject::connect(&p, &QProcess::channelReadyRead, [&](){
|
||||
QString data = p.readAll();
|
||||
qDebug().noquote() << data;
|
||||
//qDebug().noquote() << data;
|
||||
|
||||
if (data.contains("Common Name (eg: your user, host, or server name)")) {
|
||||
p.write("\n");
|
||||
}
|
||||
});
|
||||
|
||||
p.start(command);
|
||||
p.start();
|
||||
p.waitForFinished();
|
||||
// qDebug().noquote() << p.readAll();
|
||||
|
||||
return "";
|
||||
#endif
|
||||
if (p.exitCode() == 0) return ErrorCode::NoError;
|
||||
else return ErrorCode::EasyRsaError;
|
||||
}
|
||||
|
||||
|
||||
|
@ -103,7 +132,7 @@ OpenVpnConfigurator::ConnectionData OpenVpnConfigurator::createCertRequest()
|
|||
QString path = dir.path();
|
||||
|
||||
initPKI(path);
|
||||
genReq(path, connData.clientId);
|
||||
ErrorCode errorCode = genReq(path, connData.clientId);
|
||||
|
||||
|
||||
QFile req(path + "/pki/reqs/" + connData.clientId + ".req");
|
||||
|
@ -114,9 +143,8 @@ OpenVpnConfigurator::ConnectionData OpenVpnConfigurator::createCertRequest()
|
|||
key.open(QIODevice::ReadOnly);
|
||||
connData.privKey = key.readAll();
|
||||
|
||||
qDebug().noquote() << connData.request;
|
||||
qDebug().noquote() << connData.privKey;
|
||||
|
||||
// qDebug().noquote() << connData.request;
|
||||
// qDebug().noquote() << connData.privKey;
|
||||
|
||||
return connData;
|
||||
}
|
||||
|
@ -126,6 +154,11 @@ OpenVpnConfigurator::ConnectionData OpenVpnConfigurator::prepareOpenVpnConfig(co
|
|||
OpenVpnConfigurator::ConnectionData connData = OpenVpnConfigurator::createCertRequest();
|
||||
connData.host = credentials.hostName;
|
||||
|
||||
if (connData.privKey.isEmpty() || connData.request.isEmpty()) {
|
||||
*errorCode = ErrorCode::EasyRsaExecutableMissing;
|
||||
return connData;
|
||||
}
|
||||
|
||||
QString reqFileName = QString("/opt/amneziavpn_data/clients/%1.req").arg(connData.clientId);
|
||||
ErrorCode e = ServerController::uploadTextFileToContainer(credentials, connData.request, reqFileName);
|
||||
if (e) {
|
||||
|
|
|
@ -29,8 +29,8 @@ private:
|
|||
static QString getEasyRsaShPath();
|
||||
|
||||
static QProcessEnvironment prepareEnv();
|
||||
static void initPKI(const QString &path);
|
||||
static QString genReq(const QString &path, const QString &clientId);
|
||||
static ErrorCode initPKI(const QString &path);
|
||||
static ErrorCode genReq(const QString &path, const QString &clientId);
|
||||
|
||||
static ConnectionData createCertRequest();
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ ErrorCode ServerController::runScript(const SshConnectionParameters &sshParams,
|
|||
// QObject::connect(proc.data(), &SshRemoteProcess::readyReadStandardOutput, [proc](){
|
||||
// QString s = proc->readAllStandardOutput();
|
||||
// if (s != "." && !s.isEmpty()) {
|
||||
// qDebug().noquote() << s << s.size();
|
||||
// qDebug().noquote() << s;
|
||||
// }
|
||||
// });
|
||||
|
||||
|
@ -239,7 +239,7 @@ ErrorCode ServerController::removeServer(const ServerCredentials &credentials, P
|
|||
{
|
||||
QString scriptFileName;
|
||||
|
||||
if (proto == Protocol::OpenVpn) {
|
||||
if (proto == Protocol::OpenVpn || proto == Protocol::Any) {
|
||||
scriptFileName = ":/server_scripts/remove_openvpn_server.sh";
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue