コード例 #1
0
ファイル: statserver.py プロジェクト: lkj01010/mypy
    def get(self):
        """
        type:0  停机维护
            msg:
        """
        print self.request.remote_ip
        if self.request.remote_ip == '127.0.0.1':
            command = self.get_argument('cmd')
            cmd_dict = json.JSONDecoder().decode(command)
            server_log.warn( 'cmd is: ' + str(cmd_dict))
            try:
                if cmd_dict["type"] == 0:
                    self.application.server_state_msg = cmd_dict["msg"]
                    self.application.server_running = False
                elif cmd_dict["type"] == 1:
                    self.application.server_state_msg = ""
                    self.application.server_running = True

                """存档服务器"""
                request = tornado.httpclient.HTTPRequest(cfg.RECORD_SERVER + '/cmd', method='POST', body=command)
                self.application.client.fetch(request, callback=CommandHandler.cmd_callback)
                """openapi服务器"""
                request = tornado.httpclient.HTTPRequest(cfg.TENCENT_ACCOUNT_SERVER + '/cmd', method='POST',
                                                         body=command)
                self.application.client.fetch(request, callback=CommandHandler.cmd_callback)

                self.write("hello")
                # self.send_error()
            except KeyError:
                pass
        pass
コード例 #2
0
    async def add_listener(self, listener: Listener) -> None:
        """Registers listener allowing it to recieve events."""

        if listener.user_id is None:
            server_log.warn(
                f"Emitter: unable to add listener, user_id is None"
            )
            return

        channels = await self._app["pg_conn"].fetchval(
            "SELECT channel_ids FROM users WHERE id = $1", listener.user_id
        )

        async with self._lock:
            for channel_id in channels:
                if channel_id in self._channels:
                    self._channels[channel_id].add(listener.user_id)
                else:
                    self._channels[channel_id] = {listener.user_id}

            self._users[listener.user_id] = set(channels)

            if listener.user_id in self._listeners:
                self._listeners[listener.user_id].add(listener)
            else:
                self._listeners[listener.user_id] = {listener}
コード例 #3
0
ファイル: check_login.py プロジェクト: lkj01010/mypy
    def check_info(self, user_id, user_key, zoneid, callback):
        self.check_ret_callback = callback

        if cfg.IS_REMOTE == 0:
            self.check_ret_callback(True)
        else:
            is_need_check = False
            if user_id in LoginChecker.user_cache.keys():
                if user_key in LoginChecker.user_cache[user_id]:
                    server_log.warn('check ok, account in cache')
                    self.check_ret_callback(True)
                else:
                    is_need_check = True
            else:
                '''insure key-set in user_cache'''
                LoginChecker.user_cache[user_id] = set()
                server_log.warn('user_cache len: %d, user add: %s' %
                                (len(LoginChecker.user_cache), user_id))
                is_need_check = True

            if is_need_check:
                server_log.info('need check_info, user_id = ' + user_id +
                                'user_key = ' + user_key)
                '''should check from tencent server'''
                request = tornado.httpclient.HTTPRequest(
                    cfg.TENCENT_ACCOUNT_SERVER + '/?openid=' + user_id +
                    '&openkey=' + user_key + '&user_pf=' + zoneid +
                    '&api=k_playzone_userinfo' + '&platform=qzone' +
                    '&callback=cb',
                    method='GET')
                server_log.info('new active url: ' + request.url)
                self.chk_client.fetch(request,
                                      callback=self._check_response_callback)
コード例 #4
0
ファイル: check_login.py プロジェクト: lkj01010/mypy
    def _check_response_callback(self, response):
        server_log.info('check_callback: ' + str(response.body))

        is_valid = False
        if response and response.body:
            j_body = json.JSONDecoder().decode(response.body.lstrip('cb(').rstrip(')'))

            server_log.warn('in _check_response_callback0, user_cache len: %d' % len(LoginChecker.user_cache))
            # [[
            if 'data'in j_body and j_body['is_ok'] == 1 and 'openid' in j_body and 'openkey' in j_body:
                openid = j_body['openid']
                if openid in LoginChecker.user_cache:
                    pass
                else:
                    LoginChecker.user_cache[openid] = set()
                    server_log.warn('in _check_response_callback1, user_cache len: %d' % len(LoginChecker.user_cache))
                LoginChecker.user_cache[openid].add(j_body['openkey'])
                is_valid = True

            # ==============> test
            # openid = j_body['openid']
            # if openid in LoginChecker.user_cache:
            #     pass
            # else:
            #     LoginChecker.user_cache[openid] = set()
            # LoginChecker.user_cache[openid].add(j_body['openkey'])
            # is_valid = True

            # ]]

        self.check_ret_callback(is_valid)
