From 46df069b9cc583b93de61baf8fa565a5062a1049 Mon Sep 17 00:00:00 2001 From: Mike Fulbright Date: Mon, 13 May 2002 21:09:40 +0000 Subject: add function to sanity check hostnames --- network.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/network.py b/network.py index 7f75da869..43f7cc259 100644 --- a/network.py +++ b/network.py @@ -22,6 +22,28 @@ import isys import socket import os from log import log +from translate import _, N_ + +def inStrRange(v, s): + if string.find(s, v) == -1: + return 0 + else: + return 1 + +def sanityCheckHostname(hostname): + if len(hostname) < 1: + return None + + if not inStrRange(hostname[0], string.ascii_letters): + return _("Hostname must start with a valid character in the range " + "'a-z' or 'A-Z'") + + for i in range(1, len(hostname)): + if not inStrRange(hostname[i], string.ascii_letters+string.digits+".-"): + return _("Hostnames can only contain the characters 'a-z', 'A-Z', '-', or '.'") + + return None + def networkDeviceCheck(network, dispatch): devs = network.available() -- cgit