diff --git a/class/core/plugin_api.py b/class/core/plugin_api.py
index fff69dd96..17a86f1d3 100755
--- a/class/core/plugin_api.py
+++ b/class/core/plugin_api.py
@@ -68,14 +68,45 @@ class plugin_api:
def checkStatus(self, info):
pass
+ def checkDisplayIndex(self, name, version):
+ if not os.path.exists(self.__index):
+ public.writeFile(self.__index, '[]')
+
+ indexList = json.loads(public.readFile(self.__index))
+ if type(version) == list:
+ for index in range(len(version)):
+ vname = name + '-' + version[index]
+ if vname in indexList:
+ return True
+ else:
+ vname = name + '-' + version
+ if vname in indexList:
+ return True
+ return False
+
+ def getVersion(self, path):
+ pass
+
# 构造本地插件信息
def getPluginInfo(self, info):
checks = ''
+ path = ''
+ coexist = False
+
if info["checks"][0:1] == '/':
checks = info["checks"]
else:
checks = public.getRootDir() + '/' + info['checks']
+ if info.has_key('path'):
+ path = info['path']
+
+ if path[0:1] != '/':
+ path = public.getRootDir() + '/' + path
+
+ if info.has_key('coexist') and info['coexist']:
+ coexist = True
+
pluginInfo = {
"id": 10000,
"pid": info['pid'],
@@ -85,11 +116,15 @@ class plugin_api:
"ps": info['ps'],
"dependnet": "",
"mutex": "",
+ "path": path,
"install_checks": checks,
"uninsatll_checks": checks,
+ "coexist": coexist,
"versions": info['versions'],
# "updates": info['updates'],
+ "display": False,
"setup": False,
+ "setup_version": "",
"status": False,
}
@@ -99,10 +134,54 @@ class plugin_api:
pluginInfo['install_checks'] = checks.replace(
'VERSION', info['versions'])
+ if path.find('VERSION') > -1:
+ pluginInfo['path'] = path.replace(
+ 'VERSION', info['versions'])
+
+ pluginInfo['display'] = self.checkDisplayIndex(
+ info['name'], pluginInfo['versions'])
+
pluginInfo['setup'] = os.path.exists(pluginInfo['install_checks'])
- pluginInfo['status'] = os.path.exists(pluginInfo['install_checks'])
+ # pluginInfo['status'] = os.path.exists(pluginInfo['install_checks'])
return pluginInfo
+ def makeCoexist(self, data):
+ plugins_info = []
+ for index in range(len(data['versions'])):
+ tmp = data.copy()
+ tmp['title'] = tmp['title'] + \
+ '-' + data['versions'][index]
+ tmp['versions'] = data['versions'][index]
+ pg = self.getPluginInfo(tmp)
+ plugins_info.append(pg)
+
+ return plugins_info
+
+ def makeList(self, data, sType):
+ plugins_info = []
+
+ if (data['pid'] == sType):
+ if type(data['versions']) == list and data.has_key('coexist') and data['coexist']:
+ tmp_data = self.makeCoexist(data)
+ for index in range(len(tmp_data)):
+ plugins_info.append(tmp_data[index])
+ else:
+ pg = self.getPluginInfo(data)
+ plugins_info.append(pg)
+ pass
+ return plugins_info
+
+ if sType == '0':
+ if type(data['versions']) == list and data.has_key('coexist') and data['coexist']:
+ tmp_data = self.makeCoexist(data)
+ for index in range(len(tmp_data)):
+ plugins_info.append(tmp_data[index])
+ else:
+ pg = self.getPluginInfo(data)
+ plugins_info.append(pg)
+
+ return plugins_info
+
def getAllList(self, sType='0'):
ret = {}
ret['type'] = json.loads(public.readFile(self.__type))
@@ -111,37 +190,18 @@ class plugin_api:
for dirinfo in os.listdir(self.__plugin_dir):
if dirinfo[0:1] == '.':
continue
-
path = self.__plugin_dir + '/' + dirinfo
-
if os.path.isdir(path):
json_file = path + '/info.json'
if os.path.exists(json_file):
try:
data = json.loads(public.readFile(json_file))
- if type(data['versions']) == list and data['name'] == 'php':
- for index in range(len(data['versions'])):
- tmp = data.copy()
- tmp['title'] = tmp['title'] + \
- '-' + data['versions'][index]
- tmp['versions'] = data['versions'][index]
- pg = self.getPluginInfo(tmp)
- if sType == '0':
- plugins_info.append(pg)
- else:
- if pg['pid'] == sType:
- plugins_info.append(pg)
- else:
- pg = self.getPluginInfo(data)
- if sType == '0':
- plugins_info.append(pg)
- else:
- if pg['pid'] == sType:
- plugins_info.append(pg)
+ tmp_data = self.makeList(data, sType)
+ for index in range(len(tmp_data)):
+ plugins_info.append(tmp_data[index])
except Exception, e:
print e
# pass
-
return plugins_info
def getPluginList(self, sType, sPage=1, sPageSize=15):
@@ -158,7 +218,32 @@ class plugin_api:
return ret
def addIndex(self, name, version):
- pass
+ if not os.path.exists(self.__index):
+ public.writeFile(self.__index, '[]')
+
+ indexList = json.loads(public.readFile(self.__index))
+ vname = name + '-' + version
+
+ if vname in indexList:
+ return public.returnJson(False, '请不要重复添加!')
+ if len(indexList) >= 12:
+ return public.returnJson(False, '首页最多只能显示12个软件!')
+
+ indexList.append(vname)
+ public.writeFile(self.__index, json.dumps(indexList))
+ return public.returnJson(True, '添加成功!')
+
+ def removeIndex(self, name, version):
+ if not os.path.exists(self.__index):
+ public.writeFile(self.__index, '[]')
+
+ indexList = json.loads(public.readFile(self.__index))
+ vname = name + '-' + version
+ if not vname in indexList:
+ return public.returnJson(True, '删除成功!')
+ indexList.remove(vname)
+ public.writeFile(self.__index, json.dumps(indexList))
+ return public.returnJson(True, '删除成功!')
def run(self):
pass
diff --git a/data/json/index.json b/data/json/index.json
new file mode 100644
index 000000000..5a6978861
--- /dev/null
+++ b/data/json/index.json
@@ -0,0 +1 @@
+["php-72", "php-56", "memcached-1.5"]
\ No newline at end of file
diff --git a/plugins/openresty/info.json b/plugins/openresty/info.json
index 29e7de511..eb376c4f2 100755
--- a/plugins/openresty/info.json
+++ b/plugins/openresty/info.json
@@ -1,5 +1,5 @@
{
- "title":"openresty",
+ "title":"OpenResty",
"tip":"soft",
"name":"openresty",
"type":"其他插件",
@@ -10,6 +10,6 @@
"home":"http://openresty.org",
"date":"2017-11-24",
"pid": "1",
- "versions": ["1.13.6"],
- "updates": ["1.13.6.2"]
+ "versions": ["1.11.2", "1.13.6"],
+ "updates": ["1.11.2.5", "1.13.6.2"]
}
\ No newline at end of file
diff --git a/plugins/openresty/versions/install.sh b/plugins/openresty/versions/install.sh
new file mode 100755
index 000000000..11896308a
--- /dev/null
+++ b/plugins/openresty/versions/install.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
+export PATH
+
+curPath=`pwd`
+rootPath=$(dirname "$curPath")
+rootPath=$(dirname "$rootPath")
+serverPath=$(dirname "$rootPath")
+
+install_tmp=${rootPath}/tmp/bt_install.pl
+
+openrestyDir=${serverPath}/source/openresty
+
+Install_openresty()
+{
+ mkdir -p ${openrestyDir}
+ echo '正在安装脚本文件...' > $install_tmp
+
+ if [ ! -f ${openrestyDir}/openresty-1.13.6.2.tar.gz ];then
+ wget -O ${openrestyDir}/openresty-1.13.6.2.tar.gz https://openresty.org/download/openresty-1.13.6.2.tar.gz
+ fi
+ cd ${openrestyDir} && tar -zxvf openresty-1.13.6.2.tar.gz
+
+ cd ${openrestyDir}/openresty* && ./configure --prefix=$serverPath/openresty \
+ --with-openssl=$serverPath/source/lib/openssl-1.0.2q && make && make install
+
+ echo '安装完成' > $install_tmp
+}
+
+Uninstall_openresty()
+{
+ rm -rf $serverPath/openresty
+ echo '卸载完成' > $install_tmp
+}
+
+action=$1
+host=$2
+if [ "${1}" == 'install' ];then
+ Install_openresty
+else
+ Uninstall_openresty
+fi
diff --git a/plugins/php/info.json b/plugins/php/info.json
index 01ec9f20a..54b3b4045 100755
--- a/plugins/php/info.json
+++ b/plugins/php/info.json
@@ -4,11 +4,12 @@
"shell": "install.sh",
"name": "php",
"title": "PHP",
- "default": false,
+ "coexist": true,
"versions": ["52","56","72"],
"updates": ["5.2.17","5.6.36","7.2.0"],
"tip": "soft",
"checks": "server/php/VERSION/bin/php",
+ "path": "server/php/VERSION",
"display": 1,
"author": "Zend",
"date": "2017-04-01",
diff --git a/plugins/redis/js/redis.js b/plugins/redis/js/redis.js
index eedb5c495..27fb2cf7f 100755
--- a/plugins/redis/js/redis.js
+++ b/plugins/redis/js/redis.js
@@ -151,9 +151,9 @@ function redisStatus() {
uptime_in_days | ' + rdata.uptime_in_days + ' | 已运行天数 |
\
tcp_port | ' + rdata.tcp_port + ' | 当前监听端口 |
\
connected_clients | ' + rdata.connected_clients + ' | 连接的客户端数量 |
\
- used_memory_rss | ' + ToSize(rdata.used_memory_rss) + ' | Redis当前占用的系统内存总量 |
\
- used_memory | ' + ToSize(rdata.used_memory) + ' | Redis当前已分配的内存总量 |
\
- used_memory_peak | ' + ToSize(rdata.used_memory_peak) + ' | Redis历史分配内存的峰值 |
\
+ used_memory_rss | ' + toSize(rdata.used_memory_rss) + ' | Redis当前占用的系统内存总量 |
\
+ used_memory | ' + toSize(rdata.used_memory) + ' | Redis当前已分配的内存总量 |
\
+ used_memory_peak | ' + toSize(rdata.used_memory_peak) + ' | Redis历史分配内存的峰值 |
\
mem_fragmentation_ratio | ' + rdata.mem_fragmentation_ratio + '% | 内存碎片比率 |
\
total_connections_received | ' + rdata.total_connections_received + ' | 运行以来连接过的客户端的总数量 |
\
total_commands_processed | ' + rdata.total_commands_processed + ' | 运行以来执行过的命令的总数量 |
\
diff --git a/plugins/score/info.json b/plugins/score/info.json
index 2c0600eab..25db28b12 100755
--- a/plugins/score/info.json
+++ b/plugins/score/info.json
@@ -4,7 +4,7 @@
"name":"score",
"type":"扩展",
"ps":"测试服务器基础性能!",
- "versions":"1.3",
+ "versions": "1.3",
"shell":"install.sh",
"checks":"server/score",
"author":"mdserver-web",
diff --git a/route/plugins.py b/route/plugins.py
index 92b85c50a..b1e1bfb98 100644
--- a/route/plugins.py
+++ b/route/plugins.py
@@ -141,11 +141,14 @@ def checkInstalled():
return "False"
-@plugins.route('/add_index', methods=['GET'])
-def addIndex():
- name = request.args.get('name', '')
- html = __plugin_name + '/' + name + '/index.html'
- return public.readFile(html)
+@plugins.route('/set_index', methods=['POST'])
+def setIndex():
+ name = request.form.get('name', '')
+ status = request.form.get('status', '0')
+ version = request.form.get('version', '')
+ if status == '1':
+ return plugin_api.plugin_api().addIndex(name, version)
+ return plugin_api.plugin_api().removeIndex(name, version)
@plugins.route('/setting', methods=['GET'])
diff --git a/static/js/soft.js b/static/js/soft.js
index 33ad863b1..f20ac8f5b 100755
--- a/static/js/soft.js
+++ b/static/js/soft.js
@@ -1,5 +1,5 @@
//转换单们到MB
-function ToSizeM(byteLen) {
+function toSizeM(byteLen) {
var a = parseInt(byteLen) / 1024 / 1024;
return a || 0;
}
@@ -65,17 +65,6 @@ function pluginMan(name, title) {
});
}
-
-//设置插件
-function SetPluginConfig(name, param, def) {
- if (def == undefined) def = 'SetConfig';
- loadT = layer.msg(lan.config.config_save, { icon: 16, time: 0, shade: [0.3, '#000'] });
- $.post('/plugin?action=a&name=' + name + '&s=' + def, param, function(rdata) {
- layer.close(loadT);
- layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
- });
-}
-
//取软件列表
function GetSList(isdisplay) {
if (isdisplay !== true) {
@@ -134,8 +123,6 @@ function GetSList(isdisplay) {
var checked = '';
checked = plugin.display ? 'checked' : '';
-
- console.log(plugin.versions);
if (typeof plugin.versions == "string"){
version_info += plugin.versions + '|';
@@ -148,44 +135,42 @@ function GetSList(isdisplay) {
version_info = version_info.substring(0, version_info.length - 1);
}
- console.log(version_info);
-
var handle = '安装';
- var isSetup = false;
- for (var n = 0; n < len; n++) {
+
+
+ if (plugin.setup == true) {
+ // if (plugin.tip == 'lib') {
+ // var mupdate = (plugin.versions[n].no == plugin.versions[n].version) ? '' : '更新 | ';
+ // handle = mupdate + '' + lan.soft.setup + ' | 卸载';
+ // titleClick = 'onclick="PluginMan(\'' + plugin.name + '\',\'' + plugin.title + '\')" style="cursor:pointer"';
+ // } else {
+
+ var mupdate = '';//(plugin.versions[n] == plugin.updates[n]) '' : '更新 | ';
+ // if (plugin.versions[n] == '') mupdate = '';
+ handle = mupdate + '' + lan.soft.setup + ' | 卸载';
+ titleClick = 'onclick="SoftMan(\'' + plugin.name + '\',\'' + version_info + '\')" style="cursor:pointer"';
+ // }
+
+ softPath = '';
+ indexshow = '';
if (plugin.status == true) {
- isSetup = true;
- // if (plugin.tip == 'lib') {
- // var mupdate = (plugin.versions[n].no == plugin.versions[n].version) ? '' : '更新 | ';
- // handle = mupdate + '' + lan.soft.setup + ' | 卸载';
- // titleClick = 'onclick="PluginMan(\'' + plugin.name + '\',\'' + plugin.title + '\')" style="cursor:pointer"';
- // } else {
-
- var mupdate = '';//(plugin.versions[n] == plugin.updates[n]) '' : '更新 | ';
- if (plugin.versions[n] == '') mupdate = '';
- handle = mupdate + '' + lan.soft.setup + ' | 卸载';
- titleClick = 'onclick="SoftMan(\'' + plugin.name + '\',\'' + version_info + '\')" style="cursor:pointer"';
- // }
-
- version = plugin.version;
- softPath = '';
- indexshow = '';
- if (rdata.data[i].versions[n].run == true) {
- state = ''
- } else {
- state = ''
- }
- }
- var isTask = plugin.task;
- if (plugin.task == '-1') {
- handle = '正在安装...';
- } else if (isTask == '0') {
- handle = '等待安装...';
+ state = ''
+ } else {
+ state = ''
}
}
- var plugin_title = plugin.title
- if (isSetup){
+ var isTask = plugin.task;
+ if (plugin.task == '-2') {
+ handle = '正在卸载...';
+ } else if (plugin.task == '-1') {
+ handle = '正在安装...';
+ } else if (isTask == '0') {
+ handle = '等待中...';
+ }
+
+ var plugin_title = plugin.title;
+ if (plugin.setup && !plugin.coexist){
plugin_title = plugin.title + ' ' + version_info;
}
@@ -238,127 +223,32 @@ function softUpdate(name, version, update) {
}, msg);
}
-//独立安装
-function oneInstall(name, version) {
- var isError = false
-
- var optw = '';
- if (name == 'mysql') {
- optw = "
" + lan.soft.mysql_f + ""
- var sUrl = '/data?action=getData&table=databases';
- $.ajax({
- url: sUrl,
- type: "GET",
- async: false,
- success: function(dataD) {
- if (dataD.data.length > 0) {
- layer.msg(lan.soft.mysql_d, { icon: 5, time: 5000 })
- isError = true;;
- }
- }
- });
- }
-
- if (isError) return;
- var one = layer.open({
- type: 1,
- title: '选择安装方式',
- area: '350px',
- closeBtn: 2,
- shadeClose: true,
- content: ""
- })
- $('.fangshi input').click(function() {
- $(this).attr('checked', 'checked').parent().siblings().find("input").removeAttr('checked');
- });
- $("#bi-btn").click(function() {
- var type = $('.fangshi input').prop("checked") ? '1' : '0';
- var data = "name=" + name + "&version=" + version + "&type=" + type;
- var loadT = layer.msg(lan.soft.add_install, { icon: 16, time: 0, shade: [0.3, '#000'] });
- $.post('/files?action=InstallSoft', data, function(rdata) {
- layer.closeAll();
- layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
- GetSList();
- })
-
- });
- $(".one-close").click(function() {
- layer.close(one);
- })
- InstallTips();
- fly("bi-btn");
-}
-
function addVersion(name, ver, type, obj, title) {
- // console.log(ver.indexOf('|'));
- var SelectVersion = '';
- // if (ver.indexOf('|') >= 0){
+
+ var option = '';
+ if (ver.indexOf('|') >= 0){
var titlename = name;
var veropt = ver.split("|");
-
+ var SelectVersion = '';
for (var i = 0; i < veropt.length; i++) {
SelectVersion += '';
}
- //} else {
- // SelectVersion = ver;
- //}
-
- if (name == 'phpmyadmin' || name == 'nginx' || name == 'apache') {
- var isError = false
- $.ajax({
- url: '/ajax?action=GetInstalled',
- type: 'get',
- async: false,
- success: function(rdata) {
- if (name == 'nginx') {
- if (rdata.webserver != name.toLowerCase() && rdata.webserver != false) {
- layer.msg(lan.soft.err_install1, { icon: 2 })
- isError = true;
- return;
- }
- }
- if (name == 'apache') {
- if (rdata.webserver != name.toLowerCase() && rdata.webserver != false) {
- layer.msg(lan.soft.err_install2, { icon: 2 })
- isError = true;
- return;
- }
- }
- if (name == 'phpmyadmin') {
- if (rdata.php.length < 1) {
- layer.msg(lan.soft.err_install3, { icon: 2 })
- isError = true;
- return;
- }
- if (!rdata.mysql.setup) {
- layer.msg(lan.soft.err_install4, { icon: 2 })
- isError = true;
- return;
- }
-
- }
- }
- });
- if (isError) return;
+ option = "";
+ } else {
+ option = '' + name + ' ' + ver + '';
}
layer.open({
type: 1,
- title: titlename + lan.soft.install_title,
+ title: titlename + "软件安装",
area: '350px',
closeBtn: 2,
shadeClose: true,
content: ""
});
@@ -367,7 +257,11 @@ function addVersion(name, ver, type, obj, title) {
$(this).attr('checked', 'checked').parent().siblings().find("input").removeAttr('checked');
});
$("#bi-btn").click(function() {
+
var info = $("#SelectVersion").val().toLowerCase();
+ if (info == ''){
+ info = $("#SelectVersion").text().toLowerCase();
+ }
var name = info.split(" ")[0];
var version = info.split(" ")[1];
var type = $('.fangshi input').prop("checked") ? '1' : '0';
@@ -384,10 +278,8 @@ function addVersion(name, ver, type, obj, title) {
fly("bi-btn");
}
-
-
//卸载软件
-function UninstallVersion(name, version, title) {
+function uninstallVersion(name, version, title) {
layer.confirm(msgTpl('您真的要卸载[{1}-{2}]吗?', [title, version]), { icon: 3, closeBtn: 2 }, function() {
var data = 'name=' + name + '&version=' + version;
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
@@ -407,8 +299,10 @@ function toIndexDisplay(name, version) {
var verinfo = version.replace(/\./, "");
status = $("#index_" + name + verinfo).prop("checked") ? "0" : "1";
}
+
+
var data = "name=" + name + "&status=" + status + "&version=" + version;
- $.post("/plugins/set_plugin_status", data, function(rdata) {
+ $.post("/plugins/set_index", data, function(rdata) {
if (rdata.status) {
layer.msg(rdata.msg, { icon: 1 })
}