Added check if update necessary
This commit is contained in:
4
TODO
4
TODO
@@ -1,14 +1,14 @@
|
|||||||
TODO for dnsupdate
|
TODO for dnsupdate
|
||||||
|
|
||||||
- Check if address needs update before sending data and create a force
|
|
||||||
update option
|
|
||||||
- Have options to delete a server as well as add/update
|
- Have options to delete a server as well as add/update
|
||||||
|
- Create a force update option
|
||||||
- Integrate the relevant dnspython modules
|
- Integrate the relevant dnspython modules
|
||||||
- Add a GUI
|
- Add a GUI
|
||||||
wxPython and/or curses?
|
wxPython and/or curses?
|
||||||
|
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
|
- Check if address needs update before sending data
|
||||||
- Validate data, check for cfg files existance
|
- Validate data, check for cfg files existance
|
||||||
- Re-structure the code
|
- Re-structure the code
|
||||||
- Add a config-file for hostname, domain and password. Option to select
|
- Add a config-file for hostname, domain and password. Option to select
|
||||||
|
|||||||
18
dnsupdate.py
18
dnsupdate.py
@@ -30,7 +30,7 @@ def getparams(msg):
|
|||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import sys
|
import sys
|
||||||
# Define option parameters
|
# Define option parameters
|
||||||
usage = "usage: %prog [-n] hostname [-i] ip adress [OPTIONS]"
|
usage = "usage: %prog [OPTIONS]"
|
||||||
parser = OptionParser(usage)
|
parser = OptionParser(usage)
|
||||||
parser.add_option("-c", "--config",
|
parser.add_option("-c", "--config",
|
||||||
type="string",
|
type="string",
|
||||||
@@ -142,7 +142,7 @@ def validate(msg):
|
|||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
# Verify all required data is present and sanity check incoming data
|
# Verify all required data is present and sanity check incoming data
|
||||||
req_vals = ['domain', 'hostname', 'ipaddress', 'keyname', 'keysecret']
|
req_vals = ['domain', 'hostname', 'ipaddress', 'keyname', 'keysecret', 'ttl']
|
||||||
for value in req_vals:
|
for value in req_vals:
|
||||||
if not msg.has_key(value):
|
if not msg.has_key(value):
|
||||||
msg['error'].append('Missing "%s" parameter' % value)
|
msg['error'].append('Missing "%s" parameter' % value)
|
||||||
@@ -158,6 +158,19 @@ def validate(msg):
|
|||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
def verify_ip(msg):
|
||||||
|
import dns.resolver
|
||||||
|
try:
|
||||||
|
ans = dns.resolver.query(msg['hostname'] + "." + msg['domain'], 'A')
|
||||||
|
for res in ans:
|
||||||
|
ip = res.to_text()
|
||||||
|
except:
|
||||||
|
ip = ""
|
||||||
|
|
||||||
|
if ip == msg['ipaddress']:
|
||||||
|
msg['error'].append("Nameserver already up to date")
|
||||||
|
|
||||||
|
return msg
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
msg = {}
|
msg = {}
|
||||||
@@ -165,6 +178,7 @@ if __name__=="__main__":
|
|||||||
|
|
||||||
getparams(msg)
|
getparams(msg)
|
||||||
validate(msg)
|
validate(msg)
|
||||||
|
verify_ip(msg)
|
||||||
err = checkerror(msg)
|
err = checkerror(msg)
|
||||||
if err == 0:
|
if err == 0:
|
||||||
update(msg)
|
update(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user