mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 20:14:37 -04:00
Refactor PHP setup.
This commit is contained in:
parent
77d6da3a24
commit
6e54ba2f73
2 changed files with 32 additions and 12 deletions
|
@ -2,12 +2,11 @@
|
||||||
|
|
||||||
class Api {
|
class Api {
|
||||||
|
|
||||||
private $actions, $app;
|
private $app;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($app) {
|
public function __construct($app) {
|
||||||
|
|
||||||
$this->actions = array("login", "logout", "get", "getThumbHref", "download");
|
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +14,8 @@ class Api {
|
||||||
public function apply() {
|
public function apply() {
|
||||||
|
|
||||||
$action = Util::get_request_param("action");
|
$action = Util::get_request_param("action");
|
||||||
Util::json_fail(Util::RC_UNSUPPORTED, "unsupported action", !in_array($action, $this->actions));
|
$supported = array("login", "logout", "get", "getThumbHref", "download");
|
||||||
|
Util::json_fail(Util::RC_UNSUPPORTED, "unsupported action", !in_array($action, $supported));
|
||||||
|
|
||||||
$methodname = "on_${action}";
|
$methodname = "on_${action}";
|
||||||
$this->$methodname();
|
$this->$methodname();
|
||||||
|
|
|
@ -4,7 +4,13 @@ class Bootstrap {
|
||||||
|
|
||||||
public static function run() {
|
public static function run() {
|
||||||
|
|
||||||
Bootstrap::setup();
|
Bootstrap::setup_misc();
|
||||||
|
Bootstrap::setup_admin();
|
||||||
|
Bootstrap::setup_php();
|
||||||
|
Bootstrap::setup_server();
|
||||||
|
Bootstrap::setup_paths();
|
||||||
|
Bootstrap::setup_cache();
|
||||||
|
Bootstrap::setup_ext_cmds();
|
||||||
|
|
||||||
$app = new App();
|
$app = new App();
|
||||||
if (Util::is_post_request()) {
|
if (Util::is_post_request()) {
|
||||||
|
@ -17,9 +23,8 @@ class Bootstrap {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function setup() {
|
private static function setup_misc() {
|
||||||
|
|
||||||
// MISC
|
|
||||||
putenv("LANG=en_US.UTF-8");
|
putenv("LANG=en_US.UTF-8");
|
||||||
setlocale(LC_CTYPE, "en_US.UTF-8");
|
setlocale(LC_CTYPE, "en_US.UTF-8");
|
||||||
date_default_timezone_set("UTC");
|
date_default_timezone_set("UTC");
|
||||||
|
@ -30,16 +35,20 @@ class Bootstrap {
|
||||||
define("BACKEND", "PHP");
|
define("BACKEND", "PHP");
|
||||||
define("API", true);
|
define("API", true);
|
||||||
define("FILE_PREFIX", "_{{pkg.name}}");
|
define("FILE_PREFIX", "_{{pkg.name}}");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ADMIN
|
private static function setup_admin() {
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
define("AS_ADMIN_SESSION_KEY", "__H5AI_AS_ADMIN__");
|
define("AS_ADMIN_SESSION_KEY", "__H5AI_AS_ADMIN__");
|
||||||
define("AS_ADMIN", isset($_SESSION[AS_ADMIN_SESSION_KEY]) && $_SESSION[AS_ADMIN_SESSION_KEY] === true);
|
define("AS_ADMIN", isset($_SESSION[AS_ADMIN_SESSION_KEY]) && $_SESSION[AS_ADMIN_SESSION_KEY] === true);
|
||||||
define("HAS_CUSTOM_PASSHASH", PASSHASH !== "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
define("HAS_CUSTOM_PASSHASH", PASSHASH !== "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// PHP
|
private static function setup_php() {
|
||||||
|
|
||||||
define("MIN_PHP_VERSION", "5.4.0");
|
define("MIN_PHP_VERSION", "5.4.0");
|
||||||
define("HAS_MIN_PHP_VERSION", version_compare(PHP_VERSION, MIN_PHP_VERSION) >= 0);
|
define("HAS_MIN_PHP_VERSION", version_compare(PHP_VERSION, MIN_PHP_VERSION) >= 0);
|
||||||
define("HAS_PHP_EXIF", function_exists("exif_thumbnail"));
|
define("HAS_PHP_EXIF", function_exists("exif_thumbnail"));
|
||||||
|
@ -49,9 +58,11 @@ class Bootstrap {
|
||||||
$has_php_jpg = array_key_exists("JPG Support", $infos) && $infos["JPG Support"] || array_key_exists("JPEG Support", $infos) && $infos["JPEG Support"];
|
$has_php_jpg = array_key_exists("JPG Support", $infos) && $infos["JPG Support"] || array_key_exists("JPEG Support", $infos) && $infos["JPEG Support"];
|
||||||
}
|
}
|
||||||
define("HAS_PHP_JPG", $has_php_jpg);
|
define("HAS_PHP_JPG", $has_php_jpg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// SERVER
|
private static function setup_server() {
|
||||||
|
|
||||||
$server_name = null;
|
$server_name = null;
|
||||||
$server_version = null;
|
$server_version = null;
|
||||||
$server_software = getenv("SERVER_SOFTWARE");
|
$server_software = getenv("SERVER_SOFTWARE");
|
||||||
|
@ -63,9 +74,11 @@ class Bootstrap {
|
||||||
define("SERVER_VERSION", $server_version);
|
define("SERVER_VERSION", $server_version);
|
||||||
define("HAS_SERVER", in_array($server_name, array("apache", "lighttpd", "nginx", "cherokee")));
|
define("HAS_SERVER", in_array($server_name, array("apache", "lighttpd", "nginx", "cherokee")));
|
||||||
define("HAS_WIN_OS", strtolower(substr(PHP_OS, 0, 3)) === "win");
|
define("HAS_WIN_OS", strtolower(substr(PHP_OS, 0, 3)) === "win");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// PATHS
|
private static function setup_paths() {
|
||||||
|
|
||||||
$script_name = getenv("SCRIPT_NAME");
|
$script_name = getenv("SCRIPT_NAME");
|
||||||
if (SERVER_NAME === "lighttpd") {
|
if (SERVER_NAME === "lighttpd") {
|
||||||
$script_name = preg_replace("#^.*?//#", "/", $script_name);
|
$script_name = preg_replace("#^.*?//#", "/", $script_name);
|
||||||
|
@ -92,14 +105,21 @@ class Bootstrap {
|
||||||
$index_href = Util::normalize_path(APP_HREF . "/server/php/index.php", false);
|
$index_href = Util::normalize_path(APP_HREF . "/server/php/index.php", false);
|
||||||
}
|
}
|
||||||
define("INDEX_HREF", $index_href);
|
define("INDEX_HREF", $index_href);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static function setup_cache() {
|
||||||
|
|
||||||
define("CACHE_HREF", Util::normalize_path(APP_HREF . "/cache", true));
|
define("CACHE_HREF", Util::normalize_path(APP_HREF . "/cache", true));
|
||||||
define("CACHE_PATH", Util::normalize_path(APP_PATH . "/cache", false));
|
define("CACHE_PATH", Util::normalize_path(APP_PATH . "/cache", false));
|
||||||
define("HAS_WRITABLE_CACHE", @is_writable(CACHE_PATH));
|
define("HAS_WRITABLE_CACHE", @is_writable(CACHE_PATH));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static function setup_ext_cmds() {
|
||||||
|
|
||||||
define("CMDS_PATH", Util::normalize_path(CACHE_PATH . "/cmds.json", false));
|
define("CMDS_PATH", Util::normalize_path(CACHE_PATH . "/cmds.json", false));
|
||||||
|
|
||||||
|
|
||||||
// EXTERNAL COMMANDS
|
|
||||||
$cmds = Util::load_commented_json(CMDS_PATH);
|
$cmds = Util::load_commented_json(CMDS_PATH);
|
||||||
if (sizeof($cmds) === 0 || Util::get_boolean_request_param("updatecmds", false)) {
|
if (sizeof($cmds) === 0 || Util::get_boolean_request_param("updatecmds", false)) {
|
||||||
$cmds["command"] = Util::exec_0("command -v command");
|
$cmds["command"] = Util::exec_0("command -v command");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue