예제 #1
0
    exit;
}
# Unavailable is distinct from disabled in that it's used to account
# for nginx's lack of a decent health check plugin that both checks
# health and removes nodes from its list of upstreams. And to make matters
# worse 501 (Not Implemented) errors are not supported by nginx's
# 'proxy_next_upstream' directive. So we're just going to use 502 and
# carry on... (20130913/straup)
if ($GLOBALS['cfg']['site_unavailable'] && !$this_is_shell) {
    loadlib("http_codes");
    $codes = http_codes();
    $code = 502;
    $status = "{$code} {$codes[$code]}";
    if ($this_is_api) {
        loadlib("api");
        api_config_freakout_and_die($code, "Not implemented");
    }
    header("HTTP/1.1 {$status}");
    header("Status: {$status}");
    $smarty->display("page_site_unavailable.txt");
    exit;
}
#
# Smarty stuff
#
$GLOBALS['error'] = array();
$GLOBALS['smarty']->assign_by_ref('error', $error);
#
# Hey look! Running code! Note that db_init will try
# to automatically connect to the db_main database
# (unless you've disable the 'auto_connect' flag) and
예제 #2
0
function api_config_init()
{
    $GLOBALS['cfg']['api_server_scheme'] = $GLOBALS['cfg']['api_require_ssl'] ? 'https' : 'http';
    $GLOBALS['cfg']['api_server_name'] = parse_url($GLOBALS['cfg']['abs_root_url'], PHP_URL_HOST);
    $GLOBALS['cfg']['api_server_port'] = parse_url($GLOBALS['cfg']['abs_root_url'], PHP_URL_PORT);
    if ($GLOBALS['cfg']['api_server_port']) {
        # these are chunked in to separate statements just because they are
        # long and hard to read as a single test (20160212/thisisaaronland)
        if ($GLOBALS['cfg']['api_server_scheme'] == 'http' && $GLOBALS['cfg']['api_server_port'] != 80) {
            $GLOBALS['cfg']['api_server_name'] .= ':' . $GLOBALS['cfg']['api_server_port'];
        } else {
            if ($GLOBALS['cfg']['api_server_scheme'] == 'https' && $GLOBALS['cfg']['api_server_port'] != 443) {
                $GLOBALS['cfg']['api_server_name'] .= ':' . $GLOBALS['cfg']['api_server_port'];
            } else {
            }
        }
    }
    if ($GLOBALS['cfg']['abs_root_suffix']) {
        $GLOBALS['cfg']['api_abs_root_url'] = $GLOBALS['cfg']['api_abs_root_url'] . $GLOBALS['cfg']['abs_root_suffix'] . "/";
    }
    # If I have an API specific subdomain/prefix then check to see if I am already
    # running on that host; if not then update the 'api_server_name' config
    if ($GLOBALS['cfg']['api_subdomain'] && !preg_match("/^{$GLOBALS['cfg']['api_subdomain']}/", $GLOBALS['cfg']['api_server_name'])) {
        $GLOBALS['cfg']['api_server_name'] = $GLOBALS['cfg']['api_subdomain'] . $GLOBALS['cfg']['api_server_name'];
    }
    # Build the 'api_abs_root_url' based on everything above
    if ($GLOBALS['cfg']['abs_root_suffix']) {
        $GLOBALS['cfg']['api_abs_root_url'] = $GLOBALS['cfg']['api_abs_root_url'] . $GLOBALS['cfg']['abs_root_suffix'] . "/";
    }
    $GLOBALS['cfg']['api_abs_root_url'] = "{$GLOBALS['cfg']['api_server_scheme']}://{$GLOBALS['cfg']['api_server_name']}" . "/";
    # If I have an API specific subdomain/prefix then check to see if I am already
    # running on that host; if I am then update the 'site_abs_root_url' config and
    # use it in your code accordingly.
    if ($GLOBALS['cfg']['api_subdomain'] && preg_match("/^{$GLOBALS['cfg']['api_subdomain']}/", $GLOBALS['cfg']['api_server_name'])) {
        # the old way (20150513/copea)
        # $GLOBALS['cfg']['site_abs_root_url'] = str_replace("{$GLOBALS['cfg']['api_subdomain']}", "", $GLOBALS['cfg']['abs_root_url']);
        $server_name = $GLOBALS['cfg']['api_server_name'];
        $server_name = preg_replace("/^{$GLOBALS['cfg']['api_subdomain']}/", "", $server_name);
        $GLOBALS['cfg']['site_abs_root_url'] = "{$GLOBALS['cfg']['api_server_scheme']}://{$server_name}/";
        # see this – we need to do this because we call $GLOBALS['cfg']['abs_root_url'] all
        # over lib_whatever land (20150513/copea)
        $GLOBALS['cfg']['abs_root_url'] = $GLOBALS['cfg']['site_abs_root_url'];
    } else {
        $GLOBALS['cfg']['site_abs_root_url'] = $GLOBALS['cfg']['abs_root_url'];
    }
    # Load methods / blessings
    # $GLOBALS['timing_keys']["api_config_methods"] = "API methods";
    # $GLOBALS['timings']['api_config_methods_count'] = 0;
    # $GLOBALS['timings']['api_config_methods_time'] = 0;
    $start = microtime_ms();
    foreach ($GLOBALS['cfg']['api_method_definitions'] as $def) {
        try {
            $path = FLAMEWORK_INCLUDE_DIR . "/config_api_{$def}.php";
            include_once $path;
            # $GLOBALS['timings']['api_config_methods_count'] += 1;
        } catch (Exception $e) {
            # $msg = $e->getMessage();
            api_config_freakout_and_die();
        }
    }
    $end = microtime_ms();
    $time = $end - $start;
    # $GLOBALS['timings']['api_config_methods_time'] = $time;
    api_config_init_blessings();
    if ($GLOBALS['this_is_webpage']) {
        $req_features = array("api", "api_site_keys", "api_site_tokens");
        if (features_is_enabled($req_features)) {
            api_config_init_site_keys();
        }
    }
}