From 19126c9ae309aebb7c802006df37a9a0dbe65077 Mon Sep 17 00:00:00 2001 From: Christopher Harvey Date: Tue, 17 Aug 2010 06:17:35 -0400 Subject: Added ip check to make sure ips in /etc/hosts are valid. --- modules/hosts/ipMatch.py | 15 +++++++++++++++ modules/hosts/main.xml | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 modules/hosts/ipMatch.py diff --git a/modules/hosts/ipMatch.py b/modules/hosts/ipMatch.py new file mode 100644 index 0000000..f633cd5 --- /dev/null +++ b/modules/hosts/ipMatch.py @@ -0,0 +1,15 @@ +import re + +def validate(userIn): + ipVer4 = "^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$" + ipVer6Std = "^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$" + ipVer6Hex = "^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$" + + if(re.match(ipVer4, userIn)!=None): + return True + elif(re.match(ipVer6Std, userIn)!=None): + return True + elif(re.match(ipVer6Hex, userIn)!=None): + return True + + return False diff --git a/modules/hosts/main.xml b/modules/hosts/main.xml index 4b17844..df647e0 100644 --- a/modules/hosts/main.xml +++ b/modules/hosts/main.xml @@ -1,7 +1,7 @@ - + - \ No newline at end of file + -- cgit v1.2.3-65-gdbad