ELV TimeMaster - Linux PC-Terminal

Schon lange geärgert, dass das PC-Terminal vom ELV TimeMaster nur für Windows verfügbar ist? Vielleicht hilft dieses kleine Python Script für Linux. ;-)

Beispielausgabe

# ./elv_timemaster_terminal.py --action time --pin XXXX
2014-07-12 17:45:58.837688 [TIME] Mustermann, Max        10      20:00   78:33

# ./elv_timemaster_terminal.py --action start --pin XXXX
2014-07-12 17:46:02.930095 [START] Mustermann, Max       10

# ./elv_timemaster_terminal.py --action end --pin XXXX
2014-07-12 17:46:06.698165 [END] Mustermann, Max 10

Quelltext

elv_timemaster_terminal.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
 
import sys
import socket
from hashlib import md5
from argparse import ArgumentParser
from datetime import datetime
 
def send_request(SERVER,PORT,REQUEST,ACTION):
	# send data to timemaster server
	S = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	S.connect((SERVER, PORT))
	S.send(REQUEST.decode('hex'))
	DATA = S.recv(1024)
	S.close()
 
	# convert binary to hex and strip first 20 hex chars (binary trash)
	OUTPUT = DATA.encode('hex')
	OUTPUT = OUTPUT[20:]
 
	# convert back to string and print
	print str(datetime.now()) + ' [' + ACTION + '] ' + OUTPUT.decode('hex')
 
def main():
	ARGS_USAGE = "%(prog)s --action <time|start|end> --pin <PIN> [--server <server>]"
	ARGS_VERSION = "ELV TimeMaster Client by Marcel Jaepel 2014-07-12"
	ARGS_PARSER = ArgumentParser(usage=ARGS_USAGE,version=ARGS_VERSION)
 
	ARGS_PARSER.add_argument("--action", action="store", dest="ACTION", choices=['time', 'start', 'end'], required=True, help="(required) TimeMaster Action")
	ARGS_PARSER.add_argument("--pin", action="store", dest="PIN", required=True, help="(required) PIN of employee")
	ARGS_PARSER.add_argument("--clientip", action="store", dest="CLIENT_IP", default="127.0.0.1", help="(optional) TimeMaster Client IP (Default: 127.0.0.1)")
	ARGS_PARSER.add_argument("--server", action="store", dest="SERVER", default="timemaster.domain.tld", help="(optional) TimeMaster Server (Default: timemaster.domain.tld)")
 
	ARGS = ARGS_PARSER.parse_args()
 
	PORT = 50505
	PIN = md5(ARGS.PIN).hexdigest()
 
	if ARGS.ACTION == 'time':
		REQUEST = PIN+'0e'+ARGS.CLIENT_IP.encode('hex')+'f5e0010000000500000000d8fb1801'
		send_request(ARGS.SERVER,PORT,REQUEST,'TIME')
	elif ARGS.ACTION == 'start':
		REQUEST = PIN+'0e'+ARGS.CLIENT_IP.encode('hex')+'000000000000020000000000000000'
		send_request(ARGS.SERVER,PORT,REQUEST,'START')
	elif ARGS.ACTION == 'end':
		REQUEST = PIN+'0e'+ARGS.CLIENT_IP.encode('hex')+'9a4400b0f5e0030000000000000000'
		send_request(ARGS.SERVER,PORT,REQUEST,'END')
	else:
		print 'No action specified!'
 
 
if __name__ == '__main__':
    main()