Skip to content

Commit

Permalink
一键部署自定义项目提供更新功能
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Jun 26, 2019
1 parent 087ff05 commit 5b9f63c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 16 deletions.
8 changes: 4 additions & 4 deletions BTPanel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def deployment(pdata = None):
if comReturn: return comReturn
import plugin_deployment
sysObject = plugin_deployment.plugin_deployment()
defs = ('GetList','AddPackage','DelPackage','SetupPackage','GetSpeed')
defs = ('GetList','AddPackage','DelPackage','SetupPackage','GetSpeed','GetPackageOther')
return publicObject(sysObject,defs,None,pdata);

@app.route('/data',methods=method_all)
Expand Down Expand Up @@ -536,8 +536,8 @@ def coll_socket(msg):
return;
emit('coll_response',getattr(t,msg['f'])(msg))

@app.route('/btco',methods=method_all)
@app.route('/btco/',methods=method_all)
@app.route('/coll',methods=method_all)
@app.route('/coll/',methods=method_all)
@app.route('/<name>/<fun>',methods=method_all)
@app.route('/<name>/<fun>/<path:stype>',methods=method_all)
def panel_other(name=None,fun = None,stype=None):
Expand All @@ -552,7 +552,7 @@ def panel_other(name=None,fun = None,stype=None):

#前置准备

if not name: name = 'btco'
if not name: name = 'coll'

