Esempio n. 1
0
 public function applyPatch($filename)
 {
     $System = new SystemEvent();
     $zip = new \ZipArchive();
     //新建一个ZipArchive的对象
     if ($zip->open($filename) === true) {
         $zip->extractTo(WEB_ROOT);
         //假设解压缩到在当前路径下/文件夹内
         $zip->close();
         //关闭处理的zip文件
         File::delFile($filename);
         $System->clearCacheAll();
         return $this->jsonResult(1, "安装成功");
     } else {
         return $this->jsonResult(0, "文件损坏");
     }
 }
 /**
  * WordPress 导入处理
  */
 public function wordpressHandle()
 {
     $config = array("savePath" => 'Data/', "maxSize" => 10000000, "exts" => array('xml'), "subName" => array('date', 'Y/m-d'));
     $upload = new Upload($config);
     $info = $upload->upload();
     if (!$info) {
         // 上传错误提示错误信息
         $this->error($upload->getError());
     } else {
         // 上传成功 获取上传文件信息
         $file_path_full = $info['file']['fullpath'];
         if (File::file_exists($file_path_full)) {
             $Wordpress = new WordpressEvent();
             $Wordpress->catImport($file_path_full);
             $Wordpress->tagImport($file_path_full);
             $Wordpress->postImport($file_path_full);
             File::delFile($file_path_full);
             $this->success('导入完成');
         }
         $this->error('导入失败');
     }
 }
