pull/109/head
Mr Chen 7 years ago
parent 48a425327c
commit 0bfd386e3f
  1. 15
      class/core/public.py
  2. 32
      class/core/system_api.py
  3. 31
      scripts/download.py
  4. 11
      scripts/download.sh
  5. 64
      static/js/index.js
  6. 19
      task.py

@ -463,6 +463,21 @@ def isRestart():
return True
def isUpdateLocalSoft():
num = M('tasks').where('status!=?', ('1',)).count()
if num == 0:
return True
data = M('tasks').where('status!=?', ('1',)).field(
'id,type,execstr').limit('1').select()
argv = data[0]['execstr'].split('|dl|')
if data[0]['type'] == 'download' and argv[1] == 'mdserver-web.zip':
return True
return False
def hasPwd(password):
# 加密密码字符
import crypt

@ -547,11 +547,21 @@ class system_api:
except Exception as e:
print e
return {}
# 更新服务
def updateServer(self, stype, version=''):
# 更新服务
try:
if public.isUpdateLocalSoft():
if stype == 'update_status':
data = public.readFile('tmp/panelExec.log')
if data == 'done':
return public.returnJson(True, '进度!', 100)
else:
_data = json.loads(data)
return public.returnJson(True, '进度!', _data['pre'])
if not public.isRestart():
return public.returnJson(False, '请等待所有安装任务完成再执行!')
if stype == 'check':
@ -563,9 +573,9 @@ class system_api:
diff = self.versionDiff(
version_now, version_new_info['version'])
if diff == 'new':
return public.returnJson(True, '有新版本!')
return public.returnJson(True, '有新版本!', version_new_info['version'])
elif diff == 'test':
return public.returnJson(True, '有测试版本!')
return public.returnJson(True, '有测试版本!', version_new_info['version'])
else:
return public.returnJson(False, '已经是最新,无需更新!')
@ -590,15 +600,13 @@ class system_api:
if not 'path' in v_new_info or v_new_info['path'] == '':
return public.returnJson(False, '下载地址不存在!')
public.downloadFile(
v_new_info['path'], 'mdserver-web.zip')
public.execShell(
'unzip -o mdserver-web.zip -d ' + os.getcwd() + '/')
execstr = v_new_info['path'] + '|dl|mdserver-web.zip'
taskAdd = (None, '下载[mdserver-web-' + v_new_info['version'] + ']',
'download', '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr)
public.execShell('rm -rf mdserver-web.zip')
public.execShell('sh restart.sh')
print v_new_info
public.M('tasks').add(
'id,name,type,status,addtime, execstr', taskAdd)
return public.returnJson(True, '下载中...')
return public.returnJson(False, '已经是最新,无需更新!')
except Exception as ex:

@ -0,0 +1,31 @@
# coding: utf-8
import sys
import json
def downloadFile(url, filename):
import urllib
urllib.urlretrieve(url, filename=filename, reporthook=downloadHook)
def downloadHook(count, blockSize, totalSize):
speed = {'total': totalSize, 'block': blockSize, 'count': count}
print speed
print '%02d%%' % (100.0 * count * blockSize / totalSize)
writeFile('/tmp/mdserver-web.log', json.dumps(speed))
def writeFile(filename, str):
# 写文件内容
try:
fp = open(filename, 'w+')
fp.write(str)
fp.close()
return True
except:
return False
if __name__ == "__main__":
url = sys.argv[1]
downloadFile(url, 'mdserver-web.zip')

@ -0,0 +1,11 @@
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
curPath=`pwd`
rootPath=$(dirname "$curPath")
echo $1
echo $rootPath
curl -o $curPath/mdserver-web.zip $1

@ -463,25 +463,27 @@ function setImg() {
setImg();
// 检查更新
// setTimeout(function() {
// $.get('/system/update_panel', function(rdata) {
// if (rdata.status == false) return;
// if (rdata.version != undefined) {
// $("#toUpdate").html('<a class="btlink" href="javascript:updateMsg();">' + lan.index.update_go + '</a>');
// return;
// }
setTimeout(function() {
$.get('/system/update_server?type=check', function(rdata) {
if (rdata.status == false) return;
if (rdata.data != undefined) {
$("#toUpdate").html('<a class="btlink" href="javascript:updateMsg();">更新</a>');
$('#toUpdate a').html('更新<i style="display: inline-block; color: red; font-size: 40px;position: absolute;top: -35px; font-style: normal; right: -8px;">.</i>');
$('#toUpdate a').css("position","relative");
return;
}
// $.get('/system?action=ReWeb', function() {});
// layer.msg(rdata.msg, { icon: 1 });
// setTimeout(function() {
// window.location.reload();
// }, 3000);
// }).error(function() {
},'json').error(function() {
// $.get('/system?action=ReWeb', function() {});
// setTimeout(function() {
// window.location.reload();
// }, 3000);
// },'json');
// }, 3000);
});
}, 3000);
//检查更新
@ -542,20 +544,56 @@ function updateVersion(version) {
$("#toUpdate").html('');
}
updateStatus();
// layer.msg(lan.index.update_ok, { icon: 1 });
// $.get('/system?action=ReWeb', function() {});
// setTimeout(function() {
// window.location.reload();
// }, 3000);
}).error(function() {
layer.msg(lan.index.update_ok, { icon: 1 });
// $.get('/system?action=ReWeb', function() {});
},'json').error(function() {
layer.msg('更新失败,请重试!', { icon: 2 });
setTimeout(function() {
window.location.reload();
}, 3000);
});
}
function updateStatus(){
layer.open({
type:1,
title:'<span class="badge badge-inverse">软件下载中...</span>',
area: '400px',
shadeClose:false,
closeBtn:2,
content:'<div class="setchmod bt-form pd20 pb70">'
+'<div class="progress"><div id="up_download_progress" class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 40%;"><span class="sr-only">40% 完成</span></div></div>'
// +'<p style="padding: 0 0 10px;line-height: 24px;">1231231</p>'
+'<div class="bt-form-submit-btn">'
+'<button type="button" class="btn btn-danger btn-sm btn-title" onclick="layer.closeAll()">取消</button>'
+'<button type="button" class="btn btn-success btn-sm btn-title" onclick="updateVersion()" >确认</button>'
+'</div>'
+'</div>'
});
var t = setInterval(function(){
$.get('/system/update_server?type=update_status', function(rdata) {
console.log(rdata);
$('#up_download_progress').css('width',rdata.data+"%");
if (rdata.data ==100){
clearInterval(t);
}
},'json');
},1000);
}
updateStatus();
//重启服务器
function ReBoot() {

@ -48,7 +48,7 @@ class MyBad():
return self._msg
def ExecShell(cmdstring, cwd=None, timeout=None, shell=True):
def execShell(cmdstring, cwd=None, timeout=None, shell=True):
print cmdstring
try:
global logPath
@ -71,20 +71,20 @@ def ExecShell(cmdstring, cwd=None, timeout=None, shell=True):
return None
def DownloadFile(url, filename):
def downloadFile(url, filename):
# 下载文件
try:
import urllib
import socket
socket.setdefaulttimeout(10)
urllib.urlretrieve(url, filename=filename, reporthook=DownloadHook)
urllib.urlretrieve(url, filename=filename, reporthook=downloadHook)
os.system('chown www.www ' + filename)
WriteLogs('done')
except:
WriteLogs('done')
def DownloadHook(count, blockSize, totalSize):
def downloadHook(count, blockSize, totalSize):
# 下载文件进度回调
global pre
used = count * blockSize
@ -92,6 +92,7 @@ def DownloadHook(count, blockSize, totalSize):
if pre == pre1:
return
speed = {'total': totalSize, 'used': used, 'pre': pre}
print speed
WriteLogs(json.dumps(speed))
pre = pre1
@ -128,10 +129,10 @@ def startTask():
sql.table('tasks').where("id=?", (value['id'],)).save(
'status,start', ('-1', start))
if value['type'] == 'download':
argv = value['execstr'].split('|bt|')
DownloadFile(argv[0], argv[1])
argv = value['execstr'].split('|dl|')
downloadFile(argv[0], argv[1])
elif value['type'] == 'execshell':
ExecShell(value['execstr'])
execShell(value['execstr'])
end = int(time.time())
sql.table('tasks').where("id=?", (value['id'],)).save(
'status,end', ('1', end))
@ -155,11 +156,11 @@ def mainSafe():
isCheck += 1
return True
isCheck = 0
isStart = public.ExecShell(
isStart = public.execShell(
"ps aux |grep 'python main.py'|grep -v grep|awk '{print $2}'")[0]
if not isStart:
os.system('/etc/init.d/bt start')
isStart = public.ExecShell(
isStart = public.execShell(
"ps aux |grep 'python main.py'|grep -v grep|awk '{print $2}'")[0]
public.WriteLog('守护程序', '面板服务程序启动成功 -> PID: ' + isStart)
except:

Loading…
Cancel
Save