コード例 #5
0
ファイル: check_login.py プロジェクト: lkj01010/mypy
    def check_info(self, user_id, user_key, zoneid, callback):
        self.check_ret_callback = callback

        if cfg.IS_REMOTE == 0:
            self.check_ret_callback(True)
        else:
            is_need_check = False
            if user_id in LoginChecker.user_cache.keys():
                if user_key in LoginChecker.user_cache[user_id]:
                    server_log.warn('check ok, account in cache')
                    self.check_ret_callback(True)
                else:
                    is_need_check = True
            else:
                '''insure key-set in user_cache'''
                LoginChecker.user_cache[user_id] = set()
                server_log.warn('user_cache len: %d, user add: %s' % (len(LoginChecker.user_cache), user_id))
                is_need_check = True

            if is_need_check:
                server_log.info('need check_info, user_id = ' + user_id + 'user_key = ' + user_key)
                '''should check from tencent server'''
                request = tornado.httpclient.HTTPRequest(cfg.TENCENT_ACCOUNT_SERVER +
                                                         '/?openid=' + user_id +
                                                         '&openkey=' + user_key +
                                                        '&user_pf=' + zoneid +
                                                        '&api=k_playzone_userinfo' +
                                                         '&platform=qzone' +
                                                        '&callback=cb',
                                                        method='GET')
                server_log.info('new active url: ' + request.url)
                self.chk_client.fetch(request, callback=self._check_response_callback)
コード例 #6
0
async def python_eval(
        req: web.Request) -> Union[Dict[str, Any], web.StreamResponse]:
    if not req.config_dict["args"].with_eval:
        raise web.HTTPForbidden(reason="Python eval page not ebabled")

    if req.app.get("eval-session", None) is not None:
        raise web.HTTPConflict(reason="Eval session already launched")

    ws_current = web.WebSocketResponse()
    ws_ready = ws_current.can_prepare(req)
    if not ws_ready.ok:
        return {}

    await ws_current.prepare(req)

    req.app["eval-session"] = ws_current

    async for msg in ws_current:
        if msg.type == aiohttp.WSMsgType.text:
            server_log.warn(
                f"Evaluating code from python eval page: {msg.data}")
            try:
                stdout, tb, returned = await eval_code(msg.data, req)
            except CompilationError as e:
                await ws_current.send_json({
                    "action": "eval_compilation_error",
                    "text": str(e)
                })
                continue

            await ws_current.send_json({
                "action": "eval_result",
                "stdout": stdout,
                "traceback": tb,
                "returned": str(returned),
            })

    req.app["eval-session"] = None

    return ws_current
コード例 #7
0
ファイル: check_login.py プロジェクト: lkj01010/mypy
    def _check_response_callback(self, response):
        server_log.info('check_callback: ' + str(response.body))

        is_valid = False
        if response and response.body:
            j_body = json.JSONDecoder().decode(
                response.body.lstrip('cb(').rstrip(')'))

            server_log.warn(
                'in _check_response_callback0, user_cache len: %d' %
                len(LoginChecker.user_cache))
            # [[
            if 'data' in j_body and j_body[
                    'is_ok'] == 1 and 'openid' in j_body and 'openkey' in j_body:
                openid = j_body['openid']
                if openid in LoginChecker.user_cache:
                    pass
                else:
                    LoginChecker.user_cache[openid] = set()
                    server_log.warn(
                        'in _check_response_callback1, user_cache len: %d' %
                        len(LoginChecker.user_cache))
                LoginChecker.user_cache[openid].add(j_body['openkey'])
                is_valid = True

            # ==============> test
            # openid = j_body['openid']
            # if openid in LoginChecker.user_cache:
            #     pass
            # else:
            #     LoginChecker.user_cache[openid] = set()
            # LoginChecker.user_cache[openid].add(j_body['openkey'])
            # is_valid = True

            # ]]

        self.check_ret_callback(is_valid)
コード例 #8
0
    def get(self):
        """
        type:0  停机维护
            msg:
        """
        print self.request.remote_ip
        if self.request.remote_ip == '127.0.0.1':
            command = self.get_argument('cmd')
            cmd_dict = json.JSONDecoder().decode(command)
            server_log.warn('cmd is: ' + str(cmd_dict))
            try:
                if cmd_dict["type"] == 0:
                    self.application.server_state_msg = cmd_dict["msg"]
                    self.application.server_running = False
                elif cmd_dict["type"] == 1:
                    self.application.server_state_msg = ""
                    self.application.server_running = True
                """存档服务器"""
                request = tornado.httpclient.HTTPRequest(cfg.RECORD_SERVER +
                                                         '/cmd',
                                                         method='POST',
                                                         body=command)
                self.application.client.fetch(
                    request, callback=CommandHandler.cmd_callback)
                """openapi服务器"""
                request = tornado.httpclient.HTTPRequest(
                    cfg.TENCENT_ACCOUNT_SERVER + '/cmd',
                    method='POST',
                    body=command)
                self.application.client.fetch(
                    request, callback=CommandHandler.cmd_callback)

                self.write("hello")
                # self.send_error()
            except KeyError:
                pass
        pass
コード例 #9
0
ファイル: check_login.py プロジェクト: lkj01010/mypy
 def clean_up(self):
     server_log.warn('clean_up Login info when user_cache len: %d' %
                     (len(LoginChecker.user_cache)))
     LoginChecker.user_cache = dict()
コード例 #10
0
ファイル: check_login.py プロジェクト: lkj01010/mypy
 def clean_up(self):
     server_log.warn('clean_up Login info when user_cache len: %d' % (len(LoginChecker.user_cache)))
     LoginChecker.user_cache = dict()