forked from bpm-diag/smartRPA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
254 lines (214 loc) · 9.14 KB
/
main.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
# ****************************** #
# Main logger
# Handles all the threads of the application
# ****************************** #
import os
import sys
sys.path.append('src/')
import time
from threading import Thread
from multiprocessing import Process, Queue
import utils.utils
import modules.GUI.GUI
# import utils.config
import modules.consumerServer
import utils.utils
from modules.events import systemEvents, officeEvents, clipboardEvents, standardEvents
import platform
def startLogger(systemLoggerFilesFolder,
systemLoggerPrograms,
systemLoggerClipboard,
systemLoggerStandard,
systemLoggerHotkeys,
systemLoggerUSB,
systemLoggerEvents,
excelFilepath,
officeExcel,
officeWord,
officePowerpoint,
officeOutlook,
browserChrome,
browserFirefox,
browserEdge,
browserOpera,
status_queue,
LOG_FILEPATH,
SCREENSHOT_FILEPATH,
processesPID
):
"""
Main function where program starts.
This method is called by the GUI when the user presses "start logger" button.
All the values are passed by the GUI module
:param systemLoggerFilesFolder: true if files/folder checkbox is checked in GUI
:param systemLoggerPrograms: true if programs checkbox is checked in GUI
:param systemLoggerClipboard: true if clipboard checkbox is checked in GUI
:param systemLoggerStandard: true if mouse and keyboard checkbox is checked in GUI
:param systemLoggerHotkeys: true if hotkeys checkbox is checked in GUI
:param systemLoggerUSB: true if usb checkbox is checked in GUI
:param systemLoggerEvents: deprecated
:param excelFilepath: contains path of excel file, default is None
:param officeExcel: true if excel checkbox is checked in GUI
:param officeWord: true if word checkbox is checked in GUI
:param officePowerpoint: true if powerpoint checkbox is checked in GUI
:param officeOutlook: true if outlook checkbox is checked in GUI
:param browserChrome: true if chrome checkbox is checked in GUI
:param browserFirefox: true if firefox checkbox is checked in GUI
:param browserEdge: true if edge checkbox is checked in GUI
:param browserOpera: true if opera checkbox is checked in GUI
:param status_queue: Queue to print messages on GUI
:param LOG_FILEPATH: path of the event log file
:param SCREENSHOT_FILEPATH: Queue of the screenshot log file folder
:param processesPID: PID of started processes, used to kill them when logger is stopped
"""
# Thread names in use
# t0: Main Logger
# t8 = Thread(target=clipboardEvents.logClipboard)
# t9 = Process(target=systemEvents.logPasteHotkey)
# t17 = Thread(target=standardEvents.logMouse)
# t18 = Thread(target=standardEvents.logKeyboard)
# t1 = Thread(target=systemEvents.watchFolder)
# t2 = Process(target=systemEvents.watchRecentsFilesWin)
# Not in use > t3 = Thread(target=systemEvents.detectSelectionWindowsExplorer)
# Not in use > t4 = Thread(target=systemEvents.printerLogger)
# t5 = Thread(target=systemEvents.watchFolderMac)
# t6 = Thread(target=systemEvents.logProcessesWin)
# t7 = Thread(target=systemEvents.logProcessesMac)
# t10 = Process(target=systemEvents.logHotkeys)
# t11 = Thread(target=systemEvents.logUSBDrives)
# t12 = Process(target=officeEvents.excelEvents, args=(status_queue, excelFilepath,))
# t13 = Thread(target=officeEvents.excelEventsMacServer, args=[status_queue, excelFilepath])
# Deprecated > t18 = Thread(target=mouseEvents.logMouse)
# t14 = Process(target=officeEvents.wordEvents)
# t15 = Process(target=officeEvents.powerpointEvents)
# t16 = Process(target=officeEvents.outlookEvents)
try:
# create the threads as daemons so they are closed when main ends
# ************
# main logging server
# ************
log_filepath, screenshot_filepath = utils.utils.createLogFile()
# return log file to GUI so it can be processed
LOG_FILEPATH.put(log_filepath)
SCREENSHOT_FILEPATH.put(screenshot_filepath)
t0 = Thread(target=modules.consumerServer.runServer, args=[status_queue])
t0.daemon = True
t0.start()
modules.consumerServer.log_filepath = log_filepath
# ************
# system logger
# ************
if systemLoggerClipboard:
# log copy event
t8 = Thread(target=clipboardEvents.logClipboard)
t8.daemon = True
t8.start()
# only way to log paste event is to detect ctrl + v, but it should be started as process instead of thread
# otherwise some events are lost
if utils.utils.WINDOWS:
t9 = Process(target=systemEvents.logPasteHotkey)
# t9.daemon = True
t9.start()
processesPID.put(t9.pid)
if systemLoggerStandard:
# Added by josaloroc & a8081
t17 = Thread(target=standardEvents.logMouse)
t17.daemon = True
t17.start()
t18 = Thread(target=standardEvents.logKeyboard)
t18.daemon = True
t18.start()
if systemLoggerFilesFolder:
if utils.utils.WINDOWS:
t1 = Thread(target=systemEvents.watchFolder)
t1.daemon = True
t1.start()
t2 = Process(target=systemEvents.watchRecentsFilesWin)
# t2.daemon = True
t2.start()
processesPID.put(t2.pid)
# t3 = Thread(target=systemEvents.detectSelectionWindowsExplorer)
# t3.daemon = True
# t3.start()
# t4 = Thread(target=systemEvents.printerLogger)
# t4.daemon = True
# t4.start()
elif utils.utils.MAC:
t5 = Thread(target=systemEvents.watchFolderMac)
t5.daemon = True
t5.start()
if systemLoggerPrograms:
if utils.utils.WINDOWS:
t6 = Thread(target=systemEvents.logProcessesWin)
t6.daemon = True
t6.start()
elif utils.utils.MAC:
t7 = Thread(target=systemEvents.logProcessesMac)
t7.daemon = True
t7.start()
if systemLoggerHotkeys and utils.utils.WINDOWS:
t10 = Process(target=systemEvents.logHotkeys)
t10.start()
processesPID.put(t10.pid)
if systemLoggerUSB and utils.utils.WINDOWS:
t11 = Thread(target=systemEvents.logUSBDrives)
t11.daemon = True
t11.start()
if systemLoggerEvents:
pass
# ************
# office logger
# ************
if officeExcel:
status_queue.put(f"[mainLogger] Loading Excel...")
if utils.utils.WINDOWS:
t12 = Process(target=officeEvents.excelEvents, args=(status_queue, excelFilepath,))
t12.start()
processesPID.put(t12.pid)
# t18 = Thread(target=mouseEvents.logMouse)
# t18.daemon = True
# t18.start()
if utils.utils.MAC:
if utils.utils.isPortInUse(3000):
os.system("pkill -f node")
t13 = Thread(target=officeEvents.excelEventsMacServer, args=[status_queue, excelFilepath])
t13.daemon = True
t13.start()
if officeWord and utils.utils.WINDOWS:
t14 = Process(target=officeEvents.wordEvents)
t14.start()
processesPID.put(t14.pid)
status_queue.put(f"[mainLogger] Loading Word...")
if officePowerpoint and utils.utils.WINDOWS:
t15 = Process(target=officeEvents.powerpointEvents)
t15.start()
processesPID.put(t15.pid)
status_queue.put(f"[mainLogger] Loading PowerPoint...")
if officeOutlook and utils.utils.WINDOWS:
t16 = Process(target=officeEvents.outlookEvents)
t16.start()
processesPID.put(t16.pid)
# ************
# browser logger
# ************
if browserChrome:
modules.consumerServer.log_chrome = True
if browserFirefox:
modules.consumerServer.log_firefox = True
if browserEdge:
modules.consumerServer.log_edge = True
if browserOpera:
modules.consumerServer.log_opera = True
# status_queue.put(f"[mainLogger] Logging started")
if browserChrome or browserFirefox or browserEdge or browserOpera:
status_queue.put(f"[mainLogger] Remember to click on extension icon to enable browser logging")
# keep main active
while 1:
time.sleep(1)
except (KeyboardInterrupt, SystemExit):
print("Closing threads and exiting...")
sys.exit(0)
if __name__ == "__main__":
# launch GUI
utils.config.set_config_default()
modules.GUI.GUI.buildGUI()