예제 #1
0
def cdata(request):
    '''
    设备向服务器的http:://xxx/cdata请求
    '''
    network_monitor(request)
    try:
        from mysite import authorize_fun
        language=request.REQUEST.get('language',None)   #---获得语言参数
        authorize_fun.check_push_device(language)   #---连接设备数量控制
        device = check_device(request, True)    #---检测、验证当前发出请求的设备
        if device is None: 
            return unknown_device_response()
        else:
            if device.deviceType==POSDEVICE:#消费机
                from mysite.pos.posdevview import pos_cdata
                ret = pos_cdata(request)
                return device_response_write(ret)
            elif device.deviceType in ['ACP', 'ACD']:#控制器or一体机:
                from mysite.iaccess.push_comm_center import acc_cdata
                ret = acc_cdata(request)
                return device_response_write(ret)
            
            if request.REQUEST.has_key('action'):
                return ok_response(device)
            elif request.method == 'GET':
                return cdata_get(request,device)
            elif request.method == 'POST':
                try:
                    return cdata_post(request, device)
#                    resp =cdata_post(request, device)
#                    return device_response_write(resp)
                except Exception, e:
                    return erro_response(e)
            else:
예제 #2
0
def check_device(request, allow_create=True, commkey_check=False):
    '''
    根据设备的http请求 检查设备的注册情况返回有效设备对象, 当为新设备时会触发set()
    涉及http参数 HITACDMFun、SN、device_type
    device 属性 
    '''
    try:
        sn = request.GET["SN"]
    except:
        sn = request.raw_post_data.split("SN=")[1].split("&")[0]
    device = Device(sn)
    try:
        device = device.get()
    except ObjectDoesNotExist:  #---设备没有登记过
        if request.method == 'GET' and commkey_check:
            from mysite import authorize_fun
            language = request.REQUEST.get('language', None)  #---获得语言参数
            authorize_fun.check_push_device(
                language, settings.AUTHORIZE_MAGIC_KEY)  #---连接设备数量控制

        if allow_create and not request.REQUEST.has_key(
                'PIN') and len(sn) >= 6:  #若SN正确,且设置可以自动注册
            device.alias = 'auto_add'
            device.ipaddress = request.META["REMOTE_ADDR"]
            device.status = 1
            str_now = datetime.datetime.now().strftime(time_fmt)
            device.last_activity = str_now
        else:
            return None

    if request.method == 'GET' and commkey_check:
        from constant import PUSH_COMM_KEY_CHECK
        if PUSH_COMM_KEY_CHECK:
            pushcommkey = request.GET.get("pushcommkey", None)
            if not pushcommkey:
                raise Exception('hase no pushcommkey param.')
                return None
            dec = Check_ClientCode(sn, settings.CUSTOMER_CODE)
            if dec != pushcommkey:
                raise Exception('pushcommkey authentication failed.')
                return None

    if device.status in (STATUS_STOP, STATUS_PAUSED):  #--- 设备处于暂停或者停止状态
        return None
    if device.isnew():
        deviceType = request.REQUEST.get('device_type')
        if (deviceType == '30'):  #消费机
            device.deviceType = '30'
        else:
            device.deviceType = ''
        ck_ret = check_count(int(device.total()))
        if ck_ret:
            print ck_ret
            return None
        device.set_area(1)  #设置默认区域
        device.set()
    else:
        device.last_activity = datetime.datetime.now().strftime(time_fmt)
        device.set('last_activity')  # 更新设备最后访问时间
    return device
예제 #3
0
def cdata(request):
    '''
    设备向服务器的http:://xxx/cdata请求
    '''
    from device_http.network import network_monitor
    network_monitor(request)

    encrypt = 1
    response = device_response()
    try:
        resp = ""
        from mysite import authorize_fun
        language = request.REQUEST.get('language', None)  #---获得语言参数
        authorize_fun.check_push_device(language)  #---连接设备数量控制
        device = check_device(request, True)  #---检测、验证当前发出请求的设备
        if device is None:
            response.write("UNKNOWN DEVICE")
            return response
        else:
            if request.REQUEST.has_key('action'):
                resp += "OK\n"
            elif request.method == 'GET':  #---设备GET请求
                if request.REQUEST.has_key('PIN'):  #---带人员PIN参数
                    resp += cdata_get_pin(request, device)
                else:  #--- 设备push的版本及其他一些信息的返回
                    alg_ver = "1.0"  #--- push 默认版本
                    if request.REQUEST.has_key(
                            'pushver'):  #---没有"PIN"但有"pushver" push版本参数
                        alg_ver = request.REQUEST.get(
                            'pushver'
                        )  #2010-8-25  device字段alg_ver用来区分新老固件  >=2.0为新固件,默认为旧固件
                    device.alg_ver = alg_ver
                    device.save()
                    resp += cdata_get_options(device)
                    encrypt = 0
            elif request.method == 'POST':  #---设备POST请求
                try:
                    resp += cdata_post(request, device)
                except Exception, e:
                    resp = u"ERROR: %s" % e
                    errorLog(request)
            else:
예제 #4
0
def cdata(request):
    '''
    设备向服务器的http:://xxx/cdata请求
    '''
    from device_http.network import network_monitor
    network_monitor(request)
    
    encrypt = 1
    response = device_response()
    try:
        resp = ""
        from mysite import authorize_fun
        language=request.REQUEST.get('language',None)   #---获得语言参数
        authorize_fun.check_push_device(language)   #---连接设备数量控制
        device = check_device(request, True)    #---检测、验证当前发出请求的设备
        if device is None: 
            response.write("UNKNOWN DEVICE")
            return response
        else:        
            if request.REQUEST.has_key('action'):
                resp += "OK\n"
            elif request.method == 'GET':   #---设备GET请求
                if request.REQUEST.has_key('PIN'):  #---带人员PIN参数
                    resp+=cdata_get_pin(request, device)
                else:   #--- 设备push的版本及其他一些信息的返回
                    alg_ver="1.0" #--- push 默认版本
                    if request.REQUEST.has_key('pushver'):  #---没有"PIN"但有"pushver" push版本参数
                        alg_ver=request.REQUEST.get('pushver')    #2010-8-25  device字段alg_ver用来区分新老固件  >=2.0为新固件,默认为旧固件
                    device.alg_ver=alg_ver
                    device.save()
                    resp+=cdata_get_options(device)
                    encrypt = 0
            elif request.method == 'POST':  #---设备POST请求
                try:
                    resp+=cdata_post(request, device)
                except Exception, e:
                    resp = u"ERROR: %s" % e
                    errorLog(request)
            else: