From d66e9d7fc6022305924354fb631fd23d22cb9d32 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 23 Jan 2023 04:09:25 +0800 Subject: [PATCH] up --- plugins/webssh/index.py | 2 -- plugins/webssh/js/webssh.js | 11 ++++++-- route/__init__.py | 44 ++++++++++++++++++++++++++++- route/templates/default/layout.html | 1 + 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/plugins/webssh/index.py b/plugins/webssh/index.py index d022b17d6..8e410b5ae 100755 --- a/plugins/webssh/index.py +++ b/plugins/webssh/index.py @@ -114,12 +114,10 @@ class App(): def get_server_list(self): host_list = [] - for name in os.listdir(self.__host_dir): info_file = self.__host_dir + '/' + name + '/info.json' if not os.path.exists(info_file): continue - try: info_tmp = self.getSshInfo(info_file) host_info = {} diff --git a/plugins/webssh/js/webssh.js b/plugins/webssh/js/webssh.js index 289fcd0bc..70565d912 100755 --- a/plugins/webssh/js/webssh.js +++ b/plugins/webssh/js/webssh.js @@ -1,4 +1,7 @@ + + + function appPost(method,args,callback){ var _args = null; if (typeof(args) == 'string'){ @@ -129,7 +132,7 @@ function webShell_Load(){ } }); - // webShell_Menu(); + webShell_Menu2(); } @@ -239,6 +242,10 @@ function webShell_getCmdList(){ } +function webShell_Menu2(){ + new Terms('#ECFEfRWM8', { ssh_info: { host: "127.0.0.1", ps: "22", id: 'ECFEfRWM8' } }); +} + function webShell_Menu() { var termCols = 83; var termRows = 20; @@ -249,7 +256,7 @@ function webShell_Menu() { term.open(); term.setOption('cursorBlink', true); term.setOption('fontSize', 14); - gterm = term + gterm = term; socket.on('server_response', function (data) { term.write(data.data); diff --git a/route/__init__.py b/route/__init__.py index a67280a89..3c9cabfc4 100755 --- a/route/__init__.py +++ b/route/__init__.py @@ -8,6 +8,7 @@ import shutil import uuid import json import traceback +import socket # reload(sys) # sys.setdefaultencoding('utf-8') @@ -27,6 +28,7 @@ from flask import render_template_string, abort from flask_caching import Cache from flask_session import Session + from whitenoise import WhiteNoise sys.path.append(os.getcwd() + "/class/core") @@ -67,6 +69,10 @@ app.config['SESSION_USE_SIGNER'] = True app.config['SESSION_KEY_PREFIX'] = 'MW_:' app.config['SESSION_COOKIE_NAME'] = "MW_VER_1" app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=31) + +if mw.isAppleSystem(): + app.config['DEBUG'] = True + # Session(app) # 设置BasicAuth @@ -88,6 +94,10 @@ from flask_socketio import SocketIO, emit, send socketio = SocketIO() socketio.init_app(app) +# sockets +from flask_sockets import Sockets +sockets = Sockets(app) + # from gevent.pywsgi import WSGIServer # from geventwebsocket.handler import WebSocketHandler # http_server = WSGIServer(('0.0.0.0', '7200'), app, @@ -637,9 +647,41 @@ def connect_ssh(): return True +# methods=["GET", "OPTIONS", "HEAD"] +# pip3 install flask==1.1.2 +# pip3 install Werkzeug==1.0.1 +@sockets.route('/webssh', methods=["GET", "OPTIONS", "HEAD"]) +def webssh(ws): + print("connection start") + while not ws.closed: + msg = ws.receive() # 同步阻塞 + print(msg) + now = datetime.datetime.now().isoformat() + ws.send(now) # 发送数据 + time.sleep(1) + + +# def handle_route_websocket(app_socket): +# @app_socket.route('/webssh') +# def page_websocket_test(ws): +# now = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) +# while not ws.closed: +# # 回传给clicent +# message = ws.receive() # 接收到消息 +# if message is not None: +# print("client says(%s): %s" % (now, message)) +# ws.send(str("回执:server已收到消息!-- %s " % now)) +# ws.send(str(json.dumps(message))) # 回传给clicent +# else: +# print(now, "no receive") + + +# handle_route_websocket(sockets) + + @socketio.on('webssh') def webssh(msg): - # print('webssh ...') + print('webssh cmd:' + msg) if not isLogined(): emit('server_response', {'data': '会话丢失,请重新登陆面板!\r\n'}) return None diff --git a/route/templates/default/layout.html b/route/templates/default/layout.html index 830a2bdbd..fd92b8308 100755 --- a/route/templates/default/layout.html +++ b/route/templates/default/layout.html @@ -75,6 +75,7 @@ +