2021-07-28 14:03:52 +00:00
|
|
|
import datetime
|
|
|
|
import pytz
|
|
|
|
|
|
|
|
UTC = pytz.utc
|
|
|
|
date = datetime.datetime.now(UTC)
|
|
|
|
|
2021-08-02 14:18:58 +00:00
|
|
|
def linecounter(incoming):
|
|
|
|
with open(incoming) as f:
|
2021-07-28 14:03:52 +00:00
|
|
|
for i, l in enumerate(f):
|
|
|
|
pass
|
|
|
|
return i + 1
|
|
|
|
|
2021-08-20 07:52:37 +00:00
|
|
|
def RPZbuilding(excluded,incoming,output,Version):
|
2021-08-02 15:17:07 +00:00
|
|
|
ankstanop = linecounter(incoming)
|
2021-07-28 14:03:52 +00:00
|
|
|
with open(excluded ,'r') as f:
|
|
|
|
exclude = f.read().split()
|
2021-08-02 14:18:58 +00:00
|
|
|
with open(incoming ,'r') as f:
|
2021-07-28 14:03:52 +00:00
|
|
|
lines = f.read().splitlines() # read lines
|
|
|
|
with open(output ,'w') as f:
|
|
|
|
f.write('; Title : Minoplhy Personal Blocklist\n')
|
|
|
|
f.write('; Description : My Very Personal DNS Blocklist plus crawling from the source\n')
|
2021-08-01 11:07:39 +00:00
|
|
|
f.write('; Source : Resources/Source.txt\n')
|
2021-08-02 15:17:07 +00:00
|
|
|
f.write('; Rule Counter : ' + str(ankstanop) +' Rules\n')
|
2021-07-28 14:03:52 +00:00
|
|
|
f.write('; Format : RPZ\n')
|
2021-08-20 07:52:37 +00:00
|
|
|
f.write('; Type : Blocklist\n')
|
|
|
|
f.write('; Version : ' + str(Version) +'\n')
|
2021-07-28 14:03:52 +00:00
|
|
|
f.write('; Licenses : MIT\n')
|
2021-08-18 04:57:39 +00:00
|
|
|
f.write('; Compiled Date : ' + str(date) +'\n;\n')
|
2021-08-16 15:11:08 +00:00
|
|
|
f.write('$TTL 30\n')
|
2021-07-28 14:03:52 +00:00
|
|
|
f.write('@ IN SOA localhost. root.localhost. (1 6h 1h 1w 2h)\n')
|
2021-08-18 04:57:39 +00:00
|
|
|
f.write(' NS localhost.\n;\n')
|
2021-07-28 14:03:52 +00:00
|
|
|
for line in lines:
|
|
|
|
if line.strip() and not line in exclude and not line.startswith(';'):
|
2021-08-18 09:57:42 +00:00
|
|
|
f.write('\n'.join([line + ' CNAME .\n'])) and f.write('\n'.join(['*.' + line + ' CNAME .\n']))
|
2021-08-02 15:30:58 +00:00
|
|
|
elif line.startswith((';','$','@',' IN')):
|
2021-07-28 14:03:52 +00:00
|
|
|
f.write('\n'.join([line + '\n']))
|
2021-08-20 07:52:37 +00:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
def ABPallowlist(incoming,output,Version):
|
|
|
|
ankstanop = linecounter(incoming)
|
|
|
|
with open(incoming ,'r') as f:
|
|
|
|
lines = f.read().splitlines() # read lines
|
|
|
|
with open(output ,'w') as f:
|
|
|
|
f.write('; Title : Minoplhy Personal Blocklist\n')
|
|
|
|
f.write('; Description : My Very Personal DNS Blocklist plus crawling from the source\n')
|
|
|
|
f.write('; Source : Resources/Source.txt\n')
|
|
|
|
f.write('; Rule Counter : ' + str(ankstanop) +' Rules\n')
|
|
|
|
f.write('; Format : Domains\n')
|
|
|
|
f.write('; Type : Allowlist\n')
|
|
|
|
f.write('; Version : ' + str(Version) +'\n')
|
|
|
|
f.write('; Licenses : MIT\n')
|
|
|
|
f.write('; Compiled Date : ' + str(date) +'\n\n')
|
|
|
|
for line in lines:
|
|
|
|
if line.strip() and not line.startswith(';'):
|
|
|
|
f.write('\n'.join([line + 'CNAME rpz-passthru.\n']))
|
|
|
|
elif line.startswith((';','$','@',' IN')):
|
|
|
|
f.write('\n'.join([line + '\n']))
|
2021-08-05 13:38:01 +00:00
|
|
|
f.close()
|