Exemple #1
0
def start_session(argvs):
    print('going to start sesssion ')
    user = auth()
    if user:
        welcome_msg(user)
        exit_flag = False
        while not exit_flag:
            bindhost_ids = display_access_host(user)
            user_option = input('\033[32;1m%s\033[0m' % ("[%s][(q)quit, select host to login]:")%user.username).strip()
            if len(user_option) == 0: continue
            if user_option == 'q':
                exit_flag = True
                break
            if user_option.isdigit():
                user_option = int(user_option)
                if bindhost_ids.index(user_option)>-1:
                    bindhost = session.query(models.BindHost).filter(models.BindHost.id==user_option).first()
                    if bindhost:
                        ssh_login.ssh_login(user,bindhost,session,log_recording)
                    else:
                        print('input error,find any data...')
                else:
                    print("input error..")
            else:
                print("input error..")
Exemple #2
0
def start_session(argvs):
    print('going to start sesssion ')
    user = auth()
    if user:
        welcome_msg(user)
        print(user.bind_hosts)
        print(user.host_groups)
        exit_flag = False
        while not exit_flag:
            if user.bind_hosts:
                print('\033[32;1mz.\tungroupped hosts (%s)\033[0m' %len(user.bind_hosts) )
            for index,group in enumerate(user.host_groups):
                print('\033[32;1m%s.\t%s (%s)\033[0m' %(index,group.name,  len(group.bind_hosts)) )

            choice = input("[%s]:" % user.username).strip()
            if len(choice) == 0:continue
            if choice == 'z':
                print("------ Group: ungroupped hosts ------" )
                for index,bind_host in enumerate(user.bind_hosts):
                    print("  %s.\t%s@%s(%s)"%(index,
                                              bind_host.remote_user.username,
                                              bind_host.host.hostname,
                                              bind_host.host.ip,
                                              ))
                print("----------- END -----------" )
            elif choice.isdigit():
                choice = int(choice)
                if choice < len(user.host_groups):
                    print("------ Group: %s ------"  % user.host_groups[choice].name )
                    for index,bind_host in enumerate(user.host_groups[choice].bind_hosts):
                        print("  %s.\t%s@%s(%s)"%(index,
                                                  bind_host.remote_user.username,
                                                  bind_host.host.hostname,
                                                  bind_host.host.ip,
                                                  ))
                    print("----------- END -----------" )

                    #host selection
                    while not exit_flag:
                        user_option = input("[(b)back, (q)quit, select host to login]:").strip()
                        if len(user_option)==0:continue
                        if user_option == 'b':break
                        if user_option == 'q':
                            exit_flag=True
                        if user_option.isdigit():
                            user_option = int(user_option)
                            if user_option < len(user.host_groups[choice].bind_hosts) :
                                print('host:',user.host_groups[choice].bind_hosts[user_option])
                                print('audit log:',user.host_groups[choice].bind_hosts[user_option].audit_logs)
                                ssh_login.ssh_login(user,
                                                    user.host_groups[choice].bind_hosts[user_option],
                                                    session,
                                                    log_recording)
                else:
                    print("no this option..")
Exemple #3
0
def start_session(argvs):
    print('going to start sesssion ')
    user = auth()
    if user:
        welcome_msg(user)
        print(user.bind_hosts)
        print(user.groups)
        exit_flag = False
        while not exit_flag:
            if user.bind_hosts:
                print('\033[32;1mz.\tungroupped hosts (%s)\033[0m' %len(user.bind_hosts) )
            for index,group in enumerate(user.groups):
                print('\033[32;1m%s.\t%s (%s)\033[0m' %(index,group.name,  len(group.bind_hosts)) )

            choice = raw_input("[%s]:" % user.username).strip()
            if len(choice) == 0:continue
            if choice == 'z':
                print("------ Group: ungroupped hosts ------" )
                for index,bind_host in enumerate(user.bind_hosts):
                    print("  %s.\t%s@%s(%s)"%(index,
                                              bind_host.remoteuser.username,
                                              bind_host.host.hostname,
                                              bind_host.host.ip_addr,
                                              ))
                print("----------- END -----------" )
            elif choice.isdigit():
                choice = int(choice)
                if choice < len(user.groups):
                    print("------ Group: %s ------"  % user.groups[choice].name )
                    for index,bind_host in enumerate(user.groups[choice].bind_hosts):
                        print("  %s.\t%s@%s(%s)"%(index,
                                                  bind_host.remoteuser.username,
                                                  bind_host.host.hostname,
                                                  bind_host.host.ip_addr,
                                                  ))
                    print("----------- END -----------" )

                    #host selection
                    while not exit_flag:
                        user_option = raw_input("[(b)back, (q)quit, select host to login]:").strip()
                        if len(user_option)==0:continue
                        if user_option == 'b':break
                        if user_option == 'q':
                            exit_flag=True
                        if user_option.isdigit():
                            user_option = int(user_option)
                            if user_option < len(user.groups[choice].bind_hosts) :
                                print('host:',user.groups[choice].bind_hosts[user_option])
                                print('audit log:',user.groups[choice].bind_hosts[user_option].audit_logs)
                                ssh_login.ssh_login(user,
                                                    user.groups[choice].bind_hosts[user_option],
                                                    session,
                                                    log_recording)
                else:
                    print("no this option..")
