Ejemplo n.º 1
0
def get_result():
    try:
        data = request.get_json(True)
        address = data['host']
        account = Account(name=data['user'], password=data['passwd'])

        if data['conntype'] == 'SSH':
            from Exscript.protocols import SSH2
            conn = SSH2()
        elif data['conntype'] == 'Telnet':
            from Exscript.protocols import Telnet
            conn = Telnet()
        else:
            raise (Exception('Unsupport connection type'))
        conn.connect(address)
        conn.login(account)
        conn.execute(data['command'])

        response = to_plain(str(conn.response))

        conn.send('exit\n')
        conn.close()
        return jsonify(success=True, response=response)
    except Exception as e:
        return jsonify(
            success=False,
            response="Opus! Some guy poisoned my coffee last night!")
Ejemplo n.º 2
0
def get_result():
    try:
        data = request.get_json(True)
        address = data['host']
        account = Account(name=data['user'], password=data['passwd'])

        if data['conntype'] == 'SSH':
            from Exscript.protocols import SSH2
            conn = SSH2()
        elif data['conntype'] == 'Telnet':
            from Exscript.protocols import Telnet
            conn = Telnet()
        else:
            raise(Exception('Unsupport connection type'))
        conn.connect(address)
        conn.login(account)
        conn.execute(data['command'])

        response = to_plain(str(conn.response))

        conn.send('exit\n')
        conn.close()
        return jsonify(success=True, response=response)
    except Exception as e:
        return jsonify(success=False, response="Opus! Some guy poisoned my coffee last night!")
Ejemplo n.º 3
0
    def execcmd(self, cmd):

        self.child.sendline(cmd)
        self.child.expect(self.prompt)
        (command, output) = self._split_output(ansiconv.to_plain(self.child.before))
        self.mylogger("Command : {}".format(command))
        self.mylogger(output)
        return output
Ejemplo n.º 4
0
    def lastlog(self, lines=20, format='', html=True):
        handler = self._loghandler
        if format:
            formatter = ColoredFormatter(format, datefmt=self.time_format)
        else:
            formatter = ColoredFormatter(
                self.html_format if html else self.format,
                datefmt=self.time_format)

        rv = u'\n'.join([formatter.format(i) for i in handler.buffer[-lines:]])

        if html:
            rv = ansiconv.to_html(self.html_fix(rv))
        else:
            rv = ansiconv.to_plain(rv)
        return rv
 def convert_plain(s):
     return ansiconv.to_plain(s)
Ejemplo n.º 6
0
 def convert_plain(s):
     "local function"
     return ansiconv.to_plain(s)
 def convert_plain(s):
     return ansiconv.to_plain(s)
Ejemplo n.º 8
0
def test_basic_to_plain():
    expected = 'Foo'
    actual = ansiconv.to_plain('\033[0;32mFoo')
    assert actual == expected