2019-12-09 08:12:48 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import database
|
|
|
|
import argparse
|
|
|
|
import sys
|
2019-12-13 13:54:00 +01:00
|
|
|
import time
|
2019-12-09 08:12:48 +01:00
|
|
|
|
2019-12-13 08:23:38 +01:00
|
|
|
FUNCTION_MAP = {
|
|
|
|
'zone': database.Database.set_zone,
|
|
|
|
'ip4network': database.Database.set_ip4network,
|
|
|
|
'asn': database.Database.set_asn,
|
|
|
|
}
|
2019-12-09 08:12:48 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
# Parsing arguments
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="TODO")
|
|
|
|
parser.add_argument(
|
|
|
|
'type',
|
2019-12-13 08:23:38 +01:00
|
|
|
choices=FUNCTION_MAP.keys(),
|
2019-12-09 08:12:48 +01:00
|
|
|
help="Type of rule inputed")
|
|
|
|
parser.add_argument(
|
|
|
|
'-i', '--input', type=argparse.FileType('r'), default=sys.stdin,
|
|
|
|
help="List of domains domains to block (with their subdomains)")
|
|
|
|
parser.add_argument(
|
|
|
|
'-f', '--first-party', action='store_true',
|
|
|
|
help="The input only comes from verified first-party sources")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2019-12-15 15:56:26 +01:00
|
|
|
DB = database.Database()
|
2019-12-13 00:11:21 +01:00
|
|
|
|
|
|
|
fun = FUNCTION_MAP[args.type]
|
|
|
|
|
2019-12-16 19:07:35 +01:00
|
|
|
source: database.RulePath
|
|
|
|
if args.first_party:
|
|
|
|
source = database.RuleFirstPath()
|
|
|
|
else:
|
|
|
|
source = database.RuleMultiPath()
|
|
|
|
|
2019-12-13 00:11:21 +01:00
|
|
|
for rule in args.input:
|
2019-12-13 13:54:00 +01:00
|
|
|
fun(DB,
|
|
|
|
rule.strip(),
|
2019-12-16 19:07:35 +01:00
|
|
|
source=source,
|
2019-12-13 13:54:00 +01:00
|
|
|
updated=int(time.time()),
|
|
|
|
)
|
2019-12-13 00:11:21 +01:00
|
|
|
|
2019-12-15 15:56:26 +01:00
|
|
|
DB.save()
|