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

animations and fix some bugs

This commit is contained in:
dbarzin 2022-07-25 01:00:07 +02:00
parent 7d52bcdfd6
commit db4600dadc
29 changed files with 104 additions and 106 deletions

BIN
images/CHEM_OK.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
images/bad.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

BIN
images/computer_OK.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
images/computer_nok.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View file

@ -1,19 +0,0 @@
#!/usr/bin/python3
# display all images and reset
import os
import time
size = "1024x600"
#size = "1920x1080"
images = ["pandora-box1.png", "pandora-box2.png", "pandora-box3.png", "pandora-box4.png", "pandora-box5.png"]
for image in images :
os.system("convert -resize %s -background black -gravity center -extent %s %s bgra:/dev/fb0" % (size, size, image))
time.sleep(1)
os.system("reset")

BIN
images/key1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 KiB

BIN
images/key2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 KiB

BIN
images/key3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 KiB

BIN
images/key4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 KiB

BIN
images/key5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 KiB

BIN
images/ok.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 526 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

BIN
images/wait1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
images/wait2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

BIN
images/wait3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
images/wait4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
images/wait5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
images/wait6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
images/wait7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
images/wait8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
images/wait9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

View file

@ -10,7 +10,7 @@ USB_AUTO_MOUNT = False
PANDORA_ROOT_URL = http://127.0.0.1:6100 PANDORA_ROOT_URL = http://127.0.0.1:6100
; Set FAKE_SCAN to true to fake the scan process (used during developement only) ; Set FAKE_SCAN to true to fake the scan process (used during developement only)
FAKE_SCAN = False FAKE_SCAN = True
; Set to true to copy infected files to the quarantine folder ; Set to true to copy infected files to the quarantine folder
; in the USB scanning station ; in the USB scanning station

View file

