Beispiel #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","")
Beispiel #2
0
def servidores_aula():
    if not auth.user: redirect(URL(c='default',f='index'))

    l=conecta()
    t = Thinclients(l,"","","","")
    computers1 = t.getAllComputersNode("group1")    
    computers2 = t.getAllComputersNode("group2")
    computers3 = t.getAllComputersNode("group3")
    computers4 = t.getAllComputersNode("group4")
    
    all = computers1["computers"]+computers2["computers"]+computers3["computers"]+computers4["computers"]
    for c in all:
        t2 = Thinclients(l,c,"","","")
        response = t2.move(c)
    
    l.close()

    c = SSHConnection("localhost","root","")
    response = c.connectWithoutPass("/var/web2py/applications/controlies/.ssh/id_rsa")
    if response != True:
        return dict()

    c.exec_command("if ! pgrep ssh-agent ; then eval $(ssh-agent -s); fi")
    #c.exec_command("ssh-add /var/web2py/applications/controlies/.ssh/id_rsa")
    c.close()
    return dict()
Beispiel #3
0
def servidores_aula():
    if not auth.user: redirect(URL(c='default', f='index'))

    l = conecta()
    t = Thinclients(l, "", "", "", "")
    computers1 = t.getAllComputersNode("group1")
    computers2 = t.getAllComputersNode("group2")
    computers3 = t.getAllComputersNode("group3")
    computers4 = t.getAllComputersNode("group4")

    all = computers1["computers"] + computers2["computers"] + computers3[
        "computers"] + computers4["computers"]
    for c in all:
        t2 = Thinclients(l, c, "", "", "")
        response = t2.move(c)

    l.close()

    c = SSHConnection("localhost", "root", "")
    response = c.connectWithoutPass(
        "/var/web2py/applications/controlies/.ssh/id_rsa")
    if response != True:
        return dict()

    c.exec_command("if ! pgrep ssh-agent ; then eval $(ssh-agent -s); fi")
    #c.exec_command("ssh-add /var/web2py/applications/controlies/.ssh/id_rsa")
    c.close()
    return dict()
Beispiel #4
0
def create_home_directory_withoutpass():
    from applications.controlies.modules.SSHConnection import SSHConnection

    c = SSHConnection("servidor","root","")
    response = c.connectWithoutPass("/var/web2py/applications/controlies/.ssh/id_rsa")

    if response != True:
		return dict(response = response)
		
    l=conecta()
    u = Users(l,"","","","",request.vars['username'],"","","","")
    responseUser = u.getUserData()
    l.close()

    homeDirectory = Utils.homeDirectory(request.vars['type'])+responseUser["user"]
			
    c.exec_command("cp -r /etc/skel "+homeDirectory)
    c.exec_command("chown -R "+responseUser["uidnumber"]+":"+responseUser["gidnumber"]+" "+homeDirectory)
    c.close()

    return dict(response = "OK")
Beispiel #5
0
def create_home_directory():
    from applications.controlies.modules.SSHConnection import SSHConnection

    #c = SSHConnection(request.vars['host'],request.vars['user'],request.vars['password'])
    c = SSHConnection("servidor","root",request.vars['password'])
    response = c.process()
    print request.vars
    if response != True:
		return dict(response = response)

    l=conecta()
    u = Users(l,"","","","",request.vars['username'],"","","","")
    responseUser = u.getUserData()
    l.close()

    homeDirectory = Utils.homeDirectory(request.vars['type'])+responseUser["user"]
			
    c.exec_command("cp -r /etc/skel "+homeDirectory)
    c.exec_command("chown -R "+responseUser["uidnumber"]+":"+responseUser["gidnumber"]+" "+homeDirectory)

    try:
		if request.vars["trustRelationship"] == "on":
			dir_ssh = "/var/web2py/applications/controlies"
			Utils.generateRSAkeys(dir_ssh)
			c.open_ftp()
			c.removeFile("/tmp/controlIES_rsa.pub")
			c.putFile(dir_ssh+"/.ssh/id_rsa.pub","/tmp/controlIES_rsa.pub")
			c.exec_command('cat /tmp/controlIES_rsa.pub >> /root/.ssh/authorized_keys')
			c.close_ftp()
    except:
		pass

    c.close()    
    return dict(response = "OK")       
Beispiel #6
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="")
Beispiel #7
0
def create_home_directory():
    # c = SSHConnection(request.vars['host'],request.vars['user'],request.vars['password'])
    c = SSHConnection("servidor", "root", request.vars["password"])
    response = c.process()

    if response != True:
        return dict(response=response)

    make_directory(request.vars["username"], request.vars["type"], c)

    try:
        if request.vars["trustRelationship"] == "on":
            dir_ssh = "/var/web2py/applications/controlies"
            Utils.generateRSAkeys(dir_ssh)
            c.open_ftp()
            c.removeFile("/tmp/controlIES_rsa.pub")
            c.putFile(dir_ssh + "/.ssh/id_rsa.pub", "/tmp/controlIES_rsa.pub")
            c.exec_command("cat /tmp/controlIES_rsa.pub >> /root/.ssh/authorized_keys")
            c.close_ftp()
    except:
        pass

    c.close()
    return dict(response="OK")
