def agreement(): while not config.getboolean("fsociety", "agreement"): clear_screen() console.print(TERMS, style="bold yellow") agree = input("You must agree to our terms and conditions first (Y/n) ") if agree.lower()[0] == "y": config.set("fsociety", "agreement", "true")
def run(self): hosts = get_hosts() set_readline(hosts) user_host = input("\nEnter a host: ").strip() if user_host not in hosts: add_host(user_host) ip = gethostbyname(user_host) console.print(f"\n{user_host} has the IP of {ip}")
def interactive(): try: while True: set_readline(commands) mainloop() except KeyboardInterrupt: console.print("\nExitting...") write_config(config) exit(0)
def print_pip_deps(packages): requirements = list() if isinstance(packages, str) and os.path.exists(packages): with open(packages, "r") as requirements_file: for line in requirements_file: if line.strip(): requirements.append(line) elif isinstance(packages, Iterable): requirements = packages else: raise ValueError table = Table("Packages", title="Pip Dependencies") for req in requirements: table.add_row(req) console.print() console.print(table)
def print_menu_items(): cols = list() for value in MENU_ITEMS: name = module_name(value) tools = format_tools(value.__tools__) tools_str = Text() tools_str.append("\n") tools_str.append(name, style="command") tools_str.append(tools) cols.append(tools_str) console.print(Columns(cols, equal=True, expand=True)) for key in BUILTIN_FUNCTIONS: print() console.print(key, style="command")
def info(): data = dict() # Config File with open(CONFIG_FILE) as file: data["Config File"] = file.read().strip() data["Python Version"] = platform.python_version() data["Platform"] = platform.platform() os = config.get("fsociety", "os") if os == "macos": data["macOS"] = platform.mac_ver()[0] elif os == "windows": data["Windows"] = platform.win32_ver()[0] for key, value in data.items(): console.print(f"# {key}") console.print(value, end="\n\n")
def run(self): console.print(""" 8888b. 888888 Yb dP .dP"Y8 8I Yb 88__ Yb dP `Ybo." 8I dY 88"" YbdP o.`Y8b 8888Y" 888888 YP 8bodP' """, style="bold yellow", highlight=False) response = get( f"https://api.github.com/repos/{GITHUB_PATH}/contributors") contributors = response.json() for contributor in sorted(contributors, key=lambda c: c['contributions'], reverse=True): username = contributor.get("login") console.print(f" {username} ".center(30, "-"))
def tools_cli(name, tools, links=True): table = Table(box=box.HEAVY_HEAD) table.add_column("Name", style="red", no_wrap=True) table.add_column("Description", style="magenta") if links: table.add_column("Link", no_wrap=True) tools_dict = dict() for tool in tools: tools_dict[str(tool)] = tool args = [str(tool), tool.description] if links: text_link = Text(f"{tool.path}") text_link.stylize_all( Style(link=f"https://github.com/{tool.path}")) args.append(text_link) table.add_row(*args) console.print(table) console.print("back", style="command") set_readline(list(tools_dict.keys()) + BACK_COMMANDS) selected_tool = input(prompt(name.split(".")[-2])).strip() if not selected_tool in tools_dict.keys(): if selected_tool in BACK_COMMANDS: return console.print("Invalid Command", style="bold yellow") return tools_cli(name, tools, links) tool = tools_dict.get(selected_tool) if hasattr(tool, "install") and not tool.installed(): tool.install() try: response = tool.run() if response and response > 0 and response != 256: console.print(f"{selected_tool} returned a non-zero exit code", style="bold red") if hasattr(tool, "install") and confirm("Do you want to reinstall?"): os.chdir(INSTALL_DIR) shutil.rmtree(tool.full_path) tool.install() except KeyboardInterrupt: return return input_wait()
def mainloop(): agreement() console.print(choice(BANNERS), style="red", highlight=False) print_menu_items() selected_command = input(prompt()).strip() if not selected_command or (selected_command not in commands): console.print("Invalid Command", style="bold yellow") return if selected_command in BUILTIN_FUNCTIONS.keys(): func = BUILTIN_FUNCTIONS.get(selected_command) return func() try: func = items[selected_command].cli return func() except Exception as error: console.print(str(error)) console.print_exception() return
def run(self): console.print("Enter `exit` to return to fsociety") shell = os.getenv("SHELL", "/bin/bash") os.chdir(INSTALL_DIR) os.system(shell)
def run(self): user_base64 = input("\nEnter base64: ").strip() text = b64decode(user_base64) console.print(f"\nDecoded that is: {text}")