Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
57492768
Commit
57492768
authored
Mar 13, 2015
by
guanghongwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ȩ
parent
a7800b9a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
16 deletions
+5
-16
connect.py
connect.py
+4
-14
api.py
jumpserver/api.py
+1
-2
No files found.
connect.py
View file @
57492768
...
...
@@ -39,19 +39,10 @@ BASE_DIR = os.path.abspath(os.path.dirname(__file__))
CONF
=
ConfigParser
()
CONF
.
read
(
os
.
path
.
join
(
BASE_DIR
,
'jumpserver.conf'
))
LOG_DIR
=
os
.
path
.
join
(
BASE_DIR
,
'logs'
)
# Web generate user ssh_key dir.
SSH_KEY_DIR
=
os
.
path
.
join
(
BASE_DIR
,
'keys'
)
# User upload the server key to this dir.
SERVER_KEY_DIR
=
os
.
path
.
join
(
SSH_KEY_DIR
,
'server'
)
# The key of decryptor.
KEY
=
CONF
.
get
(
'web'
,
'key'
)
# Login user.
LOGIN_NAME
=
getpass
.
getuser
()
#LOGIN_NAME = os.getlogin()
USER_KEY_FILE
=
os
.
path
.
join
(
SERVER_KEY_DIR
,
LOGIN_NAME
)
if
not
os
.
path
.
isfile
(
USER_KEY_FILE
):
USER_KEY_FILE
=
None
def
color_print
(
msg
,
color
=
'blue'
):
...
...
@@ -212,7 +203,7 @@ def get_connect_item(username, ip):
return
username
,
password
,
ip
,
port
else
:
raise
ServerError
(
'Login type is not in ["L", "
S", "P", "
M"]'
)
raise
ServerError
(
'Login type is not in ["L", "M"]'
)
def
verify_connect
(
username
,
part_ip
):
...
...
@@ -222,12 +213,11 @@ def verify_connect(username, part_ip):
if
len
(
ip_matched
)
>
1
:
for
ip
in
ip_matched
:
print
'
[
%
s]
%
s --
%
s'
%
(
hosts_attr
[
ip
][
0
],
ip
,
hosts_attr
[
ip
][
1
])
print
'
%
s --
%
s'
%
(
ip
,
hosts_attr
[
ip
][
1
])
elif
len
(
ip_matched
)
<
1
:
color_print
(
'No Permission or No host.'
,
'red'
)
else
:
username
,
password
,
host
,
port
=
get_connect_item
(
username
,
ip_matched
[
0
])
print
username
,
password
,
host
,
port
connect
(
username
,
password
,
host
,
port
,
LOGIN_NAME
)
...
...
@@ -261,7 +251,7 @@ def connect(username, password, host, port, login_name):
ssh
.
load_system_host_keys
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
try
:
ssh
.
connect
(
host
,
port
=
port
,
username
=
username
,
password
=
password
,
key_filename
=
USER_KEY_FILE
,
compress
=
True
)
ssh
.
connect
(
host
,
port
=
port
,
username
=
username
,
password
=
password
,
compress
=
True
)
except
paramiko
.
ssh_exception
.
AuthenticationException
,
paramiko
.
ssh_exception
.
SSHException
:
raise
ServerError
(
'Authentication Error.'
)
except
socket
.
error
:
...
...
@@ -294,7 +284,7 @@ def remote_exec_cmd(ip, port, username, password, cmd):
time
.
sleep
(
5
)
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
connect
(
ip
,
port
,
username
,
password
,
key_filename
=
USER_KEY_FILE
,
timeout
=
5
)
ssh
.
connect
(
ip
,
port
,
username
,
password
,
timeout
=
5
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"bash -l -c '
%
s'"
%
cmd
)
out
=
stdout
.
readlines
()
err
=
stderr
.
readlines
()
...
...
jumpserver/api.py
View file @
57492768
...
...
@@ -14,8 +14,7 @@ def user_perm_group_api(user):
asset_group_list
=
[]
for
perm
in
perm_list
:
asset_group_list
.
extend
(
perm
.
asset_group
.
all
())
asset_group_list
.
append
(
perm
.
asset_group
)
return
asset_group_list
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment