Revision 145
added some more logging to server
trunk/swipe/tooltron.py | ||
---|---|---|
84 | 84 |
|
85 | 85 |
BAUD_RATE = 9600 |
86 | 86 |
|
87 |
#fails until a warning is sent |
|
88 |
MAX_TOOL_FAILS = 5 |
|
89 |
|
|
87 | 90 |
################################################# |
88 | 91 |
#this code spawns a thread which always puts the last card id in the |
89 | 92 |
#lastid variable. |
... | ... | |
123 | 126 |
#end thread |
124 | 127 |
############################################### |
125 | 128 |
|
126 |
flog = open("tooltron.log", "wa")
|
|
129 |
flog = open("tooltron.log", "a") |
|
127 | 130 |
|
128 | 131 |
def logMessage(str): |
129 | 132 |
flog.write(strftime("%Y.%m.%d %H:%M:%S ") + str + "\n") |
130 | 133 |
|
134 |
logMessage("----- SERVER STARTED -----") |
|
135 |
|
|
131 | 136 |
def keypad2toolID(t): |
132 |
return ids[t] |
|
137 |
if t in ids: |
|
138 |
return ids[t] |
|
139 |
else: |
|
140 |
return -1 |
|
133 | 141 |
|
134 | 142 |
def reverseTool(tn): |
135 | 143 |
for t in tools: |
136 | 144 |
if tn in tools[t]: |
137 | 145 |
return t |
138 | 146 |
|
139 |
return 0
|
|
147 |
return 'invalid'
|
|
140 | 148 |
|
149 |
#keep count of successive non-acks |
|
150 |
toolFails = tools.copy() |
|
151 |
for t in toolFails: |
|
152 |
toolFails[t] = 0 |
|
153 |
|
|
141 | 154 |
def get_last_id(): |
142 | 155 |
global idready |
143 | 156 |
global lastid |
... | ... | |
270 | 283 |
|
271 | 284 |
print "user has access to:", acl |
272 | 285 |
|
286 |
user = "user" |
|
287 |
|
|
273 | 288 |
startTime = time.time(); |
274 | 289 |
resp = "" |
275 | 290 |
while resp=="": |
... | ... | |
289 | 304 |
#if we have a vaid response |
290 | 305 |
if resp != "" and resp != TT_TIMEOUT: |
291 | 306 |
|
292 |
print "request:",resp |
|
307 |
toolName = reverseTool(resp) |
|
308 |
toolNameLong = toolName + " (k="+str(resp)+", t="+str(keypad2toolID(resp))+")" |
|
309 |
print "request:",resp,toolNameLong |
|
293 | 310 |
|
294 | 311 |
if acl.count(resp) > 0: |
295 | 312 |
keypad.write(TT_ACK) |
296 | 313 |
sendTool(resp) |
297 | 314 |
print "ACCESS GRANTED" |
298 |
logMessage("user accessed tool "+reverseTool(resp))
|
|
315 |
logMessage(user+" accessed tool "+toolNameLong)
|
|
299 | 316 |
if checkAck(resp): |
300 | 317 |
print "ACK" |
318 |
toolFails[toolName] = 0 |
|
301 | 319 |
else: |
302 | 320 |
print "NO ACK!!!!" |
303 |
logMessage("tool "+reverseTool(resp)+" did not ACK") |
|
321 |
logMessage("tool "+toolNameLong+" did not ACK") |
|
322 |
toolFails[toolName] += 1 |
|
323 |
if toolFails > MAX_TOOL_FAILS: |
|
324 |
#TODO: send email |
|
325 |
logMessage("WARNING: tool "+toolNameLong+ |
|
326 |
" has failed to ACK "+ |
|
327 |
str(MAX_TOOL_FAILS)+" times in a row.") |
|
304 | 328 |
|
305 | 329 |
else: |
306 | 330 |
keypad.write(TT_NACK) |
307 | 331 |
print "ACCESS DENIED!!" |
332 |
logMessage(user + " denied on tool "+toolNameLong) |
|
308 | 333 |
|
309 | 334 |
clear_id() |
310 | 335 |
|
Also available in: Unified diff