From 9c31d76442ccc60743ce5234b40df9ffa4eeec15 Mon Sep 17 00:00:00 2001 From: midoks Date: Sat, 1 Jul 2023 21:34:04 +0800 Subject: [PATCH] docker update --- plugins/docker/index.py | 42 +++++++++++++++++++++++++++++++++ plugins/docker/js/docker.js | 36 +++++++++++++++++++++++----- plugins/tgclient/js/tgclient.js | 1 + 3 files changed, 73 insertions(+), 6 deletions(-) diff --git a/plugins/docker/index.py b/plugins/docker/index.py index 72c19df80..0eecf1b76 100755 --- a/plugins/docker/index.py +++ b/plugins/docker/index.py @@ -233,6 +233,44 @@ def dockerLogCon(): return mw.returnJson(False, 'Get Logs failed') +def dockerRunCon(): + # 启动容器 + args = getArgs() + data = checkArgs(args, ['Hostname']) + if not data[0]: + return data[1] + + Hostname = args['Hostname'] + c = getDClient() + try: + conFind = c.containers.get(Hostname) + if not conFind: + return mw.returnJson(False, 'The specified container does not exist!') + conFind.start() + return mw.returnJson(True, '启动成功!') + except docker.errors.APIError as ex: + return mw.returnJson(False, '启动失败!' + str(ex)) + + +def dockerStopCon(): + # 停止容器 + args = getArgs() + data = checkArgs(args, ['Hostname']) + if not data[0]: + return data[1] + + Hostname = args['Hostname'] + c = getDClient() + try: + conFind = c.containers.get(Hostname) + if not conFind: + return mw.returnJson(False, 'The specified container does not exist!') + conFind.stop() + return mw.returnJson(True, '停止成功!') + except docker.errors.APIError as ex: + return mw.returnJson(False, '停止失败!' + str(ex)) + + def imageList(): imageList = [] c = getDClient() @@ -428,6 +466,10 @@ if __name__ == "__main__": print(dockerLogCon()) elif func == 'docker_remove_con': print(dockerRemoveCon()) + elif func == 'docker_run_con': + print(dockerRunCon()) + elif func == 'docker_stop_con': + print(dockerStopCon()) elif func == 'image_list': print(imageListData()) elif func == 'docker_remove_image': diff --git a/plugins/docker/js/docker.js b/plugins/docker/js/docker.js index 2605ec956..afc90a81c 100755 --- a/plugins/docker/js/docker.js +++ b/plugins/docker/js/docker.js @@ -94,9 +94,29 @@ function deleteCon(Hostname){ }); } + +function startCon(Hostname){ + dPost('docker_run_con','',{Hostname:Hostname},function(rdata){ + var rdata = $.parseJSON(rdata.data); + layer.msg(rdata.msg,{icon:rdata.status?1:2}); + if(rdata.status) { + dockerConListRender(); + } + }); +} + +function stopCon(Hostname){ + dPost('docker_stop_con','',{Hostname:Hostname},function(rdata){ + var rdata = $.parseJSON(rdata.data); + layer.msg(rdata.msg,{icon:rdata.status?1:2}); + if(rdata.status) { + dockerConListRender(); + } + }); +} + function dockerConListRender(){ dPost('con_list', '', {}, function(rdata){ - // console.log(rdata); var rdata = $.parseJSON(rdata.data); console.log(rdata); if (!rdata.status){ @@ -109,8 +129,10 @@ function dockerConListRender(){ var rlist = rdata.data; for (var i = 0; i < rlist.length; i++) { + var docker_status = 'stop'; var status = ''; if (rlist[i]['State']['Status'] == 'running'){ + docker_status = 'start'; status = ''; } @@ -119,12 +141,17 @@ function dockerConListRender(){ op += '日志 | '; op += '删除'; - list += ''; list += ''+rlist[i]['Name'].substring(1)+''; list += ''+rlist[i]['Config']['Image']+''; list += ''+getFormatTime(rlist[i]['Created'])+''; - list += ''+status+''; + + + if (docker_status == 'start'){ + list += ''+status+''; + } else{ + list += ''+status+''; + } list += ''+op+''; list += ''; } @@ -136,9 +163,6 @@ function dockerConList(){ var con = '
\ \ - \ - \ - \
\
\ \ diff --git a/plugins/tgclient/js/tgclient.js b/plugins/tgclient/js/tgclient.js index 1b1b403e8..39b11fac1 100755 --- a/plugins/tgclient/js/tgclient.js +++ b/plugins/tgclient/js/tgclient.js @@ -2,6 +2,7 @@ function readme(){ var readme = '
    '; readme += '
  • 在填写好配置信息好后,还要执行下面命令。进行手机号和短信码验证。再重启,即可正常使用
  • '; readme += '
  • cd /www/server/mdserver-web && source bin/activate && python3 /www/server/tgclient/tgclient.py
  • '; + readme += '
  • https://my.telegram.org/auth
  • '; readme += '
'; $('.soft-man-con').html(readme); }