ipquery IP validation + repaired config integers

Signed-off-by: Georg <georg@lysergic.dev>
This commit is contained in:
Georg Pfuetzenreuter 2021-08-31 16:29:17 +02:00
parent 14e7d4e74e
commit 46596e0b33
Signed by: Georg
GPG Key ID: 1DAF57F49F8E8F22
2 changed files with 24 additions and 22 deletions

View File

@ -74,14 +74,14 @@ conf.registerGlobalValue(SnoParser, 'debug',
### ###
conf.registerGroup(SnoParser, 'redis') conf.registerGroup(SnoParser, 'redis')
conf.registerGlobalValue(SnoParser.redis, 'db1', conf.registerGlobalValue(SnoParser.redis, 'db1',
registry.Integer('1', registry.Integer(1,
""" """
Redis: Database number for counting of NICKNAMES. Redis: Database number for counting of NICKNAMES.
""" """
, private=True , private=True
)) ))
conf.registerGlobalValue(SnoParser.redis, 'db2', conf.registerGlobalValue(SnoParser.redis, 'db2',
registry.Integer('2', registry.Integer(2,
""" """
Redis: Database number for counting of IP ADDRESSES. Redis: Database number for counting of IP ADDRESSES.
""" """
@ -95,7 +95,7 @@ conf.registerGlobalValue(SnoParser.redis, 'host',
, private=True , private=True
)) ))
conf.registerGlobalValue(SnoParser.redis, 'port', conf.registerGlobalValue(SnoParser.redis, 'port',
registry.Integer('6379', registry.Integer(6379,
""" """
Redis: Port. Redis: Port.
""" """
@ -115,7 +115,7 @@ conf.registerGlobalValue(SnoParser.redis, 'password',
""" """
)) ))
conf.registerGlobalValue(SnoParser.redis, 'timeout', conf.registerGlobalValue(SnoParser.redis, 'timeout',
registry.Integer('5', registry.Integer(5,
""" """
Redis: Socket Timeout. The developer does not know what to recommend here, but `5` seems to yield good results. Redis: Socket Timeout. The developer does not know what to recommend here, but `5` seems to yield good results.
""" """
@ -141,7 +141,7 @@ conf.registerGlobalValue(SnoParser.whois, 'sample',
, private=True , private=True
)) ))
conf.registerGlobalValue(SnoParser.whois, 'ttl', conf.registerGlobalValue(SnoParser.whois, 'ttl',
registry.Integer('3600', registry.Integer(3600,
""" """
SnoParser: How long to cache WHOIS entries for. SnoParser: How long to cache WHOIS entries for.
""" """
@ -149,7 +149,7 @@ conf.registerGlobalValue(SnoParser.whois, 'ttl',
)) ))
conf.registerGroup(SnoParser.whois, 'redis') conf.registerGroup(SnoParser.whois, 'redis')
conf.registerGlobalValue(SnoParser.whois.redis, 'db', conf.registerGlobalValue(SnoParser.whois.redis, 'db',
registry.Integer('0', registry.Integer(0,
""" """
Redis: Database number for WHOIS query caching. Redis: Database number for WHOIS query caching.
""" """

View File

@ -168,7 +168,7 @@ class SnoParser(callbacks.Plugin):
print(data) print(data)
data = json.dumps(data) data = json.dumps(data)
state = self.whois_set_cache(key=sourceip, value=data) state = self.whois_set_cache(key=sourceip, value=data)
if state is True: if state is True:
return json.loads(data) return json.loads(data)
else: else:
@ -243,11 +243,10 @@ class SnoParser(callbacks.Plugin):
ttl = self.redis_client_whois.ttl(ipaddress) ttl = self.redis_client_whois.ttl(ipaddress)
count = self.redis_client_ips.get(ipaddress) count = self.redis_client_ips.get(ipaddress)
decoded_count = count.decode('utf-8') decoded_count = count.decode('utf-8')
print('SnoParser manual query: ', data, ' ', ttl) print('SnoParser manual query: ', data, ' ', ttl)
irc.reply(f'{decoded_data} - Count: {decoded_count} - Remaining: {ttl}s') irc.reply(f'{decoded_data} - Count: {decoded_count} - Remaining: {ttl}s')
ipquery = wrap(ipquery, ['anything']) ipquery = wrap(ipquery, ['ip'])
def doNotice(self, irc, msg): def doNotice(self, irc, msg):
@ -342,7 +341,7 @@ class SnoParser(callbacks.Plugin):
ip = couple.group(3) ip = couple.group(3)
DictFromSnotice = {'notice': 'accreg', 'hostmask': hostmask, 'account': account, 'ip': ip} DictFromSnotice = {'notice': 'accreg', 'hostmask': hostmask, 'account': account, 'ip': ip}
repl = f"\x02\x1FNOTICE: accreg -> [{account}] was registered by hostmask [{hostmask}] from IP {ip}" repl = f"\x02\x1FNOTICE: accreg -> [{account}] was registered by hostmask [{hostmask}] from IP {ip}"
# Trigger HS SET # Trigger HS SET
self._setvhost(irc, msg, account) self._setvhost(irc, msg, account)
@ -354,17 +353,20 @@ class SnoParser(callbacks.Plugin):
account = couple.group(2) account = couple.group(2)
DictFromSnotice = {'notice': 'sareg', 'oper': oper, 'account': account} DictFromSnotice = {'notice': 'sareg', 'oper': oper, 'account': account}
repl = f"\x02\x1FNOTICE: sareg -> [{account}] was registered by operator [{oper}]" repl = f"\x02\x1FNOTICE: sareg -> [{account}] was registered by operator [{oper}]"
self._setvhost(irc, msg, account) self._setvhost(irc, msg, account)
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
if 'OPER' in text and 'Client opered up' in text: if 'OPER' in text and 'Client opered up' in text:
operregex = "^-OPER- Client opered up \[(.*)\, \ (.*)\]$"
operregex = "^-OPER- Client opered up \[(.*)\]"
couple = re.match(operregex, text) couple = re.match(operregex, text)
account = couple.group(1) hostmask = couple.group(1)
DictFromSnotice = {'notice': 'oper'} oper = couple.group(2)
repl = f"\x02\x1FNOTICE:\x0F [{account}] opered up."
print(couple)
DictFromSnotice = {'notice': 'opered', 'hostmask': hostmask, 'oper': oper}
repl = f"\x02\x1FNOTICE:\x0F [{hostmask}] opered up as [{oper}]."
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
@ -373,14 +375,14 @@ class SnoParser(callbacks.Plugin):
operregex = "^-OPER- Client deopered \[(.*)\]" operregex = "^-OPER- Client deopered \[(.*)\]"
couple = re.match(operregex, text) couple = re.match(operregex, text)
account = couple.group(1) account = couple.group(1)
DictFromSnotice = {'notice': 'oper'} DictFromSnotice = {'notice': 'deopered', 'name': account}
repl = f"\x02\x1FNOTICE:\x0F [{account}] opered down." repl = f"\x02\x1FNOTICE:\x0F [{account}] opered down."
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
# Post Registration # Post Registration
def _setvhost(self, irc, msg, account): def _setvhost(self, irc, msg, account):
arg = ['SET'] arg = ['SET']
arg.append(account) arg.append(account)
@ -390,18 +392,18 @@ class SnoParser(callbacks.Plugin):
args=arg)) args=arg))
# Send formatted SNO to channel # Send formatted SNO to channel
def _sendSnotice(self, irc, msg, repl): def _sendSnotice(self, irc, msg, repl):
try: try:
channel = self.registryValue('targetChannel') channel = self.registryValue('targetChannel')
if channel[0] == '#': if channel[0] == '#':
irc.queueMsg(msg=ircmsgs.IrcMsg(command='NOTICE', irc.queueMsg(msg=ircmsgs.IrcMsg(command='NOTICE',
args=(channel, repl))) args=(channel, repl)))
# what sort of exception does one raise # what sort of exception does one raise
except: except:
pass pass
Class = SnoParser Class = SnoParser