added protocol settings pages and models for openvpn, cloak and shadowsocks
This commit is contained in:
parent
a97417fd38
commit
c13b9754eb
42 changed files with 2130 additions and 576 deletions
|
@ -29,6 +29,11 @@ bool ContainersModel::setData(const QModelIndex &index, const QVariant &value, i
|
|||
case ConfigRole: {
|
||||
m_settings->setContainerConfig(m_currentlyProcessedServerIndex, container, value.toJsonObject());
|
||||
m_containers = m_settings->containers(m_currentlyProcessedServerIndex);
|
||||
if (m_defaultContainerIndex != DockerContainer::None) {
|
||||
break;
|
||||
} else if (ContainerProps::containerService(container) == ServiceType::Other) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ServiceTypeRole:
|
||||
// return ContainerProps::containerService(container);
|
||||
|
@ -108,6 +113,11 @@ int ContainersModel::getCurrentlyProcessedContainerIndex()
|
|||
return m_currentlyProcessedContainerIndex;
|
||||
}
|
||||
|
||||
QString ContainersModel::getCurrentlyProcessedContainerName()
|
||||
{
|
||||
return ContainerProps::containerHumanNames().value(static_cast<DockerContainer>(m_currentlyProcessedContainerIndex));
|
||||
}
|
||||
|
||||
void ContainersModel::removeAllContainers()
|
||||
{
|
||||
|
||||
|
@ -116,14 +126,39 @@ void ContainersModel::removeAllContainers()
|
|||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
beginResetModel();
|
||||
|
||||
m_settings->setContainers(m_currentlyProcessedServerIndex, {});
|
||||
m_settings->setDefaultContainer(m_currentlyProcessedServerIndex, DockerContainer::None);
|
||||
m_containers = m_settings->containers(m_currentlyProcessedServerIndex);
|
||||
|
||||
setData(index(DockerContainer::None, 0), true, IsDefaultRole);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
// todo process errors
|
||||
}
|
||||
|
||||
void ContainersModel::removeCurrentlyProcessedContainer()
|
||||
{
|
||||
ServerController serverController(m_settings);
|
||||
auto credentials = m_settings->serverCredentials(m_currentlyProcessedServerIndex);
|
||||
auto dockerContainer = static_cast<DockerContainer>(m_currentlyProcessedContainerIndex);
|
||||
|
||||
ErrorCode e = serverController.removeContainer(credentials, dockerContainer);
|
||||
|
||||
beginResetModel(); // todo change to begin remove rows?
|
||||
m_settings->removeContainerConfig(m_currentlyProcessedServerIndex, dockerContainer);
|
||||
m_containers = m_settings->containers(m_currentlyProcessedServerIndex);
|
||||
|
||||
if (m_defaultContainerIndex == m_currentlyProcessedContainerIndex) {
|
||||
if (m_containers.isEmpty()) {
|
||||
setData(index(DockerContainer::None, 0), true, IsDefaultRole);
|
||||
} else {
|
||||
setData(index(m_containers.begin().key(), 0), true, IsDefaultRole);
|
||||
}
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ContainersModel::clearCachedProfiles()
|
||||
{
|
||||
const auto &containers = m_settings->containers(m_currentlyProcessedServerIndex);
|
||||
|
@ -150,6 +185,7 @@ QHash<int, QByteArray> ContainersModel::roleNames() const
|
|||
roles[DescRole] = "description";
|
||||
roles[ServiceTypeRole] = "serviceType";
|
||||
roles[DockerContainerRole] = "dockerContainer";
|
||||
roles[ConfigRole] = "config";
|
||||
|
||||
roles[IsEasySetupContainerRole] = "isEasySetupContainer";
|
||||
roles[EasySetupHeaderRole] = "easySetupHeader";
|
||||
|
|
|
@ -45,10 +45,14 @@ public slots:
|
|||
QString getDefaultContainerName();
|
||||
|
||||
void setCurrentlyProcessedServerIndex(const int index);
|
||||
|
||||
void setCurrentlyProcessedContainerIndex(int index);
|
||||
int getCurrentlyProcessedContainerIndex();
|
||||
|
||||
QString getCurrentlyProcessedContainerName();
|
||||
|
||||
void removeAllContainers();
|
||||
void removeCurrentlyProcessedContainer();
|
||||
void clearCachedProfiles();
|
||||
|
||||
bool isAmneziaDnsContainerInstalled();
|
||||
|
|
|
@ -22,14 +22,8 @@ QVariant LanguageModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
|
||||
switch (role) {
|
||||
case NameRole: {
|
||||
return m_availableLanguages[index.row()].name;
|
||||
break;
|
||||
}
|
||||
case IndexRole: {
|
||||
return static_cast<int>(m_availableLanguages[index.row()].index);
|
||||
break;
|
||||
}
|
||||
case NameRole: return m_availableLanguages[index.row()].name;
|
||||
case IndexRole: return static_cast<int>(m_availableLanguages[index.row()].index);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
|
81
client/ui/models/protocols/cloakConfigModel.cpp
Normal file
81
client/ui/models/protocols/cloakConfigModel.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include "cloakConfigModel.h"
|
||||
|
||||
#include "protocols/protocols_defs.h"
|
||||
|
||||
CloakConfigModel::CloakConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int CloakConfigModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool CloakConfigModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= ContainerProps::allContainers().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::PortRole: m_protocolConfig.insert(config_key::port, value.toString()); break;
|
||||
case Roles::CipherRole: m_protocolConfig.insert(config_key::cipher, value.toString()); break;
|
||||
case Roles::SiteRole: m_protocolConfig.insert(config_key::site, value.toString()); break;
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, QList { role });
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant CloakConfigModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= rowCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::PortRole: return m_protocolConfig.value(config_key::port).toString(protocols::cloak::defaultPort);
|
||||
case Roles::CipherRole: return m_protocolConfig.value(config_key::cipher).toString(protocols::cloak::defaultCipher);
|
||||
case Roles::SiteRole: return m_protocolConfig.value(config_key::site).toString(protocols::cloak::defaultRedirSite);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void CloakConfigModel::updateModel(const QJsonObject &config)
|
||||
{
|
||||
beginResetModel();
|
||||
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||
|
||||
m_fullConfig = config;
|
||||
QJsonObject protocolConfig = config.value(config_key::cloak).toObject();
|
||||
|
||||
m_protocolConfig.insert(config_key::cipher,
|
||||
protocolConfig.value(config_key::cipher).toString(protocols::cloak::defaultCipher));
|
||||
|
||||
m_protocolConfig.insert(config_key::port,
|
||||
protocolConfig.value(config_key::port).toString(protocols::cloak::defaultPort));
|
||||
|
||||
m_protocolConfig.insert(config_key::site,
|
||||
protocolConfig.value(config_key::site).toString(protocols::cloak::defaultRedirSite));
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QJsonObject CloakConfigModel::getConfig()
|
||||
{
|
||||
m_fullConfig.insert(config_key::cloak, m_protocolConfig);
|
||||
return m_fullConfig;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> CloakConfigModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
|
||||
roles[PortRole] = "port";
|
||||
roles[CipherRole] = "cipher";
|
||||
roles[SiteRole] = "site";
|
||||
|
||||
return roles;
|
||||
}
|
40
client/ui/models/protocols/cloakConfigModel.h
Normal file
40
client/ui/models/protocols/cloakConfigModel.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef CLOAKCONFIGMODEL_H
|
||||
#define CLOAKCONFIGMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
class CloakConfigModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Roles {
|
||||
PortRole = Qt::UserRole + 1,
|
||||
CipherRole,
|
||||
SiteRole
|
||||
};
|
||||
|
||||
explicit CloakConfigModel(QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
public slots:
|
||||
void updateModel(const QJsonObject &config);
|
||||
QJsonObject getConfig();
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
DockerContainer m_container;
|
||||
QJsonObject m_protocolConfig;
|
||||
QJsonObject m_fullConfig;
|
||||
};
|
||||
|
||||
#endif // CLOAKCONFIGMODEL_H
|
76
client/ui/models/protocols/ikev2ConfigModel.cpp
Normal file
76
client/ui/models/protocols/ikev2ConfigModel.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include "ikev2ConfigModel.h".h "
|
||||
|
||||
#include "protocols/protocols_defs.h"
|
||||
|
||||
Ikev2ConfigModel::Ikev2ConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int Ikev2ConfigModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool Ikev2ConfigModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= ContainerProps::allContainers().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::PortRole: m_protocolConfig.insert(config_key::port, value.toString()); break;
|
||||
case Roles::CipherRole: m_protocolConfig.insert(config_key::cipher, value.toString()); break;
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, QList { role });
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant Ikev2ConfigModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= rowCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::PortRole: return m_protocolConfig.value(config_key::port).toString(protocols::shadowsocks::defaultPort);
|
||||
case Roles::CipherRole:
|
||||
return m_protocolConfig.value(config_key::cipher).toString(protocols::shadowsocks::defaultCipher);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void Ikev2ConfigModel::updateModel(const QJsonObject &config)
|
||||
{
|
||||
beginResetModel();
|
||||
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||
|
||||
m_fullConfig = config;
|
||||
QJsonObject protocolConfig = config.value(config_key::shadowsocks).toObject();
|
||||
|
||||
m_protocolConfig.insert(config_key::cipher,
|
||||
protocolConfig.value(config_key::cipher).toString(protocols::shadowsocks::defaultCipher));
|
||||
|
||||
m_protocolConfig.insert(config_key::port,
|
||||
protocolConfig.value(config_key::port).toString(protocols::shadowsocks::defaultPort));
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QJsonObject Ikev2ConfigModel::getConfig()
|
||||
{
|
||||
m_fullConfig.insert(config_key::shadowsocks, m_protocolConfig);
|
||||
return m_fullConfig;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> Ikev2ConfigModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
|
||||
roles[PortRole] = "port";
|
||||
roles[CipherRole] = "cipher";
|
||||
|
||||
return roles;
|
||||
}
|
39
client/ui/models/protocols/ikev2ConfigModel.h
Normal file
39
client/ui/models/protocols/ikev2ConfigModel.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef IKEV2CONFIGMODEL_H
|
||||
#define IKEV2CONFIGMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
class Ikev2ConfigModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Roles {
|
||||
PortRole = Qt::UserRole + 1,
|
||||
CipherRole
|
||||
};
|
||||
|
||||
explicit Ikev2ConfigModel(QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
public slots:
|
||||
void updateModel(const QJsonObject &config);
|
||||
QJsonObject getConfig();
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
DockerContainer m_container;
|
||||
QJsonObject m_protocolConfig;
|
||||
QJsonObject m_fullConfig;
|
||||
};
|
||||
|
||||
#endif // IKEV2CONFIGMODEL_H
|
152
client/ui/models/protocols/openvpnConfigModel.cpp
Normal file
152
client/ui/models/protocols/openvpnConfigModel.cpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
#include "openvpnConfigModel.h"
|
||||
|
||||
#include "protocols/protocols_defs.h"
|
||||
|
||||
OpenVpnConfigModel::OpenVpnConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int OpenVpnConfigModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool OpenVpnConfigModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= ContainerProps::allContainers().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::SubnetAddressRole:
|
||||
m_protocolConfig.insert(amnezia::config_key::subnet_address, value.toString());
|
||||
break;
|
||||
case Roles::TransportProtoRole: m_protocolConfig.insert(config_key::transport_proto, value.toString()); break;
|
||||
case Roles::PortRole: m_protocolConfig.insert(config_key::port, value.toString()); break;
|
||||
case Roles::AutoNegotiateEncryprionRole: m_protocolConfig.insert(config_key::ncp_disable, !value.toBool()); break;
|
||||
case Roles::HashRole: m_protocolConfig.insert(config_key::hash, value.toString()); break;
|
||||
case Roles::CipherRole: m_protocolConfig.insert(config_key::cipher, value.toString()); break;
|
||||
case Roles::TlsAuthRole: m_protocolConfig.insert(config_key::tls_auth, value.toBool()); break;
|
||||
case Roles::BlockDnsRole: m_protocolConfig.insert(config_key::block_outside_dns, value.toBool()); break;
|
||||
case Roles::AdditionalClientCommandsRole:
|
||||
m_protocolConfig.insert(config_key::additional_client_config, value.toString());
|
||||
break;
|
||||
case Roles::AdditionalServerCommandsRole:
|
||||
m_protocolConfig.insert(config_key::additional_server_config, value.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, QList { role });
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant OpenVpnConfigModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= rowCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::SubnetAddressRole:
|
||||
return m_protocolConfig.value(amnezia::config_key::subnet_address)
|
||||
.toString(amnezia::protocols::openvpn::defaultSubnetAddress);
|
||||
case Roles::TransportProtoRole:
|
||||
return m_protocolConfig.value(config_key::transport_proto).toString(protocols::openvpn::defaultTransportProto);
|
||||
case Roles::PortRole: return m_protocolConfig.value(config_key::port).toString(protocols::openvpn::defaultPort);
|
||||
case Roles::AutoNegotiateEncryprionRole:
|
||||
return !m_protocolConfig.value(config_key::ncp_disable).toBool(protocols::openvpn::defaultNcpDisable);
|
||||
case Roles::HashRole: return m_protocolConfig.value(config_key::hash).toString(protocols::openvpn::defaultHash);
|
||||
case Roles::CipherRole:
|
||||
return m_protocolConfig.value(config_key::cipher).toString(protocols::openvpn::defaultCipher);
|
||||
case Roles::TlsAuthRole:
|
||||
return m_protocolConfig.value(config_key::tls_auth).toBool(protocols::openvpn::defaultTlsAuth);
|
||||
case Roles::BlockDnsRole:
|
||||
return m_protocolConfig.value(config_key::block_outside_dns).toBool(protocols::openvpn::defaultBlockOutsideDns);
|
||||
case Roles::AdditionalClientCommandsRole:
|
||||
return m_protocolConfig.value(config_key::additional_client_config)
|
||||
.toString(protocols::openvpn::defaultAdditionalClientConfig);
|
||||
case Roles::AdditionalServerCommandsRole:
|
||||
return m_protocolConfig.value(config_key::additional_server_config)
|
||||
.toString(protocols::openvpn::defaultAdditionalServerConfig);
|
||||
case Roles::IsPortEditable: return m_container == DockerContainer::OpenVpn ? true : false;
|
||||
case Roles::IsTransportProtoEditable: return m_container == DockerContainer::OpenVpn ? true : false;
|
||||
case Roles::HasRemoveButton: return m_container == DockerContainer::OpenVpn ? true : false;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void OpenVpnConfigModel::updateModel(const QJsonObject &config)
|
||||
{
|
||||
beginResetModel();
|
||||
m_container =
|
||||
ContainerProps::containerFromString(config.value(config_key::container).toString()); // todo maybe unused
|
||||
|
||||
m_fullConfig = config;
|
||||
QJsonObject protocolConfig = config.value(config_key::openvpn).toObject();
|
||||
|
||||
m_protocolConfig.insert(config_key::subnet_address,
|
||||
protocolConfig.value(amnezia::config_key::subnet_address)
|
||||
.toString(amnezia::protocols::openvpn::defaultSubnetAddress));
|
||||
|
||||
QString transportProto;
|
||||
if (m_container == DockerContainer::OpenVpn) {
|
||||
transportProto =
|
||||
protocolConfig.value(config_key::transport_proto).toString(protocols::openvpn::defaultTransportProto);
|
||||
} else {
|
||||
transportProto = "tcp";
|
||||
}
|
||||
|
||||
m_protocolConfig.insert(config_key::transport_proto, transportProto);
|
||||
|
||||
m_protocolConfig.insert(config_key::ncp_disable,
|
||||
protocolConfig.value(config_key::ncp_disable).toBool(protocols::openvpn::defaultNcpDisable));
|
||||
m_protocolConfig.insert(config_key::cipher,
|
||||
protocolConfig.value(config_key::cipher).toString(protocols::openvpn::defaultCipher));
|
||||
m_protocolConfig.insert(config_key::hash,
|
||||
protocolConfig.value(config_key::hash).toString(protocols::openvpn::defaultHash));
|
||||
m_protocolConfig.insert(config_key::block_outside_dns,
|
||||
protocolConfig.value(config_key::tls_auth).toBool(protocols::openvpn::defaultTlsAuth));
|
||||
m_protocolConfig.insert(config_key::port,
|
||||
protocolConfig.value(config_key::port).toString(protocols::openvpn::defaultPort));
|
||||
m_protocolConfig.insert(
|
||||
config_key::tls_auth,
|
||||
protocolConfig.value(config_key::block_outside_dns).toBool(protocols::openvpn::defaultBlockOutsideDns));
|
||||
m_protocolConfig.insert(config_key::additional_client_config,
|
||||
protocolConfig.value(config_key::additional_client_config)
|
||||
.toString(protocols::openvpn::defaultAdditionalClientConfig));
|
||||
m_protocolConfig.insert(config_key::additional_server_config,
|
||||
protocolConfig.value(config_key::additional_server_config)
|
||||
.toString(protocols::openvpn::defaultAdditionalServerConfig));
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QJsonObject OpenVpnConfigModel::getConfig()
|
||||
{
|
||||
m_fullConfig.insert(config_key::openvpn, m_protocolConfig);
|
||||
return m_fullConfig;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> OpenVpnConfigModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
|
||||
roles[SubnetAddressRole] = "subnetAddress";
|
||||
roles[TransportProtoRole] = "transportProto";
|
||||
roles[PortRole] = "port";
|
||||
roles[AutoNegotiateEncryprionRole] = "autoNegotiateEncryprion";
|
||||
roles[HashRole] = "hash";
|
||||
roles[CipherRole] = "cipher";
|
||||
roles[TlsAuthRole] = "tlsAuth";
|
||||
roles[BlockDnsRole] = "blockDns";
|
||||
roles[AdditionalClientCommandsRole] = "additionalClientCommands";
|
||||
roles[AdditionalServerCommandsRole] = "additionalServerCommands";
|
||||
|
||||
roles[IsPortEditable] = "isPortEditable";
|
||||
roles[IsTransportProtoEditable] = "isTransportProtoEditable";
|
||||
|
||||
roles[HasRemoveButton] = "hasRemoveButton";
|
||||
|
||||
return roles;
|
||||
}
|
52
client/ui/models/protocols/openvpnConfigModel.h
Normal file
52
client/ui/models/protocols/openvpnConfigModel.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef OPENVPNCONFIGMODEL_H
|
||||
#define OPENVPNCONFIGMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
class OpenVpnConfigModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Roles {
|
||||
SubnetAddressRole = Qt::UserRole + 1,
|
||||
TransportProtoRole,
|
||||
PortRole,
|
||||
AutoNegotiateEncryprionRole,
|
||||
HashRole,
|
||||
CipherRole,
|
||||
TlsAuthRole,
|
||||
BlockDnsRole,
|
||||
AdditionalClientCommandsRole,
|
||||
AdditionalServerCommandsRole,
|
||||
|
||||
IsPortEditable,
|
||||
IsTransportProtoEditable,
|
||||
|
||||
HasRemoveButton
|
||||
};
|
||||
|
||||
explicit OpenVpnConfigModel(QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
public slots:
|
||||
void updateModel(const QJsonObject &config);
|
||||
QJsonObject getConfig();
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
DockerContainer m_container;
|
||||
QJsonObject m_protocolConfig;
|
||||
QJsonObject m_fullConfig;
|
||||
};
|
||||
|
||||
#endif // OPENVPNCONFIGMODEL_H
|
76
client/ui/models/protocols/shadowsocksConfigModel.cpp
Normal file
76
client/ui/models/protocols/shadowsocksConfigModel.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include "shadowsocksConfigModel.h"
|
||||
|
||||
#include "protocols/protocols_defs.h"
|
||||
|
||||
ShadowSocksConfigModel::ShadowSocksConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int ShadowSocksConfigModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool ShadowSocksConfigModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= ContainerProps::allContainers().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::PortRole: m_protocolConfig.insert(config_key::port, value.toString()); break;
|
||||
case Roles::CipherRole: m_protocolConfig.insert(config_key::cipher, value.toString()); break;
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, QList { role });
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant ShadowSocksConfigModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= rowCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::PortRole: return m_protocolConfig.value(config_key::port).toString(protocols::shadowsocks::defaultPort);
|
||||
case Roles::CipherRole:
|
||||
return m_protocolConfig.value(config_key::cipher).toString(protocols::shadowsocks::defaultCipher);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ShadowSocksConfigModel::updateModel(const QJsonObject &config)
|
||||
{
|
||||
beginResetModel();
|
||||
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||
|
||||
m_fullConfig = config;
|
||||
QJsonObject protocolConfig = config.value(config_key::shadowsocks).toObject();
|
||||
|
||||
m_protocolConfig.insert(config_key::cipher,
|
||||
protocolConfig.value(config_key::cipher).toString(protocols::shadowsocks::defaultCipher));
|
||||
|
||||
m_protocolConfig.insert(config_key::port,
|
||||
protocolConfig.value(config_key::port).toString(protocols::shadowsocks::defaultPort));
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QJsonObject ShadowSocksConfigModel::getConfig()
|
||||
{
|
||||
m_fullConfig.insert(config_key::shadowsocks, m_protocolConfig);
|
||||
return m_fullConfig;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> ShadowSocksConfigModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
|
||||
roles[PortRole] = "port";
|
||||
roles[CipherRole] = "cipher";
|
||||
|
||||
return roles;
|
||||
}
|
39
client/ui/models/protocols/shadowsocksConfigModel.h
Normal file
39
client/ui/models/protocols/shadowsocksConfigModel.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef SHADOWSOCKSCONFIGMODEL_H
|
||||
#define SHADOWSOCKSCONFIGMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
class ShadowSocksConfigModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Roles {
|
||||
PortRole = Qt::UserRole + 1,
|
||||
CipherRole
|
||||
};
|
||||
|
||||
explicit ShadowSocksConfigModel(QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
public slots:
|
||||
void updateModel(const QJsonObject &config);
|
||||
QJsonObject getConfig();
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
DockerContainer m_container;
|
||||
QJsonObject m_protocolConfig;
|
||||
QJsonObject m_fullConfig;
|
||||
};
|
||||
|
||||
#endif // SHADOWSOCKSCONFIGMODEL_H
|
70
client/ui/models/protocols/wireguardConfigModel.cpp
Normal file
70
client/ui/models/protocols/wireguardConfigModel.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include "wireguardConfigModel.h"
|
||||
|
||||
#include "protocols/protocols_defs.h"
|
||||
|
||||
WireGuardConfigModel::WireGuardConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int WireGuardConfigModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool WireGuardConfigModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= ContainerProps::allContainers().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::PortRole: m_protocolConfig.insert(config_key::port, value.toString()); break;
|
||||
case Roles::CipherRole: m_protocolConfig.insert(config_key::cipher, value.toString()); break;
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, QList { role });
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant WireGuardConfigModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= rowCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::PortRole: return m_protocolConfig.value(config_key::port).toString(protocols::shadowsocks::defaultPort);
|
||||
case Roles::CipherRole:
|
||||
return m_protocolConfig.value(config_key::cipher).toString(protocols::shadowsocks::defaultCipher);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void WireGuardConfigModel::updateModel(const QJsonObject &config)
|
||||
{
|
||||
beginResetModel();
|
||||
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||
|
||||
m_fullConfig = config;
|
||||
QJsonObject protocolConfig = config.value(config_key::wireguard).toObject();
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QJsonObject WireGuardConfigModel::getConfig()
|
||||
{
|
||||
m_fullConfig.insert(config_key::wireguard, m_protocolConfig);
|
||||
return m_fullConfig;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> WireGuardConfigModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
|
||||
roles[PortRole] = "port";
|
||||
roles[CipherRole] = "cipher";
|
||||
|
||||
return roles;
|
||||
}
|
39
client/ui/models/protocols/wireguardConfigModel.h
Normal file
39
client/ui/models/protocols/wireguardConfigModel.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef WIREGUARDCONFIGMODEL_H
|
||||
#define WIREGUARDCONFIGMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
class WireGuardConfigModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Roles {
|
||||
PortRole = Qt::UserRole + 1,
|
||||
CipherRole
|
||||
};
|
||||
|
||||
explicit WireGuardConfigModel(QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
public slots:
|
||||
void updateModel(const QJsonObject &config);
|
||||
QJsonObject getConfig();
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
DockerContainer m_container;
|
||||
QJsonObject m_protocolConfig;
|
||||
QJsonObject m_fullConfig;
|
||||
};
|
||||
|
||||
#endif // WIREGUARDCONFIGMODEL_H
|
|
@ -1,62 +1,73 @@
|
|||
#include "protocols_model.h"
|
||||
|
||||
ProtocolsModel::ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent) :
|
||||
m_settings(settings),
|
||||
QAbstractListModel(parent)
|
||||
ProtocolsModel::ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: m_settings(settings), QAbstractListModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int ProtocolsModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return ProtocolProps::allProtocols().size();
|
||||
return m_content.size();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> ProtocolsModel::roleNames() const {
|
||||
QHash<int, QByteArray> ProtocolsModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[NameRole] = "name_role";
|
||||
roles[DescRole] = "desc_role";
|
||||
roles[ServiceTypeRole] = "service_type_role";
|
||||
roles[IsInstalledRole] = "is_installed_role";
|
||||
|
||||
roles[ProtocolNameRole] = "protocolName";
|
||||
roles[ProtocolPageRole] = "protocolPage";
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
QVariant ProtocolsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0
|
||||
|| index.row() >= ProtocolProps::allProtocols().size()) {
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= m_content.size()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Proto p = ProtocolProps::allProtocols().at(index.row());
|
||||
if (role == NameRole) {
|
||||
return ProtocolProps::protocolHumanNames().value(p);
|
||||
switch (role) {
|
||||
case ProtocolNameRole: {
|
||||
amnezia::Proto proto = ProtocolProps::protoFromString(m_content.keys().at(index.row()));
|
||||
return ProtocolProps::protocolHumanNames().value(proto);
|
||||
}
|
||||
if (role == DescRole) {
|
||||
return ProtocolProps::protocolDescriptions().value(p);
|
||||
}
|
||||
if (role == ServiceTypeRole) {
|
||||
return ProtocolProps::protocolService(p);
|
||||
}
|
||||
if (role == IsInstalledRole) {
|
||||
return ContainerProps::protocolsForContainer(m_selectedDockerContainer).contains(p);
|
||||
case ProtocolPageRole:
|
||||
return static_cast<int>(protocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ProtocolsModel::setSelectedServerIndex(int index)
|
||||
void ProtocolsModel::updateModel(const QJsonObject &content)
|
||||
{
|
||||
beginResetModel();
|
||||
m_selectedServerIndex = index;
|
||||
endResetModel();
|
||||
m_container = ContainerProps::containerFromString(content.value(config_key::container).toString());
|
||||
|
||||
m_content = content;
|
||||
m_content.remove(config_key::container);
|
||||
}
|
||||
|
||||
void ProtocolsModel::setSelectedDockerContainer(DockerContainer c)
|
||||
QJsonObject ProtocolsModel::getConfig()
|
||||
{
|
||||
beginResetModel();
|
||||
m_selectedDockerContainer = c;
|
||||
endResetModel();
|
||||
QJsonObject config = m_content;
|
||||
config.insert(config_key::container, ContainerProps::containerToString(m_container));
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
PageLoader::PageEnum ProtocolsModel::protocolPage(Proto protocol) const
|
||||
{
|
||||
switch (protocol) {
|
||||
case Proto::OpenVpn: return PageLoader::PageEnum::PageProtocolOpenVpnSettings;
|
||||
case Proto::Cloak: return PageLoader::PageEnum::PageProtocolCloakSettings;
|
||||
case Proto::ShadowSocks: return PageLoader::PageEnum::PageProtocolShadowSocksSettings;
|
||||
case Proto::WireGuard: return PageLoader::PageEnum::PageProtocolWireGuardSettings;
|
||||
case Proto::Ikev2: return PageLoader::PageEnum::PageProtocolIKev2Settings;
|
||||
case Proto::L2tp: return PageLoader::PageEnum::PageProtocolOpenVpnSettings;
|
||||
// non-vpn
|
||||
case Proto::TorWebSite: return PageLoader::PageEnum::PageProtocolOpenVpnSettings;
|
||||
case Proto::Dns: return PageLoader::PageEnum::PageProtocolOpenVpnSettings;
|
||||
case Proto::FileShare: return PageLoader::PageEnum::PageProtocolOpenVpnSettings;
|
||||
case Proto::Sftp: return PageLoader::PageEnum::PageProtocolOpenVpnSettings;
|
||||
default: return PageLoader::PageEnum::PageProtocolOpenVpnSettings;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,38 +3,40 @@
|
|||
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
#include "../controllers/pageController.h"
|
||||
#include "settings.h"
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
class ProtocolsModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
public:
|
||||
enum SiteRoles {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
DescRole,
|
||||
ServiceTypeRole,
|
||||
IsInstalledRole
|
||||
enum Roles {
|
||||
ProtocolNameRole = Qt::UserRole + 1,
|
||||
ProtocolPageRole
|
||||
};
|
||||
|
||||
ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
Q_INVOKABLE void setSelectedServerIndex(int index);
|
||||
Q_INVOKABLE void setSelectedDockerContainer(DockerContainer c);
|
||||
|
||||
public slots:
|
||||
void updateModel(const QJsonObject &content);
|
||||
|
||||
QJsonObject getConfig();
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
int m_selectedServerIndex;
|
||||
DockerContainer m_selectedDockerContainer;
|
||||
PageLoader::PageEnum protocolPage(Proto protocol) const;
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
|
||||
DockerContainer m_container;
|
||||
QJsonObject m_content;
|
||||
};
|
||||
|
||||
#endif // PROTOCOLS_MODEL_H
|
||||
|
|
|
@ -123,6 +123,7 @@ bool ServersModel::isDefaultServerHasWriteAccess()
|
|||
|
||||
void ServersModel::addServer(const QJsonObject &server)
|
||||
{
|
||||
// todo beginInsertRows()?
|
||||
beginResetModel();
|
||||
m_settings->addServer(server);
|
||||
m_servers = m_settings->serversArray();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue