public function get($id) { if ((int) $this->check_access() < 9) { $this->response(null, null, 401); } $list_url = ""; switch ($id) { case "extension": $list = $this->ext_list; break; case "category": $list = $this->cat_list; break; case "handle": $list = $this->han_list; break; default: $this->response(null, null, 400); break; } $repo_file = RazorFileTools::get_remote_content($this->repo_url . $list); if (!empty($repo_file)) { $repo = json_decode($repo_file); $this->response(array("list" => $repo), "json"); } // send back unnavailable $this->response(null, null, 404); }
public function post($data) { if ((int) $this->check_access() < 9) { $this->response(null, null, 401); } if (empty($data) || !isset($data["type"]) || !isset($data["handle"]) || !isset($data["extension"])) { $this->response(null, null, 400); } if (!isset($data["manifests"]) && !isset($data["manifest"])) { $this->response(null, null, 400); } // fetch cleaned data $manifest = preg_replace('/[^a-zA-Z0-9-_]/', '', isset($data["manifests"][0]) ? $data["manifests"][0] : $data["manifest"]); // grab first only $category = preg_replace('/[^a-zA-Z0-9-_]/', '', strtolower($data["type"])); $handle = preg_replace('/[^a-zA-Z0-9-_]/', '', strtolower($data["handle"])); $name = preg_replace('/[^a-zA-Z0-9-_]/', '', strtolower($data["extension"])); // fetch details $man_url = $this->repo_url . "extension/{$category}/{$handle}/{$name}/{$manifest}.manifest.json"; $details_file = RazorFileTools::get_remote_content($man_url); if (!empty($details_file)) { $details = json_decode($details_file); $this->response(array("details" => $details), "json"); } // send back not found if no details $this->response(null, null, 404); }
private function package_system_upgrade() { if ((int) $this->check_access() < 10) { $this->response(null, null, 401); } $file_contents = RazorFileTools::get_remote_content($this->upgrade_url); if (empty($file_contents)) { $this->response(null, null, 404); } if (!RazorFileTools::write_file_contents("{$this->package_path}/system_upgrade.zip", $file_contents)) { throw new Exception("Could not write upgrade file to storage/tmp/package."); } $this->response("success", "json"); }
public function get($id) { if ($id != "current") { $this->response(null, null, 400); } $host = isset($_SERVER["SERVER_NAME"]) ? urlencode($_SERVER["SERVER_NAME"]) : (isset($_SERVER["HTTP_HOST"]) ? urlencode($_SERVER["HTTP_HOST"]) : "current"); $version_file = RazorFileTools::get_remote_content($this->check_url . $host); if (!empty($version_file)) { $version = json_decode($version_file); $this->response($version, "json"); } else { // send back unnavailable $this->response(null, null, 404); } // send back unnavailable $this->response(null, null, 404); }
public function post($data) { if ((int) $this->check_access() < 9) { $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"; $package_contents = RazorFileTools::get_remote_content($package_url); // copy package to temp location 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); }