Merge branch 'dev' of github.com:amnezia-vpn/desktop-client into feature/qt6-libssh-support
This commit is contained in:
commit
74fbce8b96
279 changed files with 3217 additions and 14329 deletions
|
|
@ -31,6 +31,7 @@ enum ErrorCode
|
|||
ServerPortAlreadyAllocatedError,
|
||||
ServerContainerMissingError,
|
||||
ServerDockerFailedError,
|
||||
ServerCancelInstallation,
|
||||
|
||||
// Ssh connection errors
|
||||
SshRequsetDeniedError, SshInterruptedError, SshInternalError,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ QString errorString(ErrorCode code){
|
|||
case(ServerPortAlreadyAllocatedError): return QObject::tr("Server port already used. Check for another software");
|
||||
case(ServerContainerMissingError): return QObject::tr("Server error: Docker container missing");
|
||||
case(ServerDockerFailedError): return QObject::tr("Server error: Docker failed");
|
||||
case(ServerCancelInstallation): return QObject::tr("Installation canceled by user");
|
||||
|
||||
// Libssh errors
|
||||
case(SshRequsetDeniedError): return QObject::tr("Ssh request was denied");
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ QString amnezia::scriptName(SharedScriptType type)
|
|||
case SharedScriptType::remove_all_containers: return QLatin1String("remove_all_containers.sh");
|
||||
case SharedScriptType::setup_host_firewall: return QLatin1String("setup_host_firewall.sh");
|
||||
case SharedScriptType::check_connection: return QLatin1String("check_connection.sh");
|
||||
case SharedScriptType::check_server_is_busy: return QLatin1String("check_server_is_busy.sh");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ enum SharedScriptType {
|
|||
remove_container,
|
||||
remove_all_containers,
|
||||
setup_host_firewall,
|
||||
check_connection
|
||||
check_connection,
|
||||
check_server_is_busy
|
||||
};
|
||||
enum ProtocolScriptType {
|
||||
// Protocol scripts
|
||||
|
|
|
|||
|
|
@ -12,9 +12,11 @@
|
|||
#include <QApplication>
|
||||
#include <QTemporaryFile>
|
||||
#include <QFileInfo>
|
||||
#include <QThread>
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
|
@ -22,7 +24,7 @@
|
|||
#include <thread>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "debug.h"
|
||||
#include "logger.h"
|
||||
#include "server_defs.h"
|
||||
#include "settings.h"
|
||||
#include "scripts_registry.h"
|
||||
|
|
@ -77,7 +79,8 @@ ErrorCode ServerController::runScript(const ServerCredentials &credentials, QStr
|
|||
}
|
||||
|
||||
qDebug().noquote() << "EXEC" << lineToExec;
|
||||
Debug::appendSshLog("Run command:" + lineToExec);
|
||||
Logger::appendSshLog("Run command:" + lineToExec);
|
||||
|
||||
|
||||
error = m_sshClient.executeCommand(lineToExec, cbReadStdOut, cbReadStdErr);
|
||||
if (error != ErrorCode::NoError) {
|
||||
|
|
@ -96,7 +99,7 @@ ErrorCode ServerController::runContainerScript(const ServerCredentials &credenti
|
|||
const std::function<ErrorCode (const QString &, libssh::Client &)> &cbReadStdErr)
|
||||
{
|
||||
QString fileName = "/opt/amnezia/" + Utils::getRandomString(16) + ".sh";
|
||||
Debug::appendSshLog("Run container script for " + ContainerProps::containerToString(container) + QStringLiteral(":\n") + script);
|
||||
Logger::appendSshLog("Run container script for " + ContainerProps::containerToString(container) + ":\n" + script);
|
||||
|
||||
ErrorCode e = uploadTextFileToContainer(container, credentials, script, fileName);
|
||||
if (e) return e;
|
||||
|
|
@ -374,14 +377,45 @@ ErrorCode ServerController::installDockerWorker(const ServerCredentials &credent
|
|||
return ErrorCode::NoError;
|
||||
};
|
||||
|
||||
ErrorCode e = runScript(credentials,
|
||||
replaceVars(amnezia::scriptData(SharedScriptType::install_docker),
|
||||
genVarsForScript(credentials)),
|
||||
cbReadStdOut, cbReadStdErr);
|
||||
QFutureWatcher<ErrorCode> watcher;
|
||||
|
||||
QFuture<ErrorCode> future = QtConcurrent::run([this, &stdOut, &cbReadStdOut, &cbReadStdErr, &credentials]() {
|
||||
do {
|
||||
if (m_cancelInstallation) {
|
||||
return ErrorCode::ServerCancelInstallation;
|
||||
}
|
||||
stdOut.clear();
|
||||
runScript(credentials,
|
||||
replaceVars(amnezia::scriptData(SharedScriptType::check_server_is_busy),
|
||||
genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr);
|
||||
if (!stdOut.isEmpty() || stdOut.contains("Unable to acquire the dpkg frontend lock")) {
|
||||
emit serverIsBusy(true);
|
||||
QThread::msleep(1000);
|
||||
}
|
||||
} while (!stdOut.isEmpty());
|
||||
return ErrorCode::NoError;
|
||||
});
|
||||
|
||||
watcher.setFuture(future);
|
||||
|
||||
QEventLoop wait;
|
||||
QObject::connect(&watcher, &QFutureWatcher<ErrorCode>::finished, &wait, &QEventLoop::quit);
|
||||
wait.exec();
|
||||
|
||||
m_cancelInstallation = false;
|
||||
emit serverIsBusy(false);
|
||||
|
||||
if (future.result() != ErrorCode::NoError) {
|
||||
return future.result();
|
||||
}
|
||||
|
||||
ErrorCode error = runScript(credentials,
|
||||
replaceVars(amnezia::scriptData(SharedScriptType::install_docker),
|
||||
genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr);
|
||||
|
||||
if (stdOut.contains("command not found")) return ErrorCode::ServerDockerFailedError;
|
||||
|
||||
return e;
|
||||
return error;
|
||||
}
|
||||
|
||||
ErrorCode ServerController::prepareHostWorker(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config)
|
||||
|
|
@ -601,6 +635,11 @@ QString ServerController::checkSshConnection(const ServerCredentials &credential
|
|||
return stdOut;
|
||||
}
|
||||
|
||||
void ServerController::setCancelInstallation(const bool cancel)
|
||||
{
|
||||
m_cancelInstallation = cancel;
|
||||
}
|
||||
|
||||
void ServerController::disconnectFromHost(const ServerCredentials &credentials)
|
||||
{
|
||||
m_sshClient.disconnectFromHost();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "defs.h"
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
#include "sshclient.h"
|
||||
|
||||
class Settings;
|
||||
|
|
@ -70,6 +69,7 @@ public:
|
|||
|
||||
QString checkSshConnection(const ServerCredentials &credentials, ErrorCode *errorCode = nullptr);
|
||||
|
||||
void setCancelInstallation(const bool cancel);
|
||||
private:
|
||||
ErrorCode installDockerWorker(const ServerCredentials &credentials, DockerContainer container);
|
||||
ErrorCode prepareHostWorker(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config = QJsonObject());
|
||||
|
|
@ -81,7 +81,10 @@ private:
|
|||
std::shared_ptr<Settings> m_settings;
|
||||
std::shared_ptr<VpnConfigurator> m_configurator;
|
||||
|
||||
bool m_cancelInstallation = false;
|
||||
libssh::Client m_sshClient;
|
||||
signals:
|
||||
void serverIsBusy(const bool isBusy);
|
||||
};
|
||||
|
||||
#endif // SERVERCONTROLLER_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue