1
0
Fork 0
mirror of https://github.com/dbarzin/pandora-box.git synced 2025-07-22 23:09:41 +02:00

work on layout

This commit is contained in:
dbarzin 2023-03-03 13:16:30 +01:00
parent 76f53ff5a4
commit 75a789b96e
2 changed files with 45 additions and 10 deletions

View file

@ -8,6 +8,7 @@ User interface
Technical Technical
- [ ] Multi threading
- [ ] ~~Deployment on Raspberry Pi~~ (too slow) - [ ] ~~Deployment on Raspberry Pi~~ (too slow)
- [x] logrotate on pandora-box.log - [x] logrotate on pandora-box.log
- [x] place logs in /var/logs - [x] place logs in /var/logs

View file

@ -274,12 +274,23 @@ class PandoraBox:
logs = [] logs = []
def _log(self, msg): def _log(self, msg):
"""log something""" """log a message with a new line"""
if self.has_curses: if self.has_curses:
# display log on screen # display log on screen
self.logs.append(msg) self.logs.append(msg)
if len(self.logs) > (curses.LINES - 22): if len(self.logs)>(curses.LINES-22):
self.logs.pop(0) self.logs.pop(0)
self._log_update()
def _log_msg(self, msg):
"""update last message -> no new line"""
if self.has_curses:
# display log on screen
self.logs[-1] = msg
self._log_update()
def _log_update(self):
"""Update the log screen"""
self.log_win.clear() self.log_win.clear()
self.log_win.border(0) self.log_win.border(0)
for i in range(min(curses.LINES - 22, len(self.logs))): for i in range(min(curses.LINES - 22, len(self.logs))):
@ -397,7 +408,12 @@ class PandoraBox:
status = None status = None
full_path = os.path.join(root, file) full_path = os.path.join(root, file)
file_size = os.path.getsize(full_path) file_size = os.path.getsize(full_path)
# log("Check %s [%s]" % (file, human_readable_size(file_size)))
# log the scan has started
self._log(
f'Scan {file} '
f'[{self._human_readable_size(file_size)}]')
file_scan_start_time = time.time() file_scan_start_time = time.time()
if self.is_fake_scan: if self.is_fake_scan:
time.sleep(0.1) time.sleep(0.1)
@ -413,13 +429,22 @@ class PandoraBox:
while loop < 960: while loop < 960:
res = pandora.task_status(res["taskId"]) res = pandora.task_status(res["taskId"])
status = res["status"] status = res["status"]
if status != "WAITING": if status != "WAITING":
break break
time.sleep(0.5) time.sleep(0.5)
# update status
self._log_msg(
f'Scan {file} '
f'[{self._human_readable_size(file_size)}] '
"." * (loop // 4))
loop += 1 loop += 1
file_scan_end_time = time.time() file_scan_end_time = time.time()
self._log( # log the result
self._log_msg(
f'Scan {file} ' f'Scan {file} '
f'[{self._human_readable_size(file_size)}] ' f'[{self._human_readable_size(file_size)}] '
'-> ' '-> '
@ -429,8 +454,11 @@ class PandoraBox:
f'size="{file_size}", ' f'size="{file_size}", '
f'status="{status}"", ' f'status="{status}"", '
f'duration="{int(file_scan_end_time - file_scan_start_time)}"') f'duration="{int(file_scan_end_time - file_scan_start_time)}"')
scanned += os.path.getsize(full_path) scanned += os.path.getsize(full_path)
file_count += 1 file_count += 1
# update status bar
self._update_bar(scanned * 100 // used) self._update_bar(scanned * 100 // used)
if status == "ALERT": if status == "ALERT":
@ -536,8 +564,14 @@ class PandoraBox:
def clean(self): def clean(self):
"""Remove infected files""" """Remove infected files"""
if len(self.infected_files) > 0: if len(self.infected_files) > 0:
self._log(f"{len(self.infected_files)} infected_files detecetd !") # display message
self._log(f"{len(self.infected_files)} infected_files detecetd :")
logging.info(f"infeted_files={len(self.infected_files)}") logging.info(f"infeted_files={len(self.infected_files)}")
# print list of files
for file in self.infected_files:
self._log(file)
if not self.has_curses: if not self.has_curses:
self.display_image("BAD") self.display_image("BAD")
self.wait_mouse_click() self.wait_mouse_click()