Guest User

Untitled

a guest
Feb 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. #
  3. # untitled
  4. #
  5. # Created by Tom Lazar on 2006-07-05.
  6. # Copyright (c) 2006 tomster.org. All rights reserved.
  7. #
  8.  
  9. import sys
  10. import os
  11.  
  12. from amara import binderytools
  13.  
  14. from helpers import *
  15. from email import *
  16. from convenience import get_hosting
  17. from helpers import openForWriting
  18. from hostingconfig import tinydnsdata, DNS_HOSTS
  19. from sshconnect import SSHHost
  20.  
  21. def createTinyDNSData(hosting=None):
  22. """ Write the domain infos to a tinydns compatible file. """
  23. if not hosting:
  24. hosting = get_hosting()
  25.  
  26. file = openForWriting(tinydnsdata)
  27.  
  28. domains = hosting.doc.xml_xpath(u"//domain[@status='active' and @admin='yes']")
  29. for domain in domains:
  30.  
  31. nshosts = domain.xml_xpath(u"specs/dns")
  32. mxhosts = domain.xml_xpath(u"specs/mx")
  33. hosts = domain.xml_xpath(u"specs/host")
  34. zone = str(domain.name)
  35.  
  36. if nshosts:
  37.  
  38. zonestring = "Z%s:%s.:hostmaster.tomster.org." % (zone, nshosts[0])
  39. file.write(zonestring)
  40. file.write("\n")
  41. for nshost in nshosts:
  42. file.write("&%s::%s" % (zone, nshost))
  43. file.write("\n")
  44.  
  45. for mxhost in mxhosts:
  46. file.write("@%s::%s:%s" % (zone, str(mxhost), str(mxhost.prio)))
  47. file.write("\n")
  48.  
  49. for host in hosts:
  50. file.write("+%s:%s" % (fqdn(str(host), zone), str(host.ipaddr)))
  51. file.write("\n")
  52. else:
  53. print ">> No DNS entries found for %s. Skipping this domain!" % zone
  54.  
  55. file.close()
  56.  
  57. def uploadTinyDNSData(hosting=None):
  58. """ Uploads the tinydns data file to each server specified in `hostingconfig` and
  59. and issues a make command there to activate the new data (if available).
  60. """
  61. if not hosting:
  62. hosting = get_hosting()
  63.  
  64. for host in DNS_HOSTS:
  65. connect = SSHHost(hostname=host['hostname'], \
  66. username=host['username'], \
  67. keyfile=host['keyfile'], \
  68. port=host['port'])
  69. print "uploading to %s." % host['hostname']
  70. connect.copy(tinydnsdata, host['datafile'])
  71. if host.has_key('makefolder'):
  72. print "rebuiding database."
  73. connect.execute("cd %s ; make" % host['makefolder'])
  74. return
  75.  
  76. def fqdn(host=None, domain=None):
  77. if domain is None:
  78. return None
  79. elif host is None or host == '':
  80. return domain
  81. else:
  82. return "%s.%s" % (host, domain)
  83.  
  84. def main():
  85. hosting = get_hosting()
  86. createTinyDNSData(hosting)
  87. uploadTinyDNSData(hosting)
  88.  
  89. if __name__ == '__main__':
  90. main()
Add Comment
Please, Sign In to add comment