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 ''))
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())
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:
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))