diff --git a/include/network.php b/include/network.php index 02b2d7c2ae..2815e1ab85 100644 --- a/include/network.php +++ b/include/network.php @@ -309,16 +309,25 @@ function xml_status($st, $message = '') { if(! function_exists('http_status_exit')) { -function http_status_exit($val) { - +function http_status_exit($val, $description = array()) { $err = ''; - if($val >= 400) + if($val >= 400) { $err = 'Error'; + if (!isset($description["title"])) + $description["title"] = $err." ".$val; + } if($val >= 200 && $val < 300) $err = 'OK'; logger('http_status_exit ' . $val); header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err); + + if (isset($description["title"])) { + $tpl = get_markup_template('http_status.tpl'); + echo replace_macros($tpl, array('$title' => $description["title"], + '$description' => $description["description"])); + } + killme(); }} diff --git a/mod/search.php b/mod/search.php index 251dd4778f..c15dfae3fe 100644 --- a/mod/search.php +++ b/mod/search.php @@ -95,10 +95,29 @@ function search_content(&$a) { } if(get_config('system','local_search') AND !local_user()) { - notice(t('Public access denied.').EOL); - return; - //http_status_exit(403); - //killme(); + http_status_exit(403, + array("title" => t("Public access denied."), + "description" => t("Only logged in users are permitted to perform a search."))); + killme(); + //notice(t('Public access denied.').EOL); + //return; + } + + if (get_config('system','permit_crawling') AND !local_user()) { + // To-Do: + // - 10 requests are "free", after the 11th only a call per minute is allowed + + $remote = $_SERVER["REMOTE_ADDR"]; + $result = Cache::get("remote_search:".$remote); + if (!is_null($result)) { + if ($result > (time() - 60)) { + http_status_exit(429, + array("title" => t("Too Many Requests"), + "description" => t("Only one search per minute is permitted for not logged in users."))); + killme(); + } + } + Cache::set("remote_search:".$remote, time(), CACHE_HOUR); } nav_set_selected('search'); diff --git a/view/templates/http_status.tpl b/view/templates/http_status.tpl new file mode 100644 index 0000000000..55cc133ff0 --- /dev/null +++ b/view/templates/http_status.tpl @@ -0,0 +1,9 @@ + + + {{$title}} + + +

{{$title}}

+

{{$description}}

+ +