コード例 #1
0
def connect_ssh():
    global shell, ssh
    if not os.path.exists('/root/.ssh/authorized_keys') or not os.path.exists(
            '/root/.ssh/id_rsa') or not os.path.exists(
                '/root/.ssh/id_rsa.pub'):
        create_rsa()

    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect('127.0.0.1', public.GetSSHPort())
    except:
        if public.GetSSHStatus():
            try:
                ssh.connect('localhost', public.GetSSHPort())
            except:
                create_rsa()
                return False
        import firewalls
        fw = firewalls.firewalls()
        get = common.dict_obj()
        get.status = '0'
        fw.SetSshStatus(get)
        ssh.connect('127.0.0.1', public.GetSSHPort())
        get.status = '1'
        fw.SetSshStatus(get)
    shell = ssh.invoke_shell(term='xterm', width=100, height=29)
    shell.setblocking(0)
    return True
コード例 #2
0
def connect_ssh(user=None, passwd=None):
    global shell, ssh
    pkey = '/root/.ssh/id_rsa_bt'
    if not os.path.exists('/root/.ssh/authorized_keys') or not os.path.exists(
            pkey):
        create_rsa()
    try:
        if not user:
            key = paramiko.RSAKey.from_private_key_file(pkey)
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        try:
            if not user:
                ssh.connect('127.0.0.1', public.GetSSHPort(), pkey=key)
            else:
                ssh.connect('127.0.0.1',
                            public.GetSSHPort(),
                            username=user,
                            password=passwd)
        except:
            if public.GetSSHStatus():
                try:
                    if not user:
                        ssh.connect('localhost', public.GetSSHPort(), pkey=key)
                    else:
                        ssh.connect('localhost',
                                    public.GetSSHPort(),
                                    username=user,
                                    password=passwd)
                except:
                    create_rsa()
                    return False
            import firewalls
            fw = firewalls.firewalls()
            get = common.dict_obj()
            get.status = '0'
            fw.SetSshStatus(get)
            if not user:
                ssh.connect('127.0.0.1', public.GetSSHPort(), pkey=key)
            else:
                ssh.connect('127.0.0.1',
                            public.GetSSHPort(),
                            username=user,
                            password=passwd)
            get.status = '1'
            fw.SetSshStatus(get)
        shell = ssh.invoke_shell(term='xterm', width=100, height=29)
        shell.setblocking(0)
        return True
    except:
        shell = None
        return False
コード例 #3
0
def connect_ssh():
    global shell, ssh
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect('127.0.0.1', public.GetSSHPort())
    except:
        if public.GetSSHStatus():
            try:
                ssh.connect('localhost', public.GetSSHPort())
            except:
                return False
        import firewalls
        fw = firewalls.firewalls()
        get = common.dict_obj()
        get.status = '0'
        fw.SetSshStatus(get)
        ssh.connect('127.0.0.1', public.GetSSHPort())
        get.status = '1'
        fw.SetSshStatus(get)
    shell = ssh.invoke_shell(term='xterm', width=100, height=29)
    shell.setblocking(0)
    return True
コード例 #4
0
ファイル: system.py プロジェクト: zwt12370/BaoTa
 def connect_ssh(self):
     import paramiko
     self.ssh = paramiko.SSHClient()
     self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
     try:
         self.ssh.connect('127.0.0.1', public.GetSSHPort())
     except:
         if public.GetSSHStatus():
             try:
                 self.ssh.connect('localhost', public.GetSSHPort())
             except:
                 return False;
         import firewalls,common
         fw = firewalls.firewalls()
         get = common.dict_obj()
         get.status = '0';
         fw.SetSshStatus(get)
         self.ssh.connect('127.0.0.1', public.GetSSHPort())
         get.status = '1';
         fw.SetSshStatus(get);
     self.shell = self.ssh.invoke_shell(term='xterm', width=100, height=29)
     self.shell.setblocking(0)
     return True