Commit fa0ec1e7 authored by root's avatar root

connect

parent 98dfebc3
...@@ -26,7 +26,7 @@ from juser.models import User ...@@ -26,7 +26,7 @@ from juser.models import User
from jasset.models import Asset from jasset.models import Asset
from jlog.models import Log from jlog.models import Log
from jumpserver.views import PyCrypt from jumpserver.views import PyCrypt
from jumpserver.api import user_perm_asset_api from jumpserver.api import user_perm_asset_api, user_perm_group_api
try: try:
import termios import termios
...@@ -183,6 +183,15 @@ def get_user_host(username): ...@@ -183,6 +183,15 @@ def get_user_host(username):
return hosts_attr return hosts_attr
def get_user_hostgroup(username):
"""Get the hostgroups of under the user control."""
groups_attr = {}
group_all = user_perm_group_api(username)
for group in group_all:
groups_attr[group.name] = [group.id, group.comment]
return groups_attr
def get_connect_item(username, ip): def get_connect_item(username, ip):
cryptor = PyCrypt(KEY) cryptor = PyCrypt(KEY)
...@@ -233,8 +242,9 @@ def print_prompt(): ...@@ -233,8 +242,9 @@ def print_prompt():
msg = """\033[1;32m### Welcome Use JumpServer To Login. ### \033[0m msg = """\033[1;32m### Welcome Use JumpServer To Login. ### \033[0m
1) Type \033[32mIP ADDRESS\033[0m To Login. 1) Type \033[32mIP ADDRESS\033[0m To Login.
2) Type \033[32mP/p\033[0m To Print The Servers You Available. 2) Type \033[32mP/p\033[0m To Print The Servers You Available.
3) Type \033[32mE/e\033[0m To Execute Command On Several Servers. 3) Type \033[32mG/g\033[0m To Print The Server Groups You Available.
4) Type \033[32mQ/q\033[0m To Quit. 4) Type \033[32mE/e\033[0m To Execute Command On Several Servers.
5) Type \033[32mQ/q\033[0m To Quit.
""" """
print textwrap.dedent(msg) print textwrap.dedent(msg)
...@@ -247,6 +257,13 @@ def print_user_host(username): ...@@ -247,6 +257,13 @@ def print_user_host(username):
print '%s -- %s' % (ip, hosts_attr[ip][1]) print '%s -- %s' % (ip, hosts_attr[ip][1])
def print_user_hostgroup(username):
group_attr = get_user_hostgroup(username)
groups = group_attr.keys()
for g in groups:
print '%s -- %s' % (g, group_attr[g][1])
def connect(username, password, host, port, login_name): def connect(username, password, host, port, login_name):
""" """
Connect server. Connect server.
...@@ -362,6 +379,9 @@ if __name__ == '__main__': ...@@ -362,6 +379,9 @@ if __name__ == '__main__':
if option in ['P', 'p']: if option in ['P', 'p']:
print_user_host(LOGIN_NAME) print_user_host(LOGIN_NAME)
continue continue
elif option in ['G', 'g']:
print_user_hostgroup(LOGIN_NAME)
continue
elif option in ['E', 'e']: elif option in ['E', 'e']:
exec_cmd_servers(LOGIN_NAME) exec_cmd_servers(LOGIN_NAME)
elif option in ['Q', 'q']: elif option in ['Q', 'q']:
......
...@@ -9,7 +9,7 @@ database = jumpserver ...@@ -9,7 +9,7 @@ database = jumpserver
[ldap] [ldap]
ldap_enable = 1 ldap_enable = 1
host_url = ldap://192.168.8.230:389 host_url = ldap://127.0.0.1:389
base_dn = dc=fengxing, dc=com base_dn = dc=fengxing, dc=com
root_dn = cn=admin,dc=fengxing,dc=com root_dn = cn=admin,dc=fengxing,dc=com
root_pw = 123456 root_pw = 123456
......
...@@ -10,7 +10,8 @@ from jasset.models import Asset, BisGroup ...@@ -10,7 +10,8 @@ from jasset.models import Asset, BisGroup
from jlog.models import Log from jlog.models import Log
def user_perm_group_api(user): def user_perm_group_api(username):
user = User.objects.get(username=username)
if user: if user:
perm_list = [] perm_list = []
user_group_all = user.group.all() user_group_all = user.group.all()
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment