예제 #1
0
def verify_connect(username, part_ip, account):
    try:
        hosts_attr = get_user_host(username)
        hosts = hosts_attr.values()
    except ServerError, e:
        color_print(e, 'red')
        return False
예제 #2
0
def verify_connect(username, part_ip, account):
    try:
        hosts_attr = get_user_host(username)
        hosts = hosts_attr.values()
    except ServerError, e:
        color_print(e, 'red')
        return False
예제 #3
0
파일: connect.py 프로젝트: iselu/jumpserver
def verify_connect(username, part_ip):
    ip_matched = []
    try:
        hosts_attr = get_user_host(username)
        hosts = hosts_attr.values()
    except ServerError, e:
        color_print(e, "red")
        return False
예제 #4
0
def get_user_hostgroup_host(username, gid):
    """Get the hostgroup hosts of under the user control."""
    hosts_attr = {}
    user = User.objects.get(username=username)
    hosts = user_perm_usergroup_hosts_api(gid)
    assets = get_user_host(username)
    for host in hosts:
        alias = AssetAlias.objects.filter(user=user, host=host)
        if alias and alias[0].alias != '':
            hosts_attr[host.ip] = [host.id, host.ip, alias[0].alias]
        else:
            hosts_attr[host.ip] = [host.id, host.ip, host.comment, assets[host.ip][3]]
    return hosts_attr
예제 #5
0
def get_user_hostgroup_host(username, gid):
    """Get the hostgroup hosts of under the user control."""
    hosts_attr = {}
    user = User.objects.get(username=username)
    hosts = user_perm_usergroup_hosts_api(gid)
    assets = get_user_host(username)
    for host in hosts:
        alias = AssetAlias.objects.filter(user=user, host=host)
        if alias and alias[0].alias != '':
            hosts_attr[host.ip] = [host.id, host.ip, alias[0].alias]
        else:
            hosts_attr[host.ip] = [
                host.id, host.ip, host.comment, assets[host.ip][3]
            ]
    return hosts_attr
예제 #6
0
def exec_cmd_servers(username):
    color_print(
        "You can choose in the following IP(s), Use glob or ips split by comma. q/Q to PreLayer.",
        'green')
    print_user_host(LOGIN_NAME)
    while True:
        hosts = []
        inputs = raw_input('\033[1;32mip(s)>: \033[0m')
        if inputs in ['q', 'Q']:
            break
        get_hosts = get_user_host(username).keys()

        if ',' in inputs:
            ips_input = inputs.split(',')
            for host in ips_input:
                if host in get_hosts:
                    hosts.append(host)
        else:
            for host in get_hosts:
                if fnmatch.fnmatch(host, inputs):
                    hosts.append(host.strip())

        if len(hosts) == 0:
            color_print("Check again, Not matched any ip!", 'red')
            continue
        else:
            print "You matched ip: %s" % hosts
        color_print(
            "Input the Command , The command will be Execute on servers, q/Q to quit.",
            'green')
        while True:
            cmd = raw_input('\033[1;32mCmd(s): \033[0m')
            if cmd in ['q', 'Q']:
                break
            exec_log_dir = os.path.join(LOG_DIR, 'exec_cmds')
            if not os.path.isdir(exec_log_dir):
                os.mkdir(exec_log_dir)
                os.chmod(exec_log_dir, 0777)
            filename = "%s/%s.log" % (exec_log_dir, time.strftime('%Y%m%d'))
            f = open(filename, 'a')
            f.write("DateTime: %s User: %s Host: %s Cmds: %s\n" %
                    (time.strftime('%Y/%m/%d %H:%M:%S'), username, hosts, cmd))
            multi_remote_exec_cmd(hosts, username, cmd)
예제 #7
0
파일: connect.py 프로젝트: iselu/jumpserver
def exec_cmd_servers(username):
    color_print("You can choose in the following IP(s), Use glob or ips split by comma. q/Q to PreLayer.", "green")
    print_user_host(LOGIN_NAME)
    while True:
        hosts = []
        inputs = raw_input("\033[1;32mip(s)>: \033[0m")
        if inputs in ["q", "Q"]:
            break
        get_hosts = get_user_host(username).keys()

        if "," in inputs:
            ips_input = inputs.split(",")
            for host in ips_input:
                if host in get_hosts:
                    hosts.append(host)
        else:
            for host in get_hosts:
                if fnmatch.fnmatch(host, inputs):
                    hosts.append(host.strip())

        if len(hosts) == 0:
            color_print("Check again, Not matched any ip!", "red")
            continue
        else:
            print "You matched ip: %s" % hosts
        color_print("Input the Command , The command will be Execute on servers, q/Q to quit.", "green")
        while True:
            cmd = raw_input("\033[1;32mCmd(s): \033[0m")
            if cmd in ["q", "Q"]:
                break
            exec_log_dir = os.path.join(LOG_DIR, "exec_cmds")
            if not os.path.isdir(exec_log_dir):
                os.mkdir(exec_log_dir)
                os.chmod(exec_log_dir, 0777)
            filename = "%s/%s.log" % (exec_log_dir, time.strftime("%Y%m%d"))
            f = open(filename, "a")
            f.write(
                "DateTime: %s User: %s Host: %s Cmds: %s\n" % (time.strftime("%Y/%m/%d %H:%M:%S"), username, hosts, cmd)
            )
            multi_remote_exec_cmd(hosts, username, cmd)
예제 #8
0
파일: connect.py 프로젝트: iselu/jumpserver
def print_user_host(username):
    try:
        hosts_attr = get_user_host(username)
    except ServerError, e:
        color_print(e, "red")
        return
예제 #9
0
def print_user_host(username):
    try:
        hosts_attr = get_user_host(username)
    except ServerError, e:
        color_print(e, 'red')
        return