diff --git a/py/client.py b/py/client.py new file mode 100755 index 0000000..33c0258 --- /dev/null +++ b/py/client.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +import ipaddress +import os +import signal +import socket +import json +from collections.abc import Iterable + +if __name__ == "__main__": + socket_path = "/run/ipban/ipban.sock" + + client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + client.connect(socket_path) + + client.sendall(b"""action +{ + "ban": { + "1.2.3.4": { + "remark": "Cloudflare's web", + "reason": "bot" + }, + "8.8.8.8": { + "remark": "", + "reason": "" + } + }, + "uban": { + "1.3.3.7": { + "reason": "Misstake" + }, + "1.0.0.1": { + "reason": "DNS" + } + } +} +""") + client.shutdown(socket.SHUT_WR) + print(client.recv(4096).decode()) diff --git a/py/daemon.py b/py/daemon.py index ec398fa..6ae36ac 100755 --- a/py/daemon.py +++ b/py/daemon.py @@ -29,7 +29,7 @@ def destroy_nft_table(): nft = Nftables() rc, output, error = nft.cmd("destroy table inet ipban") -#delete old table, create new, and fill with ip's +#delete old table, create new, and fill it with ip's def flush_nft(ips : Iterable[ipaddress.IPv4Address]): nft = Nftables() ips_str = "" @@ -92,6 +92,7 @@ def action(sql_conn: sqlite3.Connection, conn: socket.socket, data: str): print("Not implemented yet") break add_to_end_nft(ips_to_ban) + conn.sendall(b"ok") def list_ips(sql_conn: sqlite3.Connection, conn: socket.socket, data: str): data = data[data.find('\n')+1:] #strip req_type