Skip to content

Instantly share code, notes, and snippets.

@corpix
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corpix/909db099458ad737adb0 to your computer and use it in GitHub Desktop.
Save corpix/909db099458ad737adb0 to your computer and use it in GitHub Desktop.
Generates salt pillar sls with adv domains
import os
import re
import http.client
connection = http.client.HTTPConnection('pgl.yoyo.org')
connection.request('GET', '/as/serverlist.php?hostformat=one-line&mimetype=plaintext')
response = connection.getresponse()
res_lines = response.read().decode().split(os.linesep)
domains = set()
for line in res_lines:
line = line.strip()
if line.startswith('#'):
continue
domains.update(set(map(lambda s: s.strip(), line.split(','))))
non_valid = re.compile('[^A-Z0-9\.-]+', re.IGNORECASE)
for item in domains:
if non_valid.search(item) is not None:
raise RuntimeError('Found invalid characters in domain from external list `%s`' % item)
chunks = item.split('.')
if len(chunks) == 1:
raise RuntimeError('Top level domain found `%s`' % item)
for chunk in chunks:
if len(chunk) == 0:
raise RuntimeError('Wrong domain chunk found in `%s`' % item)
with open(os.path.join(os.path.dirname(__file__), 'init.sls'), 'w') as f:
f.write('\n'.join([
'#!py',
'def run():',
' return {',
' "adv_hostnames": [',
' %s' % ',\n'.join(map(lambda x: '"%s"' % x, domains)),
' ]',
' }'
]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment