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=(",", ":"))
def set(self, collection, query): if collection == 'users': coll = self.users elif collection == 'events': coll = self.events else: raise InvalidQuery try: coll.insert(query) except: log.trace() raise InvalidQuery
def get(self, collection, query): if collection == 'users': coll = self.users elif collection == 'events': coll = self.events else: raise InvalidQuery try: output = list(coll.find(query)) for obj in output: try: for key in obj: o = obj[key] if type(o) == 'unicode': obj[key] = str(o.encode('utf16', 'replace')) del obj['_id'] except: pass return output except: log.trace() raise InvalidQuery
def main(argv=None): # Set up some custom exception handling; handle exceptions nicely using # the logger module sys.excepthook = eyearexception logger.getInstance().level = config.LOG_LEVEL # Set up the HTTP server reactor.listenTCP(config.HTTP_PORT, http.getInstance()) # Reconnect users to their servers & channels users = database.get('users', {}) for user in users: if 'servers' in user.keys(): for server in user['servers']: try: addr = server['addr'] chans = server['channels'] irc.connect(user['user'], addr, chans) except irc.UserNotConnected: logger.e("%s couldn't connect to %s", user['user'], server) logger.trace() # Start doing MAGIC reactor.run()