-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.php
118 lines (108 loc) · 2.92 KB
/
update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* 检查版本更新
**/
include("../includes/common.php");
$title='检查版本更新';
include './head.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
adminpermission('super', 1);
//函数
function zipExtract ($src, $dest)
{
$zip = new ZipArchive();
if ($zip->open($src)===true)
{
$zip->extractTo($dest);
$zip->close();
return true;
}
return false;
}
function deldir($dir) {
if(!is_dir($dir))return false;
$dh=opendir($dir);
while ($file=readdir($dh)) {
if($file!="." && $file!="..") {
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)) {
unlink($fullpath);
} else {
deldir($fullpath);
}
}
}
closedir($dh);
if(rmdir($dir)) {
return true;
} else {
return false;
}
}
$scriptpath=str_replace('\\','/',$_SERVER['SCRIPT_NAME']);
$scriptpath = substr($scriptpath, 0, strrpos($scriptpath, '/'));
$admin_path = substr($scriptpath, strrpos($scriptpath, '/')+1);
?>
<div class="col-xs-12 col-sm-10 col-lg-8 center-block" style="float: none;">
<div class="block">
<div class="block-title"><h3 class="panel-title">检查更新</h3></div>
<div class="">
<?php
$act = isset($_GET['act']) ? $_GET['act'] : null;
switch ($act) {
default:
$res=update_version();
if(!$res['msg'])$res['msg']='啊哦,更新服务器开小差了,请刷新此页面。';
echo '<div class="alert alert-info">'.$res['msg'].'</div>';
echo '<hr/>';
if($res['code']==1) {
if(!class_exists('ZipArchive',false) || defined("SAE_ACCESSKEY") || defined("BAE_ENV_APPID")) {
echo '您的空间不支持自动更新,请手动下载更新包并覆盖到程序根目录!<br/>
更新包下载:<a href="'.$res['file'].'" class="btn btn-primary">点击下载</a>';
} else {
echo '<a href="update.php?act=do" class="btn btn-primary btn-block">立即更新到最新版本</a>';
}
echo '<hr/><div class="well">'.$res['uplog'].'</div>';
}
break;
case 'do':
$res=update_version();
$RemoteFile = $res['file'];
$ZipFile = "Archive.zip";
copy($RemoteFile,$ZipFile) or die("无法下载更新包文件!".'<a href="update.php">返回上级</a>');
if (zipExtract($ZipFile,ROOT)) {
if($admin_path!='admin' && is_dir(ROOT.'admin')){ //修改后台地址
deldir(ROOT.$admin_path);
rename(ROOT.'admin',ROOT.$admin_path);
}
if(function_exists("opcache_reset"))@opcache_reset();
if(!empty($res['sql'])){
$sql=$res['sql'];
$t=0; $e=0; $error='';
for($i=0;$i<count($sql);$i++) {
if (trim($sql[$i])=='')continue;
if($DB->exec($sql[$i])!==false) {
++$t;
} else {
++$e;
$error.=$DB->error().'<br/>';
}
}
$addstr='<br/>数据库更新成功。SQL成功'.$t.'句/失败'.$e.'句';
}
echo "程序更新成功!".$addstr."<br>";
echo '<a href="./">返回首页</a>';
unlink($ZipFile);
}
else {
echo "无法解压文件!<br>";
echo '<a href="update.php">返回上级</a>';
if (file_exists($ZipFile))
unlink($ZipFile);
}
break;
}
echo '</div></div>';
?>
</div>
</div>