[fix] Bad call to dict

This commit is contained in:
ljf 2020-04-13 16:41:27 +02:00
parent 0b7984adf1
commit 5b0698e798
2 changed files with 11 additions and 10 deletions

View file

@ -36,12 +36,13 @@ class MailDiagnoser(Diagnoser):
# Are IPs listed on a DNSBL ? # Are IPs listed on a DNSBL ?
self.logger_debug("Running DNSBL detection") self.logger_debug("Running DNSBL detection")
blacklisted_details = self.check_ip_dnsbl() blacklisted_details = list(self.check_dnsbl(self.get_public_ips()))
print(blacklisted_details)
if blacklisted_details: if blacklisted_details:
yield dict(meta={"test": "mail_blacklist"}, yield dict(meta={"test": "mail_blacklist"},
status="ERROR", status="ERROR",
summary="diagnosis_mail_blacklist_nok", summary="diagnosis_mail_blacklist_nok",
details=list(blacklisted_details)) details=blacklisted_details)
else: else:
yield dict(meta={"test": "mail_blacklist"}, yield dict(meta={"test": "mail_blacklist"},
status="SUCCESS", status="SUCCESS",
@ -57,23 +58,22 @@ class MailDiagnoser(Diagnoser):
# check for unusual failed sending attempt being refused in the logs ? # check for unusual failed sending attempt being refused in the logs ?
def check_blacklisted(self): def check_dnsbl(self, ips):
""" Check with dig onto blacklist DNS server """ Check with dig onto blacklist DNS server
""" """
dns_blacklists = read_yaml(DEFAULT_DNS_BLACKLIST) dns_blacklists = read_yaml(DEFAULT_DNS_BLACKLIST)
for ip in self.get_public_ips(): for ip in ips:
for blacklist in dns_blacklists: for blacklist in dns_blacklists:
if "." in ip and not blacklist['ipv4']:
if "." in ip and not blacklist.ipv4:
continue continue
if ":" in ip and not blacklist.ipv6: if ":" in ip and not blacklist['ipv6']:
continue continue
# Determine if we are listed on this RBL # Determine if we are listed on this RBL
try: try:
rev = dns.reversename.from_address(ip) rev = dns.reversename.from_address(ip)
query = str(rev.split(3)[0]) + '.' + blacklist.dns_server query = str(rev.split(3)[0]) + '.' + blacklist['dns_server']
# TODO add timeout lifetime # TODO add timeout lifetime
dns.resolver.query(query, "A") dns.resolver.query(query, "A")
except (dns.resolver.NXDOMAIN, dns.resolver.NoNameservers, dns.resolver.NoAnswer, except (dns.resolver.NXDOMAIN, dns.resolver.NoNameservers, dns.resolver.NoAnswer,
@ -89,7 +89,8 @@ class MailDiagnoser(Diagnoser):
yield ('diagnosis_mail_blacklisted_by', { yield ('diagnosis_mail_blacklisted_by', {
'ip': ip, 'ip': ip,
'blacklist': blacklist, 'blacklist_name': blacklist['name'],
'blacklist_website': blacklist['website'],
'reason': reason}) 'reason': reason})
def get_public_ips(self): def get_public_ips(self):

View file

@ -188,7 +188,7 @@
"diagnosis_mail_ougoing_port_25_blocked": "Outgoing port 25 appears to be blocked. You should try to unblock it in your internet service provider (or hosting provider) configuration panel. Meanwhile, the server won't be able to send emails to other servers.", "diagnosis_mail_ougoing_port_25_blocked": "Outgoing port 25 appears to be blocked. You should try to unblock it in your internet service provider (or hosting provider) configuration panel. Meanwhile, the server won't be able to send emails to other servers.",
"diagnosis_mail_blacklist_ok": "Your server public IP are not listed on email blacklists.", "diagnosis_mail_blacklist_ok": "Your server public IP are not listed on email blacklists.",
"diagnosis_mail_blacklist_nok": "Your server public IPs are listed on email blacklists.", "diagnosis_mail_blacklist_nok": "Your server public IPs are listed on email blacklists.",
"diagnosis_mail_blacklisted_by": "{ip} is listed on {blacklist.name}. Reason: {reason}. See {blacklist.website}", "diagnosis_mail_blacklisted_by": "{ip} is listed on {blacklist_name}. Reason: {reason}. See {blacklist_website}",
"diagnosis_regenconf_allgood": "All configurations files are in line with the recommended configuration!", "diagnosis_regenconf_allgood": "All configurations files are in line with the recommended configuration!",
"diagnosis_regenconf_manually_modified": "Configuration file <code>{file}</code> appears to have been manually modified.", "diagnosis_regenconf_manually_modified": "Configuration file <code>{file}</code> appears to have been manually modified.",
"diagnosis_regenconf_manually_modified_details": "This is probably OK if you know what you're doing! YunoHost will stop updating this file automatically... But beware that YunoHost upgrades could contain important recommended changes. If you want to, you can inspect the differences with <cmd>yunohost tools regen-conf {category} --dry-run --with-diff</cmd> and force the reset to the recommended configuration with <cmd>yunohost tools regen-conf {category} --force</cmd>", "diagnosis_regenconf_manually_modified_details": "This is probably OK if you know what you're doing! YunoHost will stop updating this file automatically... But beware that YunoHost upgrades could contain important recommended changes. If you want to, you can inspect the differences with <cmd>yunohost tools regen-conf {category} --dry-run --with-diff</cmd> and force the reset to the recommended configuration with <cmd>yunohost tools regen-conf {category} --force</cmd>",