| 1 | + | import yaml |
| 2 | + | from src import utils |
| 3 | + | from src import OsintgramStatus |
| 4 | + | import sys |
| 5 | + | import signal |
| 6 | + | import argparse |
| 7 | + | from src import printcolors as pc |
| 8 | + | import readline |
| 9 | + | from src.Osintgram import Osintgram |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | def signal_handler(sig, frame): |
| 14 | + | pc.printout("\nGoodbye!\n", pc.RED) |
| 15 | + | sys.exit(0) |
| 16 | + | |
| 17 | + | |
| 18 | + | def completer(text, state): |
| 19 | + | options = [i for i in status.get_commands() if i.startswith(text)] |
| 20 | + | if state < len(options): |
| 21 | + | return options[state] |
| 22 | + | else: |
| 23 | + | return None |
| 24 | + | |
| 25 | + | def _quit(): |
| 26 | + | pc.printout("Goodbye!\n", pc.RED) |
| 27 | + | sys.exit(0) |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | parser = argparse.ArgumentParser(description='Osintgram is a OSINT tool on Instagram. It offers an interactive shell ' |
| 32 | + | 'to perform analysis on Instagram account of any users by its nickname ') |
| 33 | + | parser.add_argument('id', type=str, # var = id |
| 34 | + | help='username') |
| 35 | + | parser.add_argument('-C','--cookies', help='clear\'s previous cookies', action="store_true") |
| 36 | + | parser.add_argument('-j', '--json', help='save commands output as JSON file', action='store_true') |
| 37 | + | parser.add_argument('-f', '--file', help='save output in a file', action='store_true') |
| 38 | + | parser.add_argument('-c', '--command', help='run in single command mode & execute provided command', action='store') |
| 39 | + | parser.add_argument('-o', '--output', help='where to store photos', action='store') |
| 40 | + | |
| 41 | + | args = parser.parse_args() |
| 42 | + | |
| 43 | + | |
| 44 | + | signal.signal(signal.SIGINT, signal_handler) |
| 45 | + | # if is_windows: |
| 46 | + | # pyreadline.Readline().parse_and_bind("tab: complete") |
| 47 | + | # pyreadline.Readline().set_completer(completer) |
| 48 | + | # else: |
| 49 | + | # gnureadline.parse_and_bind("tab: complete") |
| 50 | + | # gnureadline.set_completer(completer) |
| 51 | + | |
| 52 | + | stream = open("src/setup.yaml", 'r') |
| 53 | + | setup = yaml.safe_load(stream) |
| 54 | + | |
| 55 | + | parser = argparse.ArgumentParser(description='Osintgram is a OSINT tool on Instagram. It offers an interactive shell ' |
| 56 | + | 'to perform analysis on Instagram account of any users by its nickname ') |
| 57 | + | parser.add_argument('id', type=str, # var = id |
| 58 | + | help='username') |
| 59 | + | parser.add_argument('-C','--cookies', help='clear\'s previous cookies', action="store_true") |
| 60 | + | parser.add_argument('-j', '--json', help='save commands output as JSON file', action='store_true') |
| 61 | + | parser.add_argument('-f', '--file', help='save output in a file', action='store_true') |
| 62 | + | parser.add_argument('-c', '--command', help='run in single command mode & execute provided command', action='store') |
| 63 | + | parser.add_argument('-o', '--output', help='where to store photos', action='store') |
| 64 | + | |
| 65 | + | args = parser.parse_args() |
| 66 | + | |
| 67 | + | if not args.command: |
| 68 | + | utils.printlogo(setup['version'], setup['author']) |
| 69 | + | |
| 70 | + | status = OsintgramStatus.OsintgramStatus() |
| 71 | + | |
| 72 | + | api = Osintgram(args.id, args.file, args.json, args.command, args.output, args.cookies) |
| 73 | + | |
| 74 | + | |
| 75 | + | status.set_commands(setup['commands']) |
| 76 | + | |
| 77 | + | |
| 78 | + | while True: |
| 79 | + | if args.command: |
| 80 | + | cmd = args.command |
| 81 | + | _cmd = commands.get(args.command) |
| 82 | + | else: |
| 83 | + | signal.signal(signal.SIGINT, signal_handler) |
| 84 | + | |
| 85 | + | completer = utils.Completer(status.get_commands()) |
| 86 | + | readline.set_completer_delims(' \t\n;') |
| 87 | + | readline.set_completer(completer.complete) |
| 88 | + | readline.parse_and_bind('tab: complete') |
| 89 | + | readline.set_completion_display_matches_hook(completer.display_matches) |
| 90 | + | |
| 91 | + | if(status.is_command_mode()): |
| 92 | + | pc.printout(status.get_command() + '> ', pc.GREEN) |
| 93 | + | else: |
| 94 | + | pc.printout("Run a command: ", pc.YELLOW) |
| 95 | + | cmd = input() |
| 96 | + | |
| 97 | + | if cmd in status.get_commands(): |
| 98 | + | _cmd = cmd |
| 99 | + | |
| 100 | + | if status.is_command_mode(): |
| 101 | + | status.set_subcommand(cmd) |
| 102 | + | else: |
| 103 | + | status.set_command(cmd) |
| 104 | + | |
| 105 | + | commands = status.get_commands() |
| 106 | + | else: |
| 107 | + | _cmd = None |
| 108 | + | |
| 109 | + | if _cmd: |
| 110 | + | __import__(status.get_module()) |
| 111 | + | mymodule = sys.modules[status.get_module()] |
| 112 | + | if status.is_subcommand(): |
| 113 | + | command.__getattribute__(_cmd)() |
| 114 | + | else: |
| 115 | + | command = mymodule.Command(status.get_path(), api) |
| 116 | + | |
| 117 | + | elif _cmd == "": |
| 118 | + | print("") |
| 119 | + | else: |
| 120 | + | pc.printout("Unknown command\n", pc.RED) |
| 121 | + | |
| 122 | + | if args.command: |
| 123 | + | break |
| 124 | + | |
| 125 | + | |
| 126 | + | |