Beispiel #1
0
def runFunction(request, module_key, function_key):

    auth_check = auth(request)
    if auth_check:
        return auth_check

    #assumption: members start with lower-case, classes start with upper-case
    safe_member_keys = [key for key in blazigator.__dict__.keys()
                if not (key.startswith("__") 
                        or inspect.isclass(blazigator.__dict__[key])
                        or inspect.ismodule(blazigator.__dict__[key])
                )
        ]

    if not module_key in safe_member_keys:
        return HttpResponse("naw bro", status =403)

    module = blazigator.__dict__[module_key]
    safe_function_keys = [f for f in dir(module) 
                                if (callable(getattr(module, f))
                                        and not f.startswith("__")
                                )
        ]

    if not function_key in safe_function_keys:
        return HttpResponse("naw bro", status =403)

    ScriptManager.current_script_name = "None.py"
    ScriptManager.run("None.py")

    args = ast.literal_eval(urllib.unquote(request.GET['args']))
    if args:
            return HttpResponse(getattr(module, function_key)(args))
    else:
            return HttpResponse(getattr(module, function_key)())
Beispiel #2
0
def run(request, title):

    auth_check = auth(request)
    if auth_check:
        return auth_check

    ScriptManager.current_script_name = title
    ScriptManager.run(title)
    return redirect("/scripts")
Beispiel #3
0
def scripts(request):

    context = {
        "scripts" : ScriptManager.getScripts(),
        "log_title": ScriptManager.current_script_name
    }

    auth_check = auth(request)
    if auth_check:
        return auth_check
    return render(request, 'OpBoxWebsite/scripts.html', context)
Beispiel #4
0
def edit(request, title):

    auth_check = auth(request)
    if auth_check:
        return auth_check

    context = {
        "default_script" : DEFAULT_SCRIPT,
        "title" : title,
        "content":ScriptManager.getSource(title)
    }

    return render(request, 'OpBoxWebsite/edit.html', context)
Beispiel #5
0
    def __init__(self):
        """Base class initializer.

        Initialize base class and manager classes. Manager classes and their methods form the Driftwood Scripting API.

        Attributes:
            config: ConfigManager instance.
            log: LogManager instance.
            database: DatabaseManager instance.
            filetype: Shortcut to filetype module.
            tick: TickManager instance.
            path: PathManager instance.
            cache: CacheManager instance.
            resource: ResourceManager instance.
            input: InputManager instance.
            window: WindowManager instance.
            entity: EntityManager instance.
            area: AreaManager instance.
            script: ScriptManager instance.

            keycode: Contains the SDL keycodes.

            running: Whether the mainloop should continue running. Set False to shut down the engine.
        """
        self.config = ConfigManager(self)
        self.log = LogManager(self)
        self.database = DatabaseManager(self)
        self.tick = TickManager(self)
        self.path = PathManager(self)
        self.cache = CacheManager(self)
        self.resource = ResourceManager(self)
        self.input = InputManager(self)
        self.window = WindowManager(self)
        self.entity = EntityManager(self)
        self.area = AreaManager(self)
        self.script = ScriptManager(self)

        # SDL Keycodes.
        self.keycode = keycode

        self.running = False
Beispiel #6
0
 def _createView(self):
     sm = ScriptManager()
     sm.addStyle('fonts')
     sm.addStyle('main')
     sm.addStyle('lib/jquery.mCustomScrollbar')
     sm.addStyle('editbox')
     sm.addScript('lib/jquery')
     sm.addScript('lib/jquery.mousewheel')
     sm.addScript('lib/jquery.mCustomScrollbar')
     sm.addScript('tabs')
     sm.addScript('tab')
     sm.addScript('editbox')
     sm.addScript('pathbox')
     sm.addScript('pane')
     sm.addScript('panes')
     sm.addScript('file')
     sm.addScript('files')
     sm.addScript('tasks')
     sm.addScript('task')
     sm.addScript('line')
     sm.addScript('mode_ind')
     sm.addScript('cmdline')
     sm.addScript('kbd')
     sm.addScript('ui')
     sm.addScript('main')
     self._html = App.resman.render('main', {
         'HEAD_CONTENT': sm.render(4)
     })
Beispiel #7
0
class Driftwood:
    """The top-level base class

    This class contains the top level manager class instances and the mainloop. The instance of this class is
    passed to scripts as an API reference.
    """

    def __init__(self):
        """Base class initializer.

        Initialize base class and manager classes. Manager classes and their methods form the Driftwood Scripting API.

        Attributes:
            config: ConfigManager instance.
            log: LogManager instance.
            database: DatabaseManager instance.
            filetype: Shortcut to filetype module.
            tick: TickManager instance.
            path: PathManager instance.
            cache: CacheManager instance.
            resource: ResourceManager instance.
            input: InputManager instance.
            window: WindowManager instance.
            entity: EntityManager instance.
            area: AreaManager instance.
            script: ScriptManager instance.

            keycode: Contains the SDL keycodes.

            running: Whether the mainloop should continue running. Set False to shut down the engine.
        """
        self.config = ConfigManager(self)
        self.log = LogManager(self)
        self.database = DatabaseManager(self)
        self.tick = TickManager(self)
        self.path = PathManager(self)
        self.cache = CacheManager(self)
        self.resource = ResourceManager(self)
        self.input = InputManager(self)
        self.window = WindowManager(self)
        self.entity = EntityManager(self)
        self.area = AreaManager(self)
        self.script = ScriptManager(self)

        # SDL Keycodes.
        self.keycode = keycode

        self.running = False

    def run(self):
        """Perform startup procedures and enter the mainloop.
        """
        # Only run if not already running.
        if not self.running:
            self.running = True

            # Execute the init function of the init script if present.
            if not self.path["init.py"]:
                self.log.msg("WARNING", "Driftwood", "init.py missing, nothing will happen")
            else:
                self.script.call("init.py", "init")

            # Escape key pauses the engine.
            self.input.register(self.keycode.SDLK_ESCAPE, self.__handle_pause)

            # This is the mainloop.
            while self.running:
                # Process SDL events.
                sdlevents = sdl2ext.get_events()
                for event in sdlevents:
                    if event.type == SDL_QUIT:
                        # Stop running.
                        self.running = False

                    elif event.type == SDL_KEYDOWN:
                        # Pass a keydown to the Input Manager.
                        self.input._key_down(event.key.keysym.sym)

                    elif event.type == SDL_KEYUP:
                        # Pass a keyup to the Input Manager.
                        self.input._key_up(event.key.keysym.sym)

                    elif event.type == SDL_WINDOWEVENT and event.window.event == SDL_WINDOWEVENT_EXPOSED:
                        self.window.refresh()

                # Process tick callbacks.
                self.tick.tick()

            print("Shutting down...")
            return 0

    def __handle_pause(self, keyevent):
        if keyevent == InputManager.ONDOWN:
            # Shift+Escape shuts down the engine.
            if self.input.pressed(self.keycode.SDLK_LSHIFT) or self.input.pressed(self.keycode.SDLK_RSHIFT):
                self.running = False

            else:
                self.tick.toggle_pause()