Added client as proof of work
This commit is contained in:
parent
5d9cd3c207
commit
4baea9e626
2 changed files with 41 additions and 1 deletions
39
py/client.py
Executable file
39
py/client.py
Executable file
|
|
@ -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())
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue