<?php
/** 
 * UQ云商：	www.uqcms.com  
 * 联系QQ：	2200631718 
 * 可免费商用，需要留UQ云商链接作为交换，只首页底部留取即可，不影响使用。
 */

defined('IN_UQ') or exit('Access Denied'); function copy_dir($uq0, $uq1) { $uq0 = rtrim($uq0, '/') . '/'; if(!file_exists($uq0)){ return false; } $uq1 = rtrim($uq1, '/') . '/'; if(!file_exists($uq1)){ file::mk_dir($uq1); } $uq2 = opendir($uq0); while($uq3 = readdir($uq2)){ $file1 = $uq0 . $uq3; $file2 = $uq1 . $uq3; if($uq3 != '.' && $uq3 != '..'){ if(is_dir($file1)){ if(!is_dir($file2)){ mkdir($file2); } copy_dir($file1, $file2); }else{ @copy($file1, $file2); } } } closedir($uq2); return true; } class yun_uqcms extends control { function __construct(){ $this->aid = $_SESSION['admin']['aid']; ob_start(); $uq4 = ini_get('output_buffering'); $this->buffer_con = str_repeat(" ", $uq4); echo $this->buffer_con; ob_flush(); flush(); parent::__construct(); } public function index() { $uq2 = UQCMS_PATH.'data/version.php'; $uq5 = include_once $uq2; $uq6 = 'http://www.uqcms.com/soft/upgrade?v='.$uq5; echo '<script>location.href="'.$uq6.'";</script>'; } function version_new() { $uq7 = $_GET['vid']??false; $uq8 = cfg['yun_url'].'api/version?alias=system&vid='.$uq7; echo curl::get($uq8); } public function version_download() { set_time_limit(0); $uq9 = $_GET['alias']??false; $uq10 = $_GET['code']??false; $uq11 = $_GET['downurl']??false; $uq6 = parse_url(base64_decode($uq11)); file::del_dir('temp/yun'); $this->display('yun/version'); ob_flush(); flush(); if(($uq6['host'] == 'www.uqcms.com') || ($uq6['host'] == 'uqcms.com')){ $uq12 = $uq6['scheme'].'://'.$uq6['host'].'/'; $uq5 = include UQCMS_PATH.'data/version.php'; $uq8 = $uq12.'soft/version_upgrade?alias='.$uq9.'&vid='.$uq5.'&code='.$uq10; $uq13 = curl::get($uq8); $uq14 = json_decode($uq13); if($uq14->error != '0'){ $this->error_report('下载错误:'.$uq14->msg); ob_flush(); flush(); exit; } $uq15 = 'temp/yun/download/system_'.$uq14->vid.".zip"; if(!_is_dir($uq15)){ file::mk_dir($uq15, true); } $this->version_download_load($uq14->url, $uq15); if(!file_exists(UQCMS_PATH.$uq15)){ $this->error_report('下载文件失败，没下载到本地！'); } ob_flush(); flush(); if(!extension_loaded('zip')){ $this->error_report('PHP没有ZIP插件，请先安装，不然无法解压。'); } $uq16 = new ZipArchive(); if($uq16->open(UQCMS_PATH.$uq15) === true){ $uq17 = 'temp/yun/cover'; if(!_is_dir($uq17)){ file::mk_dir($uq17); } $uq16->extractTo($uq17); $uq16->close(); if(!empty($uq14->sql)){ $uq18 = base64_decode($uq14->sql); file::write_file($uq17 . '/data/sql/version.sql', $uq18); } echo $this->buffer_con."<script type=\"text/javascript\">add_url('yun/version_cover', '下一步 [警告：覆盖更新文件]');</script>"; }else{ $this->error_report('打开文件失败，请重新下载！'); ob_flush(); flush(); exit; } }else{ exit('获取失败'); } } function version_download_load($uq6, $uq15) { $uq19 = $this->remote_filesize($uq6); $uq2 = fopen($uq6, "r"); if($uq2){ $uq20 = fopen($uq15, "wb"); $uq21 = 0; $uq22 = 0; $uq23 = 0; $uq24 = 0; if($uq20){ while(!feof($uq2) && $uq21 <= $uq19) { $uq25 = fread($uq2, 1024); fwrite($uq20, $uq25, 1024); $uq21 += strlen($uq25); $uq26 = round($uq21/$uq19, 3); $uq27 = $uq26*100; if($uq27 != $uq22){ echo $this->buffer_con."<script type=\"text/javascript\">updateProgress('".$uq27."');</script>"; $uq22 = $uq27; } if(strlen($uq25) == 0){ $uq23++; if($uq23 > 5){ echo $this->buffer_con."<script type=\"text/javascript\">downloadTimeout();</script>"; break; } }else{ $uq23 = 0; } $uq24++; ob_flush(); flush(); } ob_flush(); flush(); } if($uq2){ fclose($uq2); } if($uq20){ fclose($uq20); } } } function remote_filesize($uq6, $uq28 = "", $uq29 = "") { $uq30 = curl_init($uq6); curl_setopt($uq30, CURLOPT_HEADER, 1); curl_setopt($uq30, CURLOPT_NOBODY, 1); if(!empty($uq28) && !empty($uq29)){ $uq31 = array('Authorization: Basic ' . base64_encode("$uq28:$uq29")); curl_setopt($uq30, CURLOPT_HTTPHEADER, $uq31); } $uq32 = curl_exec($uq30); curl_close($uq30); $uq33 = ob_get_contents(); ob_end_clean(); $uq34 = preg_match('/Content-Length:\s([0-9].+?)\s/', $uq33, $uq35); return isset($uq35[1])?$uq35[1]:'0'; } public function version_cover() { if(cfg['site_local']){ $this->assign('msg', '本地测试环境，禁止更新'); }else{ copy_dir(UQCMS_PATH.'temp/yun/cover', UQCMS_PATH); $uq2 = file::read_file('temp/version/cover/data/sql/version.sql'); if($uq2){ $this->db->autocommit(); $uq36 = explode(';', $uq2); foreach($uq36 as $uq37){ if(trim($uq37) != ''){ $uq38 = $this->db->query($uq37); if($uq38){ $uq34[] = ''; } $count2[] = ''; } } if((count($uq34) == count($count2)) && (count($uq34) > 0)){ $this->db->commit(); }else{ sys_log('系统更新失败'); $this->db->rollback(); } $this->assign('msg', '更新错误'); }else{ $this->assign('msg', '更新错误'); } $this->assign('msg', '更新成功'); file::del_dir('temp/yun'); } $this->display('yun/version'); } private function error_report($uq39) { echo "<script type=\"text/javascript\">error_report('".$uq39."');</script>"; ob_flush(); flush(); } } 