From c4b4f6dafd555abe076a0aca58ca6d1ced948bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D0=BC=D0=BE=D1=83=D0=BA=D0=B8=D0=BD=20=D0=90?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 18 Nov 2009 15:43:35 +0300 Subject: [PATCH] Changed the generation of value for the variable profile 'os_net_allow' --- pym/cl_fill.py | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/pym/cl_fill.py b/pym/cl_fill.py index 6fc2f75..0766441 100644 --- a/pym/cl_fill.py +++ b/pym/cl_fill.py @@ -145,12 +145,24 @@ class fillVars(object, cl_base.glob_attr): # Разрешенные сети (в данном случае все сети) def get_os_net_allow(self): """Разрешенные сети разделитель запятая""" - net={'255.0.0.0':'/8', - '255.255.0.0':'/16', - '255.255.255.0':'/24', - '255.255.255.128':'/25', - '255.255.255.252':'/30', - '255.255.255.255':''} + + def getNet(ip, mask): + """По ip и маске получаем сеть""" + octetsMult = (0x1, 0x100, 0x10000, 0x1000000) + octetsIp = map(lambda x: int(x), ip.split(".")) + octetsMask = map(lambda x: int(x), mask.split(".")) + ipNumb = 0 + for i in octetsMult: + ipNumb += octetsIp.pop()*i + maskNumb = 0 + for i in octetsMult: + maskNumb += octetsMask.pop()*i + startIpNumber = maskNumb&ipNumb + x = startIpNumber + nMask = lambda y: len(filter(lambda x: y >> x &1 ,range(32))) + return "%s.%s.%s.%s/%s"\ + %(x>>24, x>>16&255, x>>8&255, x&255, nMask(maskNumb)) + networks=[] netInterfaces=cl_utils.getdirlist("/sys/class/net/") flagError = False @@ -162,27 +174,8 @@ class fillVars(object, cl_base.glob_attr): for j in res: s_ip=re.search('addr:([0-9\.]+).+Bcast:.+Mask:([0-9\.]+)' ,j) if s_ip: - ip, netmask=s_ip.groups() - ip=ip.split('.') - if ip[0]=='10' or\ - (ip[0]=='172' and int(ip[1])>=16 and int(ip[1])<=31)or\ - (ip[0]=='192' and ip[1]=='168'): - if netmask=='255.255.255.255': - networks.append(ip) - elif netmask=='255.255.255.252': - networks.append(ip[0]+"."+ip[1]+"."+ip[2]+"."+\ - "252"+net[netmask]) - elif netmask=='255.255.255.128': - networks.append(ip[0]+"."+ip[1]+"."+ip[2]+"."+\ - "128"+net[netmask]) - elif netmask=='255.255.255.0': - networks.append(ip[0]+"."+ip[1]+"."+ip[2]+"."+"0"+\ - net[netmask]) - elif netmask=='255.255.0.0': - networks.append(ip[0]+"."+ip[1]+".0.0"+net[netmask]) - elif netmask=='255.0.0.0': - networks.append(ip[0]+".0.0.0"+net[netmask]) - + ip, mask = s_ip.groups() + networks.append(getNet(ip, mask)) if flagError: return "" return ",".join(networks)