commit 8bf6ed09c211dc1372f3c0a09460c43eda544b5a Author: Minoplhy Date: Fri May 28 14:06:52 2021 +0700 init commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e44bd70 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +## Keeping filters converter + +## Available Converter + +### X -> RPZ +X = * adguard +X = * adguard_wildcards [Domains itself and all subdomain] +X = * domains +X = * domains_wildcards [Domains itself and all subdomain] +X = * dnsmasq +X = * hostfile +X = * unbound \ No newline at end of file diff --git a/to-rpz/adguard-host-wildcards_rpz_argv.py b/to-rpz/adguard-host-wildcards_rpz_argv.py new file mode 100644 index 0000000..64f119c --- /dev/null +++ b/to-rpz/adguard-host-wildcards_rpz_argv.py @@ -0,0 +1,55 @@ +import os +import sys +from re import sub +from shutil import copyfile + +infile = sys.argv[1] +outfile = sys.argv[2] + +f = open(infile,'r') +a = ['||','^'] +lst = [] +for line in f: + for word in a: + if word in line: + line = line.replace(word,'') + lst.append(line) +f.close() +f = open(infile,'w') +for line in lst: + f.write(line) +f.close() + +with open(infile) as f: + file = f.read().split('\n') +for i in range(len(file)): + file[i] = sub(r'!', ';', file[i]) +#print(file) +with open(infile, 'w') as f1: + f1.writelines(["%s\n" % item for item in file]) +f.close() + +with open(infile, 'r') as f: # load file + lines = f.read().splitlines() # read lines +with open(infile, 'w') as f: # load file in write mode + for line in lines: + if line.startswith(';'): + f.write('\n'.join([line + '\n'])) + elif not line.startswith(';'): + f.write('\n'.join([line + '\n'])) and f.write('\n'.join(['*.'+line+'\n'])) # add *. and CNAME . if file does not start with ; +f.close() + +with open(infile, 'r') as f: # load file + lines = f.read().splitlines() # read lines +with open(infile, 'w') as f: # load file in write mode + for line in lines: + if line.startswith(';'): + f.write('\n'.join([line + '\n'])) + elif line.startswith('*.') or not line.startswith(';'): + f.write('\n'.join([line + ' CNAME .\n'])) # add CNAME . if line start with *. +f.close() + +copyfile(infile, outfile) # copy input file to output file +os.remove(infile) # remove input file + +exit() diff --git a/to-rpz/adguard-host_rpz_argv.py b/to-rpz/adguard-host_rpz_argv.py new file mode 100644 index 0000000..a7f10b1 --- /dev/null +++ b/to-rpz/adguard-host_rpz_argv.py @@ -0,0 +1,63 @@ +import os +import sys +from re import sub +from shutil import copyfile + +infile = sys.argv[1] +outfile = sys.argv[2] + +f = open(infile,'r') +a = ['||','^','|'] +lst = [] +for line in f: + for word in a: + if word in line: + line = line.replace(word,'') + lst.append(line) +f.close() +f = open(infile,'w') +for line in lst: + f.write(line) +f.close() + +with open(infile) as f: + file = f.read().split('\n') +for i in range(len(file)): + file[i] = sub(r'!', ';', file[i]) +#print(file) +with open(infile, 'w') as f1: + f1.writelines(["%s\n" % item for item in file]) +f.close() + +with open(infile, 'r') as f: # load file + lines = f.read().splitlines() # read lines +with open(infile, 'w') as f: # load file in write mode + for line in lines: + if line.startswith(';'): + f.write('\n'.join([line + '\n'])) + elif line.startswith('@@'): + f.write('\n'.join([line + ' CNAME rpz-passthru.\n'])) + elif not line.strip(): + f.write('\n'.join([line + '\n'])) + elif not line.startswith(';') and not line.startswith('@@') and line.strip(): + f.write('\n'.join([line + ' CNAME .\n'])) # add CNAME . if file does not start with ; +f.close() + +f = open(infile,'r') +a = ['@@'] +lst = [] +for line in f: + for word in a: + if word in line: + line = line.replace(word,'') + lst.append(line) +f.close() +f = open(infile,'w') +for line in lst: + f.write(line) +f.close() + +copyfile(infile, outfile) # copy input file to output file +os.remove(infile) # remove input file + +exit() \ No newline at end of file diff --git a/to-rpz/dnsmasq_rpz_argv.py b/to-rpz/dnsmasq_rpz_argv.py new file mode 100644 index 0000000..ef34c60 --- /dev/null +++ b/to-rpz/dnsmasq_rpz_argv.py @@ -0,0 +1,47 @@ +import os +import sys +from re import sub +from shutil import copyfile + +infile = sys.argv[1] +outfile = sys.argv[2] + +f = open(infile,'r') +a = ['address=/','/#','server=/','/','127.0.0.1','0.0.0.0','::1'] +lst = [] +for line in f: + for word in a: + if word in line: + line = line.replace(word,'') + lst.append(line) +f.close() +f = open(infile,'w') +for line in lst: + f.write(line) +f.close() + +with open(infile) as f: + file = f.read().split('\n') +for i in range(len(file)): + file[i] = sub(r'#', ';', file[i]) +#print(file) +with open(infile, 'w') as f1: + f1.writelines(["%s\n" % item for item in file]) +f.close() + +with open(infile, 'r') as f: # load file + lines = f.read().splitlines() # read lines +with open(infile, 'w') as f: # load file in write mode + for line in lines: + if line.startswith(';'): + f.write('\n'.join([line + '\n'])) + elif not line.strip(): + f.write('\n'.join([line + '\n'])) + elif not line.startswith(';') and line.strip(): + f.write('\n'.join([line + ' CNAME .\n'])) # add CNAME . if file does not start with ; +f.close() + +copyfile(infile, outfile) # copy input file to output file +os.remove(infile) # remove input file + +exit() \ No newline at end of file diff --git a/to-rpz/domains_rpz_argv.py b/to-rpz/domains_rpz_argv.py new file mode 100644 index 0000000..c03df95 --- /dev/null +++ b/to-rpz/domains_rpz_argv.py @@ -0,0 +1,47 @@ +import os +import sys +from re import sub +from shutil import copyfile + +infile = sys.argv[1] +outfile = sys.argv[2] + +with open(infile) as f: + file = f.read().split('\n') +for i in range(len(file)): + file[i] = sub(r'#', ';', file[i]) +#print(file) +with open(infile, 'w') as f1: + f1.writelines(["%s\n" % item for item in file]) +f.close() + +with open(infile, 'r') as f: # load file + lines = f.read().splitlines() # read lines +with open(infile, 'w') as f: # load file in write mode + for line in lines: + if line.startswith(';'): + f.write('\n'.join([line + '\n'])) + elif not line.strip(): + f.write('\n'.join([line + '\n'])) + elif not line.startswith(';') and line.strip(): + f.write('\n'.join([line + ' CNAME .\n'])) # add CNAME . if file does not start with ; +f.close() + +f = open(infile,'r') +a = ['@@'] +lst = [] +for line in f: + for word in a: + if word in line: + line = line.replace(word,'') + lst.append(line) +f.close() +f = open(infile,'w') +for line in lst: + f.write(line) +f.close() + +copyfile(infile, outfile) # copy input file to output file +os.remove(infile) # remove input file + +exit() \ No newline at end of file diff --git a/to-rpz/domains_wildcards_rpz_argv.py b/to-rpz/domains_wildcards_rpz_argv.py new file mode 100644 index 0000000..7f771f9 --- /dev/null +++ b/to-rpz/domains_wildcards_rpz_argv.py @@ -0,0 +1,59 @@ +import os +import sys +from re import sub +from shutil import copyfile + +infile = sys.argv[1] +outfile = sys.argv[2] + +f = open(infile,'r') +a = ['*.'] +lst = [] +for line in f: + for word in a: + if word in line: + line = line.replace(word,'') + lst.append(line) +f.close() +f = open(infile,'w') +for line in lst: + f.write(line) +f.close() + +with open(infile) as f: + file = f.read().split('\n') +for i in range(len(file)): + file[i] = sub(r'#', ';', file[i]) +#print(file) +with open(infile, 'w') as f1: + f1.writelines(["%s\n" % item for item in file]) +f.close() + +with open(infile, 'r') as f: # load file + lines = f.read().splitlines() # read lines +with open(infile, 'w') as f: # load file in write mode + for line in lines: + if line.startswith(';'): + f.write('\n'.join([line + '\n'])) + elif not line.strip(): + f.write('\n'.join([line + '\n'])) + elif not line.startswith(';') and line.strip(): + f.write('\n'.join([line + '\n'])) and f.write('\n'.join(['*.'+line+'\n'])) # add *. and CNAME . if file does not start with ; +f.close() + +with open(infile, 'r') as f: # load file + lines = f.read().splitlines() # read lines +with open(infile, 'w') as f: # load file in write mode + for line in lines: + if line.startswith(';'): + f.write('\n'.join([line + '\n'])) + elif not line.strip(): + f.write('\n'.join([line + '\n'])) + elif line.startswith('*.') or not line.startswith(';') and line.strip(): + f.write('\n'.join([line + ' CNAME .\n'])) # add CNAME . if line start with *. +f.close() + +copyfile(infile, outfile) # copy input file to output file +os.remove(infile) # remove input file + +exit() diff --git a/to-rpz/host_rpz_argv.py b/to-rpz/host_rpz_argv.py new file mode 100644 index 0000000..5c18f34 --- /dev/null +++ b/to-rpz/host_rpz_argv.py @@ -0,0 +1,58 @@ +import os +import sys +from re import sub +from shutil import copyfile + +infile = sys.argv[1] +outfile = sys.argv[2] + +f = open(infile,'r') +a = ['0.0.0.0','::1','127.0.0.1','0','::'] +lst = [] +for line in f: + for word in a: + if word in line: + line = line.replace(word,'') + lst.append(line) +f.close() +f = open(infile,'w') +for line in lst: + f.write(line) +f.close() + +with open(infile) as f: + file = f.read().split('\n') +for i in range(len(file)): + file[i] = sub(r'#', ';', file[i]) +#print(file) +with open(infile, 'w') as f1: + f1.writelines(["%s\n" % item for item in file]) +f.close() + +with open(infile, 'r') as f: # load file + lines = f.read().splitlines() # read lines +with open(infile, 'w') as f: # load file in write mode + for line in lines: + if line.startswith(';'): + f.write('\n'.join([line + '\n'])) + elif not line.strip(): + f.write('\n'.join([line + '\n'])) + elif line.startswith('-'): + f.write('\n'.join([line + '\n'])) + elif not line.startswith(';') and not line.startswith('-') and line.strip(): + f.write('\n'.join([line + ' CNAME .\n'])) # add CNAME . if file does not start with ; +f.close() + +remove_words = ['localhost','localhost.localdomain','local','broadcasthost','loopback','ip6-localnet','ip6-mcastprefix','ip6-allnodes','ip6-allrouters','ip6-allhosts'] + +with open(infile, 'r') as f: + lines = f.read().splitlines() +with open(infile, 'w') as f: + for line in lines: + if not any(remove_word in line for remove_word in remove_words): + f.write('\n'.join([line + '\n'])) + +copyfile(infile, outfile) # copy input file to output file +os.remove(infile) # remove input file + +exit() \ No newline at end of file diff --git a/to-rpz/unbound_rpz_argv.py b/to-rpz/unbound_rpz_argv.py new file mode 100644 index 0000000..f5ba1a6 --- /dev/null +++ b/to-rpz/unbound_rpz_argv.py @@ -0,0 +1,63 @@ +import os +import sys +from re import sub +from shutil import copyfile + +infile = sys.argv[1] +outfile = sys.argv[2] + +f = open(infile,'r') +a = ['local-data: ','"','local-zone: ','always_refuse','A','127.0.0.1','always_nxdomain'] +lst = [] +for line in f: + for word in a: + if word in line: + line = line.replace(word,'') + lst.append(line) +f.close() +f = open(infile,'w') +for line in lst: + f.write(line) +f.close() + +with open(infile) as f: + file = f.read().split('\n') +for i in range(len(file)): + file[i] = sub(r'#', ';', file[i]) +#print(file) +with open(infile, 'w') as f1: + f1.writelines(["%s\n" % item for item in file]) +f.close() + +with open(infile, 'r') as f: # load file + lines = f.read().splitlines() # read lines +with open(infile, 'w') as f: # load file in write mode + for line in lines: + if line.startswith(';'): + f.write('\n'.join([line + '\n'])) + elif not line.strip(): + f.write('\n'.join([line + '\n'])) + elif line.strip() and not line.startswith(';') and not line.endswith('transparent') and not line.endswith('redirect'): + f.write('\n'.join([line + ' CNAME .\n'])) # add CNAME . if file does not start with ; + elif line.endswith('transparent'): + f.write('\n'.join([line + ' CNAME rpz-passthru.\n'])) +f.close() + +f = open(infile,'r') +a = ['transparent','static'] +lst = [] +for line in f: + for word in a: + if word in line: + line = line.replace(word,'') + lst.append(line) +f.close() +f = open(infile,'w') +for line in lst: + f.write(line) +f.close() + +copyfile(infile, outfile) # copy input file to output file +os.remove(infile) # remove input file + +exit() \ No newline at end of file