mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-30 10:49:40 +02:00
work in progress
This commit is contained in:
parent
6829801ff1
commit
0a995240b7
1 changed files with 136 additions and 98 deletions
|
@ -25,6 +25,7 @@ PANDORA_ROOT_URL = "http://127.0.0.1:6100"
|
||||||
FAKE_SCAN = False
|
FAKE_SCAN = False
|
||||||
QUARANTINE = False
|
QUARANTINE = False
|
||||||
CURSES = True
|
CURSES = True
|
||||||
|
SCREEN_SIZE = None
|
||||||
|
|
||||||
""" read configuration file """
|
""" read configuration file """
|
||||||
def config():
|
def config():
|
||||||
|
@ -43,6 +44,8 @@ def config():
|
||||||
QUARANTINE_FOLDER = config['DEFAULT']['QUARANTINE_FOLDER']
|
QUARANTINE_FOLDER = config['DEFAULT']['QUARANTINE_FOLDER']
|
||||||
# Curses
|
# Curses
|
||||||
CURSES = config['DEFAULT']['CURSES'].lower()=="true"
|
CURSES = config['DEFAULT']['CURSES'].lower()=="true"
|
||||||
|
# Screen size
|
||||||
|
SCREEN_SIZE = config['DEFAULT']['SCREEN_SIZE']
|
||||||
|
|
||||||
# ----------------------------------------------------------
|
# ----------------------------------------------------------
|
||||||
|
|
||||||
|
@ -61,10 +64,16 @@ 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"
|
||||||
elif status=="WORK":
|
elif status=="WORK":
|
||||||
|
image = "pandora-box2.png"
|
||||||
elif status=="OK":
|
elif status=="OK":
|
||||||
|
image = "pandora-box3.png"
|
||||||
elif status=="BAD":
|
elif status=="BAD":
|
||||||
|
image = "pandora-box4.png"
|
||||||
else
|
else
|
||||||
|
return
|
||||||
|
os.system("convert -resize %s -background black -gravity center -extent %s %s bgra:/dev/fb0" % (SCREEN_SIZE, SCREEN_SIZE, image))
|
||||||
|
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
# CURSES Screen
|
# CURSES Screen
|
||||||
|
@ -73,23 +82,27 @@ def display_image(status):
|
||||||
"""Initialise curses"""
|
"""Initialise curses"""
|
||||||
def intit_curses():
|
def intit_curses():
|
||||||
global screen
|
global screen
|
||||||
|
if CURSES:
|
||||||
screen = curses.initscr()
|
screen = curses.initscr()
|
||||||
screen.keypad(1)
|
screen.keypad(1)
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
|
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
|
||||||
curses.flushinp()
|
curses.flushinp()
|
||||||
curses.noecho()
|
curses.noecho()
|
||||||
# screen.clear()
|
else:
|
||||||
|
display_image("WAIT")
|
||||||
|
|
||||||
"""Print FS Label"""
|
"""Print FS Label"""
|
||||||
def print_fslabel(label):
|
def print_fslabel(label):
|
||||||
global status_win
|
global status_win
|
||||||
|
if CURSES:
|
||||||
status_win.addstr(1, 1, "Partition : %-32s" % label, curses.color_pair(2))
|
status_win.addstr(1, 1, "Partition : %-32s" % label, curses.color_pair(2))
|
||||||
status_win.refresh()
|
status_win.refresh()
|
||||||
|
|
||||||
"""Print FS Size"""
|
"""Print FS Size"""
|
||||||
def print_size(label):
|
def print_size(label):
|
||||||
global status_win
|
global status_win
|
||||||
|
if CURSES:
|
||||||
if label == None:
|
if label == None:
|
||||||
status_win.addstr(2, 1, "Size : ",curses.color_pair(2))
|
status_win.addstr(2, 1, "Size : ",curses.color_pair(2))
|
||||||
else:
|
else:
|
||||||
|
@ -100,6 +113,7 @@ def print_size(label):
|
||||||
"""Print FS Used Size"""
|
"""Print FS Used Size"""
|
||||||
def print_used(label):
|
def print_used(label):
|
||||||
global status_win
|
global status_win
|
||||||
|
if CURSES:
|
||||||
if label == None:
|
if label == None:
|
||||||
status_win.addstr(3, 1, "Used : ",curses.color_pair(2))
|
status_win.addstr(3, 1, "Used : ",curses.color_pair(2))
|
||||||
else:
|
else:
|
||||||
|
@ -109,22 +123,26 @@ def print_used(label):
|
||||||
|
|
||||||
def print_fstype(label):
|
def print_fstype(label):
|
||||||
global status_win
|
global status_win
|
||||||
|
if CURSES:
|
||||||
status_win.addstr(1, 50, "Part / Type : %-32s" % label, curses.color_pair(2))
|
status_win.addstr(1, 50, "Part / Type : %-32s" % label, curses.color_pair(2))
|
||||||
status_win.refresh()
|
status_win.refresh()
|
||||||
|
|
||||||
def print_model(label):
|
def print_model(label):
|
||||||
global status_win
|
global status_win
|
||||||
|
if CURSES:
|
||||||
status_win.addstr(2, 50, "Model : %-32s" % label, curses.color_pair(2))
|
status_win.addstr(2, 50, "Model : %-32s" % label, curses.color_pair(2))
|
||||||
status_win.refresh()
|
status_win.refresh()
|
||||||
|
|
||||||
def print_serial(label):
|
def print_serial(label):
|
||||||
global status_win
|
global status_win
|
||||||
|
if CURSES:
|
||||||
status_win.addstr(3, 50, "Serial : %-32s" % label, curses.color_pair(2))
|
status_win.addstr(3, 50, "Serial : %-32s" % label, curses.color_pair(2))
|
||||||
status_win.refresh()
|
status_win.refresh()
|
||||||
|
|
||||||
"""Initialise progress bar"""
|
"""Initialise progress bar"""
|
||||||
def init_bar():
|
def init_bar():
|
||||||
global progress_win
|
global progress_win
|
||||||
|
if CURSES:
|
||||||
progress_win = curses.newwin(3, curses.COLS-12, 17, 5)
|
progress_win = curses.newwin(3, curses.COLS-12, 17, 5)
|
||||||
progress_win.border(0)
|
progress_win.border(0)
|
||||||
progress_win.refresh()
|
progress_win.refresh()
|
||||||
|
@ -132,6 +150,7 @@ def init_bar():
|
||||||
"""Update progress bar"""
|
"""Update progress bar"""
|
||||||
def update_bar(progress):
|
def update_bar(progress):
|
||||||
global progress_win
|
global progress_win
|
||||||
|
if CURSES:
|
||||||
if progress == 0:
|
if progress == 0:
|
||||||
progress_win.clear()
|
progress_win.clear()
|
||||||
progress_win.border(0)
|
progress_win.border(0)
|
||||||
|
@ -161,6 +180,7 @@ s[9] = " ░
|
||||||
"""Print main screen"""
|
"""Print main screen"""
|
||||||
def print_screen():
|
def print_screen():
|
||||||
global status_win
|
global status_win
|
||||||
|
if CURSES:
|
||||||
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
|
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
|
||||||
curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
|
curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
|
||||||
curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
|
curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
|
||||||
|
@ -193,6 +213,7 @@ def print_screen():
|
||||||
|
|
||||||
"""Closes curses"""
|
"""Closes curses"""
|
||||||
def end_curses():
|
def end_curses():
|
||||||
|
if CURSES:
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
curses.flushinp()
|
curses.flushinp()
|
||||||
|
|
||||||
|
@ -202,6 +223,7 @@ def end_curses():
|
||||||
|
|
||||||
def init_log():
|
def init_log():
|
||||||
global log_win, logging
|
global log_win, logging
|
||||||
|
if CURSES:
|
||||||
log_win = curses.newwin(curses.LINES-20, curses.COLS, 20, 0)
|
log_win = curses.newwin(curses.LINES-20, curses.COLS, 20, 0)
|
||||||
log_win.border(0)
|
log_win.border(0)
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
@ -215,6 +237,8 @@ logs = []
|
||||||
def log(str):
|
def log(str):
|
||||||
global log_win, logging
|
global log_win, logging
|
||||||
logging.info(str)
|
logging.info(str)
|
||||||
|
if CURSES:
|
||||||
|
# display log on screen
|
||||||
logs.append(str)
|
logs.append(str)
|
||||||
if len(logs)>(curses.LINES-22):
|
if len(logs)>(curses.LINES-22):
|
||||||
logs.pop(0)
|
logs.pop(0)
|
||||||
|
@ -279,6 +303,9 @@ 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:
|
||||||
|
display_image("WORK")
|
||||||
|
else:
|
||||||
# display device type
|
# display device type
|
||||||
print_fslabel(device.get("ID_FS_LABEL"))
|
print_fslabel(device.get("ID_FS_LABEL"))
|
||||||
print_fstype(device.get("ID_PART_TABLE_TYPE") + " " + device.get("ID_FS_TYPE"))
|
print_fstype(device.get("ID_PART_TABLE_TYPE") + " " + device.get("ID_FS_TYPE"))
|
||||||
|
@ -304,6 +331,9 @@ 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:
|
||||||
|
display_image("BAD")
|
||||||
|
else:
|
||||||
log('PRESS KEY TO CLEAN')
|
log('PRESS KEY TO CLEAN')
|
||||||
screen.getch()
|
screen.getch()
|
||||||
# Remove infected files
|
# Remove infected files
|
||||||
|
@ -314,9 +344,15 @@ def device_loop():
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
log("Unexpected error: %s" % str(e))
|
log("Unexpected error: %s" % str(e))
|
||||||
log("Clean done.")
|
log("Clean done.")
|
||||||
|
else:
|
||||||
|
if !CURSES:
|
||||||
|
display_image("OK")
|
||||||
|
|
||||||
if device.action == "remove":
|
if device.action == "remove":
|
||||||
log("Device removed")
|
log("Device removed")
|
||||||
|
if !CURSES:
|
||||||
|
display_image("WAIT")
|
||||||
|
else:
|
||||||
print_fslabel("")
|
print_fslabel("")
|
||||||
print_size(None)
|
print_size(None)
|
||||||
print_used(None)
|
print_used(None)
|
||||||
|
@ -425,13 +461,15 @@ def main(stdscr):
|
||||||
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()
|
||||||
|
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
wrapper(main)
|
wrapper(main)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue