Placeholder Image

ADN Informatique

Consultant Ingénierie Informatique

Saguenay (Jonquière), Québec, Canada. Tél: (581) 683-9887 Téléc: (581) 221-0874

Placeholder Picture

Retour

Update PowerDNS

2005-05-20 20:56:17 (ID: 63, Parent: 0, Type: post)
Ce script reçoit en paramètre le mot de passe du compte Il se connecte à un serveur web sur lequel est installer PowerDNS et met à jour un enregistrement. <pre> #!/bin/bash ################################################################ # # Author: Jean-Luc Cyr # Copyright 2004 / ADN Informatique # Date: 2004-09-27 # Desc: PowerDNS Administration automatic DNS record update #       from a GNET router dynamic IP configuration # ################################################################ #GNET ROUTER INTERNAL IP ROUTER_IP=1.2.3.4 #PowerDNS Administration server url DNS_SERVER= mydomain.com/powerdns DNS_USER=username DNS_PASS=$1 DNS_RECORD=33643 if [ $1 ] ; then echo "" >/dev/null ; else echo "must give password"; exit; fi DNS_LOGIN="username=$DNS_USER&password=$DNS_PASS&submit=Log%20in" cd /tmp #date if [ -f status.htm ] ; then rm status.htm ; fi if [ -f oldip ] ; then rm oldip ; fi if [ -f currentip ] ; then cp currentip oldip ; fi #echo =======Get router status page======================= wget -q http://$ROUTER_IP/status.htm #echo =======Find out the router ip address=============== if [ -f status.htm ] ; then cat status.htm | grep "IP Address" | cut -b 41- | cut -f1 -d"<" > currentip ; else exit ; fi #date >>/tmp/currentip #echo =======Check if router address has changed========== #if diff -q oldip currentip | grep differ >/dev/null ; then echo "ROUTER IP HAS CHANGED" ; else echo "ROUTER IP HAS NOT CHANGED" ; exit ; fi if diff -q oldip currentip | grep differ >/dev/null ; then echo "ROUTER IP HAS CHANGED" ; else echo "" >/dev/null ; exit ; fi #echo =====================LOGGING IN===================== #Call the login page: http://ns1.lcinter.net/dns2/index.php (user/pass/submit) curl -D headers_and_cookies -d $DNS_LOGIN $DNS_SERVER/login.php 2>/dev/null #echo =====================GETTING RECORD================= #Call the update record page: http://ns1.lcinter.net/dns2/edit_record.php?id=33643 (dns data/submit) curl -b headers_and_cookies $DNS_SERVER/edit_record.php?id=$DNS_RECORD 2>/dev/null | grep content | grep name= | cut -b 74- | cut -f1 -d"<" > /tmp/dnsip #if diff -q dnsip currentip | grep differ >/dev/null ; then echo "DNS DIFFER FROM ROUTER IP" ; else echo "DNS IS UP TO DATE" ; curl -b headers_and_cookies $DNS_SERVER/logout.php ; exit ; fi if diff -q dnsip currentip | grep differ >/dev/null ; then echo "DNS DIFFER FROM ROUTER IP" ; else echo "" >/dev/null ; curl -b headers_and_cookies $DNS_SERVER/logout.php 2>/dev/null ; exit ; fi echo =====================UPDATING RECORD================ date #Call the update record page #Here are en example of the original update page from PowerDNS #<form action="update_record.php?id=33643" method="post"> #  <input type="text" name="record" size="15" maxlength="200" value="home">.adninformatique.net #  <select name="type"> #    <option value="NS">NS</option> #    <option value="MX">MX</option> #    <option value="A" selected>A</option> #    <option value="AAAA">AAAA</option> #    <option value="PTR">PTR</option> #    <option value="CNAME">CNAME</option> #    <option value="TXT">TXT</option> #  </select> #  <input type="text" name="prio" size="5" maxlength="11" value=""> #  <input type="text" name="content" size="15" maxlength="255" value="24.201.6.204"> #  <input type="text" name="ttl" size="5" maxlength="11" value="1"> #  <input type="submit" value="Update"> #</form> echo update adni.adninformatique.net dns DNS_REQ="record=home&type=A&prio=&ttl=1&submit=Update&content=`cat /tmp/currentip`" #echo request is $DNS_REQ curl -b headers_and_cookies -d $DNS_REQ $DNS_SERVER/update_record.php?id=$DNS_RECORD >/dev/null 2>/dev/null echo update jlcyr.dyn.grafsoft.com dns curl www.grafsoft.com/~jlcyr/dns_update.php?ip=24.201.6.204 >/dev/null 2>/dev/null #grep "The record was updated" #echo =====================LOGGING OUT==================== #Call the logout page: http://ns1.lcinter.net/dns2/logout.php curl -b headers_and_cookies $DNS_SERVER/logout.php 2>/dev/null rm -f headers_and_cookies echo "dynamic ip updated" </pre>  <dtml-var standard_html_header> <h2><dtml-var title_or_id></h2> <p> This is the <dtml-var id> Document. </p> <dtml-var standard_html_footer>

Document Informatif

ADN Informatique

2015

Rev. 1

Jean-Luc Cyr