1
0
Fork 0
mirror of https://github.com/dbarzin/pandora-box.git synced 2025-07-19 13:29:42 +02:00

work in progress

This commit is contained in:
Didier 2022-06-28 19:42:16 +00:00
parent 27ac29e900
commit 650bfbc5b5
2 changed files with 31 additions and 29 deletions

View file

@ -1,12 +1,12 @@
[DEFAULT] [DEFAULT]
; Curses mode (full text) ; Curses mode (full text)
CURSES = False CURSES = False
; Screen size (graphic mode) ; Screen size (graphic mode)
SCREEN_SIZE = "1020x600" SCREEN_SIZE = "1024x600"
; Set USB_AUTO_MOUNT to true is if the OS mount automaticaly mount USB keys ; Set USB_AUTO_MOUNT to true is if the OS mount automaticaly mount USB keys
USB_AUTO_MOUNT = True USB_AUTO_MOUNT = False
; Set PANDORA_ROOT_URL to the URL of the Pandora server ; Set PANDORA_ROOT_URL to the URL of the Pandora server
; the default value is "http://127.0.0.1:6100" ; the default value is "http://127.0.0.1:6100"

View file

@ -31,10 +31,11 @@ SCREEN_SIZE = None
def config(): def config():
global USB_AUTO_MOUNT, PANDORA_ROOT_URL global USB_AUTO_MOUNT, PANDORA_ROOT_URL
global FAKE_SCAN, QUARANTINE, QUARANTINE_FOLDER global FAKE_SCAN, QUARANTINE, QUARANTINE_FOLDER
global CURSES, SCREEN_SIZE
# intantiate a ConfirParser # intantiate a ConfirParser
config = configparser.ConfigParser() config = configparser.ConfigParser()
# read the config file # read the config file
config.read('pandorabox.ini') config.read('pandora-box.ini')
# set values # set values
FAKE_SCAN=config['DEFAULT']['FAKE_SCAN'].lower()=="true" FAKE_SCAN=config['DEFAULT']['FAKE_SCAN'].lower()=="true"
USB_AUTO_MOUNT=config['DEFAULT']['USB_AUTO_MOUNT'].lower()=="true" USB_AUTO_MOUNT=config['DEFAULT']['USB_AUTO_MOUNT'].lower()=="true"
@ -64,14 +65,14 @@ def human_readable_size(size, decimal_places=1):
def display_image(status): def display_image(status):
if status=="WAIT": if status=="WAIT":
image = "pandora-box1.png" image = "images/pandora-box1.png"
elif status=="WORK": elif status=="WORK":
image = "pandora-box2.png" image = "images/pandora-box2.png"
elif status=="OK": elif status=="OK":
image = "pandora-box3.png" image = "images/pandora-box3.png"
elif status=="BAD": elif status=="BAD":
image = "pandora-box4.png" image = "images/pandora-box4.png"
else else:
return return
os.system("convert -resize %s -background black -gravity center -extent %s %s bgra:/dev/fb0" % (SCREEN_SIZE, SCREEN_SIZE, image)) os.system("convert -resize %s -background black -gravity center -extent %s %s bgra:/dev/fb0" % (SCREEN_SIZE, SCREEN_SIZE, image))
@ -80,16 +81,17 @@ def display_image(status):
# ----------------------------------------------------------- # -----------------------------------------------------------
"""Initialise curses""" """Initialise curses"""
def intit_curses(): def init_curses():
global screen global screen
screen = curses.initscr()
screen.keypad(1)
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
curses.flushinp()
curses.noecho()
if CURSES: if CURSES:
screen = curses.initscr() # remove blinking cursor
screen.keypad(1)
curses.curs_set(0) curses.curs_set(0)
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION) else:
curses.flushinp()
curses.noecho()
else:
display_image("WAIT") display_image("WAIT")
"""Print FS Label""" """Print FS Label"""
@ -213,9 +215,8 @@ def print_screen():
"""Closes curses""" """Closes curses"""
def end_curses(): def end_curses():
if CURSES: curses.endwin()
curses.endwin() curses.flushinp()
curses.flushinp()
# ----------------------------------------------------------- # -----------------------------------------------------------
# Logging windows # Logging windows
@ -303,7 +304,7 @@ def device_loop():
if device.action == "add": if device.action == "add":
log("Device inserted") log("Device inserted")
log_device_info(device) log_device_info(device)
if !CURSES: if not CURSES:
display_image("WORK") display_image("WORK")
else: else:
# display device type # display device type
@ -331,7 +332,7 @@ def device_loop():
# Clean files # Clean files
if len(infected_files) > 0: if len(infected_files) > 0:
log('%d infected files found !' % len(infected_files)) log('%d infected files found !' % len(infected_files))
if !CURSES: if not CURSES:
display_image("BAD") display_image("BAD")
else: else:
log('PRESS KEY TO CLEAN') log('PRESS KEY TO CLEAN')
@ -343,14 +344,18 @@ def device_loop():
log('%s removed' % file) log('%s removed' % file)
except Exception as e : except Exception as e :
log("Unexpected error: %s" % str(e)) log("Unexpected error: %s" % str(e))
os.system("sync")
log("Clean done.") log("Clean done.")
if not CURSES:
display_image("OK")
else: else:
if !CURSES: if not CURSES:
display_image("OK") display_image("OK")
if device.action == "remove": if device.action == "remove":
log("Device removed") log("Device removed")
if !CURSES: umount_device()
if not CURSES:
display_image("WAIT") display_image("WAIT")
else: else:
print_fslabel("") print_fslabel("")
@ -359,7 +364,6 @@ def device_loop():
print_fstype("") print_fstype("")
print_model("") print_model("")
print_serial("") print_serial("")
umount_device()
update_bar(0) update_bar(0)
except Exception as e: except Exception as e:
log("Unexpected error: %s" % str(e) ) log("Unexpected error: %s" % str(e) )
@ -456,17 +460,15 @@ def main(stdscr):
try : try :
init_log() init_log()
config() config()
intit_curses() init_curses()
print_screen() print_screen()
while True: while True:
device_loop() device_loop()
except Exception as e : except Exception as e :
if CURSES: end_curses()
end_curses()
print("Unexpected error: ", e) print("Unexpected error: ", e)
finally: finally:
if CURSES: end_curses()
end_curses()
# -------------------------------------- # --------------------------------------