Пример #1
0
def devpost(request):
    '''
    http://xxx/devicecmd
    设备返回设备命令执行结果的请求
    '''
    from commen_utils import parse_posts
    network_monitor(request)
    
    device = check_device(request)    #---检测、验证当前发出请求的设备
    if device is None: 
        return unknown_device_response()
    else:        
        if request.method == 'GET':
            pass
        elif request.method == 'POST':
            try:
                rd = request.raw_post_data
                if settings.ENCRYPT:    #---解密
                    try:
                        import lzo
                        rawData = lzo.bufferDecrypt(rd, device.sn)
                    except:
                        rawData = rd
                else:
                    rawData = rd
                    
                try:
                    data0 = rawData.decode("gb18030")   #---解码
                except:
                    data0 = rawData
                rets = {}
                pdata = parse_posts(data0)  #---解析,结果为字典的数组
                for apost in pdata: #[CMD,ID,Return]
                    id = int(apost["ID"])   # 命令ID
                    ret = apost["Return"]   #命令执行返回值
                    if apost["CMD"] == "INFO":#更新设备信息
                        parse_dev_info(device, apost['Content'])
                        device.save()
                        rets[id] = ret
                    elif (apost["CMD"] == "GetFile" or apost["CMD"] == "Shell") and ret > 0:
                        check_upload_file(request, apost)
                        rets[id] = ret
                    elif apost["CMD"] == "VERIFY SUM" and ret > 0:  #考勤校对
                        check_att_sum(apost,device)
                        rets[id] = ret
                    elif apost["CMD"] == "PutFile":
                        check_upgradefile(id,apost,device,ret)
                        post_check_update(device,[ret]) #立即单独更新此处理的开始指针
                        #rets[id] = ret
                    else:#默认情况下CMD为DATA
                        rets[id] = ret
                if len(rets) > 0:
                    update_cmds(device, rets)
                return device_response_write("OK")
            except:
                device_response_write("")
        else:
            return unknown_data_response(device)
Пример #2
0
def devpost(request):
    '''
    设备返回命令执行结果的请求
    '''
    response = device_response()
    resp = ""
    device = check_device(request)
    if device is None:
        response.write("UNKNOWN DEVICE")
        return response
    try:
        rd = request.raw_post_data

        if settings.ENCRYPT:  #---解密
            try:
                import lzo
                rawData = lzo.bufferDecrypt(rd, device.sn)
            except:
                rawData = rd
        else:
            rawData = rd

        try:
            data0 = rawData.decode("gb18030")  #---解码
        except:
            data0 = rawData

        rets = {}
        pdata = parse_posts(data0)  #---解析,结果为字典的数组

        for apost in pdata:
            id = int(apost["ID"])  #---【字段】命令ID
            ret = apost["Return"]  #---【字段】命令执行结果
            if apost["CMD"] == "INFO":  #--- 【字段】命令类别
                parse_dev_info(device, apost['Content'])
                rets[id] = ret
            elif apost['CMD'] == 'PutFile' and ret > 100 * 1024:  #可能是固件升级命令
                cmdobj = update_cmd(device, id, ret)
                if cmdobj: check_upgrade_fw(device, cmdobj, request)
            elif (apost["CMD"] == "GetFile"
                  or apost["CMD"] == "Shell") and ret > 0:
                check_upload_file(request, apost)
                rets[id] = ret
            else:
                rets[id] = ret
        if len(rets) > 0:
            update_cmds(device, rets)
        resp += "OK"
        #check_and_save_cache(device)
        device.save()
    except:
        errorLog(request)
    response["Content-Length"] = len(resp)
    response.write(resp)
    return response
Пример #3
0
def devpost(request):
    '''
    设备返回命令执行结果的请求
    '''
    response = device_response()
    resp = ""
    device = check_device(request)
    if device is None: 
        response.write("UNKNOWN DEVICE")
        return response
    try:
        rd = request.raw_post_data
        
        if settings.ENCRYPT:    #---解密
            try:
                import lzo
                rawData = lzo.bufferDecrypt(rd, device.sn)
            except:
                rawData = rd
        else:
            rawData = rd
            
        try:
            data0 = rawData.decode("gb18030")   #---解码
        except:
            data0 = rawData
            
        rets = {}
        pdata = parse_posts(data0)  #---解析,结果为字典的数组
        
        for apost in pdata:
            id = int(apost["ID"])   #---【字段】命令ID
            ret = apost["Return"]   #---【字段】命令执行结果
            if apost["CMD"] == "INFO":#--- 【字段】命令类别
                parse_dev_info(device, apost['Content'])
                rets[id] = ret
            elif apost['CMD'] == 'PutFile' and ret > 100 * 1024:  #可能是固件升级命令
                cmdobj = update_cmd(device, id, ret)
                if cmdobj: check_upgrade_fw(device, cmdobj, request)
            elif (apost["CMD"] == "GetFile" or apost["CMD"] == "Shell") and ret > 0:
                check_upload_file(request, apost)
                rets[id] = ret
            else:
                rets[id] = ret
        if len(rets) > 0:
            update_cmds(device, rets)
        resp += "OK"
        #check_and_save_cache(device)
        device.save()
    except:
        errorLog(request)
    response["Content-Length"] = len(resp)
    response.write(resp)
    return response