pslockout/authserver/parselog_example.py

52 lines
3.4 KiB
Python
Raw Normal View History

import base64
import struct
import time
EVENTS = [
'LOG_BOOT_UP - Booted up',
'LOG_INIT_COMPLETE - Initialization completed',
'LOG_WIFI_CONNECTED - Wifi connected',
'LOG_WIFI_DISCONNECTED - Wifi disconnected',
'LOG_COMM_LOCK_FAIL - Lock status communication failed, code: ',
'LOG_COMM_CARD_FAIL - Card list communication failed, code: ',
'LOG_COMM_INFO_FAIL - Info log communication failed, code: ',
'LOG_LOCK_OFF - Lock turned off',
'LOG_LOCK_ARMED - Lock armed',
'LOG_LOCK_TIMEOUT - Lock armed timed out',
'LOG_LOCK_ON - Lock turned on',
'LOG_LOCK_CANCEL - Lock armed cancelled',
'LOG_LOCK_ERROR - Lock armed button error',
'LOG_CARD_GOOD_READ - Successful read from card: ',
'LOG_CARD_ACCEPTED - Accepted card: ',
'LOG_CARD_DENIED - Denied card: ',
]
encoded = "AAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAABgAAAAIAAAAAAAAAAAAABwAAAAQ1MDMAAAAAAAAA0whEXA0wNzAwQjU2MUMx0whEXA8wNzAwQjU2MUMx1AhEXA0wNzAwQjU2MUMx1AhEXA8wNzAwQjU2MUMx6whEXA0wNzAwQjU2MUMx6whEXA8wNzAwQjU2MUMx7AhEXA0wNzAwQjU2MUMx7AhEXA8wNzAwQjU2MUMx7ghEXA0wNzAwQjU2MUMx7ghEXA8wNzAwQjU2MUMx7whEXA0wNzAwQjU2MUMx7whEXA8wNzAwQjU2MUMx8AhEXA0wNzAwQjU2MUMx8AhEXA8wNzAwQjU2MUMx8QhEXA0wNzAwQjU2MUMx8QhEXA8wNzAwQjU2MUMx8QhEXA0wNzAwQjU2MUMx8QhEXA8wNzAwQjU2MUMx8ghEXA0wNzAwQjU2MUMx8ghEXA8wNzAwQjU2MUMx8whEXA0wNzAwQjU2MUMx8whEXA8wNzAwQjU2MUMx8whEXA0wNzAwQjU2MUMx8whEXA8wNzAwQjU2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U2MUMxCQlEXA8wNzAwQjU2MUMxCQlEXA0wNzAwQjU2MUMxCQlEXA8wNzAwQjU2MUMxCglEXA0wNzAwQjU2MUMxCglEXA8wNzAwQjU2MUMxCwlEXA0wNzAwQjU2MUMxCwlEXA8wNzAwQjU2MUMxDAlEXA0wNzAwQjU2MUMxDAlEXA8wNzAwQjU2MUMxDAlEXA0wNzAwQjU2MUMx"
while True:
try:
decoded = base64.b64decode(encoded)
unpacked = list(struct.iter_unpack('<IB10s', decoded))
entries_processed = 0
for entry in unpacked:
# if time is obviously wrong, just use the time right now
entry_time = entry[0] if entry[0] > 1000000 else int(time.time())
entry_time_string = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(entry_time))
entry_event = EVENTS[entry[1]]
entry_data = entry[2].decode('ascii')
entry_string = entry_time_string + ' - ' + entry_event + entry_data
print(entry_string)
print(len(unpacked))
break
except:
print('bad parse')
encoded = encoded[:-1]