summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-03-30 14:07:21 +0200
committerGravatar mkaay <mkaay@mkaay.de> 2010-03-30 14:07:21 +0200
commitaa43045a553e63c7f02cfed9bd1c4a688c0b690a (patch)
tree020259d797ce726d20b0ef4dec5e4bdeeea161c6 /module
parentbetter config parser (diff)
downloadpyload-aa43045a553e63c7f02cfed9bd1c4a688c0b690a.tar.xz
config input valadiation
Diffstat (limited to 'module')
-rw-r--r--module/XMLConfigParser.py31
-rw-r--r--module/config/core_default.xml1
2 files changed, 28 insertions, 4 deletions
diff --git a/module/XMLConfigParser.py b/module/XMLConfigParser.py
index 50cc4485d..6396122f4 100644
--- a/module/XMLConfigParser.py
+++ b/module/XMLConfigParser.py
@@ -119,6 +119,8 @@ class XMLConfigParser():
sectionNode = False
if type(data) == str:
data = {"option": data}
+ if not self.checkInput(section, data["option"], value):
+ raise Exception("invalid input")
for node in root.childNodes:
if node.nodeType == node.ELEMENT_NODE:
if section == node.tagName:
@@ -178,10 +180,9 @@ class XMLConfigParser():
return "str"
def getInputValues(self, section, option):
- try:
- return self.data[section]["options"][option]["input"].split(";")
- except:
+ if not self.data[section]["options"][option]["input"]:
return []
+ return self.data[section]["options"][option]["input"].split(";")
def getDisplayName(self, section, option=None):
try:
@@ -202,6 +203,30 @@ class XMLConfigParser():
except:
return False
+ def checkInput(self, section, option, value):
+ oinput = self.getInputValues(section, option)
+ print oinput
+ if oinput:
+ for i in oinput:
+ if i == value:
+ return True
+ return False
+ otype = self.getType(section, option)
+ if not otype:
+ return True
+ if otype == "int" and (type(value) == int or re.match("^\d+$")):
+ return True
+ elif otype == "bool" and (type(value) == bool or re.match("^(true|false|True|False)$")):
+ return True
+ elif otype == "time" and re.match("^[0-2]{0,1}\d:[0-5]{0,1}\d$"):
+ return True
+ elif otype == "ip" and re.match("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"):
+ return True
+ elif otype == "str":
+ return True
+ else:
+ return False
+
class Config(object):
def __init__(self, parser):
self.parser = parser
diff --git a/module/config/core_default.xml b/module/config/core_default.xml
index 0aea08325..8223768ec 100644
--- a/module/config/core_default.xml
+++ b/module/config/core_default.xml
@@ -5,7 +5,6 @@
<listenaddr type="ip" name="Adress">0.0.0.0</listenaddr>
<username type="str" name="Username">admin</username>
<password type="str" name="Password">pwhere</password>
- <test>bla</test>
</remote>
<ssl name="SSL">
<activated type="bool" name="Activated">False</activated>