Beispiel #1
0
 def newmoduletarget(self, **kwargs):
     global scopes
     pages.require("/admin/modules.edit")
     global moduleschanged
     moduleschanged = True
     #If there is no module by that name, create a blank template and the scope obj
     with modulesLock:
         if kwargs['name'] not in ActiveModules:
             ActiveModules[kwargs['name']] = {
                 "__description": {
                     "resource-type": "module-description",
                     "text": "Module info here"
                 }
             }
             #Create the scope that code in the module will run in
             scopes[kwargs['name']] = obj()
             #Go directly to the newly created module
             messagebus.postMessage(
                 "/system/notifications",
                 "User " + pages.getAcessingUser() + " Created Module " +
                 kwargs['name'])
             raise cherrypy.HTTPRedirect("/modules/module/" +
                                         util.url(kwargs['name']))
         else:
             return pages.get_template("error.html").render(
                 info=" A module already exists by that name,")
Beispiel #2
0
def load_modules_from_zip(f):
    "Given a zip file, import all modules found therin."
    new_modules = {}
    z = zipfile.ZipFile(f)

    for i in z.namelist():
        #get just the folder, ie the module
        p = unurl(i.split('/')[0])
        #Remove the.json by getting rid of last 5 chars
        n = unurl((i.split('/'))[1][:-5])
        if p not in new_modules:
            new_modules[p] = {}
        f = z.open(i)
        new_modules[p][n] = json.loads(f.read().decode())
        f.close()
    
    with modulesLock:
        for i in new_modules:
            if i in ActiveModules:
                raise cherrypy.HTTPRedirect("/errors/alreadyexists")
        for i in new_modules:
            ActiveModules[i] = new_modules[i]
            messagebus.postMessage("/system/notifications","User "+ pages.getAcessingUser() + " uploaded module" + i + " from a zip file")    
            bookkeeponemodule(i)
            
    z.close()
Beispiel #3
0
def load_modules_from_zip(f):
    "Given a zip file, import all modules found therin."
    new_modules = {}
    z = zipfile.ZipFile(f)

    for i in z.namelist():
        #get just the folder, ie the module
        p = unurl(i.split('/')[0])
        #Remove the.json by getting rid of last 5 chars
        n = unurl((i.split('/'))[1][:-5])
        if p not in new_modules:
            new_modules[p] = {}
        f = z.open(i)
        new_modules[p][n] = json.loads(f.read().decode())
        f.close()

    with modulesLock:
        for i in new_modules:
            if i in ActiveModules:
                raise cherrypy.HTTPRedirect("/errors/alreadyexists")
        for i in new_modules:
            ActiveModules[i] = new_modules[i]
            messagebus.postMessage(
                "/system/notifications", "User " + pages.getAcessingUser() +
                " uploaded module" + i + " from a zip file")
            bookkeeponemodule(i)

    z.close()
Beispiel #4
0
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))
Beispiel #5
0
 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")
Beispiel #6
0
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))
Beispiel #7
0
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))
Beispiel #8
0
 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")
Beispiel #9
0
 def newmoduletarget(self,**kwargs):
     global scopes
     pages.require("/admin/modules.edit")
     global moduleschanged
     moduleschanged = True
     #If there is no module by that name, create a blank template and the scope obj
     with modulesLock:
         if kwargs['name'] not in ActiveModules:
             ActiveModules[kwargs['name']] = {"__description":
             {"resource-type":"module-description",
             "text":"Module info here"}}
             #Create the scope that code in the module will run in
             scopes[kwargs['name']] = obj()
             #Go directly to the newly created module
             messagebus.postMessage("/system/notifications","User "+ pages.getAcessingUser() + " Created Module " + kwargs['name'])    
             raise cherrypy.HTTPRedirect("/modules/module/"+util.url(kwargs['name']))
         else:
             return pages.get_template("error.html").render(info = " A module already exists by that name,")
Beispiel #10
0
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))
Beispiel #11
0
    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']))
Beispiel #12
0
    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']))