From 3437d2e4841e20a026846774e4707b7c369b0bc6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 1 Jun 2024 12:17:10 +0800 Subject: [PATCH 001/121] Update php.js --- plugins/php/js/php.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/php/js/php.js b/plugins/php/js/php.js index 5c369d2ba8..0e041ad546 100755 --- a/plugins/php/js/php.js +++ b/plugins/php/js/php.js @@ -26,7 +26,7 @@ function phpPost(method, version, args,callback){ },'json'); } -function phpPostCallbak(method, version, args,callback){ +function phpPostCallback(method, version, args,callback){ var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); var req_data = {}; @@ -715,7 +715,7 @@ function getPHPInfo_old(version) { } function getPHPInfo(version) { - phpPostCallbak('get_php_info', version, {}, function(data){ + phpPostCallback('get_php_info', version, {}, function(data){ if (!data.status){ layer.msg(rdata.msg, { icon: 2 }); return; @@ -739,7 +739,7 @@ function phpLibConfig(version){ // var rdata = $.parseJSON(rdata.data); // }); - phpPostCallbak('get_lib_conf', version, {}, function(rdata){ + phpPostCallback('get_lib_conf', version, {}, function(rdata){ var rdata = rdata.data; if (!rdata.status){ From 8f3e722a0f9cc8b38646719b3d72f1860528ae8b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 3 Jun 2024 00:43:38 +0800 Subject: [PATCH 002/121] Update .gitignore --- .gitignore | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 806ca813f5..e2ef12599c 100644 --- a/.gitignore +++ b/.gitignore @@ -115,7 +115,22 @@ tmp/* *.swp *.pem *.zip +debug.out +mdioks.session-journal +*.session + logs/* + +ssl/local +ssl/nginx +ssl/choose.pl + +scripts/init.d/mw +scripts/mdserver-web + +data/api_login.txt +data/sessions + data/*.db data/iplist.txt data/json/index.json @@ -131,12 +146,6 @@ data/debug.pl data/default_site.pl data/ssl.pl -scripts/init.d/mw -scripts/mdserver-web - -data/api_login.txt -data/sessions - data/port.pl data/ipv6.pl data/restart.pl @@ -153,10 +162,6 @@ data/bind_domain.pl data/unauthorized_status.pl data/auth_secret.pl -ssl/local -ssl/nginx -ssl/choose.pl - plugins/vip_* plugins/own_* plugins/my_* @@ -175,8 +180,4 @@ plugins/frp plugins/file_search plugins/proxysql plugins/tidb -debug.out - - -mdioks.session-journal -*.session +plugins/task_manager From 6783e1507dbdafe2278b9aa04d6de2f867f1697f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 3 Jun 2024 12:10:59 +0800 Subject: [PATCH 003/121] Update mysql.js --- plugins/mysql/js/mysql.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index ca65c75701..bafe7cfc4b 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2936,10 +2936,10 @@ function masterOrSlaveConf(version=''){ getMasterDbList(); } - if (rdata.slave_status){ + // if (rdata.slave_status){ getAsyncMasterDbList(); getAsyncDataList() - } + // } }); } getMasterStatus(); From 19a4974537c6854800d11d606142d6a7c44f4769 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 3 Jun 2024 23:09:30 +0800 Subject: [PATCH 004/121] Update stats.js --- plugins/webstats/js/stats.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/webstats/js/stats.js b/plugins/webstats/js/stats.js index 570329d973..29aa9730d7 100644 --- a/plugins/webstats/js/stats.js +++ b/plugins/webstats/js/stats.js @@ -2420,8 +2420,9 @@ var html = '
\ \ \ \ - \ + \ \ + \ \ \ \ From 6c40e57ff6a95ec771c7afd93e6aa2e922d99947 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:19:15 +0800 Subject: [PATCH 005/121] update --- .gitignore | 1 - plugins/task_manager/ico.png | Bin 0 -> 455 bytes plugins/task_manager/index.html | 554 ++++++++ plugins/task_manager/index.py | 62 + plugins/task_manager/info.json | 17 + plugins/task_manager/install.sh | 33 + plugins/task_manager/js/task_manager.js | 1103 +++++++++++++++ plugins/task_manager/process_network_total.py | 318 +++++ plugins/task_manager/task_manager_index.py | 1182 +++++++++++++++++ 9 files changed, 3269 insertions(+), 1 deletion(-) create mode 100644 plugins/task_manager/ico.png create mode 100755 plugins/task_manager/index.html create mode 100755 plugins/task_manager/index.py create mode 100755 plugins/task_manager/info.json create mode 100755 plugins/task_manager/install.sh create mode 100644 plugins/task_manager/js/task_manager.js create mode 100644 plugins/task_manager/process_network_total.py create mode 100755 plugins/task_manager/task_manager_index.py diff --git a/.gitignore b/.gitignore index e2ef12599c..f19ace7587 100644 --- a/.gitignore +++ b/.gitignore @@ -180,4 +180,3 @@ plugins/frp plugins/file_search plugins/proxysql plugins/tidb -plugins/task_manager diff --git a/plugins/task_manager/ico.png b/plugins/task_manager/ico.png new file mode 100644 index 0000000000000000000000000000000000000000..60fa27d663a8f3f63ce92e95d426e73d37ea97cf GIT binary patch literal 455 zcmeAS@N?(olHy`uVBq!ia0vp^20*OA!VDz6R;D-sDdu7)&kzm{j@u9Y9{{-q0X`wF z|Ns9_BLytWVF%eEP!i-9%pj;_>=K$*-Z694?lX7a{V$u!C<>J0EbxddW?4=TCI1#TvI-O)`}#s?Kg$83nEzH64*cd!;M^zwBJKSC2IoccdIy&*S<(^e1oXsv zg>;Ul28LxU=dA@QS~L%Gm%T~%;Z#c&FgP&fK-N$GHA0U{?YlR68GNWa_Rf**o_>Jg z)-79H)(HJvaW3`2-!vY^zb}M5Ha03Ta`Grt^s6y)+9|AXpWMJ)a{8geksCJzR +/*任务管理器*/ +.man-menu-sub { + background-color: #fff; + border-bottom: 1px solid #ccc; + height: 50px; + display: flex; + flex-direction: row; + justify-content: space-between; + flex-wrap: nowrap; + align-items: center; +} + +.t-mana .table > tbody > tr.active td { + background-color: #E4EEE0; +} + +.search-bar { +} + +.search-bar .search_input { + height: 30px; + line-height: 30px; + border-radius: 2px; + border: 1px solid #ccc; + outline: none; + padding-left: 8px; + vertical-align: top; + width: 230px; +} + +.search-bar .search_input:focus { + border-color: #20a53a; + + span.glyphicon-search { + color: #20a53a; + } +} + +.search-bar .glyphicon { + position: relative; + top: 1px; + display: inline-block; + font-family: 'Glyphicons Halflings'; + font-style: normal; + font-weight: 400; + line-height: 1; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.search-bar .glyphicon-search { + height: 28px; + line-height: 28px; + padding: 0 10px; + color: #888; + position: absolute; + right: 14px; + top: 11px; + font-size: 14px; + cursor: pointer; +} +.r56 { + right: 56px !important; +} + +.man-menu-sub { + background-color: #fff; + border-bottom: 1px solid #ccc; + height: 50px; +} + +.man-menu-sub span { + padding: 14px 15px; + cursor: pointer; + display: inline-block; + font-size: 14px; +} + +.man-menu-sub .on { + border-bottom: 2px solid #20a53a; + color: #20a53a; + font-weight: bold; +} + +.soft-ico-min { + display: inline-block; + width: 16px; + margin-right: 5px; +} + +.soft-ico-min img { + width: 16px; +} + +.table-cont { + height: 500px; + overflow: auto; + border: #ddd 1px solid; + position: relative; +} + +.ts-line { + position: absolute; + top: 99px; + height: 1px; + background-color: #ddd; + left: 16px; + z-index: 2; +} + +.t-mana .bt-ico-ask { + height: 14px; + width: 14px; + line-height: 14px; +} + +.mini-info { + width: 100%; + border-top: #DBDBEA 1px solid; + background-color: #f6f6f6; + padding: 15px; +} + +.mini-info-box { + width: 500px; + margin: 0 auto; + background-color: #fff; + border: #DBDBEA 1px solid; + border-radius: 6px; + height: 66px; + box-shadow: 0 0 40px #eee; +} + +.mini-info-con { + float: left; + height: 100%; + width: 33%; + line-height: 26px; + padding: 6px 16px; +} + +.mini-info-con:nth-of-type(2) { + border-left: #DBDBEA 1px solid; + border-right: #DBDBEA 1px solid; + width: 34%; +} + +.mini-info-con p { + text-align: right; + position: relative; +} + +.mini-info-con .tname { + display: inline-block; + position: absolute; + left: 0; +} + +.mini-level { + border: #ddd 1px solid; + width: 166px; + background-color: #fff; + border-radius: 6px; + margin: 0 auto; + height: 66px; + line-height: 66px; + text-align: center; +} + +.jc-detail .tname { + font-size: 12px; + font-weight: bold; + margin-right: 10px; +} + +.jc-detail h3.tname { + margin-bottom: 10px; + margin-top: 15px; + color: #999; +} + +.jc-detail .jc-info { + margin: 10px 0; + border-bottom: #ddd 1px solid; + padding-bottom: 10px; +} + +#TaskManagement .td-pid { + /* display: flex; */ + /* border-top: #ddd 2px solid; */ + /* height: 38px; */ + /* height: 100%; */ + /* margin-top: 1px; */ +} + +.td-pid img { + /* margin-right: 8px; */ + /* display: inline-block; */ + float: left; + cursor: pointer; + /* position: relative; + left: -80px; + filter: drop-shadow(#fff 80px 0); */ + /* position: relative; + left: -80px; + filter: drop-shadow(#238B37 0 80px); */ +} + +.td-pid svg { + float: left; + cursor: pointer; +} + +.td-pid .colp { + transform: rotate(-90deg); + -moz-transform: rotate(-90deg); + -webkit-transform: rotate(-90deg); +} + +.td-pid .arrow:hover { + filter: drop-shadow(#999999 0 0) +} + +.td-pid .process-child { + margin-left: 50px; + /* display: none; */ +} + +.td-pid span { + display: inline-block; + float: right; +} + +.td-pid a { + display: block; + margin-left: 30px; +} + +#TaskManagement th: { + height: 34px; +} + +#TaskManagement tr: { + height: 38px; +} + +#TaskManagement tr:hover { + /* background-color: rgb(245, 247, 250,0.6); */ + background-color: rgb(246, 246, 246, 0.65); +} + +#TaskManagement .process-select { + /* background-color: rgb(242, 242, 242); */ + /* background-color: rgb(245, 247, 250,0.6); */ + background-color: rgb(246, 246, 246, 0.6); + /* background-color: rgb(246, 246, 246,0.65); */ +} + +#taskResourceTable .process-select { + /* background-color: rgb(242, 242, 242); */ + background-color: #F1F9F3; +} + +#TaskManagement .process-select:hover { + /* background-color: rgb(211, 210, 210); */ + /* background-color: rgb(245, 247, 250); */ + background-color: rgb(246, 246, 246); + /* border: 1px solid #ddd; + box-sizing: border-box; */ +} + +#taskResourceTable .process-select:hover { + /* background-color: rgb(211, 210, 210); */ + background-color: #BCE4C4; +} + +.resource-panel { + display: none; + width: 100%; + height: 700px; + /* height: 300px; */ +} + +.resource-tab { + float: left; + width: 100px; + height: 300px; + background-color: thistle; +} + +.resource-right { + margin-left: 100px; + /* width: 100%; */ + /* background-color: gray; */ + /* height: 600px; */ +} + +.resource-panel-show { + display: block; +} + +.divtable-hide { + display: none; + /* visibility: hidden; */ +} + +.resource-tab span { + display: block; + height: 30px; + line-height: 30px; + text-align: center; + cursor: pointer; +} + +.resource-tab span:hover { + background-color: #ccc; +} + +.plug_menu { + display: none; +} +.plug_menu .setting_ul::after{ + display: none; +} +.plug_menu .setting_ul.undisplay::after { + content: ''; + position: absolute; + color: #fff; + width: 12px; + height: 12px; + font-size: 14px; + top: -7px; + right: 8px; + display: inline-block; + background: #fff; + transform: rotate(-45deg); + border-top: 1px solid rgba(0, 0, 0, 0.25); + border-right: 1px solid rgba(0, 0, 0, 0.25); +} + +.set_list_fid_dropdown { + display: inline-block; + line-height: 30px; + margin-left: 10px; + position: relative; + vertical-align: bottom; +} +.set_list_fid_dropdown .setting_btn { + border: 1px solid #ccc; + height: 30px; + width: 30px; + border-radius: 4px; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; +} +.set_list_fid_dropdown .setting_btn:hover{ + background: #e9f6eb; + border-color: #bce4c4; +} +.set_list_fid_dropdown .icon-setting { + color: rgb(102, 102, 102); +} +.set_list_fid_dropdown .setting_btn:hover .icon-setting { + color: #20a53a; +} +.set_list_fid_dropdown .setting_ul { + position: absolute; + z-index: 99; + background: #fff; + width: 150px; + right: 0; + border-radius: 4px; + box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25); + padding: 10px 0; + margin-top: 10px; + display: none; +} +.set_list_fid_dropdown .setting_ul::after { + content: ''; + position: absolute; + color: #fff; + width: 12px; + height: 12px; + font-size: 14px; + top: -7px; + right: 8px; + display: inline-block; + background: #fff; + transform: rotate(-45deg); + border-top: 1px solid rgba(0, 0, 0, 0.25); + border-right: 1px solid rgba(0, 0, 0, 0.25); +} +.setting_ul .setting_ul_li{ + display: flex; + align-items: center; + line-height: 27px; + padding: 0 16px; + cursor: pointer; +} +.setting_ul .setting_ul_li:hover{ + background: #e9f6eb; +} +.setting_ul .setting_ul_li.disabled { + cursor: not-allowed; +} + +.setting_ul .setting_ul_li i { + display: inline-block; + width: 16px; + height: 16px; + border: 1px solid #ccc; + background-color: #fff; + vertical-align: top; + position: relative; + border-radius: 2px; +} +.setting_ul .setting_ul_li.active i { + background-color: #20a53a; + border-color: #20a53a; +} +.setting_ul .setting_ul_li.disabled i { + background-color: #edf2fc; + border-color: #dcdfe6; +} +.setting_ul .setting_ul_li.active.disabled i { + background-color: #f2f6fc; + border-color: #dcdfe6; +} +.setting_ul .setting_ul_li.active.disabled i::after{ + border: solid #dcdfe6; + border-width: 0 2px 2px 0; +} +.setting_ul .setting_ul_li.active i::after{ + content: ''; + position: absolute; + display: block; + left: 50%; + top: 50%; + margin-left: -2px; + margin-top: -6px; + width: 5px; + height: 10px; + border: solid #fff; + border-width: 0 2px 2px 0; + transform: rotate(45deg); +} + + +
+
+
+ 进程 + + 启动项 + 服务 + 网络 + 用户 + 计划任务 + 会话 +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+ CPU + 内存 + 磁盘 +
+ +
+
+
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+ + + + diff --git a/plugins/task_manager/index.py b/plugins/task_manager/index.py new file mode 100755 index 0000000000..f2f22f90ee --- /dev/null +++ b/plugins/task_manager/index.py @@ -0,0 +1,62 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import re + +sys.path.append(os.getcwd() + "/class/core") +import mw + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'task_manager' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + +def getArgs(): + args = sys.argv[3:] + tmp = {} + args_len = len(args) + + if args_len == 1: + t = args[0].strip('{').strip('}') + if t.strip() == '': + tmp = [] + else: + t = t.split(':') + tmp[t[0]] = t[1] + tmp[t[0]] = t[1] + elif args_len > 1: + for i in range(len(args)): + t = args[i].split(':') + tmp[t[0]] = t[1] + return tmp + +def checkArgs(data, ck=[]): + for i in range(len(ck)): + if not ck[i] in data: + return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) + return (True, mw.returnJson(True, 'ok')) + +def status(): + return 'start' + + +if __name__ == "__main__": + func = sys.argv[1] + if func == 'status': + print(status()) + else: + print('error') diff --git a/plugins/task_manager/info.json b/plugins/task_manager/info.json new file mode 100755 index 0000000000..bdfcdda38c --- /dev/null +++ b/plugins/task_manager/info.json @@ -0,0 +1,17 @@ +{ + "sort": 7, + "ps": "轻松管理进程、流量监控、启动项、用户、服务、计划任务、会话[开发中]", + "name": "task_manager", + "title": "任务管理器", + "shell": "install.sh", + "versions":"1.0", + "tip": "soft", + "checks": "server/task_manager", + "path": "server/task_manager", + "display": 1, + "author": "task_manager", + "date": "2024-06-01", + "home": "task_manager", + "type": 0, + "pid": "4" +} \ No newline at end of file diff --git a/plugins/task_manager/install.sh b/plugins/task_manager/install.sh new file mode 100755 index 0000000000..6cb2d35978 --- /dev/null +++ b/plugins/task_manager/install.sh @@ -0,0 +1,33 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin +export PATH + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") + +install_tmp=${rootPath}/tmp/mw_install.pl +VERSION=$2 + +Install_App() +{ + echo '正在安装脚本文件...' > $install_tmp + mkdir -p $serverPath/task_manager + + echo "$VERSION" > $serverPath/task_manager/version.pl + echo "安装任务管理器成功" +} + +Uninstall_App() +{ + rm -rf $serverPath/task_manager + echo "卸载任务管理器成功" +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_App +else + Uninstall_App +fi diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js new file mode 100644 index 0000000000..413d045bd0 --- /dev/null +++ b/plugins/task_manager/js/task_manager.js @@ -0,0 +1,1103 @@ + +function tmPostCallback(method, args, callback, version='1.0'){ + var req_data = {}; + req_data['name'] = 'task_manager'; + req_data['func'] = method; + req_data['script']='task_manager_index'; + args['version'] = version; + + if (typeof(args) == 'string' && args == ''){ + req_data['args'] = JSON.stringify(toArrayObject(args)); + } else { + req_data['args'] = JSON.stringify(args); + } + + $.post('/plugins/callback', req_data, function(data) { + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + +var tab_name = 'p_list'; +var search_val = ''; +var select_pid = undefined; // 当前选中进程的id +var realProcess = []; // 进程数组 +var originProcess = []; // 当前进程展示的列表 +var wrapPid = {}; // 展开的父进程 +var TaskProcessLayerIndex = ''; // 进程详情弹窗的index +var canScroll2TaskMangerPossess = true; // 是否可以定位到选中的进程 + +$('.t-mana .man-menu-sub span').click(function () { + $(this).siblings().removeClass("on"); + tab_name = $(this).attr('class'); + $(this).addClass("on") + // console.log(tab_name); + if (tab_name == 'p_resource') { + $('.resource-panel').addClass('resource-panel-show') + $('.taskdivtable').addClass('divtable-hide') + $('.ts-line').addClass('divtable-hide') + } else if (tab_name !== 'p_resource on') { + $('.resource-panel').removeClass('resource-panel-show') + $('.taskdivtable').removeClass('divtable-hide') + $('.ts-line').removeClass('divtable-hide') + } + search_val = $('.search-bar .search_input').val('') + get_list_bytab(false); +}); + +$('.search-bar .search_input').on({ + 'keyup': function (e) { + if (e.keyCode == 13) { + get_list_bytab(); + } + }, + 'blur': function () { + get_list_bytab(true); + }, +}); + +$('.search-bar .glyphicon').click(function (e) { + get_list_bytab(); +}); + +var process_list_s = 0; +get_process_list(); + +function setTableHead(data) { + $.each(Object.keys(data.meter_head), function (index, item) { + if (!$('.' + item).hasClass('disabled')) { + if (data.meter_head[item]) { + $('.' + item).addClass('active'); + } else { + $('.' + item).removeClass('active'); + } + } + }); + + $('#change_thead').bind("contextmenu", function () { + return false; + }) + $(".plug_menu").bind("contextmenu", function () { + return false; + }) + $('#change_thead').mousedown(function (e) { + e.preventDefault(); + if (e.which == 3) { // 1 = 鼠标左键; 2 = 鼠标中键; 3 = 鼠标右键 + var menu = $('.setting_ul'); + var offset = $(this).offset(); + var x = e.pageX - offset.left; + var y = e.pageY - offset.top; + var width = menu.outerWidth(); + $(".plug_menu").removeAttr('style'); + $(".setting_ul").removeClass('undisplay'); + if ($('#change_thead').width() - x < width) { + $(".plug_menu").css({ + position: 'absolute', + left: x - width + 150 + "px", + top: y + 50 + "px", + }).show(); + } else { + $(".plug_menu").css({ + position: 'absolute', + left: x + width + "px", + top: y + 50 + "px", + }).show(); + } + } + $(".setting_ul").show(); + }); +} + + +$('.layui-layer').not($('.setting_ul_li')).click(function () { + $(".plug_menu").hide() + $(".setting_ul").hide(); +}); +var isProcessing = false; // 设置标志 + + $('.setting_ul_li').off('click').click(function (e) { + var that = $(this) + e.stopPropagation() + // 检查标志 + if (isProcessing) { + return; + } + if (!$(this).hasClass('disabled')) { + isProcessing = true; // 点击事件被触发,设置标志 + var name = $(this).attr("name") + clearInterval(process_list_s); + bt_tools.send({ + url: 'plugin?action=a&name=task_manager&s=set_meter_head', + data: {meter_head_name: name} + }, function (data) { + isProcessing = false; // 操作完成,清除标志 + if (!data) { + layer.msg('设置失败'); + } + that.toggleClass('active') + get_process_list(null, null, false); + clearInterval(process_list_s); + process_list_s = setInterval(function () { + if ($(".t-mana").length == 0) { + clearInterval(process_list_s); + process_list_s = 0; + console.log('进程列表轮询任务已停止'); + } + get_process_list(null, null, true); + }, 3000); + }) + } + }) + + $('.setting_btn').on('click',function (e) { + e.stopPropagation() + var offset = $('.man-menu-sub').offset(); + var x = e.pageX - offset.left; + var y = e.pageY - offset.top; + var width = $('.man-menu-sub').outerWidth(); + if ($('.man-menu-sub').width() - x < width) { + $(".plug_menu").css({ + position: 'absolute', + right: "14.5px", + top:"40px", + }).toggle(); + $('.setting_ul').addClass('undisplay') + } + $(".setting_ul").toggle(); + }) + + if (process_list_s === 0) { + process_list_s = setInterval(function () { + if ($(".t-mana").length == 0) { + clearInterval(process_list_s); + process_list_s = 0; + console.log('进程列表轮询任务已停止') + } + get_process_list(null, null, true); + }, 3000); + } + + function get_list_bytab(isblur) { + if (isblur && $('.search-bar .search_input').val() === search_val) { + return; + } + search_val = $('.search-bar .search_input').val(); + get_process_list(); + + switch (tab_name) { + case 'p_list': + $('.table_config').show(); + $('.search-bar span').addClass('r56'); + select_pid = '' + wrapPid = {} + canScroll2TaskMangerPossess = true + get_process_list(); + break; + case 'p_resource': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_resource_list(); + break; + case 'p_run': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_run_list(); + break; + case 'p_service': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_service_list(); + break; + case 'p_network': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_network_list(); + break; + case 'p_user': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_user_list(); + break; + case 'p_cron': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_cron_list(); + break; + case 'p_session': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_who_list(); + break; + } + } + +function get_process_list(sortx, reverse, rx) { + if ($('.t-mana .man-menu-sub .on').attr('class') != 'p_list on') return; + var cookie_key = 'task_process_sort'; + var s_tmp = getCookie(cookie_key); + if (sortx == undefined || sortx == null) { + if (s_tmp) { + sortx_arr = s_tmp.split('|'); + sortx = sortx_arr[0]; + reverse = sortx_arr[1]; + } else { + sortx = 'cpu_percent'; + } + } + + res_list = { + True: 'False', + False: 'True' + }; + setCookie(cookie_key, sortx + '|' + reverse); + if (!rx) { + var loadT = layer.msg('正在获取进程列表..', {icon: 16, time: 0, shade: [0.3, '#000']}) + } + + tmPostCallback('get_process_list', {sortx: sortx,reverse: reverse,search:search_val}, function(rdata){ + console.log(rdata); + if (!rx) layer.close(loadT); + if ($('.t-mana .man-menu-sub .on').attr('class') != 'p_list on') return; + if (rdata.status === false) { + layer.closeAll(); + layer.msg(rdata.msg, {icon: 2}); + return; + } + var data = rdata.data; + + var year = new Date().getFullYear(); + realProcess = []; + originProcess = []; + var list = data.process_list; + for (var i = 0; i < list.length; i++) { + list[i].haschild = false; + if (list[i].children && list[i].children.length > 0) { + list[i].haschild = true; + } + originProcess.push(list[i]); + realProcess.push(list[i]); + } + var selectline = buildRealProcess(); + var tbody_tr = createProcessTable(true, data); + var tbody = '\ + \ + 应用名称\ + PID\ + 线程\ + 用户\ + CPU\ + 内存\ + io读\ + io写\ + 上行\ + 下行\ + 连接\ + 状态\ + 操作\ + \ + \ + ' + tbody_tr + ''; + $("#TaskManagement").html(tbody); + var topMsg = '
\ +

CPU:' + data.info.cpu + '%

内存:' + toSize(data.info.mem) + '

\ +

负载(load average)

' + data.info.load_average[1] + ', ' + data.info.load_average[5] + ', ' + data.info.load_average[15] + '

\ +

进程数:' + data.process_list.length + '

磁盘:' + toSize(data.info.disk) + '

\ +
'; + $("#load_average").html(topMsg).show(); + $(".pro_" + sortx).append(''); + $(".table-cont").css("height", "500px"); + scropll2selectPossess(selectline); + show_task(); + setTableHead(data); + if(getCookie('table_config_tip')=='false'||!getCookie('table_config_tip')){ + layer.tips('点击可设置表头', '.setting_btn', { + tips: [1, '#20a53a'], + time: 3000 + }); + setCookie('table_config_tip',true); + } + // 清除掉之前绑定的滚动事件 + $("#table-cont").unbind('scroll'); + // 重新绑定滚动事件 + $('#table-cont').scroll(task_manager_possess_scroll()); + }); +} + +function task_manager_possess_scroll() { + var timer = null; + var set2selected = null + // 滚动节流 + return function () { + if (timer !== null) return + timer = setTimeout(function () { + timer = null + canScroll2TaskMangerPossess = false + if (set2selected !== null) clearTimeout(set2selected) + // 最后一次滚动后2秒内不再滚动,才能滚动到选中的行 + set2selected = setTimeout(function () { + canScroll2TaskMangerPossess = true + }, 2000) + }, 500) + } +} + +function scropll2selectPossess(selectline) { + if (canScroll2TaskMangerPossess && selectline !== -1) { + var top = $('#table-cont')[0].scrollTop; + // if(selectline > 2) + if (selectline * 38 > top + 500 || selectline * 38 < top) { + $('#table-cont')[0].scrollTo(0, (selectline - 2) * 38, 'smooth'); + } + } +} + +function show_process_child(pid) { + wrapPid[pid + ''] = true; + // buildRealProcess() + // createProcessTable() +} + +function colp_process_child(pid) { + // select_pid = pid+''; + wrapPid[pid + ''] = false; + // buildRealProcess() + // createProcessTable() +} + +function click_process_tr(e, pid, fpid) { + select_pid = pid + ''; + if (e.target.innerText === '结束' && fpid) { + select_pid = fpid + ''; + } + var selectline = buildRealProcess() + createProcessTable() + scropll2selectPossess(selectline) +} + +// 构建真实进程列表 +function buildRealProcess() { + realProcess = []; + var len = originProcess.length; + for (var i = 0; i < len; i++) { + realProcess.push(originProcess[i]); + if (wrapPid[originProcess[i].pid + '']) { + // console.log(originProcess[i]); + if (!originProcess[i].children) { + wrapPid[originProcess[i].pid + ''] = false; + continue; + } + var childSelected = false; + for (var j = 0; j < originProcess[i].children.length; j++) { + originProcess[i].children[j].fpid = originProcess[i].pid + '' + originProcess[i].children[j].ischild = true + originProcess[i].children[j].isselect = false + if (originProcess[i].pid + '' === select_pid) { + originProcess[i].children[j].isselect = true + } + if (originProcess[i].children[j].pid + '' === select_pid) { + var childSelected = true; + } + realProcess.push(originProcess[i].children[j]); + // 显示选中的父子进程 + } + if (childSelected) { + for (var k = 0; k <= originProcess[i].children.length; k++) { + realProcess.pop() + } + originProcess[i].isselect = true + realProcess.push(originProcess[i]) + for (var l = 0; l < originProcess[i].children.length; l++) { + originProcess[i].children[l].isselect = true + realProcess.push(originProcess[i].children[l]); + } + } + } + } + for (var i = 0; i < realProcess.length; i++) { + if (realProcess[i].pid + '' === select_pid) { + return i// 返回选中的下标 + } + } + return -1 +} + +// 生成进程表格内容 +function createProcessTable(getboday, data) { + console.log('createProcessTable',getboday, data); + console.log('realProcess',realProcess); + var tbody_tr = ''; + for (var i = 0; i < realProcess.length; i++) { + if (realProcess[i].status == '活动') realProcess[i].status = '活动'; + var colp = realProcess[i].haschild ? '\ + \ + ' : ''; + if (wrapPid[realProcess[i].pid + '']) { + colp = '\ + \ + '; + } + var childNums = realProcess[i].haschild ? '(' + realProcess[i].children.length + ')' : ''; + var namewidth = "max-width:120px;" + if (realProcess[i].ischild) { + namewidth = "max-width:80px;" + } + if (realProcess[i].haschild) { + namewidth = "max-width:100px;" + } + var processName = '' + realProcess[i].ps + ''; + var isProcessChild = realProcess[i].ischild ? 'process-child' : ''; + var childStyle = realProcess[i].ischild ? 'width:100px' : ''; + var selected = realProcess[i].pid + '' === select_pid || realProcess[i].isselect ? 'class="process-select"' : ''; + var selected_one = realProcess[i].pid + '' === select_pid ? 'style="background-color:#F6F6F6;"' : ''; + var kill_process = realProcess[i].haschild ? 'kill_process_all' : 'kill_process'; + + var tbody_td = ''; + if ('io_read_bytes' in realProcess[i]){ + tbody_td =+ '' + toSize(realProcess[i].io_read_speed).replace(' ', '') + ''; + tbody_td =+ '' + toSize(realProcess[i].io_write_speed).replace(' ', '') + ''; + } + + // ' + ToSize(realProcess[i].up).replace(' ', '') + '\ + // ' + ToSize(realProcess[i].down).replace(' ', '') + '\ + tbody_tr += '\ + \ + ' + colp + '\ + \ + ' + processName + '\ + ' + childNums + '\ + \ + ' + realProcess[i].pid + '\ + ' + realProcess[i].threads + '\ + ' + realProcess[i].user + '\ + ' + realProcess[i].cpu_percent + '%\ + ' + toSize(realProcess[i].memory_used).replace(' ', '') + '\ + '+tbody_td+'\ + ' + realProcess[i].connects + '\ + ' + realProcess[i].status + '\ + 结束\ + '; + } + if (getboday) return tbody_tr; + $("#TaskManagement tbody").html(tbody_tr); +} + +// 获取资源列表 +function get_resource_list() { + // console.log('get_resource_list----------'); + var url = '/plugin?action=a&name=task_manager&s=cpu_status' + // url = 'plugin?action=a&name=task_manager&s=get_disk_staus' + + var res_list = { + True: 'False', + False: 'True' + } + var reverse = 'True' + $.post(url, function (data) { + console.log(data); + realProcess = [] + originProcess = [] + var list = data.process_list + for (var i = 0; i < list.length; i++) { + list[i].haschild = false + if (list[i].children && list[i].children.length > 0) { + list[i].haschild = true + } + originProcess.push(list[i]) + realProcess.push(list[i]) + } + // console.log('realllll'); + + buildRealProcess() + var tbody_tr = createProcessTable(true) + var tbody = '\ + \ + 应用名称\ + PID\ + 线程\ + 用户\ + CPU\ + 内存\ + io读\ + io写\ + 上行\ + 下行\ + 连接\ + 状态\ + 操作\ + \ + \ + ' + tbody_tr + '' + $('#taskResourceTable').html(tbody); + $(".table-cont").css("height", "220px"); + }) + + $("#load_average").html('') +} + +//查看计划任务列表 +function get_cron_list() { + var loadT = layer.msg('获取计划任务列表..', {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('get_cron_list', {search:search_val}, function(rdata){ + layer.close(loadT); + var tbody_tr = ''; + for (var i = 0; i < rdata.length; i++) { + tbody_tr += '\ + ' + rdata[i].cycle + '\ + ' + rdata[i].exe + '\ + ' + rdata[i].ps + '\ + 删除\ + '; + } + var tbody = '\ + \ + 周期\ + 执行\ + 描述\ + 操作\ + \ + \ + ' + tbody_tr + ''; + $("#TaskManagement").html(tbody); + var topMsg = ''; + $("#load_average").html(topMsg).hide(); + $(".table-cont").css("height", "597px"); + show_task(); + }); +} + + +//查看网络状态 +function get_network_list(rflush) { + var loadT = layer.msg(lan.public.the_get, {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('get_network_list', {search:search_val}, function(rdata){ + layer.close(loadT); + if (rdata.data['is_mac']){ + tbody_tr += "mac无法使用"; + tbody = "\ + \ + " + lan.index.net_protocol + "\ + " + lan.index.net_address_dst + "\ + " + lan.index.net_address_src + "\ + " + lan.index.net_address_status + "?\ + " + lan.index.net_process + "\ + " + lan.index.net_process_pid + "\ + \ + \ + " + tbody_tr + ""; + $("#TaskManagement").html(tbody); + show_task(); + return; + } + + console.log(rdata); + + var tbody_tr = ""; + for (var i = 0; i < rdata.list.length; i++) { + tbody_tr += "" + + "" + rdata.list[i].type + "" + + "" + rdata.list[i].laddr[0] + ":" + rdata.list[i].laddr[1] + "" + + "" + (rdata.list[i].raddr.length > 1 ? "" + rdata.list[i].raddr[0] + ":" + rdata.list[i].raddr[1] : 'NONE') + "" + + "" + rdata.list[i].status + "" + + "" + rdata.list[i].process + "" + + "" + rdata.list[i].pid + "" + + ""; + } + + tbody = "\ + \ + " + lan.index.net_protocol + "\ + " + lan.index.net_address_dst + "\ + " + lan.index.net_address_src + "\ + " + lan.index.net_address_status + "?\ + " + lan.index.net_process + "\ + " + lan.index.net_process_pid + "\ + \ + \ + " + tbody_tr + ""; + + $("#TaskManagement").html(tbody); + var topMsg = '
\ +
\ +

总发送:' + toSize(rdata.state.upTotal) + '

\ +

总接收:' + toSize(rdata.state.downTotal) + '

\ +
\ +
\ +

上行:' + toSize(rdata.state.up) + '

\ +

下行:' + toSize(rdata.state.down) + '

\ +
\ +
\ +

总发包:' + to_max(rdata.state.upPackets) + '

\ +

总收包:' + to_max(rdata.state.downPackets) + '

\ +
\ +
\ +

包发送/秒:' + to_max(rdata.state.upPackets_s) + '

\ +

包接收/秒:' + to_max(rdata.state.downPackets_s) + '

\ +
\ +
'; + $("#load_average").html(topMsg).show(); + $(".table-cont").css("height", "500px"); + show_task(); + }); +} + +function to_max(num) { + if (num > 10000) { + num = num / 10000; + if (num > 10000) { + num = num / 10000; + return num.toFixed(5) + ' 亿'; + } + return num.toFixed(5) + ' 万'; + } + return num; +} + +//获取会话列表 +function get_who_list() { + var loadT = layer.msg('正在获取用户会话列表..', {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('get_who', {search:search_val}, function(data){ + layer.close(loadT); + var rdata = data.data; + var tbody_tr = ''; + for (var i = 0; i < rdata.length; i++) { + tbody_tr += '\ + ' + rdata[i].user + '\ + ' + rdata[i].pts + '\ + ' + rdata[i].ip + '\ + ' + rdata[i].date + '\ + 强制断开\ + '; + } + var tbody = '\ + \ + 用户\ + PTS\ + 登陆IP\ + 登陆时间\ + 操作\ + \ + \ + ' + tbody_tr + ''; + $("#TaskManagement").html(tbody); + var topMsg = ''; + $("#load_average").html(topMsg).hide(); + $(".table-cont").css("height", "597px"); + show_task(); + }); +} + +//获取启动列表 +function get_run_list() { + var loadT = layer.msg('正在获取启动项列表..', {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('get_run_list', {search:search_val}, function(rdata){ + layer.close(loadT); + if (rdata.data['is_mac']){ + tbody_tr += "mac无法使用"; + var tbody = '\ + \ + 名称\ + 启动路径\ + 文件大小\ + 文件权限\ + 描述\ + 操作\ + \ + \ + ' + tbody_tr + ''; + $("#TaskManagement").html(tbody); + return; + } + + + var tbody_tr = ''; + for (var i = 0; i < rdata.run_list.length; i++) { + tbody_tr += '\ + ' + rdata.run_list[i].name + '\ + ' + rdata.run_list[i].srcfile + '\ + ' + toSize(rdata.run_list[i].size) + '\ + ' + rdata.run_list[i].access + '\ + ' + rdata.run_list[i].ps + '\ + 编辑\ + '; + } + var tbody = '\ + \ + 名称\ + 启动路径\ + 文件大小\ + 文件权限\ + 描述\ + 操作\ + \ + \ + ' + tbody_tr + ''; + $("#TaskManagement").html(tbody); + var topMsg = '
当前运行级别: level-' + rdata.run_level + '?
'; + $("#load_average").html(topMsg).show(); + $(".table-cont").css("height", "500px"); + show_task(); + }); +} + +//获取服务列表 +function get_service_list() { + var loadT = layer.msg('正在获取服务列表..', {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('get_service_list', {search:search_val}, function(rdata){ + layer.close(loadT); + + if (rdata.data['is_mac']){ + tbody_tr += "mac无法使用"; + var tbody = '\ + \ + 名称\ + Level-0\ + Level-1\ + Level-2\ + Level-3\ + Level-4\ + Level-5\ + Level-6\ + 描述\ + 操作\ + \ + \ + ' + tbody_tr + ''; + $("#TaskManagement").html(tbody); + return; + } + + var tbody_tr = ''; + for (var i = 0; i < rdata.serviceList.length; i++) { + tbody_tr += '\ + ' + rdata.serviceList[i].name + '\ + ' + rdata.serviceList[i].runlevel_0 + '\ + ' + rdata.serviceList[i].runlevel_1 + '\ + ' + rdata.serviceList[i].runlevel_2 + '\ + ' + rdata.serviceList[i].runlevel_3 + '\ + ' + rdata.serviceList[i].runlevel_4 + '\ + ' + rdata.serviceList[i].runlevel_5 + '\ + ' + rdata.serviceList[i].runlevel_6 + '\ + ' + rdata.serviceList[i].ps + '\ + 删除\ + '; + } + var tbody = '\ + \ + 名称\ + Level-0\ + Level-1\ + Level-2\ + Level-3\ + Level-4\ + Level-5\ + Level-6\ + 描述\ + 操作\ + \ + \ + ' + tbody_tr + ''; + $("#TaskManagement").html(tbody); + var topMsg = '
当前运行级别: level-' + rdata.runlevel + '?
'; + $("#load_average").html(topMsg).show(); + $(".table-cont").css("height", "500px"); + show_task(); + }); +} + +//取用户列表 +function get_user_list() { + var loadT = layer.msg('正在获取用户列表..', {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('get_user_list', {search:search_val}, function(data){ + layer.close(loadT); + var rdata = data.data; + var tbody_tr = ''; + for (var i = 0; i < rdata.length; i++) { + tbody_tr += '\ + ' + rdata[i].username + '\ + ' + rdata[i].home + '\ + ' + rdata[i].group + '\ + ' + rdata[i].uid + '\ + ' + rdata[i].gid + '\ + ' + rdata[i].login_shell + '\ + ' + rdata[i].ps + '\ + 删除\ + '; + } + var tbody = '\ + \ + 用户名\ + home\ + 用户组\ + uid\ + gid\ + 登陆脚本?\ + 描述\ + 操作\ + \ + \ + ' + tbody_tr + ''; + $("#TaskManagement").html(tbody); + var topMsg = ''; + $("#load_average").html(topMsg).hide(); + $(".table-cont").css("height", "597px"); + show_task(); + }); +} + +//删除用户 +function userdel(user) { + safeMessage('删除用户【' + user + '】', '删除后可能导致您的环境无法正常运行,继续吗?', function () { + var loadT = layer.msg('正在删除用户[' + user + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); + $.post('/plugin?action=a&name=task_manager&s=remove_user', {user: user}, function (rdata) { + layer.close(loadT); + layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + if (rdata.status) get_user_list(); + }); + }); +} + +//结束进程 +function kill_process(pid, fpid) { + if (fpid) { + select_pid = fpid; + } + var w = layer.confirm('您是否要结束 (' + pid + ') 进程?', { + btn: ['结束', '取消'], //按钮 + title: '结束' + pid, + closeBtn: 2 + }, function () { + var loadT = layer.msg('正在结束进程[' + pid + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); + $.post('/plugin?action=a&name=task_manager&s=kill_process', {pid: pid}, function (rdata) { + layer.close(loadT); + layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + if (rdata.status) get_process_list(); + }) + }, function () { + layer.close(w) + }) +} + +//结束进程树 +function kill_process_all(pid) { + var w = layer.confirm('您是否要结束 (' + pid + ') 进程?', { + btn: ['结束', '取消'], //按钮 + title: '结束' + pid, + closeBtn: 2 + }, function () { + var loadT = layer.msg('正在结束父进程[' + pid + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); + $.post('/plugin?action=a&name=task_manager&s=kill_process_all', {pid: pid}, function (rdata) { + layer.close(loadT); + layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + if (rdata.status) get_process_list(); + }) + }, function () { + layer.close(w) + }) +} + +//打开文件所在位置 +function open_path(path) { + tmp = path.split('/') + tmp[tmp.length - 1] = ''; + path = '/' + tmp.join('/'); + openPath(path); +} + +//删除服务 +function remove_service(serviceName) { + SafeMessage('删除服务【' + serviceName + '】', '删除后可能导致您的环境无法正常运行,继续吗?', function () { + var loadT = layer.msg('正在删除服务[' + serviceName + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); + $.post('/plugin?action=a&name=task_manager&s=remove_service', {serviceName: serviceName}, function (rdata) { + layer.close(loadT); + layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + if (rdata.status) get_service_list(); + }); + }); +} + +//在线编辑文件 +function online_edit_file(fileName) { + onlineEditFile(0, fileName); +} + +//删除计划任务 +function remove_cron(index) { + safeMessage('删除计划任务[' + index + ']', '删除后将无法恢复,继续吗?', function () { + var loadT = layer.msg('正在删除计划任务..', {icon: 16, time: 0, shade: [0.3, '#000']}); + $.post('/plugin?action=a&name=task_manager&s=remove_cron', {index: index}, function (rdata) { + layer.close(loadT); + layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + if (rdata.status) get_cron_list(); + }); + }); +} + +//强制断开会话 +function pkill_session(pts) { + safeMessage('强制断开会话[' + pts + ']', '强制断开此会话吗?', function () { + var loadT = layer.msg('正在断开会话..', {icon: 16, time: 0, shade: [0.3, '#000']}); + $.post('/plugin?action=a&name=task_manager&s=pkill_session', {pts: pts}, function (rdata) { + layer.close(loadT); + layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + if (rdata.status) get_who_list(); + }); + }); +} + +//设置服务启动级别状态 +function set_runlevel_state(runlevel, serviceName) { + var loadT = layer.msg('正在设置服务[' + serviceName + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); + $.post('/plugin?action=a&name=task_manager&s=set_runlevel_state', { + runlevel: runlevel, + serviceName: serviceName + }, function (rdata) { + layer.close(loadT); + layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + if (rdata.status) get_service_list(); + }); +} + +//查看进程详情 +function get_process_info(pid) { + var loadT = layer.msg('正在获取进程信息[' + pid + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('get_process_info', {pid:pid}, function(data){ + console.log('get_process_info',data); + layer.close(loadT); + var rdata = data.data; + fileBody = ''; + for (var i = 0; i < rdata.open_files.length; i++) { + fileBody += '' + rdata.open_files[i].path + '\ + ' + rdata.open_files[i].mode + '\ + ' + rdata.open_files[i].position + '\ + ' + rdata.open_files[i].flags + '\ + ' + rdata.open_files[i].fd + '\ + '; + } + var cbody = '
\ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
名称' + rdata.name + 'PID' + rdata.pid + '状态' + rdata.status + '
父进程' + rdata.pname + '(' + rdata.ppid + ')用户' + rdata.user + '线程' + rdata.threads + '
Socket' + rdata.connects + 'io读' + toSize(rdata.io_read_bytes) + 'io写' + toSize(rdata.io_write_bytes) + '
启动时间' + getLocalTime(rdata.create_time) + '描述' + rdata.ps + '
启动命令' + rdata.comline.join(" ") + '
\ +
\ +

内存

\ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
rss' + toSize(rdata.memory_full.rss) + 'pss' + toSize(rdata.memory_full.pss) + 'uss' + toSize(rdata.memory_full.uss) + '
vms' + toSize(rdata.memory_full.vms) + 'swap' + toSize(rdata.memory_full.swap) + 'shared' + toSize(rdata.memory_full.shared) + '
data' + toSize(rdata.memory_full.data) + 'text' + toSize(rdata.memory_full.text) + 'dirty' + toSize(rdata.memory_full.dirty) + '
\ +
\ +

打开的文件列表

\ +
\ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + ' + fileBody + '\ +
文件modepositionflagsfd
\ +
\ +
\ +
\ +
\ + \ + \ +
'; + + TaskProcessLayerIndex = layer.open({ + type: 1, + title: '进程属性[' + rdata.name + '] -- ' + rdata.exe, + area: '750px', + closeBtn: 2, + shadeClose: false, + content: cbody + }); + show_jc_flie(); + }); +} + +//屏蔽指定IP +function dropAddress(address) { + layer.confirm(lan.index.net_doup_ip_msg, {icon: 3, closeBtn: 2}, function () { + loadT = layer.msg(lan.index.net_doup_ip_to, {icon: 16, time: 0, shade: [0.3, '#000']}); + $.post('/firewall?action=AddDropAddress', 'port=' + address + '&ps=' + lan.index.net_doup_ip_ps, function (rdata) { + layer.close(loadT); + layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + }); + }); +} + +function show_task() { + $(".ts-line").width($("#TaskManagement").width()); + $("#TaskManagement tbody td").click(function () { + // console.log('---'); + $(this).parents("tr").addClass("active").siblings().removeClass("active"); + }); + var tableCont = document.querySelector('#table-cont'); + //表格固定 + var sct = tableCont.scrollTop; + tableCont.querySelector('thead').style.transform = 'translateY(' + sct + 'px)'; + tableCont.addEventListener('scroll', scrollHandle); +} + +function show_jc_flie() { + var tableJc = document.querySelector('#jc-file-table'); + //文件表格固定 + tableJc.addEventListener('scroll', scrollHandle); +} + +function scrollHandle(e) { + var scrollTop = this.scrollTop; + this.querySelector('thead').style.transform = 'translateY(' + scrollTop + 'px)'; +} + +var masterPluginTitle = $('.TaskManView').parents('.layui-layer'); +// masterPluginTitle.append(''); +masterPluginTitle.on('click', '.bt-desired', function(){ + bt_tools.nps({name:'任务管理器',type:26}) +}) \ No newline at end of file diff --git a/plugins/task_manager/process_network_total.py b/plugins/task_manager/process_network_total.py new file mode 100644 index 0000000000..cd317721c1 --- /dev/null +++ b/plugins/task_manager/process_network_total.py @@ -0,0 +1,318 @@ +#coding: utf-8 +#------------------------------------------------------------------- +# 宝塔Linux面板 +#------------------------------------------------------------------- +# Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved. +#------------------------------------------------------------------- +# Author: hwliang +#------------------------------------------------------------------- + +import sys +import time +import os +import struct + +os.chdir('/www/server/panel') +if 'class/' in sys.path: sys.path.insert(0,"class/") +import copy +try: + import pcap +except ImportError: + if os.path.exists('/usr/bin/apt'): + os.system("apt install libpcap-dev -y") + elif os.path.exists('/usr/bin/dnf'): + red_file = '/etc/redhat-release' + if os.path.exists(red_file): + f = open(red_file,'r') + red_body = f.read() + f.close() + if red_body.find('CentOS Linux release 8.') != -1: + rpm_file = '/root/libpcap-1.9.1.rpm' + down_url = "wget -O {} https://repo.almalinux.org/almalinux/8/PowerTools/x86_64/os/Packages/libpcap-devel-1.9.1-5.el8.x86_64.rpm --no-check-certificate -T 10".format(rpm_file) + print(down_url) + os.system(down_url) + os.system("rpm -ivh {}".format(rpm_file)) + if os.path.exists(rpm_file): os.remove(rpm_file) + else: + os.system("dnf install libpcap-devel -y") + else: + os.system("dnf install libpcap-devel -y") + elif os.path.exists('/usr/bin/yum'): + os.system("yum install libpcap-devel -y") + + os.system("btpip install pypcap") + try: + import pcap + except ImportError: + print("pypcap module install failed.") + sys.exit() + +class process_network_total: + __pid_file = 'logs/process_network_total.pid' + __inode_list = {} + __net_process_list = {} + __net_process_size = {} + __last_stat = 0 + __last_write_time = 0 + __end_time = 0 + + def start(self,timeout = 0): + ''' + @name 启动进程网络监控 + @author hwliang<2021-09-13> + @param timeout 结束时间(秒),0表示持久运行,默认为0 + @return void + ''' + stime = time.time() + self.__end_time = timeout + stime + self.__last_stat = stime + try: + p = pcap.pcap() # 监听所有网卡 + p.setfilter('tcp') # 只监听TCP数据包 + for p_time,p_data in p: + self.handle_packet(p_data) + # 过期停止监听 + if timeout > 0: + if p_time > self.__end_time: + self.rm_pid_file() + break + except: + self.rm_pid_file() + + def handle_packet(self, pcap_data): + ''' + @name 处理pcap数据包 + @author hwliang<2021-09-12> + @param pcap_data pcap数据包 + @return void + ''' + # 获取IP协议头 + ip_header = pcap_data[14:34] + # 解析src/dst地址 + src_ip = ip_header[12:16] + dst_ip = ip_header[16:20] + # 解析sport/dport端口 + src_port = pcap_data[34:36] + dst_port = pcap_data[36:38] + + src = src_ip + b':' + src_port + dst = dst_ip + b':' + dst_port + # 计算数据包长度 + pack_size = len(pcap_data) + # 统计进程流量 + self.total_net_process(dst,src,pack_size) + + def total_net_process(self,dst,src,pack_size): + ''' + @name 统计进程流量 + @author hwliang<2021-09-13> + @param dst 目标地址 + @param src 源地址 + @param pack_size 数据包长度 + @return void + ''' + self.get_tcp_stat() + direction = None + mtime = time.time() + if dst in self.__net_process_list: + pid = self.__net_process_list[dst] + direction = 'down' + elif src in self.__net_process_list: + pid = self.__net_process_list[src] + direction = 'up' + else: + if mtime - self.__last_stat > 3: + self.__last_stat = mtime + self.get_tcp_stat(True) + if dst in self.__net_process_list: + pid = self.__net_process_list[dst] + direction = 'down' + elif src in self.__net_process_list: + pid = self.__net_process_list[src] + direction = 'up' + + if not direction: return False + if not pid: return False + if not pid in self.__net_process_size: + self.__net_process_size[pid] = {} + self.__net_process_size[pid]['down'] = 0 + self.__net_process_size[pid]['up'] = 0 + self.__net_process_size[pid]['up_package'] = 0 + self.__net_process_size[pid]['down_package'] = 0 + + self.__net_process_size[pid][direction] += pack_size + self.__net_process_size[pid][direction + '_package'] += 1 + + # 写入到文件 + if mtime - self.__last_write_time > 1: + self.__last_write_time = mtime + self.write_net_process() + + def write_net_process(self): + ''' + @name 写入进程流量 + @author hwliang<2021-09-13> + @return void + ''' + w_file = '/dev/shm/bt_net_process' + process_size = copy.deepcopy(self.__net_process_size) + net_process = [] + for pid in process_size.keys(): + net_process.append(str(pid) + " " + str(process_size[pid]['down']) + " " + str(process_size[pid]['up']) + " " + str(process_size[pid]['down_package']) + " " + str(process_size[pid]['up_package'])) + + f = open(w_file,'w+',encoding='utf-8') + f.write('\n'.join(net_process)) + f.close() + + def hex_to_ip(self, hex_ip): + ''' + @name 将16进制的IP地址转换为字符串IP地址 + @author hwliang<2021-09-13> + @param hex_ip 16进制的IP地址:16进程端口 + @return tuple(ip,port) IP地址,端口 + ''' + hex_ip,hex_port = hex_ip.split(':') + ip = '.'.join([str(int(hex_ip[i:i+2], 16)) for i in range(0, len(hex_ip), 2)][::-1]) + port = int(hex_port, 16) + return ip,port + + def get_tcp_stat(self,force = False): + ''' + @name 获取当前TCP连接状态表 + @author hwliang<2021-09-13> + @param force 是否强制刷新 + @return dict + ''' + if not force and self.__net_process_list: return self.__net_process_list + self.__net_process_list = {} + tcp_stat_file = '/proc/net/tcp' + tcp_stat = open(tcp_stat_file, 'rb') + tcp_stat_list = tcp_stat.read().decode('utf-8').split('\n') + tcp_stat.close() + tcp_stat_list = tcp_stat_list[1:] + if force: self.get_process_inodes(force) + for i in tcp_stat_list: + tcp_tmp = i.split() + if len(tcp_tmp) < 10: continue + inode = tcp_tmp[9] + if inode == '0': continue + local_ip,local_port = self.hex_to_ip(tcp_tmp[1]) + if local_ip == '127.0.0.1': continue + remote_ip,remote_port = self.hex_to_ip(tcp_tmp[2]) + if local_ip == remote_ip: continue + if remote_ip == '0.0.0.0': continue + + pid = self.inode_to_pid(inode,force) + if not pid: continue + + key = self.get_ip_pack(local_ip) + b':' + self.get_port_pack(local_port) + self.__net_process_list[key] = pid + return self.__net_process_list + + + def get_port_pack(self,port): + ''' + @name 将端口转换为字节流 + @author hwliang<2021-09-13> + @param port 端口 + @return bytes + ''' + return struct.pack('H',int(port))[::-1] + + def get_ip_pack(self,ip): + ''' + @name 将IP地址转换为字节流 + @author hwliang<2021-09-13> + @param ip IP地址 + @return bytes + ''' + ip_arr = ip.split('.') + ip_pack = b'' + for i in ip_arr: + ip_pack += struct.pack('B',int(i)) + return ip_pack + + def inode_to_pid(self,inode,force = False): + ''' + @name 将inode转换为进程ID + @author hwliang<2021-09-13> + @param inode inode + @param force 是否强制刷新 + @return int + ''' + inode_list = self.get_process_inodes() + if inode in inode_list: + return inode_list[inode] + return None + + def get_process_inodes(self,force = False): + ''' + @name 获取进程inode列表 + @author hwliang<2021-09-13> + @param force 是否强制刷新 + @return dict + ''' + if not force and self.__inode_list: return self.__inode_list + proc_path = '/proc' + inode_list = {} + for pid in os.listdir(proc_path): + try: + if not pid.isdigit(): continue + inode_path = proc_path + '/' + pid + '/fd' + for fd in os.listdir(inode_path): + try: + fd_file = inode_path + '/' + fd + fd_link = os.readlink(fd_file) + if fd_link.startswith('socket:['): + inode = fd_link[8:-1] + inode_list[inode] = pid + except: + continue + except: + continue + self.__inode_list = inode_list + return inode_list + + def get_process_name(self,pid): + ''' + @name 获取进程名称 + @author hwliang<2021-09-13> + @param pid 进程ID + @return str + ''' + pid_path = '/proc/' + pid + '/comm' + if not os.path.exists(pid_path): return '' + pid_file = open(pid_path, 'rb') + pid_name = pid_file.read().decode('utf-8').strip() + pid_file.close() + return pid_name + + + def write_pid(self): + ''' + @name 写入进程ID到PID文件 + @author hwliang<2021-09-13> + @return void + ''' + self_pid = os.getpid() + pid_file = open(self.__pid_file,'w') + pid_file.write(str(self_pid)) + pid_file.close() + + def rm_pid_file(self): + ''' + @name 删除进程pid文件 + @author hwliang<2021-09-13> + @return void + ''' + if os.path.exists(self.__pid_file): + os.remove(self.__pid_file) + +if __name__ == '__main__': + if len(sys.argv) > 1: + timeout = int(sys.argv[-1]) + else: + timeout = 0 + p = process_network_total() + p.write_pid() + p.start(timeout) \ No newline at end of file diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py new file mode 100755 index 0000000000..230b5d114b --- /dev/null +++ b/plugins/task_manager/task_manager_index.py @@ -0,0 +1,1182 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import re +import threading +import psutil +import json + +from typing import List, Dict + +sys.path.append(os.getcwd() + "/class/core") +import mw + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'task_manager' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +class mainClass(object): + + pids = None + + new_info = {} + old_info = {} + new_net_info = {} + old_net_info = {} + old_path = '/www/server/task_manager/task_old.json' + old_net_path = '/www/server/task_manager/network_old.json' + panel_pid = None + task_pid = None + __process_net_list = {} + __cpu_time = None + + meter_head = {} + + last_net_process = None + last_net_process_time = 0 + + # lock + _instance_lock = threading.Lock() + is_mac = False + + def __init__(self): + # print("__init__") + self.is_mac = mw.isAppleSystem() + self.old_path = getServerDir()+'/task_old.json' + self.old_net_path = getServerDir()+'/network_old.json' + + self.old_info['cpu_time'] = self.get_cpu_time() + self.old_info['time'] = time.time() + + @classmethod + def instance(cls, *args, **kwargs): + if not hasattr(mainClass, "_instance"): + with mainClass._instance_lock: + if not hasattr(mainClass, "_instance"): + mainClass._instance = mainClass(*args, **kwargs) + return mainClass._instance + + def get_old(self): + if self.old_info: return True + # if not os.path.exists(self.old_path): return False + data = cache.get(self.old_path) + if not data: return False + # data = json.loads(data) + if not data: return False + self.old_info = data + del (data) + return True + + def get_net_old(self): + if self.old_net_info: return True + # if not os.path.exists(self.old_net_path): return False + data = cache.get(self.old_net_path) + if not data: return False + # data = json.loads(data) + if not data: return False + self.old_net_info = data + del (data) + return True + + def get_process_net_list(self): + w_file = '/dev/shm/bt_net_process' + if not os.path.exists(w_file): return + self.last_net_process = cache.get('net_process') + self.last_net_process_time = cache.get('last_net_process') + net_process_body = public.readFile(w_file) + if not net_process_body: return + net_process = net_process_body.split('\n') + for np in net_process: + if not np: continue + tmp = {} + np_list = np.split() + if len(np_list) < 5: continue + tmp['pid'] = int(np_list[0]) + tmp['down'] = int(np_list[1]) + tmp['up'] = int(np_list[2]) + tmp['down_package'] = int(np_list[3]) + tmp['up_package'] = int(np_list[4]) + self.__process_net_list[tmp['pid']] = tmp + cache.set('net_process', self.__process_net_list, 600) + cache.set('last_net_process', time.time(), 600) + + # 获取进程连接数 + def get_connects(self, pid): + connects = 0 + try: + if pid == 1: return connects + tp = '/proc/' + str(pid) + '/fd/' + if not os.path.exists(tp): return connects + for d in os.listdir(tp): + fname = tp + d + if os.path.islink(fname): + l = os.readlink(fname) + if l.find('socket:') != -1: connects += 1 + except: + pass + return connects + + def get_mem_info(self, get=None): + mem = psutil.virtual_memory() + if self.is_mac: + memInfo = {'memTotal': mem.total} + memInfo['memRealUsed'] = memInfo['memTotal'] * (mem.percent / 100) + return memInfo['memRealUsed'] + + memInfo = {'memTotal': mem.total, 'memFree': mem.free, 'memBuffers': mem.buffers, 'memCached': mem.cached} + memInfo['memRealUsed'] = memInfo['memTotal'] - memInfo['memFree'] - memInfo['memBuffers'] - memInfo['memCached'] + return memInfo['memRealUsed'] + + # 进程备注,name,pid,启动命令 + def get_process_ps(self, name, pid, p_exe=None, p=None): + processPs = { + 'irqbalance': '系统进程-优化系统性能服务', + 'containerd': 'docker管理服务', + 'qmgr': '系统进程-管理和控制邮件进程', + 'pickup': '系统进程-接收和处理待发送的邮件', + 'cleanup': '系统进程-服务器释放资源进程', + 'trivial-rewrite': '系统进程-邮件重写和转发服务', + 'bt-ipfilter': '宝塔网络的IP过滤器', + 'oneav': '微步木马检测服务', + 'rhsmcertd': '系统进程-验证系统的订阅状态服务', + 'tamperuser': '宝塔-企业级防篡改服务', + 'lvmetad': '系统进程-元数据守护进程', + 'containerd-shim-runc-v2': 'docker容器管理服务', + 'tuned': '系统进程-优化系统服务', + 'chronyd': '系统进程-时间同步服务', + 'auditd': '系统进程-系统安全日志记录服务', + 'gssproxy': '系统进程-身份验证和授权服务', + 'ossfs': '阿里云对象存储挂载服务', + 'cosfs': '腾讯云对象存储挂载服务', + 'obsfs': '华为云对象存储挂载服务', + 's3fs': '对象存储挂载服务', + 'bosfs': '百度云对象存储挂载服务', + 'jsvc': 'tomcat服务', + 'oneavd': '微步木马检测服务', + 'btsync': '宝塔文件同步服务', + 'mysqld': 'MySQL服务', + 'php-fpm': 'PHP子进程', + 'php-cgi': 'PHP-CGI进程', + 'nginx': 'Nginx服务', + 'httpd': 'Apache服务', + 'sshd': 'SSH服务', + 'pure-ftpd': 'FTP服务', + 'sftp-server': 'SFTP服务', + 'mysqld_safe': 'MySQL服务', + 'firewalld': '防火墙服务', + 'BT-Panel': '宝塔面板-主进程', + 'BT-Task': '宝塔面板-后台任务进程', + 'NetworkManager': '网络管理服务', + 'svlogd': '日志守护进程', + 'memcached': 'Memcached缓存器', + 'gunicorn': "python项目", + "BTPanel": '宝塔面板', + 'baota_coll': "堡塔云控-主控端", + 'baota_client': "堡塔云控-被控端", + 'node': 'Node.js程序', + 'supervisord': 'Supervisor进程', + 'rsyslogd': 'rsyslog日志服务', + 'crond': '计划任务服务', + 'cron': '计划任务服务', + 'rsync': 'rsync文件同步进程', + 'ntpd': '网络时间同步服务', + 'rpc.mountd': 'NFS网络文件系统挂载服务', + 'sendmail': 'sendmail邮件服务', + 'postfix': 'postfix邮件服务', + 'npm': 'Node.js NPM管理器', + 'PM2': 'Node.js PM2进程管理器', + 'htop': 'htop进程监控软件', + 'btpython': '宝塔面板-独立Python环境进程', + 'btappmanagerd': '宝塔应用管理器插件', + 'dockerd': 'Docker容器管理器', + 'docker-proxy': 'Docker容器管理器', + 'docker-registry': 'Docker容器管理器', + 'docker-distribution': 'Docker容器管理器', + 'docker-network': 'Docker容器管理器', + 'docker-volume': 'Docker容器管理器', + 'docker-swarm': 'Docker容器管理器', + 'docker-systemd': 'Docker容器管理器', + 'docker-containerd': 'Docker容器管理器', + 'docker-containerd-shim': 'Docker容器管理器', + 'docker-runc': 'Docker容器管理器', + 'docker-init': 'Docker容器管理器', + 'docker-init-systemd': 'Docker容器管理器', + 'docker-init-upstart': 'Docker容器管理器', + 'docker-init-sysvinit': 'Docker容器管理器', + 'docker-init-openrc': 'Docker容器管理器', + 'docker-init-runit': 'Docker容器管理器', + 'docker-init-systemd-resolved': 'Docker容器管理器', + 'rpcbind': 'NFS网络文件系统服务', + 'dbus-daemon': 'D-Bus消息总线守护进程', + 'systemd-logind': '登录管理器', + 'systemd-journald': 'Systemd日志管理服务', + 'systemd-udevd': '系统设备管理服务', + 'systemd-timedated': '系统时间日期服务', + 'systemd-timesyncd': '系统时间同步服务', + 'systemd-resolved': '系统DNS解析服务', + 'systemd-hostnamed': '系统主机名服务', + 'systemd-networkd': '系统网络管理服务', + 'systemd-resolvconf': '系统DNS解析服务', + 'systemd-local-resolv': '系统DNS解析服务', + 'systemd-sysctl': '系统系统参数服务', + 'systemd-modules-load': '系统模块加载服务', + 'systemd-modules-restore': '系统模块恢复服务', + 'agetty': 'TTY登陆验证程序', + 'sendmail-mta': 'MTA邮件传送代理', + 'bash': 'bash命令行进程', + '(sd-pam)': '可插入认证模块', + 'polkitd': '授权管理服务', + 'mongod': 'MongoDB数据库服务', + 'mongodb': 'MongoDB数据库服务', + 'mongodb-mms-monitor': 'MongoDB数据库服务', + 'mongodb-mms-backup': 'MongoDB数据库服务', + 'mongodb-mms-restore': 'MongoDB数据库服务', + 'mongodb-mms-agent': 'MongoDB数据库服务', + 'mongodb-mms-analytics': 'MongoDB数据库服务', + 'mongodb-mms-tools': 'MongoDB数据库服务', + 'mongodb-mms-backup-agent': 'MongoDB数据库服务', + 'mongodb-mms-backup-tools': 'MongoDB数据库服务', + 'mongodb-mms-restore-agent': 'MongoDB数据库服务', + 'mongodb-mms-restore-tools': 'MongoDB数据库服务', + 'mongodb-mms-analytics-agent': 'MongoDB数据库服务', + 'mongodb-mms-analytics-tools': 'MongoDB数据库服务', + 'dhclient': 'DHCP协议客户端', + 'dhcpcd': 'DHCP协议客户端', + 'dhcpd': 'DHCP服务器', + 'isc-dhcp-server': 'DHCP服务器', + 'isc-dhcp-server6': 'DHCP服务器', + 'dhcp6c': 'DHCP服务器', + 'dhcpcd': 'DHCP服务器', + 'dhcpd': 'DHCP服务器', + 'avahi-daemon': 'Zeroconf守护进程', + 'login': '登录进程', + 'systemd': '系统管理服务', + 'systemd-sysv': '系统管理服务', + 'systemd-journal-gateway': '系统管理服务', + 'systemd-journal-remote': '系统管理服务', + 'systemd-journal-upload': '系统管理服务', + 'systemd-networkd': '系统网络管理服务', + 'rpc.idmapd': 'NFS网络文件系统相关服务', + 'cupsd': '打印服务', + 'cups-browsed': '打印服务', + 'sh': 'shell进程', + 'php': 'PHP CLI模式进程', + 'blkmapd': 'NFS映射服务', + 'lsyncd': '文件同步服务', + 'sleep': '延迟进程' + } + if p_exe: + if name == 'php-fpm': + try: + php_version = '.'.join(p_exe.split('/')[-3]) + return 'PHP' + php_version + '进程' + except: + pass + elif name == 'python': + p_exe_arr = p_exe.split('/') + if p_exe_arr[-1] in ['BT-Task', 'task.py']: + return '面板-后台任务进程' + elif p_exe_arr[-1] in ['BT-Panel', 'runserver.py']: + return '面板-主进程' + elif p_exe.find('process_network_total') != -1: + return '面板-进程网络监控' + if p: + cmdline = ' '.join(p.cmdline()).strip() + cmdline_arr = cmdline.split('/') + if cmdline.find('process_network_total') != -1: + return '进程网络监控' + if cmdline_arr[-1] in ['BT-Task', 'task.py']: + return '后台任务进程' + elif cmdline_arr[-1] in ['BT-Panel', 'runserver.py']: + return '主进程' + elif cmdline.find('process_network_total') != -1: + return '进程网络监控' + elif cmdline.find('tamper_proof_service') != -1: + return '网站防篡改' + elif cmdline.find('syssafe') != -1: + return '系统加固' + elif cmdline.find('opwaf') != -1: + return 'WAF防火墙' + elif cmdline.find('acme') != -1: + return 'SSL证书签发' + elif cmdline.find('psync') != -1: + return '面板一键迁移' + elif cmdline.find('/panel/plugin') != -1: + return '面板插件进程' + elif cmdline.find('/www/server/cron/') != -1: + return '面板计划任务' + elif name == 'nginx': + if p.username() == 'www': + return 'Nginx子进程' + else: + return 'Nginx主进程' + elif p_exe == '/usr/bin/bash': + cmdline = ' '.join(p.cmdline()).strip() + if cmdline.find('/www/server/cron/') != -1: + return '面板计划任务' + elif cmdline.find('/www/server/mdserver-web/plugins') != -1: + return '面板插件进程' + + if name in processPs: return processPs[name] + if name == 'python': + if self.is_panel_process(pid): return 'MW面板' + + if p_exe: + exe_keys = { + '/www/server/mdserver-web/plugins/': '面板插件', + '/www/server/cron/': '计划任务进程', + 'pm2': 'PM2进程管理器', + 'PM2': 'PM2进程管理器', + 'nvm': 'NVM Node版本管理器', + 'npm': 'NPM Node包管理器' + } + + for k in exe_keys.keys(): + if p_exe.find(k) != -1: return exe_keys[k] + if name.find(k) != -1: return exe_keys[k] + + return name + + def get_process_network(self, pid): + ''' + @name 获取进程网络流量 + @author hwliang<2021-09-13> + @param pid 进程ID + @return tuple + ''' + if not self.__process_net_list: + self.get_process_net_list() + if not self.last_net_process_time: return 0, 0, 0, 0 + if not pid in self.__process_net_list: return 0, 0, 0, 0 + + if not pid in self.last_net_process: + return self.__process_net_list[pid]['up'], self.__process_net_list[pid]['up_package'], \ + self.__process_net_list[pid]['down'], self.__process_net_list[pid]['down_package'] + + up = int((self.__process_net_list[pid]['up'] - self.last_net_process[pid]['up']) / ( + time.time() - self.last_net_process_time)) + down = int((self.__process_net_list[pid]['down'] - self.last_net_process[pid]['down']) / ( + time.time() - self.last_net_process_time)) + up_package = int((self.__process_net_list[pid]['up_package'] - self.last_net_process[pid]['up_package']) / ( + time.time() - self.last_net_process_time)) + down_package = int( + (self.__process_net_list[pid]['down_package'] - self.last_net_process[pid]['down_package']) / ( + time.time() - self.last_net_process_time)) + return up, up_package, down, down_package + + def get_process_cpu_time(self, cpu_times): + cpu_time = 0.00 + for s in cpu_times: cpu_time += s + return cpu_time + + # 获取cpu使用率 + def get_cpu_percent(self, pid, cpu_times, cpu_time): + percent = 0.00 + process_cpu_time = self.get_process_cpu_time(cpu_times) + + if not self.old_info: self.old_info = {} + if not pid in self.old_info: + self.old_info[pid] = {} + self.old_info[pid]['cpu_time'] = process_cpu_time + return percent + + if cpu_time == self.old_info['cpu_time']: + return 0.00 + + percent = round(100.00 * (process_cpu_time - self.old_info[pid]['cpu_time']) / (cpu_time - self.old_info['cpu_time']), 2) + # self.old_info[pid]['cpu_time'] = process_cpu_time + + if percent > 0: return percent + return 0.00 + + # 获取平均负载 + def get_load_average(self): + c = os.getloadavg() + data = {} + data['1'] = round(float(c[0]), 3) # float(c[0]) + data['5'] = round(float(c[1]), 3) # float(c[1]) + data['15'] = round(float(c[2]), 3) # float(c[2]) + return data + + def get_meter_head(self, get=None): + meter_head_file = getServerDir()+'/meter_head.json' + if os.path.exists(meter_head_file): + self.meter_head = json.loads(mw.readFile(meter_head_file)) + else: + self.meter_head = { + 'name': True, + 'pid': True, + 'cpu_percent': True, + 'down': True, + 'up': True, + 'status': True, + 'threads': True, + 'user': True, + 'ps': True, + 'memory_used': True, + 'io_read_bytes': True, + 'io_write_bytes': True, + 'connects': True + } + mw.writeFile(meter_head_file, json.dumps(self.meter_head)) + return self.meter_head + + # 添加进程查找 + def search_pro(self, data, search): + try: + ldata = [] + for i in data: + if search in i['name'] or search in i['exe'] or search in i['ps'] or search in i[ + 'user'] or search in str(i['pid']) or search in i['status']: + ldata.append(i) + elif hasattr(i, 'children'): + for k in i['children']: + if search in k['name'] or search in k['exe'] or search in k['ps'] or search in k[ + 'user'] or search in str(k['pid']): + ldata.append(i) + return ldata + except: + print(mw.getTracebackInfo()) + return data + + def get_cpu_time(self): + cpu_times = psutil.cpu_times() + + cpu_time = 0.00 + for s in cpu_times: cpu_time += s + return cpu_time + # return s.user + s.system + s.nice + s.idle + + # 获取python的路径 + def get_python_bin(self): + mw_dir = mw.getServerDir() + '/mdserver-web' + bin_file = mw_dir + '/bin/python' + if os.path.exists(bin_file): + return bin_file + return '/usr/bin/python' + + # 检查process_network_total.py是否运行 + def check_process_net_total(self): + mw_dir = mw.getServerDir() + '/mdserver-web' + _pid_file = mw_dir+'/logs/process_network_total.pid' + if os.path.exists(_pid_file): + pid = public.readFile(_pid_file) + if os.path.exists('/proc/' + pid): return True + + cmd_file = getServerDir()+'/process_network_total.py' + python_bin = self.get_python_bin() + _cmd = 'nohup {} {} 600 &> /tmp/net.log &'.format(python_bin, cmd_file) + mw.execShell(_cmd) + + # 进程折叠,将子进程折叠到父进程下,并将使用资源累加。 + def __pro_s_s(self, data: List) -> List: + """ + 将子进程合并到父进程中 + :param data:进程列表 + :return:合并后的进程列表增加children字段 + """ + data1 = [] + children_set = {'childrens': []} + for i in data: + if i['pid'] > 30 and i['ppid'] == 1: + children = self.__get_children(i['pid']) + s4 = time.time() + if children != []: children_set[i['pid']] = children + children_set['childrens'] += children + for i in data: + if i['pid'] in children_set: + i['children'] = [] + for j in data: + if j['pid'] in children_set[i['pid']]: + i['children'].append(j) + i['memory_used'] += j['memory_used'] + i['cpu_percent'] = round(i['cpu_percent'] + j['cpu_percent'], 2) + i['connects'] += j['connects'] + i['threads'] += j['threads'] + + if 'io_write_bytes' in j: + i['io_write_bytes'] += j['io_write_bytes'] + if 'io_read_bytes' in j: + i['io_read_bytes'] += j['io_read_bytes'] + if 'io_write_speed' in j: + i['io_write_speed'] += j['io_write_speed'] + if 'io_read_speed' in j: + i['io_read_speed'] += j['io_read_speed'] + + if 'up' in j: + i['up'] += j['up'] + if 'up_package' in j: + i['up_package'] += j['up_package'] + + if 'down' in j: + i['down'] += j['down'] + if 'down_package' in j: + i['down_package'] += j['down_package'] + data1.append(i) + elif i['pid'] not in children_set['childrens']: + data1.append(i) + return data1 + + def __get_children(self, pid: int) -> List: + try: + p = psutil.Process(pid) # pid为指定进程的进程号 + psutil.process_iter() + children = p.children(recursive=True) # 获取指定进程的所有子进程 + pids = [] + for child in children: + pids.append(child.pid) + return pids + except: + return [] + + def get_process_list(self, args = {}): + # https://hellowac.github.io/psutil-doc-zh/processes/process_class/oneshot.html + if self.is_mac: + return self.get_process_list_mac(args) + return self.get_process_list_linux(args) + + def get_process_list_mac(self, args = {}): + self.new_info['cpu_time'] = self.get_cpu_time() + self.new_info['time'] = time.time() + + sortx = 'all' + if 'sortx' in args: sortx = args['sortx'] + + if not 'sortx' in args: + args['sortx'] = 'status' + if args['sortx'] == 'status': res = False + if 'reverse' in args: + if args['reverse'] in ['undefined', 'null']: + args['reverse'] = 'True' + args['sortx'] = 'all' + if not args['reverse'] in ['True', 'False']: args['reverse'] = 'True' + res_list = {'True': True, 'False': False} + res = res_list[args['reverse']] + else: + args['reverse'] = True + if args['reverse'] in ['undefined', 'null']: + args['reverse'] = 'True' + args['sortx'] = 'all' + + info = {} + info['activity'] = 0 + info['cpu'] = 0.00 + info['mem'] = 0 + info['disk'] = 0 + status_ps = {'sleeping': '睡眠', 'running': '活动'} + ppids = psutil.pids() + processList = [] + for pid in ppids: + tmp = {} + try: + p = psutil.Process(pid) + with p.oneshot(): + p_state = p.status() + try: + tmp['exe'] = p.exe() + except Exception as e: + continue + + tmp['name'] = p.name() + tmp['pid'] = pid + tmp['ppid'] = p.ppid() + tmp['create_time'] = int(p.create_time()) + tmp['status'] = p_state + tmp['user'] = p.username() + tmp['connects'] = self.get_connects(pid) + + if p_state == 'running': info['activity'] += 1 + if p_state in status_ps: p_state = status_ps[p_state] + + try: + tmp['threads'] = p.num_threads() + except Exception as e: + continue + + + tmp['ps'] = self.get_process_ps(tmp['name'], pid, tmp['exe'], p) + tmp['up'], tmp['up_package'], tmp['down'], tmp['down_package'] = self.get_process_network(pid) + + + try: + p_cpus = p.cpu_times() + except Exception as e: + continue + + try: + p_mem = p.memory_info() + except Exception as e: + continue + if p_mem.rss == 0: continue + + tmp['memory_used'] = p_mem.rss + tmp['cpu_percent'] = self.get_cpu_percent(str(pid), p_cpus, self.new_info['cpu_time']) + # print(tmp['cpu_percent']) + if tmp['cpu_percent'] > 100: tmp['cpu_percent'] = 0.1 + info['cpu'] += tmp['cpu_percent'] + info['disk'] += 0 + + processList.append(tmp) + del (p) + del (tmp) + except Exception as e: + print("err:", mw.getTracebackInfo()) + continue + + + processList = self.__pro_s_s(processList) + res = True + + if args['sortx'] not in ['all']: + processList = sorted(processList, key=lambda x: x[args['sortx']], reverse=res) + else: + processList = sorted(processList, key=lambda x: [x['cpu_percent'], x['connects'], x['threads'], + x['memory_used']], reverse=res) + + info['load_average'] = self.get_load_average() + data = {} + data['is_mac'] = self.is_mac + data['process_list'] = processList + info['cpu'] = round(info['cpu'], 3) + info['mem'] = self.get_mem_info() + data['info'] = info + if hasattr(args, 'search'): + if args.search != '': + data['process_list'] = self.search_pro(data['process_list'], args.search) + self.get_meter_head() + data['meter_head'] = self.meter_head + + data['meter_head']['io_read_bytes'] = False + data['meter_head']['io_write_bytes'] = False + data['meter_head']['down'] = False + data['meter_head']['up'] = False + return data + + # 获取进程信息 + def get_process_list_linux(self, get = {}): + self.check_process_net_total() + self.Pids = psutil.pids() + processList = [] + if type(self.new_info) != dict: self.new_info = {} + self.new_info['cpu_time'] = self.get_cpu_time() + self.new_info['time'] = time.time() + self.get_process_net_list() + if not 'sortx' in get: get.sortx = 'all' + info = {} + info['activity'] = 0 + info['cpu'] = 0.00 + info['mem'] = 0 + info['disk'] = 0 + status_ps = {'sleeping': '睡眠', 'running': '活动'} + for pid in self.Pids: + tmp = {} + try: + p = psutil.Process(pid) + with p.oneshot(): + p_mem = p.memory_full_info() + if p_mem.rss == 0: continue + pio = p.io_counters() + p_cpus = p.cpu_times() + p_state = p.status() + if p_state == 'running': info['activity'] += 1 + if p_state in status_ps: p_state = status_ps[p_state] + tmp['exe'] = p.exe() + tmp['name'] = p.name() + tmp['pid'] = pid + tmp['ppid'] = p.ppid() + # tmp['create_time'] = int(p.create_time()) + tmp['status'] = p_state + tmp['user'] = p.username() + tmp['memory_used'] = p_mem.uss + tmp['cpu_percent'] = self.get_cpu_percent(str(pid), p_cpus, self.new_info['cpu_time']) + if tmp['name'] == 'BT-Panel' and tmp['cpu_percent'] > 1: + tmp['cpu_percent'] = round(tmp['cpu_percent'] % 1, 2) + tmp['io_write_bytes'] = pio.write_bytes + tmp['io_read_bytes'] = pio.read_bytes + tmp['io_write_speed'] = self.get_io_write(str(pid), pio.write_bytes) + tmp['io_read_speed'] = self.get_io_read(str(pid), pio.read_bytes) + tmp['connects'] = self.get_connects(pid) + tmp['threads'] = p.num_threads() + tmp['ps'] = self.get_process_ps(tmp['name'], pid, tmp['exe'], p) + tmp['up'], tmp['up_package'], tmp['down'], tmp['down_package'] = self.get_process_network(pid) + if tmp['cpu_percent'] > 100: tmp['cpu_percent'] = 0.1 + info['cpu'] += tmp['cpu_percent'] + info['disk'] += tmp['io_write_speed'] + tmp['io_read_speed'] + processList.append(tmp) + del (p) + del (tmp) + except: + continue + + cache.set(self.old_path, self.new_info, 600) + processList = self.__pro_s_s(processList) + res = True + if get.sortx == 'status': res = False + if 'reverse' in get: + if get.reverse in ['undefined', 'null']: + get.reverse = 'True' + get.sortx = 'all' + if not get.reverse in ['True', 'False']: get.reverse = 'True' + res_list = {'True': True, 'False': False} + res = res_list[get.reverse] + else: + get.reverse = True + if get.reverse in ['undefined', 'null']: + get.reverse = 'True' + get.sortx = 'all' + if get.sortx not in ['all']: + processList = sorted(processList, key=lambda x: x[get.sortx], reverse=res) + else: + processList = sorted(processList, key=lambda x: [x['cpu_percent'], x['up'], x['down'], x['io_write_speed'], + x['io_read_speed'], x['connects'], x['threads'], + x['memory_used']], reverse=res) + info['load_average'] = self.get_load_average() + data = {} + data['process_list'] = processList + info['cpu'] = round(info['cpu'], 2) + info['mem'] = self.get_mem_info() + data['info'] = info + if 'search' in get: + if get['search'] != '': + data['process_list'] = self.search_pro(data['process_list'], get.search) + self.get_meter_head() + data['meter_head'] = self.meter_head + return data + + def object_to_dict(self, obj): + result = {} + for name in dir(obj): + value = getattr(obj, name) + if not name.startswith('__') and not callable(value) and not name.startswith('_'): result[name] = value + return result + + def list_to_dict(self, data): + result = [] + for s in data: + result.append(self.object_to_dict(s)) + return result + + # 获取进程的详细信息 + def get_process_info(self, args={}): + pid = int(args['pid']) + try: + p = psutil.Process(pid) + processInfo = {} + + if self.is_mac: + p_mem = self.object_to_dict(p.memory_info()) + else: + p_mem = self.object_to_dict(p.memory_full_info()) + pio = p.io_counters() + processInfo['io_write_bytes'] = pio.write_bytes; + processInfo['io_read_bytes'] = pio.read_bytes; + # p_cpus= p.cpu_times() + processInfo['exe'] = p.exe() + processInfo['name'] = p.name(); + processInfo['pid'] = pid; + processInfo['ppid'] = p.ppid() + processInfo['pname'] = 'sys' + if processInfo['ppid'] != 0: processInfo['pname'] = psutil.Process(processInfo['ppid']).name() + processInfo['comline'] = p.cmdline() + processInfo['create_time'] = int(p.create_time()) + processInfo['open_files'] = self.list_to_dict(p.open_files()) + processInfo['status'] = p.status(); + processInfo['user'] = p.username(); + processInfo['memory_full'] = p_mem + + processInfo['connects'] = self.get_connects(pid) + processInfo['threads'] = p.num_threads() + processInfo['ps'] = self.get_process_ps(processInfo['name'], pid, processInfo['exe'], p) + except Exception as e: + # print(mw.getTracebackInfo()) + return mw.returnData(False, '指定进程已关闭!') + return processInfo + + # 获取用户组处理函数 get_user_list——>引用get_group_name + def get_group_name(self, gid): + for g in self.groupList: + if g['gid'] == gid: return g['group'] + return '' + + # 用户名注释:ps get_user_list——>引用get_user_ps + def get_user_ps(self, name, ps): + userPs = {'www': '宝塔面板', 'root': '超级管理员', 'mysql': '用于运行MySQL的用户', + 'mongo': '用于运行MongoDB的用户', + 'git': 'git用户', 'mail': 'mail', 'nginx': '第三方nginx用户', 'postfix': 'postfix邮局用户', + 'lp': '打印服务帐号', + 'daemon': '控制后台进程的系统帐号', 'nobody': '匿名帐户', 'bin': '管理大部分命令的帐号', + 'adm': '管理某些管理文件的帐号', 'smtp': 'smtp邮件'} + if name in userPs: return userPs[name] + if not ps: return name + return ps + + # 获取服务器的组名和id,从/etc/group中读取。存储到self.groupList,get_user_list——>引用get_group_list + def get_group_list(self, get): + tmpList = mw.readFile('/etc/group').split("\n") + groupList = [] + for gl in tmpList: + tmp = gl.split(':') + if len(tmp) < 3: continue + groupInfo = {} + groupInfo['group'] = tmp[0] + groupInfo['gid'] = tmp[2] + groupList.append(groupInfo) + return groupList; + + # 外部接口,删除用户,不能删除系统运行环境用户 + def remove_user(self, get): + if self.is_mac: + return mw.returnData(False, '无法操作!') + users = ['www', 'root', 'mysql', 'shutdown', 'postfix', 'smmsp', 'sshd', 'systemd-network', 'systemd-bus-proxy', + 'avahi-autoipd', 'mail', 'sync', 'lp', 'adm', 'bin', 'mailnull', 'ntp', 'daemon', 'sys']; + + if 'user' in get: + return mw.returnData(False, '缺少参数!') + + if get['user'] in users: return mw.returnData(False, '不能删除系统和环境关键用户!') + + r = mw.execShell("userdel " + get['user']) + if r[1].find('process') != -1: + try: + pid = r[1].split()[-1] + p = psutil.Process(int(pid)) + pname = p.name() + p.kill() + mw.execShell("pkill -9 " + pname) + r = mw.execShell("userdel " + get.user) + except: + pass + if r[1].find('userdel:') != -1: return mw.returnData(False, r[1]); + return mw.returnData(True, '删除成功!') + + # 获取用户列表 从/etc/passwd文件中读取 + def get_user_list(self, get={}): + tmpList = mw.readFile('/etc/passwd').strip().split("\n") + userList = [] + self.groupList = self.get_group_list(get) + for ul in tmpList: + tmp = ul.split(':') + if len(tmp) < 6: continue + userInfo = {} + userInfo['username'] = tmp[0] + userInfo['uid'] = tmp[2] + userInfo['gid'] = tmp[3] + userInfo['group'] = self.get_group_name(tmp[3]) + userInfo['ps'] = self.get_user_ps(tmp[0], tmp[4]) + userInfo['home'] = tmp[5] + userInfo['login_shell'] = tmp[6] + userList.append(userInfo) + + # print(userList) + if 'search' in get: + if get['search'] != '': + userList = self.search_user(userList, get['search']) + return userList + + + # 获取当前网络连接信息 + def get_network_list(self, get = {}): + data = {} + data['is_mac'] = False + if self.is_mac: + data['is_mac'] = self.is_mac + return data + + + netstats = psutil.net_connections() + + networkList = [] + for netstat in netstats: + tmp = {} + if netstat.type == 1: + tmp['type'] = 'tcp' + else: + tmp['type'] = 'udp' + tmp['family'] = netstat.family + tmp['laddr'] = netstat.laddr + tmp['raddr'] = netstat.raddr + tmp['status'] = netstat.status + p = psutil.Process(netstat.pid) + tmp['process'] = p.name() + if tmp['process'] in ['BT-Panel', 'gunicorn', 'baota_coll', 'baota_client']: continue + tmp['pid'] = netstat.pid + networkList.append(tmp) + del (p) + del (tmp) + networkList = sorted(networkList, key=lambda x: x['status'], reverse=True) + + data['list'] = networkList + data['state'] = self.get_network() + if hasattr(get, 'search'): + if get.search != '': + data['list'] = self.search_network(data['list'], get.search) + return data + + # 获取当前运行级别 get_service_list ——> 引用get_my_runlevel + def get_my_runlevel(self): + try: + runlevel = mw.execShell('runlevel')[0].split()[1] + except: + runlevel_dict = {"multi-user.target": '3', 'rescue.target': '1', 'poweroff.target': '0', + 'graphical.target': '5', "reboot.target": '6'} + r_tmp = mw.execShell('systemctl get-default')[0].strip() + if r_tmp in runlevel_dict: + runlevel = runlevel_dict[r_tmp] + else: + runlevel = '3' + return runlevel + + # 服务注释 get_service_list——>引用 get_run_ps + def get_run_ps(self, name): + runPs = {'netconsole': '网络控制台日志', 'network': '网络服务', 'jexec': 'JAVA', 'tomcat8': 'Apache Tomcat', + 'tomcat7': 'Apache Tomcat', 'mariadb': 'Mariadb', + 'tomcat9': 'Apache Tomcat', 'tomcat': 'Apache Tomcat', 'memcached': 'Memcached缓存器', + 'php-fpm-53': 'PHP-5.3', 'php-fpm-52': 'PHP-5.2', + 'php-fpm-54': 'PHP-5.4', 'php-fpm-55': 'PHP-5.5', 'php-fpm-56': 'PHP-5.6', 'php-fpm-70': 'PHP-7.0', + 'php-fpm-71': 'PHP-7.1', + 'php-fpm-72': 'PHP-7.2', 'rsync_inotify': 'rsync实时同步', 'pure-ftpd': 'FTP服务', + 'mongodb': 'MongoDB', 'nginx': 'Web服务器(Nginx)', + 'httpd': 'Web服务器(Apache)', 'mw': '面板', 'mysqld': 'MySQL数据库', 'rsynd': 'rsync主服务', + 'php-fpm': 'PHP服务', 'systemd': '系统核心服务', + '/etc/rc.local': '用户自定义启动脚本', '/etc/profile': '全局用户环境变量', + '/etc/inittab': '用于自定义系统运行级别', '/etc/rc.sysinit': '系统初始化时调用的脚本', + 'sshd': 'SSH服务', 'crond': '计划任务服务', 'udev-post': '设备管理系统', 'auditd': '审核守护进程', + 'rsyslog': 'rsyslog服务', 'sendmail': '邮件发送服务', 'blk-availability': 'lvm2相关', + 'local': '用户自定义启动脚本', 'netfs': '网络文件系统', 'lvm2-monitor': 'lvm2相关', + 'xensystem': 'xen云平台相关', 'iptables': 'iptables防火墙', 'ip6tables': 'iptables防火墙 for IPv6', + 'firewalld': 'firewall防火墙'} + if name in runPs: return runPs[name] + return name + + # 清除注释 + def clear_comments(self, body): + bodyTmp = body.split("\n") + bodyR = "" + for tmp in bodyTmp: + if tmp.startswith('#'): continue + if tmp.strip() == '': continue + bodyR += tmp + return bodyR + + # 获取启动项 + def get_run_list(self, get={}): + data = {} + data['is_mac'] = False + if self.is_mac: + data['is_mac'] = self.is_mac + return data + + runFile = ['/etc/rc.local', '/etc/profile', '/etc/inittab', '/etc/rc.sysinit'] + runList = [] + for rfile in runFile: + if not os.path.exists(rfile): continue + bodyR = self.clear_comments(mw.readFile(rfile)) + if not bodyR: continue + stat = os.stat(rfile) + accept = str(oct(stat.st_mode)[-3:]) + if accept == '644': continue + tmp = {} + tmp['name'] = rfile + tmp['srcfile'] = rfile + tmp['size'] = os.path.getsize(rfile) + tmp['access'] = accept + tmp['ps'] = self.get_run_ps(rfile) + # tmp['body'] = bodyR + runList.append(tmp) + runlevel = self.get_my_runlevel() + runPath = ['/etc/init.d', '/etc/rc' + runlevel + '.d'] + tmpAll = [] + islevel = False + for rpath in runPath: + if not os.path.exists(rpath): continue + if runPath[1] == rpath: islevel = True + for f in os.listdir(rpath): + if f[:1] != 'S': continue + filename = rpath + '/' + f + if not os.path.exists(filename): continue + if os.path.isdir(filename): continue + if os.path.islink(filename): + flink = os.readlink(filename).replace('../', '/etc/') + if not os.path.exists(flink): continue + filename = flink + tmp = {} + tmp['name'] = f + if islevel: tmp['name'] = f[3:] + if tmp['name'] in tmpAll: continue + stat = os.stat(filename) + accept = str(oct(stat.st_mode)[-3:]) + if accept == '644': continue + tmp['srcfile'] = filename + tmp['access'] = accept + tmp['size'] = os.path.getsize(filename) + tmp['ps'] = self.get_run_ps(tmp['name']) + runList.append(tmp) + tmpAll.append(tmp['name']) + data = {} + data['run_list'] = runList + data['run_level'] = runlevel + if 'search' in get: + if get['search'] != '': + data['run_list'] = self.search_run(data['run_list'], get['search']) + return data + + # 外部接口 查询服务启动级别 /etc/init.d/ + def get_service_list(self, get = {}): + data = {} + data['is_mac'] = False + if self.is_mac: + data['is_mac'] = self.is_mac + return data + + init_d = '/etc/init.d/' + serviceList = [] + for sname in os.listdir(init_d): + try: + if str(oct(os.stat(init_d + sname).st_mode)[-3:]) == '644': continue + serviceInfo = {} + runlevels = self.get_runlevel(sname) + serviceInfo['name'] = sname + serviceInfo['runlevel_0'] = runlevels[0] + serviceInfo['runlevel_1'] = runlevels[1] + serviceInfo['runlevel_2'] = runlevels[2] + serviceInfo['runlevel_3'] = runlevels[3] + serviceInfo['runlevel_4'] = runlevels[4] + serviceInfo['runlevel_5'] = runlevels[5] + serviceInfo['runlevel_6'] = runlevels[6] + serviceInfo['ps'] = self.get_run_ps(sname) + serviceList.append(serviceInfo) + except: + continue + + data['runlevel'] = self.get_my_runlevel() + data['serviceList'] = sorted(serviceList, key=lambda x: x['name'], reverse=False) + data['serviceList'] = self.get_systemctl_list(data['serviceList'], data['runlevel']) + if hasattr(get, 'search'): + if get.search != '': + data['serviceList'] = self.search_service(data['serviceList'], get.search) + return data + + # 获取存放计划任务的路径 + def get_cron_file(self): + filename = '/var/spool/cron/crontabs/root' + if os.path.exists(filename): return filename + filename = '/var/spool/cron/root' + if not os.path.exists(filename): + mw.writeFile(filename, "") + return filename + + # 外部接口,获取计划任务列表 + def get_cron_list(self, get = {}): + filename = self.get_cron_file() + tmpList = public.readFile(filename).split("\n") + cronList = [] + for c in tmpList: + c = c.strip() + if c.startswith('#'): continue + tmp = c.split(' ') + if len(tmp) < 6: continue + cronInfo = {} + cronInfo['cycle'] = self.decode_cron_cycle(tmp) + if not cronInfo['cycle']: continue + ctmp = self.decode_cron_connand(tmp) + cronInfo['command'] = c + cronInfo['ps'] = ctmp[1] + cronInfo['exe'] = ctmp[2] + cronInfo['test'] = ctmp[0] + cronList.append(cronInfo) + if hasattr(get, 'search'): + if get.search != '': + cronList = self.search_cron(cronList, get.search) + return cronList + + # 获取当前会话 + def get_who(self, get = {}): + whoTmp = mw.execShell('who')[0] + tmpList = whoTmp.split("\n") + whoList = [] + for w in tmpList: + tmp = w.split() + if len(tmp) < 5: continue + whoInfo = {} + whoInfo['user'] = tmp[0] + whoInfo['pts'] = tmp[1] + whoInfo['date'] = tmp[2] + ' ' + tmp[3] + whoInfo['ip'] = tmp[4].replace('(', '').replace(')', '') + if len(tmp) > 5: + whoInfo['date'] = tmp[2] + ' ' + tmp[3] + ' ' + tmp[4] + whoInfo['ip'] = tmp[5].replace('(', '').replace(')', '') + whoList.append(whoInfo) + if hasattr(get, 'search'): + if get.search != '': + whoList = self.search_who(whoList, get.search) + return whoList + + def test_cpu(self): + pid = 43046 + p = psutil.Process(pid) + tmp = {} + self.new_info['cpu_time'] = self.get_cpu_time() + self.new_info['time'] = time.time() + with p.oneshot(): + p_cpus = p.cpu_times() + print(p_cpus) + + tmp['cpu_percent'] = self.get_cpu_percent(str(pid), p_cpus, self.new_info['cpu_time']) + print(tmp['cpu_percent']) + + +mc_instance = mainClass.instance() + +def get_network_list(args = {}): + return mc_instance.get_network_list(args) + +def get_process_list(args = {}): + return mc_instance.get_process_list(args) + +def get_service_list(args = {}): + return mc_instance.get_service_list(args) + +def get_run_list(args = {}): + return mc_instance.get_run_list(args) + +def get_cron_list(args = {}): + return mc_instance.get_cron_list(args) + +def get_who(args = {}): + return mc_instance.get_who(args) + +def get_process_info(args = {}): + return mc_instance.get_process_info(args) + +def get_user_list(args = {}): + return mc_instance.get_user_list(args) + +def remove_user(args = {}): + return mc_instance.remove_user(args) + +if __name__ == "__main__": + # mc_instance.get_process_list() + print(mc_instance.get_process_info({'pid':66647})) + # for x in range(10): + # mc_instance.test_cpu() + # time.sleep(1) + + # mc_instance.test_cpu() + # time.sleep(1) + # mc_instance.test_cpu() From 4d85ed4e883008a35dad278b25322d4c333a4880 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:22:42 +0800 Subject: [PATCH 006/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 230b5d114b..070ed6668b 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -724,7 +724,6 @@ def get_process_list_linux(self, get = {}): except: continue - cache.set(self.old_path, self.new_info, 600) processList = self.__pro_s_s(processList) res = True if get.sortx == 'status': res = False From 1ef0c4b8f0aa8aa6865d8705d9416c07b534c7e5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:23:06 +0800 Subject: [PATCH 007/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 070ed6668b..9c0e2bcb7e 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -700,7 +700,7 @@ def get_process_list_linux(self, get = {}): tmp['name'] = p.name() tmp['pid'] = pid tmp['ppid'] = p.ppid() - # tmp['create_time'] = int(p.create_time()) + tmp['create_time'] = int(p.create_time()) tmp['status'] = p_state tmp['user'] = p.username() tmp['memory_used'] = p_mem.uss From 4b11415f36d727e7a61e87439c99f7f80b615aad Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:23:52 +0800 Subject: [PATCH 008/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 9c0e2bcb7e..309ad94020 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -671,7 +671,7 @@ def get_process_list_mac(self, args = {}): # 获取进程信息 def get_process_list_linux(self, get = {}): self.check_process_net_total() - self.Pids = psutil.pids() + self.pids = psutil.pids() processList = [] if type(self.new_info) != dict: self.new_info = {} self.new_info['cpu_time'] = self.get_cpu_time() @@ -684,7 +684,7 @@ def get_process_list_linux(self, get = {}): info['mem'] = 0 info['disk'] = 0 status_ps = {'sleeping': '睡眠', 'running': '活动'} - for pid in self.Pids: + for pid in self.pids: tmp = {} try: p = psutil.Process(pid) From 2ba57ab05f05ea7bd0bf979b4fe7f69717fc7b4f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:25:04 +0800 Subject: [PATCH 009/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 309ad94020..2edda475ea 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -677,7 +677,10 @@ def get_process_list_linux(self, get = {}): self.new_info['cpu_time'] = self.get_cpu_time() self.new_info['time'] = time.time() self.get_process_net_list() - if not 'sortx' in get: get.sortx = 'all' + + if not 'sortx' in get: + get['sortx'] = 'all' + info = {} info['activity'] = 0 info['cpu'] = 0.00 From 203b4d11a80e743c38360e467f2c078bccaa56ea Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:26:48 +0800 Subject: [PATCH 010/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 39 ++++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 2edda475ea..3cdc7d7e2a 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -677,9 +677,25 @@ def get_process_list_linux(self, get = {}): self.new_info['cpu_time'] = self.get_cpu_time() self.new_info['time'] = time.time() self.get_process_net_list() - - if not 'sortx' in get: - get['sortx'] = 'all' + + sortx = 'all' + if 'sortx' in args: sortx = args['sortx'] + + if not 'sortx' in args: + args['sortx'] = 'status' + if args['sortx'] == 'status': res = False + if 'reverse' in args: + if args['reverse'] in ['undefined', 'null']: + args['reverse'] = 'True' + args['sortx'] = 'all' + if not args['reverse'] in ['True', 'False']: args['reverse'] = 'True' + res_list = {'True': True, 'False': False} + res = res_list[args['reverse']] + else: + args['reverse'] = True + if args['reverse'] in ['undefined', 'null']: + args['reverse'] = 'True' + args['sortx'] = 'all' info = {} info['activity'] = 0 @@ -729,21 +745,8 @@ def get_process_list_linux(self, get = {}): processList = self.__pro_s_s(processList) res = True - if get.sortx == 'status': res = False - if 'reverse' in get: - if get.reverse in ['undefined', 'null']: - get.reverse = 'True' - get.sortx = 'all' - if not get.reverse in ['True', 'False']: get.reverse = 'True' - res_list = {'True': True, 'False': False} - res = res_list[get.reverse] - else: - get.reverse = True - if get.reverse in ['undefined', 'null']: - get.reverse = 'True' - get.sortx = 'all' - if get.sortx not in ['all']: - processList = sorted(processList, key=lambda x: x[get.sortx], reverse=res) + if sortx not in ['all']: + processList = sorted(processList, key=lambda x: x[get['sortx']], reverse=res) else: processList = sorted(processList, key=lambda x: [x['cpu_percent'], x['up'], x['down'], x['io_write_speed'], x['io_read_speed'], x['connects'], x['threads'], From 900dfc6ca7b0239413a368e6206e2f809468307b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:28:42 +0800 Subject: [PATCH 011/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 3cdc7d7e2a..b0563480b7 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -679,23 +679,23 @@ def get_process_list_linux(self, get = {}): self.get_process_net_list() sortx = 'all' - if 'sortx' in args: sortx = args['sortx'] - - if not 'sortx' in args: - args['sortx'] = 'status' - if args['sortx'] == 'status': res = False - if 'reverse' in args: - if args['reverse'] in ['undefined', 'null']: - args['reverse'] = 'True' - args['sortx'] = 'all' - if not args['reverse'] in ['True', 'False']: args['reverse'] = 'True' + if 'sortx' in get: sortx = get['sortx'] + + if not 'sortx' in get: + get['sortx'] = 'status' + if get['sortx'] == 'status': res = False + if 'reverse' in get: + if get['reverse'] in ['undefined', 'null']: + get['reverse'] = 'True' + get['sortx'] = 'all' + if not get['reverse'] in ['True', 'False']: get['reverse'] = 'True' res_list = {'True': True, 'False': False} - res = res_list[args['reverse']] + res = res_list[get['reverse']] else: - args['reverse'] = True - if args['reverse'] in ['undefined', 'null']: - args['reverse'] = 'True' - args['sortx'] = 'all' + get['reverse'] = True + if get['reverse'] in ['undefined', 'null']: + get['reverse'] = 'True' + get['sortx'] = 'all' info = {} info['activity'] = 0 @@ -759,7 +759,7 @@ def get_process_list_linux(self, get = {}): data['info'] = info if 'search' in get: if get['search'] != '': - data['process_list'] = self.search_pro(data['process_list'], get.search) + data['process_list'] = self.search_pro(data['process_list'], get['search']) self.get_meter_head() data['meter_head'] = self.meter_head return data From ffec30883f3587ec77e9dd4f457065981fae3b3e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:30:29 +0800 Subject: [PATCH 012/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index b0563480b7..8752a831e2 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -821,7 +821,7 @@ def get_group_name(self, gid): # 用户名注释:ps get_user_list——>引用get_user_ps def get_user_ps(self, name, ps): - userPs = {'www': '宝塔面板', 'root': '超级管理员', 'mysql': '用于运行MySQL的用户', + userPs = {'www': '面板', 'root': '超级管理员', 'mysql': '用于运行MySQL的用户', 'mongo': '用于运行MongoDB的用户', 'git': 'git用户', 'mail': 'mail', 'nginx': '第三方nginx用户', 'postfix': 'postfix邮局用户', 'lp': '打印服务帐号', From 9b0c30e554ea3de05aa574d05afeaebe3a73da2f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:33:02 +0800 Subject: [PATCH 013/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 8752a831e2..6e49afe599 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1176,8 +1176,8 @@ def remove_user(args = {}): return mc_instance.remove_user(args) if __name__ == "__main__": - # mc_instance.get_process_list() - print(mc_instance.get_process_info({'pid':66647})) + print(mc_instance.get_process_list()) + # print(mc_instance.get_process_info({'pid':66647})) # for x in range(10): # mc_instance.test_cpu() # time.sleep(1) From 808e65091da3af6880fb73a08ffb09c08e603486 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:34:19 +0800 Subject: [PATCH 014/121] Update install.sh --- plugins/task_manager/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/task_manager/install.sh b/plugins/task_manager/install.sh index 6cb2d35978..d9e58e88b4 100755 --- a/plugins/task_manager/install.sh +++ b/plugins/task_manager/install.sh @@ -10,6 +10,8 @@ serverPath=$(dirname "$rootPath") install_tmp=${rootPath}/tmp/mw_install.pl VERSION=$2 +# python3 plugins/task_manager/task_manager_index.py + Install_App() { echo '正在安装脚本文件...' > $install_tmp From b9b7081eb453f741965489b303a0651f3c948cb8 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 00:38:18 +0800 Subject: [PATCH 015/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 6e49afe599..9bce2b5aa5 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -132,6 +132,38 @@ def get_connects(self, pid): pass return connects + # 获取进程io写 + def get_io_write(self, pid, io_write): + # self.get_old() + disk_io_write = 0 + if not self.old_info: self.old_info = {} + if not pid in self.old_info: + self.new_info[pid]['io_write'] = io_write + return disk_io_write + if not 'time' in self.old_info: self.old_info['time'] = self.new_info['time'] + io_end = (io_write - self.old_info[pid]['io_write']) + if io_end > 0: + disk_io_write = io_end / (time.time() - self.old_info['time']) + self.new_info[pid]['io_write'] = io_write + if disk_io_write > 0: return int(disk_io_write) + return 0 + + # 获取io读 + def get_io_read(self, pid, io_read): + # self.get_old() + disk_io_read = 0 + if not self.old_info: self.old_info = {} + if not pid in self.old_info: + self.new_info[pid]['io_read'] = io_read + return disk_io_read + if not 'time' in self.old_info: self.old_info['time'] = self.new_info['time'] + io_end = (io_read - self.old_info[pid]['io_read']) + if io_end > 0: + disk_io_read = io_end / (time.time() - self.old_info['time']) + self.new_info[pid]['io_read'] = io_read + if disk_io_read > 0: return int(disk_io_read) + return 0 + def get_mem_info(self, get=None): mem = psutil.virtual_memory() if self.is_mac: @@ -740,7 +772,7 @@ def get_process_list_linux(self, get = {}): processList.append(tmp) del (p) del (tmp) - except: + except Exception as e: continue processList = self.__pro_s_s(processList) From 36b50d3bf299a96a6e072ff273544293c3bf5fba Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:01:15 +0800 Subject: [PATCH 016/121] update --- plugins/task_manager/js/task_manager.js | 2 +- plugins/task_manager/task_manager_index.py | 26 ++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 413d045bd0..da4a592e50 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -710,7 +710,7 @@ function get_run_list() { return; } - + var rdata = rdata.data; var tbody_tr = ''; for (var i = 0; i < rdata.run_list.length; i++) { tbody_tr += '\ diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 9bce2b5aa5..b2374b1a3a 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -134,33 +134,40 @@ def get_connects(self, pid): # 获取进程io写 def get_io_write(self, pid, io_write): - # self.get_old() disk_io_write = 0 if not self.old_info: self.old_info = {} if not pid in self.old_info: - self.new_info[pid]['io_write'] = io_write + self.old_info[pid] = {} + self.old_info[pid]['io_write'] = io_write + return disk_io_write + + if not 'io_write' in self.old_info[pid]: + self.old_info[pid]['io_write'] = io_write return disk_io_write - if not 'time' in self.old_info: self.old_info['time'] = self.new_info['time'] + io_end = (io_write - self.old_info[pid]['io_write']) if io_end > 0: disk_io_write = io_end / (time.time() - self.old_info['time']) - self.new_info[pid]['io_write'] = io_write + self.old_info[pid]['io_write'] = io_write if disk_io_write > 0: return int(disk_io_write) return 0 # 获取io读 def get_io_read(self, pid, io_read): - # self.get_old() disk_io_read = 0 - if not self.old_info: self.old_info = {} if not pid in self.old_info: - self.new_info[pid]['io_read'] = io_read + self.old_info[pid] = {} + self.old_info[pid]['io_read'] = io_read + return disk_io_read + + if not 'io_read' in self.old_info[pid]: + self.old_info[pid]['io_read'] = io_read return disk_io_read - if not 'time' in self.old_info: self.old_info['time'] = self.new_info['time'] + io_end = (io_read - self.old_info[pid]['io_read']) if io_end > 0: disk_io_read = io_end / (time.time() - self.old_info['time']) - self.new_info[pid]['io_read'] = io_read + self.old_info[pid]['io_read'] = io_read if disk_io_read > 0: return int(disk_io_read) return 0 @@ -773,6 +780,7 @@ def get_process_list_linux(self, get = {}): del (p) del (tmp) except Exception as e: + print(mw.getTracebackInfo()) continue processList = self.__pro_s_s(processList) From dc1f03b7ae3473113bd2f0223536c0d8f63ec5f7 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:04:16 +0800 Subject: [PATCH 017/121] update --- plugins/task_manager/js/task_manager.js | 4 +-- plugins/task_manager/task_manager_index.py | 36 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index da4a592e50..22dcd21935 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -591,8 +591,8 @@ function get_network_list(rflush) { return; } - console.log(rdata); - + var rdata = rdata.data; + var tbody_tr = ""; for (var i = 0; i < rdata.list.length; i++) { tbody_tr += "" diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index b2374b1a3a..727db43724 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -934,6 +934,42 @@ def get_user_list(self, get={}): userList = self.search_user(userList, get['search']) return userList + # get_network_list ——>引用get_network + def get_network(self): + try: + self.get_net_old() + networkIo = psutil.net_io_counters()[:4] + self.new_net_info['upTotal'] = networkIo[0] + self.new_net_info['downTotal'] = networkIo[1] + self.new_net_info['upPackets'] = networkIo[2] + self.new_net_info['downPackets'] = networkIo[3] + self.new_net_info['time'] = time.time() + + if not self.old_net_info: self.old_net_info = {} + if not 'upTotal' in self.old_net_info: + time.sleep(0.1) + networkIo = psutil.net_io_counters()[:4] + self.old_net_info['upTotal'] = networkIo[0] + self.old_net_info['downTotal'] = networkIo[1] + self.old_net_info['upPackets'] = networkIo[2] + self.old_net_info['downPackets'] = networkIo[3] + self.old_net_info['time'] = time.time() + + s = self.new_net_info['time'] - self.old_net_info['time'] + networkInfo = {} + networkInfo['upTotal'] = networkIo[0] + networkInfo['downTotal'] = networkIo[1] + networkInfo['up'] = round((float(networkIo[0]) - self.old_net_info['upTotal']) / s, 2) + networkInfo['down'] = round((float(networkIo[1]) - self.old_net_info['downTotal']) / s, 2) + networkInfo['downPackets'] = networkIo[3] + networkInfo['upPackets'] = networkIo[2] + networkInfo['downPackets_s'] = int((networkIo[3] - self.old_net_info['downPackets']) / s) + networkInfo['upPackets_s'] = int((networkIo[2] - self.old_net_info['upPackets']) / s) + cache.set(self.old_net_path, self.new_net_info, 600) + return networkInfo + except: + return None + # 获取当前网络连接信息 def get_network_list(self, get = {}): From aaa2b766a3f42377c8fe0d1b028e6f10e82c7325 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:07:52 +0800 Subject: [PATCH 018/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 22dcd21935..c8199ea4db 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -456,10 +456,12 @@ function createProcessTable(getboday, data) { if ('io_read_bytes' in realProcess[i]){ tbody_td =+ '' + toSize(realProcess[i].io_read_speed).replace(' ', '') + ''; tbody_td =+ '' + toSize(realProcess[i].io_write_speed).replace(' ', '') + ''; + + tbody_td =+ '' + toSize(realProcess[i].up).replace(' ', '') + ''; + tbody_td =+ '' + toSize(realProcess[i].down).replace(' ', '') + ''; } - // ' + ToSize(realProcess[i].up).replace(' ', '') + '\ - // ' + ToSize(realProcess[i].down).replace(' ', '') + '\ + tbody_tr += '\ \ ' + colp + '\ @@ -510,7 +512,7 @@ function get_resource_list() { // console.log('realllll'); buildRealProcess() - var tbody_tr = createProcessTable(true) + var tbody_tr = createProcessTable(true); var tbody = '\ \ 应用名称\ From 3ccf084a531cd21eeba57ad843de1057c1bde97d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:27:43 +0800 Subject: [PATCH 019/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index c8199ea4db..e648e8ca4b 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -424,8 +424,6 @@ function buildRealProcess() { // 生成进程表格内容 function createProcessTable(getboday, data) { - console.log('createProcessTable',getboday, data); - console.log('realProcess',realProcess); var tbody_tr = ''; for (var i = 0; i < realProcess.length; i++) { if (realProcess[i].status == '活动') realProcess[i].status = '活动'; @@ -454,13 +452,12 @@ function createProcessTable(getboday, data) { var tbody_td = ''; if ('io_read_bytes' in realProcess[i]){ - tbody_td =+ '' + toSize(realProcess[i].io_read_speed).replace(' ', '') + ''; - tbody_td =+ '' + toSize(realProcess[i].io_write_speed).replace(' ', '') + ''; + tbody_td += '' + toSize(realProcess[i].io_read_speed).replace(' ', '') + ''; + tbody_td += '' + toSize(realProcess[i].io_write_speed).replace(' ', '') + ''; - tbody_td =+ '' + toSize(realProcess[i].up).replace(' ', '') + ''; - tbody_td =+ '' + toSize(realProcess[i].down).replace(' ', '') + ''; + tbody_td += '' + toSize(realProcess[i].up).replace(' ', '') + ''; + tbody_td += '' + toSize(realProcess[i].down).replace(' ', '') + ''; } - tbody_tr += '\ \ From 93ef3659f2e32ebfc3f66b247d8a2aca4561e023 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:34:17 +0800 Subject: [PATCH 020/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 727db43724..c798ddde5f 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1186,6 +1186,13 @@ def get_cron_list(self, get = {}): cronList = self.search_cron(cronList, get.search) return cronList + # 外部接口 强制结束会话 + def pkill_session(self, get= {}): + if not 'pts' in get: + return mw.returnData(False, '缺少参数!') + mw.execShell("pkill -kill -t " + get['pts']) + return mw.returnData(True, '已强行结束会话[' + get['pts'] + ']') + # 获取当前会话 def get_who(self, get = {}): whoTmp = mw.execShell('who')[0] @@ -1239,6 +1246,9 @@ def get_run_list(args = {}): def get_cron_list(args = {}): return mc_instance.get_cron_list(args) +def pkill_session(args = {}): + return mc_instance.pkill_session(args) + def get_who(args = {}): return mc_instance.get_who(args) From 894656741d5dada780f75f16a5963fd7929fa4ba Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:35:09 +0800 Subject: [PATCH 021/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index e648e8ca4b..68574481ad 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -937,10 +937,12 @@ function remove_cron(index) { function pkill_session(pts) { safeMessage('强制断开会话[' + pts + ']', '强制断开此会话吗?', function () { var loadT = layer.msg('正在断开会话..', {icon: 16, time: 0, shade: [0.3, '#000']}); - $.post('/plugin?action=a&name=task_manager&s=pkill_session', {pts: pts}, function (rdata) { + tmPostCallback('pkill_session', {pts:pts}, function(data){ layer.close(loadT); layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); - if (rdata.status) get_who_list(); + if (rdata.status){ + get_who_list(); + } }); }); } From 39853e39c769942a08ce781956ffc4246a38c817 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:38:37 +0800 Subject: [PATCH 022/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 68574481ad..f60936933c 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -939,6 +939,8 @@ function pkill_session(pts) { var loadT = layer.msg('正在断开会话..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('pkill_session', {pts:pts}, function(data){ layer.close(loadT); + + var rdata = data.data; layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); if (rdata.status){ get_who_list(); From 9884bbd0e3179d1cde8b27a1ed3146a1b5d24fbe Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:38:53 +0800 Subject: [PATCH 023/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index f60936933c..a48cd22425 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -966,7 +966,7 @@ function set_runlevel_state(runlevel, serviceName) { function get_process_info(pid) { var loadT = layer.msg('正在获取进程信息[' + pid + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('get_process_info', {pid:pid}, function(data){ - console.log('get_process_info',data); + // console.log('get_process_info',data); layer.close(loadT); var rdata = data.data; fileBody = ''; From 50f44afd826d1f459ab13205ba181eda280c1e51 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:48:47 +0800 Subject: [PATCH 024/121] update --- plugins/task_manager/js/task_manager.js | 3 +- plugins/task_manager/task_manager_index.py | 42 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index a48cd22425..2485814caa 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -745,7 +745,6 @@ function get_service_list() { var loadT = layer.msg('正在获取服务列表..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('get_service_list', {search:search_val}, function(rdata){ layer.close(loadT); - if (rdata.data['is_mac']){ tbody_tr += "mac无法使用"; var tbody = '\ @@ -939,7 +938,7 @@ function pkill_session(pts) { var loadT = layer.msg('正在断开会话..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('pkill_session', {pts:pts}, function(data){ layer.close(loadT); - + var rdata = data.data; layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); if (rdata.status){ diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index c798ddde5f..9e7518d6da 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1117,6 +1117,42 @@ def get_run_list(self, get={}): data['run_list'] = self.search_run(data['run_list'], get['search']) return data + # 检查服务是否为系统服务get_systemctl_list——>引用cont_systemctl + def cont_systemctl(self, name): + conts = ['systemd', 'rhel', 'plymouth', 'rc-', '@', 'init', 'ipr', 'dbus', '-local'] + for c in conts: + if name.find(c) != -1: return False + return True + + # 获取系统服务运行级别 get_service_list——>引用get_systemctl_list + def get_systemctl_list(self, serviceList, runlevel): + systemctl_user_path = '/usr/lib/systemd/system/' + systemctl_run_path = '/etc/systemd/system/multi-user.target.wants/' + if not os.path.exists(systemctl_user_path) or not os.path.exists(systemctl_run_path): return serviceList + r = '.service' + for d in os.listdir(systemctl_user_path): + if d.find(r) == -1: continue; + if not self.cont_systemctl(d): continue; + isrun = '关闭' + serviceInfo = {} + serviceInfo['name'] = d.replace(r, '') + serviceInfo['runlevel_0'] = isrun + serviceInfo['runlevel_1'] = isrun + serviceInfo['runlevel_2'] = isrun + serviceInfo['runlevel_3'] = isrun + serviceInfo['runlevel_4'] = isrun + serviceInfo['runlevel_5'] = isrun + serviceInfo['runlevel_6'] = isrun + if os.path.exists(systemctl_run_path + d): + isrun = '开启' + serviceInfo['runlevel_' + runlevel] = isrun + serviceInfo['runlevel_3'] = isrun + serviceInfo['runlevel_5'] = isrun + + serviceInfo['ps'] = self.get_run_ps(serviceInfo['name']) + serviceList.append(serviceInfo) + return serviceList + # 外部接口 查询服务启动级别 /etc/init.d/ def get_service_list(self, get = {}): data = {} @@ -1148,9 +1184,9 @@ def get_service_list(self, get = {}): data['runlevel'] = self.get_my_runlevel() data['serviceList'] = sorted(serviceList, key=lambda x: x['name'], reverse=False) data['serviceList'] = self.get_systemctl_list(data['serviceList'], data['runlevel']) - if hasattr(get, 'search'): - if get.search != '': - data['serviceList'] = self.search_service(data['serviceList'], get.search) + if 'search' in get: + if get['search'] != '': + data['serviceList'] = self.search_service(data['serviceList'], get['search']) return data # 获取存放计划任务的路径 From 39676d1a3781ad5c1945607ee5d78867c0084eb6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:49:24 +0800 Subject: [PATCH 025/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 9e7518d6da..1536d51a5c 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1189,6 +1189,16 @@ def get_service_list(self, get = {}): data['serviceList'] = self.search_service(data['serviceList'], get['search']) return data + def search_service(self, data, search): + try: + ldata = [] + for i in data: + if search in i['name'] or search in i['ps']: + ldata.append(i) + return ldata + except: + return data + # 获取存放计划任务的路径 def get_cron_file(self): filename = '/var/spool/cron/crontabs/root' From 4bb9d0f0028285f20930686f75a7dbd45bb1e042 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 01:51:09 +0800 Subject: [PATCH 026/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 2485814caa..190b001733 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -766,6 +766,8 @@ function get_service_list() { return; } + var rdata = rdata.data; + var tbody_tr = ''; for (var i = 0; i < rdata.serviceList.length; i++) { tbody_tr += '\ From 10c7ec8718351bcb50d30124bfdada4bec9716d9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 03:32:34 +0800 Subject: [PATCH 027/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 1536d51a5c..896a5e9a76 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -717,12 +717,14 @@ def get_process_list_linux(self, get = {}): self.new_info['time'] = time.time() self.get_process_net_list() - sortx = 'all' - if 'sortx' in get: sortx = get['sortx'] if not 'sortx' in get: - get['sortx'] = 'status' - if get['sortx'] == 'status': res = False + get['sortx'] = 'all' + + res = True + if get['sortx'] == 'status': + res = False + if 'reverse' in get: if get['reverse'] in ['undefined', 'null']: get['reverse'] = 'True' @@ -784,8 +786,8 @@ def get_process_list_linux(self, get = {}): continue processList = self.__pro_s_s(processList) - res = True - if sortx not in ['all']: + + if get['sortx'] not in ['all']: processList = sorted(processList, key=lambda x: x[get['sortx']], reverse=res) else: processList = sorted(processList, key=lambda x: [x['cpu_percent'], x['up'], x['down'], x['io_write_speed'], From 9e774fb62910c1c1eeda855a41f0a6525946c75f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 17:57:58 +0800 Subject: [PATCH 028/121] update --- class/core/mw.py | 9 +++ plugins/task_manager/js/task_manager.js | 54 +++++++++------- plugins/task_manager/task_manager_index.py | 74 +++++++++++++++++++++- 3 files changed, 112 insertions(+), 25 deletions(-) diff --git a/class/core/mw.py b/class/core/mw.py index 04d8d61866..f5d90dbc9a 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -2110,6 +2110,15 @@ def notifyMessage(msg, stype='common', trigger_time=300, is_write_log=True): ##################### notify end ######################################### +def getGlibcVersion(): + try: + cmd_result = execShell("ldd --version")[0] + if not cmd_result: return '' + glibc_version = cmd_result.split("\n")[0].split()[-1] + except: + return '' + return glibc_version + ##################### ssh start ######################################### def getSshDir(): if isAppleSystem(): diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 190b001733..8dc9ffa768 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -861,47 +861,53 @@ function userdel(user) { //结束进程 function kill_process(pid, fpid) { if (fpid) { - select_pid = fpid; + select_pid = fpid; } var w = layer.confirm('您是否要结束 (' + pid + ') 进程?', { - btn: ['结束', '取消'], //按钮 - title: '结束' + pid, - closeBtn: 2 + btn: ['结束', '取消'], //按钮 + title: '结束' + pid, + closeBtn: 2 }, function () { - var loadT = layer.msg('正在结束进程[' + pid + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); - $.post('/plugin?action=a&name=task_manager&s=kill_process', {pid: pid}, function (rdata) { - layer.close(loadT); - layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); - if (rdata.status) get_process_list(); - }) + var loadT = layer.msg('正在结束进程[' + pid + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('kill_process', {pid:pid}, function(data){ + layer.close(loadT); + layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + if (rdata.status) { + get_process_list(); + } + }); }, function () { - layer.close(w) + layer.close(w); }) } //结束进程树 function kill_process_all(pid) { var w = layer.confirm('您是否要结束 (' + pid + ') 进程?', { - btn: ['结束', '取消'], //按钮 - title: '结束' + pid, - closeBtn: 2 + btn: ['结束', '取消'], //按钮 + title: '结束' + pid, + closeBtn: 2 }, function () { - var loadT = layer.msg('正在结束父进程[' + pid + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); - $.post('/plugin?action=a&name=task_manager&s=kill_process_all', {pid: pid}, function (rdata) { - layer.close(loadT); - layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); - if (rdata.status) get_process_list(); - }) + var loadT = layer.msg('正在结束父进程[' + pid + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('kill_process_all', {pid:pid}, function(data){ + layer.close(loadT); + var rdata = data.data; + showMsg(rdata.msg, function(){ + if (rdata.status) { + get_process_list(); + } + },{icon: rdata.status ? 1 : 2}); + }); }, function () { - layer.close(w) - }) + layer.close(w); + }); } //打开文件所在位置 function open_path(path) { - tmp = path.split('/') + var tmp = path.split('/'); tmp[tmp.length - 1] = ''; - path = '/' + tmp.join('/'); + var path = '/' + tmp.join('/'); openPath(path); } diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 896a5e9a76..722feeff23 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -584,6 +584,68 @@ def __get_children(self, pid: int) -> List: except: return [] + # 外部接口,结束进程,pid30以上 + def kill_process(self, get): + pid = int(get['pid']) + if pid < 30: return mw.returnData(False, '不能结束系统关键进程!') + if not pid in psutil.pids(): return mw.returnData(False, '指定进程不存在!') + if not 'killall' in get: + p = psutil.Process(pid) + if self.is_panel_process(pid): return mw.returnData(False, '不能结束面板服务进程') + p.kill() + return mw.returnData(True, '进程已结束') + return self.kill_process_all(pid) + + # 是否为面板进程 + def is_panel_process(self, pid): + if not self.panel_pid: + self.panel_pid = os.getpid() + if pid == self.panel_pid: return True + if not self.task_pid: + try: + self.task_pid = int(mw.execShell("ps aux | grep 'python3 task.py' |grep -v grep|head -n1|awk '{print $2}'")[0]) + except: + self.task_pid = -1 + if pid == self.task_pid: return True + return False + + # 遍历结束pid的子进程 kill_process_all——>引用kill_process_lower + def kill_process_lower(self, pid): + pids = psutil.pids() + for lpid in pids: + if lpid < 30: continue + if self.is_panel_process(lpid): continue + p = psutil.Process(lpid) + ppid = p.ppid() + if ppid == pid: + p.kill() + return self.kill_process_lower(lpid) + return True + + # 结束进程树 kill_process——>引用kill_process_all + def kill_process_all(self, pid): + # public.print_log(pid) + if pid < 30: return mw.returnData(True, '已结束此进程树!') + if self.is_panel_process(pid): return mw.returnData(False, '不能结束面板服务进程') + try: + if not pid in psutil.pids(): mw.returnData(True, '已结束此进程树!') + p = psutil.Process(pid) + ppid = p.ppid() + name = p.name() + p.kill() + mw.execShell('pkill -9 ' + name) + if name.find('php-') != -1: + mw.execShell("rm -f /tmp/php-cgi-*.sock") + elif name.find('mysql') != -1: + mw.execShell("rm -f /tmp/mysql.sock") + elif name.find('nginx') != -1: + mw.execShell("rm -f /tmp/mysql.sock") + self.kill_process_lower(pid) + if ppid: return self.kill_process_all(ppid) + except: + pass + return public.returnMsg(True, '已结束此进程树!') + def get_process_list(self, args = {}): # https://hellowac.github.io/psutil-doc-zh/processes/process_class/oneshot.html if self.is_mac: @@ -724,7 +786,7 @@ def get_process_list_linux(self, get = {}): res = True if get['sortx'] == 'status': res = False - + if 'reverse' in get: if get['reverse'] in ['undefined', 'null']: get['reverse'] = 'True' @@ -1285,6 +1347,16 @@ def get_network_list(args = {}): def get_process_list(args = {}): return mc_instance.get_process_list(args) +def kill_process(args = {}): + return mc_instance.kill_process(args) + +def kill_process_all(args = {}): + if not 'pid' in args: + return mw.returnData(False, '缺少参数!') + return mc_instance.kill_process_all(int(args['pid'])) + + + def get_service_list(args = {}): return mc_instance.get_service_list(args) From beccfe8519c44c78146ebd1e78d5f8161066c53c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 18:19:17 +0800 Subject: [PATCH 029/121] update --- plugins/task_manager/js/task_manager.js | 17 +++++++----- plugins/task_manager/task_manager_index.py | 31 +++++++++++++++++++++- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 8dc9ffa768..483db11850 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -913,13 +913,16 @@ function open_path(path) { //删除服务 function remove_service(serviceName) { - SafeMessage('删除服务【' + serviceName + '】', '删除后可能导致您的环境无法正常运行,继续吗?', function () { - var loadT = layer.msg('正在删除服务[' + serviceName + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); - $.post('/plugin?action=a&name=task_manager&s=remove_service', {serviceName: serviceName}, function (rdata) { - layer.close(loadT); - layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); - if (rdata.status) get_service_list(); - }); + safeMessage('删除服务【' + serviceName + '】', '删除后可能导致您的环境无法正常运行,继续吗?', function () { + var loadT = layer.msg('正在删除服务[' + serviceName + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('remove_service', {serviceName:serviceName}, function(data){ + layer.close(loadT); + showMsg(rdata.msg, function(){ + if (rdata.status){ + get_service_list(); + } + },{icon: rdata.status ? 1 : 2}) + }); }); } diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 722feeff23..6a83bd498d 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1217,6 +1217,34 @@ def get_systemctl_list(self, serviceList, runlevel): serviceList.append(serviceInfo) return serviceList + # 外部接口,删除服务。不能删除mw + def remove_service(self, get): + if not 'serviceName' in get: + return mw.returnData(False,'缺少参数'); + + serviceName = get['serviceName'] + if serviceName == 'mw': return mw.returnData(False, '不能通过面板结束面板服务!') + systemctl_user_path = '/usr/lib/systemd/system/' + if os.path.exists(systemctl_user_path + serviceName + '.service'): + return mw.returnData(False,'Systemctl托管的服务不能通过面板删除'); + + mw.execShell('service ' + serviceName + ' stop') + if os.path.exists('/usr/sbin/update-rc.d'): + mw.execShell('update-rc.d ' + serviceName + ' remove') + elif os.path.exists('/usr/sbin/chkconfig'): + mw.execShell('chkconfig --del ' + serviceName) + else: + mw.execShell("rm -f /etc/rc0.d/*" + serviceName) + mw.execShell("rm -f /etc/rc1.d/*" + serviceName) + mw.execShell("rm -f /etc/rc2.d/*" + serviceName) + mw.execShell("rm -f /etc/rc3.d/*" + serviceName) + mw.execShell("rm -f /etc/rc4.d/*" + serviceName) + mw.execShell("rm -f /etc/rc5.d/*" + serviceName) + mw.execShell("rm -f /etc/rc6.d/*" + serviceName) + filename = '/etc/init.d/' + serviceName + if os.path.exists(filename): os.remove(filename) + return mw.returnData(True, '删除成功!') + # 外部接口 查询服务启动级别 /etc/init.d/ def get_service_list(self, get = {}): data = {} @@ -1355,7 +1383,8 @@ def kill_process_all(args = {}): return mw.returnData(False, '缺少参数!') return mc_instance.kill_process_all(int(args['pid'])) - +def remove_service(args = {}): + return mc_instance.remove_service(args) def get_service_list(args = {}): return mc_instance.get_service_list(args) From b81e51c0e8d384f1cb4138c3ca0394317b3fc38b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 20:35:43 +0800 Subject: [PATCH 030/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 483db11850..d6812525b2 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -916,6 +916,7 @@ function remove_service(serviceName) { safeMessage('删除服务【' + serviceName + '】', '删除后可能导致您的环境无法正常运行,继续吗?', function () { var loadT = layer.msg('正在删除服务[' + serviceName + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('remove_service', {serviceName:serviceName}, function(data){ + var rdata = data.data; layer.close(loadT); showMsg(rdata.msg, function(){ if (rdata.status){ @@ -959,16 +960,14 @@ function pkill_session(pts) { }); } + //设置服务启动级别状态 function set_runlevel_state(runlevel, serviceName) { var loadT = layer.msg('正在设置服务[' + serviceName + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); - $.post('/plugin?action=a&name=task_manager&s=set_runlevel_state', { - runlevel: runlevel, - serviceName: serviceName - }, function (rdata) { - layer.close(loadT); - layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); - if (rdata.status) get_service_list(); + $.post('/plugin?action=a&name=task_manager&s=set_runlevel_state', {runlevel: runlevel,serviceName: serviceName}, function (rdata) { + layer.close(loadT); + layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + if (rdata.status) get_service_list(); }); } From 44d529d32f98016bcd5f7683e18af5923b512844 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 20:36:31 +0800 Subject: [PATCH 031/121] Update public.js --- route/static/app/public.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/route/static/app/public.js b/route/static/app/public.js index 08d2e6761f..b73fe3d810 100755 --- a/route/static/app/public.js +++ b/route/static/app/public.js @@ -610,7 +610,7 @@ function showMsg(msg, callback ,icon, time){ function openPath(a) { setCookie("open_dir_path", a); - window.location.href = "/files/" + window.location.href = "/files/"; } function onlineEditFile(k, f, callback) { From c83b2d5bc5f074467e0807dce1332e82041c1a4f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 22:09:59 +0800 Subject: [PATCH 032/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 43 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 6a83bd498d..62a34ff091 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1221,7 +1221,7 @@ def get_systemctl_list(self, serviceList, runlevel): def remove_service(self, get): if not 'serviceName' in get: return mw.returnData(False,'缺少参数'); - + serviceName = get['serviceName'] if serviceName == 'mw': return mw.returnData(False, '不能通过面板结束面板服务!') systemctl_user_path = '/usr/lib/systemd/system/' @@ -1245,6 +1245,44 @@ def remove_service(self, get): if os.path.exists(filename): os.remove(filename) return mw.returnData(True, '删除成功!') + # 外部接口,设置软件运行环境,不能设置0,6 + def set_runlevel_state(self, get): + if not 'runlevel' in get: + return mw.returnData(False,'缺少参数[runlevel]') + + if not 'serviceName' in get: + return mw.returnData(False,'缺少参数[serviceName]') + + runlevel = get['runlevel'] + serviceName = get['serviceName'] + if runlevel == '0' or runlevel == '6': + return mw.returnData(False,'为安全考虑,不能通过面板直接修改此运行级别') + + systemctl_user_path = '/usr/lib/systemd/system/' + systemctl_run_path = '/etc/systemd/system/multi-user.target.wants/' + if os.path.exists(systemctl_user_path + get.serviceName + '.service'): + runlevel = mw.execShell('runlevel')[0].split()[1] + if get.runlevel != runlevel: + return mw.returnData(False,'Systemctl托管的服务不能设置非当前运行级别的状态') + action = 'enable' + if os.path.exists(systemctl_run_path + serviceName + '.service'): + action = 'disable' + mw.execShell('systemctl ' + action + ' ' + serviceName + '.service') + return mw.returnData(True, '设置成功!') + + rc_d = '/etc/rc' + runlevel + '.d/' + import shutil + for d in os.listdir(rc_d): + if d[3:] != serviceName: continue + sfile = rc_d + d + c = 'S' + if d[:1] == 'S': c = 'K' + dfile = rc_d + c + d[1:] + shutil.move(sfile, dfile) + return mw.returnData(True, '设置成功!') + return mw.returnData(False, '设置失败!') + + # 外部接口 查询服务启动级别 /etc/init.d/ def get_service_list(self, get = {}): data = {} @@ -1386,6 +1424,9 @@ def kill_process_all(args = {}): def remove_service(args = {}): return mc_instance.remove_service(args) +def set_runlevel_state(args = {}): + return mc_instance.set_runlevel_state(args) + def get_service_list(args = {}): return mc_instance.get_service_list(args) From 61608199200ca18c4f53657b2d1c4ba77a22e230 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 22:17:14 +0800 Subject: [PATCH 033/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index d6812525b2..21c95c4792 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -960,14 +960,17 @@ function pkill_session(pts) { }); } - //设置服务启动级别状态 function set_runlevel_state(runlevel, serviceName) { var loadT = layer.msg('正在设置服务[' + serviceName + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); - $.post('/plugin?action=a&name=task_manager&s=set_runlevel_state', {runlevel: runlevel,serviceName: serviceName}, function (rdata) { + tmPostCallback('set_runlevel_state', {runlevel: runlevel,serviceName: serviceName}, function(data){ layer.close(loadT); - layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); - if (rdata.status) get_service_list(); + var rdata = data.data; + showMsg(rdata.msg, function(){ + if (rdata.status) { + get_service_list(); + } + },{icon: rdata.status ? 1 : 2}); }); } @@ -975,7 +978,6 @@ function set_runlevel_state(runlevel, serviceName) { function get_process_info(pid) { var loadT = layer.msg('正在获取进程信息[' + pid + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('get_process_info', {pid:pid}, function(data){ - // console.log('get_process_info',data); layer.close(loadT); var rdata = data.data; fileBody = ''; From 660d95616d2c75fd34dae64ebf9c1904303cd479 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 22:26:13 +0800 Subject: [PATCH 034/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 62a34ff091..b44e4b9083 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1260,7 +1260,7 @@ def set_runlevel_state(self, get): systemctl_user_path = '/usr/lib/systemd/system/' systemctl_run_path = '/etc/systemd/system/multi-user.target.wants/' - if os.path.exists(systemctl_user_path + get.serviceName + '.service'): + if os.path.exists(systemctl_user_path + serviceName + '.service'): runlevel = mw.execShell('runlevel')[0].split()[1] if get.runlevel != runlevel: return mw.returnData(False,'Systemctl托管的服务不能设置非当前运行级别的状态') From d9fbfcb1844bd201491471289a258d099df840ed Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 22:28:35 +0800 Subject: [PATCH 035/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index b44e4b9083..dd203363a4 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1261,8 +1261,8 @@ def set_runlevel_state(self, get): systemctl_user_path = '/usr/lib/systemd/system/' systemctl_run_path = '/etc/systemd/system/multi-user.target.wants/' if os.path.exists(systemctl_user_path + serviceName + '.service'): - runlevel = mw.execShell('runlevel')[0].split()[1] - if get.runlevel != runlevel: + runlevel_cmd = mw.execShell('runlevel')[0].split()[1] + if runlevel_cmd != runlevel: return mw.returnData(False,'Systemctl托管的服务不能设置非当前运行级别的状态') action = 'enable' if os.path.exists(systemctl_run_path + serviceName + '.service'): From d05e72e1d71fb437dc0c8b3f66322f8c0346c0a7 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 4 Jun 2024 23:42:37 +0800 Subject: [PATCH 036/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 47 +++++++++++++++++----- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index dd203363a4..48093d5a60 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -998,10 +998,22 @@ def get_user_list(self, get={}): userList = self.search_user(userList, get['search']) return userList + # 查询用户 + def search_user(self, data, search): + try: + ldata = [] + for i in data: + if search in i['username'] or search in i['ps'] or search in i['login_shell'] or search in i[ + 'home'] or search in i['group']: + ldata.append(i) + return ldata + except: + mw.writeLog('任务管理', traceback.format_exc()) + return data + # get_network_list ——>引用get_network def get_network(self): try: - self.get_net_old() networkIo = psutil.net_io_counters()[:4] self.new_net_info['upTotal'] = networkIo[0] self.new_net_info['downTotal'] = networkIo[1] @@ -1029,7 +1041,6 @@ def get_network(self): networkInfo['upPackets'] = networkIo[2] networkInfo['downPackets_s'] = int((networkIo[3] - self.old_net_info['downPackets']) / s) networkInfo['upPackets_s'] = int((networkIo[2] - self.old_net_info['upPackets']) / s) - cache.set(self.old_net_path, self.new_net_info, 600) return networkInfo except: return None @@ -1037,15 +1048,14 @@ def get_network(self): # 获取当前网络连接信息 def get_network_list(self, get = {}): + netstats = psutil.net_connections() data = {} data['is_mac'] = False if self.is_mac: data['is_mac'] = self.is_mac return data - netstats = psutil.net_connections() - networkList = [] for netstat in netstats: tmp = {} @@ -1059,7 +1069,7 @@ def get_network_list(self, get = {}): tmp['status'] = netstat.status p = psutil.Process(netstat.pid) tmp['process'] = p.name() - if tmp['process'] in ['BT-Panel', 'gunicorn', 'baota_coll', 'baota_client']: continue + if tmp['process'] in ['gunicorn']: continue tmp['pid'] = netstat.pid networkList.append(tmp) del (p) @@ -1068,11 +1078,29 @@ def get_network_list(self, get = {}): data['list'] = networkList data['state'] = self.get_network() - if hasattr(get, 'search'): - if get.search != '': - data['list'] = self.search_network(data['list'], get.search) + if 'search' in get: + if get['search'] != '': + data['list'] = self.search_network(data['list'], get['search']) return data + # 查询网络 + def search_network(self, data, search): + try: + ldata = [] + for i in data: + if search in i['process'] or search in i['status'] or search in str(i['pid']) or search in i['laddr'][ + 0] or search in str( + i['laddr'][1]): + ldata.append(i) + continue + if i['raddr'] != 'NONE': + for j in i['raddr']: + if search in str(j): + ldata.append(i) + return ldata + except: + return data + # 获取当前运行级别 get_service_list ——> 引用get_my_runlevel def get_my_runlevel(self): try: @@ -1452,7 +1480,8 @@ def remove_user(args = {}): return mc_instance.remove_user(args) if __name__ == "__main__": - print(mc_instance.get_process_list()) + # print(mc_instance.get_process_list()) + print(mc_instance.get_network_list()) # print(mc_instance.get_process_info({'pid':66647})) # for x in range(10): # mc_instance.test_cpu() From 6164d462f395287dd25e3f8b204e40e1e54e6620 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 00:08:28 +0800 Subject: [PATCH 037/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 21c95c4792..0b5cbe35c9 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -832,7 +832,7 @@ function get_user_list() { 用户组\ uid\ gid\ - 登陆脚本?\ + 登陆脚本\ 描述\ 操作\ \ From 6fd145fa52bf2bc97f23a53248faa5d27ade6250 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 00:13:42 +0800 Subject: [PATCH 038/121] Update index.html --- plugins/task_manager/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/task_manager/index.html b/plugins/task_manager/index.html index b51b420c20..12445cd4c6 100755 --- a/plugins/task_manager/index.html +++ b/plugins/task_manager/index.html @@ -453,7 +453,6 @@
进程 - 启动项 服务 网络 From a428636e1cb32ddffb723ad9c9bbb06c94a361e2 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 00:31:17 +0800 Subject: [PATCH 039/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 48093d5a60..15d467e106 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1369,7 +1369,7 @@ def get_cron_file(self): # 外部接口,获取计划任务列表 def get_cron_list(self, get = {}): filename = self.get_cron_file() - tmpList = public.readFile(filename).split("\n") + tmpList = mw.readFile(filename).split("\n") cronList = [] for c in tmpList: c = c.strip() @@ -1385,11 +1385,21 @@ def get_cron_list(self, get = {}): cronInfo['exe'] = ctmp[2] cronInfo['test'] = ctmp[0] cronList.append(cronInfo) - if hasattr(get, 'search'): - if get.search != '': - cronList = self.search_cron(cronList, get.search) + if 'search' in get, 'search': + if get['search'] != '': + cronList = self.search_cron(cronList, get['search']) return cronList + def search_cron(self, data, search): + try: + ldata = [] + for i in data: + if search in i['command'] or search in i['cycle'] or search in i['ps']: + ldata.append(i) + return ldata + except: + return data + # 外部接口 强制结束会话 def pkill_session(self, get= {}): if not 'pts' in get: From c6cf6fef0b9f6f01f6a9322073ff660ae02236ad Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 00:32:50 +0800 Subject: [PATCH 040/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 15d467e106..aef9b88934 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1366,6 +1366,49 @@ def get_cron_file(self): mw.writeFile(filename, "") return filename + # 解析计划任务执行周期 + def decode_cron_cycle(self, tmp): + if not tmp[4]: tmp[4] = '*' + if tmp[4] != '*': + cycle = '每周' + self.toWeek(int(tmp[4])) + '的' + tmp[1] + '时' + tmp[0] + '分' + elif tmp[2] != '*': + if tmp[2].find('*') == -1: + cycle = '每月的' + tmp[2] + '日,' + tmp[1] + '时' + tmp[0] + '分' + else: + cycle = '每隔' + tmp[2].split('/')[1] + '天' + tmp[1] + '时' + tmp[0] + '分' + elif tmp[1] != '*': + if tmp[1].find('*') == -1: + cycle = '每天的' + tmp[1] + '时' + tmp[0] + '分' + else: + cycle = '每隔' + tmp[1].split('/')[1] + '小时' + tmp[0] + '分钟' + elif tmp[0] != '*': + if tmp[0].find('*') == -1: + cycle = '每小时的第' + tmp[0] + '分钟' + else: + cycle = '每隔' + tmp[0].split('/')[1] + '分钟' + else: + return None + return cycle + + # 添加计划任务备注 + def decode_cron_connand(self, tmp): + command = '' + for i in range(len(tmp)): + if i < 5: continue + command += tmp[i] + ' ' + ps = '未知任务' + if command.find('/www/server/cron') != -1: + ps = '通过面板添加的计划任务' + elif command.find('.acme.sh') != -1: + ps = '基于acme.sh的证书续签任务' + elif command.find('certbot-auto renew') != -1: + ps = '基于certbot的证书续签任务' + + tmpScript = command.split('>')[0].strip() + filename = tmpScript.replace('"', '').split()[0] + # if not os.path.exists(filename): filename = ''; + return command.strip(), ps, filename + # 外部接口,获取计划任务列表 def get_cron_list(self, get = {}): filename = self.get_cron_file() From e6463e02864be208f9dcadf5ef33c12ae3595c2f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 00:35:08 +0800 Subject: [PATCH 041/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index aef9b88934..43c0d95956 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1428,7 +1428,7 @@ def get_cron_list(self, get = {}): cronInfo['exe'] = ctmp[2] cronInfo['test'] = ctmp[0] cronList.append(cronInfo) - if 'search' in get, 'search': + if 'search' in get: if get['search'] != '': cronList = self.search_cron(cronList, get['search']) return cronList From 640e8bbfa01df9f55ea39336f9c27f4941513eb4 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 00:37:13 +0800 Subject: [PATCH 042/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 43c0d95956..9e0080a9a4 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1366,6 +1366,21 @@ def get_cron_file(self): mw.writeFile(filename, "") return filename + # 数转周 + def toWeek(self, num): + if num > 6: return '' + wheres = { + 0: mw.getMsg('CRONTAB_SUNDAY'), + 1: mw.getMsg('CRONTAB_MONDAY'), + 2: mw.getMsg('CRONTAB_TUESDAY'), + 3: mw.getMsg('CRONTAB_WEDNESDAY'), + 4: mw.getMsg('CRONTAB_THURSDAY'), + 5: mw.getMsg('CRONTAB_FRIDAY'), + 6: mw.getMsg('CRONTAB_SATURDAY') + } + + return wheres[num] + # 解析计划任务执行周期 def decode_cron_cycle(self, tmp): if not tmp[4]: tmp[4] = '*' From 8a4a63c85b00b4fe2889e3a5fd58a8156b1c4215 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 00:39:40 +0800 Subject: [PATCH 043/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 0b5cbe35c9..7cafdf7da9 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -540,6 +540,8 @@ function get_cron_list() { var loadT = layer.msg('获取计划任务列表..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('get_cron_list', {search:search_val}, function(rdata){ layer.close(loadT); + + var rdata = rdata.data; var tbody_tr = ''; for (var i = 0; i < rdata.length; i++) { tbody_tr += '\ From b33be2ab84e75b3c86b121db0f3e4047bfbe8924 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 00:50:42 +0800 Subject: [PATCH 044/121] update --- plugins/task_manager/js/task_manager.js | 2 +- plugins/task_manager/task_manager_index.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 7cafdf7da9..112eaebed6 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -540,7 +540,7 @@ function get_cron_list() { var loadT = layer.msg('获取计划任务列表..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('get_cron_list', {search:search_val}, function(rdata){ layer.close(loadT); - + var rdata = rdata.data; var tbody_tr = ''; for (var i = 0; i < rdata.length; i++) { diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 9e0080a9a4..9997300ce5 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1370,15 +1370,14 @@ def get_cron_file(self): def toWeek(self, num): if num > 6: return '' wheres = { - 0: mw.getMsg('CRONTAB_SUNDAY'), - 1: mw.getMsg('CRONTAB_MONDAY'), - 2: mw.getMsg('CRONTAB_TUESDAY'), - 3: mw.getMsg('CRONTAB_WEDNESDAY'), - 4: mw.getMsg('CRONTAB_THURSDAY'), - 5: mw.getMsg('CRONTAB_FRIDAY'), - 6: mw.getMsg('CRONTAB_SATURDAY') + 0: '周日', + 1: '周一', + 2: '周二', + 3: '周三', + 4: '周四', + 5: '周五', + 6: '周六', } - return wheres[num] # 解析计划任务执行周期 From 3bb0552ba62f4c2b6c06e806bd7ac38811c052f5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 00:52:03 +0800 Subject: [PATCH 045/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 9997300ce5..61f96402e1 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1370,13 +1370,13 @@ def get_cron_file(self): def toWeek(self, num): if num > 6: return '' wheres = { - 0: '周日', - 1: '周一', - 2: '周二', - 3: '周三', - 4: '周四', - 5: '周五', - 6: '周六', + 0: '日', + 1: '一', + 2: '二', + 3: '三', + 4: '四', + 5: '五', + 6: '六', } return wheres[num] From 1cf49c24ef66d7839467483a45ef97e0c01c8027 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 01:03:38 +0800 Subject: [PATCH 046/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 61f96402e1..5937c0d419 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1426,8 +1426,10 @@ def decode_cron_connand(self, tmp): # 外部接口,获取计划任务列表 def get_cron_list(self, get = {}): filename = self.get_cron_file() - tmpList = mw.readFile(filename).split("\n") cronList = [] + if not os.path.exists(filename): + return cronList + tmpList = mw.readFile(filename).split("\n") for c in tmpList: c = c.strip() if c.startswith('#'): continue @@ -1457,6 +1459,31 @@ def search_cron(self, data, search): except: return data + # 重启cron服务 + def crondReload(self): + if os.path.exists('/etc/init.d/crond'): + public.ExecShell('/etc/init.d/crond reload') + elif os.path.exists('/etc/init.d/cron'): + public.ExecShell('service cron restart') + else: + public.ExecShell("systemctl reload crond") + + # 外部接口,删除计划任务 + def remove_cron(self, get): + index = int(get.index) + cronList = self.get_cron_list({}) + if index > len(cronList) + 1: return mw.returnData(False, '指定任务不存在!') + toCron = [] + for i in range(len(cronList)): + if i == index: continue + toCron.append(cronList[i]['command']) + cronStr = "\n".join(toCron) + "\n\n" + filename = self.get_cron_file() + mw.writeFile(filename, cronStr) + mw.execShell("chmod 600 " + filename) + self.crondReload() + return mw.returnData(True, '删除成功!') + # 外部接口 强制结束会话 def pkill_session(self, get= {}): if not 'pts' in get: @@ -1531,6 +1558,9 @@ def get_run_list(args = {}): def get_cron_list(args = {}): return mc_instance.get_cron_list(args) +def remove_cron(args = {}): + return mc_instance.remove_cron(args) + def pkill_session(args = {}): return mc_instance.pkill_session(args) From 30b02aea330830753c1c2b621edcbe7e7307788f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 01:05:37 +0800 Subject: [PATCH 047/121] update --- plugins/task_manager/js/task_manager.js | 18 +++++++++++------- plugins/task_manager/task_manager_index.py | 5 ++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 112eaebed6..1a13427ac1 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -540,7 +540,7 @@ function get_cron_list() { var loadT = layer.msg('获取计划任务列表..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('get_cron_list', {search:search_val}, function(rdata){ layer.close(loadT); - + var rdata = rdata.data; var tbody_tr = ''; for (var i = 0; i < rdata.length; i++) { @@ -937,12 +937,16 @@ function online_edit_file(fileName) { //删除计划任务 function remove_cron(index) { safeMessage('删除计划任务[' + index + ']', '删除后将无法恢复,继续吗?', function () { - var loadT = layer.msg('正在删除计划任务..', {icon: 16, time: 0, shade: [0.3, '#000']}); - $.post('/plugin?action=a&name=task_manager&s=remove_cron', {index: index}, function (rdata) { - layer.close(loadT); - layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); - if (rdata.status) get_cron_list(); - }); + var loadT = layer.msg('正在删除计划任务..', {icon: 16, time: 0, shade: [0.3, '#000']}); + tmPostCallback('remove_cron', {index:index}, function(rdata){ + layer.close(loadT); + var rdata = data.data; + showMsg(rdata.msg, function(){ + if (rdata.status) { + get_cron_list(); + } + },{icon: rdata.status ? 1 : 2}); + }); }); } diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 5937c0d419..9e308c8064 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1470,7 +1470,10 @@ def crondReload(self): # 外部接口,删除计划任务 def remove_cron(self, get): - index = int(get.index) + if not 'index' in get: + return mw.returnData(False, '参数不存在[index]!') + + index = int(get['index']) cronList = self.get_cron_list({}) if index > len(cronList) + 1: return mw.returnData(False, '指定任务不存在!') toCron = [] From e80162cfa97b6fab929d6bd189de2f2b98587790 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 01:07:14 +0800 Subject: [PATCH 048/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 1a13427ac1..9ece99faf0 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -940,7 +940,7 @@ function remove_cron(index) { var loadT = layer.msg('正在删除计划任务..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('remove_cron', {index:index}, function(rdata){ layer.close(loadT); - var rdata = data.data; + var rdata = rdata.data; showMsg(rdata.msg, function(){ if (rdata.status) { get_cron_list(); From 9b008fcff91837721f4eec6bffbb1558d4ef0bcc Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 01:09:51 +0800 Subject: [PATCH 049/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 9e308c8064..d7bb9ae146 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -99,7 +99,7 @@ def get_process_net_list(self): if not os.path.exists(w_file): return self.last_net_process = cache.get('net_process') self.last_net_process_time = cache.get('last_net_process') - net_process_body = public.readFile(w_file) + net_process_body = mw.readFile(w_file) if not net_process_body: return net_process = net_process_body.split('\n') for np in net_process: @@ -515,7 +515,7 @@ def check_process_net_total(self): mw_dir = mw.getServerDir() + '/mdserver-web' _pid_file = mw_dir+'/logs/process_network_total.pid' if os.path.exists(_pid_file): - pid = public.readFile(_pid_file) + pid = mw.readFile(_pid_file) if os.path.exists('/proc/' + pid): return True cmd_file = getServerDir()+'/process_network_total.py' @@ -624,7 +624,6 @@ def kill_process_lower(self, pid): # 结束进程树 kill_process——>引用kill_process_all def kill_process_all(self, pid): - # public.print_log(pid) if pid < 30: return mw.returnData(True, '已结束此进程树!') if self.is_panel_process(pid): return mw.returnData(False, '不能结束面板服务进程') try: @@ -644,7 +643,7 @@ def kill_process_all(self, pid): if ppid: return self.kill_process_all(ppid) except: pass - return public.returnMsg(True, '已结束此进程树!') + return mw.returnData(True, '已结束此进程树!') def get_process_list(self, args = {}): # https://hellowac.github.io/psutil-doc-zh/processes/process_class/oneshot.html @@ -1462,11 +1461,11 @@ def search_cron(self, data, search): # 重启cron服务 def crondReload(self): if os.path.exists('/etc/init.d/crond'): - public.ExecShell('/etc/init.d/crond reload') + mw.execShell('/etc/init.d/crond reload') elif os.path.exists('/etc/init.d/cron'): - public.ExecShell('service cron restart') + mw.execShell('service cron restart') else: - public.ExecShell("systemctl reload crond") + mw.execShell("systemctl reload crond") # 外部接口,删除计划任务 def remove_cron(self, get): From a0a61d3bbc0f46c9d7a5a5d9650a31c15a35d7bc Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 01:15:34 +0800 Subject: [PATCH 050/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 9ece99faf0..3b0157ec43 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -852,10 +852,15 @@ function get_user_list() { function userdel(user) { safeMessage('删除用户【' + user + '】', '删除后可能导致您的环境无法正常运行,继续吗?', function () { var loadT = layer.msg('正在删除用户[' + user + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); - $.post('/plugin?action=a&name=task_manager&s=remove_user', {user: user}, function (rdata) { + tmPostCallback('remove_user', {user:user}, function(rdata){ layer.close(loadT); - layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); - if (rdata.status) get_user_list(); + + var rdata = data.data; + showMsg(rdata.msg, function(){ + if (rdata.status) { + get_user_list(); + } + },{icon: rdata.status ? 1 : 2}); }); }); } From 43aba019c050850f7a38e60ed408dbb51275997a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 02:09:19 +0800 Subject: [PATCH 051/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index d7bb9ae146..ae1d9c0469 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -207,8 +207,6 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): 's3fs': '对象存储挂载服务', 'bosfs': '百度云对象存储挂载服务', 'jsvc': 'tomcat服务', - 'oneavd': '微步木马检测服务', - 'btsync': '宝塔文件同步服务', 'mysqld': 'MySQL服务', 'php-fpm': 'PHP子进程', 'php-cgi': 'PHP-CGI进程', @@ -323,11 +321,12 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): if p_exe: if name == 'php-fpm': try: - php_version = '.'.join(p_exe.split('/')[-3]) + php_version = p_exe.split('/')[-3][3:] return 'PHP' + php_version + '进程' except: pass - elif name == 'python': + elif name == 'python' or name == 'python3': + # print(name, pid, p_exe, p) p_exe_arr = p_exe.split('/') if p_exe_arr[-1] in ['BT-Task', 'task.py']: return '面板-后台任务进程' @@ -338,6 +337,8 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): if p: cmdline = ' '.join(p.cmdline()).strip() cmdline_arr = cmdline.split('/') + # print(cmdline) + # print(cmdline_arr) if cmdline.find('process_network_total') != -1: return '进程网络监控' if cmdline_arr[-1] in ['BT-Task', 'task.py']: @@ -356,20 +357,26 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return 'SSL证书签发' elif cmdline.find('psync') != -1: return '面板一键迁移' - elif cmdline.find('/panel/plugin') != -1: + elif cmdline.find('mdserver-web/plugins') != -1: return '面板插件进程' elif cmdline.find('/www/server/cron/') != -1: return '面板计划任务' + # elif cmdline.find('') != -1: + # return '面板计划任务' elif name == 'nginx': + default_name = 'Nginx' + if p_exe.find('openresty/nginx') != -1: + default_name = 'OpenResty' + if p.username() == 'www': - return 'Nginx子进程' + return default_name+'子进程' else: - return 'Nginx主进程' + return default_name+'主进程' elif p_exe == '/usr/bin/bash': cmdline = ' '.join(p.cmdline()).strip() if cmdline.find('/www/server/cron/') != -1: return '面板计划任务' - elif cmdline.find('/www/server/mdserver-web/plugins') != -1: + elif cmdline.find('mdserver-web/plugins') != -1: return '面板插件进程' if name in processPs: return processPs[name] @@ -685,7 +692,11 @@ def get_process_list_mac(self, args = {}): for pid in ppids: tmp = {} try: - p = psutil.Process(pid) + try: + p = psutil.Process(pid) + except Exception as e: + continue + with p.oneshot(): p_state = p.status() try: From 6a584ccf7bcd6c15d577710b26d5b61d5697735f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 02:13:02 +0800 Subject: [PATCH 052/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index ae1d9c0469..2d608f8924 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -491,7 +491,7 @@ def search_pro(self, data, search): if search in i['name'] or search in i['exe'] or search in i['ps'] or search in i[ 'user'] or search in str(i['pid']) or search in i['status']: ldata.append(i) - elif hasattr(i, 'children'): + elif 'children' in i: for k in i['children']: if search in k['name'] or search in k['exe'] or search in k['ps'] or search in k[ 'user'] or search in str(k['pid']): @@ -767,9 +767,9 @@ def get_process_list_mac(self, args = {}): info['cpu'] = round(info['cpu'], 3) info['mem'] = self.get_mem_info() data['info'] = info - if hasattr(args, 'search'): - if args.search != '': - data['process_list'] = self.search_pro(data['process_list'], args.search) + if 'search' in args: + if args['search'] != '': + data['process_list'] = self.search_pro(data['process_list'], args['search']) self.get_meter_head() data['meter_head'] = self.meter_head From 1ffe197d6952f0a04fa5d7411cf9b785fee86146 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 02:16:53 +0800 Subject: [PATCH 053/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 2d608f8924..7271d08dfd 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -321,7 +321,10 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): if p_exe: if name == 'php-fpm': try: - php_version = p_exe.split('/')[-3][3:] + if self.is_mac: + php_version = p_exe.split('/')[-3][3:] + else: + php_version = p_exe.split('/')[-3] return 'PHP' + php_version + '进程' except: pass From 369dc69364f7b09b73b45e3f51b5ae03a4541f2c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 02:23:47 +0800 Subject: [PATCH 054/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 3b0157ec43..ce169f80e6 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -735,7 +735,7 @@ function get_run_list() { \ ' + tbody_tr + ''; $("#TaskManagement").html(tbody); - var topMsg = '
当前运行级别: level-' + rdata.run_level + '?
'; + var topMsg = '
当前运行级别: level-' + rdata.run_level + '
'; $("#load_average").html(topMsg).show(); $(".table-cont").css("height", "500px"); show_task(); From 67505f7aefec118e5e262721152b080f37b7b40a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 02:40:57 +0800 Subject: [PATCH 055/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 7271d08dfd..f53f727c61 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -184,6 +184,7 @@ def get_mem_info(self, get=None): # 进程备注,name,pid,启动命令 def get_process_ps(self, name, pid, p_exe=None, p=None): + # print(name, pid, p_exe, p) processPs = { 'irqbalance': '系统进程-优化系统性能服务', 'containerd': 'docker管理服务', @@ -328,8 +329,8 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return 'PHP' + php_version + '进程' except: pass - elif name == 'python' or name == 'python3': - # print(name, pid, p_exe, p) + elif name.lower() == 'python' or name.lower() == 'python3': + print(name.lower(), pid, p_exe) p_exe_arr = p_exe.split('/') if p_exe_arr[-1] in ['BT-Task', 'task.py']: return '面板-后台任务进程' @@ -340,8 +341,6 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): if p: cmdline = ' '.join(p.cmdline()).strip() cmdline_arr = cmdline.split('/') - # print(cmdline) - # print(cmdline_arr) if cmdline.find('process_network_total') != -1: return '进程网络监控' if cmdline_arr[-1] in ['BT-Task', 'task.py']: @@ -364,8 +363,8 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return '面板插件进程' elif cmdline.find('/www/server/cron/') != -1: return '面板计划任务' - # elif cmdline.find('') != -1: - # return '面板计划任务' + elif cmdline.find('mdserver-web') != -1 and cmdline.find('gunicorn -c setting.py app:app') != -1: + return 'MW面板' elif name == 'nginx': default_name = 'Nginx' if p_exe.find('openresty/nginx') != -1: @@ -383,6 +382,8 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return '面板插件进程' if name in processPs: return processPs[name] + + if name == 'python': if self.is_panel_process(pid): return 'MW面板' From a44ac7606a0a1f0485bf4fa4289b1fb703313dff Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 02:43:31 +0800 Subject: [PATCH 056/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index f53f727c61..5e8a7be7df 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -823,7 +823,10 @@ def get_process_list_linux(self, get = {}): for pid in self.pids: tmp = {} try: - p = psutil.Process(pid) + try: + p = psutil.Process(pid) + except Exception as e: + continue with p.oneshot(): p_mem = p.memory_full_info() if p_mem.rss == 0: continue From 204be55c81dc99cb1999048bde56606b28d631f1 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 02:48:19 +0800 Subject: [PATCH 057/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 5e8a7be7df..e6be8145b6 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -828,7 +828,12 @@ def get_process_list_linux(self, get = {}): except Exception as e: continue with p.oneshot(): - p_mem = p.memory_full_info() + + try: + p_mem = p.memory_full_info() + except Exception as e: + continue + if p_mem.rss == 0: continue pio = p.io_counters() p_cpus = p.cpu_times() From 6eadb548a1c3549b56b4f21579ae6dca23b3b5d5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 02:54:10 +0800 Subject: [PATCH 058/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index e6be8145b6..bae2f2685d 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -365,6 +365,11 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return '面板计划任务' elif cmdline.find('mdserver-web') != -1 and cmdline.find('gunicorn -c setting.py app:app') != -1: return 'MW面板' + elif name.lower() == 'gunicorn': + print(name.lower(), pid, p_exe) + if p: + cmdline = ' '.join(p.cmdline()).strip() + print(cmdline) elif name == 'nginx': default_name = 'Nginx' if p_exe.find('openresty/nginx') != -1: From 3c90a0fbe6db2ef7e1764025261bb0488d43ed7d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 03:03:43 +0800 Subject: [PATCH 059/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index bae2f2685d..fc6f8a6dea 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -330,7 +330,7 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): except: pass elif name.lower() == 'python' or name.lower() == 'python3': - print(name.lower(), pid, p_exe) + # print(name.lower(), pid, p_exe) p_exe_arr = p_exe.split('/') if p_exe_arr[-1] in ['BT-Task', 'task.py']: return '面板-后台任务进程' @@ -366,10 +366,11 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): elif cmdline.find('mdserver-web') != -1 and cmdline.find('gunicorn -c setting.py app:app') != -1: return 'MW面板' elif name.lower() == 'gunicorn': - print(name.lower(), pid, p_exe) + # print(name.lower(), pid, p_exe) if p: cmdline = ' '.join(p.cmdline()).strip() - print(cmdline) + if cmdline.find('mdserver-web') != -1 and cmdline.find('gunicorn -c setting.py app:app') != -1: + return 'MW面板' elif name == 'nginx': default_name = 'Nginx' if p_exe.find('openresty/nginx') != -1: @@ -379,6 +380,12 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return default_name+'子进程' else: return default_name+'主进程' + elif name == 'openresty': + if p.username() == 'www': + return 'OpenResty子进程' + return 'OpenResty主进程' + elif name == 'mw': + return 'MW面板-命令' elif p_exe == '/usr/bin/bash': cmdline = ' '.join(p.cmdline()).strip() if cmdline.find('/www/server/cron/') != -1: From 48388edcfcd02f74f8171a28693bd5433a836b82 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 03:07:24 +0800 Subject: [PATCH 060/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index fc6f8a6dea..b9af59863b 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -528,10 +528,10 @@ def get_cpu_time(self): # 获取python的路径 def get_python_bin(self): mw_dir = mw.getServerDir() + '/mdserver-web' - bin_file = mw_dir + '/bin/python' + bin_file = mw_dir + '/bin/python3' if os.path.exists(bin_file): return bin_file - return '/usr/bin/python' + return '/usr/bin/python3' # 检查process_network_total.py是否运行 def check_process_net_total(self): From 60717c33639ab7a9f785e7b5bd9ef181d0492b14 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 03:09:10 +0800 Subject: [PATCH 061/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index ce169f80e6..09c3ef8d0e 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -581,7 +581,7 @@ function get_network_list(rflush) { " + lan.index.net_protocol + "\ " + lan.index.net_address_dst + "\ " + lan.index.net_address_src + "\ - " + lan.index.net_address_status + "?\ + " + lan.index.net_address_status + "\ " + lan.index.net_process + "\ " + lan.index.net_process_pid + "\ \ @@ -611,7 +611,7 @@ function get_network_list(rflush) { " + lan.index.net_protocol + "\ " + lan.index.net_address_dst + "\ " + lan.index.net_address_src + "\ - " + lan.index.net_address_status + "?\ + " + lan.index.net_address_status + "\ " + lan.index.net_process + "\ " + lan.index.net_process_pid + "\ \ @@ -801,7 +801,7 @@ function get_service_list() { \ ' + tbody_tr + ''; $("#TaskManagement").html(tbody); - var topMsg = '
当前运行级别: level-' + rdata.runlevel + '?
'; + var topMsg = '
当前运行级别: level-' + rdata.runlevel + '
'; $("#load_average").html(topMsg).show(); $(".table-cont").css("height", "500px"); show_task(); From 4c50e44e2c9dbd930ab90793339518c9898ebd77 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 03:15:32 +0800 Subject: [PATCH 062/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 09c3ef8d0e..067bd1caa1 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -878,6 +878,7 @@ function kill_process(pid, fpid) { var loadT = layer.msg('正在结束进程[' + pid + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('kill_process', {pid:pid}, function(data){ layer.close(loadT); + var rdata = data.data; layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); if (rdata.status) { get_process_list(); From d8efd3f9878049d243d5e42113efd071c7a6f0ba Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 03:19:48 +0800 Subject: [PATCH 063/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 067bd1caa1..3116e844e5 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -854,8 +854,7 @@ function userdel(user) { var loadT = layer.msg('正在删除用户[' + user + ']..', {icon: 16, time: 0, shade: [0.3, '#000']}); tmPostCallback('remove_user', {user:user}, function(rdata){ layer.close(loadT); - - var rdata = data.data; + var rdata = rdata.data; showMsg(rdata.msg, function(){ if (rdata.status) { get_user_list(); From 6fe205dbfb7071352ec5649aed15733d230ecd88 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 10:51:36 +0800 Subject: [PATCH 064/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index b9af59863b..39e894a4ae 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -369,8 +369,11 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): # print(name.lower(), pid, p_exe) if p: cmdline = ' '.join(p.cmdline()).strip() + if cmdline.find('task.py') != -1: + return 'MW面板-后台任务' if cmdline.find('mdserver-web') != -1 and cmdline.find('gunicorn -c setting.py app:app') != -1: return 'MW面板' + elif name == 'nginx': default_name = 'Nginx' if p_exe.find('openresty/nginx') != -1: From c3b60695c7e7e0b6e2ed6b84cbfaf4389315822b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 10:54:21 +0800 Subject: [PATCH 065/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 39e894a4ae..d290ad921f 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -369,8 +369,6 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): # print(name.lower(), pid, p_exe) if p: cmdline = ' '.join(p.cmdline()).strip() - if cmdline.find('task.py') != -1: - return 'MW面板-后台任务' if cmdline.find('mdserver-web') != -1 and cmdline.find('gunicorn -c setting.py app:app') != -1: return 'MW面板' @@ -391,6 +389,8 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return 'MW面板-命令' elif p_exe == '/usr/bin/bash': cmdline = ' '.join(p.cmdline()).strip() + if cmdline.find('task.py') != -1: + return 'MW面板-后台任务' if cmdline.find('/www/server/cron/') != -1: return '面板计划任务' elif cmdline.find('mdserver-web/plugins') != -1: From 0f488b26d193ba6d3a2461cfd135890920786c47 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:03:41 +0800 Subject: [PATCH 066/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index d290ad921f..1e38dfdc98 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -363,6 +363,8 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return '面板插件进程' elif cmdline.find('/www/server/cron/') != -1: return '面板计划任务' + elif cmdline.find('mdserver-web') != -1 and cmdline.find('task.py') != -1: + return 'MW面板-后台任务' elif cmdline.find('mdserver-web') != -1 and cmdline.find('gunicorn -c setting.py app:app') != -1: return 'MW面板' elif name.lower() == 'gunicorn': From dccea0e2836c5f5fc8bb86ab8b1874c2e64999a9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:04:05 +0800 Subject: [PATCH 067/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 1e38dfdc98..1ab285b7dd 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -320,6 +320,10 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): 'sleep': '延迟进程' } if p_exe: + # print(name.lower(), pid, p_exe) + # if p: + # cmdline = ' '.join(p.cmdline()).strip() + # print(cmdline) if name == 'php-fpm': try: if self.is_mac: From 52724dd5b22efb2604afd0b700876b6dfae54e3a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:04:42 +0800 Subject: [PATCH 068/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 1ab285b7dd..6eae85ec29 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -334,7 +334,6 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): except: pass elif name.lower() == 'python' or name.lower() == 'python3': - # print(name.lower(), pid, p_exe) p_exe_arr = p_exe.split('/') if p_exe_arr[-1] in ['BT-Task', 'task.py']: return '面板-后台任务进程' @@ -367,7 +366,7 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return '面板插件进程' elif cmdline.find('/www/server/cron/') != -1: return '面板计划任务' - elif cmdline.find('mdserver-web') != -1 and cmdline.find('task.py') != -1: + elif cmdline.find('task.py') != -1: return 'MW面板-后台任务' elif cmdline.find('mdserver-web') != -1 and cmdline.find('gunicorn -c setting.py app:app') != -1: return 'MW面板' From 0cd7a7dc9e55e848b4727e5abd0983a5fe9b54a3 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:05:10 +0800 Subject: [PATCH 069/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 6eae85ec29..dc6cc72c27 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -335,8 +335,8 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): pass elif name.lower() == 'python' or name.lower() == 'python3': p_exe_arr = p_exe.split('/') - if p_exe_arr[-1] in ['BT-Task', 'task.py']: - return '面板-后台任务进程' + if p_exe_arr[-1] in ['task.py']: + return 'MW面板-后台任务进程' elif p_exe_arr[-1] in ['BT-Panel', 'runserver.py']: return '面板-主进程' elif p_exe.find('process_network_total') != -1: From b36fc5883947c43604b89f8e17eaad31d193a32a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:09:53 +0800 Subject: [PATCH 070/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index dc6cc72c27..6a4ff3b5ea 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -341,6 +341,7 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return '面板-主进程' elif p_exe.find('process_network_total') != -1: return '面板-进程网络监控' + if self.is_panel_process(pid): return 'MW面板' if p: cmdline = ' '.join(p.cmdline()).strip() cmdline_arr = cmdline.split('/') @@ -371,7 +372,6 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): elif cmdline.find('mdserver-web') != -1 and cmdline.find('gunicorn -c setting.py app:app') != -1: return 'MW面板' elif name.lower() == 'gunicorn': - # print(name.lower(), pid, p_exe) if p: cmdline = ' '.join(p.cmdline()).strip() if cmdline.find('mdserver-web') != -1 and cmdline.find('gunicorn -c setting.py app:app') != -1: @@ -400,12 +400,10 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return '面板计划任务' elif cmdline.find('mdserver-web/plugins') != -1: return '面板插件进程' + if name in processPs: return processPs[name] - - if name == 'python': - if self.is_panel_process(pid): return 'MW面板' if p_exe: exe_keys = { From 1c5a3f3c13357bdc519463fd3a7d679e51a4b9d4 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:17:30 +0800 Subject: [PATCH 071/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 6a4ff3b5ea..9198a40123 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -341,7 +341,7 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return '面板-主进程' elif p_exe.find('process_network_total') != -1: return '面板-进程网络监控' - if self.is_panel_process(pid): return 'MW面板' + if p: cmdline = ' '.join(p.cmdline()).strip() cmdline_arr = cmdline.split('/') @@ -404,7 +404,8 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): if name in processPs: return processPs[name] - + # if self.is_panel_process(pid): return 'MW面板' + if p_exe: exe_keys = { '/www/server/mdserver-web/plugins/': '面板插件', From 159660815b66368f4500741f8ff2581b53c8d25d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:20:28 +0800 Subject: [PATCH 072/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 99 ++++++++++++------------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 3116e844e5..db90aa0755 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -178,59 +178,59 @@ var isProcessing = false; // 设置标志 }, 3000); } - function get_list_bytab(isblur) { +function get_list_bytab(isblur) { if (isblur && $('.search-bar .search_input').val() === search_val) { - return; + return; } search_val = $('.search-bar .search_input').val(); get_process_list(); switch (tab_name) { - case 'p_list': - $('.table_config').show(); - $('.search-bar span').addClass('r56'); - select_pid = '' - wrapPid = {} - canScroll2TaskMangerPossess = true - get_process_list(); - break; - case 'p_resource': - $('.table_config').hide(); - $('.search-bar span').removeClass('r56'); - get_resource_list(); - break; - case 'p_run': - $('.table_config').hide(); - $('.search-bar span').removeClass('r56'); - get_run_list(); - break; - case 'p_service': - $('.table_config').hide(); - $('.search-bar span').removeClass('r56'); - get_service_list(); - break; - case 'p_network': - $('.table_config').hide(); - $('.search-bar span').removeClass('r56'); - get_network_list(); - break; - case 'p_user': - $('.table_config').hide(); - $('.search-bar span').removeClass('r56'); - get_user_list(); - break; - case 'p_cron': - $('.table_config').hide(); - $('.search-bar span').removeClass('r56'); - get_cron_list(); - break; - case 'p_session': - $('.table_config').hide(); - $('.search-bar span').removeClass('r56'); - get_who_list(); - break; + case 'p_list': + $('.table_config').show(); + $('.search-bar span').addClass('r56'); + select_pid = ''; + wrapPid = {}; + canScroll2TaskMangerPossess = true; + get_process_list(); + break; + case 'p_resource': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_resource_list(); + break; + case 'p_run': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_run_list(); + break; + case 'p_service': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_service_list(); + break; + case 'p_network': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_network_list(); + break; + case 'p_user': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_user_list(); + break; + case 'p_cron': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_cron_list(); + break; + case 'p_session': + $('.table_config').hide(); + $('.search-bar span').removeClass('r56'); + get_who_list(); + break; } - } +} function get_process_list(sortx, reverse, rx) { if ($('.t-mana .man-menu-sub .on').attr('class') != 'p_list on') return; @@ -246,17 +246,14 @@ function get_process_list(sortx, reverse, rx) { } } - res_list = { - True: 'False', - False: 'True' - }; + res_list = {True: 'False',False: 'True'}; setCookie(cookie_key, sortx + '|' + reverse); if (!rx) { var loadT = layer.msg('正在获取进程列表..', {icon: 16, time: 0, shade: [0.3, '#000']}) } tmPostCallback('get_process_list', {sortx: sortx,reverse: reverse,search:search_val}, function(rdata){ - console.log(rdata); + // console.log(rdata); if (!rx) layer.close(loadT); if ($('.t-mana .man-menu-sub .on').attr('class') != 'p_list on') return; if (rdata.status === false) { From a0696fc9744918a92f33872f732c8a6037a96d52 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:25:32 +0800 Subject: [PATCH 073/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 9198a40123..0a20b929b9 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -405,7 +405,7 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): if name in processPs: return processPs[name] # if self.is_panel_process(pid): return 'MW面板' - + if p_exe: exe_keys = { '/www/server/mdserver-web/plugins/': '面板插件', @@ -1001,7 +1001,9 @@ def remove_user(self, get): if get['user'] in users: return mw.returnData(False, '不能删除系统和环境关键用户!') - r = mw.execShell("userdel " + get['user']) + user = get['user'] + + r = mw.execShell("userdel " + user) if r[1].find('process') != -1: try: pid = r[1].split()[-1] @@ -1009,7 +1011,7 @@ def remove_user(self, get): pname = p.name() p.kill() mw.execShell("pkill -9 " + pname) - r = mw.execShell("userdel " + get.user) + r = mw.execShell("userdel " + .user) except: pass if r[1].find('userdel:') != -1: return mw.returnData(False, r[1]); From 60a0bd7a658488b00cab31137e08bcc364cb705b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:25:54 +0800 Subject: [PATCH 074/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 0a20b929b9..73db82e37b 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -993,8 +993,10 @@ def get_group_list(self, get): def remove_user(self, get): if self.is_mac: return mw.returnData(False, '无法操作!') - users = ['www', 'root', 'mysql', 'shutdown', 'postfix', 'smmsp', 'sshd', 'systemd-network', 'systemd-bus-proxy', - 'avahi-autoipd', 'mail', 'sync', 'lp', 'adm', 'bin', 'mailnull', 'ntp', 'daemon', 'sys']; + users = ['www', 'root', 'mysql', 'shutdown', 'postfix', + 'smmsp', 'sshd', 'systemd-network', 'systemd-bus-proxy', + 'avahi-autoipd', 'mail', 'sync', 'lp', + 'adm', 'bin', 'mailnull', 'ntp', 'daemon', 'sys']; if 'user' in get: return mw.returnData(False, '缺少参数!') From cd1a3de04a086f22b0b5000169322b276f116eb5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:27:26 +0800 Subject: [PATCH 075/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 73db82e37b..fbf4e34fea 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1013,7 +1013,7 @@ def remove_user(self, get): pname = p.name() p.kill() mw.execShell("pkill -9 " + pname) - r = mw.execShell("userdel " + .user) + r = mw.execShell("userdel " + user) except: pass if r[1].find('userdel:') != -1: return mw.returnData(False, r[1]); From f2a167424773d278952cc14c033d190a47d2d943 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:29:04 +0800 Subject: [PATCH 076/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index fbf4e34fea..7cfaaa2bee 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -998,7 +998,7 @@ def remove_user(self, get): 'avahi-autoipd', 'mail', 'sync', 'lp', 'adm', 'bin', 'mailnull', 'ntp', 'daemon', 'sys']; - if 'user' in get: + if not 'user' in get: return mw.returnData(False, '缺少参数!') if get['user'] in users: return mw.returnData(False, '不能删除系统和环境关键用户!') From 0082bcd159e3e9d53504d23c615ed2bbbc03d037 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:39:21 +0800 Subject: [PATCH 077/121] Update site.css --- route/static/css/site.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/route/static/css/site.css b/route/static/css/site.css index 7b0960491e..358ac8c93a 100755 --- a/route/static/css/site.css +++ b/route/static/css/site.css @@ -276,6 +276,10 @@ html { margin-left: 5px; } +.ml10 { + margin-left: 10px; +} + .mr5 { margin-right: 5px; } @@ -283,6 +287,7 @@ html { .mr20 { margin-right: 20px; } + .ml0{ margin-left: 0; } From 207cef200f61d5a13a2e65acc34e67b4bc312ab9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 11:58:07 +0800 Subject: [PATCH 078/121] update --- plugins/task_manager/js/task_manager.js | 83 +++++++++++----------- plugins/task_manager/task_manager_index.py | 23 ++++++ 2 files changed, 64 insertions(+), 42 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index db90aa0755..a2272c628d 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -116,67 +116,66 @@ $('.layui-layer').not($('.setting_ul_li')).click(function () { }); var isProcessing = false; // 设置标志 - $('.setting_ul_li').off('click').click(function (e) { - var that = $(this) +$('.setting_ul_li').off('click').click(function (e) { + var that = $(this); e.stopPropagation() // 检查标志 if (isProcessing) { - return; + return; } if (!$(this).hasClass('disabled')) { - isProcessing = true; // 点击事件被触发,设置标志 - var name = $(this).attr("name") - clearInterval(process_list_s); - bt_tools.send({ - url: 'plugin?action=a&name=task_manager&s=set_meter_head', - data: {meter_head_name: name} - }, function (data) { - isProcessing = false; // 操作完成,清除标志 - if (!data) { - layer.msg('设置失败'); - } - that.toggleClass('active') - get_process_list(null, null, false); + isProcessing = true; // 点击事件被触发,设置标志 + var name = $(this).attr("name"); clearInterval(process_list_s); - process_list_s = setInterval(function () { - if ($(".t-mana").length == 0) { + + tmPostCallback('set_meter_head',{meter_head_name: name}, function(data){ + console.log(data); + isProcessing = false; // 操作完成,清除标志 + if (!data) { + layer.msg('设置失败'); + } + that.toggleClass('active'); + get_process_list(null, null, false); clearInterval(process_list_s); - process_list_s = 0; - console.log('进程列表轮询任务已停止'); - } - get_process_list(null, null, true); - }, 3000); - }) + process_list_s = setInterval(function () { + if ($(".t-mana").length == 0) { + clearInterval(process_list_s); + process_list_s = 0; + console.log('进程列表轮询任务已停止'); + } + get_process_list(null, null, true); + }, 3000); + }); } - }) +}); - $('.setting_btn').on('click',function (e) { - e.stopPropagation() +$('.setting_btn').on('click',function (e) { + e.stopPropagation(); var offset = $('.man-menu-sub').offset(); var x = e.pageX - offset.left; var y = e.pageY - offset.top; var width = $('.man-menu-sub').outerWidth(); if ($('.man-menu-sub').width() - x < width) { - $(".plug_menu").css({ - position: 'absolute', - right: "14.5px", - top:"40px", - }).toggle(); - $('.setting_ul').addClass('undisplay') + $(".plug_menu").css({ + position: 'absolute', + right: "14.5px", + top:"40px", + }).toggle(); + $('.setting_ul').addClass('undisplay') } $(".setting_ul").toggle(); - }) +}); - if (process_list_s === 0) { +if (process_list_s === 0) { process_list_s = setInterval(function () { - if ($(".t-mana").length == 0) { - clearInterval(process_list_s); - process_list_s = 0; - console.log('进程列表轮询任务已停止') - } - get_process_list(null, null, true); + if ($(".t-mana").length == 0) { + clearInterval(process_list_s); + process_list_s = 0; + console.log('进程列表轮询任务已停止') + } + get_process_list(null, null, true); }, 3000); - } +} function get_list_bytab(isblur) { if (isblur && $('.search-bar .search_input').val() === search_val) { diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 7cfaaa2bee..9e474a44c4 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -483,6 +483,24 @@ def get_load_average(self): data['15'] = round(float(c[2]), 3) # float(c[2]) return data + def set_meter_head(self, get): + if not 'meter_head_name' in get: + return False + + meter_head_name = get['meter_head_name'] + meter_head_file = getServerDir()+'/meter_head.json' + try: + self.get_meter_head() + if meter_head_name not in self.meter_head.keys(): + return False + if meter_head_name in ['ps', 'memory_used', 'cpu_percent', 'name']: + return False + self.meter_head[meter_head_name] = not self.meter_head[meter_head_name] + mw.writeFile(meter_head_file, json.dumps(self.meter_head)) + return True + except: + return False + def get_meter_head(self, get=None): meter_head_file = getServerDir()+'/meter_head.json' if os.path.exists(meter_head_file): @@ -675,6 +693,8 @@ def kill_process_all(self, pid): pass return mw.returnData(True, '已结束此进程树!') + + def get_process_list(self, args = {}): # https://hellowac.github.io/psutil-doc-zh/processes/process_class/oneshot.html if self.is_mac: @@ -1591,6 +1611,9 @@ def kill_process_all(args = {}): return mw.returnData(False, '缺少参数!') return mc_instance.kill_process_all(int(args['pid'])) +def set_meter_head(args = {}): + return mc_instance.set_meter_head(args) + def remove_service(args = {}): return mc_instance.remove_service(args) From 95e29d626676cb0b7b1b0d6314cdab8986562102 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 12:00:27 +0800 Subject: [PATCH 079/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index a2272c628d..23b4a135c8 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -129,7 +129,6 @@ $('.setting_ul_li').off('click').click(function (e) { clearInterval(process_list_s); tmPostCallback('set_meter_head',{meter_head_name: name}, function(data){ - console.log(data); isProcessing = false; // 操作完成,清除标志 if (!data) { layer.msg('设置失败'); @@ -173,7 +172,7 @@ if (process_list_s === 0) { process_list_s = 0; console.log('进程列表轮询任务已停止') } - get_process_list(null, null, true); + get_process_list(null, null, true); }, 3000); } From 0bc9ed9d49d6c8fd8658748e29a907b9c4d89eb6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 12:01:13 +0800 Subject: [PATCH 080/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 23b4a135c8..e838f2c74e 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -1095,8 +1095,8 @@ function dropAddress(address) { function show_task() { $(".ts-line").width($("#TaskManagement").width()); $("#TaskManagement tbody td").click(function () { - // console.log('---'); - $(this).parents("tr").addClass("active").siblings().removeClass("active"); + // console.log('---'); + $(this).parents("tr").addClass("active").siblings().removeClass("active"); }); var tableCont = document.querySelector('#table-cont'); //表格固定 From d5d96f6323a96ca3060bd442445c01b487fd0c69 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 12:01:38 +0800 Subject: [PATCH 081/121] Update config_api.py --- class/core/config_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index bfd27b69c4..b0dab12a3b 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -28,7 +28,7 @@ class config_api: - __version = '0.17.0' + __version = '0.17.0.1' __api_addr = 'data/api.json' # 统一默认配置文件 From 4420bbc36c0d75878036fb3d3ee5eb2c0591ab3a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 12:08:33 +0800 Subject: [PATCH 082/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index e838f2c74e..87e5ee5b00 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -118,7 +118,7 @@ var isProcessing = false; // 设置标志 $('.setting_ul_li').off('click').click(function (e) { var that = $(this); - e.stopPropagation() + e.stopPropagation(); // 检查标志 if (isProcessing) { return; @@ -170,7 +170,7 @@ if (process_list_s === 0) { if ($(".t-mana").length == 0) { clearInterval(process_list_s); process_list_s = 0; - console.log('进程列表轮询任务已停止') + console.log('进程列表轮询任务已停止'); } get_process_list(null, null, true); }, 3000); From 3d69e3723ecc76d0436edb61d951e1b9f009f448 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 12:13:56 +0800 Subject: [PATCH 083/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 87e5ee5b00..b54602b642 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -1085,7 +1085,7 @@ function get_process_info(pid) { function dropAddress(address) { layer.confirm(lan.index.net_doup_ip_msg, {icon: 3, closeBtn: 2}, function () { loadT = layer.msg(lan.index.net_doup_ip_to, {icon: 16, time: 0, shade: [0.3, '#000']}); - $.post('/firewall?action=AddDropAddress', 'port=' + address + '&ps=' + lan.index.net_doup_ip_ps, function (rdata) { + $.post('/firewall/add_drop_address', 'type=address&protocol=tcp&port=' + address + '&ps=手动屏蔽', function (rdata) { layer.close(loadT); layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); }); From 95f8faf30f20376cae936724fec063e41fd9a5b9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 12:14:29 +0800 Subject: [PATCH 084/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index b54602b642..618ca4c7c5 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -1114,10 +1114,4 @@ function show_jc_flie() { function scrollHandle(e) { var scrollTop = this.scrollTop; this.querySelector('thead').style.transform = 'translateY(' + scrollTop + 'px)'; -} - -var masterPluginTitle = $('.TaskManView').parents('.layui-layer'); -// masterPluginTitle.append(''); -masterPluginTitle.on('click', '.bt-desired', function(){ - bt_tools.nps({name:'任务管理器',type:26}) -}) \ No newline at end of file +} \ No newline at end of file From 7ab974e565f3948c79478ad776b1a7c5445e04ac Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 12:56:47 +0800 Subject: [PATCH 085/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 9e474a44c4..9ff70e31e6 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -423,12 +423,6 @@ def get_process_ps(self, name, pid, p_exe=None, p=None): return name def get_process_network(self, pid): - ''' - @name 获取进程网络流量 - @author hwliang<2021-09-13> - @param pid 进程ID - @return tuple - ''' if not self.__process_net_list: self.get_process_net_list() if not self.last_net_process_time: return 0, 0, 0, 0 @@ -486,7 +480,7 @@ def get_load_average(self): def set_meter_head(self, get): if not 'meter_head_name' in get: return False - + meter_head_name = get['meter_head_name'] meter_head_file = getServerDir()+'/meter_head.json' try: From 650b565fdf1c259878c021c2943651b95d87aa82 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 12:58:19 +0800 Subject: [PATCH 086/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 9ff70e31e6..c3dbbdd6a0 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -184,7 +184,6 @@ def get_mem_info(self, get=None): # 进程备注,name,pid,启动命令 def get_process_ps(self, name, pid, p_exe=None, p=None): - # print(name, pid, p_exe, p) processPs = { 'irqbalance': '系统进程-优化系统性能服务', 'containerd': 'docker管理服务', From a9e4c1b793a96feb588283b8d06d5926a1101b21 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 12:59:31 +0800 Subject: [PATCH 087/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index c3dbbdd6a0..d6d54d4116 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -1641,8 +1641,8 @@ def remove_user(args = {}): return mc_instance.remove_user(args) if __name__ == "__main__": - # print(mc_instance.get_process_list()) - print(mc_instance.get_network_list()) + print(mc_instance.get_process_list()) + # print(mc_instance.get_network_list()) # print(mc_instance.get_process_info({'pid':66647})) # for x in range(10): # mc_instance.test_cpu() From 1759b6bcb1255997c0fe03e4491266b2813a6d8a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 13:16:56 +0800 Subject: [PATCH 088/121] update --- plugins/task_manager/process_network_total.py | 2 +- plugins/task_manager/task_manager_index.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/process_network_total.py b/plugins/task_manager/process_network_total.py index cd317721c1..11584b5d83 100644 --- a/plugins/task_manager/process_network_total.py +++ b/plugins/task_manager/process_network_total.py @@ -12,7 +12,7 @@ import os import struct -os.chdir('/www/server/panel') +os.chdir('/www/server/mdserver-web') if 'class/' in sys.path: sys.path.insert(0,"class/") import copy try: diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index d6d54d4116..e81febdb0b 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -559,7 +559,7 @@ def check_process_net_total(self): pid = mw.readFile(_pid_file) if os.path.exists('/proc/' + pid): return True - cmd_file = getServerDir()+'/process_network_total.py' + cmd_file = mw_dir+'/plugins/task_manager/process_network_total.py' python_bin = self.get_python_bin() _cmd = 'nohup {} {} 600 &> /tmp/net.log &'.format(python_bin, cmd_file) mw.execShell(_cmd) From 05a2ba7f21993948010df633a7d5f249bb285984 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 13:18:06 +0800 Subject: [PATCH 089/121] Update process_network_total.py --- plugins/task_manager/process_network_total.py | 82 +------------------ 1 file changed, 2 insertions(+), 80 deletions(-) diff --git a/plugins/task_manager/process_network_total.py b/plugins/task_manager/process_network_total.py index 11584b5d83..53ad15f0d0 100644 --- a/plugins/task_manager/process_network_total.py +++ b/plugins/task_manager/process_network_total.py @@ -56,13 +56,7 @@ class process_network_total: __last_write_time = 0 __end_time = 0 - def start(self,timeout = 0): - ''' - @name 启动进程网络监控 - @author hwliang<2021-09-13> - @param timeout 结束时间(秒),0表示持久运行,默认为0 - @return void - ''' + def start(self,timeout = 0): stime = time.time() self.__end_time = timeout + stime self.__last_stat = stime @@ -80,12 +74,6 @@ def start(self,timeout = 0): self.rm_pid_file() def handle_packet(self, pcap_data): - ''' - @name 处理pcap数据包 - @author hwliang<2021-09-12> - @param pcap_data pcap数据包 - @return void - ''' # 获取IP协议头 ip_header = pcap_data[14:34] # 解析src/dst地址 @@ -103,14 +91,6 @@ def handle_packet(self, pcap_data): self.total_net_process(dst,src,pack_size) def total_net_process(self,dst,src,pack_size): - ''' - @name 统计进程流量 - @author hwliang<2021-09-13> - @param dst 目标地址 - @param src 源地址 - @param pack_size 数据包长度 - @return void - ''' self.get_tcp_stat() direction = None mtime = time.time() @@ -149,12 +129,7 @@ def total_net_process(self,dst,src,pack_size): self.write_net_process() def write_net_process(self): - ''' - @name 写入进程流量 - @author hwliang<2021-09-13> - @return void - ''' - w_file = '/dev/shm/bt_net_process' + w_file = '/dev/shm/mw_net_process' process_size = copy.deepcopy(self.__net_process_size) net_process = [] for pid in process_size.keys(): @@ -165,24 +140,12 @@ def write_net_process(self): f.close() def hex_to_ip(self, hex_ip): - ''' - @name 将16进制的IP地址转换为字符串IP地址 - @author hwliang<2021-09-13> - @param hex_ip 16进制的IP地址:16进程端口 - @return tuple(ip,port) IP地址,端口 - ''' hex_ip,hex_port = hex_ip.split(':') ip = '.'.join([str(int(hex_ip[i:i+2], 16)) for i in range(0, len(hex_ip), 2)][::-1]) port = int(hex_port, 16) return ip,port def get_tcp_stat(self,force = False): - ''' - @name 获取当前TCP连接状态表 - @author hwliang<2021-09-13> - @param force 是否强制刷新 - @return dict - ''' if not force and self.__net_process_list: return self.__net_process_list self.__net_process_list = {} tcp_stat_file = '/proc/net/tcp' @@ -211,21 +174,9 @@ def get_tcp_stat(self,force = False): def get_port_pack(self,port): - ''' - @name 将端口转换为字节流 - @author hwliang<2021-09-13> - @param port 端口 - @return bytes - ''' return struct.pack('H',int(port))[::-1] def get_ip_pack(self,ip): - ''' - @name 将IP地址转换为字节流 - @author hwliang<2021-09-13> - @param ip IP地址 - @return bytes - ''' ip_arr = ip.split('.') ip_pack = b'' for i in ip_arr: @@ -233,25 +184,12 @@ def get_ip_pack(self,ip): return ip_pack def inode_to_pid(self,inode,force = False): - ''' - @name 将inode转换为进程ID - @author hwliang<2021-09-13> - @param inode inode - @param force 是否强制刷新 - @return int - ''' inode_list = self.get_process_inodes() if inode in inode_list: return inode_list[inode] return None def get_process_inodes(self,force = False): - ''' - @name 获取进程inode列表 - @author hwliang<2021-09-13> - @param force 是否强制刷新 - @return dict - ''' if not force and self.__inode_list: return self.__inode_list proc_path = '/proc' inode_list = {} @@ -274,12 +212,6 @@ def get_process_inodes(self,force = False): return inode_list def get_process_name(self,pid): - ''' - @name 获取进程名称 - @author hwliang<2021-09-13> - @param pid 进程ID - @return str - ''' pid_path = '/proc/' + pid + '/comm' if not os.path.exists(pid_path): return '' pid_file = open(pid_path, 'rb') @@ -289,22 +221,12 @@ def get_process_name(self,pid): def write_pid(self): - ''' - @name 写入进程ID到PID文件 - @author hwliang<2021-09-13> - @return void - ''' self_pid = os.getpid() pid_file = open(self.__pid_file,'w') pid_file.write(str(self_pid)) pid_file.close() def rm_pid_file(self): - ''' - @name 删除进程pid文件 - @author hwliang<2021-09-13> - @return void - ''' if os.path.exists(self.__pid_file): os.remove(self.__pid_file) From 1cadeb3f59d02502d70b48d00cd57378d4b6013d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 13:19:44 +0800 Subject: [PATCH 090/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index e81febdb0b..71b99a13d6 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -95,7 +95,7 @@ def get_net_old(self): return True def get_process_net_list(self): - w_file = '/dev/shm/bt_net_process' + w_file = '/dev/shm/mw_net_process' if not os.path.exists(w_file): return self.last_net_process = cache.get('net_process') self.last_net_process_time = cache.get('last_net_process') @@ -113,8 +113,8 @@ def get_process_net_list(self): tmp['down_package'] = int(np_list[3]) tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - cache.set('net_process', self.__process_net_list, 600) - cache.set('last_net_process', time.time(), 600) + # cache.set('net_process', self.__process_net_list, 600) + # cache.set('last_net_process', time.time(), 600) # 获取进程连接数 def get_connects(self, pid): From ade3a5621faa1dfa3d0e2dc6cbdfa91f5851c759 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 13:33:23 +0800 Subject: [PATCH 091/121] Update process_network_total.py --- plugins/task_manager/process_network_total.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/process_network_total.py b/plugins/task_manager/process_network_total.py index 53ad15f0d0..90af7a29f7 100644 --- a/plugins/task_manager/process_network_total.py +++ b/plugins/task_manager/process_network_total.py @@ -40,7 +40,7 @@ elif os.path.exists('/usr/bin/yum'): os.system("yum install libpcap-devel -y") - os.system("btpip install pypcap") + os.system("pip install pypcap") try: import pcap except ImportError: From fe4ab5a0137894117939b78e9038458478f1e0bc Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 13:40:27 +0800 Subject: [PATCH 092/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 23 ---------------------- 1 file changed, 23 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 71b99a13d6..3c2ac10aba 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -39,8 +39,6 @@ class mainClass(object): old_info = {} new_net_info = {} old_net_info = {} - old_path = '/www/server/task_manager/task_old.json' - old_net_path = '/www/server/task_manager/network_old.json' panel_pid = None task_pid = None __process_net_list = {} @@ -72,27 +70,6 @@ def instance(cls, *args, **kwargs): mainClass._instance = mainClass(*args, **kwargs) return mainClass._instance - def get_old(self): - if self.old_info: return True - # if not os.path.exists(self.old_path): return False - data = cache.get(self.old_path) - if not data: return False - # data = json.loads(data) - if not data: return False - self.old_info = data - del (data) - return True - - def get_net_old(self): - if self.old_net_info: return True - # if not os.path.exists(self.old_net_path): return False - data = cache.get(self.old_net_path) - if not data: return False - # data = json.loads(data) - if not data: return False - self.old_net_info = data - del (data) - return True def get_process_net_list(self): w_file = '/dev/shm/mw_net_process' From a6619b6e9d6c7d773cfe9e214e5b6d9e0f9b7b36 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 13:56:34 +0800 Subject: [PATCH 093/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 3c2ac10aba..c6ddc422ed 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -74,8 +74,8 @@ def instance(cls, *args, **kwargs): def get_process_net_list(self): w_file = '/dev/shm/mw_net_process' if not os.path.exists(w_file): return - self.last_net_process = cache.get('net_process') - self.last_net_process_time = cache.get('last_net_process') + # self.last_net_process = cache.get('net_process') + # self.last_net_process_time = cache.get('last_net_process') net_process_body = mw.readFile(w_file) if not net_process_body: return net_process = net_process_body.split('\n') From 5012dc3a7bdf112f1af91cda5505602750a88935 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 14:02:41 +0800 Subject: [PATCH 094/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index c6ddc422ed..3d669cac67 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -74,8 +74,6 @@ def instance(cls, *args, **kwargs): def get_process_net_list(self): w_file = '/dev/shm/mw_net_process' if not os.path.exists(w_file): return - # self.last_net_process = cache.get('net_process') - # self.last_net_process_time = cache.get('last_net_process') net_process_body = mw.readFile(w_file) if not net_process_body: return net_process = net_process_body.split('\n') @@ -90,8 +88,8 @@ def get_process_net_list(self): tmp['down_package'] = int(np_list[3]) tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - # cache.set('net_process', self.__process_net_list, 600) - # cache.set('last_net_process', time.time(), 600) + self.last_net_process = self.__process_net_list + self.last_net_process_time = time.time() # 获取进程连接数 def get_connects(self, pid): From 082c90b76944d841b4c3f07793c8aca30b311f28 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 15:14:20 +0800 Subject: [PATCH 095/121] update --- plugins/task_manager/install.sh | 1 + plugins/task_manager/process_network_total.py | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/task_manager/install.sh b/plugins/task_manager/install.sh index d9e58e88b4..ba943c6278 100755 --- a/plugins/task_manager/install.sh +++ b/plugins/task_manager/install.sh @@ -11,6 +11,7 @@ install_tmp=${rootPath}/tmp/mw_install.pl VERSION=$2 # python3 plugins/task_manager/task_manager_index.py +# /www/server/mdserver-web/bin/python3 /www/server/mdserver-web/plugins/task_manager/process_network_total.py Install_App() { diff --git a/plugins/task_manager/process_network_total.py b/plugins/task_manager/process_network_total.py index 90af7a29f7..be1a658873 100644 --- a/plugins/task_manager/process_network_total.py +++ b/plugins/task_manager/process_network_total.py @@ -1,11 +1,4 @@ #coding: utf-8 -#------------------------------------------------------------------- -# 宝塔Linux面板 -#------------------------------------------------------------------- -# Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved. -#------------------------------------------------------------------- -# Author: hwliang -#------------------------------------------------------------------- import sys import time From b94af58524d6036440609e6eba99e006f7139070 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 15:14:48 +0800 Subject: [PATCH 096/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 3d669cac67..3ba858cde0 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -536,7 +536,7 @@ def check_process_net_total(self): cmd_file = mw_dir+'/plugins/task_manager/process_network_total.py' python_bin = self.get_python_bin() - _cmd = 'nohup {} {} 600 &> /tmp/net.log &'.format(python_bin, cmd_file) + _cmd = 'nohup {} {} &> /tmp/net.log &'.format(python_bin, cmd_file) mw.execShell(_cmd) # 进程折叠,将子进程折叠到父进程下,并将使用资源累加。 From 5a37c742e2f60dffff04083bcb2efd0fbfe73529 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 15:21:09 +0800 Subject: [PATCH 097/121] Update info.json --- plugins/task_manager/info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/info.json b/plugins/task_manager/info.json index bdfcdda38c..13ef84a2f0 100755 --- a/plugins/task_manager/info.json +++ b/plugins/task_manager/info.json @@ -1,6 +1,6 @@ { "sort": 7, - "ps": "轻松管理进程、流量监控、启动项、用户、服务、计划任务、会话[开发中]", + "ps": "轻松管理进程、流量监控、启动项、用户、服务、计划任务、会话", "name": "task_manager", "title": "任务管理器", "shell": "install.sh", From 23fe4928e04496f72acd631882ad35f5f4b2cc73 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 15:31:09 +0800 Subject: [PATCH 098/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 3ba858cde0..6d3cd24f87 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -866,6 +866,7 @@ def get_process_list_linux(self, get = {}): tmp['threads'] = p.num_threads() tmp['ps'] = self.get_process_ps(tmp['name'], pid, tmp['exe'], p) tmp['up'], tmp['up_package'], tmp['down'], tmp['down_package'] = self.get_process_network(pid) + # print(pid,tmp['up'], tmp['up_package'], tmp['down'], tmp['down_package']) if tmp['cpu_percent'] > 100: tmp['cpu_percent'] = 0.1 info['cpu'] += tmp['cpu_percent'] info['disk'] += tmp['io_write_speed'] + tmp['io_read_speed'] From 80b615810cae6eaf98c117e12559a9633b312a66 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 15:56:27 +0800 Subject: [PATCH 099/121] Update process_network_total.py --- plugins/task_manager/process_network_total.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/task_manager/process_network_total.py b/plugins/task_manager/process_network_total.py index be1a658873..d941b64e2b 100644 --- a/plugins/task_manager/process_network_total.py +++ b/plugins/task_manager/process_network_total.py @@ -63,6 +63,7 @@ def start(self,timeout = 0): if p_time > self.__end_time: self.rm_pid_file() break + except: self.rm_pid_file() @@ -224,10 +225,6 @@ def rm_pid_file(self): os.remove(self.__pid_file) if __name__ == '__main__': - if len(sys.argv) > 1: - timeout = int(sys.argv[-1]) - else: - timeout = 0 p = process_network_total() p.write_pid() - p.start(timeout) \ No newline at end of file + p.start(600) \ No newline at end of file From eaa1a74dd61655f3af17ea54f6e16924a62151fb Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 16:05:46 +0800 Subject: [PATCH 100/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 6d3cd24f87..c22ff7eabc 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -88,8 +88,10 @@ def get_process_net_list(self): tmp['down_package'] = int(np_list[3]) tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - self.last_net_process = self.__process_net_list - self.last_net_process_time = time.time() + + if time.time() - self.last_net_process_time > 3: + self.last_net_process = self.__process_net_list + self.last_net_process_time = time.time() # 获取进程连接数 def get_connects(self, pid): From 13bb828a95cb311d4e20d2d19275d1c19989d4e5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 16:12:37 +0800 Subject: [PATCH 101/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 618ca4c7c5..2915ba7c97 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -321,29 +321,29 @@ function get_process_list(sortx, reverse, rx) { function task_manager_possess_scroll() { var timer = null; - var set2selected = null + var set2selected = null; // 滚动节流 return function () { - if (timer !== null) return - timer = setTimeout(function () { - timer = null - canScroll2TaskMangerPossess = false - if (set2selected !== null) clearTimeout(set2selected) - // 最后一次滚动后2秒内不再滚动,才能滚动到选中的行 - set2selected = setTimeout(function () { - canScroll2TaskMangerPossess = true - }, 2000) - }, 500) + if (timer !== null) return; + timer = setTimeout(function () { + timer = null; + canScroll2TaskMangerPossess = false; + if (set2selected !== null) clearTimeout(set2selected) + // 最后一次滚动后2秒内不再滚动,才能滚动到选中的行 + set2selected = setTimeout(function () { + canScroll2TaskMangerPossess = true; + }, 2000); + }, 500); } } function scropll2selectPossess(selectline) { if (canScroll2TaskMangerPossess && selectline !== -1) { - var top = $('#table-cont')[0].scrollTop; - // if(selectline > 2) - if (selectline * 38 > top + 500 || selectline * 38 < top) { - $('#table-cont')[0].scrollTo(0, (selectline - 2) * 38, 'smooth'); - } + var top = $('#table-cont')[0].scrollTop; + // if(selectline > 2) + if (selectline * 38 > top + 500 || selectline * 38 < top) { + $('#table-cont')[0].scrollTo(0, (selectline - 2) * 38, 'smooth'); + } } } From 17a40802ae6f8d290bd3de1fca96f419db02bc92 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 16:16:10 +0800 Subject: [PATCH 102/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index c22ff7eabc..476f85302a 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -408,6 +408,7 @@ def get_process_network(self, pid): return self.__process_net_list[pid]['up'], self.__process_net_list[pid]['up_package'], \ self.__process_net_list[pid]['down'], self.__process_net_list[pid]['down_package'] + # print(pid, self.__process_net_list[pid]['up'], self.last_net_process[pid]['up'],time.time(),self.last_net_process_time) up = int((self.__process_net_list[pid]['up'] - self.last_net_process[pid]['up']) / ( time.time() - self.last_net_process_time)) down = int((self.__process_net_list[pid]['down'] - self.last_net_process[pid]['down']) / ( From 6d77e923b7f3febed6d7fc2f83c39b7ad6d30b13 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 16:22:04 +0800 Subject: [PATCH 103/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 476f85302a..fa2631e1ab 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -89,7 +89,7 @@ def get_process_net_list(self): tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - if time.time() - self.last_net_process_time > 3: + if time.time() - self.last_net_process_time > 10: self.last_net_process = self.__process_net_list self.last_net_process_time = time.time() From e441d8dc87927299bb8e4c43731d4c975b2201fc Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 16:22:12 +0800 Subject: [PATCH 104/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index fa2631e1ab..fd53064caf 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -89,7 +89,7 @@ def get_process_net_list(self): tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - if time.time() - self.last_net_process_time > 10: + if time.time() - self.last_net_process_time > 7: self.last_net_process = self.__process_net_list self.last_net_process_time = time.time() From 62df45da6a7899e2b21c878cb328701d7687ac12 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 16:22:45 +0800 Subject: [PATCH 105/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index fd53064caf..9ebf7560b1 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -418,6 +418,7 @@ def get_process_network(self, pid): down_package = int( (self.__process_net_list[pid]['down_package'] - self.last_net_process[pid]['down_package']) / ( time.time() - self.last_net_process_time)) + # print(up, up_package, down, down_package) return up, up_package, down, down_package def get_process_cpu_time(self, cpu_times): From cbb2a076e39528a81f80850267fb56d08d043925 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 16:30:10 +0800 Subject: [PATCH 106/121] Update task_manager.js --- plugins/task_manager/js/task_manager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/js/task_manager.js b/plugins/task_manager/js/task_manager.js index 2915ba7c97..6c3f7f36e6 100644 --- a/plugins/task_manager/js/task_manager.js +++ b/plugins/task_manager/js/task_manager.js @@ -313,9 +313,9 @@ function get_process_list(sortx, reverse, rx) { setCookie('table_config_tip',true); } // 清除掉之前绑定的滚动事件 - $("#table-cont").unbind('scroll'); + // $("#table-cont").unbind('scroll'); // 重新绑定滚动事件 - $('#table-cont').scroll(task_manager_possess_scroll()); + // $('#table-cont').scroll(task_manager_possess_scroll()); }); } From 5ba5da4cd1a0bcb909d59b42f47f5f4f3893e14d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 16:39:48 +0800 Subject: [PATCH 107/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 9ebf7560b1..09085c5660 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -89,7 +89,7 @@ def get_process_net_list(self): tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - if time.time() - self.last_net_process_time > 7: + if time.time() - self.last_net_process_time > 600 and self.last_net_process_time != 0: self.last_net_process = self.__process_net_list self.last_net_process_time = time.time() From ded25a7c87047d4dcbcd92d45789dfd1a9da14c6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 16:41:29 +0800 Subject: [PATCH 108/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 09085c5660..3cc38030e6 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -418,7 +418,7 @@ def get_process_network(self, pid): down_package = int( (self.__process_net_list[pid]['down_package'] - self.last_net_process[pid]['down_package']) / ( time.time() - self.last_net_process_time)) - # print(up, up_package, down, down_package) + # print('get_process_network', up, up_package, down, down_package) return up, up_package, down, down_package def get_process_cpu_time(self, cpu_times): From 27b914a9054e416572cefe05b4944a28d71fff3e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 17:01:45 +0800 Subject: [PATCH 109/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 3cc38030e6..2c1713cdf4 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -89,7 +89,7 @@ def get_process_net_list(self): tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - if time.time() - self.last_net_process_time > 600 and self.last_net_process_time != 0: + if time.time() - self.last_net_process_time > 600 or self.last_net_process_time == 0: self.last_net_process = self.__process_net_list self.last_net_process_time = time.time() From d94290019c56ec82470a59b05d40672e5a508934 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 17:08:42 +0800 Subject: [PATCH 110/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 2c1713cdf4..1a6c23b4d3 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -89,7 +89,7 @@ def get_process_net_list(self): tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - if time.time() - self.last_net_process_time > 600 or self.last_net_process_time == 0: + if time.time() - self.last_net_process_time > 60 or self.last_net_process_time == 0: self.last_net_process = self.__process_net_list self.last_net_process_time = time.time() From fee8c8c3db020f4cfdad107055f4aa16deb5d70e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 17:13:16 +0800 Subject: [PATCH 111/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 1a6c23b4d3..3d822e413c 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -72,6 +72,7 @@ def instance(cls, *args, **kwargs): def get_process_net_list(self): + import copy w_file = '/dev/shm/mw_net_process' if not os.path.exists(w_file): return net_process_body = mw.readFile(w_file) @@ -90,7 +91,7 @@ def get_process_net_list(self): self.__process_net_list[tmp['pid']] = tmp if time.time() - self.last_net_process_time > 60 or self.last_net_process_time == 0: - self.last_net_process = self.__process_net_list + self.last_net_process = copy.deepcopy(self.__process_net_list) self.last_net_process_time = time.time() # 获取进程连接数 From 2e1c2e21b7caf5a275c30b67174716e28bea9210 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 17:18:19 +0800 Subject: [PATCH 112/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 3d822e413c..7ef9c511c6 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -90,7 +90,7 @@ def get_process_net_list(self): tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - if time.time() - self.last_net_process_time > 60 or self.last_net_process_time == 0: + if time.time() - self.last_net_process_time > 600 or self.last_net_process_time == 0: self.last_net_process = copy.deepcopy(self.__process_net_list) self.last_net_process_time = time.time() From c24510e1e78239c6aafbb2960d2599b1a3ba5bc6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 17:44:27 +0800 Subject: [PATCH 113/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index 7ef9c511c6..d4c3fa8fab 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -409,16 +409,12 @@ def get_process_network(self, pid): return self.__process_net_list[pid]['up'], self.__process_net_list[pid]['up_package'], \ self.__process_net_list[pid]['down'], self.__process_net_list[pid]['down_package'] + now_t = time.time() # print(pid, self.__process_net_list[pid]['up'], self.last_net_process[pid]['up'],time.time(),self.last_net_process_time) - up = int((self.__process_net_list[pid]['up'] - self.last_net_process[pid]['up']) / ( - time.time() - self.last_net_process_time)) - down = int((self.__process_net_list[pid]['down'] - self.last_net_process[pid]['down']) / ( - time.time() - self.last_net_process_time)) - up_package = int((self.__process_net_list[pid]['up_package'] - self.last_net_process[pid]['up_package']) / ( - time.time() - self.last_net_process_time)) - down_package = int( - (self.__process_net_list[pid]['down_package'] - self.last_net_process[pid]['down_package']) / ( - time.time() - self.last_net_process_time)) + up = int((self.__process_net_list[pid]['up'] - self.last_net_process[pid]['up']) / ( now_t - self.last_net_process_time)) + down = int((self.__process_net_list[pid]['down'] - self.last_net_process[pid]['down']) / ( now_t - self.last_net_process_time)) + up_package = int((self.__process_net_list[pid]['up_package'] - self.last_net_process[pid]['up_package']) / ( now_t - self.last_net_process_time)) + down_package = int((self.__process_net_list[pid]['down_package'] - self.last_net_process[pid]['down_package']) / (now_t - self.last_net_process_time)) # print('get_process_network', up, up_package, down, down_package) return up, up_package, down, down_package From 8d0ee48aa69252141f042251672b5c2d41d99609 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 17:47:13 +0800 Subject: [PATCH 114/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index d4c3fa8fab..cba95c2dc7 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -90,7 +90,7 @@ def get_process_net_list(self): tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - if time.time() - self.last_net_process_time > 600 or self.last_net_process_time == 0: + if time.time() - self.last_net_process_time > 6 or self.last_net_process_time == 0: self.last_net_process = copy.deepcopy(self.__process_net_list) self.last_net_process_time = time.time() From a69d5367d7fa14ec3d44ae07bf891df2b05c4d37 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 17:48:26 +0800 Subject: [PATCH 115/121] Update task_manager_index.py --- plugins/task_manager/task_manager_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/task_manager/task_manager_index.py b/plugins/task_manager/task_manager_index.py index cba95c2dc7..f172e4b25f 100755 --- a/plugins/task_manager/task_manager_index.py +++ b/plugins/task_manager/task_manager_index.py @@ -90,7 +90,7 @@ def get_process_net_list(self): tmp['up_package'] = int(np_list[4]) self.__process_net_list[tmp['pid']] = tmp - if time.time() - self.last_net_process_time > 6 or self.last_net_process_time == 0: + if time.time() - self.last_net_process_time > 12 or self.last_net_process_time == 0: self.last_net_process = copy.deepcopy(self.__process_net_list) self.last_net_process_time = time.time() From d0cdab81d4f4ddbfee5c61abdd3b80990bd26892 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 18:08:57 +0800 Subject: [PATCH 116/121] Update install.sh --- plugins/task_manager/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/task_manager/install.sh b/plugins/task_manager/install.sh index ba943c6278..2db35da72a 100755 --- a/plugins/task_manager/install.sh +++ b/plugins/task_manager/install.sh @@ -12,6 +12,7 @@ VERSION=$2 # python3 plugins/task_manager/task_manager_index.py # /www/server/mdserver-web/bin/python3 /www/server/mdserver-web/plugins/task_manager/process_network_total.py +# ps -ef|grep process_network_total| grep -v grep | awk '{print $2}' | xargs kill -9 Install_App() { From fbce4a1abcdec3e5030379dacb50472ec8b5eb1a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 18:12:51 +0800 Subject: [PATCH 117/121] Update install.sh --- plugins/task_manager/install.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/task_manager/install.sh b/plugins/task_manager/install.sh index 2db35da72a..a5df25b6cc 100755 --- a/plugins/task_manager/install.sh +++ b/plugins/task_manager/install.sh @@ -19,6 +19,14 @@ Install_App() echo '正在安装脚本文件...' > $install_tmp mkdir -p $serverPath/task_manager + if [ -d /usr/bin/apt ]; then + apt install libpcap-dev -y + fi + + if [ -d /usr/bin/yum ]; then + yum install libpcap-devel -y + fi + echo "$VERSION" > $serverPath/task_manager/version.pl echo "安装任务管理器成功" } From 1e71eedc19c0b49d78769954acb0e85819ef3876 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 18:13:40 +0800 Subject: [PATCH 118/121] Update install.sh --- plugins/task_manager/install.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/task_manager/install.sh b/plugins/task_manager/install.sh index a5df25b6cc..ca6548c7da 100755 --- a/plugins/task_manager/install.sh +++ b/plugins/task_manager/install.sh @@ -19,14 +19,18 @@ Install_App() echo '正在安装脚本文件...' > $install_tmp mkdir -p $serverPath/task_manager - if [ -d /usr/bin/apt ]; then + if [ -f /usr/bin/apt ]; then apt install libpcap-dev -y fi - if [ -d /usr/bin/yum ]; then + if [ -f /usr/bin/yum ]; then yum install libpcap-devel -y fi + if [ -f /usr/bin/dnf ]; then + dnf install libpcap-devel -y + fi + echo "$VERSION" > $serverPath/task_manager/version.pl echo "安装任务管理器成功" } From ff015b19f7d73c2a76c679ae231c2d491745ef48 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 18:14:40 +0800 Subject: [PATCH 119/121] Update install.sh --- plugins/task_manager/install.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/task_manager/install.sh b/plugins/task_manager/install.sh index ca6548c7da..1884c74a85 100755 --- a/plugins/task_manager/install.sh +++ b/plugins/task_manager/install.sh @@ -14,6 +14,10 @@ VERSION=$2 # /www/server/mdserver-web/bin/python3 /www/server/mdserver-web/plugins/task_manager/process_network_total.py # ps -ef|grep process_network_total| grep -v grep | awk '{print $2}' | xargs kill -9 +if [ -f ${rootPath}/bin/activate ];then + source ${rootPath}/bin/activate +fi + Install_App() { echo '正在安装脚本文件...' > $install_tmp @@ -31,6 +35,8 @@ Install_App() dnf install libpcap-devel -y fi + pip3 install pypcap + echo "$VERSION" > $serverPath/task_manager/version.pl echo "安装任务管理器成功" } From 8984381ea2c1f90c394b321ad1ea4730a57001bc Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 18:57:35 +0800 Subject: [PATCH 120/121] 0.17.1 --- README.md | 4 ++-- class/core/config_api.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 47ba88475a..dad5d30436 100644 --- a/README.md +++ b/README.md @@ -110,9 +110,9 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443: ``` -### 版本更新 0.17.0 +### 版本更新 0.17.1 -- 面板SSL调整。 +- 任务管理器-插件。 ### JSDelivr安装地址 diff --git a/class/core/config_api.py b/class/core/config_api.py index b0dab12a3b..02688fa957 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -28,7 +28,7 @@ class config_api: - __version = '0.17.0.1' + __version = '0.17.1' __api_addr = 'data/api.json' # 统一默认配置文件 From d2b837f52c1a4d40d57348dea11604ad5f1e570c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 5 Jun 2024 18:58:12 +0800 Subject: [PATCH 121/121] Update mw.py --- class/core/mw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/mw.py b/class/core/mw.py index f5d90dbc9a..add6338e2a 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -1466,7 +1466,7 @@ def makeConf(): file = getRunDir() + '/data/json/config.json' if not os.path.exists(file): c = {} - c['title'] = '老子面板' + c['title'] = '后羿面板' c['home'] = 'http://github/midoks/mdserver-web' c['recycle_bin'] = True c['template'] = 'default'