コード例 #1
0
ファイル: gestion.py プロジェクト: japastor/controlies
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
ファイル: usuarios.py プロジェクト: Chisco77/controlies
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")       
コード例 #3
0
ファイル: usuarios.py プロジェクト: manumora/controlies
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")
コード例 #4
0
ファイル: usuarios.py プロジェクト: manumora/controlies
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")       
コード例 #5
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","")