def put(self): """Update the parameters of terminal. """ status = ErrorCode.SUCCESS try: data = DotDict(json_decode(self.request.body)) tid = data.get('tid', None) # check tid whether exist in request and update current_user self.check_tid(tid) logging.info("[UWEB] Terminal request: %s, uid: %s, tid: %s", data, self.current_user.uid, self.current_user.tid) except Exception as e: status = ErrorCode.ILLEGAL_DATA_FORMAT self.write_ret(status) return try: terminal = QueryHelper.get_available_terminal( self.current_user.tid, self.db) if not terminal: status = ErrorCode.LOGIN_AGAIN logging.error("[UWEB] The terminal with tid: %s does not exist," " redirect to login.html", self.current_user.tid) self.write_ret(status) return user = QueryHelper.get_user_by_uid(self.current_user.uid, self.db) if not user: status = ErrorCode.LOGIN_AGAIN logging.error("[UWEB] The user with uid: %s does not exist," " redirect to login.html", self.current_user.uid) self.write_ret(status) return # sql injection if data.has_key('corp_cnum') and not check_cnum(data.corp_cnum): status = ErrorCode.ILLEGAL_CNUM self.write_ret(status) return # NOTE: deprecated if data.has_key('white_list'): white_list = ":".join(data.white_list) if not check_sql_injection(white_list): status = ErrorCode.ILLEGAL_WHITELIST self.write_ret(status) return self.update_terminal_db(data) # NOTE: wspush to client if status == ErrorCode.SUCCESS: WSPushHelper.pushS7(tid, self.db, self.redis) self.write_ret(status) except Exception as e: logging.exception("[UWEB] uid:%s, tid:%s update terminal info failed. Exception: %s", self.current_user.uid, self.current_user.tid, e.args) status = ErrorCode.SERVER_BUSY self.write_ret(status)
def post(self): status = ErrorCode.SUCCESS try: data = DotDict(json_decode(self.request.body)) tid = data.get('tid', None) tids = data.get('tids', None) # check tid whether exist in request and update current_user self.check_tid(tid) logging.info("[UWEB] Defend request: %s, uid: %s, tid: %s, tids: %s", data, self.current_user.uid, self.current_user.tid, tids) except Exception as e: status = ErrorCode.ILLEGAL_DATA_FORMAT logging.exception("[UWEB] Invalid data format. body:%s, Exception: %s", self.request.body, e.args) self.write_ret(status) return try: res = [] tids = str_to_list(tids) tids = tids if tids else [self.current_user.tid, ] tids = [str(tid) for tid in tids] for tid in tids: r = DotDict(tid=tid, status=ErrorCode.SUCCESS) try: terminal = QueryHelper.get_available_terminal(tid, self.db) if not terminal: r.status = ErrorCode.LOGIN_AGAIN res.append(r) logging.error("[UWEB] The terminal with tid: %s does not exist, redirect to login.html", tid) continue update_mannual_status(self.db, self.redis, tid, data.mannual_status) logging.info("[UWEB] uid:%s, tid:%s set mannual status to %s successfully", self.current_user.uid, tid, data.mannual_status) except Exception as e: r.status = ErrorCode.FAILED logging.exception("[UWEB] uid:%s, tid:%s set mannual status to %s failed. Exception: %s", self.current_user.uid, tid, data.mannual_status, e.args) finally: res.append(r) # NOTE: wspush if status == ErrorCode.SUCCESS: for tid in tids: WSPushHelper.pushS7(tid, self.db, self.redis) self.write_ret(status, dict_=DotDict(res=res)) except Exception as e: logging.exception("[UWEB] uid:%s, tid:%s set mannual status to %s failed. Exception: %s", self.current_user.uid, self.current_user.tid, data.mannual_status, e.args) status = ErrorCode.SERVER_BUSY self.write_ret(status)
def post(self): """Acquire push account through uid @uid: user uid """ status = ErrorCode.SUCCESS try: data = DotDict(json_decode(self.request.body)) tid = data.tid s_type = data.s_type if data.get("category", None): category = int(data.get("category")) else: category = 1 logging.info("[UWEB] Test wspush request: %s.", data) except Exception as e: status = ErrorCode.ILLEGAL_DATA_FORMAT logging.exception("[UWEB] Invalid data format. body: %s, Exception: %s", self.request.body, e.args) self.write_ret(status) return try: # user = self.db.get("select owner_mobile") user = QueryHelper.get_user_by_tid(tid, self.db) uid = user.owner_mobile if s_type == "S3": WSPushHelper.pushS3(tid, self.db, self.redis) elif s_type == "S4": WSPushHelper.pushS4(tid, self.db, self.redis) elif s_type == "S5": body = dict( tid=tid, category=category, pbat=100, type=1, timestamp=int(time.time()), longitude=419004000, latitude=143676000, clongitude=419004000, clatitude=143676000, name="test name", speed=111, degree=203, gsm=0, locate_error=100, gps=25, alias="111", region_id=11, ) WSPushHelper.pushS5(tid, body, self.db, self.redis) elif s_type == "S6": WSPushHelper.pushS6(tid, self.db, self.redis) elif s_type == "S7": WSPushHelper.pushS7(tid, self.db, self.redis) elif s_type == "S8": acc_message = 1 WSPushHelper.pushS8(tid, acc_message, self.db, self.redis) self.write_ret(status=status) except Exception as e: logging.exception("[UWEB] WSPushHandler get push account failed, Exception:%s", e.args) status = ErrorCode.SERVER_BUSY self.write_ret(status)