Exemple #4
0
    def start_session():
        user = auth()
        if user:
            print('Hello %s!' % (user.username))
            exit_flag = False
            while not exit_flag:
                choice = input(user_choice)
                if choice == 'H':
                    print(user.bind_hosts)
                    for index, bind_host in enumerate(user.bind_hosts):
                        print('%s  %s (%s)' %
                              (index, bind_host.host, len(bind_host.host)))
                    user_option = input(
                        "[(q)quit, select host to login]:").strip()
                    if user_option == 'q':
                        exit_flag = True
                    if user_option.isdigit():
                        user_option = int(user_option)
                        host = user.bind_hosts[user_option]
                elif choice == 'G':
                    for index, group in enumerate(user.groups):
                        print('%s  %s (%s)' %
                              (index, group.name, len(group.bind_hosts)))
                    user_option = input("[select group to login]:").strip()
                    if user_option.isdigit():
                        user_option = int(user_option)
                        for index, bind_host in enumerate(
                                user.groups[user_option].bind_hosts):
                            print('%s  %s' % (index, bind_host))
                        user_option1 = input(
                            "[(q)quit, select host to login]:").strip()
                        if user_option1 == 'q':
                            exit_flag = True
                        if user_option1.isdigit():
                            user_option1 = int(user_option)
                            host = user.groups[user_option].bind_hosts[
                                user_option1]

                else:
                    continue

                ssh_login.ssh_login(user, host, session, log_recording)
Exemple #5
0
def start_session(argvs):
    print('****going to start session****')
    user = auth()
    if user:
        welcome_msg(user)
        exit_flag = False
        while not exit_flag:
            #打印登录用户关联的未分组主机
            if user.bind_hosts:
                print('ungrouped hosts(%s)' % len(user.bind_hosts))
            #打印登录用户关联的组
            if user.groups:
                for index,group in enumerate(user.groups):
                    print('%s.\t%s(%s)' % (index,group.name,len(group.bind_hosts)))

            #提示用户输入,选择组
            choice = input('[%s]: ' % user.username).strip()
            if len(choice) == 0:continue
            if choice == 'z':
                print('---------- Group: ungrouped hosts ------------')
                for index,bind_host in enumerate(user.bind_hosts):
                    print('%s.\t%s@%s(%s)' % (index,
                                              bind_host.remote_user.username,
                                              bind_host.host.hostname,
                                              bind_host.host.ip_addr
                                              ))
                print('---------- End ----------')
                # 再次提示用户输入,选择未分组的主机
                while not exit_flag:
                    user_option = input('[(b)ack, (q)uit, select host to login]: ').strip()
                    if len(user_option) == 0: continue
                    if user_option == 'q': exit_flag = True
                    if user_option == 'b': break
                    if user_option.isdigit():
                        user_option = int(user_option)
                        if user_option < len(user.bind_hosts):
                            ssh_login.ssh_login(user,
                                                user.bind_hosts[user_option],
                                                session,
                                                log_recording)
                        else:
                            print('**** no this option ****')

            elif choice.isdigit():
                choice = int(choice)
                if choice < len(user.groups):
                    print('---------- Group: %s ------------' % user.groups[choice].name)
                    for index,bind_host in enumerate(user.groups[choice].bind_hosts):
                        print('%s.\t%s@%s(%s)' % (index,
                                                  bind_host.remote_user.username,
                                                  bind_host.host.hostname,
                                                  bind_host.host.ip_addr))
                    print('---------- End ----------')
                    #再次提示用户输入,选择组中的主机
                    while not exit_flag:
                        user_option = input('[(b)ack, (q)uit, select host to login]: ').strip()
                        if len(user_option) == 0:continue
                        if user_option == 'q': exit_flag = True
                        if user_option == 'b':break
                        if user_option.isdigit():
                            user_option = int(user_option)
                            # print('user_option',user_option)
                            # print(len(user.groups[choice].bind_hosts))
                            if user_option < len(user.groups[choice].bind_hosts):

                                ssh_login.ssh_login(user,
                                                    user.groups[choice].bind_hosts[user_option],
                                                    session,
                                                    log_recording)
                            else:
                                print('**** no this option1 ****')
                else:
                    print('**** no this option2 ****')
