added display of wireguard configs, such a config will be displayed as raw text
This commit is contained in:
parent
99a6cd82b2
commit
6941b7463e
10 changed files with 142 additions and 14 deletions
|
@ -74,6 +74,7 @@ HEADERS += \
|
||||||
ui/pages_logic/protocols/OtherProtocolsLogic.h \
|
ui/pages_logic/protocols/OtherProtocolsLogic.h \
|
||||||
ui/pages_logic/protocols/PageProtocolLogicBase.h \
|
ui/pages_logic/protocols/PageProtocolLogicBase.h \
|
||||||
ui/pages_logic/protocols/ShadowSocksLogic.h \
|
ui/pages_logic/protocols/ShadowSocksLogic.h \
|
||||||
|
ui/pages_logic/protocols/WireGuardLogic.h \
|
||||||
ui/property_helper.h \
|
ui/property_helper.h \
|
||||||
ui/models/servers_model.h \
|
ui/models/servers_model.h \
|
||||||
ui/uilogic.h \
|
ui/uilogic.h \
|
||||||
|
@ -136,6 +137,7 @@ SOURCES += \
|
||||||
ui/pages_logic/protocols/PageProtocolLogicBase.cpp \
|
ui/pages_logic/protocols/PageProtocolLogicBase.cpp \
|
||||||
ui/pages_logic/protocols/ShadowSocksLogic.cpp \
|
ui/pages_logic/protocols/ShadowSocksLogic.cpp \
|
||||||
ui/models/servers_model.cpp \
|
ui/models/servers_model.cpp \
|
||||||
|
ui/pages_logic/protocols/WireGuardLogic.cpp \
|
||||||
ui/uilogic.cpp \
|
ui/uilogic.cpp \
|
||||||
ui/qautostart.cpp \
|
ui/qautostart.cpp \
|
||||||
ui/models/sites_model.cpp \
|
ui/models/sites_model.cpp \
|
||||||
|
|
|
@ -59,7 +59,7 @@ constexpr char additional_server_config[] = "additional_server_config";
|
||||||
// proto config keys
|
// proto config keys
|
||||||
constexpr char last_config[] = "last_config";
|
constexpr char last_config[] = "last_config";
|
||||||
|
|
||||||
constexpr char is_third_party_config[] = "is_third_party_config";
|
constexpr char isThirdPartyConfig[] = "isThirdPartyConfig";
|
||||||
|
|
||||||
constexpr char openvpn[] = "openvpn";
|
constexpr char openvpn[] = "openvpn";
|
||||||
constexpr char wireguard[] = "wireguard";
|
constexpr char wireguard[] = "wireguard";
|
||||||
|
|
|
@ -160,5 +160,6 @@
|
||||||
<file>ui/qml/Pages/PageQrDecoderIos.qml</file>
|
<file>ui/qml/Pages/PageQrDecoderIos.qml</file>
|
||||||
<file>server_scripts/website_tor/Dockerfile</file>
|
<file>server_scripts/website_tor/Dockerfile</file>
|
||||||
<file>ui/qml/Pages/PageViewConfig.qml</file>
|
<file>ui/qml/Pages/PageViewConfig.qml</file>
|
||||||
|
<file>ui/qml/Pages/Protocols/PageProtoWireGuard.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -317,5 +317,5 @@ bool Settings::isThirdPartyConfig(int serverIndex) const
|
||||||
{
|
{
|
||||||
if (serverIndex < 0) return false;
|
if (serverIndex < 0) return false;
|
||||||
const QJsonObject &s = server(serverIndex);
|
const QJsonObject &s = server(serverIndex);
|
||||||
return s.value(config_key::is_third_party_config).toBool();
|
return s.value(config_key::isThirdPartyConfig).toBool();
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,22 +267,22 @@ bool StartPageLogic::importConnectionFromOpenVpnConfig(const QString &config)
|
||||||
o[config_key::description] = "OpenVpn server";
|
o[config_key::description] = "OpenVpn server";
|
||||||
|
|
||||||
|
|
||||||
const static QRegularExpression dnsRegExp("dhcp-option DNS \\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b");
|
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);
|
QRegularExpressionMatchIterator dnsMatch = dnsRegExp.globalMatch(config);
|
||||||
if (dnsMatch.hasNext()) {
|
if (dnsMatch.hasNext()) {
|
||||||
o[config_key::dns1] = dnsMatch.next().captured(0).split(" ").at(2);
|
o[config_key::dns1] = dnsMatch.next().captured(1);
|
||||||
}
|
}
|
||||||
if (dnsMatch.hasNext()) {
|
if (dnsMatch.hasNext()) {
|
||||||
o[config_key::dns2] = dnsMatch.next().captured(0).split(" ").at(2);
|
o[config_key::dns2] = dnsMatch.next().captured(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const static QRegularExpression hostNameRegExp("remote \\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b");
|
const static QRegularExpression hostNameRegExp("remote (\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b)");
|
||||||
QRegularExpressionMatch hostNameMatch = hostNameRegExp.match(config);
|
QRegularExpressionMatch hostNameMatch = hostNameRegExp.match(config);
|
||||||
if (hostNameMatch.hasMatch()) {
|
if (hostNameMatch.hasMatch()) {
|
||||||
o[config_key::hostName] = hostNameMatch.captured(0).split(" ").at(1);
|
o[config_key::hostName] = hostNameMatch.captured(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
o[config_key::is_third_party_config] = true;
|
o[config_key::isThirdPartyConfig] = true;
|
||||||
|
|
||||||
return importConnection(o);
|
return importConnection(o);
|
||||||
}
|
}
|
||||||
|
@ -301,9 +301,8 @@ bool StartPageLogic::importConnectionFromWireguardConfig(const QString &config)
|
||||||
port = hostNameAndPortMatch.captured(2);
|
port = hostNameAndPortMatch.captured(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QJsonObject wireguardConfig;
|
QJsonObject wireguardConfig;
|
||||||
wireguardConfig[config_key::last_config] = lastConfig;
|
wireguardConfig[config_key::last_config] = QString(QJsonDocument(lastConfig).toJson());;
|
||||||
wireguardConfig[config_key::port] = port;
|
wireguardConfig[config_key::port] = port;
|
||||||
wireguardConfig[config_key::transport_proto] = "udp";
|
wireguardConfig[config_key::transport_proto] = "udp";
|
||||||
|
|
||||||
|
@ -318,7 +317,16 @@ bool StartPageLogic::importConnectionFromWireguardConfig(const QString &config)
|
||||||
o[config_key::containers] = arr;
|
o[config_key::containers] = arr;
|
||||||
o[config_key::defaultContainer] = "amnezia-wireguard";
|
o[config_key::defaultContainer] = "amnezia-wireguard";
|
||||||
o[config_key::description] = "Wireguard server";
|
o[config_key::description] = "Wireguard server";
|
||||||
|
|
||||||
|
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;
|
o[config_key::hostName] = hostName;
|
||||||
|
o[config_key::isThirdPartyConfig] = true;
|
||||||
|
|
||||||
return importConnection(o);
|
return importConnection(o);
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,11 +91,12 @@ void OpenVpnLogic::updateProtocolPage(const QJsonObject &openvpnConfig, DockerCo
|
||||||
auto lastConfig = openvpnConfig.value(config_key::last_config).toString();
|
auto lastConfig = openvpnConfig.value(config_key::last_config).toString();
|
||||||
auto lastConfigJson = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
auto lastConfigJson = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||||
QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
||||||
|
QString openVpnLastConfigText;
|
||||||
for (const QString &l: lines) {
|
for (const QString &l: lines) {
|
||||||
m_openVpnLastConfigText.append(l + "\n");
|
openVpnLastConfigText.append(l + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
emit openVpnLastConfigTextChanged(m_openVpnLastConfigText);
|
set_openVpnLastConfigText(m_openVpnLastConfigText);
|
||||||
set_isThirdPartyConfig(isThirdPartyConfig);
|
set_isThirdPartyConfig(isThirdPartyConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
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, bool isThirdPartyConfig)
|
||||||
|
{
|
||||||
|
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(isThirdPartyConfig);
|
||||||
|
}
|
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, bool isThirdPartyConfig) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
UiLogic *m_uiLogic;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WIREGUARDLOGIC_H
|
60
client/ui/qml/Pages/Protocols/PageProtoWireGuard.qml
Normal file
60
client/ui/qml/Pages/Protocols/PageProtoWireGuard.qml
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
import QtQuick 2.12
|
||||||
|
import QtQuick.Controls 2.12
|
||||||
|
import QtQuick.Layouts 1.15
|
||||||
|
import ProtocolEnum 1.0
|
||||||
|
import "../"
|
||||||
|
import "../../Controls"
|
||||||
|
import "../../Config"
|
||||||
|
|
||||||
|
PageProtocolBase {
|
||||||
|
id: root
|
||||||
|
protocol: ProtocolEnum.WireGuard
|
||||||
|
logic: UiLogic.protocolLogic(protocol)
|
||||||
|
|
||||||
|
BackButton {
|
||||||
|
id: back
|
||||||
|
}
|
||||||
|
Caption {
|
||||||
|
id: caption
|
||||||
|
text: qsTr("WireGuard Settings")
|
||||||
|
}
|
||||||
|
|
||||||
|
Flickable {
|
||||||
|
id: fl
|
||||||
|
width: root.width
|
||||||
|
anchors.top: caption.bottom
|
||||||
|
anchors.topMargin: 20
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.bottomMargin: 20
|
||||||
|
anchors.left: root.left
|
||||||
|
anchors.leftMargin: 30
|
||||||
|
anchors.right: root.right
|
||||||
|
anchors.rightMargin: 30
|
||||||
|
|
||||||
|
contentHeight: content.height
|
||||||
|
clip: true
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
id: content
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
|
||||||
|
TextAreaType {
|
||||||
|
id: ta_config
|
||||||
|
|
||||||
|
Layout.topMargin: 5
|
||||||
|
Layout.bottomMargin: 20
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.leftMargin: 1
|
||||||
|
Layout.rightMargin: 1
|
||||||
|
Layout.preferredHeight: fl.height - 70
|
||||||
|
flickableDirection: Flickable.AutoFlickIfNeeded
|
||||||
|
|
||||||
|
textArea.readOnly: true
|
||||||
|
textArea.text: logic.wireGuardLastConfigText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -71,7 +71,7 @@
|
||||||
#include "pages_logic/protocols/OpenVpnLogic.h"
|
#include "pages_logic/protocols/OpenVpnLogic.h"
|
||||||
#include "pages_logic/protocols/ShadowSocksLogic.h"
|
#include "pages_logic/protocols/ShadowSocksLogic.h"
|
||||||
#include "pages_logic/protocols/OtherProtocolsLogic.h"
|
#include "pages_logic/protocols/OtherProtocolsLogic.h"
|
||||||
|
#include "pages_logic/protocols/WireGuardLogic.h"
|
||||||
|
|
||||||
using namespace amnezia;
|
using namespace amnezia;
|
||||||
using namespace PageEnumNS;
|
using namespace PageEnumNS;
|
||||||
|
@ -94,7 +94,7 @@ UiLogic::UiLogic(std::shared_ptr<Settings> settings, std::shared_ptr<VpnConfigur
|
||||||
m_protocolLogicMap.insert(Proto::OpenVpn, new OpenVpnLogic(this));
|
m_protocolLogicMap.insert(Proto::OpenVpn, new OpenVpnLogic(this));
|
||||||
m_protocolLogicMap.insert(Proto::ShadowSocks, new ShadowSocksLogic(this));
|
m_protocolLogicMap.insert(Proto::ShadowSocks, new ShadowSocksLogic(this));
|
||||||
m_protocolLogicMap.insert(Proto::Cloak, new CloakLogic(this));
|
m_protocolLogicMap.insert(Proto::Cloak, new CloakLogic(this));
|
||||||
//m_protocolLogicMap->insert(Proto::WireGuard, new WireguardLogic(this));
|
m_protocolLogicMap.insert(Proto::WireGuard, new WireGuardLogic(this));
|
||||||
|
|
||||||
m_protocolLogicMap.insert(Proto::Dns, new OtherProtocolsLogic(this));
|
m_protocolLogicMap.insert(Proto::Dns, new OtherProtocolsLogic(this));
|
||||||
m_protocolLogicMap.insert(Proto::Sftp, new OtherProtocolsLogic(this));
|
m_protocolLogicMap.insert(Proto::Sftp, new OtherProtocolsLogic(this));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue