def addResourceTarget(module,type,name,kwargs): pages.require("/admin/modules.edit") #Create a permission if type == 'permission': with modulesLock: if kwargs['name'] in ActiveModules[module]: raise cherrypy.HTTPRedirect("/errors/alreadyexists") else: ActiveModules[module] [kwargs['name']]= {"resource-type":"permission","description":kwargs['description']} #has its own lock auth.importPermissionsFromModules() #sync auth's list of permissions raise cherrypy.HTTPRedirect("/modules/module/" +util.url(module)+ '/resource/' + util.url(name) ) if type == 'event': with modulesLock: if kwargs['name'] not in ActiveModules[module]: ActiveModules[module] [kwargs['name']]= {"resource-type":"event","trigger":"False","action":"pass", "once":True} #newevt maintains a cache of precompiled events that must be kept in sync with #the modules newevt.updateOneEvent(kwargs['name'],module) raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module)+'/resource/'+util.url(name)) else: raise cherrypy.HTTPRedirect("/errors/alreadyexists") if type == 'page': with modulesLock: if kwargs['name'] not in ActiveModules[module]: ActiveModules[module][kwargs['name']]= {"resource-type":"page","body":"Content here",'no-navheader':True} #newevt maintains a cache of precompiled events that must be kept in sync with #the modules raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module)+'/resource/'+util.url(name)) else: raise cherrypy.HTTPRedirect("/errors/alreadyexists")
def deletemoduletarget(self,**kwargs): pages.require("/admin/modules.edit") with modulesLock: ActiveModules.pop(kwargs['name']) #Get rid of any lingering cached events newevt.removeModuleEvents(kwargs['name']) #Get rid of any permissions defined in the modules. auth.importPermissionsFromModules() raise cherrypy.HTTPRedirect("/modules")
def resourceUpdateTarget(module, resource, kwargs): pages.require("/admin/modules.edit") global moduleschanged moduleschanged = True with modulesLock: t = ActiveModules[module][resource]['resource-type'] resourceobj = ActiveModules[module][resource] if t == 'permission': resourceobj['description'] = kwargs['description'] #has its own lock auth.importPermissionsFromModules( ) #sync auth's list of permissions if t == 'event': e = newevt.Event(kwargs['trigger'], kwargs['action'], {}) #Test compile, throw error on fail. resourceobj['trigger'] = kwargs['trigger'] resourceobj['action'] = kwargs['action'] resourceobj['setup'] = kwargs['setup'] resourceobj['priority'] = max([int(kwargs['priority']), 0]) resourceobj['continual'] = 'continual' in kwargs resourceobj['rate-limit'] = float(kwargs['ratelimit']) #I really need to do something about this possibly brittle bookkeeping system #But anyway, when the active modules thing changes we must update the newevt cache thing. newevt.updateOneEvent(resource, module) if t == 'page': resourceobj['body'] = kwargs['body'] resourceobj['no-navheader'] = 'no-navheader' in kwargs resourceobj['no-header'] = 'no-header' in kwargs resourceobj['dont-show-in-index'] = 'dont-show-in-index' in kwargs #Method checkboxes resourceobj['require-method'] = [] if 'allow-GET' in kwargs: resourceobj['require-method'].append('GET') if 'allow-POST' in kwargs: resourceobj['require-method'].append('POST') #permission checkboxes resourceobj['require-permissions'] = [] for i in kwargs: #Since HTTP args don't have namespaces we prefix all the permission checkboxes with permission if i[:10] == 'Permission': if kwargs[i] == 'true': resourceobj['require-permissions'].append(i[10:]) usrpages.updateOnePage(resource, module) messagebus.postMessage( "/system/notifications", "User " + pages.getAcessingUser() + " modified resource " + resource + " of module " + module) #Return user to the module page raise cherrypy.HTTPRedirect( "/modules/module/" + util.url(module)) #+'/resource/'+util.url(resource))
def deletemoduletarget(self,**kwargs): pages.require("/admin/modules.edit") global moduleschanged moduleschanged = True with modulesLock: ActiveModules.pop(kwargs['name']) #Get rid of any lingering cached events newevt.removeModuleEvents(kwargs['name']) #Get rid of any permissions defined in the modules. auth.importPermissionsFromModules() usrpages.removeModulePages(kwargs['name']) messagebus.postMessage("/system/notifications","User "+ pages.getAcessingUser() + " Deleted module " + kwargs['name']) raise cherrypy.HTTPRedirect("/modules")
def module(self,module,*path,**kwargs): #If we are not performing an action on a module just going to its page if not path: pages.require("/admin/modules.view") return pages.get_template("modules/module.html").render(module = ActiveModules[module],name = module) else: #This gets the interface to add a page if path[0] == 'addresource': #path[1] tells what type of resource is being created and addResourceDispatcher returns the appropriate crud screen return addResourceDispatcher(module,path[1]) #This case handles the POST request from the new resource target if path[0] == 'addresourcetarget': return addResourceTarget(module,path[1],kwargs['name'],kwargs) #This case shows the information and editing page for one resource if path[0] == 'resource': return resourceEditPage(module,path[1]) #This goes to a dispatcher that takes into account the type of resource and updates everything about the resource. if path[0] == 'updateresource': return resourceUpdateTarget(module,path[1],kwargs) #This returns a page to delete any resource by name if path[0] == 'deleteresource': pages.require("/admin/modules.edit") return pages.get_template("modules/deleteresource.html").render(module=module) #This handles the POST request to actually do the deletion if path[0] == 'deleteresourcetarget': pages.require("/admin/modules.edit") with modulesLock: r = ActiveModules[module].pop(kwargs['name']) #Annoying bookkeeping crap to get rid of the cached crap if r['resource-type'] == 'event': newevt.removeOneEvent(kwargs['name']) if r['resource-type'] == 'permission': auth.importPermissionsFromModules() #sync auth's list of permissions raise cherrypy.HTTPRedirect('/modules') #This is the target used to change the name and description(basic info) of a module if path[0] == 'update': pages.require("/admin/modules.edit") with modulesLock: ActiveModules[kwargs['name']] = ActiveModules.pop(module) ActiveModules[module]['__description']['text'] = kwargs['description'] raise cherrypy.HTTPRedirect('/modules/module/'+util.url(kwargs['name']))
def addResourceTarget(module, type, name, kwargs): pages.require("/admin/modules.edit") global moduleschanged moduleschanged = True def insertResource(r): ActiveModules[module][kwargs['name']] = r with modulesLock: #Check if a resource by that name is already there if kwargs['name'] in ActiveModules[module]: raise cherrypy.HTTPRedirect("/errors/alreadyexists") #Create a permission if type == 'permission': insertResource({ "resource-type": "permission", "description": kwargs['description'] }) #has its own lock auth.importPermissionsFromModules( ) #sync auth's list of permissions if type == 'event': insertResource({ "resource-type": "event", "trigger": "False", "action": "pass", "once": True }) #newevt maintains a cache of precompiled events that must be kept in sync with #the modules newevt.updateOneEvent(kwargs['name'], module) if type == 'page': insertResource({ "resource-type": "page", "body": "Content here", 'no-navheader': True }) usrpages.updateOnePage(kwargs['name'], module) messagebus.postMessage( "/system/notifications", "User " + pages.getAcessingUser() + " added resource " + kwargs['name'] + " of type " + type + " to module " + module) #Take the user straight to the resource page raise cherrypy.HTTPRedirect("/modules/module/" + util.url(module) + '/resource/' + util.url(name))
def resourceUpdateTarget(module,resource,kwargs): pages.require("/admin/modules.edit") global moduleschanged moduleschanged = True with modulesLock: t = ActiveModules[module][resource]['resource-type'] resourceobj = ActiveModules[module][resource] if t == 'permission': resourceobj['description'] = kwargs['description'] #has its own lock auth.importPermissionsFromModules() #sync auth's list of permissions if t == 'event': e = newevt.Event(kwargs['trigger'],kwargs['action'],{})#Test compile, throw error on fail. resourceobj['trigger'] = kwargs['trigger'] resourceobj['action'] = kwargs['action'] resourceobj['setup'] = kwargs['setup'] resourceobj['priority'] = max([int(kwargs['priority']),0]) resourceobj['continual'] = 'continual' in kwargs resourceobj['rate-limit'] = float(kwargs['ratelimit']) #I really need to do something about this possibly brittle bookkeeping system #But anyway, when the active modules thing changes we must update the newevt cache thing. newevt.updateOneEvent(resource,module) if t == 'page': resourceobj['body'] = kwargs['body'] resourceobj['no-navheader'] = 'no-navheader' in kwargs resourceobj['no-header'] = 'no-header' in kwargs resourceobj['dont-show-in-index'] = 'dont-show-in-index' in kwargs #Method checkboxes resourceobj['require-method'] = [] if 'allow-GET' in kwargs: resourceobj['require-method'].append('GET') if 'allow-POST' in kwargs: resourceobj['require-method'].append('POST') #permission checkboxes resourceobj['require-permissions'] = [] for i in kwargs: #Since HTTP args don't have namespaces we prefix all the permission checkboxes with permission if i[:10] == 'Permission': if kwargs[i] == 'true': resourceobj['require-permissions'].append(i[10:]) usrpages.updateOnePage(resource,module) messagebus.postMessage("/system/notifications", "User "+ pages.getAcessingUser() + " modified resource " + resource + " of module " + module) #Return user to the module page raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module))#+'/resource/'+util.url(resource))
def deletemoduletarget(self, **kwargs): pages.require("/admin/modules.edit") global moduleschanged moduleschanged = True with modulesLock: ActiveModules.pop(kwargs['name']) #Get rid of any lingering cached events newevt.removeModuleEvents(kwargs['name']) #Get rid of any permissions defined in the modules. auth.importPermissionsFromModules() usrpages.removeModulePages(kwargs['name']) messagebus.postMessage( "/system/notifications", "User " + pages.getAcessingUser() + " Deleted module " + kwargs['name']) raise cherrypy.HTTPRedirect("/modules")
def loadAll(): for i in range(0,15): #Gets the highest numbered of all directories that are named after floating point values(i.e. most recent timestamp) name = util.getHighestNumberedTimeDirectory(directories.moduledir) possibledir = os.path.join(directories.moduledir,name) #__COMPLETE__ is a special file we write to the dump directory to show it as valid if '''__COMPLETE__''' in util.get_files(possibledir): loadModules(possibledir) auth.importPermissionsFromModules() break #We sucessfully found the latest good ActiveModules dump! so we break the loop else: #If there was no flag indicating that this was an actual complete dump as opposed #To an interruption, rename it and try again shutil.copytree(possibledir,os.path.join(directories.moduledir,name+"INCOMPLETE")) shutil.rmtree(possibledir)
def loadAll(): for i in range(0, 15): #Gets the highest numbered of all directories that are named after floating point values(i.e. most recent timestamp) name = util.getHighestNumberedTimeDirectory(directories.moduledir) possibledir = os.path.join(directories.moduledir, name) #__COMPLETE__ is a special file we write to the dump directory to show it as valid if '''__COMPLETE__''' in util.get_files(possibledir): loadModules(possibledir) auth.importPermissionsFromModules() break #We sucessfully found the latest good ActiveModules dump! so we break the loop else: #If there was no flag indicating that this was an actual complete dump as opposed #To an interruption, rename it and try again shutil.copytree( possibledir, os.path.join(directories.moduledir, name + "INCOMPLETE")) shutil.rmtree(possibledir)
def addResourceTarget(module,type,name,kwargs): pages.require("/admin/modules.edit") global moduleschanged moduleschanged = True def insertResource(r): ActiveModules[module][kwargs['name']] = r with modulesLock: #Check if a resource by that name is already there if kwargs['name'] in ActiveModules[module]: raise cherrypy.HTTPRedirect("/errors/alreadyexists") #Create a permission if type == 'permission': insertResource({ "resource-type":"permission", "description":kwargs['description']}) #has its own lock auth.importPermissionsFromModules() #sync auth's list of permissions if type == 'event': insertResource({ "resource-type":"event", "trigger":"False", "action":"pass", "once":True}) #newevt maintains a cache of precompiled events that must be kept in sync with #the modules newevt.updateOneEvent(kwargs['name'],module) if type == 'page': insertResource({ "resource-type":"page", "body":"Content here", 'no-navheader':True}) usrpages.updateOnePage(kwargs['name'],module) messagebus.postMessage("/system/notifications", "User "+ pages.getAcessingUser() + " added resource " + kwargs['name'] + " of type " + type+" to module " + module) #Take the user straight to the resource page raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module)+'/resource/'+util.url(name))
def resourceUpdateTarget(module,resource,kwargs): pages.require("/admin/modules.edit") t = ActiveModules[module][resource]['resource-type'] if t == 'permission': with modulesLock: ActiveModules[module][resource]['description'] = kwargs['description'] #has its own lock auth.importPermissionsFromModules() #sync auth's list of permissions if t == 'event': with modulesLock: e = newevt.Event(kwargs['trigger'],kwargs['action'],{})#Test compile, throw error on fail. ActiveModules[module][resource]['trigger'] = kwargs['trigger'] ActiveModules[module][resource]['action'] = kwargs['action'] #I really need to do something about this possibly brittle bookkeeping system #But anyway, when the active modules thing changes we must update the newevt cache thing. newevt.updateOneEvent(resource,module) if t == 'page': with modulesLock: pageinquestion = ActiveModules[module][resource] pageinquestion['body'] = kwargs['body'] pageinquestion['no-navheader'] = 'no-navheader' in kwargs #Method checkboxes pageinquestion['require-method'] = [] if 'allow-GET' in kwargs: pageinquestion['require-method'].append('GET') if 'allow-POST' in kwargs: pageinquestion['require-method'].append('POST') #permission checkboxes pageinquestion['require-permissions'] = [] for i in kwargs: #Since HTTP args don't have namespaces we prefix all the permission checkboxes with permission if i[:10] == 'Permission': if kwargs[i] == 'true': pageinquestion['require-permissions'].append(i[10:]) #Return user to the module page raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module))#+'/resource/'+util.url(resource))
def module(self,module,*path,**kwargs): global moduleschanged #If we are not performing an action on a module just going to its page if not path: pages.require("/admin/modules.view") return pages.get_template("modules/module.html").render(module = ActiveModules[module],name = module) else: #This gets the interface to add a page if path[0] == 'addresource': #path[1] tells what type of resource is being created and addResourceDispatcher returns the appropriate crud screen return addResourceDispatcher(module,path[1]) #This case handles the POST request from the new resource target if path[0] == 'addresourcetarget': return addResourceTarget(module,path[1],kwargs['name'],kwargs) #This case shows the information and editing page for one resource if path[0] == 'resource': return resourceEditPage(module,path[1]) #This goes to a dispatcher that takes into account the type of resource and updates everything about the resource. if path[0] == 'updateresource': return resourceUpdateTarget(module,path[1],kwargs) #This returns a page to delete any resource by name if path[0] == 'deleteresource': pages.require("/admin/modules.edit") return pages.get_template("modules/deleteresource.html").render(module=module) #This handles the POST request to actually do the deletion if path[0] == 'deleteresourcetarget': pages.require("/admin/modules.edit") moduleschanged = True with modulesLock: r = ActiveModules[module].pop(kwargs['name']) if r['resource-type'] == 'page': usrpages.removeOnePage(module,kwargs['name']) #Annoying bookkeeping crap to get rid of the cached crap if r['resource-type'] == 'event': newevt.removeOneEvent(module,kwargs['name']) if r['resource-type'] == 'permission': auth.importPermissionsFromModules() #sync auth's list of permissions messagebus.postMessage("/system/notifications","User "+ pages.getAcessingUser() + " deleted resource " + kwargs['name'] + " from module " + module) raise cherrypy.HTTPRedirect('/modules') #This is the target used to change the name and description(basic info) of a module if path[0] == 'update': pages.require("/admin/modules.edit") moduleschanged = True with modulesLock: ActiveModules[module]['__description']['text'] = kwargs['description'] ActiveModules[kwargs['name']] = ActiveModules.pop(module) #UHHG. So very much code tht just syncs data structures. #This gets rid of the cache under the old name newevt.removeModuleEvents(module) usrpages.removeModulePages(module) #And calls this function the generate the new cache bookkeeponemodule(kwargs['name']) #Just for fun, we should probably also sync the permissions auth.importPermissionsFromModules() raise cherrypy.HTTPRedirect('/modules/module/'+util.url(kwargs['name']))
def module(self, module, *path, **kwargs): global moduleschanged #If we are not performing an action on a module just going to its page if not path: pages.require("/admin/modules.view") return pages.get_template("modules/module.html").render( module=ActiveModules[module], name=module) else: #This gets the interface to add a page if path[0] == 'addresource': #path[1] tells what type of resource is being created and addResourceDispatcher returns the appropriate crud screen return addResourceDispatcher(module, path[1]) #This case handles the POST request from the new resource target if path[0] == 'addresourcetarget': return addResourceTarget(module, path[1], kwargs['name'], kwargs) #This case shows the information and editing page for one resource if path[0] == 'resource': return resourceEditPage(module, path[1]) #This goes to a dispatcher that takes into account the type of resource and updates everything about the resource. if path[0] == 'updateresource': return resourceUpdateTarget(module, path[1], kwargs) #This returns a page to delete any resource by name if path[0] == 'deleteresource': pages.require("/admin/modules.edit") return pages.get_template( "modules/deleteresource.html").render(module=module) #This handles the POST request to actually do the deletion if path[0] == 'deleteresourcetarget': pages.require("/admin/modules.edit") moduleschanged = True with modulesLock: r = ActiveModules[module].pop(kwargs['name']) if r['resource-type'] == 'page': usrpages.removeOnePage(module, kwargs['name']) #Annoying bookkeeping crap to get rid of the cached crap if r['resource-type'] == 'event': newevt.removeOneEvent(module, kwargs['name']) if r['resource-type'] == 'permission': auth.importPermissionsFromModules( ) #sync auth's list of permissions messagebus.postMessage( "/system/notifications", "User " + pages.getAcessingUser() + " deleted resource " + kwargs['name'] + " from module " + module) raise cherrypy.HTTPRedirect('/modules') #This is the target used to change the name and description(basic info) of a module if path[0] == 'update': pages.require("/admin/modules.edit") moduleschanged = True with modulesLock: ActiveModules[module]['__description']['text'] = kwargs[ 'description'] ActiveModules[kwargs['name']] = ActiveModules.pop(module) #UHHG. So very much code tht just syncs data structures. #This gets rid of the cache under the old name newevt.removeModuleEvents(module) usrpages.removeModulePages(module) #And calls this function the generate the new cache bookkeeponemodule(kwargs['name']) #Just for fun, we should probably also sync the permissions auth.importPermissionsFromModules() raise cherrypy.HTTPRedirect('/modules/module/' + util.url(kwargs['name']))