Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (46 sloc) 1.57 KB
<?
require_once("config.inc.php");
require(POUETAPI_POUET_ROOT_LOCAL . "/bootstrap.inc.php");
// rate limit
if ($ephemeralStorage && POUETAPI_RATELIMIT_TIMEFRAME && POUETAPI_RATELIMIT_REQUESTCOUNT)
{
$key = "API_RATE_" . $_SERVER["REMOTE_ADDR"];
$rateLimit = array("hits"=>0,"start"=>time());
if ($ephemeralStorage->has( $key ))
{
$rateLimit = $ephemeralStorage->get( $key );
}
$rateLimit["hits"]++;
if (time() - $rateLimit["start"] < POUETAPI_RATELIMIT_TIMEFRAME)
{
if ($rateLimit["hits"] >= POUETAPI_RATELIMIT_REQUESTCOUNT)
{
header("HTTP/1.1 429 Too Many Requests");
die(sprintf("<html><body><h1>HTTP 429 - Too Many Requests</h1>".
"You have exhausted your request limit of %d requests under %d seconds; you can restart in %d seconds.</body></html>",
POUETAPI_RATELIMIT_REQUESTCOUNT, POUETAPI_RATELIMIT_TIMEFRAME, POUETAPI_RATELIMIT_TIMEFRAME - (time() - $rateLimit["start"]) ));
}
}
else
{
$rateLimit["start"] = time();
$rateLimit["hits"] = 0;
}
$ephemeralStorage->set($key, $rateLimit);
}
// render
$r = new Rewriter();
$r->addRules(array(
"^\/+v1\/prod\/?$" => "v1_prod.php",
"^\/+v1\/prod\/comments\/?$" => "v1_prod_comments.php",
"^\/+v1\/search\/prod\/?$" => "v1_search_prod.php",
"^\/+v1\/group\/?$" => "v1_group.php",
"^\/+v1\/party\/?$" => "v1_party.php",
"^\/+v1\/user\/?$" => "v1_user.php",
"^\/+v1\/stats\/?$" => "v1_stats.php",
"^\/+adhoc\/prods-from-year\/?$" => "adhoc_prods_year.php",
));
$r->addBootstrap("./functions.inc.php");
$r->addEntryPoint("POUET_API");
$r->rewrite();
?>