From: linostar Date: Wed, 1 Jun 2016 21:06:20 +0000 (+0000) Subject: Catch timeout exceptions and decrease the default timeout value X-Git-Url: https://jfr.im/git/irc/rizon/acid.git/commitdiff_plain/44e1ff37ae9b0162db528dfddfb3d66de0e5315c?hp=4d2abfb01e58eef803f0156975e088ddc8449386 Catch timeout exceptions and decrease the default timeout value --- diff --git a/pyva/pyva/src/main/python/moo/requests.py b/pyva/pyva/src/main/python/moo/requests.py index 34160eb..650bd4d 100644 --- a/pyva/pyva/src/main/python/moo/requests.py +++ b/pyva/pyva/src/main/python/moo/requests.py @@ -346,7 +346,15 @@ class RequestManager(object): return (False, reason, int) is_resolvable, resolved, host = self.__is_resolvable(vhost) - txt_record_exists = self.check_nick_in_TXT_records(vhost, nick) + (txt_record_exists, resolving_error) = self.check_nick_in_TXT_records(vhost, nick) + + if resolving_error == "timeout": + self.module.msg(self.module.chan, "DNS Timeout when trying to check TXT record for vhost @b{}@b requested by @b{}@b.".format( + vhost, nick)) + elif resolving_error: + self.module.msg(self.module.chan, "The following error occured when checking TXT record for vhost @b{}@b requested by @b{}@b @sep {}.".format( + vhost, nick, resolving_error)) + if is_resolvable and not txt_record_exists: return (False, 'Your vHost resolves. You can add a particular DNS TXT record to confirm the ownership of the domain and request again. %s' % RULES, @@ -399,16 +407,22 @@ class RequestManager(object): return False def check_nick_in_TXT_records(self, host, nick): - DNS.ParseResolvConf() - dns_req = DNS.DnsRequest(name=host, qtype='TXT') - res = dns_req.req() - for answer in res.answers: - if 'data' in answer and (isinstance(answer['data'], list) or isinstance(answer['data'], tuple)): - for entry in answer['data']: - parts = entry.split('=') - if len(parts) > 1 and parts[0].lower().strip() == 'rizon_vhost': - if parts[1].strip() == '*': - return True - nicks = [n.lower().strip() for n in parts[1].split(',')] - if nick.lower() in nicks: - return True + try: + DNS.ParseResolvConf() + dns_req = DNS.DnsRequest(name=host, qtype='TXT', timeout=10) + res = dns_req.req() + for answer in res.answers: + if 'data' in answer and (isinstance(answer['data'], list) or isinstance(answer['data'], tuple)): + for entry in answer['data']: + parts = entry.split('=') + if len(parts) > 1 and parts[0].lower().strip() == 'rizon_vhost': + if parts[1].strip() == '*': + return (True, "") + nicks = [n.lower().strip() for n in parts[1].split(',')] + if nick.lower() in nicks: + return (True, "") + return (False, "") + except DNS.TimeoutError, e: + return (False, "timeout") + except Exception, e: + return (False, str(e))