diff --git a/__pycache__/config.cpython-38.pyc b/__pycache__/config.cpython-38.pyc index 2c3345f..bf4d66c 100644 Binary files a/__pycache__/config.cpython-38.pyc and b/__pycache__/config.cpython-38.pyc differ diff --git a/__pycache__/plugin.cpython-38.pyc b/__pycache__/plugin.cpython-38.pyc index 790a6db..8a822d7 100644 Binary files a/__pycache__/plugin.cpython-38.pyc and b/__pycache__/plugin.cpython-38.pyc differ diff --git a/config.py b/config.py index a3a96e9..4c4f08d 100644 --- a/config.py +++ b/config.py @@ -61,4 +61,53 @@ conf.registerGlobalValue(SnoParser, 'AutoVhost', conf.registerGlobalValue(SnoParser, 'preventHighlight', registry.Boolean(True, ("""Toggles in channel highlights with ZWSP"""))) +conf.registerGroup(SnoParser, 'whois') +conf.registerGlobalValue(SnoParser.whois, 'debug', + registry.Boolean('false', + """ + SnoParser: True: Very verbose console output. False: Mostly silent operation. + """ + , private=True +)) +conf.registerGroup(SnoParser.whois, 'redis') +conf.registerGlobalValue(SnoParser.whois.redis, 'host', + registry.String('127.0.0.1', + """ + Redis: IP address or hostname. + """ + , private=True +)) +conf.registerGlobalValue(SnoParser.whois.redis, 'port', + registry.String('6379', + """ + Redis: Port. + """ + , private=True +)) +conf.registerGlobalValue(SnoParser.whois.redis, 'username', + registry.String('', + """ + Redis: Username. This is optional and has not been tested. It is recommended to perform initial tests on a local instance with no username and password. + """ + , private=True +)) +conf.registerGlobalValue(SnoParser.whois.redis, 'password', + registry.String('', + """ + Redis: Password. This is optional and has not been tested. It is recommended to perform initial tests on a local instance with no username and password. + """ +)) +conf.registerGlobalValue(SnoParser.whois.redis, 'db', + registry.String('0', + """ + Redis: Database number. It is recommended to use a dedicated, isolated, Redis instance for SnoParser instead of using an existing one with a different database. + """ +)) +conf.registerGlobalValue(SnoParser.whois.redis, 'timeout', + registry.String('5', + """ + Redis: Socket Timeout. The developer does not know what to recommend here, but `5` seems to yield good results. + """ +)) + # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/plugin.py b/plugin.py index bfa31a9..6b29756 100644 --- a/plugin.py +++ b/plugin.py @@ -56,11 +56,12 @@ class SnoParser(callbacks.Plugin): def redis_connect() -> redis.client.Redis: try: redis_client = redis.Redis( - host="localhost", - port=6378, - #password="test", - db=0, - socket_timeout=5, + host = .registryValue('whois.redis.host'), + port = self.registryValue('whois.redis.port'), + password = self.registryValue('whois.redis.password'), + username = self.registryValue('whois.redis.username'), + db = self.registryValue('whois.redis.db'), + socket_timeout = self.registryValue('whois.redis.timeout') ) ping = redis_client.ping() if ping is True: @@ -70,12 +71,12 @@ class SnoParser(callbacks.Plugin): redis_client = redis_connect() - def whois_fresh(coordinates: str) -> dict: + def whois_fresh(sourceip: str) -> dict: """Data from cache.""" asn = 0 subnet = '' try: - whois = IPWhois(coordinates) + whois = IPWhois(sourceip) whoisres = whois.lookup_rdap(depth=1,retry_count=0) results = whoisres print(results) @@ -86,10 +87,6 @@ class SnoParser(callbacks.Plugin): except ipwhois.exceptions.IPDefinedError: whoisout = 'RFC 4291 (Local)' -# rr = f"{results}" -# response = rr -# return response.json() -# response = results response = whoisout return response @@ -105,28 +102,30 @@ class SnoParser(callbacks.Plugin): state = SnoParser.redis_client.setex(key, timedelta(seconds=3600), value=value,) return state - def whois_run(coordinates: str) -> dict: - data = SnoParser.whois_get_cache(key=coordinates) + def whois_run(sourceip: str) -> dict: + """Whois query router.""" + + data = SnoParser.whois_get_cache(key=sourceip) if data is not None: data = json.loads(data) #data["cache"] = True print("DEBUG - CACHE: TRUE") print(data) - print(coordinates) + print(sourceip) return data else: - data = SnoParser.whois_fresh(coordinates) - print("ELSE WHOIS_FRESH CALLED") + data = SnoParser.whois_fresh(sourceip) + print("DEBUG - ELSE WHOIS_FRESH CALLED") print(data) - print(coordinates) + print(sourceip) if data.startswith("WHOIS"): #data["cache"] = False print("DEBUG - CACHE: FALSE") data = json.dumps(data) - state = SnoParser.whois_set_cache(key=coordinates, value=data) + state = SnoParser.whois_set_cache(key=sourceip, value=data) print(data) - print(coordinates) + print(sourceip) if state is True: return json.loads(data) @@ -149,31 +148,14 @@ class SnoParser(callbacks.Plugin): username = couple.group(2) host = couple.group(3) #ip = couple.group(4) - ip = '::1' + ip = '2a03:4000:55:d20::' realname = couple.group(5) ip_seen = 0 nick_seen = 0 asn = 0 subnet = '' -# SnoParser.whois_run(coordinates=ip) whoisout = SnoParser.whois_run(ip) -# whoisout = SnoParser.whois_run(whoisout) -# SnoParser.whois_run(ip) -# whoisout = SnoParser.whois_run.coordinates - -# try: -# #whois = IPWhois(ip) -# #whoisres = whois.lookup_rdap(depth=1,retry_count=0) -# #results = whoisres -# whoisres = data -# print(results) -# asn = whoisres['asn_registry'] -# country = whoisres['asn_country_code'] -# description = whoisres['asn_description'] -# whoisout = asn + ' ' + country + ' ' + description -# except ipwhois.exceptions.IPDefinedError: -# whoisout = 'RFC 4291 (Local)' DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen} #repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" repl = f"\x02\x1F{DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} {whoisout} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}"