コード例 #1
0
 /**
  * _unzipFile
  *
  * @return	bool
  **/
 public function _unzipFile()
 {
     // local file name
     $downloadDirPath = realpath($this->Xupdate->params['temp_path']);
     $downloadFilePath = $this->Xupdate->params['temp_path'] . '/' . $this->target_key . '.zip';
     $exploredDirPath = realpath($downloadDirPath . '/' . $this->target_key);
     if (empty($downloadFilePath)) {
         $this->_set_error_log('getDownloadFilePath not found error in: ' . $this->_getDownloadFilePath());
         return false;
     }
     if (!chdir($exploredDirPath)) {
         $this->_set_error_log('chdir error in: ' . $exploredDirPath);
         return false;
         //chdir error
     }
     File_Archive::extract(File_Archive::read($downloadFilePath . '/'), File_Archive::appender($exploredDirPath));
     return true;
 }
コード例 #2
0
/**
 * cmdUpgrade()
 *
 * @param  array &$aryPear
 * @return void
 */
function cmdUpgrade(&$aryPear)
{
    $sFile = BLOCKEN_TMP_DIR . '/BlockenPackage.zip';
    $sRet = $aryPear['curl']->execute(BLOCKEN_UPGRADE_URL);
    if (PEAR::isError($sRet)) {
        echo "Blockenのアップグレードに失敗しました\n";
        return;
    }
    $fpPkg = fopen($sFile, 'wb');
    if (!$fpPkg) {
        echo "Blockenのアップグレードに失敗しました\n";
        return;
    }
    flock($fpPkg, LOCK_EX);
    fwrite($fpPkg, $sRet);
    flock($fpPkg, LOCK_UN);
    fclose($fpPkg);
    File_Archive::extract(File_Archive::read("{$sFile}/"), File_Archive::appender(BLOCKEN_BASE));
    unlink($sFile);
    $aryOldFile = file(BLOCKEN_BASE . '/config.php');
    $aryNewFile = file(BLOCKEN_BASE . '/config.php.default');
    $objDiff =& new Text_Diff($aryOldFile, $aryNewFile);
    $objRenderer =& new Text_Diff_Renderer_unified();
    $sBuff = $objRenderer->render($objDiff);
    $fpDiff = fopen(BLOCKEN_BASE . '/config.php.diff', 'w');
    if (!$fpDiff) {
        echo "Blockenのアップグレードに失敗しました\n";
        return;
    }
    flock($fpDiff, LOCK_EX);
    fwrite($fpDiff, $sBuff);
    flock($fpDiff, LOCK_UN);
    fclose($fpDiff);
    chmod(BLOCKEN_BASE . '/config.php.default', 0644);
    chmod(BLOCKEN_BASE . '/config.php.diff', 0644);
    echo "Blockenのアップグレードが完了しました\n";
    echo "configファイルを必要に応じてマージしてください\n";
    echo "New Config File:  " . BLOCKEN_BASE . "/config.php.default\n";
    echo "Diff Config File: " . BLOCKEN_BASE . "/config.php.diff\n";
}
コード例 #3
0
ファイル: Archive.php プロジェクト: kosmosby/medicine-prof
 /**
  * Try to interpret the object as a writer
  * Strings are converted to writers using File_Archive::appender
  * Arrays are converted to writers using a multi writer
  *
  * @access private
  */
 function &_convertToWriter(&$dest)
 {
     if (is_string($dest)) {
         return File_Archive::appender($dest);
     } else {
         if (is_array($dest)) {
             require_once dirname(__FILE__) . '/Archive/Writer/Multi.php';
             $writer = new File_Archive_Writer_Multi();
             foreach ($dest as $key => $foo) {
                 $writer->addWriter($dest[$key]);
             }
         } else {
             return $dest;
         }
     }
 }
