added page to display raw config

This commit is contained in:
vladimir.kuznetsov 2023-07-14 13:14:50 +09:00
parent c13b9754eb
commit 3aaa7b62ef
16 changed files with 266 additions and 30 deletions

View file

@ -86,6 +86,21 @@ void AmneziaApplication::init()
initModels(); initModels();
initControllers(); 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); m_engine->load(url);

View file

@ -22,6 +22,7 @@
#include "ui/models/containers_model.h" #include "ui/models/containers_model.h"
#include "ui/models/languageModel.h" #include "ui/models/languageModel.h"
#include "ui/models/protocols/cloakConfigModel.h" #include "ui/models/protocols/cloakConfigModel.h"
#include "ui/notificationhandler.h"
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
#include "ui/models/protocols/ikev2ConfigModel.h" #include "ui/models/protocols/ikev2ConfigModel.h"
#endif #endif
@ -91,6 +92,7 @@ private:
#endif #endif
QSharedPointer<VpnConnection> m_vpnConnection; QSharedPointer<VpnConnection> m_vpnConnection;
QScopedPointer<NotificationHandler> m_notificationHandler;
QScopedPointer<ConnectionController> m_connectionController; QScopedPointer<ConnectionController> m_connectionController;
QScopedPointer<PageController> m_pageController; QScopedPointer<PageController> m_pageController;

View file

@ -273,5 +273,6 @@
<file>ui/qml/Pages2/PageProtocolOpenVpnSettings.qml</file> <file>ui/qml/Pages2/PageProtocolOpenVpnSettings.qml</file>
<file>ui/qml/Pages2/PageProtocolShadowSocksSettings.qml</file> <file>ui/qml/Pages2/PageProtocolShadowSocksSettings.qml</file>
<file>ui/qml/Pages2/PageProtocolCloakSettings.qml</file> <file>ui/qml/Pages2/PageProtocolCloakSettings.qml</file>
<file>ui/qml/Pages2/PageProtocolRaw.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -36,10 +36,9 @@ void ExportController::generateFullAccessConfig()
QByteArray compressedConfig = QJsonDocument(config).toJson(); QByteArray compressedConfig = QJsonDocument(config).toJson();
compressedConfig = qCompress(compressedConfig, 8); compressedConfig = qCompress(compressedConfig, 8);
m_rawConfig = QString("vpn://%1") m_config = QString("vpn://%1")
.arg(QString(compressedConfig.toBase64(QByteArray::Base64UrlEncoding .arg(QString(compressedConfig.toBase64(QByteArray::Base64UrlEncoding
| QByteArray::OmitTrailingEquals))); | QByteArray::OmitTrailingEquals)));
m_formattedConfig = m_rawConfig;
m_qrCodes = generateQrCodeImageSeries(compressedConfig); m_qrCodes = generateQrCodeImageSeries(compressedConfig);
emit exportConfigChanged(); emit exportConfigChanged();
@ -88,10 +87,9 @@ void ExportController::generateConnectionConfig()
QByteArray compressedConfig = QJsonDocument(config).toJson(); QByteArray compressedConfig = QJsonDocument(config).toJson();
compressedConfig = qCompress(compressedConfig, 8); compressedConfig = qCompress(compressedConfig, 8);
m_rawConfig = QString("vpn://%1") m_config = QString("vpn://%1")
.arg(QString(compressedConfig.toBase64(QByteArray::Base64UrlEncoding .arg(QString(compressedConfig.toBase64(QByteArray::Base64UrlEncoding
| QByteArray::OmitTrailingEquals))); | QByteArray::OmitTrailingEquals)));
m_formattedConfig = m_rawConfig;
m_qrCodes = generateQrCodeImageSeries(compressedConfig); m_qrCodes = generateQrCodeImageSeries(compressedConfig);
emit exportConfigChanged(); emit exportConfigChanged();
@ -120,12 +118,10 @@ void ExportController::generateOpenVpnConfig()
} }
config = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::OpenVpn, config); config = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::OpenVpn, config);
m_rawConfig = config;
auto configJson = QJsonDocument::fromJson(config.toUtf8()).object(); auto configJson = QJsonDocument::fromJson(config.toUtf8()).object();
QStringList lines = configJson.value(config_key::config).toString().replace("\r", "").split("\n"); QStringList lines = configJson.value(config_key::config).toString().replace("\r", "").split("\n");
for (const QString &line : lines) { for (const QString &line : lines) {
m_formattedConfig.append(line + "\n"); m_config.append(line + "\n");
} }
emit exportConfigChanged(); emit exportConfigChanged();
@ -154,20 +150,18 @@ void ExportController::generateWireGuardConfig()
} }
config = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::WireGuard, config); config = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::WireGuard, config);
m_rawConfig = config;
auto configJson = QJsonDocument::fromJson(config.toUtf8()).object(); auto configJson = QJsonDocument::fromJson(config.toUtf8()).object();
QStringList lines = configJson.value(config_key::config).toString().replace("\r", "").split("\n"); QStringList lines = configJson.value(config_key::config).toString().replace("\r", "").split("\n");
for (const QString &line : lines) { for (const QString &line : lines) {
m_formattedConfig.append(line + "\n"); m_config.append(line + "\n");
} }
emit exportConfigChanged(); emit exportConfigChanged();
} }
QString ExportController::getFormattedConfig() QString ExportController::getConfig()
{ {
return m_formattedConfig; return m_config;
} }
QList<QString> ExportController::getQrCodes() QList<QString> ExportController::getQrCodes()
@ -193,7 +187,7 @@ void ExportController::saveFile()
QFile save(fileName.toLocalFile()); QFile save(fileName.toLocalFile());
save.open(QIODevice::WriteOnly); save.open(QIODevice::WriteOnly);
save.write(m_rawConfig.toUtf8()); save.write(m_config.toUtf8());
save.close(); save.close();
QFileInfo fi(fileName.toLocalFile()); QFileInfo fi(fileName.toLocalFile());
@ -233,7 +227,6 @@ int ExportController::getQrCodesCount()
void ExportController::clearPreviousConfig() void ExportController::clearPreviousConfig()
{ {
m_rawConfig.clear(); m_config.clear();
m_formattedConfig.clear();
m_qrCodes.clear(); m_qrCodes.clear();
} }

