pull/109/head
Mr Chen 7 years ago
parent fcf7ff1b21
commit 50e0344a34
  1. 133
      class/core/plugin_api.py
  2. 1
      data/json/index.json
  3. 6
      plugins/openresty/info.json
  4. 42
      plugins/openresty/versions/install.sh
  5. 3
      plugins/php/info.json
  6. 6
      plugins/redis/js/redis.js
  7. 13
      route/plugins.py
  8. 174
      static/js/soft.js

@ -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

@ -0,0 +1 @@
["php-72", "php-56", "memcached-1.5"]

@ -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"]
}

@ -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

@ -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",

@ -151,9 +151,9 @@ function redisStatus() {
<tr><th>uptime_in_days</th><td>' + rdata.uptime_in_days + '</td><td></td></tr>\
<tr><th>tcp_port</th><td>' + rdata.tcp_port + '</td><td></td></tr>\
<tr><th>connected_clients</th><td>' + rdata.connected_clients + '</td><td></td></tr>\
<tr><th>used_memory_rss</th><td>' + ToSize(rdata.used_memory_rss) + '</td><td>Redis</td></tr>\
<tr><th>used_memory</th><td>' + ToSize(rdata.used_memory) + '</td><td>Redis</td></tr>\
<tr><th>used_memory_peak</th><td>' + ToSize(rdata.used_memory_peak) + '</td><td>Redis</td></tr>\
<tr><th>used_memory_rss</th><td>' + toSize(rdata.used_memory_rss) + '</td><td>Redis</td></tr>\
<tr><th>used_memory</th><td>' + toSize(rdata.used_memory) + '</td><td>Redis</td></tr>\
<tr><th>used_memory_peak</th><td>' + toSize(rdata.used_memory_peak) + '</td><td>Redis</td></tr>\
<tr><th>mem_fragmentation_ratio</th><td>' + rdata.mem_fragmentation_ratio + '%</td><td></td></tr>\
<tr><th>total_connections_received</th><td>' + rdata.total_connections_received + '</td><td></td></tr>\
<tr><th>total_commands_processed</th><td>' + rdata.total_commands_processed + '</td><td></td></tr>\

@ -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'])

@ -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) {
@ -135,8 +124,6 @@ function GetSList(isdisplay) {
checked = plugin.display ? 'checked' : '';
console.log(plugin.versions);
if (typeof plugin.versions == "string"){
version_info += plugin.versions + '|';
} else {
@ -148,13 +135,10 @@ function GetSList(isdisplay) {
version_info = version_info.substring(0, version_info.length - 1);
}
console.log(version_info);
var handle = '<a class="btlink" onclick="addVersion(\'' + plugin.name + '\',\'' + version_info + '\',\'' + plugin.tip + '\',this,\'' + plugin.title + '\')">安装</a>';
var isSetup = false;
for (var n = 0; n < len; n++) {
if (plugin.status == true) {
isSetup = true;
if (plugin.setup == true) {
// if (plugin.tip == 'lib') {
// var mupdate = (plugin.versions[n].no == plugin.versions[n].version) ? '' : '<a class="btlink" onclick="SoftUpdate(\'' + plugin.name + '\',\'' + plugin.versions + '\',\'' + plugin.versions[n].version + '\')">更新</a> | ';
// handle = mupdate + '<a class="btlink" onclick="PluginMan(\'' + plugin.name + '\',\'' + plugin.title + '\')">' + lan.soft.setup + '</a> | <a class="btlink" onclick="UninstallVersion(\'' + plugin.name + '\',\'' + plugin.versions + '\',\'' + plugin.title + '\')">卸载</a>';
@ -162,30 +146,31 @@ function GetSList(isdisplay) {
// } else {
var mupdate = '';//(plugin.versions[n] == plugin.updates[n]) '' : '<a class="btlink" onclick="SoftUpdate(\'' + plugin.name + '\',\'' + plugin.versions[n].version + '\',\'' + plugin.updates[n] + '\')">更新</a> | ';
if (plugin.versions[n] == '') mupdate = '';
// if (plugin.versions[n] == '') mupdate = '';
handle = mupdate + '<a class="btlink" onclick="SoftMan(\'' + plugin.name + '\',\'' + version_info + '\')">' + lan.soft.setup + '</a> | <a class="btlink" onclick="UninstallVersion(\'' + plugin.name + '\',\'' + plugin.versions + '\',\'' + plugin.title + '\')">卸载</a>';
titleClick = 'onclick="SoftMan(\'' + plugin.name + '\',\'' + version_info + '\')" style="cursor:pointer"';
// }
version = plugin.version;
softPath = '<span class="glyphicon glyphicon-folder-open" title="' + rdata.data[i].path + '" onclick="openPath(\'' + rdata.data[i].path + '\')"></span>';
indexshow = '<div class="index-item"><input class="btswitch btswitch-ios" id="index_' + rdata.data[i].name + '" type="checkbox" ' + checked + '><label class="btswitch-btn" for="index_' + plugin.name + '" onclick="toIndexDisplay(\'' + plugin.name + '\',\'' + version + '\')"></label></div>';
if (rdata.data[i].versions[n].run == true) {
softPath = '<span class="glyphicon glyphicon-folder-open" title="' + plugin.path + '" onclick="openPath(\'' + plugin.path + '\')"></span>';
indexshow = '<div class="index-item"><input class="btswitch btswitch-ios" id="index_' + plugin.name + '" type="checkbox" ' + checked + '><label class="btswitch-btn" for="index_' + plugin.name + '" onclick="toIndexDisplay(\'' + plugin.name + '\',\'' + plugin.versions + '\')"></label></div>';
if (plugin.status == true) {
state = '<span style="color:#20a53a" class="glyphicon glyphicon-play"></span>'
} else {
state = '<span style="color:red" class="glyphicon glyphicon-pause"></span>'
}
}
var isTask = plugin.task;
if (plugin.task == '-1') {
if (plugin.task == '-2') {
handle = '<a style="color:green;" href="javascript:task();">正在卸载...</a>';
} else if (plugin.task == '-1') {
handle = '<a style="color:green;" href="javascript:task();">正在安装...</a>';
} else if (isTask == '0') {
handle = '<a style="color:#C0C0C0;" href="javascript:task();">等待安装...</a>';
}
handle = '<a style="color:#C0C0C0;" href="javascript:task();">等待中...</a>';
}
var plugin_title = plugin.title
if (isSetup){
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 = "<br><br><li style='color:red;'>" + lan.soft.mysql_f + "</li>"
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: "<div class='bt-form pd20 pb70 c6'>\
<div class='version line'>安装版本<span style='margin-left:30px'>" + name + " " + version + "</span>" + optw + "</div>\
<div class='bt-form-submit-btn'>\
<button type='button' class='btn btn-danger btn-sm btn-title one-close'>关闭</button>\
<button type='button' id='bi-btn' class='btn btn-success btn-sm btn-title bi-btn'>提交</button>\
</div>\
</div>"
})
$('.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 += '<option>' + name + ' ' + veropt[i] + '</option>';
}
//} 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 = "<select id='SelectVersion' class='bt-input-text' style='margin-left:30px'>" + SelectVersion + "</select>";
} else {
option = '<span id="SelectVersion">' + name + ' ' + ver + '</span>';
}
layer.open({
type: 1,
title: titlename + lan.soft.install_title,
title: titlename + "软件安装",
area: '350px',
closeBtn: 2,
shadeClose: true,
content: "<div class='bt-form pd20 pb70 c6'>\
<div class='version line'>安装版本<select id='SelectVersion' class='bt-input-text' style='margin-left:30px'>" + SelectVersion + "</select></div>\
<div class='version line'>安装版本" + option + "</div>\
<div class='bt-form-submit-btn'>\
<button type='button' class='btn btn-danger btn-sm btn-title' onclick='layer.closeAll()'>" + lan.public.close + "</button>\
<button type='button' id='bi-btn' class='btn btn-success btn-sm btn-title bi-btn'>" + lan.public.submit + "</button>\
<button type='button' class='btn btn-danger btn-sm btn-title' onclick='layer.closeAll()'>关闭</button>\
<button type='button' id='bi-btn' class='btn btn-success btn-sm btn-title bi-btn'>提交</button>\
</div>\
</div>"
});
@ -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 })
}

Loading…
Cancel
Save