feature/mtu connection config (#833)

* added the ability to change mtu for connection-only configs
* added replacing MTU with default when importing awg/wg configs in amnezia
This commit is contained in:
Nethius 2024-09-13 12:38:48 +04:00 committed by GitHub
parent fff15fffe2
commit 96566f04ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 903 additions and 249 deletions

View file

@ -16,9 +16,11 @@ QHash<int, QByteArray> ProtocolsModel::roleNames() const
QHash<int, QByteArray> roles;
roles[ProtocolNameRole] = "protocolName";
roles[ProtocolPageRole] = "protocolPage";
roles[ServerProtocolPageRole] = "serverProtocolPage";
roles[ClientProtocolPageRole] = "clientProtocolPage";
roles[ProtocolIndexRole] = "protocolIndex";
roles[RawConfigRole] = "rawConfig";
roles[IsClientProtocolExistsRole] = "isClientProtocolExists";
return roles;
}
@ -34,8 +36,10 @@ QVariant ProtocolsModel::data(const QModelIndex &index, int role) const
amnezia::Proto proto = ProtocolProps::protoFromString(m_content.keys().at(index.row()));
return ProtocolProps::protocolHumanNames().value(proto);
}
case ProtocolPageRole:
return static_cast<int>(protocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
case ServerProtocolPageRole:
return static_cast<int>(serverProtocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
case ClientProtocolPageRole:
return static_cast<int>(clientProtocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
case ProtocolIndexRole: return ProtocolProps::protoFromString(m_content.keys().at(index.row()));
case RawConfigRole: {
auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
@ -50,6 +54,15 @@ QVariant ProtocolsModel::data(const QModelIndex &index, int role) const
}
return rawConfig;
}
case IsClientProtocolExistsRole: {
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();
auto configString = lastConfigJson.value(config_key::config).toString();
return !configString.isEmpty();
}
}
return QVariant();
@ -70,7 +83,7 @@ QJsonObject ProtocolsModel::getConfig()
return config;
}
PageLoader::PageEnum ProtocolsModel::protocolPage(Proto protocol) const
PageLoader::PageEnum ProtocolsModel::serverProtocolPage(Proto protocol) const
{
switch (protocol) {
case Proto::OpenVpn: return PageLoader::PageEnum::PageProtocolOpenVpnSettings;
@ -90,3 +103,12 @@ PageLoader::PageEnum ProtocolsModel::protocolPage(Proto protocol) const
default: return PageLoader::PageEnum::PageProtocolOpenVpnSettings;
}
}
PageLoader::PageEnum ProtocolsModel::clientProtocolPage(Proto protocol) const
{
switch (protocol) {
case Proto::WireGuard: return PageLoader::PageEnum::PageProtocolWireGuardClientSettings;
case Proto::Awg: return PageLoader::PageEnum::PageProtocolAwgClientSettings;
default: return PageLoader::PageEnum::PageProtocolOpenVpnSettings;
}
}