public function delete($id) { if ((int) $this->check_access() < 9) { $this->response(null, null, 401); } if (empty($id)) { $this->response(null, null, 400); } $parts = explode("__", strtolower($id)); if (count($parts) != 3) { $this->response(null, null, 400); } $category = preg_replace('/[^a-z0-9-_]/', '', $parts[0]); $handle = preg_replace('/[^a-z0-9-_]/', '', $parts[1]); $extension = preg_replace('/[^a-z0-9-_]/', '', $parts[2]); $remove_path = "{$this->ext_path}/{$category}/{$handle}/{$extension}"; $rars_remove_path = "{$this->rars_path}/{$category}/{$handle}/{$extension}"; if (!is_dir($remove_path)) { $this->response(null, null, 400); } if (RazorFileTools::delete_directory($remove_path)) { if (is_dir($rars_remove_path)) { RazorFileTools::delete_directory($rars_remove_path); } $this->response("success", "json"); } $this->response(null, null, 400); }
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); }
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"); }