Commit d8874625 authored by Markus's avatar Markus
Browse files

2nd commit

- requirements  added
- wsgi script using bobo to update dyndns
parent 8860e9b9
import bobo
from tempfile import NamedTemporaryFile
from subprocess import call
from base64 import b64decode
ZONE = ""
BASEDOMAIN = "people"
@bobo.subroute('/update', scan=True)
class Dynschiss:
def __init__(self, request):
self.request = request
authstring = self.request.headers['Authorization'].split()[1]
self.user = b64decode(authstring).decode('utf-8').split(sep=':')[0]
if "ip" and "domain" in self.request.params:
self.ip = self.request.params['ip']
self.domain = self.request.params['domain']
self.status = "sucess"
self.status = "fail"'/')
def base(self):
updater = DynDnsUpdater(ZONE, self.user + "." + BASEDOMAIN)
updater.update(self.domain, self.ip)
return self.status
class DynDnsUpdater:
template = """server %s %d
zone %s.
update delete %s A
update add %s %d A %s
def __init__(self, zone, baseDomain, dnsIP="", dnsPort=53, ttl=60): = zone
self.baseDomain = baseDomain
self.dnsIP = dnsIP
self.dnsPort = dnsPort
self.ttl = ttl
def update(self, domain, ip):
template = self._renderUpdateTemplate(domain, ip)
return self
def _renderUpdateTemplate(self, domain, ip):
return self.template % (self.dnsIP, self.dnsPort,,
domain, domain, self.ttl, ip)
def _validate(self, domain):
namespace = "%s.%s" % ("." + self.baseDomain if
self.baseDomain else "",
if(not domain.endswith(namespace)):
raise ValueError("domain is not in predefined namespace. your\
domain must end with %s" % (namespace))
def _writeUpdate(self, content):
tmp = NamedTemporaryFile()
tmp.file.write(bytes(content, 'UTF-8'))
if __name__ == '__main__':
app = Dynschiss()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment