Added check if update necessary
This commit is contained in:
4
TODO
4
TODO
@@ -1,14 +1,14 @@
|
||||
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
|
||||
- Create a force update option
|
||||
- Integrate the relevant dnspython modules
|
||||
- Add a GUI
|
||||
wxPython and/or curses?
|
||||
|
||||
|
||||
Done:
|
||||
- Check if address needs update before sending data
|
||||
- Validate data, check for cfg files existance
|
||||
- Re-structure the code
|
||||
- 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
|
||||
import sys
|
||||
# Define option parameters
|
||||
usage = "usage: %prog [-n] hostname [-i] ip adress [OPTIONS]"
|
||||
usage = "usage: %prog [OPTIONS]"
|
||||
parser = OptionParser(usage)
|
||||
parser.add_option("-c", "--config",
|
||||
type="string",
|
||||
@@ -142,7 +142,7 @@ def validate(msg):
|
||||
import re
|
||||
import string
|
||||
# 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:
|
||||
if not msg.has_key(value):
|
||||
msg['error'].append('Missing "%s" parameter' % value)
|
||||
@@ -158,6 +158,19 @@ def validate(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__":
|
||||
msg = {}
|
||||
@@ -165,6 +178,7 @@ if __name__=="__main__":
|
||||
|
||||
getparams(msg)
|
||||
validate(msg)
|
||||
verify_ip(msg)
|
||||
err = checkerror(msg)
|
||||
if err == 0:
|
||||
update(msg)
|
||||
|
||||
Reference in New Issue
Block a user