]> jfr.im git - irc/rizon/acid.git/commitdiff
Do not reject resolving vhosts
authorOrillion <redacted>
Sat, 10 Mar 2018 13:40:51 +0000 (14:40 +0100)
committerOrillion <redacted>
Sat, 10 Mar 2018 13:40:51 +0000 (14:40 +0100)
pyva/pyva/src/main/python/moo/cmd_user.py
pyva/pyva/src/main/python/moo/moo_utils.py
pyva/pyva/src/main/python/moo/requests.py

index fb37cab025b3c1d29b08a798b3653070c4f99fbe..a0f55b6d067b1519dc0d5a3c6c47c031d49d921d 100644 (file)
@@ -134,7 +134,7 @@ def cmd_check_pending(self, manager, channel, sender, arg):
                self.msg(self.chan, '@b[pending]@b %d pending vHost%s:' % (size, 's' if size != 1 else ''))
                for req in s:
                        min = (datetime.now() - req['date']).seconds / 60
-                       self.msg(self.chan, moo_utils.format_last_req(req['last'], '@b%(id)d.@b %(nick)s @sep @bvHost@b %(vhost)s%(susp)s @sep @bWaiting for@b %(wait)s minute%(s)s @sep%(lastreq)s' % {
+                       self.msg(self.chan, moo_utils.format_last_req(req['last'], req['should_warn'], '@b%(id)d.@b %(nick)s @sep @bvHost@b %(vhost)s%(susp)s @sep @bWaiting for@b %(wait)s minute%(s)s @sep%(lastreq)s' % {
                                'id'     : req['id'],
                                'nick'   : req['nick'],
                                'vhost'  : req['vhost'] if not req['suspicious'] else '@c10@b[!]@o ' + req['vhost'],
index 4a28672067938027f27abaf67915c1041b51ebd4..18cec8ddd9e73bb82a598d6f5dc393ccb0844143 100644 (file)
@@ -1,8 +1,8 @@
 import re
 from datetime import datetime
 
-def format_last_req(last_req, message):
-       c = '09'
+def format_last_req(last_req, should_warn, message):
+       c = '08' if should_warn else '09'
        if last_req:
                d = datetime.now() - last_req.date
                if d.days < 1:
index 1d8b879cfc4a0408a3b1632306ff370a340559dd..14996bf2dd59150bb7f95a12b8464c3cfb36970b 100644 (file)
@@ -94,16 +94,16 @@ class RequestManager(object):
        def add(self, vhost, nick, main=None):
                if main:
                        last_req = self.__get_last_request(main)
-                       acceptable, rating, internal = self.__verify(nick, vhost, main)
+                       acceptable, rating, internal, warn = self.__verify(nick, vhost, main)
                else: # only for requests missed during downtime
                        userinfo = User.findUser(nick)
                        if userinfo and userinfo['su']:
                                main = userinfo['su']
                                last_req = self.__get_last_request(main)
-                               acceptable, rating, internal = self.__verify(nick, vhost, main)
+                               acceptable, rating, internal, warn = self.__verify(nick, vhost, main)
                        else: # user no longer online or SU is empty, can't check main nick / last request
                                last_req = self.__get_last_request(nick)
-                               acceptable, rating, internal = self.__verify(nick, vhost)
+                               acceptable, rating, internal, warn = self.__verify(nick, vhost)
                
                if not acceptable:
                        self.module.msg('HostServ', 'REJECT %s %s' % (nick, rating if rating else ''))
@@ -131,14 +131,14 @@ class RequestManager(object):
                
                suspicious = self.__is_suspicious(vhost)
                date = datetime.now()
-               self.list[nick.lower()] = {'id': id, 'vhost': vhost, 'rating': rating, 'date': date, 'main': main, 'nick': nick, 'last': last_req, 'suspicious': suspicious}
-               self.module.msg(self.module.chan, moo_utils.format_last_req(last_req, '[new] %(id)d.@o %(nick)s @sep %(vhost)s%(susp)s @sep%(lastreq)s %(extra)s' % {
+               self.list[nick.lower()] = {'id': id, 'vhost': vhost, 'rating': rating, 'date': date, 'main': main, 'nick': nick, 'last': last_req, 'suspicious': suspicious, 'should_warn': warn}
+               self.module.msg(self.module.chan, moo_utils.format_last_req(last_req, warn, '[new] %(id)d.@o %(nick)s @sep %(vhost)s%(susp)s @sep%(lastreq)s %(extra)s' % {
                                'id'     : id,
                                'nick'   : nick,
                                'vhost'  : vhost if not suspicious else '@c10@b[!]@o ' + vhost,
                                'susp'   : ' @sep @bSuspicious@b %s' % suspicious if suspicious else '',
                                'lastreq': ' @bLast request@b %s ago as %s @sep' % (utils.get_timespan(last_req.date), last_req.nickname) if last_req else '',
-                               'extra'  : 'vHost resolved but its ownership was verified by the existence of a DNS TXT record' if internal == 'TXT record' else ''}))
+                               'extra'  : internal if internal is not None else ''}))
        
        def add_blacklist(self, vhost, by, reason=None):
                b = (vhost, by, reason, datetime.now())
@@ -333,47 +333,50 @@ class RequestManager(object):
                if is_banned:
                        return (False, 
                                'You have been banned from requesting vHosts. For more information, join #services', 
-                               'vHost: %s. Ban reason: %s - %s ago' % (vhost, reason if reason else 'No reason', utils.get_timespan(date)))
+                               'vHost: %s. Ban reason: %s - %s ago' % (vhost, reason if reason else 'No reason', utils.get_timespan(date)),
+                               False)
                
                if main and main != nick:
                        is_banned, reason, by, date = self.__is_banned(main)
                        if is_banned:
                                return (False, 
                                        'You have been banned from requesting vHosts%s.' % (('. Reason: %s' % reason) if reason else ''), 
-                                       'vHost: %s. Ban reason: %s - %s ago' % (vhost, reason if reason else 'No reason', utils.get_timespan(date)))
+                                       'vHost: %s. Ban reason: %s - %s ago' % (vhost, reason if reason else 'No reason', utils.get_timespan(date)),
+                                       False)
                
                is_blacklisted, reason, int = self.__is_blacklisted(vhost)
                if is_blacklisted:
-                       return (False, reason, int)
+                       return (False, reason, int, False)
                        
                for req in self.list.values():
                        if main == req['main'] and nick != req['nick']:
                                return (False,
                                        'You already have a pending vHost request for a grouped nickname. Please wait for it to be reviewed before requesting a new one.',
-                                       'Has a pending request with grouped nick %s' % req['nick'])
+                                       'Has a pending request with grouped nick %s' % req['nick'],
+                                       False)
 
                if vhost.replace(".", "").isdigit() and not self.__is_numeric_ip(vhost):
-                       return (True, '@c9Acceptable@c', None)
+                       return (True, '@c9Acceptable@c', None, False)
                
                is_resolvable, resolved, host = self.__is_resolvable(vhost)
                if is_resolvable:
                        (txt_record_exists, resolving_error) = self.check_nick_in_TXT_records(vhost, nick)
 
+                       message = 'vHost resolves (%s => %s)' % (host, resolved)
+
                        if resolving_error == "timeout":
-                               return (False, "Rejected vHost", "DNS Timeout when trying to check TXT record for vhost @b{}@b requested by @b{}@b.".format(
-                                       vhost, nick))
-                       elif resolving_error:
-                               return (False, "Unkown error", "The following error occured when checking TXT record for vhost @b{}@b requested by @b{}@b @sep {}.".format(
-                                       vhost, nick, resolving_error))
+                               message = "DNS Timeout when trying to check TXT record for vhost @b{}@b requested by @b{}@b.".format(vhost, nick)
+                       elif resolving_error == "noentry":
+                               message = "@b{}@b not found in TXT record of @b{}@b".format(nick, vhost)
+                       elif resolving_error != "norecord":
+                               message = "The following error occured when checking TXT record for vhost @b{}@b requested by @b{}@b @sep {}.".format(vhost, nick, resolving_error)
 
                        if 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, 
-                                       'vHost resolves (%s => %s)' % (host, resolved)) 
+                               return (True, '@c9Acceptable@c', message, True)
                        else:
-                               return (True, '@c9Acceptable@c', 'TXT record')
+                               return (True, '@c9Acceptable@c', 'vHost resolved but its ownership was verified by the existence of a DNS TXT record', False)
 
-               return (True, '@c9Acceptable@c', None)
+               return (True, '@c9Acceptable@c', None, False)
 
        def __is_numeric_ip(self, host):
                try:
@@ -432,8 +435,10 @@ class RequestManager(object):
                                                nicks = [n.lower().strip() for n in parts[1].split(',')]
                                                if nick.lower() in nicks:
                                                        return (True, "")
-                       return (False, "")
+                       return (False, "noentry")
                except dns.exception.Timeout, e:
                        return (False, "timeout")
+               except dns.resolver.NoAnswer, e:
+                       return (False, "norecord")
                except Exception, e:
                        return (False, str(e))