67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from simple_term_menu import TerminalMenu
|
|
from database import Database
|
|
from scrapper import get_files, get_uri
|
|
|
|
url = ""
|
|
|
|
def add_site(database: Database) -> dict:
|
|
print("add a site:")
|
|
site = {}
|
|
site.update({"url": input("url without protocol (ip:port):")})
|
|
site.update({"user": input("user(leave blank):")})
|
|
site.update({"password": input("password(leave blank):")})
|
|
site.update({"id": str(database.get_sites_table_len())})
|
|
name = input(f"name[{str(len(sites_table.all()))}] :")
|
|
if (name == ""):
|
|
name = str(database.get_sites_table_len())
|
|
site.update({"name": name})
|
|
return (site)
|
|
|
|
def files_preview(filename: str) -> str:
|
|
if (not filename.endswith("/")):
|
|
return (None)
|
|
files = get_files(url + filename)
|
|
return ("\n".join(files))
|
|
|
|
def files(base_url:str):
|
|
global url
|
|
|
|
url = base_url
|
|
files = get_files(base_url)
|
|
terminal_menu = TerminalMenu(files,
|
|
preview_command=files_preview,
|
|
preview_size=0.3,
|
|
show_search_hint=True,
|
|
title=f"Index of {get_uri(url)}")
|
|
choose = terminal_menu.show()
|
|
return (files[choose])
|
|
|
|
def config_preview(site_name:str):
|
|
id = int(site_name.split(": ")[0])
|
|
site = database.get_site_by_id(id)
|
|
str = f"""
|
|
url: {site.get('url')}
|
|
user: {site.get('user')}
|
|
password: {site.get('password')}
|
|
"""
|
|
return (str)
|
|
|
|
def site_deleter(sites: list):
|
|
terminal_menu = TerminalMenu(sites,
|
|
show_search_hint=True,
|
|
preview_title="delete",
|
|
preview_command=config_preview)
|
|
choose = terminal_menu.show()
|
|
return (choose)
|
|
|
|
def site_editor(lst: list):
|
|
terminal_menu = TerminalMenu(lst + ["", "quit"],
|
|
skip_empty_entries=True,
|
|
show_search_hint=True,
|
|
preview_title="Edit",
|
|
preview_command=config_preview)
|
|
choose = terminal_menu.show()
|
|
if (choose == len(lst) + 1):
|
|
return (None)
|
|
return (choose)
|