Check openvpn config for scripts
QML refactoring
This commit is contained in:
parent
7c749a964c
commit
3a5a7bf674
19 changed files with 367 additions and 121 deletions
|
@ -24,7 +24,7 @@ enum class Page {Start = 0, NewServer, NewServerProtocols, Vpn,
|
|||
Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress,
|
||||
GeneralSettings, AppSettings, NetworkSettings, ServerSettings,
|
||||
ServerContainers, ServersList, ShareConnection, Sites,
|
||||
ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About};
|
||||
ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig};
|
||||
Q_ENUM_NS(Page)
|
||||
|
||||
static void declareQmlPageEnum() {
|
||||
|
|
|
@ -34,6 +34,6 @@ void GeneralSettingsLogic::onPushButtonGeneralSettingsShareConnectionClicked()
|
|||
qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel())->setSelectedServerIndex(uiLogic()->selectedServerIndex);
|
||||
qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel())->setSelectedDockerContainer(uiLogic()->selectedDockerContainer);
|
||||
|
||||
uiLogic()->shareConnectionLogic()->updateSharingPage(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
emit uiLogic()->goToPage(Page::ShareConnection);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ void QrDecoderLogic::onDetectedQrCode(const QString &code)
|
|||
data.append(m_chunks.value(i));
|
||||
}
|
||||
|
||||
bool ok = uiLogic()->startPageLogic()->importConnectionFromQr(data);
|
||||
bool ok = uiLogic()->pageLogic<StartPageLogic>()->importConnectionFromQr(data);
|
||||
if (ok) {
|
||||
set_detectingEnabled(false);
|
||||
emit stopDecode();
|
||||
|
@ -67,7 +67,7 @@ void QrDecoderLogic::onDetectedQrCode(const QString &code)
|
|||
}
|
||||
}
|
||||
else {
|
||||
bool ok = uiLogic()->startPageLogic()->importConnectionFromQr(ba);
|
||||
bool ok = uiLogic()->pageLogic<StartPageLogic>()->importConnectionFromQr(ba);
|
||||
if (ok) {
|
||||
set_detectingEnabled(false);
|
||||
emit stopDecode();
|
||||
|
|
|
@ -54,13 +54,13 @@ void ServerContainersLogic::onPushButtonDefaultClicked(DockerContainer c)
|
|||
if (!uiLogic()->m_vpnConnection) return;
|
||||
if (!uiLogic()->m_vpnConnection->isConnected()) return;
|
||||
|
||||
uiLogic()->vpnLogic()->onDisconnect();
|
||||
uiLogic()->vpnLogic()->onConnect();
|
||||
uiLogic()->pageLogic<VpnLogic>()->onDisconnect();
|
||||
uiLogic()->pageLogic<VpnLogic>()->onConnect();
|
||||
}
|
||||
|
||||
void ServerContainersLogic::onPushButtonShareClicked(DockerContainer c)
|
||||
{
|
||||
uiLogic()->shareConnectionLogic()->updateSharingPage(uiLogic()->selectedServerIndex, c);
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->selectedServerIndex, c);
|
||||
emit uiLogic()->goToPage(Page::ShareConnection);
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int p
|
|||
emit uiLogic()->goToPage(Page::ServerConfiguringProgress);
|
||||
qApp->processEvents();
|
||||
|
||||
ErrorCode e = uiLogic()->serverConfiguringProgressLogic()->doInstallAction([this, c, &config](){
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, c, &config](){
|
||||
return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), c, config);
|
||||
});
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ void ServerSettingsLogic::onPushButtonClearServer()
|
|||
set_pushButtonClearText(tr("Uninstalling Amnezia software..."));
|
||||
|
||||
if (m_settings->defaultServerIndex() == uiLogic()->selectedServerIndex) {
|
||||
uiLogic()->vpnLogic()->onDisconnect();
|
||||
uiLogic()->pageLogic<VpnLogic>()->onDisconnect();
|
||||
}
|
||||
|
||||
ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->selectedServerIndex));
|
||||
|
@ -76,7 +76,7 @@ void ServerSettingsLogic::onPushButtonClearServer()
|
|||
void ServerSettingsLogic::onPushButtonForgetServer()
|
||||
{
|
||||
if (m_settings->defaultServerIndex() == uiLogic()->selectedServerIndex && uiLogic()->m_vpnConnection->isConnected()) {
|
||||
uiLogic()->vpnLogic()->onDisconnect();
|
||||
uiLogic()->pageLogic<VpnLogic>()->onDisconnect();
|
||||
}
|
||||
m_settings->removeServer(uiLogic()->selectedServerIndex);
|
||||
|
||||
|
@ -128,6 +128,6 @@ void ServerSettingsLogic::onLineEditDescriptionEditingFinished()
|
|||
|
||||
void ServerSettingsLogic::onPushButtonShareFullClicked()
|
||||
{
|
||||
uiLogic()->shareConnectionLogic()->updateSharingPage(uiLogic()->selectedServerIndex, DockerContainer::None);
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->selectedServerIndex, DockerContainer::None);
|
||||
emit uiLogic()->goToShareProtocolPage(Proto::Any);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ void SitesLogic::onUpdatePage()
|
|||
|
||||
void SitesLogic::onPushButtonAddCustomSitesClicked()
|
||||
{
|
||||
if (uiLogic()->vpnLogic()->radioButtonVpnModeAllSitesChecked()) {
|
||||
if (uiLogic()->pageLogic<VpnLogic>()->radioButtonVpnModeAllSitesChecked()) {
|
||||
return;
|
||||
}
|
||||
Settings::RouteMode mode = m_settings->routeMode();
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "StartPageLogic.h"
|
||||
#include "ViewConfigLogic.h"
|
||||
|
||||
#include "core/errorstrings.h"
|
||||
#include "configurators/ssh_configurator.h"
|
||||
#include "configurators/vpn_configurator.h"
|
||||
|
@ -17,13 +19,7 @@ StartPageLogic::StartPageLogic(UiLogic *logic, QObject *parent):
|
|||
m_pushButtonConnectEnabled{true},
|
||||
m_pushButtonConnectText{tr("Connect")},
|
||||
m_pushButtonConnectKeyChecked{false},
|
||||
m_lineEditStartExistingCodeText{},
|
||||
m_textEditSshKeyText{},
|
||||
m_lineEditIpText{},
|
||||
m_lineEditPasswordText{},
|
||||
m_lineEditLoginText{},
|
||||
m_labelWaitInfoVisible{true},
|
||||
m_labelWaitInfoText{},
|
||||
m_pushButtonBackFromStartVisible{true},
|
||||
m_ipAddressPortRegex{Utils::ipAddressPortRegExp()}
|
||||
{
|
||||
|
@ -150,11 +146,9 @@ bool StartPageLogic::importConnection(const QJsonObject &profile)
|
|||
credentials.password = profile.value(config_key::password).toString();
|
||||
|
||||
if (credentials.isValid() || profile.contains(config_key::containers)) {
|
||||
m_settings->addServer(profile);
|
||||
m_settings->setDefaultServer(m_settings->serversCount() - 1);
|
||||
|
||||
emit uiLogic()->goToPage(Page::Vpn);
|
||||
emit uiLogic()->setStartPage(Page::Vpn);
|
||||
// check config
|
||||
uiLogic()->pageLogic<ViewConfigLogic>()->set_configJson(profile);
|
||||
emit uiLogic()->goToPage(Page::ViewConfig);
|
||||
}
|
||||
else {
|
||||
qDebug() << "Failed to import profile";
|
||||
|
|
67
client/ui/pages_logic/ViewConfigLogic.cpp
Normal file
67
client/ui/pages_logic/ViewConfigLogic.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "ViewConfigLogic.h"
|
||||
#include "core/errorstrings.h"
|
||||
#include "../uilogic.h"
|
||||
|
||||
|
||||
ViewConfigLogic::ViewConfigLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ViewConfigLogic::onUpdatePage()
|
||||
{
|
||||
set_configText(QJsonDocument(configJson()).toJson());
|
||||
|
||||
m_openVpnLastConfigs = m_openVpnMalStrings =
|
||||
"<style> \
|
||||
div { line-height: 0.5; } \
|
||||
</style><div>";
|
||||
|
||||
m_warningStringNumber = 3;
|
||||
m_warningActive = false;
|
||||
|
||||
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;
|
||||
}
|
||||
else {
|
||||
m_openVpnLastConfigs.append("<p>" + l + " \n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit openVpnLastConfigsChanged(m_openVpnLastConfigs);
|
||||
emit openVpnMalStringsChanged(m_openVpnMalStrings);
|
||||
emit warningStringNumberChanged(m_warningStringNumber);
|
||||
emit warningActiveChanged(m_warningActive);
|
||||
}
|
||||
|
||||
void ViewConfigLogic::importConfig()
|
||||
{
|
||||
m_settings->addServer(configJson());
|
||||
m_settings->setDefaultServer(m_settings->serversCount() - 1);
|
||||
|
||||
emit uiLogic()->goToPage(Page::Vpn);
|
||||
emit uiLogic()->setStartPage(Page::Vpn);
|
||||
}
|
||||
|
47
client/ui/pages_logic/ViewConfigLogic.h
Normal file
47
client/ui/pages_logic/ViewConfigLogic.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef VIEW_CONFIG_LOGIC_H
|
||||
#define VIEW_CONFIG_LOGIC_H
|
||||
|
||||
#include "PageLogicBase.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
|
||||
class UiLogic;
|
||||
|
||||
class ViewConfigLogic : public PageLogicBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
AUTO_PROPERTY(QString, configText)
|
||||
AUTO_PROPERTY(QString, openVpnLastConfigs)
|
||||
AUTO_PROPERTY(QString, openVpnMalStrings)
|
||||
AUTO_PROPERTY(QJsonObject, configJson)
|
||||
AUTO_PROPERTY(int, warningStringNumber)
|
||||
AUTO_PROPERTY(bool, warningActive)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE void onUpdatePage() override;
|
||||
Q_INVOKABLE void importConfig();
|
||||
|
||||
|
||||
public:
|
||||
explicit ViewConfigLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~ViewConfigLogic() = default;
|
||||
|
||||
private:
|
||||
QRegularExpression m_re {"(\\w+-\\w+|\\w+)"};
|
||||
|
||||
// https://github.com/OpenVPN/openvpn/blob/master/doc/man-sections/script-options.rst
|
||||
QStringList dangerousTags {
|
||||
"up",
|
||||
"tls-verify",
|
||||
"ipchange",
|
||||
"client-connect",
|
||||
"route-up",
|
||||
"route-pre-down",
|
||||
"client-disconnect",
|
||||
"down",
|
||||
"learn-address",
|
||||
"auth-user-pass-verify"
|
||||
};
|
||||
};
|
||||
#endif // VIEW_CONFIG_LOGIC_H
|
|
@ -59,7 +59,7 @@ PageBase {
|
|||
text: qsTr("Share for Amnezia")
|
||||
height: 40
|
||||
width: tb_c.width - 10
|
||||
onClicked: UiLogic.onGotoShareProtocolPage(ProtocolEnum.Any)
|
||||
onClicked: UiLogic.goToShareProtocolPage(ProtocolEnum.Any)
|
||||
}
|
||||
|
||||
ListView {
|
||||
|
@ -82,7 +82,7 @@ PageBase {
|
|||
text: qsTr("Share for ") + name_role
|
||||
height: 40
|
||||
width: tb_c.width - 10
|
||||
onClicked: UiLogic.onGotoShareProtocolPage(proxyProtocolsModel.mapToSource(index))
|
||||
onClicked: UiLogic.goToShareProtocolPage(proxyProtocolsModel.mapToSource(index))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
148
client/ui/qml/Pages/PageViewConfig.qml
Normal file
148
client/ui/qml/Pages/PageViewConfig.qml
Normal file
|
@ -0,0 +1,148 @@
|
|||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.15
|
||||
import PageEnum 1.0
|
||||
import "./"
|
||||
import "../Controls"
|
||||
import "../Config"
|
||||
|
||||
PageBase {
|
||||
id: root
|
||||
page: PageEnum.ViewConfig
|
||||
logic: ViewConfigLogic
|
||||
|
||||
readonly property double rowHeight: ta_last_config.contentHeight / ta_last_config.textArea.lineCount
|
||||
|
||||
BackButton {}
|
||||
|
||||
Caption {
|
||||
id: caption
|
||||
text: qsTr("Check config")
|
||||
}
|
||||
|
||||
Flickable {
|
||||
id: fl
|
||||
width: root.width
|
||||
anchors.top: caption.bottom
|
||||
anchors.topMargin: 20
|
||||
anchors.bottom: root.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
|
||||
enabled: logic.pageEnabled
|
||||
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: ViewConfigLogic.warningActive ? 250 : fl.height - 70
|
||||
flickableDirection: Flickable.AutoFlickIfNeeded
|
||||
|
||||
textArea.readOnly: true
|
||||
textArea.text: logic.configText
|
||||
}
|
||||
|
||||
LabelType {
|
||||
id: lb_att
|
||||
visible: ViewConfigLogic.warningActive
|
||||
text: qsTr("Attention!
|
||||
The config above contains cached OpenVPN connection profile.
|
||||
AmneziaVPN detected this profile may contain malicious scripts. Please, carefully review the config and import this config only if you completely trust it.")
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
LabelType {
|
||||
visible: ViewConfigLogic.warningActive
|
||||
text: qsTr("Suspicious string:")
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
TextAreaType {
|
||||
id: ta_mal
|
||||
visible: ViewConfigLogic.warningActive
|
||||
|
||||
Layout.topMargin: 5
|
||||
Layout.bottomMargin: 20
|
||||
Layout.fillWidth: true
|
||||
Layout.leftMargin: 1
|
||||
Layout.rightMargin: 1
|
||||
Layout.preferredHeight: 60
|
||||
flickableDirection: Flickable.AutoFlickIfNeeded
|
||||
|
||||
textArea.readOnly: true
|
||||
textArea.text: logic.openVpnMalStrings
|
||||
textArea.textFormat: TextEdit.RichText
|
||||
}
|
||||
|
||||
LabelType {
|
||||
visible: ViewConfigLogic.warningActive
|
||||
text: qsTr("Cached connection profile:")
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
TextAreaType {
|
||||
id: ta_last_config
|
||||
visible: ViewConfigLogic.warningActive
|
||||
|
||||
Layout.topMargin: 5
|
||||
Layout.bottomMargin: 20
|
||||
Layout.fillWidth: true
|
||||
Layout.leftMargin: 1
|
||||
Layout.rightMargin: 1
|
||||
Layout.preferredHeight: 350
|
||||
flickableDirection: Flickable.AutoFlickIfNeeded
|
||||
|
||||
textArea.readOnly: true
|
||||
textArea.text: logic.openVpnLastConfigs
|
||||
textArea.textFormat: TextEdit.RichText
|
||||
|
||||
Connections {
|
||||
target: logic
|
||||
function onWarningStringNumberChanged(n) {
|
||||
ta_last_config.contentY = rowHeight * n - ta_last_config.height / 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: btns_row
|
||||
|
||||
BasicButtonType {
|
||||
Layout.preferredWidth: (content.width - parent.spacing) /2
|
||||
Layout.preferredHeight: 41
|
||||
font.pixelSize: btn_import.font.pixelSize
|
||||
text: qsTr("Cancel")
|
||||
onClicked: {
|
||||
UiLogic.closePage()
|
||||
}
|
||||
}
|
||||
|
||||
BlueButtonType {
|
||||
id: btn_import
|
||||
Layout.preferredWidth: (content.width - parent.spacing) /2
|
||||
Layout.preferredHeight: 41
|
||||
text: qsTr("Import config")
|
||||
onClicked: {
|
||||
logic.importConfig()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,6 @@
|
|||
#include <QDesktopServices>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHostInfo>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QJsonDocument>
|
||||
|
@ -16,8 +15,10 @@
|
|||
#include <QSysInfo>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QRegularExpression>
|
||||
#include <QQmlFile>
|
||||
#include <QMetaObject>
|
||||
|
||||
#include "amnezia_application.h"
|
||||
|
||||
#include "configurators/cloak_configurator.h"
|
||||
#include "configurators/vpn_configurator.h"
|
||||
|
@ -62,6 +63,7 @@
|
|||
#include "pages_logic/ShareConnectionLogic.h"
|
||||
#include "pages_logic/SitesLogic.h"
|
||||
#include "pages_logic/StartPageLogic.h"
|
||||
#include "pages_logic/ViewConfigLogic.h"
|
||||
#include "pages_logic/VpnLogic.h"
|
||||
#include "pages_logic/WizardLogic.h"
|
||||
|
||||
|
@ -88,20 +90,6 @@ UiLogic::UiLogic(std::shared_ptr<Settings> settings, std::shared_ptr<VpnConfigur
|
|||
m_vpnConnection->moveToThread(&m_vpnConnectionThread);
|
||||
m_vpnConnectionThread.start();
|
||||
|
||||
m_appSettingsLogic = new AppSettingsLogic(this);
|
||||
m_generalSettingsLogic = new GeneralSettingsLogic(this);
|
||||
m_networkSettingsLogic = new NetworkSettingsLogic(this);
|
||||
m_newServerProtocolsLogic = new NewServerProtocolsLogic(this);
|
||||
m_qrDecoderLogic = new QrDecoderLogic(this);
|
||||
m_serverConfiguringProgressLogic = new ServerConfiguringProgressLogic(this);
|
||||
m_serverListLogic = new ServerListLogic(this);
|
||||
m_serverSettingsLogic = new ServerSettingsLogic(this);
|
||||
m_serverprotocolsLogic = new ServerContainersLogic(this);
|
||||
m_shareConnectionLogic = new ShareConnectionLogic(this);
|
||||
m_sitesLogic = new SitesLogic(this);
|
||||
m_startPageLogic = new StartPageLogic(this);
|
||||
m_vpnLogic = new VpnLogic(this);
|
||||
m_wizardLogic = new WizardLogic(this);
|
||||
|
||||
m_protocolLogicMap.insert(Proto::OpenVpn, new OpenVpnLogic(this));
|
||||
m_protocolLogicMap.insert(Proto::ShadowSocks, new ShadowSocksLogic(this));
|
||||
|
@ -143,7 +131,7 @@ void UiLogic::initalizeUiLogic()
|
|||
#ifdef Q_OS_ANDROID
|
||||
connect(AndroidController::instance(), &AndroidController::initialized, [this](bool status, bool connected, const QDateTime& connectionDate) {
|
||||
if (connected) {
|
||||
vpnLogic()->onConnectionStateChanged(VpnProtocol::Connected);
|
||||
pageLogic<VpnLogic>()->onConnectionStateChanged(VpnProtocol::Connected);
|
||||
}
|
||||
});
|
||||
if (!AndroidController::instance()->initialize()) {
|
||||
|
@ -157,8 +145,8 @@ void UiLogic::initalizeUiLogic()
|
|||
|
||||
connect(m_vpnConnection, &VpnConnection::connectionStateChanged, m_notificationHandler, &NotificationHandler::setConnectionState);
|
||||
connect(m_notificationHandler, &NotificationHandler::raiseRequested, this, &UiLogic::raise);
|
||||
connect(m_notificationHandler, &NotificationHandler::connectRequested, vpnLogic(), &VpnLogic::onConnect);
|
||||
connect(m_notificationHandler, &NotificationHandler::disconnectRequested, vpnLogic(), &VpnLogic::onDisconnect);
|
||||
connect(m_notificationHandler, &NotificationHandler::connectRequested, pageLogic<VpnLogic>(), &VpnLogic::onConnect);
|
||||
connect(m_notificationHandler, &NotificationHandler::disconnectRequested, pageLogic<VpnLogic>(), &VpnLogic::onDisconnect);
|
||||
|
||||
if (m_settings->serversCount() > 0) {
|
||||
if (m_settings->defaultServerIndex() < 0) m_settings->setDefaultServer(0);
|
||||
|
@ -190,21 +178,7 @@ void UiLogic::showOnStartup()
|
|||
|
||||
void UiLogic::onUpdateAllPages()
|
||||
{
|
||||
for (PageLogicBase *logic : {
|
||||
(PageLogicBase *) m_appSettingsLogic,
|
||||
(PageLogicBase *) m_generalSettingsLogic,
|
||||
(PageLogicBase *) m_networkSettingsLogic,
|
||||
(PageLogicBase *) m_serverConfiguringProgressLogic,
|
||||
(PageLogicBase *) m_newServerProtocolsLogic,
|
||||
(PageLogicBase *) m_serverListLogic,
|
||||
(PageLogicBase *) m_serverSettingsLogic,
|
||||
(PageLogicBase *) m_serverprotocolsLogic,
|
||||
(PageLogicBase *) m_shareConnectionLogic,
|
||||
(PageLogicBase *) m_sitesLogic,
|
||||
(PageLogicBase *) m_startPageLogic,
|
||||
(PageLogicBase *) m_vpnLogic,
|
||||
(PageLogicBase *) m_wizardLogic
|
||||
}) {
|
||||
for (auto logic : m_logicMap) {
|
||||
logic->onUpdatePage();
|
||||
}
|
||||
}
|
||||
|
@ -332,34 +306,34 @@ void UiLogic::installServer(QMap<DockerContainer, QJsonObject> &containers)
|
|||
|
||||
PageFunc page_new_server_configuring;
|
||||
page_new_server_configuring.setEnabledFunc = [this] (bool enabled) -> void {
|
||||
serverConfiguringProgressLogic()->set_pageEnabled(enabled);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_pageEnabled(enabled);
|
||||
};
|
||||
ButtonFunc no_button;
|
||||
LabelFunc label_new_server_configuring_wait_info;
|
||||
label_new_server_configuring_wait_info.setTextFunc = [this] (const QString& text) -> void {
|
||||
serverConfiguringProgressLogic()->set_labelWaitInfoText(text);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_labelWaitInfoText(text);
|
||||
};
|
||||
label_new_server_configuring_wait_info.setVisibleFunc = [this] (bool visible) ->void {
|
||||
serverConfiguringProgressLogic()->set_labelWaitInfoVisible(visible);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_labelWaitInfoVisible(visible);
|
||||
};
|
||||
ProgressFunc progressBar_new_server_configuring;
|
||||
progressBar_new_server_configuring.setVisibleFunc = [this] (bool visible) ->void {
|
||||
serverConfiguringProgressLogic()->set_progressBarVisible(visible);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_progressBarVisible(visible);
|
||||
};
|
||||
progressBar_new_server_configuring.setValueFunc = [this] (int value) ->void {
|
||||
serverConfiguringProgressLogic()->set_progressBarValue(value);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_progressBarValue(value);
|
||||
};
|
||||
progressBar_new_server_configuring.getValueFunc = [this] (void) -> int {
|
||||
return serverConfiguringProgressLogic()->progressBarValue();
|
||||
return pageLogic<ServerConfiguringProgressLogic>()->progressBarValue();
|
||||
};
|
||||
progressBar_new_server_configuring.getMaximiumFunc = [this] (void) -> int {
|
||||
return serverConfiguringProgressLogic()->progressBarMaximium();
|
||||
return pageLogic<ServerConfiguringProgressLogic>()->progressBarMaximium();
|
||||
};
|
||||
progressBar_new_server_configuring.setTextVisibleFunc = [this] (bool visible) ->void {
|
||||
serverConfiguringProgressLogic()->set_progressBarTextVisible(visible);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_progressBarTextVisible(visible);
|
||||
};
|
||||
progressBar_new_server_configuring.setTextFunc = [this] (const QString& text) ->void {
|
||||
serverConfiguringProgressLogic()->set_progressBarText(text);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_progressBarText(text);
|
||||
};
|
||||
bool ok = installContainers(installCredentials, containers,
|
||||
page_new_server_configuring,
|
||||
|
@ -595,6 +569,11 @@ NotificationHandler *UiLogic::notificationHandler() const
|
|||
return m_notificationHandler;
|
||||
}
|
||||
|
||||
void UiLogic::setQmlContextProperty(PageLogicBase *logic)
|
||||
{
|
||||
amnApp->qmlEngine()->rootContext()->setContextProperty(logic->metaObject()->className(), logic);
|
||||
}
|
||||
|
||||
PageEnumNS::Page UiLogic::currentPage()
|
||||
{
|
||||
return static_cast<PageEnumNS::Page>(currentPageValue());
|
||||
|
@ -677,3 +656,24 @@ void UiLogic::shareTempFile(const QString &suggestedName, QString ext, const QSt
|
|||
filesToSend.append(fileName);
|
||||
MobileUtils::shareText(filesToSend);
|
||||
}
|
||||
|
||||
void UiLogic::registerPagesLogic()
|
||||
{
|
||||
amnApp->qmlEngine()->rootContext()->setContextProperty("UiLogic", this);
|
||||
|
||||
registerPageLogic<AppSettingsLogic>();
|
||||
registerPageLogic<GeneralSettingsLogic>();
|
||||
registerPageLogic<NetworkSettingsLogic>();
|
||||
registerPageLogic<NewServerProtocolsLogic>();
|
||||
registerPageLogic<QrDecoderLogic>();
|
||||
registerPageLogic<ServerConfiguringProgressLogic>();
|
||||
registerPageLogic<ServerListLogic>();
|
||||
registerPageLogic<ServerSettingsLogic>();
|
||||
registerPageLogic<ServerContainersLogic>();
|
||||
registerPageLogic<ShareConnectionLogic>();
|
||||
registerPageLogic<SitesLogic>();
|
||||
registerPageLogic<StartPageLogic>();
|
||||
registerPageLogic<ViewConfigLogic>();
|
||||
registerPageLogic<VpnLogic>();
|
||||
registerPageLogic<WizardLogic>();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#include <QKeyEvent>
|
||||
#include <QThread>
|
||||
|
||||
#include <typeindex>
|
||||
#include <typeinfo>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "property_helper.h"
|
||||
#include "pages.h"
|
||||
#include "protocols/vpnprotocol.h"
|
||||
|
@ -21,6 +25,8 @@ class Settings;
|
|||
class VpnConfigurator;
|
||||
class ServerController;
|
||||
|
||||
class PageLogicBase;
|
||||
|
||||
class AppSettingsLogic;
|
||||
class GeneralSettingsLogic;
|
||||
class NetworkSettingsLogic;
|
||||
|
@ -33,6 +39,7 @@ class ServerContainersLogic;
|
|||
class ShareConnectionLogic;
|
||||
class SitesLogic;
|
||||
class StartPageLogic;
|
||||
class ViewConfigLogic;
|
||||
class VpnLogic;
|
||||
class WizardLogic;
|
||||
|
||||
|
@ -77,6 +84,7 @@ public:
|
|||
friend class ShareConnectionLogic;
|
||||
friend class SitesLogic;
|
||||
friend class StartPageLogic;
|
||||
friend class ViewConfigLogic;
|
||||
friend class VpnLogic;
|
||||
friend class WizardLogic;
|
||||
|
||||
|
@ -96,10 +104,6 @@ public:
|
|||
Q_INVOKABLE QString containerName(int container);
|
||||
Q_INVOKABLE QString containerDesc(int container);
|
||||
|
||||
Q_INVOKABLE void onGotoPage(PageEnumNS::Page p, bool reset = true, bool slide = true) { emit goToPage(p, reset, slide); }
|
||||
Q_INVOKABLE void onGotoProtocolPage(Proto p, bool reset = true, bool slide = true) { emit goToProtocolPage(p, reset, slide); }
|
||||
Q_INVOKABLE void onGotoShareProtocolPage(Proto p, bool reset = true, bool slide = true) { emit goToShareProtocolPage(p, reset, slide); }
|
||||
|
||||
Q_INVOKABLE void onGotoCurrentProtocolsPage();
|
||||
|
||||
Q_INVOKABLE void keyPressEvent(Qt::Key key);
|
||||
|
@ -166,21 +170,6 @@ private:
|
|||
|
||||
|
||||
public:
|
||||
AppSettingsLogic *appSettingsLogic() { return m_appSettingsLogic; }
|
||||
GeneralSettingsLogic *generalSettingsLogic() { return m_generalSettingsLogic; }
|
||||
NetworkSettingsLogic *networkSettingsLogic() { return m_networkSettingsLogic; }
|
||||
NewServerProtocolsLogic *newServerProtocolsLogic() { return m_newServerProtocolsLogic; }
|
||||
QrDecoderLogic *qrDecoderLogic() { return m_qrDecoderLogic; }
|
||||
ServerConfiguringProgressLogic *serverConfiguringProgressLogic() { return m_serverConfiguringProgressLogic; }
|
||||
ServerListLogic *serverListLogic() { return m_serverListLogic; }
|
||||
ServerSettingsLogic *serverSettingsLogic() { return m_serverSettingsLogic; }
|
||||
ServerContainersLogic *serverprotocolsLogic() { return m_serverprotocolsLogic; }
|
||||
ShareConnectionLogic *shareConnectionLogic() { return m_shareConnectionLogic; }
|
||||
SitesLogic *sitesLogic() { return m_sitesLogic; }
|
||||
StartPageLogic *startPageLogic() { return m_startPageLogic; }
|
||||
VpnLogic *vpnLogic() { return m_vpnLogic; }
|
||||
WizardLogic *wizardLogic() { return m_wizardLogic; }
|
||||
|
||||
Q_INVOKABLE PageProtocolLogicBase *protocolLogic(Proto p);
|
||||
|
||||
QObject *qmlRoot() const;
|
||||
|
@ -188,23 +177,27 @@ public:
|
|||
|
||||
NotificationHandler *notificationHandler() const;
|
||||
|
||||
void setQmlContextProperty(PageLogicBase *logic);
|
||||
void registerPagesLogic();
|
||||
|
||||
template<typename T>
|
||||
void registerPageLogic()
|
||||
{
|
||||
T* logic = new T(this);
|
||||
m_logicMap[std::type_index(typeid(T))] = logic;
|
||||
setQmlContextProperty(logic);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* pageLogic()
|
||||
{
|
||||
return static_cast<T *>(m_logicMap.value(std::type_index(typeid(T))));
|
||||
}
|
||||
|
||||
private:
|
||||
QObject *m_qmlRoot{nullptr};
|
||||
|
||||
AppSettingsLogic *m_appSettingsLogic;
|
||||
GeneralSettingsLogic *m_generalSettingsLogic;
|
||||
NetworkSettingsLogic *m_networkSettingsLogic;
|
||||
NewServerProtocolsLogic *m_newServerProtocolsLogic;
|
||||
QrDecoderLogic *m_qrDecoderLogic;
|
||||
ServerConfiguringProgressLogic *m_serverConfiguringProgressLogic;
|
||||
ServerListLogic *m_serverListLogic;
|
||||
ServerSettingsLogic *m_serverSettingsLogic;
|
||||
ServerContainersLogic *m_serverprotocolsLogic;
|
||||
ShareConnectionLogic *m_shareConnectionLogic;
|
||||
SitesLogic *m_sitesLogic;
|
||||
StartPageLogic *m_startPageLogic;
|
||||
VpnLogic *m_vpnLogic;
|
||||
WizardLogic *m_wizardLogic;
|
||||
QMap<std::type_index, PageLogicBase*> m_logicMap;
|
||||
|
||||
QMap<Proto, PageProtocolLogicBase *> m_protocolLogicMap;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue