mirror of
https://codeberg.org/prof_x_pvt_ltd/captive.whump.shanti-portal
synced 2024-08-14 22:46:42 +00:00
50 lines
950 B
Python
50 lines
950 B
Python
#!/usr/bin/env python
|
|
|
|
from sys import exit
|
|
from argparse import ArgumentParser, FileType
|
|
from pprint import pprint as pp
|
|
from configparser import RawConfigParser
|
|
|
|
import errors
|
|
from storage import StoragePostgres
|
|
from client import Client
|
|
|
|
parser = ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
'--protocol',
|
|
required=True,
|
|
choices=['tcp', 'udp'],
|
|
help='Protocol for client'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--config',
|
|
type=FileType('r'),
|
|
required=True,
|
|
help='Configuration file'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'src_ip',
|
|
help='Client source IP to add'
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
config = RawConfigParser()
|
|
config.readfp(args.config)
|
|
|
|
sr = StoragePostgres(config=config)
|
|
try:
|
|
client = Client(
|
|
storage=sr,
|
|
ip_address=args.src_ip,
|
|
protocol=args.protocol,
|
|
chain=config.get('iptables', 'chain')
|
|
)
|
|
except errors.StorageNotFound:
|
|
print('Could not find client')
|
|
exit(1)
|
|
|
|
client.delete()
|