Commit be241e55 authored by Vitaly Lipatov's avatar Vitaly Lipatov

gateway: fix IPv6 unban and report delivery failure

parent 9b775f5b
...@@ -380,13 +380,16 @@ def process_message(message): ...@@ -380,13 +380,16 @@ def process_message(message):
elif message is not None and message['type'] =='message' and message['channel'] == b'unban' : elif message is not None and message['type'] =='message' and message['channel'] == b'unban' :
print (message) print (message)
ip = message['data'].decode('utf-8') ip = message['data'].decode('utf-8')
try:
ipo = ipaddress.ip_network(ip, strict=False) ipo = ipaddress.ip_network(ip, strict=False)
if isinstance(ipo, ipaddress.IPv6Address): except ValueError:
log.write("Not parsed as IP, skipped " + str(ip) + '\n')
log.flush()
return
if isinstance(ipo, ipaddress.IPv6Network):
unban = 'ipset -D ' + ipset_eterban_1_ipv6 + ' ' + ip unban = 'ipset -D ' + ipset_eterban_1_ipv6 + ' ' + ip
elif isinstance(ipo, ipaddress.IPv4Network): elif isinstance(ipo, ipaddress.IPv4Network):
unban = 'ipset -D ' + ipset_eterban_1 + ' ' + ip unban = 'ipset -D ' + ipset_eterban_1 + ' ' + ip
else:
log.write("Not parsed as IP, skipped " + str(ip) + '\n')
#add = 'ipset -A ' + ipset_eterban_white + ' ' + ip #add = 'ipset -A ' + ipset_eterban_white + ' ' + ip
subprocess.call (unban, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell = True) subprocess.call (unban, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell = True)
#subprocess.call (add, shell = True) #subprocess.call (add, shell = True)
......
...@@ -34,8 +34,12 @@ if not ip: ...@@ -34,8 +34,12 @@ if not ip:
try: try:
r = redis.Redis (host=redis_server) r = redis.Redis (host=redis_server)
r.publish ('unban', ip) subscribers = r.publish ('unban', ip)
if subscribers == 0:
print("No eterban Redis subscribers; IP was not unblocked")
sys.exit(1)
message = ip + " was unblocked by admin on " + hostname message = ip + " was unblocked by admin on " + hostname
r.publish ('by', message) r.publish ('by', message)
except: except Exception as error:
print("Error with connect to redis " + redis_server) print("Error with connect to redis " + redis_server + ": " + str(error))
sys.exit(1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment