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
e4c6823e
Commit
e4c6823e
authored
Dec 22, 2014
by
guanghongwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alert_print fuction
parent
e2e32b4b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
connect.py
connect.py
+10
-11
No files found.
connect.py
View file @
e4c6823e
...
@@ -32,6 +32,11 @@ def red_print(string):
...
@@ -32,6 +32,11 @@ def red_print(string):
print
'
\033
[1;31m
%
s
\033
[0m'
%
string
print
'
\033
[1;31m
%
s
\033
[0m'
%
string
def
alert_print
(
string
):
red_print
(
string
)
time
.
sleep
(
2
)
sys
.
exit
()
def
get_win_size
():
def
get_win_size
():
"""This function use to get the size of the windows!"""
"""This function use to get the size of the windows!"""
if
'TIOCGWINSZ'
in
dir
(
termios
):
if
'TIOCGWINSZ'
in
dir
(
termios
):
...
@@ -67,14 +72,12 @@ def posix_shell(chan, user, host):
...
@@ -67,14 +72,12 @@ def posix_shell(chan, user, host):
try
:
try
:
os
.
makedirs
(
today_connect_log_dir
)
os
.
makedirs
(
today_connect_log_dir
)
except
OSError
:
except
OSError
:
red_print
(
'Create
%
s failed, Please modify
%
s permission.'
%
(
today_connect_log_dir
,
connect_log_dir
))
alert_print
(
'Create
%
s failed, Please modify
%
s permission.'
%
(
today_connect_log_dir
,
connect_log_dir
))
sys
.
exit
()
try
:
try
:
log
=
open
(
log_file_path
,
'a'
)
log
=
open
(
log_file_path
,
'a'
)
except
IOError
:
except
IOError
:
red_print
(
'Create logfile failed, Please modify
%
s permission.'
%
today_connect_log_dir
)
alert_print
(
'Create logfile failed, Please modify
%
s permission.'
%
today_connect_log_dir
)
sys
.
exit
()
old_tty
=
termios
.
tcgetattr
(
sys
.
stdin
)
old_tty
=
termios
.
tcgetattr
(
sys
.
stdin
)
try
:
try
:
...
@@ -124,13 +127,9 @@ def connect(username, password, host, port):
...
@@ -124,13 +127,9 @@ def connect(username, password, host, port):
try
:
try
:
ssh
.
connect
(
host
,
port
=
port
,
username
=
username
,
password
=
password
,
compress
=
True
)
ssh
.
connect
(
host
,
port
=
port
,
username
=
username
,
password
=
password
,
compress
=
True
)
except
paramiko
.
ssh_exception
.
AuthenticationException
:
except
paramiko
.
ssh_exception
.
AuthenticationException
:
red_print
(
'Password Error, Please Correct it.'
)
alert_print
(
'Host Password Error, Please Correct it.'
)
time
.
sleep
(
2
)
sys
.
exit
()
except
socket
.
error
:
except
socket
.
error
:
red_print
(
'Connect SSH Socket Port Error, Please Correct it.'
)
alert_print
(
'Connect SSH Socket Port Error, Please Correct it.'
)
time
.
sleep
(
2
)
sys
.
exit
()
# Make a channel and set windows size
# Make a channel and set windows size
global
channel
global
channel
...
@@ -144,7 +143,7 @@ def connect(username, password, host, port):
...
@@ -144,7 +143,7 @@ def connect(username, password, host, port):
# Modify PS1
# Modify PS1
channel
.
send
(
'PS1=
%
s'
%
ps1
)
channel
.
send
(
'PS1=
%
s'
%
ps1
)
channel
.
send
(
"clear;echo -e '
\\
033[32mLogin
%
s
OK
.
\\
033[0m'
\n
"
%
host
)
channel
.
send
(
"clear;echo -e '
\\
033[32mLogin
%
s
done. Enjoy it
.
\\
033[0m'
\n
"
%
host
)
# Make ssh interactive tunnel
# Make ssh interactive tunnel
posix_shell
(
channel
,
username
,
host
)
posix_shell
(
channel
,
username
,
host
)
...
...
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