Added check for /etc/dnsupdaterc if no ~/.dnsupdaterc

Fixed spelling of IP address
This commit is contained in:
2004-01-26 20:18:00 +00:00
parent 07b185d418
commit 21285b65e1

View File

@@ -17,7 +17,7 @@ def checkerror(msg, show=""):
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
import re
import urllib
@@ -29,7 +29,7 @@ def get_ipaddress():
ip = res.group()
return ip
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")
parser.add_option("-i", "--ipaddress",
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",
type="string",
help="Name of the TSIG key")
@@ -61,7 +61,7 @@ def getparams(msg):
help="Hostname to publish")
parser.add_option("--nameserver",
type="string",
help="IP-address to the name server")
help="IP address to the name server")
parser.add_option("-q", "--quiet",
action="store_true",
help="Quit mode")
@@ -73,7 +73,7 @@ def getparams(msg):
help="Display config file data")
parser.add_option("-u", "--ipurl",
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",
type="int",
help="TTL in seconds")
@@ -126,6 +126,8 @@ def readcfg(msg, show=""):
if not msg.has_key('cfgfile'):
if os.path.exists(os.path.expanduser("~/.dnsupdaterc")):
cfgfile = open(os.path.expanduser("~/.dnsupdaterc"), 'r')
elif os.path.exists("/etc/dnsupdaterc")):
cfgfile = open("/etc/dnsupdaterc"), 'r')
else:
return msg
else:
@@ -196,13 +198,9 @@ def update(msg):
if msg.has_key("delete"):
print "Host '%s.%s' has been deleted" % (msg['hostname'], msg['domain'])
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:
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 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
@@ -243,13 +241,13 @@ def verify_ip(msg):
pass
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'):
msg['error'].append("name server does not recognise the hostname")
msg['error'].append("Name server does not recognise the hostname")
return msg
if __name__=="__main__":
if __name__ == "__main__":
import sys
msg = {}
msg['error'] = []