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
95e9ac11
Commit
95e9ac11
authored
Mar 25, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改proxy
parent
bb1031b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
23 deletions
+31
-23
proxy.py
coco/proxy.py
+31
-23
No files found.
coco/proxy.py
View file @
95e9ac11
...
@@ -86,36 +86,44 @@ class ProxyServer:
...
@@ -86,36 +86,44 @@ class ProxyServer:
def
get_telnet_server_conn
(
self
,
asset
,
system_user
):
def
get_telnet_server_conn
(
self
,
asset
,
system_user
):
pass
pass
def
make_proxy_command
(
self
,
asset
):
def
get_proxy_sock
(
self
,
asset
):
gateway
=
asset
.
domain
.
random_gateway
()
domain
=
self
.
app
.
service
.
get_domain_detail_with_gateway
(
proxy_command
=
[
asset
.
domain
"ssh"
,
"-p"
,
str
(
gateway
.
port
),
)
"{}@{}"
.
format
(
gateway
.
username
,
gateway
.
ip
),
"-W"
,
"{}:{}"
.
format
(
asset
.
ip
,
asset
.
port
),
"-q"
,
]
if
gateway
.
password
:
proxy_command
.
insert
(
0
,
"sshpass -p {}"
.
format
(
gateway
.
password
))
if
gateway
.
private_key
:
gateway
.
set_key_dir
(
os
.
path
.
join
(
self
.
app
.
root_path
,
'keys'
))
proxy_command
.
append
(
"-i {}"
.
format
(
gateway
.
private_key_file
))
proxy_command
=
' '
.
join
(
proxy_command
)
return
proxy_command
def
get_ssh_server_conn
(
self
,
asset
,
system_user
):
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
sock
=
None
sock
=
None
if
asset
.
domain
:
for
i
in
domain
.
gateways
:
asset
.
domain
=
self
.
app
.
service
.
get_domain_detail_with_gateway
(
asset
.
domain
)
gateway
=
domain
.
random_gateway
()
proxy_command
=
[
"ssh"
,
"-p"
,
str
(
gateway
.
port
),
"{}@{}"
.
format
(
gateway
.
username
,
gateway
.
ip
),
"-W"
,
"{}:{}"
.
format
(
asset
.
ip
,
asset
.
port
),
"-q"
,
]
if
gateway
.
password
:
proxy_command
.
insert
(
0
,
"sshpass -p {}"
.
format
(
gateway
.
password
))
if
gateway
.
private_key
:
gateway
.
set_key_dir
(
os
.
path
.
join
(
self
.
app
.
root_path
,
'keys'
))
proxy_command
.
append
(
"-i {}"
.
format
(
gateway
.
private_key_file
))
proxy_command
=
' '
.
join
(
proxy_command
)
try
:
try
:
proxy_command
=
self
.
make_proxy_command
(
asset
)
sock
=
paramiko
.
ProxyCommand
(
proxy_command
)
sock
=
paramiko
.
ProxyCommand
(
proxy_command
)
break
except
(
paramiko
.
AuthenticationException
,
except
(
paramiko
.
AuthenticationException
,
paramiko
.
BadAuthenticationType
,
SSHException
,
paramiko
.
BadAuthenticationType
,
SSHException
,
TimeoutError
)
as
e
:
TimeoutError
)
as
e
:
logger
.
error
(
e
)
logger
.
error
(
e
)
continue
return
sock
def
get_ssh_server_conn
(
self
,
asset
,
system_user
):
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
sock
=
None
if
asset
.
domain
:
sock
=
self
.
get_proxy_sock
(
asset
)
try
:
try
:
ssh
.
connect
(
ssh
.
connect
(
...
...
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