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

work in progress

This commit is contained in:
dbarzin 2022-06-12 20:37:49 +02:00
parent 414beccf04
commit 9f68da0094
2 changed files with 84 additions and 58 deletions

View file

@ -6,6 +6,7 @@ Pandorabox is a USB scaning station base on Pandora
Mouse terminal Mouse terminal
--------------- ---------------
sudo apt install gpm sudo apt install gpm
User mount device User mount device

View file

@ -11,6 +11,7 @@ import pyudev
import psutil import psutil
import os import os
import logging import logging
import time
# ----------------------------------------------------------- # -----------------------------------------------------------
# Config variables # Config variables
@ -114,9 +115,11 @@ def update_bar(progress):
progress_win.clear() progress_win.clear()
progress_win.border(0) progress_win.border(0)
time.sleep(0) time.sleep(0)
progress_win.addstr(0, 1, "Progress:")
else: else:
pos = (80 * progress) // 100 pos = (80 * progress) // 100
progress_win.addstr(1, 1, "#"*pos) progress_win.addstr(1, 1, "#"*pos)
progress_win.addstr(0, 1, "Progress: %d%%" % progress)
progress_win.refresh() progress_win.refresh()
def init_log(): def init_log():
@ -179,6 +182,7 @@ def print_screen():
title_win.refresh() title_win.refresh()
status_win = curses.newwin(5, 101, 12, 0) status_win = curses.newwin(5, 101, 12, 0)
status_win.border(0) status_win.border(0)
status_win.addstr(0, 1, "USB Key Information")
# print_status("WAITING") # print_status("WAITING")
print_fslabel("") print_fslabel("")
print_size(None) print_size(None)
@ -240,6 +244,7 @@ def device_loop():
context = pyudev.Context() context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context) monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by("block") monitor.filter_by("block")
try:
for device in iter(monitor.poll, None): for device in iter(monitor.poll, None):
if device.get("ID_FS_USAGE") == "filesystem" and device.device_node[5:7] == "sd": if device.get("ID_FS_USAGE") == "filesystem" and device.device_node[5:7] == "sd":
if device.action == "add": if device.action == "add":
@ -255,8 +260,8 @@ def device_loop():
mount_point = mount_device(device) mount_point = mount_device(device)
try: try:
statvfs=os.statvfs(mount_point) statvfs=os.statvfs(mount_point)
except: except Exception as e :
log("Unexpected error: %-80s" % sys.exc_info()[0]) logging.error("Unexpected error: ", e)
continue continue
print_size(human_readable_size(statvfs.f_frsize * statvfs.f_blocks)) print_size(human_readable_size(statvfs.f_frsize * statvfs.f_blocks))
print_used(human_readable_size(statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree))) print_used(human_readable_size(statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree)))
@ -269,8 +274,11 @@ def device_loop():
time.sleep(0.03) time.sleep(0.03)
update_bar(loading) update_bar(loading)
else: else:
scan(mount_point, statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree)) res = scan(mount_point, statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree))
if res:
log("Scan done.") log("Scan done.")
else:
log("Scan failed !")
if device.action == "remove": if device.action == "remove":
log("Device removed") log("Device removed")
@ -285,6 +293,10 @@ def device_loop():
print_serial("") print_serial("")
umount_device() umount_device()
update_bar(0) update_bar(0)
except Exception as e:
log("Unexpected error: %s" % e )
finally:
log("Done.")
def log_device_info(dev): def log_device_info(dev):
@ -312,20 +324,31 @@ def log_device_info(dev):
"""Scan a mount point with Pandora""" """Scan a mount point with Pandora"""
def scan(mount_point, used): def scan(mount_point, used):
global infected_filed
infected_files = array()
scanned = 0 scanned = 0
file_count = 0
scan_start_time = time.time()
if FAKE_SCAN: if FAKE_SCAN:
for root, dirs, files in os.walk(mount_point): for root, dirs, files in os.walk(mount_point):
for file in files: for file in files:
try :
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("Check %-s [%s]" % (file, human_readable_size(file_size)))
time.sleep(0.05) file_scan_start_time = time.time()
log("Check %s -> %-s" % (file,"SKIPPED")) time.sleep(0.1)
file_scan_end_time = time.time()
log("Check %s (%ds) -> %-s" % (file,(file_scan_end_time - file_scan_start_time),"SKIPPED"))
scanned += os.path.getsize(full_path) scanned += os.path.getsize(full_path)
file_count += 1
update_bar(scanned * 100 // used) update_bar(scanned * 100 // used)
except Exception as e :
log("Unexpected error: %s" % e)
return False
update_bar(100) update_bar(100)
log("Scan done in %ds" % (time.time() - scan_start_time))
log("%d files scanned" % file_count)
else: else:
pp = pypandora.PyPandora(root_url=PANDORA_ROOT_URL) pp = pypandora.PyPandora(root_url=PANDORA_ROOT_URL)
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
@ -343,6 +366,7 @@ def scan(mount_point, used):
break; break;
log("Scan %s -> %s" % (arg,res["status"])) log("Scan %s -> %s" % (arg,res["status"]))
return True
# -------------------------------------- # --------------------------------------
@ -350,14 +374,15 @@ def scan(mount_point, used):
"""Main entry point""" """Main entry point"""
def main(stdscr): def main(stdscr):
try: try :
init_log() init_log()
intit_curses() intit_curses()
print_screen() print_screen()
while True:
device_loop() device_loop()
except: except Exception as e :
logging.error("Unexpected error:", sys.exc_info()[0]) logging.error("Unexpected error: ", e)
logging.error(traceback.format_exc()) # logging.error(traceback.format_exc())
finally: finally:
end_curses() end_curses()