Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
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
luna
Commits
fbb0d283
Commit
fbb0d283
authored
Feb 28, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 修改中文输入bug
parent
36e587df
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
84 deletions
+5
-84
websocket.py
luna/views/websocket.py
+5
-84
No files found.
luna/views/websocket.py
View file @
fbb0d283
...
@@ -15,7 +15,7 @@ from ..proxy import ProxyServer
...
@@ -15,7 +15,7 @@ from ..proxy import ProxyServer
from
..channel
import
ProxyChannel
from
..channel
import
ProxyChannel
clients
=
app
.
clients
clients
=
app
.
clients
logger
=
logging
.
getLogger
(
__file__
)
logger
=
app
.
logger
__all__
=
[
__all__
=
[
...
@@ -56,9 +56,10 @@ def handle_machine(message):
...
@@ -56,9 +56,10 @@ def handle_machine(message):
@socket_io.on
(
'data'
)
@socket_io.on
(
'data'
)
def
handle_data
(
message
):
def
handle_data
(
message
):
sid
=
request
.
sid
sid
=
request
.
sid
logger
.
debug
(
'Receive data:
%
s'
%
message
)
message
=
message
.
encode
(
'utf-8'
)
logger
.
warning
(
'Receive data:
%
s'
%
message
)
if
clients
[
sid
][
'proxy_chan'
]:
if
clients
[
sid
][
'proxy_chan'
]:
print
(
'Sending to client channel'
)
logger
.
info
(
'Sending to client channel'
)
clients
[
sid
][
'proxy_chan'
]
.
write
(
message
)
clients
[
sid
][
'proxy_chan'
]
.
write
(
message
)
...
@@ -74,85 +75,5 @@ def handle_term_resize(json):
...
@@ -74,85 +75,5 @@ def handle_term_resize(json):
sid
=
request
.
sid
sid
=
request
.
sid
logger
.
debug
(
'Resize term:
%
s'
%
json
)
logger
.
debug
(
'Resize term:
%
s'
%
json
)
"""
@socket_io.on('nav')
def handle_api(sid):
socket_io.emit('nav', json.dumps(nav), room=sid)
@socket_io.on('connect', namespace='/')
def handle_term_connect(sid, environ):
clients[sid] = collections.defaultdict(dict)
@socket_io.on('machine')
def handle_machine(sid, message):
clients[sid]['host'] = host = '120.25.240.109'
clients[sid]['port'] = port = 8022
user = to_dotmap({'username': 'root', 'name': 'redhat'})
asset = to_dotmap({'hostname': host, 'ip': host, 'port': 8022})
# win_width = request.cookies.get('col')
# win_height = request.cookies.get('row')
system_user = to_dotmap({'name': 'jms', 'username': 'jms', 'id': 102})
clients[sid]['proxy_chan'] = proxy_chan = ProxyChannel(sid)
# proxy_chan.set_win_size((win_width, win_height))
proxy_server = ProxyServer(app, user, asset, system_user, proxy_chan)
t = threading.Thread(target=proxy_server.proxy, args=())
t.daemon = True
t.start()
@socket_io.on('data')
def handle_data(sid, message):
logger.debug('Receive data:
%
s'
%
message)
if clients[sid]['proxy_chan']:
print('Sending to client channel')
clients[sid]['proxy_chan'].write(message)
@socket_io.on('disconnect')
def handle_term_disconnect(sid):
del clients[sid]
print('term disconnect')
@socket_io.on('resize')
def handle_term_resize(sid, json):
logger.debug('Resize term:
%
s'
%
json)
"""
### Only for test ###
def
forward
(
sid
):
print
(
request
)
try
:
host
=
clients
[
sid
][
'host'
]
port
=
clients
[
sid
][
'port'
]
except
KeyError
as
e
:
socket_io
.
emit
(
'data'
,
e
,
room
=
sid
)
return
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
connect
(
host
,
port
=
port
,
username
=
'jms'
,
password
=
'redhat'
)
clients
[
sid
][
'ssh'
]
=
ssh
clients
[
sid
][
'chan'
]
=
chan
=
ssh
.
invoke_shell
()
while
app
.
active
:
r
,
w
,
x
=
select
.
select
([
chan
],
[],
[])
if
chan
in
r
:
data
=
chan
.
recv
(
1024
)
if
not
len
(
data
):
break
socket_io
.
emit
(
'data'
,
data
,
room
=
sid
)
del
clients
[
sid
]
def
handle
(
p
):
while
True
:
r
,
w
,
x
=
select
.
select
([
p
],
[],
[])
if
p
in
r
:
data
=
p
.
recv
(
1024
)
if
len
(
data
)
==
0
:
break
print
(
"Recieve client:
%
s"
%
data
)
# Todo: flask app logger using
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