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
838b10d3
Commit
838b10d3
authored
Nov 01, 2014
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
ssh://172.10.10.9:2001/opt/jumpserver
into dev
parents
cd84f0d5
641b72f3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
35 deletions
+21
-35
jumpserver.iml
.idea/jumpserver.iml
+1
-1
jumpserver.py
jumpserver.py
+18
-34
pip-requirement.txt
pip-requirement.txt
+2
-0
No files found.
.idea/jumpserver.iml
View file @
838b10d3
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
>
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$"
/>
<content
url=
"file://$MODULE_DIR$"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 2.7.
8 (C:\Python27\
python.exe)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 2.7.
6 (C:/Python27/
python.exe)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</component>
</module>
</module>
...
...
jumpserver.py
View file @
838b10d3
...
@@ -16,6 +16,7 @@ from Crypto.Cipher import AES
...
@@ -16,6 +16,7 @@ from Crypto.Cipher import AES
from
binascii
import
b2a_hex
,
a2b_hex
from
binascii
import
b2a_hex
,
a2b_hex
import
ConfigParser
import
ConfigParser
import
paramiko
import
paramiko
import
pxssh
base_dir
=
"/opt/jumpserver/"
base_dir
=
"/opt/jumpserver/"
cf
=
ConfigParser
.
ConfigParser
()
cf
=
ConfigParser
.
ConfigParser
()
...
@@ -61,7 +62,10 @@ class PyCrypt(object):
...
@@ -61,7 +62,10 @@ class PyCrypt(object):
def
sigwinch_passthrough
(
sig
,
data
):
def
sigwinch_passthrough
(
sig
,
data
):
"""This function use to set the window size of the terminal!"""
"""This function use to set the window size of the terminal!"""
winsize
=
getwinsize
()
winsize
=
getwinsize
()
foo
.
setwinsize
(
winsize
[
0
],
winsize
[
1
])
try
:
foo
.
setwinsize
(
winsize
[
0
],
winsize
[
1
])
except
:
pass
def
getwinsize
():
def
getwinsize
():
...
@@ -69,7 +73,7 @@ def getwinsize():
...
@@ -69,7 +73,7 @@ def getwinsize():
if
'TIOCGWINSZ'
in
dir
(
termios
):
if
'TIOCGWINSZ'
in
dir
(
termios
):
TIOCGWINSZ
=
termios
.
TIOCGWINSZ
TIOCGWINSZ
=
termios
.
TIOCGWINSZ
else
:
else
:
TIOCGWINSZ
=
1074295912L
# Assume
TIOCGWINSZ
=
1074295912L
# Assume
s
=
struct
.
pack
(
'HHHH'
,
0
,
0
,
0
,
0
)
s
=
struct
.
pack
(
'HHHH'
,
0
,
0
,
0
,
0
)
x
=
fcntl
.
ioctl
(
sys
.
stdout
.
fileno
(),
TIOCGWINSZ
,
s
)
x
=
fcntl
.
ioctl
(
sys
.
stdout
.
fileno
(),
TIOCGWINSZ
,
s
)
return
struct
.
unpack
(
'HHHH'
,
x
)[
0
:
2
]
return
struct
.
unpack
(
'HHHH'
,
x
)[
0
:
2
]
...
@@ -110,38 +114,18 @@ def connect(host, port, user, password):
...
@@ -110,38 +114,18 @@ def connect(host, port, user, password):
os
.
mkdir
(
log_date_dir
)
os
.
mkdir
(
log_date_dir
)
logfile
=
open
(
"
%
s/
%
s_
%
s"
%
(
log_date_dir
,
host
,
user
),
'a'
)
logfile
=
open
(
"
%
s/
%
s_
%
s"
%
(
log_date_dir
,
host
,
user
),
'a'
)
logfile
.
write
(
'
\n\n
%
s
\n\n
'
%
time
.
strftime
(
'
%
Y
%
m
%
d_
%
H
%
M
%
S'
))
logfile
.
write
(
'
\n\n
%
s
\n\n
'
%
time
.
strftime
(
'
%
Y
%
m
%
d_
%
H
%
M
%
S'
))
cmd
=
'ssh -q -p
%
s
%
s@
%
s'
%
(
port
,
user
,
host
)
try
:
global
foo
global
foo
foo
=
pexpect
.
spawn
(
'/bin/bash'
,
[
'-c'
,
cmd
])
foo
=
pxssh
.
pxssh
()
foo
.
logfile
=
logfile
foo
.
login
(
host
,
user
,
password
,
port
=
port
,
auto_prompt_reset
=
False
)
while
True
:
foo
.
logfile
=
logfile
index
=
foo
.
expect
([
'continue'
,
foo
.
sendline
(
''
)
'assword'
,
signal
.
signal
(
signal
.
SIGWINCH
,
sigwinch_passthrough
)
pexpect
.
EOF
,
foo
.
interact
(
escape_character
=
chr
(
28
))
pexpect
.
TIMEOUT
],
timeout
=
3
)
except
pxssh
.
ExceptionPxssh
as
e
:
if
index
==
0
:
print
(
'登录失败:
%
s'
%
e
)
foo
.
sendline
(
'yes'
)
except
KeyboardInterrupt
:
continue
foo
.
logout
()
elif
index
==
1
:
foo
.
sendline
(
password
)
index
=
foo
.
expect
([
'assword'
,
'.*'
,
pexpect
.
EOF
,
pexpect
.
TIMEOUT
],
timeout
=
3
)
if
index
==
1
:
signal
.
signal
(
signal
.
SIGWINCH
,
sigwinch_passthrough
)
size
=
getwinsize
()
foo
.
setwinsize
(
size
[
0
],
size
[
1
])
foo
.
interact
()
break
elif
index
==
0
:
print
"Password error."
break
else
:
print
"Login failed, please contact system administrator!"
break
foo
.
terminate
(
force
=
True
)
def
ip_all_select
(
username
):
def
ip_all_select
(
username
):
...
...
pip-requirement.txt
0 → 100644
View file @
838b10d3
pexpect == 3.3
\ No newline at end of file
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