2021-05-07 23:28:37 +03:00
|
|
|
#include "shadowsocks_configurator.h"
|
|
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QJsonDocument>
|
2024-04-12 20:00:21 +05:00
|
|
|
#include <QJsonObject>
|
2021-05-07 23:28:37 +03:00
|
|
|
|
2021-09-09 20:15:44 +03:00
|
|
|
#include "containers/containers_defs.h"
|
2023-10-12 20:48:03 +05:00
|
|
|
#include "core/controllers/serverController.h"
|
2022-08-25 17:35:28 +03:00
|
|
|
|
2024-04-12 20:00:21 +05:00
|
|
|
ShadowSocksConfigurator::ShadowSocksConfigurator(std::shared_ptr<Settings> settings, const QSharedPointer<ServerController> &serverController,
|
|
|
|
|
QObject *parent)
|
|
|
|
|
: ConfiguratorBase(settings, serverController, parent)
|
2022-08-25 17:35:28 +03:00
|
|
|
{
|
|
|
|
|
}
|
2021-05-07 23:28:37 +03:00
|
|
|
|
2024-04-01 20:20:02 +07:00
|
|
|
QString ShadowSocksConfigurator::createConfig(const ServerCredentials &credentials, DockerContainer container,
|
2024-05-09 20:56:52 +03:00
|
|
|
const QJsonObject &containerConfig, ErrorCode &errorCode)
|
2021-05-07 23:28:37 +03:00
|
|
|
{
|
2024-04-12 20:00:21 +05:00
|
|
|
QString ssKey =
|
|
|
|
|
m_serverController->getTextFileFromContainer(container, credentials, amnezia::protocols::shadowsocks::ssKeyPath, errorCode);
|
2021-05-07 23:28:37 +03:00
|
|
|
ssKey.replace("\n", "");
|
|
|
|
|
|
2024-04-01 20:20:02 +07:00
|
|
|
if (errorCode != ErrorCode::NoError) {
|
2021-05-07 23:28:37 +03:00
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QJsonObject config;
|
|
|
|
|
config.insert("server", credentials.hostName);
|
|
|
|
|
config.insert("server_port", "$SHADOWSOCKS_SERVER_PORT");
|
|
|
|
|
config.insert("local_port", "$SHADOWSOCKS_LOCAL_PORT");
|
|
|
|
|
config.insert("password", ssKey);
|
|
|
|
|
config.insert("timeout", 60);
|
|
|
|
|
config.insert("method", "$SHADOWSOCKS_CIPHER");
|
|
|
|
|
|
2024-04-12 20:00:21 +05:00
|
|
|
QString textCfg = m_serverController->replaceVars(QJsonDocument(config).toJson(),
|
|
|
|
|
m_serverController->genVarsForScript(credentials, container, containerConfig));
|
2021-05-07 23:28:37 +03:00
|
|
|
|
2024-04-12 20:00:21 +05:00
|
|
|
// qDebug().noquote() << textCfg;
|
2021-05-07 23:28:37 +03:00
|
|
|
return textCfg;
|
|
|
|
|
}
|