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
c924285d
Commit
c924285d
authored
May 23, 2018
by
广宏伟
Browse files
Options
Browse Files
Download
Plain Diff
Merged in dev (pull request #62)
Dev
parents
9d737363
5130c43c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
12 deletions
+20
-12
app.py
coco/app.py
+5
-3
connection.py
coco/connection.py
+4
-3
httpd.py
coco/httpd.py
+7
-3
recorder.py
coco/recorder.py
+3
-3
requirements.txt
requirements/requirements.txt
+1
-0
No files found.
coco/app.py
View file @
c924285d
...
@@ -218,9 +218,11 @@ class Coco:
...
@@ -218,9 +218,11 @@ class Coco:
self
.
run_httpd
()
self
.
run_httpd
()
signal
.
signal
(
signal
.
SIGTERM
,
lambda
x
,
y
:
self
.
shutdown
())
signal
.
signal
(
signal
.
SIGTERM
,
lambda
x
,
y
:
self
.
shutdown
())
while
self
.
stop_evt
.
wait
(
5
):
while
True
:
print
(
"Coco receive term signal, exit"
)
if
self
.
stop_evt
.
is_set
():
break
print
(
"Coco receive term signal, exit"
)
break
time
.
sleep
(
3
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
self
.
stop_evt
.
set
()
self
.
stop_evt
.
set
()
self
.
shutdown
()
self
.
shutdown
()
...
...
coco/connection.py
View file @
c924285d
...
@@ -61,9 +61,9 @@ class SSHConnection:
...
@@ -61,9 +61,9 @@ class SSHConnection:
system_user
.
username
,
asset
.
ip
,
asset
.
port
,
system_user
.
username
,
asset
.
ip
,
asset
.
port
,
password_short
,
key_fingerprint
,
password_short
,
key_fingerprint
,
))
))
return
None
,
str
(
e
)
return
None
,
None
,
str
(
e
)
except
(
socket
.
error
,
TimeoutError
)
as
e
:
except
(
socket
.
error
,
TimeoutError
)
as
e
:
return
None
,
str
(
e
)
return
None
,
None
,
str
(
e
)
return
ssh
,
sock
,
None
return
ssh
,
sock
,
None
def
get_transport
(
self
,
asset
,
system_user
):
def
get_transport
(
self
,
asset
,
system_user
):
...
@@ -88,7 +88,8 @@ class SSHConnection:
...
@@ -88,7 +88,8 @@ class SSHConnection:
else
:
else
:
return
None
,
sock
,
msg
return
None
,
sock
,
msg
def
get_proxy_sock_v2
(
self
,
asset
):
@staticmethod
def
get_proxy_sock_v2
(
asset
):
sock
=
None
sock
=
None
domain
=
app_service
.
get_domain_detail_with_gateway
(
domain
=
app_service
.
get_domain_detail_with_gateway
(
asset
.
domain
asset
.
domain
...
...
coco/httpd.py
View file @
c924285d
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
import
os
import
os
import
socket
import
socket
import
uuid
import
uuid
import
eventlet
from
flask_socketio
import
SocketIO
,
Namespace
,
join_room
from
flask_socketio
import
SocketIO
,
Namespace
,
join_room
from
flask
import
Flask
,
request
,
current_app
,
redirect
from
flask
import
Flask
,
request
,
current_app
,
redirect
...
@@ -16,6 +17,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
...
@@ -16,6 +17,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
logger
=
get_logger
(
__file__
)
logger
=
get_logger
(
__file__
)
eventlet
.
monkey_patch
()
class
BaseNamespace
(
Namespace
):
class
BaseNamespace
(
Namespace
):
current_user
=
None
current_user
=
None
...
@@ -23,7 +26,7 @@ class BaseNamespace(Namespace):
...
@@ -23,7 +26,7 @@ class BaseNamespace(Namespace):
def
on_connect
(
self
):
def
on_connect
(
self
):
self
.
current_user
=
self
.
get_current_user
()
self
.
current_user
=
self
.
get_current_user
()
if
self
.
current_user
is
None
:
if
self
.
current_user
is
None
:
return
redirect
(
current_app
.
config
[
'LOGIN_URL'
])
return
redirect
(
self
.
socketio
.
config
[
'LOGIN_URL'
])
logger
.
debug
(
"{} connect websocket"
.
format
(
self
.
current_user
))
logger
.
debug
(
"{} connect websocket"
.
format
(
self
.
current_user
))
def
get_current_user
(
self
):
def
get_current_user
(
self
):
...
@@ -236,8 +239,8 @@ class HttpServer:
...
@@ -236,8 +239,8 @@ class HttpServer:
'LOGIN_URL'
:
'/login'
'LOGIN_URL'
:
'/login'
}
}
init_kwargs
=
dict
(
init_kwargs
=
dict
(
# async_mode="geven
t",
async_mode
=
"eventle
t"
,
async_mode
=
"threading"
,
#
async_mode="threading",
ping_timeout
=
20
,
ping_timeout
=
20
,
ping_interval
=
10
ping_interval
=
10
)
)
...
@@ -264,6 +267,7 @@ class HttpServer:
...
@@ -264,6 +267,7 @@ class HttpServer:
def
run
(
self
):
def
run
(
self
):
host
=
self
.
flask_app
.
config
[
"BIND_HOST"
]
host
=
self
.
flask_app
.
config
[
"BIND_HOST"
]
port
=
self
.
flask_app
.
config
[
"HTTPD_PORT"
]
port
=
self
.
flask_app
.
config
[
"HTTPD_PORT"
]
print
(
'Starting websock server at {}:{}'
.
format
(
host
,
port
))
self
.
socket_io
.
init_app
(
self
.
socket_io
.
init_app
(
self
.
flask_app
,
self
.
flask_app
,
**
self
.
init_kwargs
**
self
.
init_kwargs
...
...
coco/recorder.py
View file @
c924285d
...
@@ -134,9 +134,9 @@ class CommandRecorder(metaclass=Singleton):
...
@@ -134,9 +134,9 @@ class CommandRecorder(metaclass=Singleton):
def
func
():
def
func
():
while
not
self
.
stop_evt
.
is_set
():
while
not
self
.
stop_evt
.
is_set
():
data_set
=
self
.
queue
.
mget
(
self
.
batch_size
,
timeout
=
self
.
timeout
)
data_set
=
self
.
queue
.
mget
(
self
.
batch_size
,
timeout
=
self
.
timeout
)
logger
.
debug
(
"Session command remain push: {}"
.
format
(
size
=
self
.
queue
.
qsize
()
self
.
queue
.
qsize
())
if
size
>
0
:
)
logger
.
debug
(
"Session command remain push: {}"
.
format
(
size
)
)
if
not
data_set
:
if
not
data_set
:
continue
continue
logger
.
debug
(
"Send {} commands to server"
.
format
(
len
(
data_set
)))
logger
.
debug
(
"Send {} commands to server"
.
format
(
len
(
data_set
)))
...
...
requirements/requirements.txt
View file @
c924285d
...
@@ -41,3 +41,4 @@ tornado==4.5.2
...
@@ -41,3 +41,4 @@ tornado==4.5.2
urllib3==1.22
urllib3==1.22
wcwidth==0.1.7
wcwidth==0.1.7
Werkzeug==0.12.2
Werkzeug==0.12.2
eventlet==0.22
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