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
d8e33ab8
Commit
d8e33ab8
authored
Jan 25, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
[Update] Merge with dev
parents
a1f7e3a7
531025db
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
94 deletions
+15
-94
httpd.py
coco/httpd.py
+9
-1
interactive.py
coco/interactive.py
+1
-1
recorder.py
coco/recorder.py
+1
-1
utils.py
coco/utils.py
+3
-90
requirements.txt
requirements/requirements.txt
+1
-1
No files found.
coco/httpd.py
View file @
d8e33ab8
...
...
@@ -148,10 +148,18 @@ class SSHws(Namespace, BaseWebSocketHandler):
def
on_logout
(
self
,
connection
):
logger
.
debug
(
"{} logout"
.
format
(
connection
))
if
connection
:
if
connection
in
self
.
clients
[
request
.
sid
][
"proxy"
]
.
keys
():
self
.
clients
[
request
.
sid
][
"proxy"
][
connection
]
.
close
()
if
connection
in
self
.
clients
[
request
.
sid
][
"client"
]
.
keys
():
self
.
clients
[
request
.
sid
][
"client"
][
connection
]
.
close
()
def
logout
(
self
,
connection
):
if
connection
and
(
request
.
sid
in
self
.
clients
.
keys
()):
if
connection
in
self
.
clients
[
request
.
sid
][
"proxy"
]
.
keys
():
del
self
.
clients
[
request
.
sid
][
"proxy"
][
connection
]
if
connection
in
self
.
clients
[
request
.
sid
][
"forwarder"
]
.
keys
():
del
self
.
clients
[
request
.
sid
][
"forwarder"
][
connection
]
self
.
clients
[
request
.
sid
][
"client"
][
connection
]
.
close
()
if
connection
in
self
.
clients
[
request
.
sid
][
"client"
]
.
keys
():
del
self
.
clients
[
request
.
sid
][
"client"
][
connection
]
...
...
coco/interactive.py
View file @
d8e33ab8
...
...
@@ -129,7 +129,7 @@ class InteractiveServer:
self
.
display_asset_groups
()
elif
opt
.
startswith
(
"g"
)
and
opt
.
lstrip
(
"g"
)
.
isdigit
():
self
.
display_group_assets
(
int
(
opt
.
lstrip
(
"g"
)))
elif
opt
in
[
'q'
,
'Q'
]:
elif
opt
in
[
'q'
,
'Q'
,
'exit'
,
'quit'
]:
return
self
.
_sentinel
elif
opt
in
[
'h'
,
'H'
]:
self
.
display_banner
()
...
...
coco/recorder.py
View file @
d8e33ab8
...
...
@@ -239,7 +239,7 @@ class ESCommandRecorder(CommandRecorder, metaclass=Singleton):
print
(
"{} has been gc"
.
format
(
self
))
class
S3ReplayRecorder
(
ReplayRecorder
):
class
S3ReplayRecorder
(
Server
ReplayRecorder
):
def
__init__
(
self
,
app
):
super
()
.
__init__
(
app
)
self
.
bucket
=
app
.
config
[
"REPLAY_RECORD_ENGINE"
]
.
get
(
"BUCKET"
,
"jumpserver"
)
...
...
coco/utils.py
View file @
d8e33ab8
...
...
@@ -86,61 +86,6 @@ def ssh_key_gen(length=2048, type='rsa', password=None,
raise
IOError
(
'These is error when generate ssh key.'
)
def
content_md5
(
data
):
"""计算data的MD5值,经过Base64编码并返回str类型。
返回值可以直接作为HTTP Content-Type头部的值
"""
if
isinstance
(
data
,
str
):
data
=
hashlib
.
md5
(
data
.
encode
(
'utf-8'
))
value
=
base64
.
b64encode
(
data
.
digest
())
return
value
.
decode
(
'utf-8'
)
_STRPTIME_LOCK
=
threading
.
Lock
()
_GMT_FORMAT
=
"
%
a,
%
d
%
b
%
Y
%
H:
%
M:
%
S GMT"
_ISO8601_FORMAT
=
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S.000Z"
def
to_unixtime
(
time_string
,
format_string
):
with
_STRPTIME_LOCK
:
return
int
(
calendar
.
timegm
(
time
.
strptime
(
str
(
time_string
),
format_string
)))
def
http_date
(
timeval
=
None
):
"""返回符合HTTP标准的GMT时间字符串,用strftime的格式表示就是"
%
a,
%
d
%
b
%
Y
%
H:
%
M:
%
S GMT"。
但不能使用strftime,因为strftime的结果是和locale相关的。
"""
return
formatdate
(
timeval
,
usegmt
=
True
)
def
http_to_unixtime
(
time_string
):
"""把HTTP Date格式的字符串转换为UNIX时间(自1970年1月1日UTC零点的秒数)。
HTTP Date形如 `Sat, 05 Dec 2015 11:10:29 GMT` 。
"""
return
to_unixtime
(
time_string
,
_GMT_FORMAT
)
def
iso8601_to_unixtime
(
time_string
):
"""把ISO8601时间字符串(形如,2012-02-24T06:07:48.000Z)转换为UNIX时间,精确到秒。"""
return
to_unixtime
(
time_string
,
_ISO8601_FORMAT
)
def
make_signature
(
access_key_secret
,
date
=
None
):
if
isinstance
(
date
,
bytes
):
date
=
bytes
.
decode
(
date
)
if
isinstance
(
date
,
int
):
date_gmt
=
http_date
(
date
)
elif
date
is
None
:
date_gmt
=
http_date
(
int
(
time
.
time
()))
else
:
date_gmt
=
date
data
=
str
(
access_key_secret
)
+
"
\n
"
+
date_gmt
return
content_md5
(
data
)
class
TtyIOParser
(
object
):
def
__init__
(
self
,
width
=
80
,
height
=
24
):
self
.
screen
=
pyte
.
Screen
(
width
,
height
)
...
...
@@ -163,9 +108,12 @@ class TtyIOParser(object):
for
d
in
data
:
self
.
stream
.
feed
(
d
)
try
:
for
line
in
self
.
screen
.
display
:
if
line
.
strip
():
output
.
append
(
line
)
except
IndexError
:
pass
self
.
screen
.
reset
()
return
sep
.
join
(
output
[
0
:
-
1
])
.
strip
()
...
...
@@ -284,10 +232,6 @@ def wrap_with_title(text):
return
wrap_with_color
(
text
,
color
=
'black'
,
background
=
'green'
)
def
b64encode_as_string
(
data
):
return
base64
.
b64encode
(
data
)
.
decode
(
"utf-8"
)
def
split_string_int
(
s
):
"""Split string or int
...
...
@@ -321,37 +265,6 @@ def sort_assets(assets, order_by='hostname'):
return
assets
class
PKey
(
object
):
@classmethod
def
from_string
(
cls
,
key_string
):
try
:
pkey
=
paramiko
.
RSAKey
(
file_obj
=
StringIO
(
key_string
))
return
pkey
except
paramiko
.
SSHException
:
try
:
pkey
=
paramiko
.
DSSKey
(
file_obj
=
StringIO
(
key_string
))
return
pkey
except
paramiko
.
SSHException
:
return
None
def
timestamp_to_datetime_str
(
ts
):
datetime_format
=
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S.
%
fZ'
dt
=
datetime
.
datetime
.
fromtimestamp
(
ts
,
tz
=
pytz
.
timezone
(
'UTC'
))
return
dt
.
strftime
(
datetime_format
)
class
MultiQueue
(
Queue
):
def
mget
(
self
,
size
=
1
,
block
=
True
,
timeout
=
5
):
items
=
[]
for
i
in
range
(
size
):
try
:
items
.
append
(
self
.
get
(
block
=
block
,
timeout
=
timeout
))
except
Empty
:
break
return
items
def
_gettext
():
gettext
.
bindtextdomain
(
"coco"
,
os
.
path
.
join
(
BASE_DIR
,
"locale"
))
gettext
.
textdomain
(
"coco"
)
...
...
requirements/requirements.txt
View file @
d8e33ab8
...
...
@@ -30,5 +30,5 @@ tornado==4.5.2
urllib3==1.22
wcwidth==0.1.7
werkzeug==0.12.2
jumpserver-python-sdk==0.0.2
6
jumpserver-python-sdk==0.0.2
7
jms-es-sdk
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