Exemple #6
0
def start_session(argvs):
    '''
    开始远程登陆函数
    :param argvs:
    :return:
    '''
    print('going to start sesssion ')
    user = auth()  #调用auth认证函数 来判断输入的堡垒机用户是否存在
    if user:
        welcome_msg(user)
        # print(user.txt.bind_hosts)
        # print(user.txt.host_groups)
        exit_flag = False
        while not exit_flag:
            if user.profile_bind:
                # 显示未分组的机器
                print('\033[32;1mz.\t z查看未分组主机列表/任意键查看已分组主机列表 (%s)\033[0m' %
                      len(user.profile_bind))
            for index, group in enumerate(user.profile_group):
                print('\033[32;1m%s.\t%s (%s)\033[0m' %
                      (index, group.group_name, len(group.group_bind)))
            # 用户输入
            choice = input("[%s]:" % user.user_name).strip()
            if len(choice) == 0:
                continue
            # 如果是z 打印未分组机器
            if choice == 'z':
                print("------ Group: 未分组主机 ------")
                for index, bind_host in enumerate(user.profile_bind):
                    print("  %s.\t%s@%s(%s)" % (
                        index,
                        bind_host.bind_remusers.username,
                        bind_host.bind_hosts.host_name,
                        bind_host.bind_hosts.IP,
                    ))
                print("----------- END -----------")
            elif choice.isdigit():  # 打印分组的机器
                choice = int(choice)
                if choice < len(user.profile_group):
                    print("------ Group: %s ------" %
                          user.profile_group[choice].group_name)
                    for index, bind_host in enumerate(
                            user.profile_group[choice].group_bind):
                        print("  %s.\t%s@%s(%s)" % (
                            index,
                            bind_host.bind_remusers.username,
                            bind_host.bind_hosts.host_name,
                            bind_host.bind_hosts.IP,
                        ))
                    print("----------- END -----------")

                    # host selection 选择机器去登陆
                    while not exit_flag:
                        user_option = input(
                            "[(b)back, (q)quit, select host to login]:").strip(
                            )
                        if len(user_option) == 0:
                            continue
                        if user_option == 'b':
                            break
                        if user_option == 'q':
                            exit_flag = True
                        if user_option.isdigit():
                            user_option = int(user_option)
                            if user_option < len(
                                    user.host_groups[choice].bind_hosts):
                                print(
                                    'host:', user.host_groups[choice].
                                    bind_hosts[user_option])
                                # print('audit log:', user.txt.host_groups[choice].bind_hosts[user_option].audit_logs)
                                ssh_login.ssh_login(
                                    user,  # 传用户,用户组,连上对应的
                                    user.host_groups[choice].
                                    bind_hosts[user_option],
                                    session,
                                    log_recording)
                else:
                    print("no this option..")
Exemple #7
0
def start_session(argvs):  # 登录系统
    print('going to start sesssion ')
    user = auth()  #调用用户认证模块 user = return 的user_obj
    if user:
        welcome_msg(user)
        print(user.bind_hosts)  #返回userid user hostname,未分组主机
        print(user.groups)  #返回 有分组的足记
        exit_flag = False  #设定一个标志位
        while not exit_flag:  #此while 为打印出用户管理的所有机器,包括分组未分组
            if user.bind_hosts:
                print('\033[32;1mz.\tungroupped hosts (%s)\033[0m' %
                      len(user.bind_hosts))  #打印出未分组主机
            for index, group in enumerate(user.groups):  #打印出以分组主机
                print('\033[32;1m%s.\t%s (%s)\033[0m' %
                      (index, group.name, len(group.bind_hosts)))

            choice = input("[%s]:" % user.username).strip()  #让用户选择输入
            if len(choice) == 0: continue
            if choice == 'z':  #如果输入z
                print("------ Group: ungroupped hosts ------")  #
                for index, bind_host in enumerate(user.bind_hosts):  #打印出未分组的机器
                    print("  %s.\t%s@%s(%s)" % (
                        index,
                        bind_host.remoteuser.username,
                        bind_host.host.hostname,
                        bind_host.host.ip_addr,
                    ))
                print("----------- END -----------")
            elif choice.isdigit():  #如果选择的是数字
                choice = int(choice)
                if choice < len(user.groups):
                    print("------ Group: %s ------" %
                          user.groups[choice].name)  #打印出分组机器
                    for index, bind_host in enumerate(
                            user.groups[choice].bind_hosts):
                        print("  %s.\t%s@%s(%s)" % (
                            index,
                            bind_host.remoteuser.username,
                            bind_host.host.hostname,
                            bind_host.host.ip_addr,
                        ))
                    print("----------- END -----------")

                    #host selection
                    while not exit_flag:  #此while 选择相应主机操作
                        user_option = input(
                            "[(b)back, (q)quit, select host to login]:").strip(
                            )
                        if len(user_option) == 0: continue
                        if user_option == 'b': break  # 选择b,break跳出循环,
                        if user_option == 'q':  #选择q修改标志位为true跳出大循环
                            exit_flag = True
                        if user_option.isdigit():  #如果选择的是数字
                            user_option = int(user_option)
                            if user_option < len(
                                    user.groups[choice].bind_hosts):
                                print('host:', user.groups[choice].
                                      bind_hosts[user_option])  #打印出host
                                print(
                                    'audit log:',
                                    user.groups[choice].bind_hosts[user_option]
                                    .audit_logs)  #打印出log
                                ssh_login.ssh_login(
                                    user,
                                    user.groups[choice].
                                    bind_hosts[user_option],  #具体操作主机的对象
                                    session,
                                    log_recording
                                )  #执行ssh_login.ssh_login 传入user.obj,主机ip地址,session , log_recording函数
                else:
                    print("no this option..")