def addUser(self, uid=0, name='nn', admin='y', password='******', user_id='1', card_number=12345): name = name admin = admin privilege = 14 if admin == 'y' else 0 password = password user_id = user_id card = card_number card = int(card) if card else 0 #if prev: # conn.delete_user(uid) #borrado previo try: Device.conn.set_user(uid=uid, name=name, privilege=privilege, password='******', group_id='', user_id=user_id, card=0) except ZKErrorResponse as e: print("error: %s" % e) #try new format zk_user = User(uid, name, privilege, password, '', user_id, card) Device.conn.save_user_template(zk_user) # forced creation Device.conn.refresh_data()
def get_users(self): users = [] users.append(User(uid=1, user_id=1, privilege='', name='Andres')) users.append(User(uid=2, user_id=2, privilege='', name='Ma. Josefina')) users.append(User(uid=3, user_id=3, privilege='', name='Lorena')) users.append(User(uid=4, user_id=4, privilege='', name='Jimena')) users.append(User(uid=5, user_id=5, privilege='', name='Natalia')) users.append(User(uid=6, user_id=6, privilege='', name='Alonda')) users.append(User(uid=7, user_id=7, privilege='', name='Paulina')) users.append(User(uid=8, user_id=8, privilege='', name='Sofia')) return users
def get_users(self): ''' return all user ''' command = const.CMD_USERTEMP_RRQ command_string = chr(const.FCT_USER) checksum = 0 session_id = self.__sesion_id reply_id = self.__reply_id response_size = 1024 cmd_response = self.__send_command(command, command_string, checksum, session_id, reply_id, response_size) users = [] if cmd_response.get('status'): if cmd_response.get('code') == const.CMD_PREPARE_DATA: bytes = self.__get_data_size() userdata = [] while bytes > 0: data_recv = self.__sock.recv(1032) userdata.append(data_recv) bytes -= 1024 data_recv = self.__sock.recv(8) response = unpack('HHHH', data_recv[:8])[0] if response == const.CMD_ACK_OK: if userdata: # The first 4 bytes don't seem to be related to the user for x in xrange(len(userdata)): if x > 0: userdata[x] = userdata[x][8:] userdata = ''.join(userdata) userdata = userdata[12:] while len(userdata) >= 72: uid, privilege, password, name, sparator, group_id, user_id = unpack('2sc8s28sc7sx24s', userdata.ljust(72)[:72]) u1 = int(uid[0].encode("hex"), 16) u2 = int(uid[1].encode("hex"), 16) uid = u1 + (u2 * 256) privilege = int(privilege.encode("hex"), 16) password = unicode(password.split('\x00')[0], errors='ignore') name = unicode(name.split('\x00')[0], errors='ignore') group_id = unicode(group_id.split('\x00')[0], errors='ignore') user_id = unicode(user_id.split('\x00')[0], errors='ignore') user = User(uid, name, privilege, password, group_id, user_id) users.append(user) userdata = userdata[72:] else: raise ZKErrorResponse("Invalid response") return users
name = input('Name :') admin = input('Admin (y/N):') privilege = 14 if admin == 'y' else 0 password = input('Password :'******'User ID2 :') card = input('Card :') card = int(card) if card else 0 #if prev: # conn.delete_user(uid) #borrado previo try: conn.set_user(uid, name, privilege, password, '', user_id, card) args.enrolluser = uid except ZKErrorResponse as e: print("error: %s" % e) #try new format zk_user = User(uid, name, privilege, password, '', user_id, card) conn.save_user_template(zk_user) # forced creation args.enrolluser = uid conn.refresh_data() if args.enrolluser: uid = int(args.enrolluser) print('--- Enrolling User #{} ---'.format(uid)) conn.delete_user_template(uid, args.finger) conn.reg_event(0xFFFF) # if conn.enroll_user(uid, args.finger): conn.test_voice(18) # register ok tem = conn.get_user_template(uid, args.finger) print(tem) else: conn.test_voice(23) # not registered
def backup_attendance(): def erase_device(conn, serialnumber, clear_attendance=False): """input serial number to corroborate.""" print('WARNING! the next step will erase the current device content.') conn.disable_device() print('Erasing device...') conn.clear_data() if clear_attendance: print('Clearing attendance too!') conn.clear_attendance() conn.read_sizes() print(conn) zk = connect_zk() try: print('Connecting to device ...') conn = zk.connect() serialnumber = conn.get_serialnumber() fp_version = conn.get_fp_version() print('Serial Number : {}'.format(serialnumber)) print('Finger Version : {}'.format(fp_version)) filename = "../{}.json.bak".format(serialnumber) print('') print('Reading file {}'.format(filename)) infile = open(filename, 'r') data = json.load(infile) infile.close() #compare versions... if data['version'] != '1.00jut': raise BasicException("file with different version... aborting!") if data['fp_version'] != fp_version: raise BasicException( "fingerprint version mismmatch {} != {} ... aborting!".format( fp_version, data['fp_version'])) #TODO: check data consistency... users = [User.json_unpack(u) for u in data['users']] #print (users) print("INFO: ready to write {} users".format(len(users))) templates = [Finger.json_unpack(t) for t in data['templates']] #print (templates) print("INFO: ready to write {} templates".format(len(templates))) erase_device(conn, serialnumber, False) print('Restoring Data...') for u in users: #look for Templates temps = list(filter(lambda f: f.uid == u.uid, templates)) #print ("user {} has {} fingers".format(u.uid, len(temps))) conn.save_user_template(u, temps) conn.enable_device() print('--- final sizes & capacity ---') conn.read_sizes() print(conn) return "success" except BasicException as e: print(e) print('') except Exception as e: print("Process terminate : {}".format(e)) print("Error: %s" % sys.exc_info()[0]) print('-' * 60) traceback.print_exc(file=sys.stdout) print('-' * 60) finally: if conn: print('Enabling device ...') conn.enable_device() conn.disconnect() print('ok bye!') print('')
json.dump(data, output, indent=1) output.close() if args.erase: erase_device(conn, serialnumber, args.clear_attendance) else: print ('Reading file {}'.format(filename)) infile = open(filename, 'r') data = json.load(infile) infile.close() #compare versions... if data['version'] != '1.00jut': raise BasicException("file with different version... aborting!") if data['fp_version'] != fp_version: raise BasicException("fingerprint version mismmatch {} != {} ... aborting!".format(fp_version, data['fp_version'])) #TODO: check data consistency... users = [User.json_unpack(u) for u in data['users']] #print (users) print ("INFO: ready to write {} users".format(len(users))) templates = [Finger.json_unpack(t) for t in data['templates']] #print (templates) print ("INFO: ready to write {} templates".format(len(templates))) erase_device(conn, serialnumber, args.clear_attendance) print ('Restoring Data...') for u in users: #look for Templates temps = list(filter(lambda f: f.uid ==u.uid, templates)) #print ("user {} has {} fingers".format(u.uid, len(temps))) conn.save_user_template(u,temps) conn.enable_device() print ('--- final sizes & capacity ---') conn.read_sizes()
if args.erase: erase_device(conn, serialnumber, args.clear_attendance) else: print('Reading file {}'.format(filename)) infile = open(filename, 'r') data = json.load(infile) infile.close() #compare versions... if data['version'] != '1.00jut': raise BasicException("file with different version... aborting!") if data['fp_version'] != fp_version: raise BasicException( "fingerprint version mismmatch {} != {} ... aborting!".format( fp_version, data['fp_version'])) #TODO: check data consistency... users = [User.json_unpack(u) for u in data['users']] #print (users) print("INFO: ready to write {} users".format(len(users))) templates = [Finger.json_unpack(t) for t in data['templates']] #print (templates) print("INFO: ready to write {} templates".format(len(templates))) erase_device(conn, serialnumber, args.clear_attendance) print('Restoring Data...') for u in users: #look for Templates temps = list(filter(lambda f: f.uid == u.uid, templates)) #print ("user {} has {} fingers".format(u.uid, len(temps))) conn.save_user_template(u, temps) conn.enable_device() print('--- final sizes & capacity ---') conn.read_sizes()
def process_unsync_record(): # Called every 30 minutes via hooks unsynced_doc_list = frappe.db.get_all('Essdee Biometric Device Sync Log', { 'status': ['in', ['Queued', 'Error']], 'resend_count': ['<', 5] }, ['name', 'device_ip']) ip_list = frappe.db.get_all('Essdee Biometric Device', ['ip']) final_list = [] for ip in ip_list: doc_list = [] for doc in unsynced_doc_list: if ip['ip'] == doc['device_ip']: doc_list.append(doc['name']) if doc_list: final_list.append({'ip': ip['ip'], 'doc_list': doc_list}) if final_list: for val in final_list: conn = None try: conn = sync_device(val['ip']) if conn: conn.disable_device() for doc_name in val['doc_list']: doc = frappe.get_doc( 'Essdee Biometric Device Sync Log', doc_name) try: employee = frappe.get_doc('Employee', doc.employee) if doc.status == 'Error': doc.resend_count += 1 if doc.action == 'Delete': conn.delete_user( uid=int(employee.attendance_device_id)) if doc.action == 'Update': conn.set_user( uid=int(employee.attendance_device_id), name=employee.employee_name, user_id=employee.attendance_device_id) if doc.action == 'Sync Templates' or doc.action == 'All': templates = [] for row in employee.finger_print_details: templates.append( Finger.json_unpack( json_unpack( row, int(employee. attendance_device_id)))) if templates: zk_user = User( int(employee.attendance_device_id), employee.employee_name, 0, user_id=employee.attendance_device_id) conn.save_user_template(zk_user, templates) doc.status = 'Completed' except: doc.status = 'Error' doc.error_message = frappe.get_traceback() doc.save() except: frappe.log_error(frappe.get_traceback()) finally: if conn: conn.refresh_data() conn.enable_device() conn.disconnect()