]> git.mxchange.org Git - friendica.git/commitdiff
New option to permit crawlers
authorMichael Vogel <icarus@dabo.de>
Sat, 3 Oct 2015 21:16:40 +0000 (23:16 +0200)
committerMichael Vogel <icarus@dabo.de>
Sat, 3 Oct 2015 21:16:40 +0000 (23:16 +0200)
include/network.php
mod/search.php

index 02b2d7c2aed1c25325754b154a8677d6dcf6e8d7..2815e1ab851e7a4f094e966b13332cfe0f8241ad 100644 (file)
@@ -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();
 
 }}
index 251dd4778f37b52545d2ee817e408ba2df47d617..c15dfae3fea8d981cf74efe685f9fef59078413f 100644 (file)
@@ -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');