示例#1
0
def setRelationshipSSH():

    if request.vars['type']=="testFields":
        if request.vars['passhost'].strip()=="":
            return dict(response="passhost")
        else:
            return dict(response="OK")

    try:
        WS.websocket_send('http://*****:*****@'+request.vars['host'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    try:
        HTML_PARSER = ansi2html()
        html = HTML_PARSER.parse(p.communicate()[0])
        WS.websocket_send('http://*****:*****@192.168.0.1 \"if ! grep -Fxq '"+idRsaPub+"' /tmp/root/.ssh/authorized_keys > /dev/null ; then echo '"+idRsaPub+"' >> /tmp/root/.ssh/authorized_keys; fi\"")

        p = subprocess.Popen('sshpass -p '+request.vars['passhost']+' ssh -A -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i '+dir_ssh+'/.ssh/id_rsa root@'+request.vars["host"]+' sshpass -p '+request.vars['passrouter']+' ssh-copy-id -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/controlIES_rsa.pub [email protected]', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        try:
            HTML_PARSER = ansi2html()
            html = HTML_PARSER.parse(p.communicate()[0])
            WS.websocket_send('http://*****:*****@'+request.vars["host"]+' sshpass -p '+request.vars['passrouter']+' ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no [email protected] "nvram set sshd_authorized_keys=\''+idRsaPub.replace(" ","\\ ")+'\' nvram commit"', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

        c.removeFile("/root/.ssh/controlIES_rsa.pub")
        c.removeFile("/root/.ssh/controlIES_rsa")

        c.close()
    return dict(response = "OK")

    """c = SSHConnection(request.vars['host'],"root","")
示例#2
0
def executeCommand():
    """try:
        server = xmlrpclib.ServerProxy("http://"+request.vars["host"]+":6800")
        s = server.exec_command(request.vars["command"])
        return dict(response="OK", host=request.vars["host"], message=s)
    except:
        return dict(response="fail", host=request.vars["host"], message="Surgió un error")"""

    c = SSHConnection(request.vars["host"], "root", "")
    response = c.connectWithoutPass(
        "/var/web2py/applications/controlies/.ssh/id_rsa")
    #response = c.connectWithoutPass("/home/manu/proyectos/controlies/applications/controlies/.ssh/id_rsa")

    try:
        WS.websocket_send(
            'http://ldap:8888', '<span style="font-size:14pt;">' +
            request.vars["host"] + '</span> > <span style="font-size:10pt;">' +
            request.vars["command"] + '</span><br>', 'mykey', 'mygroup')
    except:
        return dict(
            response="fail",
            host=request.vars["host"],
            message="No se pudo conectar con el servidor websocket.<br/>")

    if response != True:
        return dict(
            response="fail",
            host=request.vars["host"],
            message=
            "No se pudo conectar. ¿Está encendido el equipo? ¿Has establecido la relación de confianza?<br/>"
        )

    channel = c.exec_command(request.vars["command"])

    import select
    while True:
        if channel.exit_status_ready():
            break
        rl, wl, xl = select.select([channel], [], [], 0.0)
        if len(rl) > 0:
            HTML_PARSER = ansi2html()
            html = HTML_PARSER.parse(channel.recv(1024))
            try:
                WS.websocket_send('http://ldap:8888', html, 'mykey', 'mygroup')
            except:
                pass

    WS.websocket_send('http://ldap:8888', '<br>', 'mykey', 'mygroup')
    channel.close()
    c.close()
    return dict(response="OK", host=request.vars["host"], message="")
示例#3
0
def getChannel(channel, name):
    while True:
        if channel.exit_status_ready():
            break
        rl, wl, xl = select.select([channel], [], [], 0.0)
        if len(rl) > 0:
            HTML_PARSER = ansi2html()
            html = HTML_PARSER.parse(channel.recv(1024))
            try:
                if html=="":
                    html="<br/>"
                WS.websocket_send('http://ldap:8888',name+": "+html,'mykey','mygroup')
            except:
                pass
示例#4
0
def getChannel(channel, name):
    while True:
        if channel.exit_status_ready():
            break
        rl, wl, xl = select.select([channel], [], [], 0.0)
        if len(rl) > 0:
            HTML_PARSER = ansi2html()
            html = HTML_PARSER.parse(channel.recv(1024))
            try:
                if html == "":
                    html = "<br/>"
                WS.websocket_send('http://ldap:8888', name + ": " + html,
                                  'mykey', 'mygroup')
            except:
                pass
示例#5
0
def executeCommand():
    """try:
        server = xmlrpclib.ServerProxy("http://"+request.vars["host"]+":6800")
        s = server.exec_command(request.vars["command"])
        return dict(response="OK", host=request.vars["host"], message=s)
    except:
        return dict(response="fail", host=request.vars["host"], message="Surgió un error")"""        

    c = SSHConnection(request.vars["host"],"root","")
    response = c.connectWithoutPass("/var/web2py/applications/controlies/.ssh/id_rsa")
    #response = c.connectWithoutPass("/home/manu/proyectos/controlies/applications/controlies/.ssh/id_rsa")

    try:
        WS.websocket_send('http://ldap:8888','<span style="font-size:14pt;">'+request.vars["host"]+'</span> > <span style="font-size:10pt;">'+request.vars["command"]+'</span><br>','mykey','mygroup')
    except:
        return dict(response="fail", host=request.vars["host"], message="No se pudo conectar con el servidor websocket.<br/>")
            
    if response != True:
        return dict(response="fail", host=request.vars["host"], message="No se pudo conectar. ¿Está encendido el equipo? ¿Has establecido la relación de confianza?<br/>")
    
    channel = c.exec_command(request.vars["command"])
    
    import select
    while True:
        if channel.exit_status_ready():
            break
        rl, wl, xl = select.select([channel], [], [], 0.0)
        if len(rl) > 0:
            HTML_PARSER = ansi2html()
            html = HTML_PARSER.parse(channel.recv(1024))
            try:        
                WS.websocket_send('http://ldap:8888',html,'mykey','mygroup')
            except:
                pass

    WS.websocket_send('http://ldap:8888','<br>','mykey','mygroup')
    channel.close()
    c.close()
    return dict(response="OK", host=request.vars["host"], message="")
示例#6
0
def setRelationshipSSH():

    if request.vars['type'] == "testFields":
        if request.vars['passhost'].strip() == "":
            return dict(response="passhost")
        else:
            return dict(response="OK")

    try:
        WS.websocket_send(
            'http://*****:*****@' + request.vars['host'],
        shell=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT)
    try:
        HTML_PARSER = ansi2html()
        html = HTML_PARSER.parse(p.communicate()[0])
        WS.websocket_send('http://*****:*****@192.168.0.1 \"if ! grep -Fxq '"+idRsaPub+"' /tmp/root/.ssh/authorized_keys > /dev/null ; then echo '"+idRsaPub+"' >> /tmp/root/.ssh/authorized_keys; fi\"")

        p = subprocess.Popen(
            'sshpass -p ' + request.vars['passhost'] +
            ' ssh -A -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i '
            + dir_ssh + '/.ssh/id_rsa root@' + request.vars["host"] +
            ' sshpass -p ' + request.vars['passrouter'] +
            ' ssh-copy-id -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/controlIES_rsa.pub [email protected]',
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT)
        try:
            HTML_PARSER = ansi2html()
            html = HTML_PARSER.parse(p.communicate()[0])
            WS.websocket_send(
                'http://*****:*****@' + request.vars["host"] +
            ' sshpass -p ' + request.vars['passrouter'] +
            ' ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no [email protected] "nvram set sshd_authorized_keys=\''
            + idRsaPub.replace(" ", "\\ ") + '\' nvram commit"',
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT)

        c.removeFile("/root/.ssh/controlIES_rsa.pub")
        c.removeFile("/root/.ssh/controlIES_rsa")

        c.close()
    return dict(response="OK")
    """c = SSHConnection(request.vars['host'],"root","")