예제 #1
0
    def __init__(self, ip="localhost"):
        RESTServer.__init__(self, ip, HTTPServer.SPAWN_THREAD)
        self._clients = AppData.load()
        self._connected = {}
        self._admins = {}

        self._clients.get_scheduler().main_loop_in_thread()

        self.route("POST", "/connect", AppServer.on_connect, self)
        self.route("GET", "/poll", AppServer.on_poll, self)
        self.route("GET", "/wait", AppServer.on_wait, self)
        self.route("PUT", "/file", AppServer.on_put_file, self)
        self.route("GET", "/file/#id", AppServer.on_get_file, self)
        self.route("POST", "/result", AppServer.on_result, self)
        self.route("GET", "/result/#clientid/#cmdid", AppServer.on_get_result,
                   self)
        self.route("GET", "/admin/login", AppServer.admin_on_auth, self)
        self.route("GET", "/admin/disconnect", AppServer.admin_on_disconnect,
                   self)
        self.route("POST", "/admin/command", AppServer.admin_on_command, self)
        self.route("POST", "/admin/command/texte",
                   AppServer.admin_on_command_texte, self)
        self.route("POST", "/admin/server/command",
                   AppServer.admin_on_server_command, self)

        self.route(["GET", "POST"], MOUSTACHES_FILES,
                   AppServer.admin_moustache, self)
        self.static("/admin",
                    "www",
                    authcb=Callback(AppServer.is_authorized, self),
                    needauthcb=Callback(AppServer.need_auth, self))