#是否响应面板默认静态文件
if name == 'static':
Expand Down
53 changes: 50 additions & 3 deletions BTPanel/static/js/soft.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,18 @@ var soft = {
<th>简介</th>\
<th>支持PHP版本</th>\
<th>提供者</th>\
<th style="text-align: right;" width="120">操作</th>\
<th style="text-align: right;" width="150">操作</th>\
</tr>\
</thead>';
var icon_other ='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAYFJREFUeNpi/P//P8NAAhZkzrVr1zyB1FwglqSiHSZAfBZZQEtLC7sDQJZLSUlJcnNzU8Xm27dvg6jVQByqqqp6FpsaJjS+JCcnJ8O/f/+ogkFATk5uJ8gRQMcYE+MAqgN2dvYMeXn5g0DmGmyOYKJHQmNjY0tQUFA4gc0RLLS0mI+PD5YOQCACSp8BYka6OEBUVJRBXFwcW8IkPgQ+r2lk+PPsJnl5XEqdgTeknvhyABsAWS6Ytwyr3PtJUTjlYPKEAEWJEGQ5MZbQzAGEQoDmDhgNAWITGk0dQCkYcAewUJoIh38IgIpTchMai6Qa5Q4gVJYP+SgYcAcwIjfLHxZo0qWNLj/hOp4GCQs7bo0121D4D1u8wGIwGlkcd/3+k/xyANlgdMcgy8McRbM0QIoFVC8J8VkOCxVSHMdCTZ+TEyooDvjPKfCP8ddXJgZGJqISIskW/v8HtIP/H85seGdWYT3L/eN1jN8/0qR8+M8l8PePgkWzSlp/I1YHDAQACDAAtKS/DHmsv9AAAAAASUVORK5CYII='
for (var i = 0; i < rdata.list.length; i++) {
var remove_opt = '';
if (rdata.list[i].id === 0) {
remove_opt = ' | <a class="btlink" onclick="soft.remove_other_dep(\'' + rdata.list[i].name + '\')">删除</a>';
remove_opt = ' | <a class="btlink" onclick="soft.update_package(\'' + rdata.list[i].name + '\')">更新</a> | <a class="btlink" onclick="soft.remove_other_dep(\'' + rdata.list[i].name + '\')">删除</a>';
rdata.list[i].min_image = icon_other
}
zbody += '<tr>'
+ '<td><img src="'+rdata.list[i].min_image+'">' + rdata.list[i].title + '</td>'
+ '<td><img src="' + rdata.list[i].min_image +'">' + rdata.list[i].title + '</td>'
+ '<td>' + rdata.list[i].version + '</td>'
+ '<td>' + rdata.list[i].ps + '</td>'
+ '<td>' + rdata.list[i].php + '</td>'
Expand Down Expand Up @@ -427,6 +429,51 @@ var soft = {
content: con
});
},
update_package: function (p_name) {
$.post('/deployment?action=GetPackageOther', { p_name: p_name }, function (rdata) {
var con = '<form class="bt-form pd20 pb70" id="input_package">\
<div class="line"><span class="tname">英文名</span>\
<input class="bt-input-text" type="text" value="'+rdata.name+'" name="name" placeholder="项目英文名" style="width:190px" />\
<span class="c9" style="margin-left: 5px;">格式: [0-9A-Za-z_-]+,不要带有空格和特殊字符</span>\
</div>\
<div class="line"><span class="tname">中文名</span>\
<input class="bt-input-text" name="title" value="'+ rdata.title +'" placeholder="项目中文名" style="width:190px" type="text">\
<span class="c9" style="margin-left: 5px;">用于显示到列表的名称</span>\
</div>\
<div class="line"><span class="tname">PHP版本</span>\
<input class="bt-input-text mr5 " name="php" placeholder="如:53,54,55,56,70,71,72" style="width:190px" value="'+ rdata.php +'" type="text" />\
<span class="c9">多个请使用","(逗号)隔开,不要使用PHP5.2</span>\
</div>\
<div class="line"><span class="tname">解禁的函数</span>\
<input class="bt-input-text mr5" name="enable_functions" value="'+ rdata.enable_functions +'" style="width:190px" placeholder="如:system,exec" type="text" />\
<span class="c9">多个请使用","(逗号)隔开,只解禁必要函数</span>\
</div>\
<div class="line"><span class="tname">项目版本</span>\
<input class="bt-input-text mr5" name="version" value="'+ rdata.version +'" style="width:190px" placeholder="如:5.2.1" type="text" />\
<span class="c9">当前导入的项目版本</span>\
</div>\
<div class="line"><span class="tname">简介</span>\
<div class="info-r c15"><input class="bt-input-text mr5" name="ps" value="'+ rdata.ps +'" type="text" style="width:290px" /></div>\
</div>\
<div class="line"><span class="tname">上传项目包</span>\
<input class="bt-input-text mr5" name="dep_zip" type="file" style="width:290px" placeholder="如:system,exec" >\
<span class="c9">请上传zip格式的项目包,里面必需包含auto_insatll.json配置文件</span>\
</div>\
<div class="bt-form-submit-btn">\
<button type="button" class="btn btn-danger btn-sm onekeycodeclose" onclick="layer.closeAll()">取消</button>\
<button type="button" class="btn btn-success btn-sm" onclick="soft.input_package_to()">更新</button>\
</div>\
</from>';
layer.open({
type: 1,
title: "更新一键部署项目包",
area: '600px',
closeBtn: 2,
shadeClose: false,
content: con
});
});
},
input_package_to: function () {
var pdata = new FormData($("#input_package")[0]);
if (!pdata.get('name') || !pdata.get('title') || !pdata.get('version') || !pdata.get('php') || !pdata.get('ps')) {
Expand Down
2 changes: 1 addition & 1 deletion class/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def init(self):
if ua:
ua = ua.lower();
if ua.find('spider') != -1 or ua.find('bot') != -1: return redirect('https://www.baidu.com');
g.version = '6.9.23'
g.version = '6.9.24'
g.title = public.GetConfigValue('title')
g.uri = request.path
session['version'] = g.version;
Expand Down
3 changes: 2 additions & 1 deletion class/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,8 @@ def ExecShell(self,get):
def GetExecShellMsg(self,get):
fileName = '/tmp/panelShell.pl';
if not os.path.exists(fileName): return 'FILE_SHELL_EMPTY';
return public.readFile('/tmp/panelShell.pl');
status = not public.process_exists('bash',None,'/tmp/panelShell.sh')
return public.returnMsg(status,public.GetNumLines(fileName,200));

#文件搜索
def GetSearch(self,get):
Expand Down
13 changes: 12 additions & 1 deletion class/plugin_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ def AddPackage(self,get):

public.writeFile(jsonFile,json.dumps(data));
return public.returnMsg(True,'导入成功!');

#取本地包信息
def GetPackageOther(self,get):
jsonFile = self.__setupPath + '/deployment_list_other.json';
if not os.path.exists(jsonFile): public.returnMsg(False,'没有找到[%s]' % p_name)
data = json.loads(public.readFile(jsonFile));
p_name = get.p_name
for i in range(len(data)):
if data[i]['name'] == p_name: return data[i]
return public.returnMsg(False,'没有找到[%s]' % p_name)


#删除程序包
def DelPackage(self,get):
Expand Down Expand Up @@ -265,7 +276,7 @@ def SetupPackage(self,get):
self.WriteLogs(json.dumps({'name':'设置权限','total':0,'used':0,'pre':0,'speed':0}));
os.system('chmod -R 755 ' + path);
os.system('chown -R www.www ' + path);
if pinfo['chmod'] != "":
if pinfo['chmod']:
for chm in pinfo['chmod']:
os.system('chmod -R ' + str(chm['mode']) + ' ' + (path + '/' + chm['path']).replace('//','/'));

Expand Down
9 changes: 6 additions & 3 deletions class/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,18 +1078,21 @@ def get_uuid():


#进程是否存在
def process_exists(pname,exe = None):
def process_exists(pname,exe = None,cmdline = None):
try:
import psutil
pids = psutil.pids()
for pid in pids:
try:
p = psutil.Process(pid)
if p.name() == pname:
if not exe:
if not exe and not cmdline:
return True;
else:
if p.exe() == exe: return True
if exe:
if p.exe() == exe: return True
if cmdline:
if cmdline in p.cmdline(): return True
except:pass
return False
except: return True
Expand Down
8 changes: 5 additions & 3 deletions class/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,9 @@ def GetDiskInfo(self,get=None):
#取磁盘分区信息
diskIo = psutil.disk_partitions();
diskInfo = []

cuts = ['/mnt/cdrom','/boot','/boot/efi','/dev','/dev/shm','/run/lock','/run','/run/shm','/run/user'];
for disk in diskIo:
if disk[1] == '/mnt/cdrom':continue;
if disk[1] == '/boot':continue;
if not cuts: continue
tmp = {}
tmp['path'] = disk[1]
tmp['size'] = psutil.disk_usage(disk[1])
Expand Down Expand Up @@ -448,6 +447,9 @@ def GetNetWork(self,get=None):
networkInfo['cpu'] = self.GetCpuInfo()
networkInfo['load'] = self.GetLoadAverage(get);
networkInfo['mem'] = self.GetMemInfo(get)
networkInfo['version'] = session['version']
networkInfo['disk'] = self.GetDiskInfo2()


return networkInfo

Expand Down

0 comments on commit 5b9f63c

Please sign in to comment.