init commit

This commit is contained in:
Minoplhy 2021-05-28 14:06:52 +07:00
commit 8bf6ed09c2
8 changed files with 404 additions and 0 deletions

12
README.md Normal file
View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

58
to-rpz/host_rpz_argv.py Normal file
View File

@ -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()

View File

@ -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()