-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFLACore.py
2113 lines (1923 loc) · 86 KB
/
FLACore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
"""==================================================================================================================
FileZilla Log Analyzer version 1.10 Alpha by Aaron Jubbal
See README for details. Brief overview of flags:
-p --parse <line number> = parse original log by splitting at login/logout for the session that
corresponds with the line number
-s --scramble <[f],[u],[v],[i]> = f: scramble file/folder names
u: scramble user names
v: scramble user names in number format
i: scramble ip addresses
-f --filter <[u],[i],[d],[p]> = u: by user name
i: by IP address
d: by date
p: by port
-d = display login/logout instances
-F = force execution, if a file is going to be overwritten, prompts for overwriting are withheld and the file is
overwritten
====================================================================================================================="""
#TODO: 1) Fix line number inconsistencies between lineInterpretation.log and listedSummary.log - class reconstruction
# may be in order-> namely storing of the line numbers rather than relying on the itr to represent line nums
# 2) add line numbers of requested command to statistics list containers to help solve issue #1
import sys, FLAmodule, flagHandler, random, nameDict, os, io, ipcalc
#Class of global variables
class G:
arbitraryIndexVal = 100000 #indicates something wrong occurred or value was not found
line = 0 #line number
events = None
userEvents = []
userPresent = (0,arbitraryIndexVal) #(if user present, index of user if present)
prevMsg = 0
prevUser = ''
prevPort = ''
userChanged = 0
changeList = None #points to changeList class
portChanged = 0
addedStat = 0
resultsFile = 'results.log'
analyzedResultsFile = 'lineInterpretation.log'
statisticsFile = 'listedSummary.log'
statisticsWriteFile = 'statisticsWrite.log'
filterLogDir = ''
subDir = ''
filterFilePath = ''
printFlag = 0
pFlag = False
fSubFlag = False
iSubFlag = False
uSubFlag = False
vSubFlag = False
hFlag = False
fFlag = False
#filterFlag = False
dFlag = False
FFlag = False
sFlag = False
sParam = ''
pParam = ''
fParam = ''
specifiedLineNum = -1
parsedFile = "parsedLog.log"
parsedList = []
logFile = ''
loggedIn = []
ipDict = {}
userDict = {}
fileDict = {}
pathDict = {}
fileNum = 1
pathNum = 1
userNum = 1
lC = 0
discInst = None
statisticLines = []
parseTill = -1
parseFrom = -1
fullInstanceList = []
AAs = []
changeListArray = []
statistics = []
userInstancesDict = {}
begFileTimeList = []
endFileTimeList = []
unscrambleableIPs = []
class userPortLst(object):
def __init__(self,p,d,t,i,a,lC):
self.port = p
self.date = []
self.time = []
self.ip = []
self.action =[]
self.analyzedAction = []
self.lineNum = []
self.CWDList = []
self.statistics = []
self.stats = None
self.statisticHolder = None
self.date.append(d)
self.time.append(t)
self.ip.append(i)
self.action.append(a)
self.lineNum.append(lC+1)
self.numEvents = 0
self.pointer = [0,G.arbitraryIndexVal]
#index counters to help with retrieval of data from lists:
self.lagParsedIndex = -1
self.lagStatisticIndex = -1
self.lagAAIndex = -1
self.lagListIndex = -1
self.lagDateIndex = -1
self.lagTimeIndex = -1
self.lagIpIndex = -1
self.lagActionIndex = -1
self.listIndex = 0
self.statsIndex = 0
self.userInstances = 0
self.suspendVal = 0 #designates if line creation needs to be held through to another run
self.storedAction = ''
self.storedActionCtr = 0
self.parsedList = []
def addEvnt(self,p,d,t,i,a,lC):
self.date.append(d)
self.time.append(t)
self.ip.append(i)
self.prevAction = self.action[-1]
self.action.append(a)
self.lineNum.append(lC+1)
self.numEvents += 1
self.pointer[0] += 1
def addCWD(self,dir):
self.CWDList.append(dir)
def getCWD(self):
if self.CWDList != []:
return self.CWDList[-1]
else:
return '/'
def store(self,action):
self.storedActionCtr = 0
self.storedAction = action
def getStored(self,specialRequest):
if specialRequest == True:
self.storedActionCtr += 1
return self.storedAction
else:
if self.storedActionCtr != 0:
return ''
else:
self.storedActionCtr += 1
return self.storedAction
def clearStored(self):
self.storedAction = ''
self.storedActionCtr = 0
def addStatistic(self,s):
G.statisticLines.append(G.line)
self.statistics.append(s)
def holdStatistic(self,s):
self.statisticHolder = s
def updateStatistic(self,o,s):
G.statisticLines.append(G.line)
if self.statisticHolder[-1] == 'unknown':
if o == 1:
self.statisticHolder[-1] = 'success'
elif o == 0:
self.statisticHolder[-1] = 'fail'
self.statisticHolder.insert(-1,s)
self.statistics.append(self.statisticHolder)
def getStatistic(self):
self.lagStatisticIndex += 1
return self.statistics[self.lagStatisticIndex]
def getHeldStatistic(self):
return self.statisticHolder
def checkPrevActionEqls(self,str):
if self.action[-2].split()[0] == str:
return True
else:
return False
def getLatestAction(self):
return self.action[-1]
def appendAA(self,analyzed):
self.analyzedAction.append(analyzed)
def getAA(self):
self.lagAAIndex += 1
return self.analyzedAction[self.lagAAIndex]
def suspend(self,value):
self.suspendVal = value
def unSuspend(self):
self.suspendVal = 0
def ifSuspend(self):
if self.suspendVal > 0:
return True
else:
return False
def resetLagListIndex(self):
self.lagListIndex = -1
self.lagAAIndex = -1
self.lagDateIndex = -1
self.lagTimeIndex = -1
self.lagIpIndex = -1
self.lagActionIndex = -1
self.lagStatisticIndex = -1
self.lagParsedIndex = -1
def getDtoA(self): #get Date to Action
self.lagListIndex += 1
return (self.date[self.lagListIndex],self.time[self.lagListIndex],\
self.ip[self.lagListIndex],self.action[self.lagListIndex])
def createParsedList(self,u,analyzed):
if grabAfterUser(analyzed[0],1) == 'disconnected.' or grabAfterUser(analyzed[0],2) == 'successfully logged':
if grabAfterUser(analyzed[0],1) == 'disconnected.':
self.parsedList.append((u,'disconnect',G.line))
else:
self.parsedList.append((u,'login',G.line))
def getParsed(self):
self.lagParsedIndex += 1
return self.parsedList[self.lagParsedIndex]
def prnt(self):
print self.action[self.listIndex],
print self.lineNum[self.listIndex]
self.listIndex += 1
def getAllStatistics(self):
return self.statistics
class userEvntLst(object):
def __init__(self,p,d,t,u,i,a,lC):
self.user = u
self.portsIndex = 0
self.portList = []
self.portList.append(userPortLst(p, d, t, i, a, lC))
self.userInstances = 0
def addEvnt(self,p,d,t,i,a,lC):
pI = self.findPortIndex(p)
if pI != G.arbitraryIndexVal:
self.portList[pI].addEvnt(p,d,t,i,a,lC)
else:
self.portList.append(userPortLst(p,d,t,i,a,lC))
def findPortIndex(self,p):
for i in range(len(self.portList)):
if p == self.portList[i].port:
return i
return G.arbitraryIndexVal
def incUsrInstance(self):
self.userInstances += 1
return
def decUsrInstance(self):
if self.userInstances > 0:
self.userInstances -= 1
return
def userLoggedIn(self):
if self.userInstances > 0:
return True
else:
return False
def addCWD(self,p,dir):
self.portList[self.findPortIndex(p)].addCWD(dir)
def getCWD(self,p):
return self.portList[self.findPortIndex(p)].getCWD()
def store(self,p,action):
self.portList[self.findPortIndex(p)].store(action)
def getStored(self,p,specialRequest):
return self.portList[self.findPortIndex(p)].getStored(specialRequest)
def clearStored(self,p):
return self.portList[self.findPortIndex(p)].clearStored()
def addStatistic(self,p,s):
self.portList[self.findPortIndex(p)].addStatistic(s)
def holdStatistic(self,p,s):
self.portList[self.findPortIndex(p)].holdStatistic(s)
def updateStatistic(self,p,o,s):
self.portList[self.findPortIndex(p)].updateStatistic(o,s)
def getStatistic(self,p):
return self.portList[self.findPortIndex(p)].getStatistic()
def getHeldStatistic(self,p):
return self.portList[self.findPortIndex(p)].getHeldStatistic()
def checkPrevActionEqls(self,p,str):
return self.portList[self.findPortIndex(p)].checkPrevActionEqls(str)
def getLatestAction(self,p):
return self.portList[self.findPortIndex(p)].getLatestAction()
def appendAA(self,p,analyzed):
self.portList[self.findPortIndex(p)].appendAA(analyzed)
def getAA(self,p):
return self.portList[self.findPortIndex(p)].getAA()
def suspend(self,p,value):
self.portList[self.findPortIndex(p)].suspend(value)
def unSuspend(self,p):
self.portList[self.findPortIndex(p)].unSuspend()
def ifSuspend(self,p):
return self.portList[self.findPortIndex(p)].ifSuspend()
def resetLagListIndex(self,p):
self.portList[self.findPortIndex(p)].resetLagListIndex()
def getDtoA(self,p):
return self.portList[self.findPortIndex(p)].getDtoA()
def getPort(self,p):
return self.portList[self.findPortIndex(p)].port
def createParsedList(self,u,p,analyzed):
self.portList[self.findPortIndex(p)].createParsedList(u,analyzed)
def getParsed(self,p):
return self.portList[self.findPortIndex(p)].getParsed()
def prnt(self,p):
print self.user,
self.portList[self.findPortIndex(p)].prnt()
def fullStatisticWrite(self,fileToWriteTo,u):
DLPathDict = {}
RESTPathDict = {}
ULPathDict = {}
APPathDict = {}
MDPathDict = {}
RMDPathDict = {}
DFPathDict = {}
RNPathDict = {}
completeUserStats = []
if u == '---' or u == '(not logged in)': #if message or failed logon, don't bother doing anything-we
#don't want their kind 'round here
return
for i in range(len(self.portList)):
completeUserStats.extend(self.portList[i].getAllStatistics())
w = open(fileToWriteTo, 'a')
w.write(str(u.upper()))
w.write(': ')
writeLoginAndDisc(w,u)
w.write('\n')
for j in range(len(completeUserStats)):
if completeUserStats[j][1] == 'download':
try:
#create dictionary using directories as keys (ie./MY DOCUMENTS)
DLPathDict[completeUserStats[j][4]].append(completeUserStats[j])
except KeyError:
DLPathDict[completeUserStats[j][4]] = [completeUserStats[j]]
if completeUserStats[j][1] == 'restart':
try:
RESTPathDict[completeUserStats[j][4]].append(completeUserStats[j])
except KeyError:
RESTPathDict[completeUserStats[j][4]] = [completeUserStats[j]]
if completeUserStats[j][1] == 'upload':
try:
ULPathDict[completeUserStats[j][4]].append(completeUserStats[j])
except KeyError:
ULPathDict[completeUserStats[j][4]] = [completeUserStats[j]]
if completeUserStats[j][1] == 'appended':
try:
APPathDict[completeUserStats[j][4]].append(completeUserStats[j])
except KeyError:
APPathDict[completeUserStats[j][4]] = [completeUserStats[j]]
if completeUserStats[j][1] == 'makedir':
try:
MDPathDict[completeUserStats[j][4]].append(completeUserStats[j])
except KeyError:
MDPathDict[completeUserStats[j][4]] = [completeUserStats[j]]
if completeUserStats[j][1] == 'rmdir':
try:
RMDPathDict[completeUserStats[j][4]].append(completeUserStats[j])
except KeyError:
RMDPathDict[completeUserStats[j][4]] = [completeUserStats[j]]
if completeUserStats[j][1] == 'delete file':
try:
DFPathDict[completeUserStats[j][4]].append(completeUserStats[j])
except KeyError:
DFPathDict[completeUserStats[j][4]] = [completeUserStats[j]]
if completeUserStats[j][1] == 'rename to':
try:
RNPathDict[completeUserStats[j][4]].append(completeUserStats[j])
except KeyError:
RNPathDict[completeUserStats[j][4]] = [completeUserStats[j]]
if DLPathDict != {}:
w.write(' ')
w.write('DOWNLOADS:\n')
for k,v in DLPathDict.items():
counter = 0
for i in range(len(v)):
if counter == 0: #if first run...
w.write(' ')
w.write(' ')
w.write(k) #write directory location
w.write(':\n')
# fileA.txt
# fail fileB.txt
w.write(' ')
if v[i][-1] == 'fail':
w.write('fail')
else:
w.write(' ')
w.write(' ')
w.write(v[i][5])
w.write(' ')
w.write(str(v[i][6]))
w.write('\n')
counter += 1
if RESTPathDict != {}:
w.write(' ')
w.write('RESTARTED DOWNLOADS:\n')
for k,v in RESTPathDict.items():
counter = 0
for i in range(len(v)):
if counter == 0: #if first run...
w.write(' ')
w.write(' ')
w.write(k) #write directory location
w.write(':\n')
w.write(' ')
if v[i][-1] == 'fail':
w.write('fail')
else:
w.write(' ')
w.write(' ')
w.write(v[i][5])
w.write(' ')
w.write(str(v[i][6]))
w.write('\n')
counter += 1
if ULPathDict != {}:
w.write(' ')
w.write('UPLOADS:\n')
for k,v in ULPathDict.items():
counter = 0
for i in range(len(v)):
if counter == 0: #if first run...
w.write(' ')
w.write(' ')
w.write(k) #write directory location
w.write(':\n')
w.write(' ')
if v[i][-1] == 'fail':
w.write('fail')
else:
w.write(' ')
w.write(' ')
w.write(v[i][5])
w.write(' ')
w.write(str(v[i][6]))
w.write('\n')
counter += 1
if APPathDict != {}:
w.write(' ')
w.write('APPENDS:\n')
for k,v in APPathDict.items():
counter = 0
for i in range(len(v)):
if counter == 0: #if first run...
w.write(' ')
w.write(' ')
w.write(k) #write directory location
w.write(':\n')
w.write(' ')
if v[i][-1] == 'fail':
w.write('fail')
else:
w.write(' ')
w.write(' ')
w.write(v[i][5])
w.write(' ')
w.write(str(v[i][6]))
w.write('\n')
counter += 1
if MDPathDict != {}:
w.write(' ')
w.write('MADE DIRECTORIES:\n')
for k,v in MDPathDict.items():
counter = 0
for i in range(len(v)):
if counter == 0: #if first run...
w.write(' ')
w.write(' ')
w.write(k) #write directory location
w.write(':\n')
w.write(' ')
if v[i][-1] == 'fail':
w.write('fail')
else:
w.write(' ')
w.write(' ')
w.write(v[i][5])
w.write(' ')
w.write(str(v[i][6]))
w.write('\n')
counter += 1
if RMDPathDict != {}:
w.write(' ')
w.write('REMOVED DIRECTORIES:\n')
for k,v in RMDPathDict.items():
counter = 0
for i in range(len(v)):
if counter == 0: #if first run...
w.write(' ')
w.write(' ')
w.write(k) #write directory location
w.write(':\n')
w.write(' ')
if v[i][-1] == 'fail':
w.write('fail')
else:
w.write(' ')
w.write(' ')
w.write(v[i][5])
w.write(' ')
w.write(str(v[i][6]))
w.write('\n')
counter += 1
if DFPathDict != {}:
w.write(' ')
w.write('DELETED FILES:\n')
for k,v in DFPathDict.items():
counter = 0
for i in range(len(v)):
if counter == 0: #if first run...
w.write(' ')
w.write(' ')
w.write(k) #write directory location
w.write(':\n')
w.write(' ')
if v[i][-1] == 'fail':
w.write('fail')
else:
w.write(' ')
w.write(' ')
w.write(v[i][5])
w.write(' ')
w.write(str(v[i][6]))
w.write('\n')
counter += 1
if RNPathDict != {}:
w.write(' ')
w.write('RENAMES:\n')
for k,v in RNPathDict.items():
counter = 0
for i in range(len(v)):
if counter == 0: #if first run...
w.write(' ')
w.write(' ')
w.write(k) #write directory location
w.write(':\n')
w.write(' ')
if v[i][-1] == 'fail':
w.write('fail')
else:
w.write(' ')
w.write(' ')
w.write(v[i][5])
w.write(' ')
w.write(v[i][6])
w.write(' ')
w.write(str(v[i][7]))
w.write('\n')
counter += 1
w.close()
class msgEvntLst(object):
def __init__(self,m,p,d,t,u,i,a,lC):
self.message = m
self.users = []
self.users.append(userEvntLst(p,d,t,u,i,a,lC))
def findUserIndex(self,u):
for i in range(len(self.users)):
if u == self.users[i].user:
return i
return G.arbitraryIndexVal
def addEvnt(self,p,d,t,u,i,a,lC):
uI = self.findUserIndex(u)
if uI != G.arbitraryIndexVal:
self.users[uI].addEvnt(p,d,t,i,a,lC)
else:
self.users.append(userEvntLst(p,d,t,u,i,a,lC))
def incUsrInstance(self,u):
self.users[self.findUserIndex(u)].incUsrInstance()
def decUsrInstance(self,u):
self.users[self.findUserIndex(u)].decUsrInstance()
def userLoggedIn(self,u):
return self.users[self.findUserIndex(u)].userLoggedIn()
def addCWD(self,u,p,dir):
self.users[self.findUserIndex(u)].addCWD(p,dir)
def getCWD(self,u,p):
return self.users[self.findUserIndex(u)].getCWD(p)
def store(self,u,p,action):
self.users[self.findUserIndex(u)].store(p,action)
def getStored(self,u,p,specialRequest):
return self.users[self.findUserIndex(u)].getStored(p,specialRequest)
def clearStored(self,u,p):
return self.users[self.findUserIndex(u)].clearStored(p)
def addStatistic(self,u,p,s):
self.users[self.findUserIndex(u)].addStatistic(p,s)
def holdStatistic(self,u,p,s):
self.users[self.findUserIndex(u)].holdStatistic(p,s)
def updateStatistic(self,u,p,o,s):
self.users[self.findUserIndex(u)].updateStatistic(p,o,s)
def getStatistic(self,u,p):
return self.users[self.findUserIndex(u)].getStatistic(p)
def getHeldStatistic(self,u,p):
return self.users[self.findUserIndex(u)].getHeldStatistic(p)
def checkPrevActionEqls(self,u,p,str):
return self.users[self.findUserIndex(u)].checkPrevActionEqls(p,str)
def getLatestAction(self,u,p):
return self.users[self.findUserIndex(u)].getLatestAction(p)
def appendAA(self,u,p,analyzed):
self.users[self.findUserIndex(u)].appendAA(p,analyzed)
def getAA(self,u,p):
return self.users[self.findUserIndex(u)].getAA(p)
def suspend(self,u,p,value):
self.users[self.findUserIndex(u)].suspend(p,value)
def unSuspend(self,u,p):
self.users[self.findUserIndex(u)].unSuspend(p)
def ifSuspend(self,u,p):
return self.users[self.findUserIndex(u)].ifSuspend(p)
def resetLagListIndex(self,u,p):
self.users[self.findUserIndex(u)].resetLagListIndex(p)
def prnt(self,u,p):
self.users[self.findUserIndex(u)].prnt(p)
def getItems(self,u,p):
u = self.users[self.findUserIndex(u)].user
p = self.users[self.findUserIndex(u)].getPort(p)
(d,t,i,a) = self.users[self.findUserIndex(u)].getDtoA(p)
return (p,d,t,u,i,a)
def createParsedList(self,u,p,analyzed):
self.users[self.findUserIndex(u)].createParsedList(u,p,analyzed)
def getParsed(self,u,p):
return self.users[self.findUserIndex(u)].getParsed(p)
def fullStatisticWrite(self,fileToWriteTo):
for i in range(len(self.users)):
self.users[i].fullStatisticWrite(fileToWriteTo,self.users[i].user)
class evntLst(object):
messages = []
def __init__(self,m,p,d,t,u,i,a,lC):
self.messages.append(msgEvntLst(m,p,d,t,u,i,a,lC))
def findMsgIndex(self,m):
for i in range(len(self.messages)):
if m == self.messages[i].message:
return i
return G.arbitraryIndexVal
def addEvnt(self,m,p,d,t,u,i,a,lC):
mI = self.findMsgIndex(m)
if mI != G.arbitraryIndexVal:
self.messages[mI].addEvnt(p,d,t,u,i,a,lC)
else:
self.messages.append(msgEvntLst(m,p,d,t,u,i,a,lC))
def incUsrInstance(self,m,u):
self.messages[self.findMsgIndex(m)].incUsrInstance(u)
def decUsrInstance(self,m,u):
self.messages[self.findMsgIndex(m)].decUsrInstance(u)
def userLoggedIn(self,m,u):
return self.messages[self.findMsgIndex(m)].userLoggedIn(u)
def createLoginList(self,m,u):
if self.messages[self.findMsgIndex(m)].userLoggedIn(u):
G.loggedIn.append((True,G.line))
else:
G.loggedIn.append((False,G.line))
def addCWD(self,m,u,p,dir):
self.messages[self.findMsgIndex(m)].addCWD(u,p,dir)
def getCWD(self,m,u,p):
return self.messages[self.findMsgIndex(m)].getCWD(u,p)
def checkPrevActionEqls(self,m,u,p,str):
return self.messages[self.findMsgIndex(m)].checkPrevActionEqls(u,p,str)
def store(self,m,u,p,action):
self.messages[self.findMsgIndex(m)].store(u,p,action)
def getStored(self,m,u,p,specialRequest):
return self.messages[self.findMsgIndex(m)].getStored(u,p,specialRequest)
def clearStored(self,m,u,p):
return self.messages[self.findMsgIndex(m)].clearStored(u,p)
def resetLagListIndex(self,lC):
m = ''
u = ''
p = ''
for itr in range(lC):
(tempM,tempU,tempP) = G.changeList.getNext(itr)
if tempM != '':
m = tempM
if tempU != '':
u = tempU
if tempP != '':
p = tempP
self.messages[self.findMsgIndex(m)].resetLagListIndex(u,p)
def addStatistic(self,m,u,p,s):
self.messages[self.findMsgIndex(m)].addStatistic(u,p,s)
def holdStatistic(self,m,u,p,s):
self.messages[self.findMsgIndex(m)].holdStatistic(u,p,s)
def updateStatistic(self,m,u,p,o,s):
try:
self.messages[self.findMsgIndex(m)].updateStatistic(u,p,o,s)
except TypeError:
print "Error: Log file continuity problem at line " + str(G.line) + \
". Most likely due to user or port popping up out of nowhere. Contact developer if you can't figure out what's wrong."
exit()
def getStatistic(self,m,u,p):
return self.messages[self.findMsgIndex(m)].getStatistic(u,p)
def getHeldStatistic(self,m,u,p):
return self.messages[self.findMsgIndex(m)].getHeldStatistic(u,p)
def getLatestAction(self,m,u,p):
return self.messages[self.findMsgIndex(m)].getLatestAction(u,p)
def appendAA(self,m,u,p,analyzed):
self.messages[self.findMsgIndex(m)].appendAA(u,p,analyzed)
def suspend(self,m,u,p,value):
self.messages[self.findMsgIndex(m)].suspend(u,p,value)
def unSuspend(self,m,u,p):
self.messages[self.findMsgIndex(m)].unSuspend(u,p)
def ifSuspend(self,m,u,p):
return self.messages[self.findMsgIndex(m)].ifSuspend(u,p)
def createParsedList(self,m,u,p,analyzed):
self.messages[self.findMsgIndex(m)].createParsedList(u,p,analyzed)
def getParsed(self,m,u,p):
return self.messages[self.findMsgIndex(m)].getParsed(u,p)
def fullStatisticWrite(self,fileToWriteTo):
for i in range(len(self.messages)):
self.messages[i].fullStatisticWrite(fileToWriteTo)
def compileAnalyzedActions(self):
for itr in range(len(G.changeListArray)):
(m,u,p) = G.changeListArray[itr]
(AA,lineCtr) = self.messages[self.findMsgIndex(m)].getAA(u,p)
G.AAs.append((AA,lineCtr))
def createLists(self):
m = ''
u = ''
p = ''
for itr in range(len(G.AAs)):
(AA,lineCtr) = G.AAs[itr]
(m,u,p) = G.changeListArray[itr]
if grabAfterUser(AA,1) == 'disconnected.' or grabAfterUser(AA,2) == 'successfully logged':
parsed = self.getParsed(m, u, p)
G.fullInstanceList.append(parsed)
if found(itr+1,G.statisticLines):
gotStatistic = self.getStatistic(m, u, p)
G.statistics.append(gotStatistic)
def findLogin(self,logins,item):
for i in range(len(logins)):
if logins[i][0] == item[0]:
if logins[i][1] == 'login':
return (logins[i],i)
print 'problem in func findLogin()'
return (None,G.arbitraryIndexVal)
def checkForLineInPCandidates(self,parseCandidates):
for i in range(len(parseCandidates)):
for j in range(len(parseCandidates[i])):
if parseCandidates[i][j] == G.specifiedLineNum:
return (i,j)
return (G.arbitraryIndexVal,G.arbitraryIndexVal)
def findMaxOfParseCandidates(self,parseCandidates):
maxOfParseCandidates = (-1,'---')
for i in range(len(parseCandidates)):
if parseCandidates[i][0] > maxOfParseCandidates[0]:
maxOfParseCandidates = parseCandidates[i]
return maxOfParseCandidates
#parse log file by user login/logouts
def parseByLogin(self):
logins = []
parseCandidates = []
for i in range(len(G.fullInstanceList)):
if i == 12:
pass
if G.fullInstanceList[i][1] == 'login': #if login, add to list of logins
logins.append(G.fullInstanceList[i])
elif G.fullInstanceList[i][1] == 'disconnect': #if disconnect...
(login,index) = self.findLogin(logins,G.fullInstanceList[i]) #try to find corresponding login...
if login != None: #if corresponding login found...
try: #add line numbers of login and disconnect to dictionary
G.userInstancesDict[G.fullInstanceList[i][0]].append((login[2],G.fullInstanceList[i][2]))
except KeyError:
G.userInstancesDict[G.fullInstanceList[i][0]] = [(login[2],G.fullInstanceList[i][2])]
if login[2] <= G.specifiedLineNum and G.fullInstanceList[i][2] >= G.specifiedLineNum: #if line num between
# login and disc lines,
# add to candidates list
parseCandidates.append((login[2],G.fullInstanceList[i][2]))
del logins[index] #remove used login from list of logins to prevent redundancies
else: #if corresponding login not found...
if G.fullInstanceList[i][0] != '(not logged in)': #...and not a failed login attempt...
try: #add line number of disconnect only to dictionary
G.userInstancesDict[G.fullInstanceList[i][0]].append(('---',G.fullInstanceList[i][2]))
except KeyError:
G.userInstancesDict[G.fullInstanceList[i][0]] = [('---',G.fullInstanceList[i][2])]
if G.fullInstanceList[i][2] >= G.specifiedLineNum: #if specified line num less than disc line num...
parseCandidates.append((0,G.fullInstanceList[i][2])) #add to candidates list
#now all logins that are leftover are indicative of users that didn't log out within the log file, and we do the "mirror"
#of what we did when corresponding logins aren't found
for i in range(len(logins)):
try:
G.userInstancesDict[logins[i][0]].append((logins[i][2],'---'))
except KeyError:
G.userInstancesDict[logins[i][0]] = [(logins[i][2],'---')]
if logins[i][2] <= G.specifiedLineNum:
parseCandidates.append((logins[i][2],'---'))
if len(parseCandidates) == 0:
return None
elif len(parseCandidates) == 1:
return parseCandidates[0]
elif len(parseCandidates) >= 1: #if more than one possible parse candidate, we let them fight it out among themselves...
#...well not really, we return the quickest instance, or the instance with the smallest
#difference in line numbers
#if the specified line number is equal to any login or disconnect line number, we return that instance instead of the
#smallest
(itrI,itrJ) = self.checkForLineInPCandidates(parseCandidates)
if (itrI or itrJ) != G.arbitraryIndexVal:
return parseCandidates[itrI]
#determine smallest instance and return it...
lineDiffList = []
smallestVal = -1
for i in range(len(parseCandidates)):
if parseCandidates[i][1] == '---': #disc missing
return self.findMaxOfParseCandidates(parseCandidates)
#return parseCandidates[i][0],parseCandidates[i][1]
lineDiffList.append(parseCandidates[i][1] - parseCandidates[i][0])
for i in range(len(lineDiffList)):
if smallestVal == -1:
smallestVal = lineDiffList[i]
if smallestVal > lineDiffList[i]:
smallestVal = lineDiffList[i]
return parseCandidates[findInList(smallestVal,lineDiffList)]
def parsedPrint(self):
G.events.resetLagListIndex(G.line-1)
m = ''
u = ''
p = ''
for itr in range(len(G.AAs)):
(AA,lineCtr) = G.AAs[itr]
(m,u,p) = G.changeListArray[itr]
if grabAfterUser(AA,1) == 'disconnected.' or grabAfterUser(AA,2) == 'successfully logged':
print self.getParsed(m, u, p)
def analyzedPrint(self,lC):
goAhead = False
m = ''
u = ''
p = ''
if not G.FFlag:
if os.path.exists(G.analyzedResultsFile):
yn = confirmation(G.analyzedResultsFile + " exists, OK to overwrite? (Y/N)")
if yn in ('N','n'):
print G.analyzedResultsFile, "not overwritten."
else:
goAhead = True
else:
goAhead = True
if G.FFlag or goAhead:
if os.path.exists(G.analyzedResultsFile):
print "Overwriting", G.analyzedResultsFile + "..."
else:
print "Writing", G.analyzedResultsFile + "..."
w = open(G.analyzedResultsFile, 'w')
for itr in range(len(G.AAs)):
(AA,lineCtr) = G.AAs[itr]
(m,u,p) = G.changeListArray[itr]
if AA != '':
w.write(AA)
w.write(" ")
w.write(str(lineCtr+1))
w.write("\n")
w.close()
def statisticWrite(self):
goAhead = False
m = ''
u = ''
p = ''
if not G.FFlag:
if os.path.exists(G.statisticsWriteFile):
yn = confirmation(G.statisticsWriteFile + " exists, OK to overwrite? (Y/N)")
if yn in ('N','n'):
print G.statisticsWriteFile, "not overwritten."
else:
print "Overwriting", G.statisticsWriteFile + "..."
goAhead = True
else:
goAhead = True
if G.FFlag or goAhead:
w = open(G.statisticsWriteFile, 'w')
for itr in range(len(G.AAs)):
(AA,lineCtr) = G.AAs[itr]
(m,u,p) = G.changeListArray[itr]
if found(itr+1,G.statisticLines):
gotStatistic = self.getStatistic(m, u, p)
w.write(str(gotStatistic))
w.write(" ")
w.write(str(itr+1))
w.write("\n")
w.close()
def statisticSummaryWrite(self):
goAhead = False
if not G.FFlag:
if os.path.exists(G.statisticsFile):
yn = confirmation(G.statisticsFile + " exists, OK to overwrite? (Y/N)")
if yn in ('N','n'):
print G.statisticsFile, "not overwritten."
else:
goAhead = True
else:
goAhead = True
if G.FFlag or goAhead:
if os.path.exists(G.statisticsFile):
print "Overwriting", G.statisticsFile + "..."
else:
print "Writing", G.statisticsFile + "..."
w = open(G.statisticsFile, 'w')
w.write('STATISTICS SUMMARY:')
w.write(' ')
w.write(str(tuple(G.begFileTimeList)))
w.write(' -> ')
w.write(str(tuple(G.endFileTimeList)))
w.write('\n')
w.close()
for itr in range(len(G.AAs)):
(AA,lineCtr) = G.AAs[itr]
(m,u,p) = G.changeListArray[itr]
self.fullStatisticWrite(G.statisticsFile)
def sortedPrint(self,lC):
m = ''
u = ''
p = ''
w = open(G.resultsFile, 'w')
for itr in range(len(G.AAs)):
(AA,lineCtr) = G.AAs[itr]
(m,u,p) = G.changeListArray[itr]
(p,d,t,u,i,a) = self.messages[self.findMsgIndex(m)].getItems(u,p)
w.write(str(p))
w.write(" ")
w.write(d)
w.write(" ")
w.write(t)
w.write(" ")
w.write(u)
w.write(" ")
w.write(i)
w.write(" ")
w.write(a)
if AA != '':
w.write(" AA: ")
w.write(AA)
w.write("\n")
w.close()