updated exception handling and changed method in which modsecurity.py accesses vars in modsecurity, in order to support TX vars. Skell.py has been updated to reflect this

This commit is contained in:
root
2014-12-04 01:19:56 -05:00
parent 11756d0dcf
commit b88108616f
3 changed files with 123 additions and 46 deletions

View File

@@ -13,7 +13,7 @@ class Singleton(object):
return class_._instances[class_]
"""
class ModSecurity():
class ModSecurity():
def __init__(self):
self.default_attr = ["default_attr", "name", "modsecCore"]
self.name = None
@@ -31,6 +31,30 @@ class ModSecurity():
self.modsecCore.log(level, msg)
return True
def __getitem__(self,key):
v = None
# split our key by parts
key = key.split(".")
if(len(key) > 2):
print("error")
if(len(key) == 1):
collection = key[0]
param = None
if(len(key) == 2):
collection = key[0]
param = key[1]
try:
v = object.__getattribute__(self, collection)
# try and access the the collection via parameter
try:
return(v[param])
# if we fail, it means an improper parameter was passed (may be a list collection)
except:
return v
except:
if self.modsecCore != None:
v = self.modsecCore.getVariable(collection,param)
return v
def __getattribute__(self, key):
v = None
try:
@@ -40,17 +64,15 @@ class ModSecurity():
except:
if self.modsecCore != None:
v = self.modsecCore.getVariable(key)
return v
def __setattr__(self, name, value):
self.__dict__[name] = value
if name not in self.default_attr:
if self.modsecCore != None:
self.modsecCore.setVariable("tx." + name, value)
"""
TODO: transformation
"""

View File

@@ -27,7 +27,7 @@ class ModSecurityExtension(ModSecurity):
self.log(8, "Hum... Do we have something at FILES_TMPNAMES? %s" %
self.FILES_TMPNAMES)
self["FILES_TMPNAMES"])
# Returns True whenever you want to send a "match" to ModSecurity core.
return True