123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- namespace app\admin;
- use PclZip;
- class update extends Base
- {
- public function initialize()
- {
-
- parent::initialize();
- $this->Administrator(5);
- $this->header();
- ?><style>
- .content{
- width: 90px;
- margin: 5px auto;
- text-align: left;
- }
- </style>
- <script>
- var filesize = 0;
- function setsize(fsize) {
- filesize = fsize;
- }
- function setdown(dlen) {
- if (filesize > 0) {
- var percent = Math.round(dlen * 100 / filesize);
- document.getElementById("progressbar").style.width = (percent + "%");
- if (percent > 0) {
- document.getElementById("progressbar").innerHTML = percent + "%";
- document.getElementById("progressText").innerHTML = "";
- } else {
- document.getElementById("progressText").innerHTML = percent + "%";
- }
- if (percent > 99) {
- document.getElementById("progressbar").innerHTML = "请稍等...";
- setTimeout("location.href='?c=update&a=replace_file';", 3e3);
- }
- }
- }
- </script><div class="container">
- <script>parent.document.title = '<?php echo IN_NAME;?>管理中心 - 程序升级';if(parent.$('#admincpnav')) parent.$('#admincpnav').innerHTML='程序升级';</script>
- <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:left" href="?c=update&a=index" title="刷新">
- <i class="layui-icon" style="line-height:38px">ဂ</i></a>
- <div class="itemtitle"><ul class="tab1" style="margin-right:10px"></ul><ul class="stepstat">
- <?php
- if ($this->action == "down_file") {
- ?><li class="current"><?php
- } else {
- ?><li><?php
- }
- ?>1.下载文件</li>
- <?php
- if ($this->action == "replace_file") {
- ?><li class="current"><?php
- } else {
- ?><li><?php
- }
- ?>2.更新文件</li>
- <?php
- if ($this->action == "change_data") {
- ?><li class="current"><?php
- } else {
- ?><li><?php
- }
- ?>3.更新数据</li>
- </ul><ul class="tab1"></ul></div>
- <table class="tb tb2">
- <tr><th class="partition">技巧提示</th></tr>
- <tr><td class="tipsblock"><ul>
- <li>升级前请先关闭站点并备份数据。如遇升级失败,请检查相关函数是否开启及文件目录是否具有写入权限;</li>
- <li>更新包较大时可能会出现下载缓慢。如遇无法升级,请前往官网下载补丁并手动覆盖更新!</li>
- </ul></td></tr>
- </table>
- <h3>提示</h3><?php
- }
- public function __destruct()
- {
- ?></div><?php
- $this->footer();
- }
- function index($_var_0 = [])
- {
- if (IN_UPDATE_API) {
- ?><div class="infobox"><p class="margintop"><input type="button" class="btn" value="检测更新" onclick="location.href='?c=update&a=checkup';"></p></div><?php
- } else {
- ?><div class="infobox"><h4 class="infotitle2">未配置线上更新接口</h4></div><?php
- }
- }
- function checkup()
- {
- $_var_1 = get_headers(IN_UPDATE_API);
- if ($_var_1[0] == "HTTP/1.1 200 OK") {
- creatdir("data/tmp");
- $_var_2 = @file_get_contents(IN_UPDATE_API);
- fwrite(fopen(IN_TMP_PATH . "update.json", "w+"), $_var_2);
- $_var_2 = json_decode($_var_2, true);
- $_var_3 = trim($_var_2["data"]["grade"]);
- $_var_4 = trim($_var_2["data"]["version"]);
- $_var_5 = intval(trim($_var_2["data"]["build"]));
- $_var_6 = detect_encoding(rawurldecode(trim($_var_2["data"]["log"])));
- $_var_7 = detect_encoding(rawurldecode(trim($_var_2["data"]["shuoming"])));
- if ($_var_3) {
- if ($_var_5 > IN_BUILD) {
- ?><div class="infobox">
- <div style="color:#C00">
- <h4 class="marginbot normal">发现可用更新 [<?php echo $_var_4;?>] [<?php echo $_var_5;?>]</h4>
- <h5><strong>最近一次更新日志:</strong>[<?php echo $_var_6;?>]</h5>
- <br>
- <h5><strong>本次更新:</strong><font size="3"><?php echo $_var_7;?></font></h5>
-
- </div>
- <p class="margintop"><input type="button" class="btn" value="开始下载更新" onclick="location.href='?c=update&a=down_file';"> <input type="button" class="btn" value="取消" onclick="history.go(-1);"></p>
- </div><?php
- } else {
- ?><div class="infobox"><h4 class="infotitle2">已经是最新版本了</h4></div><?php
- }
- } else {
- ?><div class="infobox"><h4 class="infotitle3">您已更新,请勿重复更新</h4></div><?php
- }
- } else {
- ?><div class="infobox"><p class="margintop"><img src="static/admincp/image/loading.gif" /></p></div><?php
- }
- }
- function down_file()
- {
- ?><div class="infobox"><table class="tb tb2" style="border:1px solid #09C"><tr><td><div id="progressbar" style="float:left;width:1px;text-align:center;color:#FFFFFF;background-color:#09C"></div><div id="progressText" style="float:left">0%</div></td></tr></table></div><?php
- ob_start();
- @set_time_limit(0);
- $_var_7 = @file_get_contents(IN_TMP_PATH . "update.json");
- $_var_7 = json_decode($_var_7, true);
- $_var_8 = pack("H*", trim($_var_7["data"]["zip"]));
- $_var_8 = trim($_var_7["data"]["zip"]);
- $_var_9 = fopen($_var_8, "rb");
-
- if ($_var_9) {
- $_var_10 = get_headers($_var_8, 1);
- if (array_key_exists("Content-Length", $_var_10)) {
- $_var_11 = $_var_10["Content-Length"];
- } else {
- $_var_11 = strlen(@file_get_contents($_var_8));
- }
- ?><script>setsize(<?php echo $_var_11;?>);</script><?php
- $_var_12 = fopen(IN_TMP_PATH . "patch.zip", "wb");
- $_var_13 = 0;
- if ($_var_12) {
-
- while (!feof($_var_9)) {
- $_var_14 = fread($_var_9, 8192);
- $_var_13 += strlen($_var_14);
- fwrite($_var_12, $_var_14, 8192);
- ?><script>setdown(<?php echo $_var_13;?>);</script><?php
- ob_flush();
- flush();
- }
- }
- if ($_var_9) {
- fclose($_var_9);
- }
- if ($_var_12) {
- fclose($_var_12);
- }
- }
- }
- function replace_file()
- {
- $_var_15 = IN_TMP_PATH . "patch.zip";
- if (is_file($_var_15)) {
- $_var_16 = new PclZip($_var_15);
- if (($_var_17 = $_var_16->listContent()) == 0) {
- exit("<div class=\"infobox\"><h4 class=\"marginbot normal\" style=\"color:#C00\">" . $_var_16->errorInfo(true) . "</h4><p class=\"margintop\"><input type=\"button\" class=\"btn\" value=\"重新升级\" onclick=\"history.back(1);\"></p></div></div></body></html>");
- }
- $_var_16->extract(PCLZIP_OPT_PATH, IN_ROOT, PCLZIP_OPT_REPLACE_NEWER);
- ?><div class="infobox"><h4 class="infotitle1">即将开始更新数据,请稍候......</h4><img src="static/admincp/image/loader.gif" class="marginbot" /></div><script>setTimeout("location.href='?c=update&a=change_data';", 1e3);</script><?php
- }
- }
- function change_data()
- {
- @unlink(IN_TMP_PATH . "patch.zip");
- $json = @file_get_contents(IN_TMP_PATH . "update.json");
- $json = json_decode($json, true);
- $version = trim($json["data"]["version"]);
- $build = intval(trim($json["data"]["build"]));
- db("config")->where("name", "IN_VERSION")->update(["value" => $version]);
- db("config")->where("name", "IN_BUILD")->update(["value" => $build]);
- db("update")->strict(false)->insert(array_merge($json["data"], ["create_time" => time()]));
- @unlink(IN_TMP_PATH . "update.json");
- include IN_TMP_PATH . "update.php";
- @unlink(IN_TMP_PATH . "update.php");
- ?><div class="infobox"><h4 class="infotitle2">恭喜!顺利升级完成!</h4><p class="margintop"><input type="button" class="btn" value="完成" onclick="parent.location.href='?c=index';"></p></div><?php
- }
- }
|