コード例 #1
0
 private function on_get()
 {
     $response = array();
     if (has_request_param("setup")) {
         use_request_param("setup");
         $response["setup"] = $this->app->get_setup();
     }
     if (has_request_param("options")) {
         use_request_param("options");
         $response["options"] = $this->app->get_options();
     }
     if (has_request_param("types")) {
         use_request_param("types");
         $response["types"] = $this->app->get_types();
     }
     if (has_request_param("theme")) {
         use_request_param("theme");
         $response["theme"] = $this->app->get_theme();
     }
     if (has_request_param("langs")) {
         use_request_param("langs");
         $response["langs"] = $this->app->get_l10n_list();
     }
     if (has_request_param("l10n")) {
         use_request_param("l10n");
         $iso_codes = use_request_param("l10nCodes");
         $iso_codes = explode(":", $iso_codes);
         $response["l10n"] = $this->app->get_l10n($iso_codes);
     }
     if (has_request_param("custom")) {
         use_request_param("custom");
         $url = use_request_param("customHref");
         $response["custom"] = $this->app->get_customizations($url);
     }
     if (has_request_param("items")) {
         use_request_param("items");
         $url = use_request_param("itemsHref");
         $what = use_request_param("itemsWhat");
         $what = is_numeric($what) ? intval($what, 10) : 1;
         $response["items"] = $this->app->get_items($url, $what);
     }
     if (has_request_param("all_items")) {
         use_request_param("all_items");
         $response["all_items"] = $this->app->get_all_items();
     }
     if (AS_ADMIN && count($_REQUEST)) {
         $response["unused"] = $_REQUEST;
     }
     json_exit($response);
 }
コード例 #2
0
ファイル: index.php プロジェクト: jreinert/h5ai
define("PASSHASH", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
function normalized_require_once($lib)
{
    require_once preg_replace("#[\\\\/]+#", "/", dirname(__FILE__) . "/inc/{$lib}.php");
}
normalized_require_once("util");
normalized_require_once("setup");
normalized_require_once("class-api");
normalized_require_once("class-app");
normalized_require_once("class-archive");
normalized_require_once("class-item");
normalized_require_once("class-thumb");
normalized_require_once("class-image");
setup();
$app = new App();
$options = $app->get_options();
if ($options["security"]["enabled"] && (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] !== $options["security"]["login"] || md5($_SERVER['PHP_AUTH_PW']) !== md5($options["security"]["password"]) || !(empty($options["security"]["allowedips"]) || in_array($_SERVER['REMOTE_ADDR'], $options["security"]["allowedips"])))) {
    header('WWW-Authenticate: Basic realm=' . $options["security"]["message"]);
    header('HTTP/1.0 401 Unauthorized');
    echo 'Access forbidden';
    exit;
} else {
    if (has_request_param("action")) {
        //	header("Content-type: application/json;charset=utf-8");
        $api = new Api($app);
        $api->apply();
    } else {
        define("FALLBACK", $app->get_fallback());
        normalized_require_once("page");
    }
}
コード例 #3
0
ファイル: setup.php プロジェクト: Anoniji/fr._h5ai.custom
function setup()
{
    // MISC
    putenv("LANG=en_US.UTF-8");
    setlocale(LC_CTYPE, "en_US.UTF-8");
    date_default_timezone_set("UTC");
    define("NAME", "h5ai");
    define("VERSION", "0.26.1");
    define("STAMP", "");
    define("BACKEND", "PHP");
    define("API", true);
    define("FILE_PREFIX", "_h5ai");
    // ADMIN
    session_start();
    define("AS_ADMIN_SESSION_KEY", "__H5AI_AS_ADMIN__");
    define("AS_ADMIN", isset($_SESSION[AS_ADMIN_SESSION_KEY]) && $_SESSION[AS_ADMIN_SESSION_KEY] === true);
    define("HAS_CUSTOM_PASSHASH", PASSHASH !== "da39a3ee5e6b4b0d3255bfef95601890afd80709");
    // PHP
    define("MIN_PHP_VERSION", "5.3.0");
    define("HAS_PHP_VERSION", version_compare(PHP_VERSION, MIN_PHP_VERSION) >= 0);
    define("HAS_PHP_EXIF", function_exists("exif_thumbnail"));
    $has_php_jpg = false;
    if (function_exists("gd_info")) {
        $infos = gd_info();
        $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);
    // SERVER
    $server_name = null;
    $server_version = null;
    $server_software = getenv("SERVER_SOFTWARE");
    if ($server_software && preg_match("#^(.*?)(?:/(.*?))?(?: |\$)#", strtolower($server_software), $matches)) {
        $server_name = $matches[1];
        $server_version = count($matches) > 2 ? $matches[2] : '';
    }
    define("SERVER_NAME", $server_name);
    define("SERVER_VERSION", $server_version);
    define("HAS_SERVER", in_array($server_name, array("apache", "lighttpd", "nginx", "cherokee")));
    define("HAS_WIN_OS", strtolower(substr(PHP_OS, 0, 3)) === "win");
    // PATHS
    $script_name = getenv("SCRIPT_NAME");
    if (SERVER_NAME === "lighttpd") {
        $script_name = preg_replace("#^.*?//#", "/", $script_name);
    }
    define("APP_HREF", normalize_path(dirname(dirname(dirname($script_name))), true));
    define("APP_PATH", normalize_path(dirname(dirname(dirname(dirname(__FILE__)))), false));
    define("ROOT_HREF", normalize_path(dirname(APP_HREF), true));
    define("ROOT_PATH", normalize_path(dirname(APP_PATH), false));
    $uri_parts = parse_url(getenv("REQUEST_URI"));
    $current_href = normalize_path($uri_parts["path"], true);
    $rel_href = substr($current_href, strlen(ROOT_HREF));
    $current_path = normalize_path(ROOT_PATH . "/" . rawurldecode($rel_href));
    if (!is_dir($current_path)) {
        $current_href = normalize_path(dirname($current_href), true);
        $current_path = normalize_path(dirname($current_path), false);
    }
    define("CURRENT_HREF", $current_href);
    define("CURRENT_PATH", $current_path);
    $index_href = null;
    if (@is_readable(normalize_path(APP_PATH . "/server/php/index.php", false))) {
        $index_href = normalize_path(APP_HREF . "/server/php/index.php", false);
    }
    define("INDEX_HREF", $index_href);
    define("CACHE_HREF", normalize_path(APP_HREF . "/cache", true));
    define("CACHE_PATH", normalize_path(APP_PATH . "/cache", false));
    define("HAS_WRITABLE_CACHE", @is_writable(CACHE_PATH));
    define("CMDS_PATH", normalize_path(CACHE_PATH . "/cmds.json", false));
    // EXTERNAL COMMANDS
    $cmds = load_commented_json(CMDS_PATH);
    if (sizeof($cmds) === 0 || has_request_param("updatecmds")) {
        $cmds["command"] = exec_0("command -v command");
        $cmds["which"] = exec_0("which which");
        $cmd = false;
        if ($cmds["command"]) {
            $cmd = "command -v";
        } else {
            if ($cmds["which"]) {
                $cmd = "which";
            }
        }
        foreach (array("tar", "zip", "convert", "ffmpeg", "avconv", "du") as $c) {
            $cmds[$c] = $cmd !== false && exec_0($cmd . " " . $c);
        }
        safe_json(CMDS_PATH, $cmds);
    }
    foreach ($cmds as $c => $has) {
        define("HAS_CMD_" . strtoupper($c), $has);
    }
}