Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
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
coco
Commits
2df44d0b
Commit
2df44d0b
authored
Aug 23, 2018
by
BaiJiangJie
Committed by
老广
Aug 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 添加ssh连接资产的超时时间为可配置选项SSH_TIMEOUT,默认15s (#88)
parent
3166c231
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
7 deletions
+14
-7
app.py
coco/app.py
+1
-0
connection.py
coco/connection.py
+5
-4
proxy.py
coco/proxy.py
+5
-3
conf_example.py
conf_example.py
+3
-0
No files found.
coco/app.py
View file @
2df44d0b
...
@@ -54,6 +54,7 @@ class Coco:
...
@@ -54,6 +54,7 @@ class Coco:
'HEARTBEAT_INTERVAL'
:
5
,
'HEARTBEAT_INTERVAL'
:
5
,
'MAX_CONNECTIONS'
:
500
,
'MAX_CONNECTIONS'
:
500
,
'ADMINS'
:
''
,
'ADMINS'
:
''
,
'SSH_TIMEOUT'
:
15
,
'COMMAND_STORAGE'
:
{
'TYPE'
:
'server'
},
# server
'COMMAND_STORAGE'
:
{
'TYPE'
:
'server'
},
# server
'REPLAY_STORAGE'
:
{
'TYPE'
:
'server'
},
'REPLAY_STORAGE'
:
{
'TYPE'
:
'server'
},
}
}
...
...
coco/connection.py
View file @
2df44d0b
...
@@ -10,11 +10,11 @@ import telnetlib
...
@@ -10,11 +10,11 @@ import telnetlib
import
paramiko
import
paramiko
from
paramiko.ssh_exception
import
SSHException
from
paramiko.ssh_exception
import
SSHException
from
.ctx
import
app_service
from
.ctx
import
app_service
,
current_app
from
.utils
import
get_logger
,
get_private_key_fingerprint
,
net_input
from
.utils
import
get_logger
,
get_private_key_fingerprint
,
net_input
logger
=
get_logger
(
__file__
)
logger
=
get_logger
(
__file__
)
TIMEOUT
=
10
BUF_SIZE
=
1024
BUF_SIZE
=
1024
MANUAL_LOGIN
=
'manual'
MANUAL_LOGIN
=
'manual'
AUTO_LOGIN
=
'auto'
AUTO_LOGIN
=
'auto'
...
@@ -46,7 +46,8 @@ class SSHConnection:
...
@@ -46,7 +46,8 @@ class SSHConnection:
ssh
.
connect
(
ssh
.
connect
(
asset
.
ip
,
port
=
asset
.
port
,
username
=
system_user
.
username
,
asset
.
ip
,
port
=
asset
.
port
,
username
=
system_user
.
username
,
password
=
system_user
.
password
,
pkey
=
system_user
.
private_key
,
password
=
system_user
.
password
,
pkey
=
system_user
.
private_key
,
timeout
=
TIMEOUT
,
compress
=
True
,
auth_timeout
=
TIMEOUT
,
timeout
=
current_app
.
config
[
'SSH_TIMEOUT'
],
compress
=
True
,
auth_timeout
=
current_app
.
config
[
'SSH_TIMEOUT'
],
look_for_keys
=
False
,
sock
=
sock
look_for_keys
=
False
,
sock
=
sock
)
)
except
(
paramiko
.
AuthenticationException
,
except
(
paramiko
.
AuthenticationException
,
...
@@ -111,7 +112,7 @@ class SSHConnection:
...
@@ -111,7 +112,7 @@ class SSHConnection:
username
=
gateway
.
username
,
username
=
gateway
.
username
,
password
=
gateway
.
password
,
password
=
gateway
.
password
,
pkey
=
gateway
.
private_key_obj
,
pkey
=
gateway
.
private_key_obj
,
timeout
=
TIMEOUT
)
timeout
=
current_app
.
config
[
'SSH_TIMEOUT'
]
)
except
(
paramiko
.
AuthenticationException
,
except
(
paramiko
.
AuthenticationException
,
paramiko
.
BadAuthenticationType
,
paramiko
.
BadAuthenticationType
,
SSHException
):
SSHException
):
...
...
coco/proxy.py
View file @
2df44d0b
...
@@ -16,7 +16,6 @@ from .utils import wrap_with_line_feed as wr, wrap_with_warning as warning, \
...
@@ -16,7 +16,6 @@ from .utils import wrap_with_line_feed as wr, wrap_with_warning as warning, \
logger
=
get_logger
(
__file__
)
logger
=
get_logger
(
__file__
)
TIMEOUT
=
10
BUF_SIZE
=
4096
BUF_SIZE
=
4096
MANUAL_LOGIN
=
'manual'
MANUAL_LOGIN
=
'manual'
AUTO_LOGIN
=
'auto'
AUTO_LOGIN
=
'auto'
...
@@ -156,8 +155,11 @@ class ProxyServer:
...
@@ -156,8 +155,11 @@ class ProxyServer:
self
.
client
.
send
(
'Connecting to {}@{} {:.1f}'
.
format
(
self
.
client
.
send
(
'Connecting to {}@{} {:.1f}'
.
format
(
system_user
,
asset
,
delay
)
system_user
,
asset
,
delay
)
)
)
while
self
.
connecting
and
delay
<
TIMEOUT
:
while
self
.
connecting
and
delay
<
current_app
.
config
[
'SSH_TIMEOUT'
]:
self
.
client
.
send
(
'
\x08\x08\x08
{:.1f}'
.
format
(
delay
)
.
encode
())
if
0
<=
delay
<
10
:
self
.
client
.
send
(
'
\x08\x08\x08
{:.1f}'
.
format
(
delay
)
.
encode
())
else
:
self
.
client
.
send
(
'
\x08\x08\x08\x08
{:.1f}'
.
format
(
delay
)
.
encode
())
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
delay
+=
0.1
delay
+=
0.1
thread
=
threading
.
Thread
(
target
=
func
)
thread
=
threading
.
Thread
(
target
=
func
)
...
...
conf_example.py
View file @
2df44d0b
...
@@ -66,5 +66,8 @@ class Config:
...
@@ -66,5 +66,8 @@ class Config:
"TYPE"
:
"server"
"TYPE"
:
"server"
}
}
# SSH connection timeout (default 15 seconds)
# SSH_TIMEOUT = 15
config
=
Config
()
config
=
Config
()
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