def getModule(self,modname): """ Find, load, return the requested module """ mhandle = None mfile = "%s/pandamon/pmModules/%s.py" % ( self.pandadir, modname ) if os.path.exists(mfile): mpath = os.path.dirname(mfile) pythonpath = sys.path if not mpath in pythonpath: # Add the path of this module to pythonpath sys.path.append(mpath) mhandle = __import__(modname) if mhandle == None: raise ValueError(mfile) else: raise ValueError("%s" % utils.reportWarning('Module %s not found under %s name ' % (modname, mfile)) ) return mhandle
def getModule(self, modname): """ Find, load, return the requested module """ mhandle = None mfile = "%s/pandamon/pmModules/%s.py" % (self.pandadir, modname) if os.path.exists(mfile): mpath = os.path.dirname(mfile) pythonpath = sys.path if not mpath in pythonpath: # Add the path of this module to pythonpath sys.path.append(mpath) mhandle = __import__(modname) if mhandle == None: raise ValueError(mfile) else: raise ValueError( "%s" % utils.reportWarning('Module %s not found under %s name ' % (modname, mfile))) return mhandle
def parseQueryString(query): """Return a dictionary of key value pairs given in the query string""" qdict = {} params = query.split('?') """Return if nothing or nothing after the '?'""" if len(params) == 0 or len(params) == 1 : return qdict if len(params[1]) == 0 : return qdict if len(params) != 1: params = params[1].split('&') for p in params: pair = p.split('=') if len(pair) > 1: pair[1] = urllib.unquote_plus(pair[1]) #qdict[pair[0]] = pair[1] if pair[0].find(";")>0: qdict[pair[0].split(";")[1]] = pair[1] else: qdict[pair[0]] = pair[1] else: #qdict[pair[0]] = '' if pair[0].find(";")>0: qdict[pair[0].split(";")[1]] = '' else: qdict[pair[0]] = '' ## string checking for key, value pair ## proceed = True for key in qdict: keyok = checkString(key) if not keyok in [0, 1]: newkey = keyok qdict[newkey] = qdict[key] del qdict[key] keyok = True if keyok: valok = checkString(qdict[key]) if not valok in [0, 1]: qdict[key] = valok valok = True if not valok: qdicttxt =utils.cleanParamsUp(qdict[key]) increport = "Invalid parameter value: [%s] for key: [%s]" % (qdicttxt, utils.cleanParamsUp(key)) print increport try: if key != 'errinfo': utils.recordIncident(increport, 'monsecurity') utils.reportWarning(increport) except: pass proceed = False else: if not str(qdict[key]) == '': utils.reportWarning("Invalid parameter key: %s" % utils.cleanParamsUp(key)) proceed = False if proceed: return qdict else: return {}
def parseQueryString(query): """Return a dictionary of key value pairs given in the query string""" qdict = {} params = query.split('?') """Return if nothing or nothing after the '?'""" if len(params) == 0 or len(params) == 1: return qdict if len(params[1]) == 0: return qdict if len(params) != 1: params = params[1].split('&') for p in params: pair = p.split('=') if len(pair) > 1: pair[1] = urllib.unquote_plus(pair[1]) #qdict[pair[0]] = pair[1] if pair[0].find(";") > 0: qdict[pair[0].split(";")[1]] = pair[1] else: qdict[pair[0]] = pair[1] else: #qdict[pair[0]] = '' if pair[0].find(";") > 0: qdict[pair[0].split(";")[1]] = '' else: qdict[pair[0]] = '' ## string checking for key, value pair ## proceed = True for key in qdict: keyok = checkString(key) if not keyok in [0, 1]: newkey = keyok qdict[newkey] = qdict[key] del qdict[key] keyok = True if keyok: valok = checkString(qdict[key]) if not valok in [0, 1]: qdict[key] = valok valok = True if not valok: qdicttxt = utils.cleanParamsUp(qdict[key]) increport = "Invalid parameter value: [%s] for key: [%s]" % ( qdicttxt, utils.cleanParamsUp(key)) print increport try: if key != 'errinfo': utils.recordIncident(increport, 'monsecurity') utils.reportWarning(increport) except: pass proceed = False else: if not str(qdict[key]) == '': utils.reportWarning("Invalid parameter key: %s" % utils.cleanParamsUp(key)) proceed = False if proceed: return qdict else: return {}