Created
September 29, 2012 18:38
-
-
Save gokmen/3804853 to your computer and use it in GitHub Desktop.
Webfaction Google Apps record creator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.5 | |
import sys | |
import getpass | |
import xmlrpclib | |
server = xmlrpclib.Server('https://api.webfaction.com/') | |
username = raw_input("Username : ") | |
password = getpass.getpass("Password : ") | |
print "Trying to connect webfaction..." | |
try: | |
session_id, account = server.login(username, password) | |
except: | |
sys.exit("Connection failed, did u mispelled something?") | |
print "Ok, connected." | |
domain = raw_input("Please enter your domain name (no www, etc): ") | |
services = ('mail', 'cal', 'docs', 'start') | |
print "Here are the default subdomains for your google apps domain:" | |
for service in services: | |
print "\t - %s.%s" % (service, domain) | |
state = raw_input("If you want to create these aliases write yes: ") | |
if state == 'yes': | |
# mx info | |
mx_info = ( | |
('ASPMX.L.GOOGLE.COM','10'), | |
('ALT1.ASPMX.L.GOOGLE.COM','20'), | |
('ALT2.ASPMX.L.GOOGLE.COM','20'), | |
('ASPMX2.GOOGLEMAIL.COM','30'), | |
('ASPMX3.GOOGLEMAIL.COM','30'), | |
('ASPMX4.GOOGLEMAIL.COM','30'), | |
('ASPMX5.GOOGLEMAIL.COM','30'), | |
) | |
print " Creating MX records for %s ..." % domain | |
try: | |
# create mx records | |
for mx in mx_info: | |
server.create_dns_override(session_id, | |
domain, | |
'', | |
'', | |
mx[0], | |
mx[1], | |
'') | |
except: | |
sys.exit(" MX record failed, exiting...") | |
else: | |
print " MX records created successfully." | |
for service in services: | |
print " Creating CNAME records for: %s.%s ..." % (service, domain) | |
# create CNAME record | |
try: | |
server.create_domain(session_id, domain, service) | |
server.create_dns_override(session_id, | |
"%s.%s" % (service, domain), | |
'', | |
'ghs.google.com', | |
'', | |
'', | |
'') | |
except: | |
print " Failed to create CNAME record for: %s.%s ..." % (service, domain) | |
else: | |
print " CNAME record created for: %s.%s ..." % (service, domain) | |
print "All records created, failed or not I have no idea, follow the messages above." | |
else: | |
print "Ok then, c ya!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment