From 3aaa7b62eff5f532a11b8fcff632878dabd7017f Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Fri, 14 Jul 2023 13:14:50 +0900 Subject: [PATCH] added page to display raw config --- client/amnezia_application.cpp | 15 ++ client/amnezia_application.h | 2 + client/resources.qrc | 1 + client/ui/controllers/exportController.cpp | 31 ++- client/ui/controllers/exportController.h | 7 +- client/ui/controllers/pageController.h | 4 +- client/ui/models/protocols_model.cpp | 14 ++ client/ui/models/protocols_model.h | 3 +- .../Components/SettingsContainersListView.qml | 13 +- .../qml/Components/ShareConnectionDrawer.qml | 2 +- client/ui/qml/Pages2/PageHome.qml | 2 +- .../qml/Pages2/PageProtocolCloakSettings.qml | 2 + .../Pages2/PageProtocolOpenVpnSettings.qml | 2 + client/ui/qml/Pages2/PageProtocolRaw.qml | 190 ++++++++++++++++++ .../PageProtocolShadowSocksSettings.qml | 2 + client/ui/qml/main2.qml | 6 + 16 files changed, 266 insertions(+), 30 deletions(-) create mode 100644 client/ui/qml/Pages2/PageProtocolRaw.qml diff --git a/client/amnezia_application.cpp b/client/amnezia_application.cpp index 436dfc3f..abd839ed 100644 --- a/client/amnezia_application.cpp +++ b/client/amnezia_application.cpp @@ -86,6 +86,21 @@ void AmneziaApplication::init() initModels(); initControllers(); + m_notificationHandler.reset(NotificationHandler::create(nullptr)); + + connect(m_vpnConnection.get(), &VpnConnection::connectionStateChanged, m_notificationHandler.get(), + &NotificationHandler::setConnectionState); + + void openConnection(); + void closeConnection(); + + connect(m_notificationHandler.get(), &NotificationHandler::raiseRequested, m_pageController.get(), + &PageController::raise); + connect(m_notificationHandler.get(), &NotificationHandler::connectRequested, m_connectionController.get(), + &ConnectionController::openConnection); + connect(m_notificationHandler.get(), &NotificationHandler::disconnectRequested, m_connectionController.get(), + &ConnectionController::closeConnection); + // m_engine->load(url); diff --git a/client/amnezia_application.h b/client/amnezia_application.h index fabc7818..6e9fcdf0 100644 --- a/client/amnezia_application.h +++ b/client/amnezia_application.h @@ -22,6 +22,7 @@ #include "ui/models/containers_model.h" #include "ui/models/languageModel.h" #include "ui/models/protocols/cloakConfigModel.h" +#include "ui/notificationhandler.h" #ifdef Q_OS_WINDOWS #include "ui/models/protocols/ikev2ConfigModel.h" #endif @@ -91,6 +92,7 @@ private: #endif QSharedPointer m_vpnConnection; + QScopedPointer m_notificationHandler; QScopedPointer m_connectionController; QScopedPointer m_pageController; diff --git a/client/resources.qrc b/client/resources.qrc index dd75555f..df6fcb3e 100644 --- a/client/resources.qrc +++ b/client/resources.qrc @@ -273,5 +273,6 @@ ui/qml/Pages2/PageProtocolOpenVpnSettings.qml ui/qml/Pages2/PageProtocolShadowSocksSettings.qml ui/qml/Pages2/PageProtocolCloakSettings.qml + ui/qml/Pages2/PageProtocolRaw.qml diff --git a/client/ui/controllers/exportController.cpp b/client/ui/controllers/exportController.cpp index 5cd9a83d..c989422d 100644 --- a/client/ui/controllers/exportController.cpp +++ b/client/ui/controllers/exportController.cpp @@ -36,10 +36,9 @@ void ExportController::generateFullAccessConfig() QByteArray compressedConfig = QJsonDocument(config).toJson(); compressedConfig = qCompress(compressedConfig, 8); - m_rawConfig = QString("vpn://%1") - .arg(QString(compressedConfig.toBase64(QByteArray::Base64UrlEncoding - | QByteArray::OmitTrailingEquals))); - m_formattedConfig = m_rawConfig; + m_config = QString("vpn://%1") + .arg(QString(compressedConfig.toBase64(QByteArray::Base64UrlEncoding + | QByteArray::OmitTrailingEquals))); m_qrCodes = generateQrCodeImageSeries(compressedConfig); emit exportConfigChanged(); @@ -88,10 +87,9 @@ void ExportController::generateConnectionConfig() QByteArray compressedConfig = QJsonDocument(config).toJson(); compressedConfig = qCompress(compressedConfig, 8); - m_rawConfig = QString("vpn://%1") - .arg(QString(compressedConfig.toBase64(QByteArray::Base64UrlEncoding - | QByteArray::OmitTrailingEquals))); - m_formattedConfig = m_rawConfig; + m_config = QString("vpn://%1") + .arg(QString(compressedConfig.toBase64(QByteArray::Base64UrlEncoding + | QByteArray::OmitTrailingEquals))); m_qrCodes = generateQrCodeImageSeries(compressedConfig); emit exportConfigChanged(); @@ -120,12 +118,10 @@ void ExportController::generateOpenVpnConfig() } config = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::OpenVpn, config); - m_rawConfig = config; - auto configJson = QJsonDocument::fromJson(config.toUtf8()).object(); QStringList lines = configJson.value(config_key::config).toString().replace("\r", "").split("\n"); for (const QString &line : lines) { - m_formattedConfig.append(line + "\n"); + m_config.append(line + "\n"); } emit exportConfigChanged(); @@ -154,20 +150,18 @@ void ExportController::generateWireGuardConfig() } config = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::WireGuard, config); - m_rawConfig = config; - auto configJson = QJsonDocument::fromJson(config.toUtf8()).object(); QStringList lines = configJson.value(config_key::config).toString().replace("\r", "").split("\n"); for (const QString &line : lines) { - m_formattedConfig.append(line + "\n"); + m_config.append(line + "\n"); } emit exportConfigChanged(); } -QString ExportController::getFormattedConfig() +QString ExportController::getConfig() { - return m_formattedConfig; + return m_config; } QList ExportController::getQrCodes() @@ -193,7 +187,7 @@ void ExportController::saveFile() QFile save(fileName.toLocalFile()); save.open(QIODevice::WriteOnly); - save.write(m_rawConfig.toUtf8()); + save.write(m_config.toUtf8()); save.close(); QFileInfo fi(fileName.toLocalFile()); @@ -233,7 +227,6 @@ int ExportController::getQrCodesCount() void ExportController::clearPreviousConfig() { - m_rawConfig.clear(); - m_formattedConfig.clear(); + m_config.clear(); m_qrCodes.clear(); } diff --git a/client/ui/controllers/exportController.h b/client/ui/controllers/exportController.h index 85144978..e4a37a96 100644 --- a/client/ui/controllers/exportController.h +++ b/client/ui/controllers/exportController.h @@ -18,7 +18,7 @@ public: Q_PROPERTY(QList qrCodes READ getQrCodes NOTIFY exportConfigChanged) Q_PROPERTY(int qrCodesCount READ getQrCodesCount NOTIFY exportConfigChanged) - Q_PROPERTY(QString formattedConfig READ getFormattedConfig NOTIFY exportConfigChanged) + Q_PROPERTY(QString config READ getConfig NOTIFY exportConfigChanged) public slots: void generateFullAccessConfig(); @@ -26,7 +26,7 @@ public slots: void generateOpenVpnConfig(); void generateWireGuardConfig(); - QString getFormattedConfig(); + QString getConfig(); QList getQrCodes(); void saveFile(); @@ -50,8 +50,7 @@ private: std::shared_ptr m_settings; std::shared_ptr m_configurator; - QString m_rawConfig; - QString m_formattedConfig; + QString m_config; QList m_qrCodes; }; diff --git a/client/ui/controllers/pageController.h b/client/ui/controllers/pageController.h index 468068b8..05b8fbf9 100644 --- a/client/ui/controllers/pageController.h +++ b/client/ui/controllers/pageController.h @@ -42,7 +42,8 @@ namespace PageLoader PageProtocolShadowSocksSettings, PageProtocolCloakSettings, PageProtocolWireGuardSettings, - PageProtocolIKev2Settings + PageProtocolIKev2Settings, + PageProtocolRaw }; Q_ENUM_NS(PageEnum) @@ -70,6 +71,7 @@ signals: void showErrorMessage(QString errorMessage); void showInfoMessage(QString message); void showBusyIndicator(bool visible); + void raise(); private: QSharedPointer m_serversModel; diff --git a/client/ui/models/protocols_model.cpp b/client/ui/models/protocols_model.cpp index ac271eb9..da730f55 100644 --- a/client/ui/models/protocols_model.cpp +++ b/client/ui/models/protocols_model.cpp @@ -17,6 +17,7 @@ QHash ProtocolsModel::roleNames() const roles[ProtocolNameRole] = "protocolName"; roles[ProtocolPageRole] = "protocolPage"; + roles[RawConfigRole] = "rawConfig"; return roles; } @@ -34,6 +35,19 @@ QVariant ProtocolsModel::data(const QModelIndex &index, int role) const } case ProtocolPageRole: return static_cast(protocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row())))); + case RawConfigRole: { + auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject(); + auto lastConfigJsonDoc = + QJsonDocument::fromJson(protocolConfig.value(config_key::last_config).toString().toUtf8()); + auto lastConfigJson = lastConfigJsonDoc.object(); + + QString rawConfig; + QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n"); + for (const QString &l : lines) { + rawConfig.append(l + "\n"); + } + return rawConfig; + } } return QVariant(); diff --git a/client/ui/models/protocols_model.h b/client/ui/models/protocols_model.h index 1e279cfb..c4ad5c70 100644 --- a/client/ui/models/protocols_model.h +++ b/client/ui/models/protocols_model.h @@ -13,7 +13,8 @@ class ProtocolsModel : public QAbstractListModel public: enum Roles { ProtocolNameRole = Qt::UserRole + 1, - ProtocolPageRole + ProtocolPageRole, + RawConfigRole }; ProtocolsModel(std::shared_ptr settings, QObject *parent = nullptr); diff --git a/client/ui/qml/Components/SettingsContainersListView.qml b/client/ui/qml/Components/SettingsContainersListView.qml index 7204ac16..d2f3ee81 100644 --- a/client/ui/qml/Components/SettingsContainersListView.qml +++ b/client/ui/qml/Components/SettingsContainersListView.qml @@ -7,6 +7,7 @@ import SortFilterProxyModel 0.2 import PageEnum 1.0 import ProtocolEnum 1.0 import ContainerEnum 1.0 +import ContainerProps 1.0 import "../Controls2" import "../Controls2/TextTypes" @@ -91,19 +92,25 @@ ListView { if (isInstalled) { var containerIndex = root.model.mapToSource(index) ContainersModel.setCurrentlyProcessedContainerIndex(containerIndex) + if (config[ContainerProps.containerTypeToString(containerIndex)]["isThirdPartyConfig"]) { + ProtocolsModel.updateModel(config) + goToPage(PageEnum.PageProtocolRaw) + return + } + switch (containerIndex) { case ContainerEnum.OpenVpn: { - OpenVpnConfigModel.updateModel(ProtocolsModel.getConfig()) + OpenVpnConfigModel.updateModel(config) goToPage(PageEnum.PageProtocolOpenVpnSettings) break } case ContainerEnum.WireGuard: { - WireGuardConfigModel.updateModel(ProtocolsModel.getConfig()) + WireGuardConfigModel.updateModel(config) goToPage(PageEnum.PageProtocolWireGuardSettings) break } case ContainerEnum.Ipsec: { - Ikev2ConfigModel.updateModel(ProtocolsModel.getConfig()) + Ikev2ConfigModel.updateModel(config) goToPage(PageEnum.PageProtocolIKev2Settings) break } diff --git a/client/ui/qml/Components/ShareConnectionDrawer.qml b/client/ui/qml/Components/ShareConnectionDrawer.qml index 275e41ea..05df413c 100644 --- a/client/ui/qml/Components/ShareConnectionDrawer.qml +++ b/client/ui/qml/Components/ShareConnectionDrawer.qml @@ -156,7 +156,7 @@ DrawerType { font.weight: Font.Medium font.family: "PT Root UI VF" - text: ExportController.formattedConfig + text: ExportController.config wrapMode: Text.Wrap diff --git a/client/ui/qml/Pages2/PageHome.qml b/client/ui/qml/Pages2/PageHome.qml index ab1eeba1..b7d44c78 100644 --- a/client/ui/qml/Pages2/PageHome.qml +++ b/client/ui/qml/Pages2/PageHome.qml @@ -102,7 +102,7 @@ PageType { description += "Amnezia DNS | " } } else { - if (ServersModel.isDefaultServerConfigContainsAmneziaDns) { + if (ServersModel.isDefaultServerConfigContainsAmneziaDns()) { description += "Amnezia DNS | " } } diff --git a/client/ui/qml/Pages2/PageProtocolCloakSettings.qml b/client/ui/qml/Pages2/PageProtocolCloakSettings.qml index 9ee67303..33d231b5 100644 --- a/client/ui/qml/Pages2/PageProtocolCloakSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolCloakSettings.qml @@ -53,6 +53,8 @@ PageType { anchors.left: parent.left anchors.right: parent.right + enabled: ServersModel.isCurrentlyProcessedServerHasWriteAccess() + ListView { id: listview diff --git a/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml b/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml index 8e5556d0..0bad68e9 100644 --- a/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml @@ -54,6 +54,8 @@ PageType { anchors.left: parent.left anchors.right: parent.right + enabled: ServersModel.isCurrentlyProcessedServerHasWriteAccess() + ListView { id: listview diff --git a/client/ui/qml/Pages2/PageProtocolRaw.qml b/client/ui/qml/Pages2/PageProtocolRaw.qml new file mode 100644 index 00000000..377d948e --- /dev/null +++ b/client/ui/qml/Pages2/PageProtocolRaw.qml @@ -0,0 +1,190 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +import SortFilterProxyModel 0.2 + +import PageEnum 1.0 +import ProtocolEnum 1.0 +import ContainerEnum 1.0 +import ContainerProps 1.0 + +import "./" +import "../Controls2" +import "../Controls2/TextTypes" +import "../Config" +import "../Components" + +PageType { + id: root + + ColumnLayout { + id: header + + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + + anchors.topMargin: 20 + + BackButtonType { + } + + HeaderType { + Layout.fillWidth: true + Layout.leftMargin: 16 + Layout.rightMargin: 16 + + headerText: ContainersModel.getCurrentlyProcessedContainerName() + qsTr(" settings") + } + } + + FlickableType { + id: fl + anchors.top: header.bottom + anchors.left: parent.left + anchors.right: parent.right + contentHeight: content.height + + Column { + id: content + + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.topMargin: 32 + + ListView { + width: parent.width + height: contentItem.height + clip: true + interactive: false + model: ProtocolsModel + + delegate: Item { + implicitWidth: parent.width + implicitHeight: delegateContent.implicitHeight + + ColumnLayout { + id: delegateContent + + anchors.fill: parent + + LabelWithButtonType { + id: button + + Layout.fillWidth: true + + text: qsTr("Show connection options") + + clickedFunction: function() { + configContentDrawer.open() + } + + MouseArea { + anchors.fill: button + cursorShape: Qt.PointingHandCursor + enabled: false + } + } + + DividerType {} + + DrawerType { + id: configContentDrawer + + width: parent.width + height: parent.height * 0.9 + + BackButtonType { + id: backButton + + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.topMargin: 16 + + backButtonFunction: function() { + configContentDrawer.visible = false + } + } + + FlickableType { + anchors.top: backButton.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + contentHeight: configContent.implicitHeight + configContent.anchors.topMargin + configContent.anchors.bottomMargin + + ColumnLayout { + id: configContent + + anchors.fill: parent + anchors.rightMargin: 16 + anchors.leftMargin: 16 + + Header2Type { + Layout.fillWidth: true + Layout.topMargin: 16 + + headerText: qsTr("Connection options ") + protocolName + } + + TextArea { + id: configText + + Layout.fillWidth: true + Layout.topMargin: 16 + Layout.bottomMargin: 16 + + padding: 0 + leftPadding: 0 + height: 24 + + color: "#D7D8DB" + selectionColor: "#412102" + selectedTextColor: "#D7D8DB" + + font.pixelSize: 16 + font.weight: Font.Medium + font.family: "PT Root UI VF" + + text: rawConfig + + wrapMode: Text.Wrap + + background: Rectangle { + color: "transparent" + } + } + } + } + } + } + } + } + + LabelWithButtonType { + id: removeButton + + width: parent.width + + text: qsTr("Remove ") + ContainersModel.getCurrentlyProcessedContainerName() + textColor: "#EB5757" + + clickedFunction: function() { + ContainersModel.removeCurrentlyProcessedContainer() + closePage() + } + + MouseArea { + anchors.fill: removeButton + cursorShape: Qt.PointingHandCursor + enabled: false + } + } + + DividerType {} + } + } +} diff --git a/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml b/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml index 57006cc4..730e3907 100644 --- a/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml @@ -53,6 +53,8 @@ PageType { anchors.left: parent.left anchors.right: parent.right + enabled: ServersModel.isCurrentlyProcessedServerHasWriteAccess() + ListView { id: listview diff --git a/client/ui/qml/main2.qml b/client/ui/qml/main2.qml index 0be8e368..8ad71d0f 100644 --- a/client/ui/qml/main2.qml +++ b/client/ui/qml/main2.qml @@ -48,5 +48,11 @@ Window { } rootStackView.replace(pagePath, { "objectName" : pagePath }) } + + function onRaise() { + root.show() + root.raise() + root.requestActivate() + } } }