From 2840bf22931acc060b57d2da99eb65ae3cf338e7 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 3 Oct 2015 23:16:40 +0200 Subject: [PATCH 1/2] New option to permit crawlers --- include/network.php | 15 ++++++++++++--- mod/search.php | 27 +++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) 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'); From 42ad8c2b25ddc33398c8fc268b2cccae11da5de7 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 3 Oct 2015 23:19:09 +0200 Subject: [PATCH 2/2] New template for http status messages --- view/templates/http_status.tpl | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 view/templates/http_status.tpl 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}}

+ +