Skip to content

Commit

Permalink
Release 1.0 (#4)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pokamest authored Jan 9, 2021
1 parent f0e5fbe commit c2a7d66
Show file tree
Hide file tree
Showing 35 changed files with 3,748 additions and 221 deletions.
78 changes: 39 additions & 39 deletions client/client.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,60 @@ QT += widgets core gui network xml

TARGET = AmneziaVPN
TEMPLATE = app
CONFIG += console
#CONFIG += console

DEFINES += QT_DEPRECATED_WARNINGS

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
Expand Down
4 changes: 2 additions & 2 deletions client/communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void Communicator::onLineAvailable(const QString& line)
emit messageReceived(message);
}

bool Communicator::connected() const
bool Communicator::isConnected() const
{
if (!m_localClient) {
return false;
Expand All @@ -66,7 +66,7 @@ bool Communicator::writeData(const QString& data)

void Communicator::sendMessage(const Message& message)
{
if (!connected()) {
if (!isConnected()) {
return;
}
const QString data = message.toString();
Expand Down
2 changes: 1 addition & 1 deletion client/communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Communicator : public QObject
explicit Communicator(QObject* parent = nullptr);
~Communicator();

bool connected() const;
bool isConnected() const;
void sendMessage(const Message& message);

signals:
Expand Down
9 changes: 7 additions & 2 deletions client/core/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ enum ErrorCode
FailedToSaveConfigData,
OpenVpnConfigMissing,
OpenVpnManagementServerError,
EasyRsaError,

// Distro errors
AmneziaServiceConnectionFailed,
OpenVpnExecutableMissing,
EasyRsaExecutableMissing
EasyRsaExecutableMissing,
AmneziaServiceConnectionFailed,

// VPN errors
OpenVpnAdaptersInUseError,
OpenVpnUnknownError
};

} // namespace amnezia
Expand Down
9 changes: 7 additions & 2 deletions client/core/errorstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "defs.h"
using namespace amnezia;

QString errorString(ErrorCode code){
static QString errorString(ErrorCode code){
switch (code) {

// General error codes
Expand All @@ -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");
Expand Down
81 changes: 57 additions & 24 deletions client/core/openvpnconfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

p.setNativeArguments(getEasyRsaShPath() + " init-pki");
#ifdef Q_OS_WIN
//p.setProgram("sh.exe");
//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);
// QObject::connect(&p, &QProcess::channelReadyRead, [&](){
// qDebug().noquote() << p.readAll();
// });

p.start();
p.waitForFinished();
qDebug().noquote() << p.readAll();

#endif
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");

p.setNativeArguments(getEasyRsaShPath() + " gen-req " + clientId + " nopass");
#ifdef Q_OS_WIN
//p.setProgram("sh.exe");
//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;
}


Expand All @@ -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");
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions client/core/openvpnconfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class OpenVpnConfigurator
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();

Expand Down
4 changes: 2 additions & 2 deletions client/core/servercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// }
// });

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

Expand Down
2 changes: 1 addition & 1 deletion client/localclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void LocalClient::onReadyRead()
if (lineLength != -1) {
QString line = buf;
line = line.simplified();
qDebug().noquote() << QString("Readed line: '%1'").arg(line);
qDebug().noquote() << QString("Read line: '%1'").arg(line);
emit lineAvailable(line);
}
}
Expand Down
2 changes: 2 additions & 0 deletions client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ int main(int argc, char *argv[])
f.setStyleStrategy(QFont::PreferAntialias);
app.setFont(f);

app.setQuitOnLastWindowClosed(false);

MainWindow mainWindow;
mainWindow.show();

Expand Down
Loading

1 comment on commit c2a7d66

@pokamest
Copy link
Member Author

@pokamest pokamest commented on c2a7d66 Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Функционал реализован при поддержке Теплицы социальных технологий. https://te-st.ru/
Функционал реализован при поддержке Privacy Accelerator. https://privacyaccelerator.org/

Please sign in to comment.