gensites.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import os,sys
  4. if not 'GLUON_SITEDIR' in os.environ:
  5. print "GLUON_SITEDIR not set"
  6. sys.exit(1)
  7. execfile(os.environ['GLUON_SITEDIR'] + "/extra/sites.conf")
  8. execfile(os.environ['GLUON_SITEDIR'] + "/extra/groups.conf")
  9. DOMAINS=os.environ['GLUON_SITEDIR'] + "/domains/"
  10. TEMPLATE = ""
  11. with open(os.environ['GLUON_SITEDIR'] + "/extra/template.conf") as f:
  12. TEMPLATE = f.readlines()
  13. if not os.path.isdir(os.environ['GLUON_SITEDIR'] + "/domains"):
  14. try:
  15. os.mkdir(os.environ['GLUON_SITEDIR'] + "/domains")
  16. except OSError:
  17. print ("Creation of the directory %s failed" % os.environ['GLUON_SITEDIR'] + "/domains")
  18. # generate domain specific site confs
  19. for s in sites:
  20. with open(DOMAINS + s['site_code'] + ".conf", "w") as f:
  21. for line in TEMPLATE:
  22. # Substitute values
  23. line = line.replace('%SN', s['site_name'])
  24. line = line.replace('%SC', s['site_code'])
  25. line = line.replace('%SS', s['ssid'])
  26. line = line.replace('%DS', groups[s['group']]['%%DS'])
  27. line = line.replace('%V4', groups[s['group']]['%%V4'])
  28. line = line.replace('%V6', groups[s['group']]['%%V6'])
  29. line = line.replace('%N4', groups[s['group']]['%%N4'])
  30. line = line.replace('%ID', groups[s['group']]['%%ID'])
  31. line = line.replace('%GN', s['group'])
  32. if 'hide' in s:
  33. line = line.replace('%HIDE', s['hide'])
  34. else:
  35. line = line.replace('%HIDE', 'false')
  36. f.write(line)