Ejemplo n.º 1
0
    def validate(self, request, args):
        self.database = database.getInstance()
        output = {"status": 1, "server_time": time.time()}
        dont_run = False
        status = 0
        if self.needsAuth is True:
            if not exists(args, "user") or not exists(args, "token"):
                output["status"] = 2
                dont_run = True
            else:
                test = self.database.get("users", {"user": args["user"]})[0]
                if test["token"] != args["token"]:
                    output["status"] = 3
                    dont_run = True
                if self.needsAdmin is True and (test["permissions"] & perm.ADMIN) is not perm.ADMIN:
                    output["status"] = 4
                    dont_run = True
                for need in self.needs:
                    if need not in args.keys() or args[need] == "":
                        output["status"] = 5
                        dont_run = True
        try:
            if dont_run is False:
                status = self.run(request, args, output)
        except:
            log.trace()
            output["status"] = -1

        if status == server.NOT_DONE_YET:
            return server.NOT_DONE_YET
        if "debug" in args.keys():
            return json.dumps(output, indent=2)
        return json.dumps(output, separators=(",", ":"))
Ejemplo n.º 2
0
 def _event(self, connection, type, user, server, channel, nicks, data,
            master=True, timestamp=time()):
     obj = {"type": type[1], "user": user, "server": server,
            "channel": channel, "nicks": nicks, "data": data,
            "time": timestamp}
     for prop in obj.keys():
         if obj[prop] is None:
             del obj[prop]
     if master:
         logger.d("%s", obj)
         database.getInstance().set('events', obj)
     try:
         getattr(self, type[1])(connection, user, server, channel,
                                nicks, data, master, timestamp)
     except AttributeError:
         pass
     page.pollWaitingConnections(user)