diff --git a/plugins/webssh/index.py b/plugins/webssh/index.py index c8377c34b..d022b17d6 100755 --- a/plugins/webssh/index.py +++ b/plugins/webssh/index.py @@ -15,6 +15,7 @@ class App(): __cmd_file = 'cmd.json' __cmd_path = '' + __host_dir = '' def __init__(self): self.__cmd_path = self.getServerDir() + '/' + self.__cmd_file @@ -22,6 +23,10 @@ class App(): if not os.path.exists(self.__cmd_path): mw.writeFile(self.__cmd_path, '[]') + self.__host_dir = self.getServerDir() + '/host' + if not os.path.exists(self.__host_dir): + os.makedirs(self.__host_dir) + def getPluginName(self): return 'webssh' @@ -103,13 +108,74 @@ class App(): alist = json.loads(mw.readFile(self.__cmd_path)) return mw.returnJson(True, 'ok', alist) + def getSshInfo(self, file): + rdata = mw.readFile(file) + return json.loads(rdata) + + 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 = {} + host_info['host'] = name + host_info['port'] = info_tmp['port'] + host_info['ps'] = info_tmp['ps'] + # host_info['sort'] = int(info_tmp['sort']) + except Exception as e: + print(e) + # if os.path.exists(info_file): + # os.remove(info_file) + # continue + + host_list.append(host_info) + + host_list = sorted(host_list, key=lambda x: x['host'], reverse=False) + return mw.returnJson(True, 'ok!', host_list) + + def del_server(self): + args = self.getArgs() + check = self.checkArgs(args, ['host']) + if not check[0]: + return check[1] + host = args['host'] + info_file = self.__host_dir + '/' + host + mw.execShell('rm -rf {}'.format(info_file)) + return mw.returnJson(True, '删除成功!') + def add_server(self): args = self.getArgs() check = self.checkArgs( - args, ['host', 'port', 'username', 'password', 'pkey', 'pkey_passwd', 'ps']) + args, ['host', 'port', 'type', 'username', 'ps']) if not check[0]: return check[1] + host = args['host'] + info = { + 'port': args['port'], + 'username': args['username'], + 'ps': args['ps'], + 'type': args['type'], + } + + if args['type'] == '0': + info['password'] = args['password'] + else: + info['pkey'] = args['pkey'] + info['pkey_passwd'] = args['pkey_passwd'] + + dst_host_dir = self.__host_dir + '/' + host + if not os.path.exists(dst_host_dir): + os.makedirs(dst_host_dir) + + mw.writeFile(dst_host_dir + '/info.json', json.dumps(info)) + return mw.returnJson(True, '添加成功!') + if __name__ == "__main__": func = sys.argv[1] classApp = App() diff --git a/plugins/webssh/js/webssh.js b/plugins/webssh/js/webssh.js index dd870d1bc..289fcd0bc 100755 --- a/plugins/webssh/js/webssh.js +++ b/plugins/webssh/js/webssh.js @@ -59,6 +59,13 @@ function appPostCallbak(method, args, callback){ } $(document).ready(function(){ + var tag = $.getUrlParam('tag'); + if(tag == 'webssh'){ + webShell_Load(); + } +}); + +function webShell_Load(){ changeDivH(); $(window).resize(function(){ changeDivH(); @@ -101,6 +108,7 @@ $(document).ready(function(){ }); //服务器列表和常用命令 + webShell_getHostList();//默认调用 $('.term_tootls .tab-nav span').click(function(){ var list_type = $(this).attr('data-type'); if (!$(this).hasClass('on')){ @@ -111,6 +119,7 @@ $(document).ready(function(){ $('.term_tootls .tab-con .tab-block').removeClass('on') if (list_type == 'host'){ $('.term_tootls .tab-con .tab-block').eq(0).addClass('on'); + webShell_getHostList(); } if (list_type == 'shell'){ @@ -120,20 +129,17 @@ $(document).ready(function(){ } }); - webShell_Menu(); -}); + // webShell_Menu(); +} function changeDivH(){ var l = $(window).height(); $('#term_box_view').parent().css('height',l-80); - $('#xterm-viewport').css('height',l-80); - $('.tootls_host_list').css('display','block').css('height',l-192); - $('.tootls_commonly_list').css('display','block').css('height',l-192); - + $('.tootls_commonly_list').css('display','block').css('height',l-192); } @@ -198,7 +204,7 @@ function webShell_getCmdList(){ for (var i = 0; i < alist.length; i++) { tli+='