View file

@ -18,7 +18,7 @@ public:
Q_PROPERTY(QList<QString> qrCodes READ getQrCodes NOTIFY exportConfigChanged) Q_PROPERTY(QList<QString> qrCodes READ getQrCodes NOTIFY exportConfigChanged)
Q_PROPERTY(int qrCodesCount READ getQrCodesCount 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: public slots:
void generateFullAccessConfig(); void generateFullAccessConfig();
@ -26,7 +26,7 @@ public slots:
void generateOpenVpnConfig(); void generateOpenVpnConfig();
void generateWireGuardConfig(); void generateWireGuardConfig();
QString getFormattedConfig(); QString getConfig();
QList<QString> getQrCodes(); QList<QString> getQrCodes();
void saveFile(); void saveFile();
@ -50,8 +50,7 @@ private:
std::shared_ptr<Settings> m_settings; std::shared_ptr<Settings> m_settings;
std::shared_ptr<VpnConfigurator> m_configurator; std::shared_ptr<VpnConfigurator> m_configurator;
QString m_rawConfig; QString m_config;
QString m_formattedConfig;
QList<QString> m_qrCodes; QList<QString> m_qrCodes;
}; };

View file

@ -42,7 +42,8 @@ namespace PageLoader
PageProtocolShadowSocksSettings, PageProtocolShadowSocksSettings,
PageProtocolCloakSettings, PageProtocolCloakSettings,
PageProtocolWireGuardSettings, PageProtocolWireGuardSettings,
PageProtocolIKev2Settings PageProtocolIKev2Settings,
PageProtocolRaw
}; };
Q_ENUM_NS(PageEnum) Q_ENUM_NS(PageEnum)
@ -70,6 +71,7 @@ signals:
void showErrorMessage(QString errorMessage); void showErrorMessage(QString errorMessage);
void showInfoMessage(QString message); void showInfoMessage(QString message);
void showBusyIndicator(bool visible); void showBusyIndicator(bool visible);
void raise();
private: private:
QSharedPointer<ServersModel> m_serversModel; QSharedPointer<ServersModel> m_serversModel;

View file

