diff --git a/images/CHEM_OK.png b/images/CHEM_OK.png new file mode 100644 index 0000000..568bfdc Binary files /dev/null and b/images/CHEM_OK.png differ diff --git a/images/bad.png b/images/bad.png new file mode 100644 index 0000000..6c1eac6 Binary files /dev/null and b/images/bad.png differ diff --git a/images/computer_OK.png b/images/computer_OK.png new file mode 100644 index 0000000..6b4428f Binary files /dev/null and b/images/computer_OK.png differ diff --git a/images/computer_nok.png b/images/computer_nok.png new file mode 100644 index 0000000..ce3b040 Binary files /dev/null and b/images/computer_nok.png differ diff --git a/images/images.py b/images/images.py deleted file mode 100755 index f40edd2..0000000 --- a/images/images.py +++ /dev/null @@ -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") - - diff --git a/images/key1.png b/images/key1.png new file mode 100644 index 0000000..e98a6b9 Binary files /dev/null and b/images/key1.png differ diff --git a/images/key2.png b/images/key2.png new file mode 100644 index 0000000..eab26f4 Binary files /dev/null and b/images/key2.png differ diff --git a/images/key3.png b/images/key3.png new file mode 100644 index 0000000..cbc2284 Binary files /dev/null and b/images/key3.png differ diff --git a/images/key4.png b/images/key4.png new file mode 100644 index 0000000..98afb7d Binary files /dev/null and b/images/key4.png differ diff --git a/images/key5.png b/images/key5.png new file mode 100644 index 0000000..3665e0f Binary files /dev/null and b/images/key5.png differ diff --git a/images/ok.png b/images/ok.png new file mode 100644 index 0000000..abfe548 Binary files /dev/null and b/images/ok.png differ diff --git a/images/pandora-box1.png b/images/pandora-box1.png deleted file mode 100644 index 58bdd76..0000000 Binary files a/images/pandora-box1.png and /dev/null differ diff --git a/images/pandora-box2.png b/images/pandora-box2.png deleted file mode 100644 index 362f14a..0000000 Binary files a/images/pandora-box2.png and /dev/null differ diff --git a/images/pandora-box3.png b/images/pandora-box3.png deleted file mode 100644 index d4ac454..0000000 Binary files a/images/pandora-box3.png and /dev/null differ diff --git a/images/pandora-box4.png b/images/pandora-box4.png deleted file mode 100644 index a056a92..0000000 Binary files a/images/pandora-box4.png and /dev/null differ diff --git a/images/pandora-box5.png b/images/pandora-box5.png deleted file mode 100644 index 105ce83..0000000 Binary files a/images/pandora-box5.png and /dev/null differ diff --git a/images/wait1.png b/images/wait1.png new file mode 100644 index 0000000..4112515 Binary files /dev/null and b/images/wait1.png differ diff --git a/images/wait2.png b/images/wait2.png new file mode 100644 index 0000000..82f2227 Binary files /dev/null and b/images/wait2.png differ diff --git a/images/wait3.png b/images/wait3.png new file mode 100644 index 0000000..37e68f8 Binary files /dev/null and b/images/wait3.png differ diff --git a/images/wait4.png b/images/wait4.png new file mode 100644 index 0000000..066a991 Binary files /dev/null and b/images/wait4.png differ diff --git a/images/wait5.png b/images/wait5.png new file mode 100644 index 0000000..ce40249 Binary files /dev/null and b/images/wait5.png differ diff --git a/images/wait6.png b/images/wait6.png new file mode 100644 index 0000000..b0cf5bf Binary files /dev/null and b/images/wait6.png differ diff --git a/images/wait7.png b/images/wait7.png new file mode 100644 index 0000000..15feab8 Binary files /dev/null and b/images/wait7.png differ diff --git a/images/wait8.png b/images/wait8.png new file mode 100644 index 0000000..826d37d Binary files /dev/null and b/images/wait8.png differ diff --git a/images/wait9.png b/images/wait9.png new file mode 100644 index 0000000..be42bc9 Binary files /dev/null and b/images/wait9.png differ diff --git a/pandora-box.ini b/pandora-box.ini index 2375f58..4989835 100644 --- a/pandora-box.ini +++ b/pandora-box.ini @@ -10,7 +10,7 @@ USB_AUTO_MOUNT = False PANDORA_ROOT_URL = http://127.0.0.1:6100 ; 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 ; in the USB scanning station diff --git a/pandora-box.py b/pandora-box.py index ed30a03..eed14f0 100755 --- a/pandora-box.py +++ b/pandora-box.py @@ -75,27 +75,37 @@ def human_readable_size(size, decimal_places=1): def display_image(status): if status=="WAIT": - image = "images/pandora-box1.png" + image = "images/key*.png" elif status=="WORK": - image = "images/pandora-box2.png" + image = "images/wait*.png" elif status=="OK": - image = "images/pandora-box3.png" + image = "images/ok.png" elif status=="BAD": - image = "images/pandora-box4.png" + image = "images/bad.png" elif status=="ERROR": - image = "images/pandora-box5.png" + image = "images/error.png" else: return - os.system("killall fim 2>/dev/null") - os.system("fim -qa %s /dev/null &" % image) + # hide old 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 &" % image) + else : + # only one image + os.system("fim -qa %s /dev/null &" % image) # ----------------------------------------------------------- def waitMouseClick(): mouse = open( "/dev/input/mice", "rb" ) + down = False; while True: buf = mouse.read(3) if ((buf[0] & 0x1)==1): + down = True + if (((buf[0] & 0x1)==0) and down): break; mouse.close() @@ -277,22 +287,27 @@ def log(str): """Mount USB device""" def mount_device(device): + log('Try to mount partition') if USB_AUTO_MOUNT: found = False loop = 0 - while (not found) and (loop < 10): + while (not found) and (loop < 15): # need to sleep before devide is mounted time.sleep(1) for partition in psutil.disk_partitions(): if partition.device == device.device_node: - log("Device mounted at {}".format(partition.mountpoint)) + log("Partition mounted at {}".format(partition.mountpoint)) found = True loop += 1 if loop < 10: return partition.mountpoint else: + log('No partition mounted') return None 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") found = False loop = 0 @@ -304,15 +319,13 @@ def mount_device(device): loop +=1 continue break; - log("Device mounted at /media/box") + log("Partition mounted at /media/box") return "/media/box" """Unmount USB device""" def umount_device(): - if not USB_AUTO_MOUNT: - if os.path.exists("/media/box"): - log("Unmounting device /media/box") - res = os.system("pumount /media/box") + log("Sync partitions") + res = os.system("sync") """Main device loop""" def device_loop(): @@ -322,78 +335,79 @@ def device_loop(): context = pyudev.Context() monitor = pyudev.Monitor.from_netlink(context) monitor.filter_by("block") - try: - for device in iter(monitor.poll, None): - if device.get("ID_FS_USAGE") == "filesystem" and device.device_node[5:7] == "sd": - if device.action == "add": - log("Device inserted") - log_device_info(device) + #try: + for device in iter(monitor.poll, None): + if device.get("ID_FS_USAGE") == "filesystem" and device.device_node[5:7] == "sd": + if device.action == "add": + log("Device inserted") + 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: - display_image("WORK") + display_image("BAD") + waitMouseClick() 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) - 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: - 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") + 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("WAIT") - else: - print_fslabel("") - 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.") + display_image("OK") + else: + if not CURSES: + display_image("OK") + umount_device() + + if device.action == "remove": + log("Device removed") + if not CURSES: + display_image("WAIT") + else: + print_fslabel("") + 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): @@ -406,13 +420,10 @@ def log_device_info(dev): logging.info("Partition type: %s" % dev.get("ID_PART_TABLE_TYPE")) logging.info("FS type: %s" % dev.get("ID_FS_TYPE")) 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('Usage: %s' % dev.get("ID_FS_USAGE")) logging.info('Model: %s' % dev.get("ID_MODEL_ID")) logging.info('Serial short: %s' % dev.get("ID_SERIAL_SHORT")) logging.info('Serial: %s' % dev.get("ID_SERIAL")) - # logging.info(os.stat(dev.get("DEVNAME"))) # ----------------------------------------------------------- # pandora diff --git a/tests/loop.py b/tests/loop.py index 0bb9bb9..bd84186 100755 --- a/tests/loop.py +++ b/tests/loop.py @@ -3,9 +3,12 @@ import os; def waitMouseClick(): mouse = open( "/dev/input/mice", "rb" ) + down = False; while True: buf = mouse.read(3) if ((buf[0] & 0x1)==1): + down = True + if (((buf[0] & 0x1)==0) and down): break; mouse.close() diff --git a/tests/slideshow.py b/tests/slideshow.py index 74db8f5..1f507a7 100755 --- a/tests/slideshow.py +++ b/tests/slideshow.py @@ -3,9 +3,12 @@ import os; def waitMouseClick(): mouse = open( "/dev/input/mice", "rb" ) + down = False; while True: buf = mouse.read(3) if ((buf[0] & 0x1)==1): + down = True + if (((buf[0] & 0x1)==0) and down): break; mouse.close()