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
299f0aa9
Commit
299f0aa9
authored
Feb 20, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fixture] 完成terminal连接
parent
09dbf394
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
18 deletions
+26
-18
luna.py
luna/luna.py
+1
-1
views.py
luna/views.py
+11
-17
run_server.py
run_server.py
+14
-0
No files found.
luna/luna.py
View file @
299f0aa9
...
...
@@ -57,5 +57,5 @@ class Luna(Flask, AppMixin):
async_mode
=
None
app
=
Luna
(
__name__
,
template_folder
=
'dist'
)
socket_io
=
socketio
.
Server
(
logger
=
True
,
async_mode
=
async_mode
)
socket_io
=
socketio
.
Server
(
logger
=
True
,
async_mode
=
'threading'
)
app
.
wsgi_app
=
socketio
.
Middleware
(
socket_io
,
app
.
wsgi_app
)
luna/views.py
View file @
299f0aa9
...
...
@@ -59,13 +59,14 @@ def handle_term_connect(sid, environ):
def
handle_machine
(
sid
,
message
):
clients
[
sid
][
'host'
]
=
host
=
'192.168.152.129'
clients
[
sid
][
'port'
]
=
port
=
22
# t = threading.Thread(target=forward, args=(sid,))
# t.setDaemon(True)
# t.start()
global
thread
if
thread
is
None
:
thread
=
socket_io
.
start_background_task
(
forward
,
sid
)
socket_io
.
emit
(
'data'
,
'Connect to
%
s:
%
s'
%
(
host
,
port
),
room
=
sid
)
t
=
threading
.
Thread
(
target
=
forward
,
args
=
(
sid
,))
t
.
setDaemon
(
True
)
t
.
start
()
# global thread
# if thread is None:
# thread = socket_io.start_background_task(forward, sid)
socket_io
.
emit
(
'data'
,
'Connect to
%
s:
%
s
\r\n
'
%
(
host
,
port
),
room
=
sid
)
print
(
t
.
is_alive
())
@socket_io.on
(
'data'
)
...
...
@@ -83,8 +84,8 @@ def handle_term_disconnect(sid):
@socket_io.on
(
'resize'
)
def
handle_term_resize
(
sid
,
json
):
print
(
'term resize: '
+
str
(
json
))
p
ass
p
rint
(
json
)
def
forward
(
sid
):
...
...
@@ -94,12 +95,6 @@ def forward(sid):
except
KeyError
as
e
:
socket_io
.
emit
(
'data'
,
e
,
room
=
sid
)
return
for
i
in
range
(
1
,
10
):
socket_io
.
emit
(
'data'
,
'Forwarding
\r\n
'
)
socket_io
.
emit
(
'data'
,
'Forwarding
\r\n
'
)
socket_io
.
sleep
(
1
)
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
connect
(
host
,
port
=
port
,
username
=
'root'
,
password
=
'redhat'
)
...
...
@@ -111,5 +106,4 @@ def forward(sid):
data
=
chan
.
recv
(
1024
)
if
not
len
(
data
):
break
print
(
'Sending data:
%
s'
%
data
)
socket_io
.
emit
(
'data'
,
'What is'
)
socket_io
.
emit
(
'data'
,
data
,
room
=
sid
)
run_server.py
View file @
299f0aa9
...
...
@@ -17,5 +17,19 @@ if __name__ == '__main__':
import
eventlet
import
eventlet.wsgi
eventlet
.
wsgi
.
server
(
eventlet
.
listen
((
''
,
5000
)),
app
)
elif
socket_io
.
async_mode
==
'gevent'
:
# deploy with gevent
from
gevent
import
pywsgi
try
:
from
geventwebsocket.handler
import
WebSocketHandler
websocket
=
True
except
ImportError
:
websocket
=
False
if
websocket
:
pywsgi
.
WSGIServer
((
''
,
5000
),
app
,
handler_class
=
WebSocketHandler
)
.
serve_forever
()
else
:
pywsgi
.
WSGIServer
((
''
,
5000
),
app
)
.
serve_forever
()
else
:
print
(
'Unkonw async_mode: '
+
socket_io
.
async_mode
)
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