Module: check_mk
Branch: master
Commit: 35e4bc2344a4fa42c032ca0f6a12a3afc4bfe91c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=35e4bc2344a4fa…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Dec 10 13:20:07 2013 +0100
Implement file upload for WSGI module
---
web/htdocs/check_mk.css | 4 ++++
web/htdocs/html_mod_python.py | 32 +-------------------------------
web/htdocs/htmllib.py | 36 ++++++++++++++++++++++++++++++++++--
3 files changed, 39 insertions(+), 33 deletions(-)
diff --git a/web/htdocs/check_mk.css b/web/htdocs/check_mk.css
index 43c727a..fb505aa 100644
--- a/web/htdocs/check_mk.css
+++ b/web/htdocs/check_mk.css
@@ -88,6 +88,10 @@ input, select, textarea {
margin-top: 0px;
}
+input[type=file] {
+ color: black;
+}
+
form {
margin: 0px;
}
diff --git a/web/htdocs/html_mod_python.py b/web/htdocs/html_mod_python.py
index e104bb3..3ad0d04 100644
--- a/web/htdocs/html_mod_python.py
+++ b/web/htdocs/html_mod_python.py
@@ -3,8 +3,6 @@ import htmllib
import os, time, config, weblib, re
import defaults
-varname_regex = re.compile('^[\w\d_.%+-\\\*]+$')
-
class html_mod_python(htmllib.html):
def __init__(self, req):
@@ -43,36 +41,8 @@ class html_mod_python(htmllib.html):
self.cookies = Cookie.get_cookies(self.req)
def read_get_vars(self):
- self.vars = {}
- self.listvars = {} # for variables with more than one occurrance
- self.uploads = {}
fields = util.FieldStorage(self.req, keep_blank_values = 1)
- for field in fields.list:
- varname = field.name
- value = field.value
-
- # To prevent variours injections, we only allow a defined set
- # of characters to be used in variables
- if not varname_regex.match(varname):
- continue
-
- # Multiple occurrance of a variable? Store in extra list dict
- if varname in self.vars:
- if varname in self.listvars:
- self.listvars[varname].append(value)
- else:
- self.listvars[varname] = [ self.vars[varname], value ]
- # In the single-value-store the last occurrance of a variable
- # has precedence. That makes appending variables to the current
- # URL simpler.
- self.vars[varname] = value
-
- # put uploaded file infos into separate storage
- if field.filename is not None:
- self.uploads[varname] = (field.filename, field.type, field.value)
-
- def uploaded_file(self, varname, default = None):
- return self.uploads.get(varname, default)
+ self.parse_field_storage(fields)
def lowlevel_write(self, text):
if self.io_error:
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index a54368d..c628238 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -34,6 +34,9 @@ try:
except NameError:
from sets import Set as set
+# Only parse variable adhering to the following regular expressions
+varname_regex = re.compile('^[\w\d_.%+-\\\*]+$')
+
# Information about uri
class InvalidUserInput(Exception):
def __init__(self, varname, text):
@@ -1245,13 +1248,42 @@ class html:
self.load_tree_states()
self.treestates[tree] = val
+ def parse_field_storage(self, fields):
+ self.vars = {}
+ self.listvars = {} # for variables with more than one occurrance
+ self.uploads = {}
+
+ for field in fields.list:
+ varname = field.name
+ value = field.value
+
+ # To prevent variours injections, we only allow a defined set
+ # of characters to be used in variables
+ if not varname_regex.match(varname):
+ continue
+
+ # put uploaded file infos into separate storage
+ if field.filename is not None:
+ self.uploads[varname] = (field.filename, field.type, field.value)
+
+ else: # normal variable
+ # Multiple occurrance of a variable? Store in extra list dict
+ if varname in self.vars:
+ if varname in self.listvars:
+ self.listvars[varname].append(value)
+ else:
+ self.listvars[varname] = [ self.vars[varname], value ]
+ # In the single-value-store the last occurrance of a variable
+ # has precedence. That makes appending variables to the current
+ # URL simpler.
+ self.vars[varname] = value
+
def uploaded_file(self, varname, default = None):
- raise MKGeneralException("uploaded_file not implemented")
+ return self.uploads.get(varname, default)
#
# Per request caching
#
-
def set_cache(self, name, value):
self.caches[name] = value