Skip to content

Commit

Permalink
提供bz2压缩格式的解压支持
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Jun 24, 2019
1 parent 048c97e commit f4fb0da
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 17 deletions.
1 change: 1 addition & 0 deletions BTPanel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ def publicObject(toObject,defs,action=None,get = None):

if hasattr(get,'path'):
get.path = get.path.replace('//','/').replace('\\','/');
if get.path.find('..') != -1: return public.ReturnJson(False,'不安全的路径'),json_header
if get.path.find('->') != -1:
get.path = get.path.split('->')[0].strip();
not_acts = ['GetTaskSpeed','GetNetWork','check_pay_status','get_re_order_status','get_order_stat']
Expand Down
4 changes: 2 additions & 2 deletions BTPanel/static/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -3172,8 +3172,8 @@ html .menu .menu_exit:hover {
background-image: url("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=")
}

.list-list .ico-gz {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTNui8sowAAAHtSURBVFiF7Ze/T8JAFMe/1QYCRKIDIe1AYcAfLJLowL/grCbGydEJTXBw0qiLA4NxNGFlkX/A0UlJJGEBQzoAC3EzxhgTgz0HPXI9jrahxTr4TZrm3r3r+/Tdu2tPIoTAT8lso9lsrgEoAVA8jLEKoMYaMpmMGABASVVVJRKJeBJZ13UAuAawmU6nayKfKa6thEIhGIbhyQUAiUTiBsC1rusrTgA8VzAY3NU07RZARQQxcQAACAQCO8lk8l4EwdeAp4pGo7QOAGDr5/4AQPoVgFgshng8brIxQM4AXisn6PdaYwHI6gJmNo6tfewe0u+1MJcvC/ueL7dH9tF+O7kqwrl82VGQiQHYZWDiAP8ZoBC+AriV7wCudkK38w/8lQxI0ve3odFoDDuoC2MXmqzMC+003gDASnZ7uVv5PgW+A5imIHK1jicA2sUjuvtLEwk49LvLngs6e4uEVaewTHjxtk5h2XTZ+u4tmg4iQ0XYPchCK9bRPcgO2lRasW7y48WOo758m5ejjWjUYKdiwXjZFiEdPOoBboJbArBvrRXrlllg0y3ytRovEUIGO1P7MPcpfbxNQRpvdfI1MPTmxAAJhI3UeXWamkw10E/lTuX23ZH0/iImkIOWADQDAITLmIRnP/vJ3BlQZYw+H8+/AFShLMorUUd8AAAAAElFTkSuQmCC")
.list-list .ico-gz, .list-list .ico-bz2 {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTNui8sowAAAHtSURBVFiF7Ze/T8JAFMe/1QYCRKIDIe1AYcAfLJLowL/grCbGydEJTXBw0qiLA4NxNGFlkX/A0UlJJGEBQzoAC3EzxhgTgz0HPXI9jrahxTr4TZrm3r3r+/Tdu2tPIoTAT8lso9lsrgEoAVA8jLEKoMYaMpmMGABASVVVJRKJeBJZ13UAuAawmU6nayKfKa6thEIhGIbhyQUAiUTiBsC1rusrTgA8VzAY3NU07RZARQQxcQAACAQCO8lk8l4EwdeAp4pGo7QOAGDr5/4AQPoVgFgshng8brIxQM4AXisn6PdaYwHI6gJmNo6tfewe0u+1MJcvC/ueL7dH9tF+O7kqwrl82VGQiQHYZWDiAP8ZoBC+AriV7wCudkK38w/8lQxI0ve3odFoDDuoC2MXmqzMC+003gDASnZ7uVv5PgW+A5imIHK1jicA2sUjuvtLEwk49LvLngs6e4uEVaewTHjxtk5h2XTZ+u4tmg4iQ0XYPchCK9bRPcgO2lRasW7y48WOo758m5ejjWjUYKdiwXjZFiEdPOoBboJbArBvrRXrlllg0y3ytRovEUIGO1P7MPcpfbxNQRpvdfI1MPTmxAAJhI3UeXWamkw10E/lTuX23ZH0/iImkIOWADQDAITLmIRnP/vJ3BlQZYw+H8+/AFShLMorUUd8AAAAAElFTkSuQmCC")
}

.list-list .ico-bt {
Expand Down
18 changes: 13 additions & 5 deletions BTPanel/static/js/crontab.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function edit_task_info(id){
minute: rdata.where_minute,
week: rdata.where1,
sType: rdata.sType,
sBody: rdata.sBody,
sBody: rdata.sBody == 'undefined' ? '' : rdata.sBody,
sName: rdata.sName,
backupTo: rdata.backupTo,
save: rdata.save,
Expand Down Expand Up @@ -146,7 +146,7 @@ function edit_task_info(id){
layer.open({
type:1,
title:'编辑计划任务-['+rdata.name+']',
area: ['850px','450px'],
area: '850px',
skin:'layer-create-content',
shadeClose:false,
closeBtn:2,
Expand Down Expand Up @@ -213,9 +213,9 @@ function edit_task_info(id){
</div>\
</div>\
</div>\
<div class="clearfix plan ptb10" style="display:'+ (obj.from.sType == "toShell"?'block;':'none') +'">\
<div class="clearfix plan ptb10" style="display:'+ ((obj.from.sType == "toShell" || obj.from.sType == 'site' || obj.from.sType == 'path')?'block;':'none') +'">\
<span class="typename controls c4 pull-left f14 text-right mr20">脚本内容</span>\
<div style="line-height:34px"><textarea class="txtsjs bt-input-text sBody_create" name="sBody">'+ obj.from.sBody +'</textarea></div>\
<div style="line-height:22px"><textarea style="line-height:22px" class="txtsjs bt-input-text sBody_create" name="sBody">'+ obj.from.sBody +'</textarea></div>\
</div>\
<div class="clearfix plan ptb10" style="display:'+ (obj.from.sType == "rememory"?'block;':'none') +'">\
<span class="typename controls c4 pull-left f14 text-right mr20">提示</span>\
Expand Down Expand Up @@ -784,7 +784,7 @@ function toBackup(type){
<li><a role="menuitem" tabindex="-1" href="javascript:;" value="ALL">'+lan.public.all+'</a></li>\
'+sOpt+'\
</ul>\
</div>'
</div>'
}else{
$(".planname input[name='name']").val(sMsg+'[/www/wwwroot/]');
sOptBody = '<div class="info-r" style="display: inline-block;float: left;margin-right: 25px;"><input id="inputPath" class="bt-input-text mr5" type="text" name="path" value="/www/wwwroot/" placeholder="备份目录" style="width:208px;height:33px;"><span class="glyphicon glyphicon-folder-open cursor" onclick="ChangePath(&quot;inputPath&quot;)"></span></div>'
Expand Down Expand Up @@ -819,6 +819,14 @@ function toBackup(type){
<span><input type="number" name="save" id="save" value="3" maxlength="4" max="100" min="1"></span>\
<span class="name">'+lan.crontab.save_num+'</span>\
</div>';
if (sType == 'sites') {
sBody += '<p class="clearfix plan">\
<div class="textname pull-left mr20" style="margin-left: 63px; font-size: 14px;">排除目录</div>\
<div class="dropdown planBackupTo pull-left mr20">\
<span><textarea style=" height: 100px;width:300px;line-height:22px;" class="bt-input-text" type="text" name="sBody" id="exclude" placeholder="每行一条规则,目录不能以/结尾,示例:\ndata/config.php\nstatic/upload\n *.log\n"></textarea></span>\
</div>\
</p>';
}
$("#implement").html(sBody);
getselectname();
$(".dropdown ul li a").click(function(){
Expand Down
6 changes: 3 additions & 3 deletions BTPanel/static/js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ function BatchPasteTo(data,path){
}
function GetExtName(fileName){
var extArr = fileName.split(".");
var exts = ['folder','folder-unempty','sql','c','cpp','cs','flv','css','js','htm','html','java','log','mht','php','url','xml','ai','bmp','cdr','gif','ico','jpeg','jpg','JPG','png','psd','webp','ape','avi','flv','mkv','mov','mp3','mp4','mpeg','mpg','rm','rmvb','swf','wav','webm','wma','wmv','rtf','docx','fdf','potm','pptx','txt','xlsb','xlsx','7z','cab','iso','rar','zip','gz','bt','file','apk','bookfolder','folder','folder-empty','folder-unempty','fromchromefolder','documentfolder','fromphonefolder','mix','musicfolder','picturefolder','videofolder','sefolder','access','mdb','accdb','sql','c','cpp','cs','js','fla','flv','htm','html','java','log','mht','php','url','xml','ai','bmp','cdr','gif','ico','jpeg','jpg','JPG','png','psd','webp','ape','avi','flv','mkv','mov','mp3','mp4','mpeg','mpg','rm','rmvb','swf','wav','webm','wma','wmv','doc','docm','dotx','dotm','dot','rtf','docx','pdf','fdf','ppt','pptm','pot','potm','pptx','txt','xls','csv','xlsm','xlsb','xlsx','7z','gz','cab','iso','rar','zip','bt','file','apk','css'];
var exts = ['folder','folder-unempty','sql','c','cpp','cs','flv','css','js','htm','html','java','log','mht','php','url','xml','ai','bmp','cdr','gif','ico','jpeg','jpg','JPG','png','psd','webp','ape','avi','flv','mkv','mov','mp3','mp4','mpeg','mpg','rm','rmvb','swf','wav','webm','wma','wmv','rtf','docx','fdf','potm','pptx','txt','xlsb','xlsx','7z','cab','iso','bz2','rar','zip','gz','bt','file','apk','bookfolder','folder','folder-empty','folder-unempty','fromchromefolder','documentfolder','fromphonefolder','mix','musicfolder','picturefolder','videofolder','sefolder','access','mdb','accdb','sql','c','cpp','cs','js','fla','flv','htm','html','java','log','mht','php','url','xml','ai','bmp','cdr','gif','ico','jpeg','jpg','JPG','png','psd','webp','ape','avi','flv','mkv','mov','mp3','mp4','mpeg','mpg','rm','rmvb','swf','wav','webm','wma','wmv','doc','docm','dotx','dotm','dot','rtf','docx','pdf','fdf','ppt','pptm','pot','potm','pptx','txt','xls','csv','xlsm','xlsb','xlsx','7z','gz','cab','iso','rar','zip','bt','file','apk','css'];
var extLastName = extArr[extArr.length - 1];
for(var i=0; i<exts.length; i++){
if(exts[i]==extLastName){
Expand Down Expand Up @@ -1340,11 +1340,11 @@ function isZip(fileName){
var ext = fileName.split('.');
var extName = ext[ext.length-1].toLowerCase();
if (extName == 'zip' || extName == 'war' || extName == 'rar') return 0;
if( extName == 'gz' || extName == 'tgz') return 1;
if( extName == 'gz' || extName == 'tgz' || extName == 'bz2') return 1;
return -1;
}
function isText(fileName){
var exts = ['rar','war','zip','tar.gz','gz','iso','xsl','doc','xdoc','jpeg','jpg','png','gif','bmp','tiff','exe','so','7z','bz'];
var exts = ['rar','war','zip','tar.gz','gz','iso','xsl','doc','xdoc','jpeg','jpg','png','gif','bmp','tiff','exe','so','7z','bz','bz2'];
return isExts(fileName,exts)?false:true;
}
function isImage(fileName){
Expand Down
4 changes: 3 additions & 1 deletion class/crontab.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ def GetShell(self,param):
log='-access_log'
if public.get_webserver()=='nginx':
log='.log'

if type in ['site','path'] and param['sBody'] != 'undefined' and len(param['sBody']) > 1:
exports = param['sBody'].replace("\r\n","\n").replace("\n",",")
head += "BT_EXCLUDE=\"" + exports.strip() + "\"\nexport BT_EXCLUDE\n"
wheres={
'path': head + "python " + public.GetConfigValue('setup_path')+"/panel/script/backup.py path "+param['sName']+" "+str(param['save']),
'site' : head + "python " + public.GetConfigValue('setup_path')+"/panel/script/backup.py site "+param['sName']+" "+str(param['save']),
Expand Down
2 changes: 2 additions & 0 deletions class/panelTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ def _unzip(self,sfile,dfile,password,log_file):
os.system('echo "'+password+'"|' + rar_file + ' x -u -y "' + sfile + '" "' + dfile + '" &> ' + log_file)
elif sfile[-4:] == '.war':
os.system("unzip -P '"+password+"' -o '" + sfile + "' -d '" + dfile + "' &> " + log_file)
elif sfile[-4:] == '.bz2':
os.system("tar jxvf '" + sfile + "' -C '" + dfile + "' &> " + log_file)
else:
os.system("gunzip -c " + sfile + " > " + sfile[:-3])

Expand Down
4 changes: 3 additions & 1 deletion runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from BTPanel import app,socketio,sys

if __name__ == '__main__':
PORT = 8888
f = open('data/port.pl')
PORT = int(f.read())
HOST = '0.0.0.0'
f.close()
socketio.run(app,host=HOST,port=PORT)
22 changes: 17 additions & 5 deletions script/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import public,db,time

class backupTools:

__exclude = ""

def __init__(self):
self.get_exclode()

def backupSite(self,name,count):
sql = db.Sql();
path = sql.table('sites').where('name=?',(name,)).getField('path');
Expand All @@ -27,9 +31,8 @@ def backupSite(self,name,count):

backup_path = sql.table('config').where("id=?",(1,)).getField('backup_path') + '/site';
if not os.path.exists(backup_path): public.ExecShell("mkdir -p " + backup_path);

filename= backup_path + "/Web_" + name + "_" + time.strftime('%Y%m%d_%H%M%S',time.localtime()) + '.tar.gz'
public.ExecShell("cd " + os.path.dirname(path) + " && tar zcvf '" + filename + "' '" + os.path.basename(path) + "' > /dev/null")
public.ExecShell("cd " + os.path.dirname(path) + " && tar zcvf '" + filename + "' '" + os.path.basename(path) + "'"+self.__exclude +" > /dev/null")


endDate = time.strftime('%Y/%m/%d %X',time.localtime())
Expand All @@ -48,6 +51,7 @@ def backupSite(self,name,count):
print(u"★["+endDate+"] " + log)
print(u"|---保留最新的["+count+u"]份备份")
print(u"|---文件名:"+filename)
if self.__exclude: print(u"|---排除规则: " + self.__exclude)

#清理多余备份
backups = sql.table('backup').where('type=? and pid=? and filename!=? and filename!=? and filename!=? and filename!=? and filename!=?',('0',pid,'alioss','txcos','upyun','qiniu','ftp')).field('id,filename').select();
Expand Down Expand Up @@ -134,7 +138,7 @@ def backupPath(self,path,count):
backup_path = sql.table('config').where("id=?",(1,)).getField('backup_path') + '/path';
if not os.path.exists(backup_path): os.makedirs(backup_path);
filename= backup_path + "/Path_" + name + "_" + time.strftime('%Y%m%d_%H%M%S',time.localtime()) + '.tar.gz'
os.system("cd " + os.path.dirname(path) + " && tar zcvf '" + filename + "' '" + os.path.basename(path) + "' > /dev/null")
os.system("cd " + os.path.dirname(path) + " && tar zcvf '" + filename + "' '" + os.path.basename(path) + "'" + self.__exclude + " > /dev/null")

endDate = time.strftime('%Y/%m/%d %X',time.localtime())
if not os.path.exists(filename):
Expand All @@ -150,6 +154,7 @@ def backupPath(self,path,count):
print(u"★["+endDate+"] " + log)
print(u"|---保留最新的["+count+u"]份备份")
print(u"|---文件名:"+filename)
if self.__exclude: print(u"|---排除规则: " + self.__exclude)

#清理多余备份
backups = sql.table('backup').where('type=? and pid=? and name=?',('2',0,path)).field('id,filename').select();
Expand All @@ -174,7 +179,14 @@ def backupDatabaseAll(self,save):
for database in databases:
self.backupDatabase(database['name'],save)


def get_exclode(self):
tmp_exclude = os.getenv('BT_EXCLUDE')
if not tmp_exclude: return ""
for ex in tmp_exclude.split(','):
self.__exclude += " --exclude=\"" + ex + "\""
self.__exclude += " "
return self.__exclude



if __name__ == "__main__":
Expand Down

0 comments on commit f4fb0da

Please sign in to comment.