54 lines
1.4 KiB
Python
Executable File
54 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(1, "./fail2ban-p2p")
|
|
sys.path.insert(2, "/usr/share/fail2ban-p2p/fail2ban-p2p")
|
|
|
|
import config
|
|
import crypto
|
|
import log
|
|
import node
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description='fail2ban-p2p help.')
|
|
parser.add_argument('-K', action='store_true', help='Create private/public keypair')
|
|
parser.add_argument('-c', default='/etc/fail2ban-p2p/', help='Read configuration from DIR.', metavar='DIR')
|
|
args = parser.parse_args()
|
|
|
|
c = config.Config()
|
|
c.configPath = args.c or "/etc/fail2ban-p2p"
|
|
c.privkey = os.path.join(c.configPath, 'private.pem')
|
|
c.pubkey = os.path.join(c.configPath, 'public.pem')
|
|
|
|
if c.loadConfig() is False:
|
|
raise OSError('Config error, check log.')
|
|
|
|
logger = log.initialize_logging("fail2ban-p2p")
|
|
|
|
if args.K:
|
|
crypto.create_keys()
|
|
sys.exit(0)
|
|
|
|
if not os.path.isfile(c.privkey) or not os.path.isfile(c.pubkey):
|
|
logger.warning('Private or public key not found, creating them')
|
|
crypto.create_keys()
|
|
|
|
n = None
|
|
try:
|
|
n = node.Node()
|
|
n.loadConfig()
|
|
n.getFriends()
|
|
n.requestBanlist()
|
|
n.cleanBanlist()
|
|
n.openSocket()
|
|
except KeyboardInterrupt:
|
|
logger.info("Keyboard Interrupt received, going down")
|
|
if n is not None:
|
|
n.cleanBanlistStop()
|
|
n.closeSocket()
|
|
logger.info("kthxbai!")
|