@ -75,27 +75,37 @@ def human_readable_size(size, decimal_places=1):
def display_image(status): def display_image(status):
if status=="WAIT": if status=="WAIT":
image = "images/pandora-box1.png" image = "images/key*.png"
elif status=="WORK": elif status=="WORK":
image = "images/pandora-box2.png" image = "images/wait*.png"
elif status=="OK": elif status=="OK":
image = "images/pandora-box3.png" image = "images/ok.png"
elif status=="BAD": elif status=="BAD":
image = "images/pandora-box4.png" image = "images/bad.png"
elif status=="ERROR": elif status=="ERROR":
image = "images/pandora-box5.png" image = "images/error.png"
else: else:
return return
os.system("killall fim 2>/dev/null") # hide old image
os.system("fim -qa %s </dev/null 2>/dev/null &" % image) os.system("killall -s 9 fim 2>/dev/null")
# display image
if "*" in image:
# slide show
os.system("fim -qa -c 'while(1){display;sleep 1;next;}' %s </dev/null 2>/dev/null &" % image)
else :
# only one image
os.system("fim -qa %s </dev/null 2>/dev/null &" % image)
# ----------------------------------------------------------- # -----------------------------------------------------------
def waitMouseClick(): def waitMouseClick():
mouse = open( "/dev/input/mice", "rb" ) mouse = open( "/dev/input/mice", "rb" )
down = False;
while True: while True:
buf = mouse.read(3) buf = mouse.read(3)
if ((buf[0] & 0x1)==1): if ((buf[0] & 0x1)==1):
down = True
if (((buf[0] & 0x1)==0) and down):
break; break;
mouse.close() mouse.close()
@ -277,22 +287,27 @@ def log(str):
"""Mount USB device""" """Mount USB device"""
def mount_device(device): def mount_device(device):
log('Try to mount partition')
if USB_AUTO_MOUNT: if USB_AUTO_MOUNT:
found = False found = False
loop = 0 loop = 0
while (not found) and (loop < 10): while (not found) and (loop < 15):
# need to sleep before devide is mounted # need to sleep before devide is mounted
time.sleep(1) time.sleep(1)
for partition in psutil.disk_partitions(): for partition in psutil.disk_partitions():
if partition.device == device.device_node: if partition.device == device.device_node:
log("Device mounted at {}".format(partition.mountpoint)) log("Partition mounted at {}".format(partition.mountpoint))
found = True found = True
loop += 1 loop += 1
if loop < 10: if loop < 10:
return partition.mountpoint return partition.mountpoint
else: else:
log('No partition mounted')
return None return None
else: else:
if not os.path.exists("/media/box"):
log("folder /media/box does not exists")
return None
res = os.system("pmount " + device.device_node + " /media/box") res = os.system("pmount " + device.device_node + " /media/box")
found = False found = False
loop = 0 loop = 0
@ -304,15 +319,13 @@ def mount_device(device):
loop +=1 loop +=1
continue continue
break; break;
log("Device mounted at /media/box") log("Partition mounted at /media/box")
return "/media/box" return "/media/box"
"""Unmount USB device""" """Unmount USB device"""
def umount_device(): def umount_device():
if not USB_AUTO_MOUNT: log("Sync partitions")
if os.path.exists("/media/box"): res = os.system("sync")
log("Unmounting device /media/box")
res = os.system("pumount /media/box")
"""Main device loop""" """Main device loop"""
def device_loop(): def device_loop():
@ -322,78 +335,79 @@ 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: #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":
log("Device inserted") log("Device inserted")
log_device_info(device) log_device_info(device)
if not CURSES:
display_image("WORK")
else:
# display device type
print_fslabel(device.get("ID_FS_LABEL"))
print_fstype(device.get("ID_PART_TABLE_TYPE") + " " + device.get("ID_FS_TYPE"))
print_model(device.get("ID_MODEL"))
print_serial(device.get("ID_SERIAL_SHORT"))
# Mount device
mount_point = mount_device(device)
log('Partition mounted at %s' % mount_point)
if mount_point == None:
# no partition
continue
try:
statvfs=os.statvfs(mount_point)
except Exception as e :
log("Unexpected error: %s" % e)
continue
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)))
# Scan files
log("Scan started...........")
infected_files = scan(mount_point, statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree))
# Clean files
if len(infected_files) > 0:
log('%d infected files found !' % len(infected_files))
if not CURSES: if not CURSES:
display_image("WORK") display_image("BAD")
waitMouseClick()
else: else:
# display device type log('PRESS KEY TO CLEAN')
print_fslabel(device.get("ID_FS_LABEL")) screen.getch()
print_fstype(device.get("ID_PART_TABLE_TYPE") + " " + device.get("ID_FS_TYPE")) # Remove infected files
print_model(device.get("ID_MODEL")) for file in infected_files:
print_serial(device.get("ID_SERIAL_SHORT")) try :
# Mount device os.remove(file)
mount_point = mount_device(device) log('%s removed' % file)
if mount_point == None: except Exception as e :
# no partition log("Unexpected error: %s" % str(e))
continue os.system("sync")
try: log("Clean done.")
statvfs=os.statvfs(mount_point)
except Exception as e :
log("Unexpected error: %s" % e)
continue
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)))
# Scan files
log("Scan started...........")
infected_files = scan(mount_point, statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree))
# Clean files
if len(infected_files) > 0:
log('%d infected files found !' % len(infected_files))
if not CURSES:
display_image("BAD")
waitMouseClick()
else:
log('PRESS KEY TO CLEAN')
screen.getch()
# Remove infected files
for file in infected_files:
try :
os.remove(file)
log('%s removed' % file)
except Exception as e :
log("Unexpected error: %s" % str(e))
os.system("sync")
log("Clean done.")
if not CURSES:
display_image("OK")
else:
if not CURSES:
display_image("OK")
umount_device()
if device.action == "remove":
log("Device removed")
if not CURSES: if not CURSES:
display_image("WAIT") display_image("OK")
else: else:
print_fslabel("") if not CURSES:
print_size(None) display_image("OK")
print_used(None) umount_device()
print_fstype("")
print_model("") if device.action == "remove":
print_serial("") log("Device removed")
update_bar(0) if not CURSES:
except Exception as e: display_image("WAIT")
log("Unexpected error: %s" % str(e) ) else:
finally: print_fslabel("")
log("Done.") print_size(None)
print_used(None)
print_fstype("")
print_model("")
print_serial("")
update_bar(0)
# except Exception as e:
# log("Unexpected error: %s" % str(e) )
# finally:
# log("Done.")
def log_device_info(dev): def log_device_info(dev):
@ -406,13 +420,10 @@ def log_device_info(dev):
logging.info("Partition type: %s" % dev.get("ID_PART_TABLE_TYPE")) logging.info("Partition type: %s" % dev.get("ID_PART_TABLE_TYPE"))
logging.info("FS type: %s" % dev.get("ID_FS_TYPE")) logging.info("FS type: %s" % dev.get("ID_FS_TYPE"))
logging.info("Partition label: %s" % dev.get("ID_FS_LABEL")) logging.info("Partition label: %s" % dev.get("ID_FS_LABEL"))
# logging.info("FS: %s" % dev.get("ID_FS_SYSTEM_ID"))
logging.info("Device model: %s" % dev.get("ID_MODEL")) logging.info("Device model: %s" % dev.get("ID_MODEL"))
# logging.info('Usage: %s' % dev.get("ID_FS_USAGE"))
logging.info('Model: %s' % dev.get("ID_MODEL_ID")) logging.info('Model: %s' % dev.get("ID_MODEL_ID"))
logging.info('Serial short: %s' % dev.get("ID_SERIAL_SHORT")) logging.info('Serial short: %s' % dev.get("ID_SERIAL_SHORT"))
logging.info('Serial: %s' % dev.get("ID_SERIAL")) logging.info('Serial: %s' % dev.get("ID_SERIAL"))
# logging.info(os.stat(dev.get("DEVNAME")))
# ----------------------------------------------------------- # -----------------------------------------------------------
# pandora # pandora

View file

@ -3,9 +3,12 @@ import os;
def waitMouseClick(): def waitMouseClick():
mouse = open( "/dev/input/mice", "rb" ) mouse = open( "/dev/input/mice", "rb" )
down = False;
while True: while True:
buf = mouse.read(3) buf = mouse.read(3)
if ((buf[0] & 0x1)==1): if ((buf[0] & 0x1)==1):
down = True
if (((buf[0] & 0x1)==0) and down):
break; break;
mouse.close() mouse.close()

View file

@ -3,9 +3,12 @@ import os;
def waitMouseClick(): def waitMouseClick():
mouse = open( "/dev/input/mice", "rb" ) mouse = open( "/dev/input/mice", "rb" )
down = False;
while True: while True:
buf = mouse.read(3) buf = mouse.read(3)
if ((buf[0] & 0x1)==1): if ((buf[0] & 0x1)==1):
down = True
if (((buf[0] & 0x1)==0) and down):
break; break;
mouse.close() mouse.close()