Beispiel #1
0
    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)
Beispiel #2
0
 def get(self):
     """Get activities.
     """
     status = ErrorCode.SUCCESS
     try:
         res = []
         timestamp = self.get_argument('timestamp', None)
         if timestamp is None:
             res = QueryHelper.get_activity_list(self.db)
         elif int(timestamp) == -1:
             res = QueryHelper.get_activity_avaliable(self.db)
         else:
             res = QueryHelper.get_activity_by_begintime(timestamp, self.db)
         for r in res:
             if r['filename']:
                 r['filepath'] = self.application.settings[
                     'activity_path'] + r['filename']
             else:
                 r['filepath'] = ''
             r['url'] = r['html_name']
             del r['filename']
             del r['html_name']
         self.write_ret(status,
                        dict_=DotDict(res=res))
     except Exception as e:
         logging.exception("[UWEB] Get activities failed. Exception: %s",
                           e.args)
         status = ErrorCode.SERVER_BUSY
         self.write_ret(status)
Beispiel #3
0
    def get(self):
        status = ErrorCode.SUCCESS
        try:
            category = int(self.get_argument('category', UWEB.APK_TYPE.YDWS))
            if category == UWEB.APK_TYPE.YDWS:  # 1
                #version_info = get_version_info("android")
                version_info = QueryHelper.get_version_info_by_category(
                    category, self.db)
            elif category == UWEB.APK_TYPE.YDWQ_MONITOR:  # 2
                version_info = QueryHelper.get_version_info_by_category(
                    category, self.db)
            elif category == UWEB.APK_TYPE.YDWQ_MONITORED:  # 3
                version_info = QueryHelper.get_version_info_by_category(
                    category, self.db)
            elif category == UWEB.APK_TYPE.YDWS_ANJIETONG:  # 4
                version_info = QueryHelper.get_version_info_by_category(
                    category, self.db)
            else:
                logging.info("[UWEB] Invalid category: %s",
                             category)

            self.write_ret(status,
                           dict_=DotDict(version_info=version_info))
        except Exception as e:
            logging.exception(
                "[UWEB] Android check update failed. Exception: %s", e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
Beispiel #4
0
 def get(self):
     category = int(self.get_argument('category', 2))
     if category == 2:  # ydws
         #version_info = get_version_info('android')
         download_info = get_download_count(category, self.db)
         version_info = QueryHelper.get_version_info_by_category(
             UWEB.APK_TYPE.YDWS, self.db)
         update_download_count(category, self.db)
         self.render('android_weixin.html',
                     versioncode=version_info.versioncode,
                     versionname=version_info.versionname,
                     versioninfo=version_info.versioninfo,
                     updatetime=version_info.updatetime,
                     filesize=version_info.filesize,
                     count=download_info.count)
     elif category == 3:  # ydwq_monitor
         version_info = QueryHelper.get_version_info_by_category(
             UWEB.APK_TYPE.YDWQ_MONITOR, self.db)
         url = "/static/apk/" + version_info['filename']
         self.redirect(url)
     elif category == 4:  # ydwq_monitored
         version_info = QueryHelper.get_version_info_by_category(
             UWEB.APK_TYPE.YDWQ_MONITORED, self.db)
         url = "/static/apk/" + version_info['filename']
         self.redirect(url)
     elif category == 5:  # ydws_anjietong
         version_info = QueryHelper.get_version_info_by_category(
             UWEB.APK_TYPE.YDWS_ANJIETONG, self.db)
         url = "/static/apk/" + version_info['filename']
         self.redirect(url)
Beispiel #5
0
    def get(self):
        """Display profile of current user.
        """
        status = ErrorCode.SUCCESS
        try: 
            tid = self.get_argument('tid',None) 
            # check tid whether exist in request and update current_user
            self.check_tid(tid)

            profile = DotDict()
            # 1: user
            user = QueryHelper.get_user_by_uid(self.current_user.uid, self.db)
            if not user:
                status = ErrorCode.LOGIN_AGAIN
                logging.error("[UWEB] User does not exist, redirect to login.html. uid: %s.", 
                              self.current_user.uid)
                self.write_ret(status)
                return

            # 2: car 
            car = QueryHelper.get_car_by_tid(self.current_user.tid, self.db)            
            profile.update(user)
            profile.update(car)
            self.write_ret(status,
                           dict_=dict(profile=profile))
        except Exception as e:
            logging.exception("[UWEB] Get user profile failed. uid:%s, tid:%s, Exception: %s", 
                              self.current_user.uid, self.current_user.tid, e.args) 
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
Beispiel #6
0
    def get(self):
        """Get terminal info.
        """
        status = ErrorCode.SUCCESS
        try:
            tid = self.get_argument('tid', None)
            # check tid whether exist in request and update current_user
            self.check_tid(tid)

            car_sets = DotDict()

            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_mobile(terminal.owner_mobile, self.db)
            if not user:
                logging.error("[UWEB] The user with uid: %s does not exist,"
                              "  redirect to login.html", 
                              self.current_user.uid)
                self.clear_cookie(self.app_name)
                self.write_ret(ErrorCode.LOGIN_AGAIN)
                return

            # NOTE: deprecated.
            if terminal['mannual_status'] == 1:
                terminal['parking_defend'] = 0
            else:
                terminal['parking_defend'] = 1

            # NOTE: deprecated.
            whitelist = QueryHelper.get_white_list_by_tid(
                self.current_user.tid, self.db)

            car_info = QueryHelper.get_car_by_tid(
                self.current_user.tid, self.db)
            car = dict(corp_cnum=car_info.get('cnum', ''))

            # add tow dict: terminal, car. add two value: whitelist_1,
            # whitelist_2
            white_list = [terminal.owner_mobile]
            for item in whitelist:
                white_list.append(item['mobile'])

            car_sets.update(terminal)
            car_sets.update(car)
            car_sets.update(DotDict(white_list=white_list))
            self.write_ret(status,
                           dict_=dict(car_sets=car_sets))
        except Exception as e:
            status = ErrorCode.SERVER_BUSY
            logging.exception("[UWEB] uid: %s tid: %s get terminal failed. Exception: %s",
                              self.current_user.uid, self.current_user.tid, e.args)
            self.write_ret(status)
Beispiel #7
0
    def post(self):
        """Get latest location of a terminal.
        """
        status = ErrorCode.SUCCESS
        res = {}
        try:
            data = DotDict(json_decode(self.request.body))
            mobile = str(data.mobile)
            token = data.token
            logging.info("[REALTIME] Request, data:%s", data)
        except Exception as e:
            status = ErrorCode.DATA_FORMAT_ILLEGAL
            logging.exception("[REALTIME] Invalid data format, body: %s, mobile: %s.",
                              self.request.body, mobile)
            self.write_ret(status)
            return

        try:
            status = self.basic_check(token, mobile)                             
            if status != ErrorCode.SUCCESS:
                self.write_ret(status)
                return
    
            terminal = QueryHelper.get_terminal_by_tmobile(mobile, self.db)
            tid = terminal.tid      
            location = QueryHelper.get_location_info(tid, self.db, self.redis)

            # check and make name valid
            if location and location['name'] is None:
                location['name'] = ''                            
            # check and make clatclon valid
            locations = [location,] 
            locations = get_locations_with_clatlon(locations, self.db) 
            location = locations[0]
            
            if (location and location.clatitude and location.clongitude):
                res = dict(lon=location.get('longitude', 0),
                           lat=location.get('latitude', 0),
                           clon=location.get('clongitude', 0),
                           clat=location.get('clatitude', 0),
                           timestamp=location.get('timestamp',0),
                           name=location.get('name',''),
                           type=location.get('type',0))
                 
            self.write_ret(status,
                           dict_=dict(res=res))

        except Exception as e:
            logging.exception("[REALTIME] sid: %s. Exception: %s",
                              mobile, e.args)
            status = ErrorCode.FAILED
            self.write_ret(status)     
Beispiel #8
0
 def handle_charge_info(self, info):
     info = DotDict(info)
     self.db.execute("INSERT INTO T_CHARGE"
                     "  VALUES (NULL, %s, %s, %s)",
                     info.dev_id, info.content, info.timestamp)
     user = QueryHelper.get_user_by_tid(info.dev_id, self.db) 
     if not user:
         logging.error("[EVENTER] Cannot find USER of terminal: %s", info.dev_id)
         return
         
     sms_option = QueryHelper.get_sms_option_by_uid(user.owner_mobile, EVENTER.SMS_CATEGORY.CHARGE.lower(), self.db)
     if sms_option == UWEB.SMS_OPTION.SEND:
         logging.error("[EVENTER] do not send charge sms temporarily")
Beispiel #9
0
 def get(self):
     """Just just to a new page. 
     """
     # NOTE: The se_id should can be found in platform.
     se_id = self.get_argument("se_id", "")
     single_event = QueryHelper.get_single_event_by_se_id(se_id, self.db)
     terminal = QueryHelper.get_terminal_info(single_event["tid"], self.db, self.redis)
     self.render(
         "single_point.html",
         single_id=single_event["sid"],
         alias=terminal["alias"],
         tid=single_event.get("tid", ""),
         start_time=single_event.get("start_time"),
         end_time=single_event.get("end_time"),
     )
Beispiel #10
0
    def pushS4(tid, db, redis):
        """
        S4
        Information about online, offline.

        e.g.

        res = []
        res.append(dict(tid='tid1',
                        login_status=1))
        res.append(dict(tid='tid2',
                        login_status=2))

        """

        res = []

        t = QueryHelper.get_terminal_info(tid, db, redis)
        if t:
            res.append(dict(tid=tid,
                            biz_type=t.get('biz_type', 0),
                            login_status=t['login'] if t['login'] == 0 else 1))

        packet = dict(packet_type="S4",
                      res=res)
        res = WSPushHelper.push_packet(tid, packet, db, redis)
Beispiel #11
0
    def get(self):
        status = ErrorCode.SUCCESS
        try:
            tid = self.get_argument('tid', None)
            # check tid whether exist in request and update current_user
            self.check_tid(tid)
            terminal = QueryHelper.get_available_terminal(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
            else:
                terminal_info_key = get_terminal_info_key(self.current_user.tid)
                terminal_info = self.redis.getvalue(terminal_info_key)
                mannual_status = terminal_info['mannual_status']

            self.write_ret(status,
                           dict_=DotDict(defend_status=mannual_status,
                                         mannual_status=mannual_status,
                                         fob_status=terminal.fob_status))
        except Exception as e:
            logging.exception("[UWEB] uid:%s tid:%s get defend status failed. Exception: %s",
                              self.current_user.uid, self.current_user.tid, e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
            return
Beispiel #12
0
    def pushS4(self, op):
        """
        res = []
        res.append(dict(tid='tid1',
                        login_status=1))
        res.append(dict(tid='tid2',
                        login_status=2))
        """

        res = [] 
        corp = self.db.get("SELECT * FROM V_TERMINAL where tid = %s",
                            self.tid) 
        if corp:
            terminals = self.db.query("SELECT tid FROM V_TERMINAL WHERE cid= %s",
                                      corp['cid'])
            for terminal in terminals:
                t = QueryHelper.get_terminal_info(terminal['tid'], self.db, self.redis) 
                res.append(dict(tid=terminal['tid'],
                                biz_type=0,
                                login_status=t['login']))
        else:
            res = []

        packet = dict(packet_type="S4",
                      res=res)
        res = self.push(packet)

        return res
Beispiel #13
0
    def get_sms_status(self, tmobile):
        """
        sms_status: 0,  // failded
                    1,  // sent
                    2,  // reached to terminal
                    3,  // terminal has connected to gataway
        """ 
        sms_status = 0
        terminal = QueryHelper.get_terminal_by_tmobile(tmobile, self.db)
        if terminal.login == GATEWAY.TERMINAL_LOGIN.ONLINE:
            sms_status = 3
        elif terminal.msgid:
            sms_status = 1
        else:
            sms = self.db.get("SELECT send_status, recv_status"
                              "  FROM T_SMS"
                              "  WHERE msgid = %s"
                              "  AND category = %s"
                              "  LIMIT 1",
                              terminal.msgid, SMS.CATEGORY.MT)
            if not sms:
                pass
            elif sms.recv_status == 0:
                sms_status = 2
            elif sms.send_status == 0:
                sms_status = 1

        return sms_status
Beispiel #14
0
    def get(self):
        """Display smsoption of current user.

        workflow:
        if alarmoption is exist:
            return alarmoption 
        else:
            initialize the alarmoption
            return alarmoption 
        """
        status = ErrorCode.SUCCESS
        try:
            umobile = self.get_argument('umobile')
            logging.info(
                "[UWEB] Alarmoption request: %s", self.request.arguments)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            logging.exception(
                "[UWEB] Invalid data format. Exception: %s", e.args)
            self.write_ret(status)
            return

        try:
            alarm_options = QueryHelper.get_alarm_options(umobile, self.db)
            self.write_ret(status,
                           dict_=dict(res=alarm_options))
        except Exception as e:
            logging.exception("[UWEB] Get alarmoption failed. umobile: %s, Exception: %s",
                              umobile, e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
Beispiel #15
0
def update_terminal_dynamic_info(db, redis, location):
    """Update terminal's dynamic info in db and redis.
    Then inclues gps, gsm, pbat.
    """
    # db
    tid = location.dev_id
    fields = []

    # NOTE: only gps, gsm, pbat should be updated
    keys = ['gps', 'gsm', 'pbat']
    for key in keys:
        if location.get(key, None) is not None:
            fields.append(key + " = " + str(location[key]))
    set_clause = ','.join(fields)
    if set_clause:
        db.execute("UPDATE T_TERMINAL_INFO"
                   "  SET " + set_clause +
                   "  WHERE tid = %s",
                   tid)
    # redis
    terminal_info = QueryHelper.get_terminal_info(tid, db, redis)
    if terminal_info:
        terminal_info_key = get_terminal_info_key(tid)
        for key in terminal_info:
            value = location.get(key, None)
            if value is not None:
                terminal_info[key] = value
        redis.setvalue(terminal_info_key, terminal_info)
Beispiel #16
0
    def post(self):
        """Get last infomation of a terminal.
        """
        status = ErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            mobile = str(data.mobile)
            manual_status = data.manual_status
            token = data.token
            logging.info("[MANUAL] Request, data:%s", data)
        except Exception as e:
            status = ErrorCode.DATA_FORMAT_INVALID
            logging.exception("[REBOO] Invalid data format, body: %s, mobile: %s.",
                              self.request.body, mobile)
            self.write_ret(status)
            return

        try:
            status = self.basic_check(token, mobile)                             
            if status != ErrorCode.SUCCESS:
                self.write_ret(status)
                return
    
            terminal = QueryHelper.get_terminal_by_tmobile(mobile, self.db)
            tid = terminal.tid                    
            update_mannual_status(self.db, self.redis, tid, manual_status)

            self.write_ret(status)

        except Exception as e:
            logging.exception("[MANUAL] mobile: %s. Exception: %s",
                              mobile, e.args)
            status = ErrorCode.FAILED
            self.write_ret(status)
Beispiel #17
0
    def get(self):
        """Get the latest usable location.

        #NOTE: deprecated
        """
        try: 
            tid = self.get_argument('tid',None) 
            # check tid whether exist in request and update current_user
            self.check_tid(tid)
            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 is noexist, redirect to login.html", 
                               self.current_user.tid)
                self.write_ret(status)                
                return

            ret = self.get_realtime(self.current_user.uid, 
                                    self.current_user.sim)
            self.set_header(*self.JSON_HEADER)
            self.write(json_encode(ret))
        except Exception as e:
            logging.exception("Failed to get location: %s, Sim: %s", 
                               e.args, self.current_user.sim) 
            status = ErrorCode.SERVER_BUSY  
            self.write_ret(status)
Beispiel #18
0
def update_terminal_info_ydwq(db, redis, t_info):
    """Update terminal's info in db and redis.
    """
    terminal_info_key = get_terminal_info_key(t_info['tid'])
    terminal_info = QueryHelper.get_terminal_info(t_info['tid'],
                                                  db, redis)

    # 1: db
    fields = []
    # gps, gsm, pbat, changed by position report
    keys = ['gps', 'gsm', 'pbat', 'login']
    for key in keys:
        value = t_info.get(key, None)
        if value is not None and value != terminal_info[key]:
            fields.append(key + " = " + str(t_info[key]))

    set_clause = ','.join(fields)
    if set_clause:
        db.execute("UPDATE T_TERMINAL_INFO"
                   "  SET " + set_clause +
                   "  WHERE tid = %s",
                   t_info['tid'])
    # 2: redis
    for key in terminal_info:
        value = t_info.get(key, None)
        if value is not None:
            terminal_info[key] = value
    redis.setvalue(terminal_info_key, terminal_info)

    return terminal_info
Beispiel #19
0
 def get(self):
     """Display profile of current operator.
     """
     status = ErrorCode.SUCCESS
     try: 
         profile = DotDict()
         # 1: user     
         oper = QueryHelper.get_operator_by_oid(self.current_user.oid, self.db)
         if not oper:
             status = ErrorCode.LOGIN_AGAIN
             logging.error("[UWEB] Operator does not exist, redirect to login.html. oid: %s.", 
                           self.current_user.oid)
             self.write_ret(status)
             return
         
         profile.update(oper)
         for key in profile.keys():
             profile[key] = profile[key] if profile[key] else ''
         self.write_ret(status,
                        dict_=dict(profile=profile))
     except Exception as e:
         logging.exception("[UWEB] Get corp profile failed. oid:%s, tid:%s, Exception: %s", 
                           self.current_user.oid, self.current_user.tid, e.args) 
         status = ErrorCode.SERVER_BUSY
         self.write_ret(status)
Beispiel #20
0
    def post(self):
        """Reboot a terminal.
        """
        status = ErrorCode.SUCCESS        
        try:
            data = DotDict(json_decode(self.request.body))
            mobile = str(data.mobile)
            token = data.token
            logging.info("[REBOOT] Request, data:%s", data)
        except Exception as e:
            logging.exception("[REBOOT] Invalid data format, body: %s, mobile: %s.",
                              self.request.body, mobile)
            status = ErrorCode.DATA_FORMAT_INVALID
            self.write_ret(status)
            return

        try:
            status = self.basic_check(token, mobile)                             
            if status != ErrorCode.SUCCESS:
                self.write_ret(status)
                return

            terminal = QueryHelper.get_terminal_by_tmobile(mobile, self.db)         
            tid = terminal.tid
            restart_terminal(self.db, self.redis, tid, mobile) 
            logging.info("[REBOOT] Restart a terminal. tid: %s, mobile: %s", tid, mobile)               

            self.write_ret(status)
        except Exception as e:
            logging.exception("[REBOOT] Reboot failed. mobile: %s. Exception: %s",
                              mobile, e.args)
            status = ErrorCode.FAILED
            self.write_ret(status)
Beispiel #21
0
    def get_realtime(self, uid, sim):
        """Get the location of the current realtime request.

        workflow:
        if there is alive memcached, we can get location from it,
        else get location from db
        return result to user browser
        """
        ret = DotDict(status=ErrorCode.SUCCESS,
                      message='',
                      location=None)
        location = QueryHelper.get_location_info(self.current_user.tid, self.db, self.redis)

        locations = [location,] 
        locations = get_locations_with_clatlon(locations, self.db) 
        location = locations[0]

        if (location and location.clatitude and location.clongitude):
            if not location.name:
                location.name = ''
            if location.has_key('id'):
                del location['id']

            location['degree'] = float(location.degree)
            location['tid'] = self.current_user.tid
            ret.location = location

        return ret
Beispiel #22
0
def handle_acc_status_report(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S31
    ACC_status_report: 

    0: success, then record new terminal's address
    1: invalid SessionID 
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id

        args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS,
                       command=head.command)
        sessionID = QueryHelper.get_terminal_sessionID(dev_id, redis)
        if sessionID != head.sessionID: 
            args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID
            logging.error("[GW] Invalid sessionID, terminal: %s", head.dev_id)
        else:
            uap = ACCStatusReportParser(body, head)
            t_info = uap.ret
            #NOTE: Just record it in db.
            db.execute("INSERT INTO T_ACC_STATUS_REPORT(tid, category, timestamp)"
                       "  VALUES(%s, %s, %s)",
                       t_info['dev_id'], t_info['category'], t_info['timestamp'])
        asc = ACCStatusReportComposer(args)
        request = DotDict(packet=asc.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle acc status report exception.")
        GWException().notify()
Beispiel #23
0
    def get(self):
        """Display smsoption of current user.
        """
        status = ErrorCode.SUCCESS
        try: 
            terminals = self.db.query("SELECT tt.mobile, tt.owner_mobile"
                                      "  FROM T_TERMINAL_INFO as tt, "
                                      "  T_GROUP as tg, T_CORP as tc" 
                                      "  WHERE tt.service_status = 1 AND tc.cid = %s "
                                      "  AND tc.cid = tg.corp_id AND tt.group_id = tg.id",
                                      self.current_user.cid)
            mobiles = []
            for terminal in terminals:
                if terminal.owner_mobile not in mobiles:
                    mobiles.append(terminal.owner_mobile)

            sms_options = {} 
            for mobile in mobiles:              
                sms_option = QueryHelper.get_sms_option(mobile, self.db) 
                sms_options[mobile] = sms_option
            self.write_ret(status,
                           dict_=dict(sms_options=sms_options))
        except Exception as e:
            logging.exception("[UWEB] uid:%s tid:%s get SMS Options failed. Exception: %s", e.args) 
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
Beispiel #24
0
    def pushS6(tid, db, redis):
        """
        S6
        Information about basic info.

        res = []
        res.append(dict(tid=tid,
                        gps=8,
                        gsm=8,
                        pbat=8,
                        ))

        """
        res = []
        terminal = QueryHelper.get_terminal_info(tid, db, redis)
        packet = dict(tid=tid,
                      biz_type=terminal.get('biz_type', 0),
                      gps=terminal['gps'],
                      gsm=terminal['gsm'],
                      pbat=terminal['pbat'])
        res.append(packet)

        packet = dict(packet_type="S6",
                      res=res)

        res = WSPushHelper.push_packet(tid, packet, db, redis)
Beispiel #25
0
    def pushS7(tid, db, redis):
        """
        S7
        Information about basic info.

        res = []
        res.append(dict(tid=tid,
                        alias='jiajiajia',
                        icon_type=2,
                        owner_mobile='13011292217',
                        mannual_status=1,
                        ))
        """
        res = []
        terminal = QueryHelper.get_terminal_info(tid, db, redis)
        packet = dict(tid=tid,
                      biz_type=terminal.get('biz_type', 0),
                      alias=terminal['alias'],
                      icon_type=terminal['icon_type'],
                      owner_mobile=terminal['owner_mobile'],
                      mannual_status=terminal['mannual_status'])

        res.append(packet)

        packet = dict(packet_type="S7",
                      res=res)
        res = WSPushHelper.push_packet(tid, packet, db, redis)
Beispiel #26
0
    def notify_to_parents(self, alias, location, mobile, region_id=None):
        """Push information to clinet through push.

        PUSH 1.0
        """
        flag = self.check_timestamp(int(location['timestamp']))
        if not flag: 
            return

        category = location.category
        dev_id = location.dev_id

        if not location['pbat']:
            terminal = QueryHelper.get_terminal_info(dev_id, self.db, self.redis) 
            location['pbat'] = terminal['pbat'] if terminal['pbat'] is not None else 0 

        if mobile:
            # 1: push to android
            android_push_list_key = get_android_push_list_key(mobile) 
            android_push_list = self.redis.getvalue(android_push_list_key) 
            if android_push_list: 
                for push_id in android_push_list: 
                    push_key = NotifyHelper.get_push_key(push_id, self.redis) 
                    NotifyHelper.push_to_android(category, dev_id, alias, location, push_id, push_key, region_id)
            # 2: push  to ios 
            ios_push_list_key = get_ios_push_list_key(mobile) 
            ios_push_list = self.redis.getvalue(ios_push_list_key) 
            if ios_push_list: 
                for ios_id in ios_push_list: 
                    ios_badge = NotifyHelper.get_iosbadge(ios_id, self.redis) 
                    NotifyHelper.push_to_ios(category, dev_id, alias, location, ios_id, ios_badge, region_id)
Beispiel #27
0
 def post(self):
     """Query the white_list according to the given parameters.
     """
     status = ErrorCode.SUCCESS
     try:
         data = json_decode(self.request.body)
         mobile = data.get('mobile')
         if check_zs_phone(mobile, self.db):
             biz_type = QueryHelper.get_biz_by_mobile(mobile, self.db)
             if biz_type:
                 biz_type = biz_type.get('biz_type')
             else:
                 r = re.compile(r"^(1477847\d{4})$")
                 if r.match(mobile):
                     biz_type = 1
                 else:
                     biz_type = 0
             whitelist = DotDict(mobile=mobile, biz_type=biz_type)
             self.write_ret(status, dict_=DotDict(whitelist=whitelist))
         else:
             status = ErrorCode.MOBILE_NOT_ORDERED
             message = ErrorCode.ERROR_MESSAGE[status] % mobile
             self.write_ret(status=status, message=message)
     except Exception as e:
         logging.exception("Search whitelist failed.Terminal mobile: %s,"
                           " owner mobile: %s", mobile)
         self.render('errors/error.html',
                     message=ErrorCode.FAILED)
Beispiel #28
0
    def get(self):
        status = ErrorCode.SUCCESS
        try:
            tid = self.get_argument('tid',None) 
            # check tid whether exist in request and update current_user
            self.check_tid(tid)

            terminal = self.db.get("SELECT id FROM T_TERMINAL_INFO"
                                   "  WHERE tid = %s"
                                   "    AND service_status = %s",
                                   self.current_user.tid,
                                   UWEB.SERVICE_STATUS.ON)
            if terminal: 
                lq_sms_key = get_lq_sms_key(self.current_user.tid) 
                sms = SMSCode.SMS_LQ % SMS.LQ.WEB 
                biz_type = QueryHelper.get_biz_type_by_tmobile(self.current_user.sim, self.db)
                if biz_type != UWEB.BIZ_TYPE.YDWS:
                    pass
                else:
                    SMSHelper.send_to_terminal(self.current_user.sim, sms) 
                self.redis.setvalue(lq_sms_key, True, SMS.LQ_INTERVAL)

                lq_interval_key = get_lq_interval_key(self.current_user.tid) 
                self.redis.setvalue(lq_interval_key, int(time.time()), (SMS.LQ.WEB*60 - 160))
                logging.info("[UWEB] wake up, send %s to Sim: %s", sms, self.current_user.sim) 
            else:
                status = ErrorCode.LOGIN_AGAIN
            self.write_ret(status) 
        except Exception as e:
            logging.exception("[UWEB] uid: %s wake up tid: %s failed.  Exception: %s", 
                              self.current_user.uid, self.current_user.tid, e.args) 
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
Beispiel #29
0
def handle_fob_info(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S19 
    NOTE: deprecated 

    fob info packet: add or remove fob
    0: success, then record new terminal's address
    1: invalid SessionID
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id
        args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS)
        sessionID = QueryHelper.get_terminal_sessionID(dev_id, redis)
        if sessionID != head.sessionID:
            args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID 
        else:
            fp = FobInfoParser(body, head)
            fobinfo = fp.ret
            update_terminal_status(redis, head.dev_id, address)
            update_fob_info(db, redis, fobinfo)

        fc = FobInfoRespComposer(args)
        request = DotDict(packet=fc.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle fob info report exception.")
        GWException().notify()
Beispiel #30
0
    def post(self):
        cid = self.get_argument("cid", "")
        message = None
        url = None
        corp = QueryHelper.get_corp_by_cid(cid, self.db)
        if not corp:
            message = ErrorCode.USER_NOT_FOUND
            self.render("delegation/delegation_enterprise.html", message=message, url=url)
        else:
            uid = "dummy"
            tid = "dummy"
            tmobile = "dummy"
            cid = cid
            oid = UWEB.DUMMY_OID

            url = "/".join(
                [
                    ConfHelper.UWEB_CONF.url_out,
                    UWebHelper.URLS.DELEGATION[1:],
                    str(uid),
                    str(tid),
                    str(tmobile),
                    str(cid),
                    str(oid),
                ]
            )
            sign = UWebHelper.get_sign("".join([str(uid), str(tid), str(tmobile), str(cid), str(oid)]))
            url += "?s=" + sign
            self.log_delegation(self.current_user.id, cid, uid, tid)

            self.render("delegation/delegation_enterprise.html", message=message, url=url)