コード例 #4
0
ファイル: Archive.php プロジェクト: nao-pon/xupdate
 /**
  * Try to interpret the object as a writer
  * Strings are converted to writers using File_Archive::appender
  * Arrays are converted to writers using a multi writer
  *
  * @access private
  */
 function &_convertToWriter(&$dest)
 {
     if (is_string($dest)) {
         $obj =& File_Archive::appender($dest);
         return $obj;
     } else {
         if (is_array($dest)) {
             require_once 'File/Archive/Writer/Multi.php';
             $writer = new File_Archive_Writer_Multi();
             foreach ($dest as $key => $foo) {
                 $writer->addWriter($dest[$key]);
             }
             return $writer;
         } else {
             return $dest;
         }
     }
 }
コード例 #5
0
 /**
  * バックアップXMLファイル->リストア配列変換処理
  *
  * @access  public
  */
 function getRestoreArray($upload_id, $backup_page_id, $module_id, $temporary_file_path)
 {
     set_time_limit(BACKUP_TIME_LIMIT);
     // メモリ最大サイズ設定
     ini_set('memory_limit', -1);
     $errorList =& $this->_actionChain->getCurErrorList();
     //if($backup_page_id == 0 || $upload_id == 0) {
     //	// フルバックアップをリストアしようとしている
     //	$errorList->add("backup", BACKUP_FAILURE_RESTORE);
     //	return false;
     //}
     //$uploads = $this->_db->selectExecute("uploads", array("upload_id" => $upload_id, "room_id" => $backup_page_id, "module_id" => $module_id));
     $uploads = $this->_db->selectExecute("uploads", array("upload_id" => $upload_id, "module_id" => $module_id));
     if ($uploads === false || !isset($uploads[0]) || count($uploads) > 1) {
         return false;
     }
     $uploads_file_path = FILEUPLOADS_DIR . "backup/" . $uploads[0]['physical_file_name'];
     if (!file_exists($uploads_file_path)) {
         // バックアップファイルなし
         $errorList->add("backup", BACKUP_NONE_RESTORE);
         return false;
     }
     if (file_exists($temporary_file_path)) {
         // 現在、同じバックアップファイル-リストア中
         // エラーとする
         $errorList->add("backup", BACKUP_RESTORING);
         return false;
     }
     if (!mkdir($temporary_file_path, 0777)) {
         $errorList->add("backup", BACKUP_RESTORE_ERROR);
         return false;
     }
     //
     // 解凍
     //
     File_Archive::extract(File_Archive::read($uploads_file_path . "/"), File_Archive::appender($temporary_file_path));
     if (!file_exists($temporary_file_path . BACKUP_ROOM_XML_FILE_NAME)) {
         // XMLファイルなし
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_FAILURE_RESTORE);
         return false;
     }
     // PHP 4 > 4.3.0, PHP 5
     $xml = file_get_contents($temporary_file_path . BACKUP_ROOM_XML_FILE_NAME);
     if ($xml === false) {
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_RESTORE_ERROR);
         return false;
     }
     if (!file_exists($temporary_file_path . BACKUP_ROOM_XML_INI_NAME)) {
         // XML INIファイルなし
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_FAILURE_RESTORE);
         return false;
     }
     $xml_ini = file_get_contents($temporary_file_path . BACKUP_ROOM_XML_INI_NAME);
     if ($xml_ini === false) {
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_RESTORE_ERROR);
         return false;
     }
     $unserializer =& new XML_Unserializer();
     //
     // 複合化チェック
     //
     $result = $unserializer->unserialize($xml_ini);
     if ($result !== true) {
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_FAILURE_UNSERIALIZE);
         return false;
     }
     $data_ini = $unserializer->getUnserializedData();
     // 共有設定されているかどうか
     if ($data_ini["host_field"] == BASE_URL . INDEX_FILE_NAME) {
         // 自サイトならば、無条件でOK
         $self_flag = true;
     } else {
         $self_flag = false;
         // サイトテーブルにあり、commons_flagが立っているものを許す
         $data_ini["host_field"] = preg_replace("/" . preg_quote(INDEX_FILE_NAME, "/") . "\$/i", "", $data_ini["host_field"]);
         $where_params = array("url" => $data_ini["host_field"], "commons_flag" => _ON);
         // 有効期限がいついつの公開鍵を取得
         $other_site = $this->_db->selectExecute("sites", $where_params, null, 1);
         if ($other_site === false) {
             $this->_fileAction->delDir($temporary_file_path);
             $errorList->add("backup", BACKUP_RESTORE_ERROR);
             return false;
         }
         if (!isset($other_site[0])) {
             // 共有設定されていない
             $this->_fileAction->delDir($temporary_file_path);
             $errorList->add("backup", BACKUP_RESTORE_COMMONS_ERROR);
             return false;
         }
     }
     $get_public_url = $data_ini["host_field"] . INDEX_FILE_NAME . "?action=encryption_view_publickey" . "&encrypt_data=" . rawurlencode($data_ini['encrypt_text']) . "&expiration_time=" . $data_ini['expiration_time'] . "&_header=" . _OFF;
     $public_key_html = $this->_requestMain->getResponseHtml($get_public_url);
     if ($public_key_html === false) {
         // 公開鍵取得失敗
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_RESTORE_PUBLIC_KEY_ERROR);
         return false;
     }
     if (is_string($public_key_html)) {
         $public_key_html = trim($public_key_html);
         $public_key = preg_replace("/^public_key=/i", "", $public_key_html);
     }
     if (isset($public_key) && $public_key_html == $public_key) {
         // 公開鍵取得失敗
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_RESTORE_PUBLIC_KEY_ERROR);
         return false;
     }
     // 複合化
     //$this->encryption =& $this->_container->getComponent("encryptionView");
     $decrypt_text = $this->encryption->decrypt($data_ini['encrypt_text'], $public_key);
     $hash_text = sha1($xml);
     if ($decrypt_text != $hash_text) {
         // 不正なファイルの可能性あり
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_FAILURE_RESTORE);
         return false;
     }
     //$options = array ('parseAttributes' => true);	属性値を含める
     //$unserializer =& new XML_Unserializer($options);
     $result = $unserializer->unserialize($xml);
     if ($result !== true) {
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_FAILURE_UNSERIALIZE);
         return false;
     }
     $data = $unserializer->getUnserializedData();
     //-----------------------------------------------------------------------------------
     // NetCommonsバージョンチェック
     // 上3桁目がいっしょならば、リストアを許す
     //-----------------------------------------------------------------------------------
     if (!isset($data["version"]) || !isset($data["version"]["_version"]) || !isset($data["_room_inf"])) {
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_FAILURE_RESTORE);
         return false;
     }
     $current_version = $data["version"]["_version"];
     $current_version_arr = explode(".", $current_version);
     $now_version_arr = explode(".", _NC_VERSION);
     if (count($current_version_arr) != 4 || count($now_version_arr) != 4) {
         // バージョン情報が不正
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_WRONG_VERSION);
         return false;
     }
     if ($now_version_arr[0] != $current_version_arr[0] || $now_version_arr[1] != $current_version_arr[1] || $now_version_arr[2] != $current_version_arr[2]) {
         // バージョン情報が一致しない
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", sprintf(BACKUP_DIFFER_VERSION, $current_version, _NC_VERSION));
         return false;
     }
     //-----------------------------------------------------------------------------------
     // リストア対象ルーム情報取得-チェック
     // DB項目が変わることもありえるので、すべての項目はチェックしない
     // 「バックアップファイル追加」時にチェックすればいい
     //-----------------------------------------------------------------------------------
     if (!isset($data["_room_inf"]["row"]) || !isset($data["_room_inf"]["row"]["page_id"]) || !isset($data["_room_inf"]["row"]["room_id"]) || !isset($data["_room_inf"]["row"]["private_flag"]) || !isset($data["_room_inf"]["row"]["space_type"]) || !isset($data["_room_inf"]["row"]["site_id"]) || !isset($data["_room_inf"]["row"]["thread_num"]) || !isset($data["_room_inf"]["row"]["parent_id"]) || $data["_room_inf"]["row"]["room_id"] != $data["_room_inf"]["row"]["page_id"]) {
         $this->_fileAction->delDir($temporary_file_path);
         $errorList->add("backup", BACKUP_WRONG_ROOMINF);
         return false;
     }
     $room_inf = $data["_room_inf"]["row"];
     if (!$self_flag) {
         $room_inf['site_id'] = $other_site[0]['site_id'];
         $room_inf['url'] = $data_ini["host_field"];
         if ($room_inf['thread_num'] == 2) {
             $room_inf['parent_id'] = 0;
         }
         $room_inf['room_id'] = 0;
     } else {
         $room_inf['url'] = '';
     }
     $room_inf['pre_page_name'] = $room_inf['page_name'];
     // スペースタイプがパブリックスペース or プライベートスペースならば上書き
     // それ以外ならば、追加登録
     if ($room_inf['thread_num'] == 0 && ($room_inf['private_flag'] == _ON || $room_inf['space_type'] == _SPACE_TYPE_PUBLIC)) {
         // パブリックスペース or プライベートスペース
         // 参加者や、その他、親カラムの情報は基本的にリストアしない(選択させる?)
         $restore_type = "top";
     } else {
         // グループルーム or サブグループ(新規ルームとしてリストア)
         if ($room_inf['thread_num'] == 2) {
             $restore_type = "subgroup";
         } else {
             if ($room_inf['space_type'] == _SPACE_TYPE_PUBLIC) {
                 $restore_type = "public_room";
             } else {
                 $restore_type = "group_room";
             }
         }
         // 同名のルームが存在したら、リネームする
         $first_room_name = $room_inf['page_name'];
         $rename_count = 1;
         while (1) {
             $chk_pages =& $this->_pagesView->getPages(array("thread_num" => $room_inf['thread_num'], "space_type" => $room_inf['space_type'], "private_flag" => $room_inf['private_flag'], "page_id=room_id" => null, "page_name" => $room_inf['page_name']));
             if ($chk_pages === false) {
                 $this->_fileAction->delDir($temporary_file_path);
                 return false;
             }
             if (isset($chk_pages[0])) {
                 // 同名のルームあり
                 $room_inf['page_name'] = sprintf(BACKUP_RESTORE_PREFIX_PAGE_NAME, $rename_count) . $first_room_name;
                 $rename_count++;
             } else {
                 break;
             }
         }
     }
     if (($restore_type == "public_room" || $restore_type == "top") && $room_inf['private_flag'] == _OFF) {
         // パブリックスペースであればサイト閉鎖中かどうかを取得(警告メッセージを表示するため)
         // サイト閉鎖中かどうか
         $closesite = $this->_configView->getConfigByConfname(_SYS_CONF_MODID, "closesite");
         if ($closesite === false) {
             $this->_fileAction->delDir($temporary_file_path);
             return false;
         }
         $closesite = $closesite['conf_value'];
     }
     //-----------------------------------------------------------------------------------
     // 各モジュールバージョンチェック
     // 上3桁目がいっしょならば、リストアを許す
     // インストールされていないモジュールはリストアしない
     //-----------------------------------------------------------------------------------
     $modules = $this->_modulesView->getModules(array("system_flag" => _OFF), null, null, null, array($this, "_fetchcallbackModules"), $this->_modulesView);
     if ($modules === false) {
         $this->_fileAction->delDir($temporary_file_path);
         return false;
     }
     $adodb = $this->_db->getAdoDbObject();
     foreach ($modules as $dirname => $module) {
         $buf_tablelist = $this->_databaseSqlutility->getTableList($dirname, false);
         if (is_array($buf_tablelist) && count($buf_tablelist) > 0) {
             foreach ($buf_tablelist as $table) {
                 // テーブルリスト取得
                 $this->tablePrimarylist[$dirname][$table] = $adodb->MetaPrimaryKeys($this->_db->getPrefix() . $table);
                 $this->tablelist[$table] = $dirname;
             }
         }
         unset($buf_tablelist);
     }
     $restore_modules = array();
     $restore_modules["system"]['restore_type'] = $restore_type;
     $restore_modules["system"]['self_flag'] = $self_flag;
     foreach ($data["version"] as $module_name => $module_version) {
         //if($module_name == "_version") {
         //	continue;
         //}
         if (preg_match("/^_/i", $module_name)) {
             // モジュール名称
             continue;
         }
         $restore_modules[$module_name] = array();
         $restore_modules[$module_name]['state'] = false;
         if (isset($modules[$module_name])) {
             $restore_modules[$module_name]['module_id'] = $modules[$module_name]['module_id'];
             $restore_modules[$module_name]['module_name'] = $modules[$module_name]['module_name'];
             $module_version_arr = explode(".", $module_version);
             $now_module_version_arr = explode(".", $modules[$module_name]['version']);
             if (count($current_version_arr) != 4 || count($now_version_arr) != 4) {
                 // モジュールのバージョンの書き方が不正(リストア対象からはずす)
                 $restore_modules[$module_name]['error_mes'] = BACKUP_WRONG_MODULE_VERSION;
                 continue;
             } else {
                 if ($now_module_version_arr[0] != $module_version_arr[0] || $now_module_version_arr[1] != $module_version_arr[1] || $now_module_version_arr[2] != $module_version_arr[2]) {
                     // バージョン情報が一致しない
                     $restore_modules[$module_name]['error_mes'] = BACKUP_DIFFER_MODULE_VERSION;
                     continue;
                 }
             }
             $this->restorelist[$module_name] = true;
             //$buf_tablelist = $this->_databaseSqlutility->getTableList($module_name, false);
             //if(is_array($buf_tablelist) && count($buf_tablelist) > 0) {
             //	foreach($buf_tablelist as $table) {
             //		// テーブルリスト取得
             //		$this->tablelist[$table] = $module_name;
             //	}
             //}
         } else {
             // 未インストールモジュール
             if (isset($data["version"]["_" . $module_name])) {
                 $restore_modules[$module_name]['module_name'] = $data["version"]["_" . $module_name];
             } else {
                 $restore_modules[$module_name]['module_name'] = $module_name;
             }
             $restore_modules[$module_name]['error_mes'] = BACKUP_UNINSTALL_MODULE;
             continue;
         }
         if ($modules[$module_name]['restore_action'] == "auto") {
             //
             // install.iniチェック
             // [Restore]
             // _transfer_id="bbs_id,post_id,topic_id,parent_id,room_id,block_id"
             //						     -> IDを振り替えるリスト($this->db->nextSeq($table_name))
             // topic_id = post_id	     -> post_idを振り替えた値をtopic_idに入れるという意味(topic_idでnextSeqしない)
             // parent_id = post_id      -> 上記と同様
             // room_id = core.room_id   -> coreのテーブルのroom_idがはいる
             // block_id = core.block_id  -> coreのテーブルのblock_idがはいる
             $file_path = MODULE_DIR . "/" . $module_name . '/install.ini';
             if (file_exists($file_path)) {
                 if (version_compare(phpversion(), "5.0.0", ">=")) {
                     $initializer =& DIContainerInitializerLocal::getInstance();
                     $install_ini = $initializer->read_ini_file($file_path, true);
                 } else {
                     $install_ini = parse_ini_file($file_path, true);
                 }
                 if (isset($install_ini['Restore']) && is_array($install_ini['Restore'])) {
                     $restore_modules[$module_name]['transfer_list'] = $install_ini['Restore'];
                 } else {
                     // リストア対象外モジュール
                     $restore_modules[$module_name]['error_mes'] = BACKUP_UNSUPPORTED_MODULE;
                 }
                 //if(isset($install_ini['CleanUp']) && is_array($install_ini['CleanUp'])) {
                 //	// uploadsテーブルのIDを振り替えるため、その振替元のカラムのupload_idの項目を更新しなければならない
                 //	// $install_ini['Restore']にそれを記述すると煩雑になるため、現状、CleanUpの項目を用いる
                 //	$restore_modules[$module_name]['transfer_uploads'] = $install_ini['CleanUp'];
                 //}
             }
         } else {
             if ($modules[$module_name]['restore_action'] == "") {
                 // リストア対象外モジュール
                 $restore_modules[$module_name]['error_mes'] = BACKUP_UNSUPPORTED_MODULE;
             } else {
                 // リストアアクションを呼ぶのみ
                 $restore_modules[$module_name]['transfer_list'] = $modules[$module_name]['restore_action'];
             }
         }
         $restore_modules[$module_name]['state'] = true;
     }
     // room毎に分割
     $this->data =& $data;
     //$this->_fileAction->delDir($temporary_file_path);
     return array($room_inf, $restore_modules, $data["version"], $modules);
 }