Added check for /etc/dnsupdaterc if no ~/.dnsupdaterc
Fixed spelling of IP address
This commit is contained in:
24
dnsupdate.py
24
dnsupdate.py
@@ -17,7 +17,7 @@ def checkerror(msg, show=""):
|
|||||||
|
|
||||||
|
|
||||||
def get_ipaddress():
|
def get_ipaddress():
|
||||||
# Connect to a remote server to determine which ip address
|
# Connect to a remote server to determine which IP address
|
||||||
# this host connects from
|
# this host connects from
|
||||||
import re
|
import re
|
||||||
import urllib
|
import urllib
|
||||||
@@ -29,7 +29,7 @@ def get_ipaddress():
|
|||||||
ip = res.group()
|
ip = res.group()
|
||||||
return ip
|
return ip
|
||||||
except:
|
except:
|
||||||
msg['error'].append("Could not determine ip address automatically,\n use -i switch to enter manually")
|
msg['error'].append("Could not determine IP address automatically,\n use -i switch to enter manually")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ def getparams(msg):
|
|||||||
help="Force the action, do not check if update is necessary")
|
help="Force the action, do not check if update is necessary")
|
||||||
parser.add_option("-i", "--ipaddress",
|
parser.add_option("-i", "--ipaddress",
|
||||||
type="string",
|
type="string",
|
||||||
help="Public IP-address for this host [auto detected]")
|
help="Public IP address for this host [auto detected]")
|
||||||
parser.add_option("-k", "--keyname",
|
parser.add_option("-k", "--keyname",
|
||||||
type="string",
|
type="string",
|
||||||
help="Name of the TSIG key")
|
help="Name of the TSIG key")
|
||||||
@@ -61,7 +61,7 @@ def getparams(msg):
|
|||||||
help="Hostname to publish")
|
help="Hostname to publish")
|
||||||
parser.add_option("--nameserver",
|
parser.add_option("--nameserver",
|
||||||
type="string",
|
type="string",
|
||||||
help="IP-address to the name server")
|
help="IP address to the name server")
|
||||||
parser.add_option("-q", "--quiet",
|
parser.add_option("-q", "--quiet",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Quit mode")
|
help="Quit mode")
|
||||||
@@ -73,7 +73,7 @@ def getparams(msg):
|
|||||||
help="Display config file data")
|
help="Display config file data")
|
||||||
parser.add_option("-u", "--ipurl",
|
parser.add_option("-u", "--ipurl",
|
||||||
type="string",
|
type="string",
|
||||||
help="URL to the server which detects the public IP-address")
|
help="URL to the server which detects the public IP address")
|
||||||
parser.add_option("-t", "--ttl",
|
parser.add_option("-t", "--ttl",
|
||||||
type="int",
|
type="int",
|
||||||
help="TTL in seconds")
|
help="TTL in seconds")
|
||||||
@@ -126,6 +126,8 @@ def readcfg(msg, show=""):
|
|||||||
if not msg.has_key('cfgfile'):
|
if not msg.has_key('cfgfile'):
|
||||||
if os.path.exists(os.path.expanduser("~/.dnsupdaterc")):
|
if os.path.exists(os.path.expanduser("~/.dnsupdaterc")):
|
||||||
cfgfile = open(os.path.expanduser("~/.dnsupdaterc"), 'r')
|
cfgfile = open(os.path.expanduser("~/.dnsupdaterc"), 'r')
|
||||||
|
elif os.path.exists("/etc/dnsupdaterc")):
|
||||||
|
cfgfile = open("/etc/dnsupdaterc"), 'r')
|
||||||
else:
|
else:
|
||||||
return msg
|
return msg
|
||||||
else:
|
else:
|
||||||
@@ -196,13 +198,9 @@ def update(msg):
|
|||||||
if msg.has_key("delete"):
|
if msg.has_key("delete"):
|
||||||
print "Host '%s.%s' has been deleted" % (msg['hostname'], msg['domain'])
|
print "Host '%s.%s' has been deleted" % (msg['hostname'], msg['domain'])
|
||||||
else:
|
else:
|
||||||
print "Host '%s.%s' has been added with ip address %s" % (msg['hostname'], msg['domain'], msg['ipaddress'])
|
print "Host '%s.%s' has been added with IP address %s" % (msg['hostname'], msg['domain'], msg['ipaddress'])
|
||||||
else:
|
else:
|
||||||
msg['error'].append("Update denied, server responded %s" % dns.rcode.to_text(response.rcode()))
|
msg['error'].append("Update denied, server responded %s" % dns.rcode.to_text(response.rcode()))
|
||||||
## elif response.rcode() == 5:
|
|
||||||
## msg['error'].append("The server refused to accept the update")
|
|
||||||
## else:
|
|
||||||
## msg['error'].append("Update refused, the server returned:\n%s" % response)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -221,7 +219,7 @@ def validate(msg):
|
|||||||
|
|
||||||
if msg.has_key('ipaddress'):
|
if msg.has_key('ipaddress'):
|
||||||
if not re.search('^[12]?[0-9]?[0-9](\.[12]?[0-9]?[0-9]){3}$', msg['ipaddress']):
|
if not re.search('^[12]?[0-9]?[0-9](\.[12]?[0-9]?[0-9]){3}$', msg['ipaddress']):
|
||||||
msg['error'].append("Invalid ip address '%s'" % msg['ipaddress'])
|
msg['error'].append("Invalid IP address '%s'" % msg['ipaddress'])
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@@ -243,9 +241,9 @@ def verify_ip(msg):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if ip == msg['ipaddress'] and not msg.has_key('delete'):
|
if ip == msg['ipaddress'] and not msg.has_key('delete'):
|
||||||
msg['error'].append("name server already up to date")
|
msg['error'].append("Name server already up to date")
|
||||||
elif ip == "" and msg.has_key('delete'):
|
elif ip == "" and msg.has_key('delete'):
|
||||||
msg['error'].append("name server does not recognise the hostname")
|
msg['error'].append("Name server does not recognise the hostname")
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user