Openvpn scripts fixes
some refactoring
This commit is contained in:
parent
c7dafe9c00
commit
bfdbe27a8d
5 changed files with 74 additions and 51 deletions
|
@ -2,7 +2,7 @@ QT += widgets core gui network xml
|
|||
|
||||
TARGET = AmneziaVPN
|
||||
TEMPLATE = app
|
||||
CONFIG += console
|
||||
#CONFIG += console
|
||||
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
|
@ -10,52 +10,52 @@ include("3rd/QtSsh/src/ssh/ssh.pri")
|
|||
include("3rd/QtSsh/src/botan/botan.pri")
|
||||
|
||||
HEADERS += \
|
||||
communicator.h \
|
||||
core/defs.h \
|
||||
core/errorstrings.h \
|
||||
core/openvpnconfigurator.h \
|
||||
core/router.h \
|
||||
core/servercontroller.h \
|
||||
debug.h \
|
||||
defines.h \
|
||||
localclient.h \
|
||||
managementserver.h \
|
||||
message.h \
|
||||
runguard.h \
|
||||
settings.h \
|
||||
ui/Controls/SlidingStackedWidget.h \
|
||||
ui/mainwindow.h \
|
||||
utils.h \
|
||||
vpnconnection.h \
|
||||
protocols/vpnprotocol.h \
|
||||
protocols/openvpnprotocol.h \
|
||||
communicator.h \
|
||||
core/defs.h \
|
||||
core/errorstrings.h \
|
||||
core/openvpnconfigurator.h \
|
||||
core/router.h \
|
||||
core/servercontroller.h \
|
||||
debug.h \
|
||||
defines.h \
|
||||
localclient.h \
|
||||
managementserver.h \
|
||||
message.h \
|
||||
runguard.h \
|
||||
settings.h \
|
||||
ui/Controls/SlidingStackedWidget.h \
|
||||
ui/mainwindow.h \
|
||||
utils.h \
|
||||
vpnconnection.h \
|
||||
protocols/vpnprotocol.h \
|
||||
protocols/openvpnprotocol.h \
|
||||
|
||||
SOURCES += \
|
||||
communicator.cpp \
|
||||
core/openvpnconfigurator.cpp \
|
||||
core/router.cpp \
|
||||
core/servercontroller.cpp \
|
||||
debug.cpp \
|
||||
localclient.cpp \
|
||||
main.cpp \
|
||||
managementserver.cpp \
|
||||
message.cpp \
|
||||
runguard.cpp \
|
||||
settings.cpp \
|
||||
ui/Controls/SlidingStackedWidget.cpp \
|
||||
ui/mainwindow.cpp \
|
||||
utils.cpp \
|
||||
vpnconnection.cpp \
|
||||
protocols/vpnprotocol.cpp \
|
||||
protocols/openvpnprotocol.cpp \
|
||||
communicator.cpp \
|
||||
core/openvpnconfigurator.cpp \
|
||||
core/router.cpp \
|
||||
core/servercontroller.cpp \
|
||||
debug.cpp \
|
||||
localclient.cpp \
|
||||
main.cpp \
|
||||
managementserver.cpp \
|
||||
message.cpp \
|
||||
runguard.cpp \
|
||||
settings.cpp \
|
||||
ui/Controls/SlidingStackedWidget.cpp \
|
||||
ui/mainwindow.cpp \
|
||||
utils.cpp \
|
||||
vpnconnection.cpp \
|
||||
protocols/vpnprotocol.cpp \
|
||||
protocols/openvpnprotocol.cpp \
|
||||
|
||||
FORMS += ui/mainwindow.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
resources.qrc
|
||||
|
||||
TRANSLATIONS = \
|
||||
translations/amneziavpn_ru.ts
|
||||
translations/amneziavpn_ru.ts
|
||||
|
||||
CONFIG(release, debug|release) {
|
||||
DESTDIR = $$PWD/../../AmneziaVPN-build/client/release
|
||||
|
|
|
@ -44,6 +44,7 @@ enum ErrorCode
|
|||
FailedToSaveConfigData,
|
||||
OpenVpnConfigMissing,
|
||||
OpenVpnManagementServerError,
|
||||
EasyRsaError,
|
||||
|
||||
// Distro errors
|
||||
AmneziaServiceConnectionFailed,
|
||||
|
|
|
@ -21,12 +21,19 @@ 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/easyrsa";
|
||||
#endif
|
||||
}
|
||||
|
||||
QProcessEnvironment OpenVpnConfigurator::prepareEnv()
|
||||
|
@ -46,9 +53,12 @@ void OpenVpnConfigurator::initPKI(const QString &path)
|
|||
p.setProcessChannelMode(QProcess::MergedChannels);
|
||||
p.setProcessEnvironment(prepareEnv());
|
||||
|
||||
QString command = QString("sh.exe");
|
||||
//QString command = QString("sh.exe");
|
||||
QString command = QString("cmd.exe");
|
||||
|
||||
p.setNativeArguments(getEasyRsaShPath() + " init-pki");
|
||||
//p.setNativeArguments(getEasyRsaShPath() + " init-pki");
|
||||
p.setNativeArguments(QString("/C \"sh.exe %1\"").arg(getEasyRsaShPath() + " init-pki"));
|
||||
//qDebug().noquote() << p.nativeArguments();
|
||||
|
||||
p.setWorkingDirectory(path);
|
||||
|
||||
|
@ -66,9 +76,13 @@ QString OpenVpnConfigurator::genReq(const QString &path, const QString &clientId
|
|||
p.setProcessChannelMode(QProcess::MergedChannels);
|
||||
p.setProcessEnvironment(prepareEnv());
|
||||
|
||||
QString command = QString("sh.exe");
|
||||
//QString command = QString("sh.exe");
|
||||
QString command = QString("cmd.exe");
|
||||
|
||||
//p.setNativeArguments(getEasyRsaShPath() + " gen-req " + clientId + " nopass");
|
||||
p.setNativeArguments(QString("/C \"sh.exe %1\"").arg(getEasyRsaShPath() + " gen-req " + clientId + " nopass"));
|
||||
//qDebug().noquote() << p.nativeArguments();
|
||||
|
||||
p.setNativeArguments(getEasyRsaShPath() + " gen-req " + clientId + " nopass");
|
||||
|
||||
p.setWorkingDirectory(path);
|
||||
|
||||
|
@ -114,9 +128,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 +139,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) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QTcpSocket>
|
||||
|
||||
#include "communicator.h"
|
||||
#include "debug.h"
|
||||
|
@ -94,8 +95,11 @@ QString OpenVpnProtocol::configPath() const
|
|||
|
||||
void OpenVpnProtocol::writeCommand(const QString& command)
|
||||
{
|
||||
QTextStream stream(reinterpret_cast<QIODevice*>(m_managementServer.socket()));
|
||||
stream << command << endl;
|
||||
QIODevice *device = dynamic_cast<QIODevice*>(m_managementServer.socket().data());
|
||||
if (device) {
|
||||
QTextStream stream(device);
|
||||
stream << command << endl;
|
||||
}
|
||||
}
|
||||
|
||||
QString OpenVpnProtocol::openVpnExecPath() const
|
||||
|
|
|
@ -15,7 +15,7 @@ class OpenVpnProtocol : public VpnProtocol
|
|||
|
||||
public:
|
||||
explicit OpenVpnProtocol(const QString& args = QString(), QObject* parent = nullptr);
|
||||
~OpenVpnProtocol();
|
||||
~OpenVpnProtocol() override;
|
||||
|
||||
ErrorCode start() override;
|
||||
void stop() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue