Merge branch 'qt_migration' into refactoring/logging
This commit is contained in:
commit
b1b9044021
48 changed files with 1068 additions and 930 deletions
|
@ -29,6 +29,7 @@ void ServerContainersLogic::onUpdatePage()
|
|||
ProtocolsModel *p_model = qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel());
|
||||
p_model->setSelectedServerIndex(uiLogic()->selectedServerIndex);
|
||||
|
||||
set_isManagedServer(m_settings->haveAuthData(uiLogic()->selectedServerIndex));
|
||||
emit updatePage();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ public:
|
|||
Q_INVOKABLE void onPushButtonRemoveClicked(DockerContainer c);
|
||||
Q_INVOKABLE void onPushButtonContinueClicked(DockerContainer c, int port, TransportProto tp);
|
||||
|
||||
AUTO_PROPERTY(bool, isManagedServer)
|
||||
|
||||
public:
|
||||
explicit ServerContainersLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~ServerContainersLogic() = default;
|
||||
|
|
|
@ -37,11 +37,17 @@ void ServerSettingsLogic::onUpdatePage()
|
|||
set_pushButtonShareFullVisible(m_settings->haveAuthData(uiLogic()->selectedServerIndex));
|
||||
const QJsonObject &server = m_settings->server(uiLogic()->selectedServerIndex);
|
||||
const QString &port = server.value(config_key::port).toString();
|
||||
set_labelServerText(QString("%1@%2%3%4")
|
||||
.arg(server.value(config_key::userName).toString())
|
||||
.arg(server.value(config_key::hostName).toString())
|
||||
.arg(port.isEmpty() ? "" : ":")
|
||||
.arg(port));
|
||||
|
||||
const QString &userName = server.value(config_key::userName).toString();
|
||||
const QString &hostName = server.value(config_key::hostName).toString();
|
||||
QString name = QString("%1%2%3%4%5")
|
||||
.arg(userName)
|
||||
.arg(userName.isEmpty() ? "" : "@")
|
||||
.arg(hostName)
|
||||
.arg(port.isEmpty() ? "" : ":")
|
||||
.arg(port);
|
||||
|
||||
set_labelServerText(name);
|
||||
set_lineEditDescriptionText(server.value(config_key::description).toString());
|
||||
|
||||
DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex);
|
||||
|
|
|
@ -15,6 +15,36 @@
|
|||
#include "platforms/android/android_controller.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
enum class ConfigTypes {
|
||||
Amnezia,
|
||||
OpenVpn,
|
||||
WireGuard
|
||||
};
|
||||
|
||||
ConfigTypes checkConfigFormat(const QString &config)
|
||||
{
|
||||
const QString openVpnConfigPatternCli = "client";
|
||||
const QString openVpnConfigPatternProto1 = "proto tcp";
|
||||
const QString openVpnConfigPatternProto2 = "proto udp";
|
||||
const QString openVpnConfigPatternDriver1 = "dev tun";
|
||||
const QString openVpnConfigPatternDriver2 = "dev tap";
|
||||
|
||||
const QString wireguardConfigPatternSectionInterface = "[Interface]";
|
||||
const QString wireguardConfigPatternSectionPeer = "[Peer]";
|
||||
|
||||
if (config.contains(openVpnConfigPatternCli) &&
|
||||
(config.contains(openVpnConfigPatternProto1) || config.contains(openVpnConfigPatternProto2)) &&
|
||||
(config.contains(openVpnConfigPatternDriver1) || config.contains(openVpnConfigPatternDriver2))) {
|
||||
return ConfigTypes::OpenVpn;
|
||||
} else if (config.contains(wireguardConfigPatternSectionInterface) &&
|
||||
config.contains(wireguardConfigPatternSectionPeer))
|
||||
return ConfigTypes::WireGuard;
|
||||
return ConfigTypes::Amnezia;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
StartPageLogic::StartPageLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent),
|
||||
m_pushButtonConnectEnabled{true},
|
||||
|
@ -135,15 +165,22 @@ void StartPageLogic::onPushButtonImport()
|
|||
|
||||
void StartPageLogic::onPushButtonImportOpenFile()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(Q_NULLPTR, tr("Open profile"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), tr("*.vpn"));
|
||||
QString fileName = QFileDialog::getOpenFileName(Q_NULLPTR, tr("Open config file"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.vpn *.ovpn *.conf");
|
||||
if (fileName.isEmpty()) return;
|
||||
|
||||
QFile file(fileName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QByteArray data = file.readAll();
|
||||
|
||||
importConnectionFromCode(QString(data));
|
||||
auto configFormat = checkConfigFormat(QString(data));
|
||||
if (configFormat == ConfigTypes::OpenVpn) {
|
||||
importConnectionFromOpenVpnConfig(QString(data));
|
||||
} else if (configFormat == ConfigTypes::WireGuard) {
|
||||
importConnectionFromWireguardConfig(QString(data));
|
||||
} else {
|
||||
importConnectionFromCode(QString(data));
|
||||
}
|
||||
}
|
||||
|
||||
bool StartPageLogic::importConnection(const QJsonObject &profile)
|
||||
|
@ -201,3 +238,90 @@ bool StartPageLogic::importConnectionFromQr(const QByteArray &data)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StartPageLogic::importConnectionFromOpenVpnConfig(const QString &config)
|
||||
{
|
||||
QJsonObject openVpnConfig;
|
||||
openVpnConfig[config_key::config] = config;
|
||||
|
||||
QJsonObject lastConfig;
|
||||
lastConfig[config_key::last_config] = QString(QJsonDocument(openVpnConfig).toJson());
|
||||
lastConfig[config_key::isThirdPartyConfig] = true;
|
||||
|
||||
QJsonObject containers;
|
||||
containers.insert(config_key::container, QJsonValue("amnezia-openvpn"));
|
||||
containers.insert(config_key::openvpn, QJsonValue(lastConfig));
|
||||
|
||||
QJsonArray arr;
|
||||
arr.push_back(containers);
|
||||
|
||||
QString hostName;
|
||||
const static QRegularExpression hostNameRegExp("remote (.*) [0-9]*");
|
||||
QRegularExpressionMatch hostNameMatch = hostNameRegExp.match(config);
|
||||
if (hostNameMatch.hasMatch()) {
|
||||
hostName = hostNameMatch.captured(1);
|
||||
}
|
||||
|
||||
QJsonObject o;
|
||||
o[config_key::containers] = arr;
|
||||
o[config_key::defaultContainer] = "amnezia-openvpn";
|
||||
o[config_key::description] = m_settings->nextAvailableServerName();
|
||||
|
||||
|
||||
const static QRegularExpression dnsRegExp("dhcp-option DNS (\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b)");
|
||||
QRegularExpressionMatchIterator dnsMatch = dnsRegExp.globalMatch(config);
|
||||
if (dnsMatch.hasNext()) {
|
||||
o[config_key::dns1] = dnsMatch.next().captured(1);
|
||||
}
|
||||
if (dnsMatch.hasNext()) {
|
||||
o[config_key::dns2] = dnsMatch.next().captured(1);
|
||||
}
|
||||
|
||||
o[config_key::hostName] = hostName;
|
||||
|
||||
return importConnection(o);
|
||||
}
|
||||
|
||||
bool StartPageLogic::importConnectionFromWireguardConfig(const QString &config)
|
||||
{
|
||||
QJsonObject lastConfig;
|
||||
lastConfig[config_key::config] = config;
|
||||
|
||||
const static QRegularExpression hostNameAndPortRegExp("Endpoint = (.*):([0-9]*)");
|
||||
QRegularExpressionMatch hostNameAndPortMatch = hostNameAndPortRegExp.match(config);
|
||||
QString hostName;
|
||||
QString port;
|
||||
if (hostNameAndPortMatch.hasMatch()) {
|
||||
hostName = hostNameAndPortMatch.captured(1);
|
||||
port = hostNameAndPortMatch.captured(2);
|
||||
}
|
||||
|
||||
QJsonObject wireguardConfig;
|
||||
wireguardConfig[config_key::last_config] = QString(QJsonDocument(lastConfig).toJson());
|
||||
wireguardConfig[config_key::isThirdPartyConfig] = true;
|
||||
wireguardConfig[config_key::port] = port;
|
||||
wireguardConfig[config_key::transport_proto] = "udp";
|
||||
|
||||
QJsonObject containers;
|
||||
containers.insert(config_key::container, QJsonValue("amnezia-wireguard"));
|
||||
containers.insert(config_key::wireguard, QJsonValue(wireguardConfig));
|
||||
|
||||
QJsonArray arr;
|
||||
arr.push_back(containers);
|
||||
|
||||
QJsonObject o;
|
||||
o[config_key::containers] = arr;
|
||||
o[config_key::defaultContainer] = "amnezia-wireguard";
|
||||
o[config_key::description] = m_settings->nextAvailableServerName();
|
||||
|
||||
const static QRegularExpression dnsRegExp("DNS = (\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b).*(\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b)");
|
||||
QRegularExpressionMatch dnsMatch = dnsRegExp.match(config);
|
||||
if (dnsMatch.hasMatch()) {
|
||||
o[config_key::dns1] = dnsMatch.captured(1);
|
||||
o[config_key::dns2] = dnsMatch.captured(2);
|
||||
}
|
||||
|
||||
o[config_key::hostName] = hostName;
|
||||
|
||||
return importConnection(o);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
bool importConnection(const QJsonObject &profile);
|
||||
bool importConnectionFromCode(QString code);
|
||||
bool importConnectionFromQr(const QByteArray &data);
|
||||
bool importConnectionFromOpenVpnConfig(const QString &config);
|
||||
bool importConnectionFromWireguardConfig(const QString &config);
|
||||
|
||||
public:
|
||||
explicit StartPageLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
|
|
|
@ -13,6 +13,8 @@ void ViewConfigLogic::onUpdatePage()
|
|||
{
|
||||
set_configText(QJsonDocument(configJson()).toJson());
|
||||
|
||||
auto s = configJson()[config_key::isThirdPartyConfig].toBool();
|
||||
|
||||
m_openVpnLastConfigs = m_openVpnMalStrings =
|
||||
"<style> \
|
||||
div { line-height: 0.5; } \
|
||||
|
@ -24,28 +26,42 @@ void ViewConfigLogic::onUpdatePage()
|
|||
const QJsonArray &containers = configJson()[config_key::containers].toArray();
|
||||
int i = 0;
|
||||
for (const QJsonValue &v: containers) {
|
||||
QString cfg_json = v.toObject()[ProtocolProps::protoToString(Proto::OpenVpn)]
|
||||
.toObject()[config_key::last_config].toString();
|
||||
|
||||
QString openvpn_cfg = QJsonDocument::fromJson(cfg_json.toUtf8()).object()[config_key::config]
|
||||
.toString();
|
||||
|
||||
openvpn_cfg.replace("\r", "");
|
||||
|
||||
QStringList lines = openvpn_cfg.split("\n");
|
||||
for (const QString &l: lines) {
|
||||
i++;
|
||||
QRegularExpressionMatch match = m_re.match(l);
|
||||
if (dangerousTags.contains(match.captured(0))) {
|
||||
QString t = QString("<p><font color=\"red\">%1</font>").arg(l);
|
||||
m_openVpnLastConfigs.append(t + "\n");
|
||||
m_openVpnMalStrings.append(t);
|
||||
if (m_warningStringNumber == 3) m_warningStringNumber = i - 3;
|
||||
m_warningActive = true;
|
||||
qDebug() << "ViewConfigLogic : malicious scripts warning:" << l;
|
||||
auto containerName = v.toObject()[config_key::container].toString();
|
||||
QJsonObject containerConfig = v.toObject()[containerName.replace("amnezia-", "")].toObject();
|
||||
if (containerConfig[config_key::isThirdPartyConfig].toBool()) {
|
||||
auto lastConfig = containerConfig.value(config_key::last_config).toString();
|
||||
auto lastConfigJson = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||
QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
||||
QString lastConfigText;
|
||||
for (const QString &l: lines) {
|
||||
lastConfigText.append(l + "\n");
|
||||
}
|
||||
else {
|
||||
m_openVpnLastConfigs.append("<p>" + l + " \n");
|
||||
set_configText(lastConfigText);
|
||||
}
|
||||
|
||||
|
||||
if (v.toObject()[config_key::container].toString() == "amnezia-openvpn") {
|
||||
QString lastConfig = v.toObject()[ProtocolProps::protoToString(Proto::OpenVpn)]
|
||||
.toObject()[config_key::last_config].toString();
|
||||
|
||||
QString lastConfigJson = QJsonDocument::fromJson(lastConfig.toUtf8()).object()[config_key::config]
|
||||
.toString();
|
||||
|
||||
QStringList lines = lastConfigJson.replace("\r", "").split("\n");
|
||||
for (const QString &l: lines) {
|
||||
i++;
|
||||
QRegularExpressionMatch match = m_re.match(l);
|
||||
if (dangerousTags.contains(match.captured(0))) {
|
||||
QString t = QString("<p><font color=\"red\">%1</font>").arg(l);
|
||||
m_openVpnLastConfigs.append(t + "\n");
|
||||
m_openVpnMalStrings.append(t);
|
||||
if (m_warningStringNumber == 3) m_warningStringNumber = i - 3;
|
||||
m_warningActive = true;
|
||||
qDebug() << "ViewConfigLogic : malicious scripts warning:" << l;
|
||||
}
|
||||
else {
|
||||
m_openVpnLastConfigs.append("<p>" + l + " \n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
explicit CloakLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~CloakLogic() = default;
|
||||
|
||||
void updateProtocolPage (const QJsonObject &ckConfig, DockerContainer container, bool haveAuthData) override;
|
||||
void updateProtocolPage(const QJsonObject &ckConfig, DockerContainer container, bool haveAuthData) override;
|
||||
QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -87,6 +87,17 @@ void OpenVpnLogic::updateProtocolPage(const QJsonObject &openvpnConfig, DockerCo
|
|||
toString(protocols::openvpn::defaultPort));
|
||||
|
||||
set_lineEditPortEnabled(container == DockerContainer::OpenVpn);
|
||||
|
||||
auto lastConfig = openvpnConfig.value(config_key::last_config).toString();
|
||||
auto lastConfigJson = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||
QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
||||
QString openVpnLastConfigText;
|
||||
for (const QString &l: lines) {
|
||||
openVpnLastConfigText.append(l + "\n");
|
||||
}
|
||||
|
||||
set_openVpnLastConfigText(openVpnLastConfigText);
|
||||
set_isThirdPartyConfig(openvpnConfig.value(config_key::isThirdPartyConfig).isBool());
|
||||
}
|
||||
|
||||
void OpenVpnLogic::onPushButtonProtoOpenVpnSaveClicked()
|
||||
|
|
|
@ -35,6 +35,9 @@ class OpenVpnLogic : public PageProtocolLogicBase
|
|||
AUTO_PROPERTY(int, progressBarResetValue)
|
||||
AUTO_PROPERTY(int, progressBarResetMaximium)
|
||||
|
||||
AUTO_PROPERTY(QString, openVpnLastConfigText)
|
||||
AUTO_PROPERTY(bool, isThirdPartyConfig)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE void onPushButtonProtoOpenVpnSaveClicked();
|
||||
|
||||
|
|
30
client/ui/pages_logic/protocols/WireGuardLogic.cpp
Normal file
30
client/ui/pages_logic/protocols/WireGuardLogic.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "WireGuardLogic.h"
|
||||
#include "core/servercontroller.h"
|
||||
#include <functional>
|
||||
#include "../../uilogic.h"
|
||||
|
||||
using namespace amnezia;
|
||||
using namespace PageEnumNS;
|
||||
|
||||
WireGuardLogic::WireGuardLogic(UiLogic *logic, QObject *parent):
|
||||
PageProtocolLogicBase(logic, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void WireGuardLogic::updateProtocolPage(const QJsonObject &wireGuardConfig, DockerContainer container, bool haveAuthData)
|
||||
{
|
||||
qDebug() << "WireGuardLogic::updateProtocolPage";
|
||||
|
||||
auto lastConfigJsonDoc = QJsonDocument::fromJson(wireGuardConfig.value(config_key::last_config).toString().toUtf8());
|
||||
auto lastConfigJson = lastConfigJsonDoc.object();
|
||||
|
||||
QString wireGuardLastConfigText;
|
||||
QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
||||
for (const QString &l: lines) {
|
||||
wireGuardLastConfigText.append(l + "\n");
|
||||
}
|
||||
|
||||
set_wireGuardLastConfigText(wireGuardLastConfigText);
|
||||
set_isThirdPartyConfig(wireGuardConfig.value(config_key::isThirdPartyConfig).toBool());
|
||||
}
|
26
client/ui/pages_logic/protocols/WireGuardLogic.h
Normal file
26
client/ui/pages_logic/protocols/WireGuardLogic.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef WIREGUARDLOGIC_H
|
||||
#define WIREGUARDLOGIC_H
|
||||
|
||||
#include "PageProtocolLogicBase.h"
|
||||
|
||||
class UiLogic;
|
||||
|
||||
class WireGuardLogic : public PageProtocolLogicBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
AUTO_PROPERTY(QString, wireGuardLastConfigText)
|
||||
AUTO_PROPERTY(bool, isThirdPartyConfig)
|
||||
|
||||
public:
|
||||
explicit WireGuardLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~WireGuardLogic() = default;
|
||||
|
||||
void updateProtocolPage(const QJsonObject &wireGuardConfig, DockerContainer container, bool haveAuthData) override;
|
||||
|
||||
private:
|
||||
UiLogic *m_uiLogic;
|
||||
|
||||
};
|
||||
|
||||
#endif // WIREGUARDLOGIC_H
|
Loading…
Add table
Add a link
Reference in a new issue