view make-tld-conf.py @ 477:331facb7b970 default tip

Added tag stable-6-0-78 for changeset fcf66a7aead5
author Carl Byington <carl@five-ten-sg.com>
date Sat, 20 Feb 2021 10:59:24 -0800
parents f5b394bec28c
children
line wrap: on
line source

#!/usr/bin/python3

import os, sys, time

def cmd(c):
    print(c)
    return os.popen(c).read().rstrip('\n')

url = 'https://publicsuffix.org/list/effective_tld_names.dat'
c = 'curl %s 2>/dev/null' % url
content = cmd(c)
f=open('tld.conf','w')
f.write(time.strftime("// generated by make-tld-conf.py on %Y-%m-%d %H:%M:%S\n\n"))
for x in content.split('\n'):
    if (x == '') or (x[:2] == '//'): f.write('%s\n' % x)
    else:
        if x[:1] == '!':
            x = x[1:]
            prefix = '!'
        else:
            prefix = ''
        yy = []
        for xx in x.split('.'):
            z = xx.encode('punycode').decode('utf8')
            if z[-1:] == '-': yy.append(xx)
            else:             yy.append('xn--%s' % z)
        y = '.'.join(yy)
        if not (y == x):
            f.write('// %s%s\n' % (prefix, x))
            x = y
        if not prefix and (len(x.split('.')) == 1):
            rc = cmd("dig %s ns +short 2>&1" % x)
            if not rc:
                rc = cmd("sleep 3; dig %s ns +short 2>&1" % x)
                if not rc: prefix = '// no ns record for '
        f.write('%s%s\n' % (prefix, x))
f.write('\n')
f.write('\n')
f.write('// add some TLDs from our rpz zone so names under them\n')
f.write('// can be added to uribl style lists\n')
f.write('\n')

c="grep '^\*.*multi.surbl' /etc/cron.daily/rpz | awk '{print $1}' | cut -c3- | sed -e 's/.multi.surbl.org//g' | grep '\.'"
content = cmd(c)
for x in content.split('\n'):
    f.write(x + '\n')

f.write('\n')
c="grep '^[^\*].*multi.surbl' /etc/cron.daily/rpz | egrep -v 'CNAME|g.write' | awk '{print $1}' | sed -e 's/.multi.surbl.org//g' | cut -d. -f2- | grep '\.'"
content = cmd(c)
for x in content.split('\n'):
    f.write(x + '\n')

f.close()