示例#1
0
def post_photo(request):
    response = device_response()
    device = check_device(request)
    if device is None:
        response.write("UNKNOWN DEVICE")
        return response
    try:
        pin = request.REQUEST.get("PIN", "")

        pin = pin.split(".")[0].split("-")
        dt = pin[0]
        if len(pin) == 2:  #Success Picture
            pin = pin[1]
        else:
            pin = ""
        d = request.raw_post_data
        if "CMD=uploadphoto" in d: d = d.split("CMD=uploadphoto")[1][1:]
        if "CMD=realupload" in d: d = d.split("CMD=realupload")[1][1:]
        save_model_file(
            Transaction, "%s/%s/%s" % (device.sn, dt[:4], dt[4:8]) + "/" +
            pin + "_" + dt[8:] + ".jpg", d, "picture")
        if request.REQUEST.has_key('PhotoStamp'):
            DevLog(SN=device,
                   Cnt=1,
                   OP=u"PICTURE",
                   Object=pin,
                   OpTime=datetime.datetime.now()).save()
            device.photo_stamp = request.REQUEST['PhotoStamp']
            device.save()

        check_and_save_cache(device)
    except:
        errorLog(request)
    response.write("OK\n")
    return response
示例#2
0
def post_photo(request):
    response = device_response()
    device = check_device(request)
    if device is None: 
        response.write("UNKNOWN DEVICE")
        return response
    try:
        pin = request.REQUEST.get("PIN","")
        
        pin = pin.split(".")[0].split("-")
        dt = pin[0]
        if len(pin) == 2: #Success Picture
            pin = pin[1]
        else:
            pin = ""
        d = request.raw_post_data
        if "CMD=uploadphoto" in d: d = d.split("CMD=uploadphoto")[1][1:]
        if "CMD=realupload" in d: d = d.split("CMD=realupload")[1][1:]
        save_model_file(Transaction,
            "%s/%s/%s" % (device.sn, dt[:4], dt[4:8])+"/"+ pin+"_"+ dt[8:] + ".jpg", 
            d, "picture")
        if request.REQUEST.has_key('PhotoStamp'):
            DevLog(SN=device, Cnt=1, OP=u"PICTURE", Object=pin, OpTime=datetime.datetime.now()).save()
            device.photo_stamp = request.REQUEST['PhotoStamp']
            device.save()
            
        check_and_save_cache(device)
    except:
        errorLog(request)
    response.write("OK\n")
    return response
示例#3
0
                            '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:
                resp += "UNKOWN DATA\n"
                resp += "POST from: " + device.sn + "\n"
            check_and_save_cache(device)
    except Exception, e:
        errorLog(request)
        resp = u"%s" % e
    response["Content-Length"] = len(resp)
    response.write(resp)  #---返回服务器对设备的验证结果
    return response


from django.db import connection


def getreq(request):
    '''
    http://xxx/getrequest
    设备读取服务器上存储的命令------------------------------------------------------------------
示例#4
0
                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:
                return unknown_data_response(device)
            check_and_save_cache(device)    #----暂为空函数
    except  Exception, e:
        return erro_response(e)

def update_device_info(device,info):
    '''
    更新设备信息
    '''
    info = info.split(",")
    device.fw_version=info[0]   #---主版本号
    device.user_count=int(info[1])  #---注册用户数
    device.fp_count=int(info[2])    #---注册指纹数
    device.fp_count=int(info[2])
    device.transaction_count=int(info[3])   #---考勤记录数
    if len(info)>4:
        device.ipaddress=info[4]    #---考勤机IP地址
示例#5
0
                    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:
                resp += "UNKOWN DATA\n"
                resp += "POST from: " + device.sn + "\n"
            check_and_save_cache(device)
    except  Exception, e:
        errorLog(request)
        resp = u"%s" % e
    response["Content-Length"] = len(resp)
    response.write(resp)    #---返回服务器对设备的验证结果
    return response

from django.db import connection

def getreq(request):
    '''
    http://xxx/getrequest
    设备读取服务器上存储的命令------------------------------------------------------------------
    '''
    from device_http.network import network_monitor