Beispiel #8
0
def create_home_directory():
    #c = SSHConnection(request.vars['host'],request.vars['user'],request.vars['password'])
    c = SSHConnection("servidor","root",request.vars['password'])
    response = c.process()

    if response != True:
        return dict(response = response)

    make_directory(request.vars['username'],request.vars['type'], c)

    try:
        if request.vars["trustRelationship"] == "on":
            dir_ssh = "/var/web2py/applications/controlies"
            Utils.generateRSAkeys(dir_ssh)
            c.open_ftp()
            c.removeFile("/tmp/controlIES_rsa.pub")
            c.putFile(dir_ssh+"/.ssh/id_rsa.pub","/tmp/controlIES_rsa.pub")
            c.exec_command('cat /tmp/controlIES_rsa.pub >> /root/.ssh/authorized_keys')
            c.close_ftp()
    except:
        pass

    c.close()    
    return dict(response = "OK")       
Beispiel #9
0
def executeCommandLaptop():
    try:
        server = xmlrpclib.ServerProxy("http://ldap:6969")
        data = server.get_data_laptops(request.vars["host"])
    except:
        pass

    try:
        proxy = data[0]["proxy"]
        ip = data[0]["ip"]
    except:
        WS.websocket_send('http://ldap:8888','<span style="font-size:14pt;">'+request.vars["host"]+'</span><br>No se pudieron obtener los datos de conexión del equipo, ¿está encendido?','mykey','mygroup')
        return dict()

    c = SSHConnection(proxy,"root","")
    response = c.connectWithoutPass("/var/web2py/applications/controlies/.ssh/id_rsa")

    if response != True:
        WS.websocket_send('http://ldap:8888','<span style="font-size:14pt;">'+request.vars["host"]+'</span><br>No se pudo conectar con el servidor de aula. ¿Has establecido la relación de confianza?','mykey','mygroup')
        return dict()

    channel = c.exec_command('/usr/bin/python /usr/share/controlies-ltspserver/remoteCommand.py '+ip+' "'+request.vars["command"]+'" '+request.vars["host"])

    import select
    import time

    while True:
	#time.sleep(0.3)

        if channel.exit_status_ready():
            break

        rl, wl, xl = select.select([channel], [], [], 0.0)
        if len(rl) > 0:
            if channel.recv(1024).rstrip().strip()=="no_ssh":
                WS.websocket_send('http://ldap:8888','El servidor de aula no pudo conectar con el equipo. ¿Has establecido la relación de confianza?','mykey','mygroup')
                break                

            if channel.recv(1024).rstrip().strip()=="no_websocket":
                WS.websocket_send('http://ldap:8888','<span style="font-size:14pt;">'+request.vars["host"]+'</span><br>El equipo no pudo conectar por websocket','mykey','mygroup')
                break   
                
    return dict()
Beispiel #10
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="")
Beispiel #11
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","")
Beispiel #12
0
def executeCommandLaptop():
    try:
        server = xmlrpclib.ServerProxy("http://ldap:6969")
        data = server.get_data_laptops(request.vars["host"])
    except:
        pass

    try:
        proxy = data[0]["proxy"]
        ip = data[0]["ip"]
    except:
        WS.websocket_send(
            'http://ldap:8888',
            '<span style="font-size:14pt;">' + request.vars["host"] +
            '</span><br>No se pudieron obtener los datos de conexión del equipo, ¿está encendido?',
            'mykey', 'mygroup')
        return dict()

    c = SSHConnection(proxy, "root", "")
    response = c.connectWithoutPass(
        "/var/web2py/applications/controlies/.ssh/id_rsa")

    if response != True:
        WS.websocket_send(
            'http://ldap:8888',
            '<span style="font-size:14pt;">' + request.vars["host"] +
            '</span><br>No se pudo conectar con el servidor de aula. ¿Has establecido la relación de confianza?',
            'mykey', 'mygroup')
        return dict()

    channel = c.exec_command(
        '/usr/bin/python /usr/share/controlies-ltspserver/remoteCommand.py ' +
        ip + ' "' + request.vars["command"] + '" ' + request.vars["host"])

    import select
    import time

    while True:
        #time.sleep(0.3)

        if channel.exit_status_ready():
            break

        rl, wl, xl = select.select([channel], [], [], 0.0)
        if len(rl) > 0:
            if channel.recv(1024).rstrip().strip() == "no_ssh":
                WS.websocket_send(
                    'http://ldap:8888',
                    'El servidor de aula no pudo conectar con el equipo. ¿Has establecido la relación de confianza?',
                    'mykey', 'mygroup')
                break

            if channel.recv(1024).rstrip().strip() == "no_websocket":
                WS.websocket_send(
                    'http://ldap:8888',
                    '<span style="font-size:14pt;">' + request.vars["host"] +
                    '</span><br>El equipo no pudo conectar por websocket',
                    'mykey', 'mygroup')
                break

    return dict()