Better DNS global status in listing page.

This commit is contained in:
Antoine Nguyen
2021-02-08 17:56:05 +01:00
parent 09a6fe1c5b
commit d42f0306a5
3 changed files with 59 additions and 48 deletions
+32 -29
View File
@@ -45,28 +45,11 @@
<template v-slot:item.domainalias_count="{ item }">
{{ item.domainalias_count }} aliases
</template>
<template v-slot:item.dns_status="{ item }">
<v-chip v-if="item.dns_status.checks === 'disabled'"
label x-small><translate>Disabled</translate></v-chip>
<v-chip v-if="item.dns_status.checks === 'pending'"
color="secondary" label x-small><translate>Pending</translate></v-chip>
<span v-if="item.dns_status.checks === 'active'">
<v-chip v-if="item.dns_status.mx"
:color="getDNSTagType(item.dns_status.mx)"
class="mr-1"
label
x-small
>
MX
</v-chip>
<v-chip v-if="item.dns_status.dnsbl"
:color="getDNSTagType(item.dns_status.dnsbl)"
label
x-small
>
DNSBL
</v-chip>
</span>
<template v-slot:item.dns_global_status="{ item }">
<v-chip :color="getDNSTagType(item.dns_global_status)"
small>
{{ getDNSLabel(item.dns_global_status) }}
</v-chip>
</template>
<template v-slot:item.message_limit="{ item }">
<v-progress-linear v-model="item.allocated_quota_in_percent" />
@@ -131,12 +114,11 @@ export default {
headers: [
{ text: 'Name', value: 'name' },
{ text: 'Aliases', value: 'domainalias_count' },
{ text: 'DNS status', value: 'dns_status', sortable: false },
{ text: 'DNS status', value: 'dns_global_status', sortable: false, align: 'center' },
{ text: 'Sending limit', value: 'message_limit' },
{ text: 'Quota', value: 'allocated_quota_in_percent' },
{ text: this.$gettext('Actions'), value: 'actions', sortable: false, align: 'right' }
],
deleteDomainMsg: this.$gettext('Confirm deletion?'),
selectedDomain: null,
showConfirmDialog: false,
search: '',
@@ -164,14 +146,35 @@ export default {
}
)
},
getDNSTagType (value) {
if (value === 'unknown') {
return 'orange'
getDNSLabel (value) {
if (value === 'disabled') {
return this.$gettext('Disabled')
}
if (value === 'pending') {
return this.$gettext('Pending')
}
if (value === 'critical') {
return this.$gettext('Problem')
}
if (value === 'ok') {
return 'warning'
return this.$gettext('Valid')
}
return 'success'
return this.$gettext('Unknown')
},
getDNSTagType (value) {
if (value === 'disabled') {
return ''
}
if (value === 'pending') {
return 'info'
}
if (value === 'critical') {
return 'error'
}
if (value === 'ok') {
return 'success'
}
return 'warning'
},
loadAliases ({ item, value }) {
if (!value) {
+25 -17
View File
@@ -149,26 +149,34 @@ class Domain(mixins.MessageLimitMixin, AdminObject):
return True
return False
@cached_property
def dns_status(self) -> dict:
"""Return information about current DNS status."""
@property
def dns_global_status(self) -> str:
"""Return global DNS status."""
if not self.enable_dns_checks or self.uses_a_reserved_tld:
return {"checks": "disabled"}
return "disabled"
elif self.awaiting_checks():
return {"checks": "pending"}
result = {"checks": "active"}
return "pending"
config = dict(param_tools.get_global_parameters("admin"))
if config["enable_mx_checks"]:
result["mx"] = "ok" if self.mxrecord_set.has_valids() else "ko"
if config["enable_dnsbl_checks"]:
if not self.dnsblresult_set.exists():
status = "unknown"
elif self.dnsblresult_set.blacklisted().exists():
status = "ko"
else:
status = "ok"
result["dnsbl"] = status
return result
errors = []
if config["enable_mx_checks"] and not self.mxrecord_set.has_valids():
errors.append("mx")
if config["enable_dnsbl_checks"] and self.dnsblresult_set.blacklisted().exists():
errors.append("dnsbl")
if config["enable_spf_checks"]:
if self.spf_record is None or not self.spf_record.is_valid():
errors.append("spf")
if self.dkim_record is None or not self.dkim_record.is_valid():
errors.append("dkim")
if self.dmarc_record is None or not self.dmarc_record.is_valid():
errors.append("dmarc")
if config["enable_autoconfig_checks"]:
if self.autoconfig_record is None:
errors.append("autoconfig")
if self.autodiscover_record is None:
errors.append("autodiscover")
if len(errors) == 0:
return "ok"
return "critical"
@cached_property
def dnsbl_status_color(self):
+2 -2
View File
@@ -52,10 +52,10 @@ class DomainSerializer(serializers.ModelSerializer):
"enable_dkim", "dkim_key_selector", "dkim_key_length",
"dkim_public_key", "dkim_private_key_path",
"mailbox_count", "mbalias_count", "domainalias_count",
"dns_status", "message_limit"
"dns_global_status", "message_limit"
)
read_only_fields = (
"pk", "dkim_public_key", "dns_status", "allocated_quota_in_percent"
"pk", "dkim_public_key", "dns_global_status", "allocated_quota_in_percent"
"mailbox_count", "mbalias_count", "domainalias_count",
"enable_dns_checks"
)