add CGI script which calls dyn-nsupdate
authorRalf Jung <post@ralfj.de>
Fri, 9 Aug 2013 21:12:07 +0000 (23:12 +0200)
committerRalf Jung <post@ralfj.de>
Fri, 9 Aug 2013 21:12:07 +0000 (23:12 +0200)
update.py [new file with mode: 0644]

diff --git a/update.py b/update.py
new file mode 100644 (file)
index 0000000..8c87e3a
--- /dev/null
+++ b/update.py
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+import cgi, os, sys, subprocess
+import cgitb
+cgitb.enable()
+form = cgi.FieldStorage()
+
+# print headers
+print "Content-Type: text/plain"
+print ""
+
+# get input
+if "user" not in form or "password" not in form or "domain" not in form or "ip" not in form:
+    print "Error:"
+    print "Mandatory argument missing: You must supply all of 'user', 'password', 'domain', 'ip'"
+    sys.exit()
+
+ip = form["ip"].value
+domain = form["domain"].value
+user = form["user"].value
+password = form["password"].value
+
+# run update program
+p = subprocess.Popen(["/var/lib/named/dyn-nsupdate", user, password, domain, ip], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+(stdout, stderr) = p.communicate()
+if stdout: raise Exception("Unexpected output from dyn-nsupdate")
+
+# check what it did
+if p.returncode == 1:
+       # error :/
+       print "There was an error while updating the DNS:"
+       print stderr
+else:
+       # all right!
+       if p.returncode or stderr:
+               raise Exception("Unexpected return code or output from dyn-nsupdate")
+       print "good",ip