@ -17,6 +17,7 @@ QHash<int, QByteArray> ProtocolsModel::roleNames() const
roles[ProtocolNameRole] = "protocolName"; roles[ProtocolNameRole] = "protocolName";
roles[ProtocolPageRole] = "protocolPage"; roles[ProtocolPageRole] = "protocolPage";
roles[RawConfigRole] = "rawConfig";
return roles; return roles;
} }
@ -34,6 +35,19 @@ QVariant ProtocolsModel::data(const QModelIndex &index, int role) const
} }
case ProtocolPageRole: case ProtocolPageRole:
return static_cast<int>(protocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row())))); return static_cast<int>(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(); return QVariant();

View file

@ -13,7 +13,8 @@ class ProtocolsModel : public QAbstractListModel
public: public:
enum Roles { enum Roles {
ProtocolNameRole = Qt::UserRole + 1, ProtocolNameRole = Qt::UserRole + 1,
ProtocolPageRole ProtocolPageRole,
RawConfigRole
}; };
ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr); ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);

View file

@ -7,6 +7,7 @@ import SortFilterProxyModel 0.2
import PageEnum 1.0 import PageEnum 1.0
import ProtocolEnum 1.0 import ProtocolEnum 1.0
import ContainerEnum 1.0 import ContainerEnum 1.0
import ContainerProps 1.0
import "../Controls2" import "../Controls2"
import "../Controls2/TextTypes" import "../Controls2/TextTypes"
@ -91,19 +92,25 @@ ListView {
if (isInstalled) { if (isInstalled) {
var containerIndex = root.model.mapToSource(index) var containerIndex = root.model.mapToSource(index)
ContainersModel.setCurrentlyProcessedContainerIndex(containerIndex) ContainersModel.setCurrentlyProcessedContainerIndex(containerIndex)
if (config[ContainerProps.containerTypeToString(containerIndex)]["isThirdPartyConfig"]) {
ProtocolsModel.updateModel(config)
goToPage(PageEnum.PageProtocolRaw)
return
}
switch (containerIndex) { switch (containerIndex) {
case ContainerEnum.OpenVpn: { case ContainerEnum.OpenVpn: {
OpenVpnConfigModel.updateModel(ProtocolsModel.getConfig()) OpenVpnConfigModel.updateModel(config)
goToPage(PageEnum.PageProtocolOpenVpnSettings) goToPage(PageEnum.PageProtocolOpenVpnSettings)
break break
} }
case ContainerEnum.WireGuard: { case ContainerEnum.WireGuard: {
WireGuardConfigModel.updateModel(ProtocolsModel.getConfig()) WireGuardConfigModel.updateModel(config)
goToPage(PageEnum.PageProtocolWireGuardSettings) goToPage(PageEnum.PageProtocolWireGuardSettings)
break break
} }
case ContainerEnum.Ipsec: { case ContainerEnum.Ipsec: {
Ikev2ConfigModel.updateModel(ProtocolsModel.getConfig()) Ikev2ConfigModel.updateModel(config)
goToPage(PageEnum.PageProtocolIKev2Settings) goToPage(PageEnum.PageProtocolIKev2Settings)
break break
} }

View file

@ -156,7 +156,7 @@ DrawerType {
font.weight: Font.Medium font.weight: Font.Medium
font.family: "PT Root UI VF" font.family: "PT Root UI VF"
text: ExportController.formattedConfig text: ExportController.config
wrapMode: Text.Wrap wrapMode: Text.Wrap

View file

@ -102,7 +102,7 @@ PageType {
description += "Amnezia DNS | " description += "Amnezia DNS | "
} }
} else { } else {
if (ServersModel.isDefaultServerConfigContainsAmneziaDns) { if (ServersModel.isDefaultServerConfigContainsAmneziaDns()) {
description += "Amnezia DNS | " description += "Amnezia DNS | "
} }
} }

View file

@ -53,6 +53,8 @@ PageType {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
enabled: ServersModel.isCurrentlyProcessedServerHasWriteAccess()
ListView { ListView {
id: listview id: listview

View file

@ -54,6 +54,8 @@ PageType {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
enabled: ServersModel.isCurrentlyProcessedServerHasWriteAccess()
ListView { ListView {
id: listview id: listview

View file

@ -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 {}
}
}
}

View file

@ -53,6 +53,8 @@ PageType {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
enabled: ServersModel.isCurrentlyProcessedServerHasWriteAccess()
ListView { ListView {
id: listview id: listview

View file

@ -48,5 +48,11 @@ Window {
} }
rootStackView.replace(pagePath, { "objectName" : pagePath }) rootStackView.replace(pagePath, { "objectName" : pagePath })
} }
function onRaise() {
root.show()
root.raise()
root.requestActivate()
}
} }
} }