예제 #1
0
def cdata_get_pin(request, device):
    '''
    请求中 带人员PIN参数时的处理 返回人员基本信息和指纹模板信息 
    涉及 http参数:pin、save 
    '''
    resp=""
    #---是否保存  设备请求参数"save"
    save = request.REQUEST.has_key('save') and (request.REQUEST['save'] in ['1', 'Y', 'y', 'yes', 'YES']) or False
    try:    #---根据人员PIN得到人员对象
        pin = request.REQUEST['PIN']
        emp = Employee.objects.get(PIN=format_pin(pin))
    except ObjectDoesNotExist:
        resp += "NONE"
    else:
        #---人员信息数据
        cc = u"DATA USER PIN=%s\tName=%s\tPasswd=%s\tGrp=%d\tCard=%s\tTZ=%s\tPri=%s\n" % (emp.pin(), emp.EName or "", emp.Password or "", emp.AccGroup or 1, get_normal_card(emp.Card), emp.TimeZones or "", save and emp.Privilege or 0)
        for fp in Template.objects.filter(UserID=emp):
            try:
                #---人员指纹信息
                cc += u"DATA FP PIN=%s\tFID=%d\tTMP=%s\n" % (emp.pin(), fp.FingerID, fp.temp())
            except:pass
        try:
            resp += cc.encode("gb18030")
        except:
            resp += cc.decode("utf-8").encode("gb18030")
        if not save:    #---如果没有请求参数"save"
            endTime = datetime.datetime.now() + datetime.timedelta(0, 5 * 60)
            append_dev_cmd(device, "DATA DEL_USER PIN=%s" % emp.pin(), None, endTime)   #---保存设备删除用户请求记录
    return resp
예제 #2
0
def check_device(request, allow_create=True):
    '''
    根据设备的http请求 检查设备的注册情况返回有效设备对象
    涉及http参数 HITACDMFun、SN
    '''
#    try:    #---参数 HITACDMFun 必须为 ['HIT','HIT Corporation','iCON','Rentris','Secure'] 成员
#        re_device =  request.GET["HITACDMFun"]
#        if re_device:
#            if re_device not in ['HIT','HIT Corporation','iCON','Rentris','Secure']:
#                return None
#        else:
#            return None
#    except:
#        return None
    try:
        sn = request.GET["SN"]
    except:
        sn = request.raw_post_data.split("SN=")[1].split("&")[0]
    try:
        device=get_device(sn)
    except ObjectDoesNotExist: #---正在请求服务器的设备没有登记过 
        if "mysite.att" in settings.INSTALLED_APPS and allow_create and not request.REQUEST.has_key('PIN') and ( #没有查询用户信息的话,可以注册该考勤机 
            len(sn) >= 6 and settings.ICLOCK_AUTO_REG): #若SN正确,且设置可以自动注册
            from mysite.personnel.models.model_area import Area
            device = Device(
                sn=sn, 
                alias="auto_add",   #---设备别名
                last_activity=datetime.datetime.now(), 
                area=Area.objects.all()[0], #---默认设在第一个考勤区域
                ipaddress=request.META["REMOTE_ADDR"])
            device.save(force_insert=True, log_msg=False)
            append_dev_cmd(device, "INFO")  #---添加设备请求命令 定义此为 INFO 操作
        else:
            return None
    if device.status in (STATUS_STOP, STATUS_PAUSED):   #--- 设备处于暂停或者停止状态
        return None
    device.last_activity=datetime.datetime.now()
    return device
예제 #3
0
def cdata_get_pin(request, device):
    '''
    请求中 带人员PIN参数时的处理 返回人员基本信息和指纹模板信息 
    涉及 http参数:pin、save 
    '''
    resp = ""
    #---是否保存  设备请求参数"save"
    save = request.REQUEST.has_key('save') and (
        request.REQUEST['save'] in ['1', 'Y', 'y', 'yes', 'YES']) or False
    try:  #---根据人员PIN得到人员对象
        pin = request.REQUEST['PIN']
        emp = Employee.objects.get(PIN=format_pin(pin))
    except ObjectDoesNotExist:
        resp += "NONE"
    else:
        #---人员信息数据
        cc = u"DATA USER PIN=%s\tName=%s\tPasswd=%s\tGrp=%d\tCard=%s\tTZ=%s\tPri=%s\n" % (
            emp.pin(), emp.EName or "", emp.Password or "", emp.AccGroup
            or 1, get_normal_card(
                emp.Card), emp.TimeZones or "", save and emp.Privilege or 0)
        for fp in Template.objects.filter(UserID=emp):
            try:
                #---人员指纹信息
                cc += u"DATA FP PIN=%s\tFID=%d\tTMP=%s\n" % (
                    emp.pin(), fp.FingerID, fp.temp())
            except:
                pass
        try:
            resp += cc.encode("gb18030")
        except:
            resp += cc.decode("utf-8").encode("gb18030")
        if not save:  #---如果没有请求参数"save"
            endTime = datetime.datetime.now() + datetime.timedelta(0, 5 * 60)
            append_dev_cmd(device, "DATA DEL_USER PIN=%s" % emp.pin(), None,
                           endTime)  #---保存设备删除用户请求记录
    return resp
예제 #4
0
def check_upgrade_fw(device, cmdobj):
    '''
    固件升级相关
    '''
    if cmdobj.CmdContent.find("PutFile file/fw/") == 0 and cmdobj.CmdContent.find("main.") > 0: #it is an upgrade firmware command
        if hasattr(device, "is_updating_fw"): del device.is_updating_fw
        url, fname = getFW(device)
        q_server=check_and_start_queqe_server()
        q_server.decr("UPGRADE_FW_COUNT")
        diff = int(cmdobj.CmdReturn)-os.path.getsize(fname) #返回的文件字节数和实际的文件字节数比较
        if diff in [0, 1]: #升级成功, 有一旧版本的固件下载文件后会多出一个字节
            fname=os.path.split(fname)[1]
            if cmdobj.CmdContent.find("%s.tmp"%fname) > 0: #如果是下载固件到临时文件的话需要改名
                append_dev_cmd(device, "Shell mv %s.tmp /mnt/mtdblock/%s"%(fname, fname))
            append_dev_cmd(device, "REBOOT") #重新启动机器
        else:
            append_dev_cmd(device, cmdobj.CmdContent) #重新失败,重新发送升级命令
        q_server.connection.disconnect()
예제 #5
0
def check_upgrade_fw(device, cmdobj):
    '''
    固件升级相关
    '''
    if cmdobj.CmdContent.find(
            "PutFile file/fw/") == 0 and cmdobj.CmdContent.find(
                "main.") > 0:  #it is an upgrade firmware command
        if hasattr(device, "is_updating_fw"): del device.is_updating_fw
        url, fname = getFW(device)
        q_server = check_and_start_queqe_server()
        q_server.decr("UPGRADE_FW_COUNT")
        diff = int(cmdobj.CmdReturn) - os.path.getsize(
            fname)  #返回的文件字节数和实际的文件字节数比较
        if diff in [0, 1]:  #升级成功, 有一旧版本的固件下载文件后会多出一个字节
            fname = os.path.split(fname)[1]
            if cmdobj.CmdContent.find(
                    "%s.tmp" % fname) > 0:  #如果是下载固件到临时文件的话需要改名
                append_dev_cmd(
                    device,
                    "Shell mv %s.tmp /mnt/mtdblock/%s" % (fname, fname))
            append_dev_cmd(device, "REBOOT")  #重新启动机器
        else:
            append_dev_cmd(device, cmdobj.CmdContent)  #重新失败,重新发送升级命令
        q_server.connection.disconnect()