Exemplo n.º 1
0
def execute_interactive():
    """ Runs the command mode once, reading the standard input for a command
    and executing it. Will return execution once a command has been executed
    or if an invalid command was passed.
    """
    old_completer = readline.get_completer()
    readline.set_completer(__readline_completer)
    readline.parse_and_bind('tab: complete')

    term.enter_buffer()
    # default raw mode is not readline friendly.
    # restore after saving display, for restoring is destructive
    term.restore_tty()

    try:
        cmd_name = raw_input('REACH:')
    except:
        # return to raw_mode
        term.set_raw()
        readline.set_completer(old_completer)
        term.leave_buffer()
        return

    cmd_args = [x for x in cmd_name.split(' ') if x != '']
    if cmd_args and cmd_args[0] in registry:
        try:
            registry[cmd_args[0]][1](cmd_args)
        except Exception, e:
            print(e)
            term.pause()
Exemplo n.º 2
0
Arquivo: x11.py Projeto: simpoir/reach
def x11_cmd(*args):
    global forwarded_port
    if forwarded_port:
        print('x11 already bound to "localhost:%d"'%forwarded_port)
        term.pause()
        return


    t = Channel.get_instance().get_transport()
    # Find usable port
    for x_port in xrange(10, 30):
        try:
            t.request_port_forward('localhost', 6000+x_port, x11_handler)
            Channel.get_instance().get_interactive_chan().send(
                'export DISPLAY=localhost:%d\n'%x_port)
            forwarded_port = x_port
            try:
                # setup xauth cookie
                # Some server may use the shared cookie authentication method.
                # Though we aren't using unix sockets, xlib apps
                # translate localhost to hostname/unix when it comes to
                # checking XAuthority files.
                cookie = commands.getoutput('xauth list %s' \
                                            % os.environ.get('DISPLAY'))
                h, p, c = [x for x in cookie.splitlines()[0].split(' ') if x]
                Channel.get_instance().get_interactive_chan().send(
                    'xauth add `hostname`/unix:%d %s %s\n' \
                    %(x_port, p, c))
            except:pass
            return
        except:
            continue
    print('Could not successfully forward any x11 port.')
    term.pause()
Exemplo n.º 3
0
 def chain_connect(self, chain):
     conn = sshconnector.SshConnector()
     for link in chain:
         conn.connect(link, self)
     from reach import commands
     for autocmd in link.get('auto', []):
         cmd_args = [x for x in autocmd.split(' ') if x != '']
         if cmd_args and cmd_args[0] in commands.registry:
             try:
                 commands.registry[cmd_args[0]][1](cmd_args)
             except Exception, e:
                 print(e)
                 term.pause()
Exemplo n.º 4
0
        # return to raw_mode
        term.set_raw()
        readline.set_completer(old_completer)
        term.leave_buffer()
        return

    cmd_args = [x for x in cmd_name.split(' ') if x != '']
    if cmd_args and cmd_args[0] in registry:
        try:
            registry[cmd_args[0]][1](cmd_args)
        except Exception, e:
            print(e)
            term.pause()
    else:
        print('No such command')
        term.pause()

    # return to raw_mode
    term.set_raw()
    readline.set_completer(old_completer)
    term.leave_buffer()


def is_ninja():
    """ This function serves no purpose. The ninja is a lie. """
    pass


def __readline_completer(text, state):
    """ Callback for completing using readline.
    """