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
c6ad5fa9
Commit
c6ad5fa9
authored
Feb 06, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into test
parents
5e63bfc3
dffeadd5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
7 deletions
+33
-7
httpd.py
coco/httpd.py
+17
-3
interactive.py
coco/interactive.py
+16
-4
No files found.
coco/httpd.py
View file @
c6ad5fa9
...
@@ -126,11 +126,12 @@ class ProxyNamespace(BaseNamespace):
...
@@ -126,11 +126,12 @@ class ProxyNamespace(BaseNamespace):
connection
=
str
(
uuid
.
uuid4
())
connection
=
str
(
uuid
.
uuid4
())
asset_id
=
message
.
get
(
'uuid'
,
None
)
asset_id
=
message
.
get
(
'uuid'
,
None
)
user_id
=
message
.
get
(
'userid'
,
None
)
user_id
=
message
.
get
(
'userid'
,
None
)
secret
=
message
.
get
(
'secret'
,
None
)
self
.
emit
(
'room'
,
{
'room'
:
connection
,
'secret'
:
message
[
'secret'
]
})
self
.
emit
(
'room'
,
{
'room'
:
connection
,
'secret'
:
secret
})
if
not
asset_id
or
not
user_id
:
if
not
asset_id
or
not
user_id
:
self
.
on_connect
()
#
self.on_connect()
return
return
asset
=
self
.
app
.
service
.
get_asset
(
asset_id
)
asset
=
self
.
app
.
service
.
get_asset
(
asset_id
)
...
@@ -148,13 +149,26 @@ class ProxyNamespace(BaseNamespace):
...
@@ -148,13 +149,26 @@ class ProxyNamespace(BaseNamespace):
self
,
child
,
self
.
clients
[
request
.
sid
][
"room"
],
connection
self
,
child
,
self
.
clients
[
request
.
sid
][
"room"
],
connection
)
)
self
.
clients
[
request
.
sid
][
"forwarder"
][
connection
]
=
ProxyServer
(
self
.
clients
[
request
.
sid
][
"forwarder"
][
connection
]
=
ProxyServer
(
self
.
app
,
self
.
clients
[
request
.
sid
][
"client"
][
connection
]
self
.
app
,
self
.
clients
[
request
.
sid
][
"client"
][
connection
]
)
)
self
.
socketio
.
start_background_task
(
self
.
socketio
.
start_background_task
(
self
.
clients
[
request
.
sid
][
"forwarder"
][
connection
]
.
proxy
,
self
.
clients
[
request
.
sid
][
"forwarder"
][
connection
]
.
proxy
,
asset
,
system_user
asset
,
system_user
)
)
def
on_token
(
self
,
message
):
# 此处获取token含有的主机的信息
logger
.
debug
(
"On token trigger"
)
token
=
message
.
get
(
'token'
,
None
)
secret
=
message
.
get
(
'secret'
,
None
)
host
=
self
.
app
.
service
.
get_token_asset
(
token
)
.
json
()
# {
# "user": {UUID},
# "asset": {UUID},
# "system_user": {UUID}
# }
self
.
on_host
({
'secret'
:
secret
,
'uuid'
:
host
[
'asset'
],
'userid'
:
host
[
'system_user'
]})
def
on_resize
(
self
,
message
):
def
on_resize
(
self
,
message
):
cols
=
message
.
get
(
'cols'
)
cols
=
message
.
get
(
'cols'
)
rows
=
message
.
get
(
'rows'
)
rows
=
message
.
get
(
'rows'
)
...
...
coco/interactive.py
View file @
c6ad5fa9
...
@@ -82,6 +82,7 @@ class InteractiveServer:
...
@@ -82,6 +82,7 @@ class InteractiveServer:
self
.
client
.
send
(
wr
(
prompt
,
before
=
1
,
after
=
0
))
self
.
client
.
send
(
wr
(
prompt
,
before
=
1
,
after
=
0
))
while
True
:
while
True
:
data
=
self
.
client
.
recv
(
10
)
data
=
self
.
client
.
recv
(
10
)
logger
.
debug
(
data
)
if
len
(
data
)
==
0
:
if
len
(
data
)
==
0
:
self
.
app
.
remove_client
(
self
.
client
)
self
.
app
.
remove_client
(
self
.
client
)
break
break
...
@@ -96,6 +97,15 @@ class InteractiveServer:
...
@@ -96,6 +97,15 @@ class InteractiveServer:
self
.
client
.
send
(
data
)
self
.
client
.
send
(
data
)
continue
continue
if
data
.
startswith
(
b
'
\x03
'
):
# Ctrl-C
self
.
client
.
send
(
b
'^C
\r\n
Opt> '
)
input_data
=
[]
continue
elif
data
.
startswith
(
b
'
\x04
'
):
# Ctrl-D
return
'q'
# Todo: Move x1b to char
# Todo: Move x1b to char
if
data
.
startswith
(
b
'
\x1b
'
)
or
data
in
char
.
UNSUPPORTED_CHAR
:
if
data
.
startswith
(
b
'
\x1b
'
)
or
data
in
char
.
UNSUPPORTED_CHAR
:
self
.
client
.
send
(
b
''
)
self
.
client
.
send
(
b
''
)
...
@@ -119,11 +129,12 @@ class InteractiveServer:
...
@@ -119,11 +129,12 @@ class InteractiveServer:
input_data
.
append
(
data
)
input_data
.
append
(
data
)
def
dispatch
(
self
,
opt
):
def
dispatch
(
self
,
opt
):
print
(
repr
(
opt
))
if
opt
is
None
:
if
opt
is
None
:
return
self
.
_sentinel
return
self
.
_sentinel
elif
opt
.
startswith
(
"/"
):
elif
opt
.
startswith
(
"/"
):
self
.
search_and_display
(
opt
.
lstrip
(
"/"
))
self
.
search_and_display
(
opt
.
lstrip
(
"/"
))
elif
opt
in
[
'p'
,
'P'
]:
elif
opt
in
[
'p'
,
'P'
,
''
]:
self
.
display_assets
()
self
.
display_assets
()
elif
opt
in
[
'g'
,
'G'
]:
elif
opt
in
[
'g'
,
'G'
]:
self
.
display_asset_groups
()
self
.
display_asset_groups
()
...
@@ -181,7 +192,7 @@ class InteractiveServer:
...
@@ -181,7 +192,7 @@ class InteractiveServer:
amount_max_length
=
max
(
len
(
str
(
max
([
group
.
assets_amount
for
group
in
self
.
asset_groups
]))),
10
)
amount_max_length
=
max
(
len
(
str
(
max
([
group
.
assets_amount
for
group
in
self
.
asset_groups
]))),
10
)
header
=
'{1:>
%
d} {0.name:
%
d} {0.assets_amount:<
%
s} '
%
(
id_max_length
,
name_max_length
,
amount_max_length
)
header
=
'{1:>
%
d} {0.name:
%
d} {0.assets_amount:<
%
s} '
%
(
id_max_length
,
name_max_length
,
amount_max_length
)
comment_length
=
self
.
request
.
meta
[
"width"
]
-
len
(
header
.
format
(
fake_group
,
id_max_length
))
comment_length
=
self
.
request
.
meta
[
"width"
]
-
len
(
header
.
format
(
fake_group
,
id_max_length
))
line
=
header
+
'{0.comment:
%
s}'
%
(
comment_length
//
2
)
# comment中可能有中文
line
=
header
+
'{0.comment:
%
s}'
%
(
comment_length
//
2
)
# comment中可能有中文
header
+=
"{0.comment:
%
s}"
%
comment_length
header
+=
"{0.comment:
%
s}"
%
comment_length
self
.
client
.
send
(
title
(
header
.
format
(
fake_group
,
"ID"
)))
self
.
client
.
send
(
title
(
header
.
format
(
fake_group
,
"ID"
)))
for
index
,
group
in
enumerate
(
self
.
asset_groups
,
1
):
for
index
,
group
in
enumerate
(
self
.
asset_groups
,
1
):
...
@@ -194,12 +205,13 @@ class InteractiveServer:
...
@@ -194,12 +205,13 @@ class InteractiveServer:
self
.
display_asset_groups
()
self
.
display_asset_groups
()
return
return
self
.
search_result
=
self
.
asset_groups
[
_id
-
1
]
.
assets_granted
self
.
search_result
=
self
.
asset_groups
[
_id
-
1
]
.
assets_granted
self
.
display_search_result
()
self
.
display_search_result
()
def
display_search_result
(
self
):
def
display_search_result
(
self
):
self
.
search_result
=
sort_assets
(
self
.
search_result
,
self
.
app
.
config
[
"ASSET_LIST_SORT_BY"
])
self
.
search_result
=
sort_assets
(
self
.
search_result
,
self
.
app
.
config
[
"ASSET_LIST_SORT_BY"
])
fake_asset
=
Asset
(
hostname
=
_
(
"Hostname"
),
ip
=
_
(
"IP"
),
_system_users_name_list
=
_
(
"LoginAs"
),
comment
=
_
(
"Comment"
))
fake_asset
=
Asset
(
hostname
=
_
(
"Hostname"
),
ip
=
_
(
"IP"
),
_system_users_name_list
=
_
(
"LoginAs"
),
comment
=
_
(
"Comment"
))
id_max_length
=
max
(
len
(
str
(
len
(
self
.
search_result
))),
3
)
id_max_length
=
max
(
len
(
str
(
len
(
self
.
search_result
))),
3
)
hostname_max_length
=
max
(
max
([
len
(
asset
.
hostname
)
for
asset
in
self
.
search_result
+
[
fake_asset
]]),
15
)
hostname_max_length
=
max
(
max
([
len
(
asset
.
hostname
)
for
asset
in
self
.
search_result
+
[
fake_asset
]]),
15
)
sysuser_max_length
=
max
([
len
(
asset
.
system_users_name_list
)
for
asset
in
self
.
search_result
+
[
fake_asset
]])
sysuser_max_length
=
max
([
len
(
asset
.
system_users_name_list
)
for
asset
in
self
.
search_result
+
[
fake_asset
]])
...
...
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