Example #1
0
 def write_history(ctrl_command):
     if self.last_command != ctrl_command:
         linux("echo '{}' >> '{}'".format(ctrl_command,
                                          self.history_path))
Example #2
0
    def main_background(self):

        self.oldstdin = sys.stdin
        tolow = lambda b: b.lower()

        while True:

            try:

                self.main_loop_heads()
                check_history_exist(self.history_path)

                if not sys.stdin.closed:
                    order_cm = input(self.in_main_prompt).strip()
                else:
                    self.close()

                if self.last_command != order_cm:
                    linux("echo '{}' >> '{}'".format(order_cm,
                                                     self.history_path))
                sys.stdin = self.oldstdin

                # press enter
                if len(order_cm) == 0: continue

                elif tolow(order_cm) == 'help':
                    LoopsHelp.in_main(self)

                elif order_cm.startswith('!'):
                    self.shortcut(order_cm)

                elif tolow(order_cm).startswith('banner'):
                    self.update_banner(order_cm)

                elif tolow(order_cm) == 'clear':
                    clear_screen()

                elif tolow(order_cm) == 'history':
                    echo_history(self.history_path)

                elif tolow(order_cm).startswith('cd'):
                    self.change_dir(order_cm)

                elif tolow(order_cm) == 'pwd':
                    pprint(os.getcwd() + '\n')

                elif tolow(order_cm) == 'config':
                    linux("nano '{}'".format(self.conf_path))
                    self.refresh_all()

                elif tolow(order_cm) == 'python':
                    self.get_python(None)

                elif tolow(order_cm).startswith('listen'):

                    argument = toarg(order_cm)

                    self.parser.listen_method(argument, self.used_ports,
                                              Listen_Class, plog, self.colors)

                elif tolow(order_cm).startswith('generate'):

                    argument = toarg(order_cm)
                    generator = ParatGenerate()

                    self.parser.generate_method(argument, generator,
                                                self.config, self.port, plog,
                                                self.colors)

                elif tolow(order_cm).startswith('setting'):

                    argument = toarg(order_cm)

                    self.parser.setting_method(argument, self.pdb, self.config,
                                               self.conf_path, plog,
                                               self.colors)

                elif tolow(order_cm) == 'version':
                    print_version()

                elif tolow(order_cm) == 'author':
                    show_info()

                elif tolow(order_cm) == 'exit -y':
                    self.do_exit()

                elif tolow(order_cm) == 'exit':

                    if len(self.client) == 0:

                        if self.login.check():
                            for path, folders, files in os.walk(
                                    os.path.abspath('')):
                                [
                                    self.login.encrypt('/'.join([path, f]))
                                    for f in files
                                ]
                        self.do_exit()

                    else:

                        self.exit_with_active_seassion()

                elif tolow(order_cm).startswith('session'):

                    argument = toarg(order_cm)

                    self.parser.sessions_method(argument, self.client,
                                                self.cdisplay,
                                                self.cli_counter, ClientShell,
                                                self.ROOT, prompt_q,
                                                self.in_main_prompt, plog,
                                                self.colors)

                elif tolow(order_cm) == 'off':
                    linux("shutdown -h now")

                else:
                    linux(order_cm)

                self.last_command = order_cm

            except ValueError as e:

                show_trace(self.verbose)
                plog.info(str(e))  #; break
                sleep(0.1)
                self.close()

            except EOFError as e:
                plog.info(str(e))  #; break
                sleep(0.1)

            except Exception as e:

                # except unknown errors
                show_trace(self.verbose)
                plog.error(str(e))
                pprint(
                    colorize(str(e) + '\n', colored=self.colors, status="ERR"),
                    1)
                sleep(0.1)

            except KeyboardInterrupt:
                pprint('\n')