Example #1
0
 public function get($type)
 {
     if ((int) $this->check_access() < 10 || empty($type)) {
         $this->response(null, null, 401);
     }
     if ($type != "full") {
         $this->response(null, null, 400);
     }
     // compress the whole system to a single zip backup file
     $zip = new RazorZip();
     $time = time();
     $zip->open("{$this->backup_path}/upgrade_backup_{$time}.zip", ZipArchive::CREATE);
     $zip->add_dir(RAZOR_BASE_PATH);
     $zip->close();
     $this->response(array("backup" => "{$this->backup_url}/upgrade_backup_{$time}.zip"), "json");
 }
Example #2
0
 public function post($data)
 {
     if ((int) $this->check_access() < 10) {
         $this->response(null, null, 401);
     }
     if (empty($data) || !isset($data["type"]) || !isset($data["handle"]) || !isset($data["extension"])) {
         $this->response(null, null, 400);
     }
     // fetch cleaned data
     $category = preg_replace('/[^a-zA-Z0-9-_]/', '', $data["type"]);
     $handle = preg_replace('/[^a-zA-Z0-9-_]/', '', $data["handle"]);
     $name = preg_replace('/[^a-zA-Z0-9-_]/', '', $data["extension"]);
     // fetch details
     $package_url = $this->package_url . "{$category}/{$handle}/{$name}/{$name}.zip";
     $headers = @get_headers($package_url);
     if (strpos($headers[0], "404") === false) {
         $ctx = stream_context_create(array('http' => array('timeout' => 60)));
         // copy package to temp location
         $package_contents = @file_get_contents($package_url, false, $ctx);
         if (!empty($package_contents)) {
             if (!RazorFileTools::write_file_contents("{$this->tmp_package_path}/{$name}.zip", $package_contents)) {
                 throw new Exception("Could not write upgrade file to storage/tmp/package.");
             }
         }
         // extract to file system
         if (!is_file("{$this->tmp_package_path}/{$name}.zip")) {
             throw new exception("Extension file not found.");
         }
         // open extension package
         $zip = new RazorZip();
         $zip->open("{$this->tmp_package_path}/{$name}.zip");
         // extract
         $zip->extractTo(RAZOR_BASE_PATH);
         $zip->close();
         // cleanup
         RazorFileTools::delete_directory($this->tmp_path);
         // send back not found if no details
         $this->response("success", "json");
     }
     // send back not found if no details
     $this->response(null, null, 404);
 }
Example #3
0
 public function post($data)
 {
     if ((int) $this->check_access() < 10) {
         $this->response(null, null, 401);
     }
     if (!isset($data["backup"])) {
         $this->response(null, null, 400);
     }
     $parts = explode("/", $data["backup"]);
     $file = end($parts);
     if (!is_file("{$this->backup_path}/{$file}")) {
         throw new exception("Upgrade file not found.");
     }
     // open backup
     $zip = new RazorZip();
     $zip->open("{$this->backup_path}/{$file}");
     /* UPGRADE */
     $zip->extractTo(RAZOR_BASE_PATH);
     $zip->close();
     // remove tmp files
     RazorFileTools::delete_directory($this->tmp_path);
     $this->response("success", "json");
 }