support multiple domains in update script; get rid of usernames
[dyn-nsupdate.git] / update
1 #!/usr/bin/python
2 import cgi, os, sys, subprocess
3 form = cgi.FieldStorage()
4
5 # print headers
6 print "Content-Type: text/plain"
7 print ""
8
9 # get input
10 if "password" not in form or "domain" not in form or "ip" not in form:
11     print "Mandatory argument missing: You must supply all of 'password', 'domain', 'ip'"
12     sys.exit()
13
14 ip = form["ip"].value
15 domain = form["domain"].value
16 password = form["password"].value
17
18 # run update program
19 p = subprocess.Popen(["/var/lib/named/dyn-nsupdate", domain, password, ip], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
20 (stdout, stderr) = p.communicate()
21
22 # check what it did
23 if p.returncode or stderr or stdout:
24         # error :/
25         print "There was an error while updating the DNS: Return code %d" % p.returncode
26         if stdout: print stdout
27         if stderr: print stderr
28 else:
29         print "good",ip