From 39c350942e49681ed24b942b80d4544fdbd302c4 Mon Sep 17 00:00:00 2001 From: midoks Date: Sat, 19 Nov 2022 00:46:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=AE=89=E8=A3=85=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/config_api.py | 2 +- class/core/plugins_api.py | 64 +++++++++++++++-- plugins/mysql/install.sh | 4 ++ plugins/openresty/install.sh | 4 ++ plugins/php/install.sh | 4 ++ plugins/phpmyadmin/install.sh | 4 ++ plugins/swap/install.sh | 4 ++ route/static/app/index.js | 112 +++++++++++++++++++++++++---- route/static/app/soft.js | 15 +++- route/static/css/site.css | 47 ++++++++---- route/templates/default/index.html | 9 ++- 11 files changed, 234 insertions(+), 35 deletions(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index e17636072..33bac5a0d 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -27,7 +27,7 @@ from flask import request class config_api: - __version = '0.11.0.1' + __version = '0.11.0.2' def __init__(self): pass diff --git a/class/core/plugins_api.py b/class/core/plugins_api.py index aea03a668..6cd67d32a 100755 --- a/class/core/plugins_api.py +++ b/class/core/plugins_api.py @@ -104,6 +104,61 @@ class plugins_api: return mw.returnJson(True, '成功!') return mw.returnJson(False, '失败!') + def initApi(self): + + plugin_names = { + 'openresty': '1.21.4.1', + 'php': '56', + 'swap': '1.1', + 'mysql': '5.7', + 'phpmyadmin': '4.4.15', + } + + pn_dir = mw.getPluginDir() + pn_list = [] + for pn in plugin_names: + info = {} + pn_json = pn_dir + '/' + pn + '/info.json' + if not os.path.exists(pn_json): + + tmp = mw.readFile(pn_json) + tmp = json.loads(tmp) + + info['title'] = tmp['title'] + info['name'] = tmp['name'] + info['versions'] = tmp['versions'] + info['default_ver'] = plugin_names[pn] + pn_list.append(info) + else: + return mw.returnJson(False, 'ok') + + return mw.returnJson(True, 'ok', pn_list) + + def initInstallApi(self): + pn_list = request.form.get('list', '') + try: + pn_list = json.loads(pn_list) + + for pn in pn_list: + name = pn['name'] + version = pn['version'] + infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json' + pluginInfo = json.loads(mw.readFile(infoJsonPos)) + self.hookInstall(pluginInfo) + execstr = 'cd ' + mw.getPluginDir() + '/' + name + ' && bash ' + \ + pluginInfo['shell'] + ' install ' + version + + taskAdd = ('安装[' + name + '-' + version + ']', + 'execshell', '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr) + + mw.M('tasks').add('name,type,status,addtime, execstr', taskAdd) + + # 任务执行相关 + mw.triggerTask() + return mw.returnJson(True, '添加成功') + except Exception as e: + return mw.returnJson(False, mw.getTracebackInfo()) + def installApi(self): rundir = mw.getRunDir() name = request.form.get('name', '') @@ -129,17 +184,16 @@ class plugins_api: pluginInfo = json.loads(mw.readFile(infoJsonPos)) self.hookInstall(pluginInfo) - execstr = "cd " + os.getcwd() + "/plugins/" + \ - name + " && /bin/bash " + pluginInfo["shell"] \ - + " install " + version + execstr = 'cd ' + mw.getPluginDir() + '/' + name + ' && bash ' + \ + pluginInfo['shell'] + ' install ' + version if mw.isAppleSystem(): print(execstr) - taskAdd = (None, mmsg + '[' + name + '-' + version + ']', + taskAdd = (mmsg + '[' + name + '-' + version + ']', 'execshell', '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr) - mw.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd) + mw.M('tasks').add('name,type,status,addtime, execstr', taskAdd) # 任务执行相关 mw.triggerTask() diff --git a/plugins/mysql/install.sh b/plugins/mysql/install.sh index 51a3f3c15..d9c519d17 100755 --- a/plugins/mysql/install.sh +++ b/plugins/mysql/install.sh @@ -24,6 +24,10 @@ if [ ! -d $curPath/versions/$2 ];then exit 0 fi +if [ -d $serverPath/mysql ];then + exit 0 +fi + if [ "${action}" == "uninstall" ];then if [ -f /usr/lib/systemd/system/mysql.service ] || [ -f /lib/systemd/system/mysql.service ];then diff --git a/plugins/openresty/install.sh b/plugins/openresty/install.sh index a2100ec71..71910b01f 100755 --- a/plugins/openresty/install.sh +++ b/plugins/openresty/install.sh @@ -25,6 +25,10 @@ fi Install_openresty() { + if [ -d $serverPath/openresty ];then + exit 0 + fi + # ----- cpu start ------ if [ -z "${cpuCore}" ]; then cpuCore="1" diff --git a/plugins/php/install.sh b/plugins/php/install.sh index 472bdc642..6938aa163 100755 --- a/plugins/php/install.sh +++ b/plugins/php/install.sh @@ -31,6 +31,10 @@ if [ ! -d $curPath/versions/$2 ];then exit 0 fi +if [ -d $serverPath/php/${type} ];then + exit 0 +fi + if [ "${action}" == "uninstall" ];then if [ -f /usr/lib/systemd/system/php${type}.service ] || [ -f /lib/systemd/system/php${type}.service ] ;then diff --git a/plugins/phpmyadmin/install.sh b/plugins/phpmyadmin/install.sh index ef85e92a2..c880a1056 100755 --- a/plugins/phpmyadmin/install.sh +++ b/plugins/phpmyadmin/install.sh @@ -41,6 +41,10 @@ fi Install_phpmyadmin() { + if [ -d $serverPath/phpmyadmin ];then + exit 0 + fi + mkdir -p ${serverPath}/phpmyadmin mkdir -p ${serverPath}/source/phpmyadmin diff --git a/plugins/swap/install.sh b/plugins/swap/install.sh index f87c28757..c950051bc 100755 --- a/plugins/swap/install.sh +++ b/plugins/swap/install.sh @@ -14,6 +14,10 @@ VERSION=$2 Install_swap() { + if [ -d $serverPath/swap ];then + exit 0 + fi + echo '正在安装脚本文件...' > $install_tmp mkdir -p $serverPath/source mkdir -p $serverPath/swap diff --git a/route/static/app/index.js b/route/static/app/index.js index e615dd235..a0e551102 100755 --- a/route/static/app/index.js +++ b/route/static/app/index.js @@ -277,8 +277,6 @@ function setcolor(pre, s, s1, s2, s3) { } - - function getNet() { var up, down; $.get("/system/network", function(net) { @@ -304,8 +302,8 @@ function getNet() { } //网络Io -function NetImg() { - var myChartNetwork = echarts.init(document.getElementById('NetImg')); +function netImg() { + var myChartNetwork = echarts.init(document.getElementById('netImg')); var xData = []; var yData = []; var zData = []; @@ -475,7 +473,7 @@ function NetImg() { myChartNetwork.resize(); }); } -NetImg(); + function setImg() { $('.circle').each(function(index, el) { @@ -499,7 +497,6 @@ function setImg() { layer.closeAll('tips'); }); } -setImg(); // 检查更新 setTimeout(function() { @@ -733,7 +730,7 @@ function warningTo(to_url, def) { layer.close(loadT); layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); if (rdata.status && def) setTimeout(function() { location.reload(); }, 1000); - }); + },'json'); } function setSafeHide() { @@ -766,10 +763,100 @@ function showDanger(num, port) { $(".showDanger td").css("padding", "8px") } -//加载关键数据总数 -loadKeyDataCount(); +function pluginInit(){ + $.post('/plugins/init', function(data){ + if (!data.status){ + return false; + } + + var rdata = data.data; + var plugin_list = ''; + + for (var i = 0; i < rdata.length; i++) { + var ver = rdata[i]['versions']; + var select_list = ''; + if (typeof(ver)=='string'){ + select_list = ''; + } else { + for (var vi = 0; vi < ver.length; vi++) { + + if (ver[vi] == rdata[i]['default_ver']){ + select_list += ''; + } else { + select_list += ''; + } + } + } + + var pn_checked = ''; + if (rdata[i]['name'] == 'swap'){ + var pn_checked = ''; + } + + plugin_list += '
  • \ + \ + \ + \ + '+pn_checked+'
  • '; + } + + layer.open({ + type: 1, + title: '推荐安装', + area: ["320px", "400px"], + closeBtn: 2, + shadeClose: false, + content:"\ +
    \ +
    \ +

    推荐以下一键套件,或在软件管理按需选择。

    \ + \ +
    \ +
    \ +

    经典LNMP

    \ +
    \ +
      " + plugin_list + "
    \ +
    一键安装
    \ +
    \ +
    \ +
    ", + success:function(l,index){ + $('.rec-box-con .onekey').click(function(){ + var post_data = []; + for (var i = 0; i < rdata.length; i++) { + var key_ver = '#select_'+rdata[i]['name']; + var key_checked = '#data_'+rdata[i]['name']; + + var val_checked = $(key_checked).prop("checked"); + if (val_checked){ + + var tmp = {}; + var val_key = $(key_ver).val(); + + tmp['version'] = val_key; + tmp['name'] = rdata[i]['name']; + post_data.push(tmp); + } + } + + $.post('/plugins/init_install', 'list='+JSON.stringify(post_data), function(data){ + layer.msg(data.msg, { icon: data.status ? 1 : 2 }); + },'json'); + }); + }, + cancel:function(){ + layer.confirm('是否不再显示推荐安装套件?', {btn : ['确定', '取消'],title: "不再显示推荐?"}, function() { + $.post('/files/create_dir', 'path=/www/server/php', function(rdata) { + layer.closeAll(); + },'json'); + }); + } + }); + },'json'); +} + function loadKeyDataCount(){ - var plist = ['mysql', 'gogs','gitea']; + var plist = ['mysql', 'gogs', 'gitea']; for (var i = 0; i < plist.length; i++) { pname = plist[i]; function call(pname){ @@ -783,8 +870,9 @@ function loadKeyDataCount(){ return; } var html = '
  • \ -

    '+pname+'

    \ -
  • '; +

    '+pname+'

    \ +
    '+rdata['data']['count']+'
    \ + '; $('#index_overview').append(html); },'json'); } diff --git a/route/static/app/soft.js b/route/static/app/soft.js index 3ef79eb98..374d339c0 100755 --- a/route/static/app/soft.js +++ b/route/static/app/soft.js @@ -307,9 +307,19 @@ function toIndexDisplay(name, version, coexist) { } function indexListHtml(callback){ - var loadT = layer.msg('正在获取列表...', { icon: 16, time: 0, shade: [0.3, '#000'] }); + + + // init + $("#indexsoft").html(''); + var index_soft = ''; + for (var i = 0; i < 12; i++) { + index_soft += '
    '; + } + $("#indexsoft").html(index_soft); + + // var loadT = layer.msg('正在获取列表...', { icon: 16, time: 0, shade: [0.3, '#000'] }); $.get('/plugins/index_list', function(rdata) { - layer.close(loadT); + // layer.close(loadT); $("#indexsoft").html(''); var con = ''; for (var i = 0; i < rdata.length; i++) { @@ -360,7 +370,6 @@ function indexListHtml(callback){ var softboxn = softboxlen; if (softboxlen <= softboxsum) { for (var i = 0; i < softboxsum - softboxlen; i++) { - // softboxn += 1000; softboxcon += '
    '; } $("#indexsoft").append(softboxcon); diff --git a/route/static/css/site.css b/route/static/css/site.css index d3591069f..0059f7846 100755 --- a/route/static/css/site.css +++ b/route/static/css/site.css @@ -352,14 +352,8 @@ html { box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6) } -.important-title { - color:red; - background-color: #fef3e2; - line-height: 46px; - margin-bottom: 15px; - padding-left: 10px; - box-shadow: 0 1px 2px 0 rgba(0,0,0,.2); -} + + .info-title-tips { background-color: #fbfbfb; border: 1px solid #eee; @@ -1967,19 +1961,46 @@ html .menu .menu_exit:hover { } .sl-s-info { - width: 124px; - border: #ccc 1px solid + width: 210px; + border: #ccc 1px solid; +} + +.important-title { + display: flex; + color:red; + background-color: #fef3e2; + line-height: 46px; + margin-bottom: 15px; + padding-left: 10px; + box-shadow: 0 1px 2px 0 rgba(0,0,0,.2); +} + +.important-title>p { + flex: 1; +} + +.rec-box-con .onekey { + font-family: "宋体"; + width: 90px; + height: 30px; + line-height: 30px; + text-align: center; + background-color: #20a53a; + border-radius: 3px; + color: #fff; + margin: 20px auto 15px; + cursor: pointer; } .rec-install { padding: 16px; width: 100%; - float: left + float: left; } .rec-install .rec-box { - width: 305px; - float: left + width: 290px; + float: left; } .rec-install h3 { diff --git a/route/templates/default/index.html b/route/templates/default/index.html index 9146b09a7..26f627483 100755 --- a/route/templates/default/index.html +++ b/route/templates/default/index.html @@ -107,7 +107,7 @@

    总发送

    0

    总接收

    0
    -
    +
    @@ -118,6 +118,13 @@