add checkip script and a client to update the IP
[dyn-nsupdate.git] / update
diff --git a/update b/update
new file mode 100755 (executable)
index 0000000..1c149be
--- /dev/null
+++ b/update
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+import cgi, os, sys, subprocess
+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 "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:
+       print "Unexpected stdout from dyn-nsupdate:"
+       print stdout
+       sys.exit()
+
+# 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:
+               print "Unexpected stderr from dyn-nsupdate:"
+               print stderr
+               sys.exit()
+       print "good",ip