2020-12-18 14:57:22 +03:00
|
|
|
#ifndef SERVERCONTROLLER_H
|
|
|
|
|
#define SERVERCONTROLLER_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include "sshconnection.h"
|
2021-01-06 17:12:24 +03:00
|
|
|
#include "sshremoteprocess.h"
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
|
|
using namespace amnezia;
|
2020-12-18 14:57:22 +03:00
|
|
|
|
|
|
|
|
class ServerController : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
static ErrorCode fromSshConnectionErrorCode(QSsh::SshError error);
|
2020-12-18 14:57:22 +03:00
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
// QSsh exitCode and exitStatus are different things
|
|
|
|
|
static ErrorCode fromSshProcessExitStatus(int exitStatus);
|
|
|
|
|
|
|
|
|
|
static QString caCertPath() { return "/opt/amneziavpn_data/pki/ca.crt"; }
|
|
|
|
|
static QString clientCertPath() { return "/opt/amneziavpn_data/pki/issued/"; }
|
|
|
|
|
static QString taKeyPath() { return "/opt/amneziavpn_data/ta.key"; }
|
|
|
|
|
|
2021-01-15 23:36:35 +03:00
|
|
|
static QString getContainerName(amnezia::DockerContainer container);
|
|
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
static QSsh::SshConnectionParameters sshParams(const ServerCredentials &credentials);
|
2020-12-18 14:57:22 +03:00
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
static ErrorCode removeServer(const ServerCredentials &credentials, Protocol proto);
|
|
|
|
|
static ErrorCode setupServer(const ServerCredentials &credentials, Protocol proto);
|
2020-12-18 14:57:22 +03:00
|
|
|
|
2021-01-15 23:36:35 +03:00
|
|
|
static ErrorCode checkOpenVpnServer(DockerContainer container, const ServerCredentials &credentials);
|
|
|
|
|
|
|
|
|
|
static ErrorCode uploadTextFileToContainer(DockerContainer container,
|
|
|
|
|
const ServerCredentials &credentials, QString &file, const QString &path);
|
|
|
|
|
|
|
|
|
|
static QString getTextFileFromContainer(DockerContainer container,
|
|
|
|
|
const ServerCredentials &credentials, const QString &path, ErrorCode *errorCode = nullptr);
|
2021-01-06 17:12:24 +03:00
|
|
|
|
2021-01-15 23:36:35 +03:00
|
|
|
static ErrorCode signCert(DockerContainer container,
|
|
|
|
|
const ServerCredentials &credentials, QString clientId);
|
2021-01-06 17:12:24 +03:00
|
|
|
|
2021-01-15 23:36:35 +03:00
|
|
|
static int ssRemotePort() { return 6789; } // TODO move to ShadowSocksDefs.h
|
|
|
|
|
static int ssContainerPort() { return 8585; } // TODO move to ShadowSocksDefs.h
|
|
|
|
|
static QString ssEncryption() { return "chacha20-ietf-poly1305"; } // TODO move to ShadowSocksDefs.h
|
2021-01-06 17:12:24 +03:00
|
|
|
|
2021-01-21 19:14:07 +03:00
|
|
|
static ErrorCode setupServerFirewall(const ServerCredentials &credentials);
|
2021-01-06 17:12:24 +03:00
|
|
|
private:
|
|
|
|
|
static QSsh::SshConnection *connectToHost(const QSsh::SshConnectionParameters &sshParams);
|
2021-03-18 18:45:08 +03:00
|
|
|
|
|
|
|
|
static ErrorCode runScript(const QHash<QString, QString> &vars,
|
2021-02-18 15:00:41 +03:00
|
|
|
const QSsh::SshConnectionParameters &sshParams, QString script,
|
2021-02-25 18:05:42 +03:00
|
|
|
const std::function<void(const QString &, QSharedPointer<QSsh::SshRemoteProcess>)> &cbReadStdOut = nullptr,
|
|
|
|
|
const std::function<void(const QString &, QSharedPointer<QSsh::SshRemoteProcess>)> &cbReadStdErr = nullptr);
|
2020-12-18 14:57:22 +03:00
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
static ErrorCode setupOpenVpnServer(const ServerCredentials &credentials);
|
|
|
|
|
static ErrorCode setupShadowSocksServer(const ServerCredentials &credentials);
|
2020-12-18 14:57:22 +03:00
|
|
|
|
2021-03-18 18:45:08 +03:00
|
|
|
|
|
|
|
|
static QHash<QString, QString> genVarsForScript(const ServerCredentials &credentials, DockerContainer container);
|
2020-12-18 14:57:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SERVERCONTROLLER_H
|