Esempio n. 3
0
 /**
  * 删除已备份数据库文件
  */
 public function delZipFiles()
 {
     if (IS_POST) {
         $zipFiles = explode(',', $_POST['zipFiles']);
         if (empty($zipFiles) || count($zipFiles) == 0 || $_POST['zipFiles'] == "") {
             $this->jsonReturn(0, "请先选择要删除的zip文件");
         }
         $files = $zipFiles;
         foreach ($files as $file) {
             File::delFile(DB_Backup_PATH . "Zip/" . $file);
             //$dir = new Dir(DB_Backup_PATH . "Zip/");
             //$dir->delDirAndFile(DB_Backup_PATH . "Zip/" . $file);
         }
         echo json_encode(array("status" => 1, "info" => "已删除:" . implode("、", $files), "url" => __URL__ . "/zipList?" . time()));
     }
 }
 public function delFileHandle($id)
 {
     $file_name = base64_decode($id);
     if (File::delFile($file_name)) {
         $this->success('删除成功');
     }
 }
 /**
  *
  */
 public function updateHandle()
 {
     G("UpdateHandle");
     $message = "";
     $version = I('get.version');
     $now_version = get_opinion('software_build', true);
     $url = Server_API . 'api/update/' . $now_version . '/';
     $json = json_decode(file_get_contents($url), true);
     G("GetJson");
     $message .= "下载Index文件成功,用时 " . G("UpdateHandle", "getJson") . "秒<br />";
     if (empty($json)) {
         $message .= "连接主升级服务器出错,使用备用服务器<br />";
         // try backup
         $url = Server_API2 . 'api/update/' . $now_version . '/';
         $json = json_decode(file_get_contents($url), true);
         G("GetJson");
         if (empty($json)) {
             $this->error('连接升级服务器出错');
         }
     }
     $target_version_info = $json['file_list'][$version];
     if (!empty($target_version_info)) {
         File::mkDir(WEB_CACHE_PATH);
         G("WebCache");
         $message .= "清空WEB_CACHE_PATH,用时 " . G("GetJson", "WebCache") . "秒<br />";
         $file_downloaded = WEB_CACHE_PATH . $target_version_info['file_name'];
         $file = file_get_contents($target_version_info['file_url']);
         if (File::writeFile($file_downloaded, $file)) {
             G("DownFile");
             $message .= "下载升级文件成功,用时 " . G("WebCache", "DownFile") . "秒<br />";
         } else {
             $this->error('下载文件失败');
         }
         //calculate md5 of file
         $file_md5 = md5_file($file_downloaded);
         G("MD5");
         $message .= "文件MD5值: {$file_md5} ,用时 " . G("DownFile", "MD5") . "秒<br />";
         //todo 系统备份
         $System = new SystemEvent();
         //$System->backupFile();
         G("BackupFile");
         $message .= "系统备份已跳过 ,用时 " . G("MD5", "BackupFile") . "秒<br />";
         $zip = new \ZipArchive();
         //新建一个ZipArchive的对象
         if ($zip->open($file_downloaded) === true) {
             $zip->extractTo(WEB_ROOT);
             //假设解压缩到在当前路径下/文件夹内
             $zip->close();
             //关闭处理的zip文件
             File::delFile($file_downloaded);
             G("UnzipFile");
             $message .= "解压成功 ,用时 " . G("BackupFile", "UnzipFile") . "秒<br />";
             $System->clearCacheAll();
             $message .= "清空缓存成功 <br />";
         } else {
             $this->error('文件损坏');
         }
         $old_build = get_opinion('software_build');
         $new_build = $target_version_info['build_to'];
         set_opinion('software_version', $target_version_info['version_to']);
         set_opinion('software_build', $target_version_info['build_to']);
         set_opinion('db_build', $target_version_info['build_to']);
         if (File::file_exists(Upgrade_PATH . 'init.php')) {
             include Upgrade_PATH . 'init.php';
             if (function_exists("upgrade_" . $old_build . "_to_" . $new_build)) {
                 $fuction_name = "upgrade_" . $old_build . "_to_" . $new_build;
                 G("FunctionStart");
                 call_user_func($fuction_name);
                 G("FunctionEnd");
                 $message .= "处理升级函数 ,用时 " . G("FunctionStart", "FunctionEnd") . "秒 <br />";
             }
         }
         $this->updateComplete('升级成功' . $target_version_info['build_to'] . "<br />" . $message);
     } else {
         $this->error('升级出错');
     }
 }
 /**
  *
  */
 public function updateHandle()
 {
     $version = I('get.version');
     $now_version = get_opinion('software_build', true);
     $url = Server_API . 'api/update/' . $now_version . '/';
     $json = json_decode(file_get_contents($url), true);
     $target_version_info = $json['file_list'][$version];
     if (!empty($target_version_info)) {
         File::mkDir(WEB_CACHE_PATH);
         $file_downloaded = WEB_CACHE_PATH . $target_version_info['file_name'];
         $file = file_get_contents($target_version_info['file_url']);
         File::writeFile($file_downloaded, $file);
         //todo 系统备份
         $System = new SystemEvent();
         //$System->backupFile();
         $zip = new \ZipArchive();
         //新建一个ZipArchive的对象
         if ($zip->open($file_downloaded) === true) {
             $zip->extractTo(WEB_ROOT);
             //假设解压缩到在当前路径下/文件夹内
             $zip->close();
             //关闭处理的zip文件
             File::delFile($file_downloaded);
             $System->clearCacheAll();
         } else {
             $this->error('文件损坏');
         }
         $old_build = get_opinion('software_build');
         $new_build = $target_version_info['build_to'];
         set_opinion('software_version', $target_version_info['version_to']);
         set_opinion('software_build', $target_version_info['build_to']);
         if (File::file_exists(Upgrade_PATH . 'init.php')) {
             include Upgrade_PATH . 'init.php';
             if (function_exists("upgrade_" . $old_build . "_to_" . $new_build)) {
                 $fuction_name = "upgrade_" . $old_build . "_to_" . $new_build;
                 call_user_func($fuction_name);
             }
         }
         $this->success('升级成功' . $target_version_info['build_to'], U('Admin/Index/updateComplete'));
     } else {
         $this->error('升级出错');
     }
 }
 /**
  *
  */
 public function step4()
 {
     $time = date("Y-m-d H:m:s");
     $db_host = $_POST["db_host"];
     $db_port = $_POST["db_port"];
     $db_user = $_POST["db_user"];
     $db_password = $_POST["db_password"];
     $db_name = $_POST["db_name"];
     $db_prefix = $_POST["db_prefix"];
     if ($_POST['admin_password'] != $_POST['admin_password2'] || trim($_POST['admin_password']) == '' || trim($_POST['admin_password2']) == '') {
         $this->error("两次输入的密码不一致,请重新设定!,或者密码为空");
     } else {
         $admin_user = $_POST['admin_user'];
         $admin_password = encrypt($_POST['admin_password']);
         $admin_email = $_POST['admin_email'];
         $user_session = encrypt($admin_user . $admin_password . time());
     }
     $title = $_POST['cfg_title'];
     $site_url = $_POST['cfg_basehost'] . $_POST['cfg_cmspath'];
     if (!test_db_connect($db_host . ":" . $db_port, $db_user, $db_password)) {
         $this->error("数据库服务器或登录密码无效,\n\n无法连接数据库,请重新设定!");
     }
     $conn = mysql_connect($db_host . ":" . $db_port, $db_user, $db_password);
     mysql_query("CREATE DATABASE IF NOT EXISTS `" . $db_name . "`;", $conn);
     if (!mysql_select_db($db_name)) {
         $this->error("选择数据库失败,可能是你没权限,请预先创建一个数据库!");
     }
     mysql_query("set character set 'utf8'");
     mysql_query("set names 'utf8'");
     $file = WEB_ROOT . 'Data/Install/db_config_sample.php';
     if (!File::file_exists($file)) {
         $this->error('Data/Install/db_config_sample.php文件不存在,请检查');
     }
     $content = File::readFile($file);
     $content = str_replace("~dbhost~", $db_host, $content);
     $content = str_replace("~dbport~", $db_port, $content);
     $content = str_replace("~dbname~", $db_name, $content);
     $content = str_replace("~dbuser~", $db_user, $content);
     $content = str_replace("~dbpwd~", $db_password, $content);
     $content = str_replace("~dbprefix~", $db_prefix, $content);
     if (!File::writeFile(WEB_ROOT . 'db_config.php', $content, 'w+')) {
         $this->error("数据库配置文件写入失败,请您手动根据Data/Install/db_config_sample.php文件在根目录创建文件");
     }
     File::makeDir(WEB_ROOT . 'Data/Cache');
     $sql_empty = File::readFile(WEB_ROOT . 'Data/Install/greencms_empty.sql');
     $sql_query = str_replace('{$db_prefix}', $db_prefix, $sql_empty);
     $file = WEB_ROOT . 'Data/Cache/greencms_sample.sql';
     File::writeFile($file, $sql_query, 'w+');
     insertDB($file, $conn);
     File::delFile($file);
     $sql_empty = File::readFile(WEB_ROOT . 'Data/Install/greencms_init.sql');
     $sql_query = str_replace('{$db_prefix}', $db_prefix, $sql_empty);
     $file2 = WEB_ROOT . 'Data/Cache/greencms_init_sample.sql';
     File::writeFile($file2, $sql_query, 'w+');
     insertDB($file2, $conn);
     File::delFile($file2);
     /**
      * 插入管理员数据&更新配置
      */
     $admin_query = "INSERT INTO `{$db_prefix}user` (`user_id`, `user_login`, `user_pass`, `user_nicename`, `user_email`,\n        `user_url`, `user_registered`, `user_activation_key`, `user_status`,  `user_intro`,\n        `user_level`, `user_session`) VALUES(1, '{$admin_user}', '" . $admin_password . "', '管理员', '{$admin_email}',\n         '', '{$time}', '', 1, '我是admin,欢迎使用', 2, '{$user_session}');";
     if (!mysql_query($admin_query, $conn)) {
         $this->error(' 插入管理员数据出错');
     }
     $cquery = "Update `{$db_prefix}options` set option_value='{$title}' where option_name='title';";
     if (!mysql_query($cquery, $conn)) {
         $this->error(' 更新配置数据出错');
     }
     $cquery = "Update `{$db_prefix}options` set option_value='{$site_url}' where option_name='site_url';";
     if (!mysql_query($cquery, $conn)) {
         $this->error(' 更新配置数据出错');
     }
     $software_version = GreenCMS_Version;
     $software_build = GreenCMS_Build;
     $cquery = "Update `{$db_prefix}options` set option_value='{$software_version}' where option_name='software_version';";
     if (!mysql_query($cquery, $conn)) {
         $this->error(' 更新配置数据出错');
     }
     $cquery = "Update `{$db_prefix}options` set option_value='{$software_build}' where option_name='software_build';";
     if (!mysql_query($cquery, $conn)) {
         $this->error(' 更新配置数据出错');
     }
     //TODO              写不下去了
     $this->redirect('Install/Index/step5');
 }