示例#1
0
 public static function importGame($pack)
 {
     $pack->auth->permission = "read_write";
     if (!users::authenticateUser($pack->auth)) {
         return new return_package(6, NULL, "Failed Authentication");
     }
     $zipbasename = substr($pack->zip_name, 0, strrpos($pack->zip_name, ".zip"));
     $tmp_import_folder = Config::v2_gamedata_folder . "/" . $zipbasename . "_import_" . date("mdY_Gis");
     if (file_exists($tmp_import_folder)) {
         return "no";
     }
     if (isset($pack->raw_upload_id)) {
         $tmp_zip = Config::raw_uploads_folder . '/' . $pack->raw_upload_id;
     } else {
         if (isset($pack->zip_data)) {
             $tmp_zip = $tmp_import_folder . ".zip";
             //save data to zip
             $zipfile = fopen($tmp_zip, "w");
             fwrite($zipfile, base64_decode($pack->zip_data));
             fclose($zipfile);
         } else {
             return new return_package(1, NULL, "No ZIP data given to import a game from");
         }
     }
     //unzip to folder
     $zip = new ZipArchive();
     if ($zip->open($tmp_zip) === TRUE) {
         $zip->extractTo($tmp_import_folder);
         $zip->close();
     }
     unlink($tmp_zip);
     //get rid of zip
     unset($pack->zip_data);
     //for readability in debug
     //read text
     $jsonfile = fopen($tmp_import_folder . "/export.json", "r");
     $assoc_data = json_decode(fread($jsonfile, filesize($tmp_import_folder . "/export.json")), true);
     fclose($jsonfile);
     //convert to non-assoc for non-data tables
     $import = new stdClass();
     $import->game_id = $assoc_data["game_id"];
     $import->table_data = array();
     for ($i = 0; $i < count($assoc_data["table_data"]); $i++) {
         $import->table_data[$i] = new stdClass();
         $import->table_data[$i]->table = $assoc_data["table_data"][$i]["table"];
         $import->table_data[$i]->columns = array();
         for ($j = 0; $j < count($assoc_data["table_data"][$i]["columns"]); $j++) {
             $import->table_data[$i]->columns[$j] = new stdClass();
             $import->table_data[$i]->columns[$j]->name = $assoc_data["table_data"][$i]["columns"][$j]["name"];
             $import->table_data[$i]->columns[$j]->meta = $assoc_data["table_data"][$i]["columns"][$j]["meta"];
         }
         $import->table_data[$i]->data = $assoc_data["table_data"][$i]["data"];
     }
     $pack->import = $import;
     $ret = duplicate::importGameData($pack);
     util::rdel($tmp_import_folder);
     //get rid of zipto
     return $ret;
 }
示例#2
0
文件: notes.php 项目: kimblemj/server
 public static function exportNotes($pack)
 {
     $pack->auth->game_id = $pack->game_id;
     $pack->auth->permission = "read_write";
     if (!editors::authenticateGameEditor($pack->auth)) {
         return new return_package(6, NULL, "Failed Authentication");
     }
     $export = notes::getNotesForGame($pack);
     $tmp_export_folder = $pack->game_id . "_notebook_export_" . date("mdY_Gis");
     $fs_tmp_export_folder = Config::v2_gamedata_folder . "/" . $tmp_export_folder;
     if (file_exists($fs_tmp_export_folder)) {
         util::rdel($fs_tmp_export_folder);
     }
     mkdir($fs_tmp_export_folder, 0777);
     $jsonfile = fopen($fs_tmp_export_folder . "/export.json", "w");
     fwrite($jsonfile, json_encode($export));
     fclose($jsonfile);
     util::rcopy(Config::v2_gamedata_folder . "/" . $pack->game_id, $fs_tmp_export_folder . "/gamedata");
     util::rzip($fs_tmp_export_folder, $fs_tmp_export_folder . ".zip");
     util::rdel($fs_tmp_export_folder);
     return new return_package(0, Config::v2_gamedata_www_path . "/" . $tmp_export_folder . ".zip");
 }
示例#3
0
文件: util.php 项目: kimblemj/server
 public static function rdel($dirPath)
 {
     //hack to "fix" security issue of this becoming open API via our terrible framework
     if (strpos($_SERVER['REQUEST_URI'], 'rdel') !== false) {
         return new return_package(6, NULL, "Attempt to bypass authentication externally.");
     }
     if (!is_dir($dirPath)) {
         throw new InvalidArgumentException("{$dirPath} must be a directory");
     }
     if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
         $dirPath .= '/';
     }
     $files = glob($dirPath . '*', GLOB_MARK);
     foreach ($files as $file) {
         if (is_dir($file)) {
             util::rdel($file);
         } else {
             unlink($file);
         }
     }
     rmdir($dirPath);
 }