diff options
| author | felix <felix@seconddrawer.com.au> | 2011-03-05 16:15:41 +0000 |
|---|---|---|
| committer | felix <felix@seconddrawer.com.au> | 2011-03-05 16:15:41 +0000 |
| commit | e135d3884efb7ef53165ca0ba4efd0033b03dfe4 (patch) | |
| tree | 9b74e9e954e4175a71b6c4a55ca21166b2e51b47 | |
| parent | deeb2cbca0c74229b1909dc453de932c30bfea49 (diff) | |
| download | tinydnsdyn-e135d3884efb7ef53165ca0ba4efd0033b03dfe4.tar.gz tinydnsdyn-e135d3884efb7ef53165ca0ba4efd0033b03dfe4.tar.bz2 | |
use alternate data file, updated readme, added makefile example
| -rw-r--r-- | Makefile.example | 13 | ||||
| -rw-r--r-- | README | 31 | ||||
| -rw-r--r-- | TODO | 4 | ||||
| -rwxr-xr-x | run | 5 | ||||
| -rwxr-xr-x | tinydnsdyn | 54 |
5 files changed, 73 insertions, 34 deletions
diff --git a/Makefile.example b/Makefile.example new file mode 100644 index 0000000..e636bc6 --- /dev/null +++ b/Makefile.example @@ -0,0 +1,13 @@ +all: remote + +remote: data.cdb + rsync -az -e ssh data.cdb remote.example.com:/etc/tinydns/root/data.cdb + +data.cdb: data + /usr/bin/tinydns-data + +data: primary.data secondary.data tinydnsdyn.data + cat primary.data secondary.data tinydnsdyn.data | sort | uniq -u > data + +secondary.data: + # perhaps axfr from another server?? @@ -18,17 +18,10 @@ To install the server code: 2. The supplied 'run' script is tailored for debian/ubuntu and may need to be changed. -3. Create a password file. This is of the format created by Apache's htpasswd - and consists of one user per line in the following format: - - <username>:<crypted hash>:<optional list of domains> - -4. Start the service by symlinking this directory into your svscan directory - (i.e. "ln $(pwd) /etc/service/" ). - -5. An existing entry in the tinydns data file should already exist. This script - will NOT add one. Only those hosts listed (with prefixes '+' and - '=') are able to update their entries. +3. You can added dynamic DNS entries to your main data file or alternatively use + a seperate file for dynamic entries. An existing entry in the tinydns data + file should already exist. This script will NOT add one. Only those hosts + listed (with prefixes '+' and '=') are able to update their entries. For example: @@ -40,6 +33,22 @@ To install the server code: will all get updated if the host groucho.example.com does a request. +4. Create a password file. This is of the format created by Apache's htpasswd + and consists of one user per line in the following format: + + <username>:<crypted hash>:<optional list of domains> + +5. The script will run 'make' in the data directory. This enables you to + concatenate your data files and whatever else before they are compiled. For + instance, you may need to combine all your primary and seconary zones and + then add the dynamic hosts before compiling. + + An example Makefile is included with some ideas. + +6. Start the service by symlinking this directory into your svscan directory + (i.e. "ln $(pwd) /etc/service/" ). + + The service operates over HTTP and should be reasonably close to the service operated by DynDns.com having the following request format: @@ -0,0 +1,4 @@ + +* Better sanity checking +* Multithread the server. Need to find a way to gracefully handle the data file +* Just better coding! @@ -1,3 +1,6 @@ #!/bin/sh exec 2>&1 -exec envuidgid tinydns ./tinydnsdyn --root=/etc/tinydns/root --passfile=/etc/tinydns/root/tinydnsdyn.passwords +exec envuidgid tinydns ./tinydnsdyn \ + --root=/etc/tinydns/root \ + --passfile=/etc/tinydns/root/tinydnsdyn.passwords \ + --data=tinydnsdyn.data @@ -29,14 +29,12 @@ import threading from optparse import OptionParser class RequestHandler(BaseHTTPRequestHandler): - - def headers_auth(self): - self.send_header('Content-type', 'text/html') - self.send_header('WWW-Authenticate', 'Basic realm=\"tinyDNSdyn\"') + """handle requests to BaseHTTPServer""" def headers_denied(self): self.send_response(401) - self.headers_auth() + self.send_header('Content-type', 'text/html') + self.send_header('WWW-Authenticate', 'Basic realm=\"tinyDNSdyn\"') def do_GET(self): self.auth = Authorizer() @@ -62,7 +60,7 @@ class RequestHandler(BaseHTTPRequestHandler): if 'hostname' not in query: response = 'notfqdn' else: - # use given ip address + # use given ip address? if 'myip' in query: address = query['myip'][0] # clean up all the hostnames for hostlist in query['hostname']: @@ -92,7 +90,7 @@ class RequestHandler(BaseHTTPRequestHandler): class Authorizer: - """A class for manipulating htpasswd files.""" + """Authorise the user using htpasswd file""" def __init__(self): self.filename = options.passfile @@ -116,11 +114,12 @@ class Authorizer: class DataFile: + """Read and write the data file""" def __init__(self): self.changed = False self.lines = [] - self.datafile_path = os.path.join(options.root, "data") + self.datafile_path = os.path.join(options.root, options.data) self.tmpfile_path = os.path.join(options.root, "data.tinydnsdyn.tmp") if os.path.exists(self.datafile_path): try: self.datafile = open(self.datafile_path,"r") @@ -136,18 +135,26 @@ class DataFile: raise IOError("unable to find data file: %s" % self.datafile_path) def update(self, address, hostname): + """update the temporary data file""" + result = -1 for line in self.datafile: if line[0] in ['+','=']: - fields = line.split(":",2) - if len(fields) > 2: - ttl = fields[2] - else: - ttl = options.ttl + fields = line.split(":",3) # i think these prefixes should work?! if fields[0].lstrip("+=.*") == hostname: + # default ttl? + if len(fields) > 2: + tail = fields[2] + else: + tail = options.ttl + + # retain the tail + if len(fields) > 3: + tail += ':' + fields[3] + if fields[1] != address: - line = "%s:%s:%s\n" % (fields[0],address,ttl) + line = "%s:%s:%s\n" % (fields[0],address,tail) result = 1 self.changed = True else: @@ -157,19 +164,19 @@ class DataFile: return result def commit(self): - # overwrite data file with temp one + """overwrite data file with temp one""" if self.changed: - try: - os.rename(self.tmpfile_path, self.datafile_path) - except: - raise IOError("unable to overwrite data file: %s" % - self.datafile_path) + try: os.rename(self.tmpfile_path, self.datafile_path) + except: raise IOError("unable to overwrite data file: %s" % + self.datafile_path) # now run the tinydns-data prog errno = os.system("cd %s && make -s" % options.root) if errno != 0: raise EnvironmentError("problem executing Makefile") else: - os.remove(self.tmpfile_path) + try: os.remove(self.tmpfile_path) + except: raise IOError("unable to remove temporary file: %s" % + self.tmpfile_path) def main(): @@ -178,6 +185,8 @@ def main(): parser = OptionParser(usage=usage) parser.add_option("-r", "--root", dest="root", help="absolute path to the tinydns data directory") + parser.add_option("-d", "--data", dest="data", + help="data file to update, relative to root (default: tinydnsdyn.data)") parser.add_option("-t", "--ttl", dest="ttl", help="default TTL (default: 3600)") parser.add_option("-a", "--address", dest="address", @@ -189,7 +198,8 @@ def main(): # defaults parser.set_defaults(root="/var/services/tinydns/root", address='', - port=5353, ttl=3600, passfile='/var/services/tinydns/htpasswd') + data="tinydnsdyn.data", port=5353, ttl=3600, + passfile='/var/services/tinydns/htpasswd') global options (options, args) = parser.parse_args() |
