added display of amnesia dns container activity on the main page

This commit is contained in:
vladimir.kuznetsov 2023-06-27 19:07:42 +09:00
parent 2ef53c6df9
commit 795405c47d
21 changed files with 238 additions and 85 deletions

View file

@ -132,6 +132,17 @@ void ContainersModel::clearCachedProfiles()
}
}
bool ContainersModel::isAmneziaDnsContainerInstalled()
{
return m_containers.contains(DockerContainer::Dns);
}
bool ContainersModel::isAmneziaDnsContainerInstalled(const int serverIndex)
{
QMap<DockerContainer, QJsonObject> containers = m_settings->containers(serverIndex);
return containers.contains(DockerContainer::Dns);
}
QHash<int, QByteArray> ContainersModel::roleNames() const
{
QHash<int, QByteArray> roles;

View file

@ -51,6 +51,9 @@ public slots:
void removeAllContainers();
void clearCachedProfiles();
bool isAmneziaDnsContainerInstalled();
bool isAmneziaDnsContainerInstalled(const int serverIndex);
protected:
QHash<int, QByteArray> roleNames() const override;

View file

@ -59,10 +59,14 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
case CredentialsLoginRole: return m_settings->serverCredentials(index.row()).userName;
case IsDefaultRole: return index.row() == m_defaultServerIndex;
case IsCurrentlyProcessedRole: return index.row() == m_currenlyProcessedServerIndex;
case HasWriteAccess: {
case HasWriteAccessRole: {
auto credentials = m_settings->serverCredentials(index.row());
return (!credentials.userName.isEmpty() && !credentials.secretData.isEmpty());
}
case ContainsAmneziaDnsRole: {
QString primaryDns = server.value(config_key::dns1).toString();
return primaryDns == protocols::dns::amneziaDnsIp;
}
}
return QVariant();
@ -109,7 +113,12 @@ bool ServersModel::isDefaultServerCurrentlyProcessed()
bool ServersModel::isCurrentlyProcessedServerHasWriteAccess()
{
return qvariant_cast<bool>(data(m_currenlyProcessedServerIndex, HasWriteAccess));
return qvariant_cast<bool>(data(m_currenlyProcessedServerIndex, HasWriteAccessRole));
}
bool ServersModel::isDefaultServerHasWriteAccess()
{
return qvariant_cast<bool>(data(m_currenlyProcessedServerIndex, HasWriteAccessRole));
}
void ServersModel::addServer(const QJsonObject &server)
@ -138,6 +147,13 @@ void ServersModel::removeServer()
endResetModel();
}
bool ServersModel::isDefaultServerConfigContainsAmneziaDns()
{
const QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
QString primaryDns = server.value(config_key::dns1).toString();
return primaryDns == protocols::dns::amneziaDnsIp;
}
QHash<int, QByteArray> ServersModel::roleNames() const
{
QHash<int, QByteArray> roles;
@ -147,6 +163,7 @@ QHash<int, QByteArray> ServersModel::roleNames() const
roles[CredentialsLoginRole] = "credentialsLogin";
roles[IsDefaultRole] = "isDefault";
roles[IsCurrentlyProcessedRole] = "isCurrentlyProcessed";
roles[HasWriteAccess] = "hasWriteAccess";
roles[HasWriteAccessRole] = "hasWriteAccess";
roles[ContainsAmneziaDnsRole] = "containsAmneziaDns";
return roles;
}

View file

@ -16,7 +16,8 @@ public:
CredentialsLoginRole,
IsDefaultRole,
IsCurrentlyProcessedRole,
HasWriteAccess
HasWriteAccessRole,
ContainsAmneziaDnsRole
};
ServersModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
@ -37,6 +38,7 @@ public slots:
bool isDefaultServerCurrentlyProcessed();
bool isCurrentlyProcessedServerHasWriteAccess();
bool isDefaultServerHasWriteAccess();
const int getServersCount();
@ -46,6 +48,8 @@ public slots:
void addServer(const QJsonObject &server);
void removeServer();
bool isDefaultServerConfigContainsAmneziaDns();
protected:
QHash<int, QByteArray> roleNames() const override;