X-Git-Url: https://git.ralfj.de/dyn-nsupdate.git/blobdiff_plain/fd7ec51f7295b7364355287ad3593e35986ab7c9..32be553e5075e9744e0f0793e8a09a205b2dc1c0:/server-scripts/update?ds=sidebyside diff --git a/server-scripts/update b/server-scripts/update index c45df30..a7535ce 100755 --- a/server-scripts/update +++ b/server-scripts/update @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python2 # Copyright (c) 2014, Ralf Jung # All rights reserved. # @@ -21,29 +21,33 @@ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# The views and conclusions contained in the software and documentation are those -# of the authors and should not be interpreted as representing official policies, -# either expressed or implied, of the FreeBSD Project. import cgi, os, sys, subprocess -form = cgi.FieldStorage() +form = cgi.FieldStorage(keep_blank_values=True) # print headers print "Content-Type: text/plain" print "" # get input -if "password" not in form or "domain" not in form or "ip" not in form: - print "Mandatory argument missing: You must supply all of 'password', 'domain', 'ip'" +if "password" not in form or "domain" not in form or ("ip" not in form and "ipv6" not in form): + print "Mandatory argument missing: You must supply all of 'password', 'domain' and at least either 'ip' or 'ipv6'" sys.exit() -ip = form["ip"].value -domain = form["domain"].value -password = form["password"].value +domain = form.getfirst("domain") +password = form.getfirst("password") +ip = form.getfirst("ip") +ipv6 = form.getfirst("ipv6") +assert domain is not None and password is not None +assert ip is not None or ipv6 is not None # run update program -p = subprocess.Popen(["/var/lib/bind/dyn-nsupdate", domain, password, ip], stdout=subprocess.PIPE, stderr=subprocess.PIPE) +args = ["/var/lib/bind/dyn-nsupdate", "--domain", domain, "--password", password] +if ip is not None: + args += ["--ipv4", ip] +if ipv6 is not None: + args += ["--ipv6", ipv6] +p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = p.communicate() # check what it did @@ -53,4 +57,9 @@ if p.returncode or stderr or stdout: if stdout: print stdout if stderr: print stderr else: - print "good",ip + print "good", + if ip is not None: + print ip, + if ipv6 is not None: + print ipv6, + print