Last active
August 29, 2015 14:12
-
-
Save ytjohn/369582d95b7e15262e2c to your computer and use it in GitHub Desktop.
update ttl
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
# this is just the beginning | |
import requests | |
import json | |
class Rage4dns(): | |
def __init__(self, username, token): | |
self.username = username | |
self.token = token | |
self.baseurl = "https://secure.rage4.com/RAPI/" | |
def _doquery(self, target, payload): | |
url = '{0}{1}'.format(self.baseurl, target) | |
r = requests.get(url, auth=(self.username, self.token), params=payload) | |
if r.status_code == 200: | |
data = json.loads(r.text) | |
elif r.status_code == 401: | |
data = "Authentication Failed" | |
else: | |
data = "Uknown Issue: {0}".format(r.text) | |
return r.status_code, data | |
def GetDomains(self): | |
target = 'GetDomains' | |
payload = None | |
status, data = self._doquery(target, payload) | |
return status, data | |
def GetDomain(self, id): | |
if isinstance(id, int): | |
target = 'GetDomain/{0}'.format(id) | |
payload = None | |
else: | |
target = 'getdomainbyname' | |
payload = { 'name': id } | |
status, data = self._doquery(target, payload) | |
return status, data | |
def CreateRegularDomain(self, domain, owner, nameservers=None): | |
#/createregulardomain/?name=<domain name [string]> | |
# &email=<owner [string]> | |
# &ns1=<primary NS name [string]> | |
# &ns2=<secondary NS name [string]> | |
# First, we're going to see if the domain already exists. | |
# If it does, just return that. If not, we'll make it. | |
# s,d = self.GetDomain(domain) | |
# if s == 200: | |
# if 'id' in d: | |
# return s, d | |
target = 'createregulardomain' | |
payload = { | |
'name': domain, | |
'email': owner, | |
} | |
if len(nameservers) == 2: | |
payload['ns1'] = nameservers[0] | |
payload['ns2'] = nameservers[1] | |
status, data = self._doquery(target, payload) | |
return status, data | |
def UpdateDomain(self): | |
# updatedomain/<domain id [int]> | |
# ?email=<owner [string]> | |
# &nsname=<vanity domain [string, nullable]> | |
# &nsprefix=<vanity prefix [string, nullable]> | |
# &enablevanity=<activate/deactivate failover [bool (true|false)]> | |
# To activate Vanity NS set values of nsname, nsprefix and set enablevanity to true. | |
# To deactivate Vanity NS set empty values to nsname, nsprefix and set enablevanity to false. | |
pass | |
def DeleteDomain(self, id): | |
# https://secure.rage4.com/rapi/deletedomain/<domain id [int]> | |
pass | |
def ListRecordTypes(self): | |
# https://secure.rage4.com/rapi/listrecordtypes/ | |
pass | |
def CreateRecord(self, domain, name, content, recordtype, priority=None, active=None, | |
failover=None): | |
# https://secure.rage4.com/rapi/createrecord/ | |
# <domain id [int]> | |
# ?name=<record name [string]> | |
# &content=<record value [string]> | |
# &type=<record type [int]>& | |
# priority=<record priority [int, nullable]> | |
# &active=<record online/offline [bool (true|false), nullable]> | |
# &failover=<enable/disable failover [bool (true|false)]> | |
# &failovercontent=<record failover value [string] | |
# &ttl=<ttl [int]>&geozone=<geo region id [long]>&geolock=<geo lock coordinates bool (true|false)> | |
# &geolat=<geo latitude [double, nullable]> | |
# &geolong=<geo longitude [double, nullable]>&udplimit=<enable/disable result set limit [bool (true|false)]> | |
target = "createrecord/{0}".format(domain) | |
payload = { | |
'name': name, | |
'content': content, | |
'type': recordtype, | |
'priority': priority, | |
} | |
# pass | |
status, result = self._doquery(target, payload) | |
return status, result | |
def ImportDomain(self, domain): | |
target = "importdomain" | |
payload = { 'name': domain } | |
status, data = self._doquery(target, payload) | |
return status, data | |
def ListAllRecords(self, domain): | |
# https://secure.rage4.com/rapi/getrecords/<domain id [int]> | |
target = "getrecords/{0}".format(domain) | |
payload = None | |
status, data = self._doquery(target, payload) | |
return status, data | |
def UpdateRecord(self, record): | |
# https://secure.rage4.com/rapi/updaterecord/<record id [int]>? | |
# name=<record name [string]> | |
# &content=<record value [string]> | |
# &priority=<record priority int, nullable]> | |
# &active=<record online/offline [bool (true|false), nullable]> | |
# &failover=<enable/disable failover [bool (true|false)]> | |
# &failovercontent=<record failover value [string]> | |
# &ttl=<TTL [int]>&geozone=<geo region ID [long]> | |
# &geolock=<geo lock coordinates bool (true|false)> | |
# &geolat=<geo latitude [double, nullable]> | |
# &geolong=<geo longitude [double, nullable]> | |
# &udplimit=<enable/disable result set limit [bool (true|false)]> | |
target = "updaterecord/{0}".format(record['id']) | |
payload = record | |
status, data = self._doquery(target, payload) | |
return status, data |
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
username = 'myemail' | |
token = 'mytoken' | |
R = Rage4dns(username=username, token=token) | |
status, domains = R.GetDomains() | |
print "gettind domains", status | |
for dom in domains: | |
print dom['name'], dom['id'] | |
rs, rr = R.ListAllRecords(dom['id']) | |
for record in rr: | |
print record['id'], record['name'], record['ttl'] | |
if record['ttl'] < 86400: | |
record['ttl'] = 86400 | |
s,r = R.UpdateRecord(record) | |
print r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://gbshouse.uservoice.com/knowledgebase/articles/109834-rage4-dns-developers-api#list_records