viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]

Add more details to FetchController's response on a bad request, a=chris

Chris Pollett [2019-01-25 02:Jan:th]
Add more details to FetchController's response on a bad request, a=chris
Filename
src/controllers/Controller.php
src/controllers/FetchController.php
src/library/WebSite.php
diff --git a/src/controllers/Controller.php b/src/controllers/Controller.php
index 9c61f9851..b56040f04 100755
--- a/src/controllers/Controller.php
+++ b/src/controllers/Controller.php
@@ -893,12 +893,18 @@ abstract class Controller
         if (empty($_REQUEST['time']) ||
             empty($_REQUEST['session']) || (
             !in_array($_REQUEST['a'], $this->activities)
-            && $_REQUEST['c'] != 'jobs' )) { return false; }
+            && $_REQUEST['c'] != 'jobs' )) {
+            return false;
+        }
         $time = $_REQUEST['time'];
             // request must be within an hour of this machine's clock
-        if (abs(time() - $time) > C\ONE_HOUR) { return false;}
+        if (abs(time() - $time) > C\ONE_HOUR) {
+            return false;
+        }
         $session = $_REQUEST['session'];
-        if (md5($time . C\AUTH_KEY) != $session) { return false; }
+        if (md5($time . C\AUTH_KEY) != $session) {
+            return false;
+        }
         return true;
     }
     /**
diff --git a/src/controllers/FetchController.php b/src/controllers/FetchController.php
index 5acd87690..e32b53bd2 100755
--- a/src/controllers/FetchController.php
+++ b/src/controllers/FetchController.php
@@ -80,6 +80,14 @@ class FetchController extends Controller implements CrawlConstants
            from a legitimate machine
          */
         if (!$this->checkRequest()) {
+            $this->web_site->header("HTTP/1.0 400 Bad Request");
+            $request = [];
+            echo "BAD REQUEST!\n";
+            foreach(['time', 'session', 'a', 'c'] as $part) {
+                if (!empty($_REQUEST[$part])) {
+                    echo $_REQUEST[$part] . "\n";
+                }
+            }
             return;
         }
         $activity = $_REQUEST['a'];
@@ -527,7 +535,7 @@ class FetchController extends Controller implements CrawlConstants
     {
         $crawl_time = substr($this->clean($_REQUEST['crawl_time'], "int"), 0,
             C\TIMESTAMP_LEN);
-        $dir = C\CRAWL_DIR . "/schedules/".$schedule_name . $crawl_time;
+        $dir = C\CRAWL_DIR . "/schedules/" . $schedule_name . $crawl_time;
         $address = str_replace(".", "-", L\remoteAddress());
         $address = str_replace(":", "_", $address);
         $time = time();
diff --git a/src/library/WebSite.php b/src/library/WebSite.php
index a751bc798..f65628475 100644
--- a/src/library/WebSite.php
+++ b/src/library/WebSite.php
@@ -651,7 +651,7 @@ class WebSite
             }
         }
         $num_bytes = file_put_contents($filename, $data);
-        chmod($filename, 0777);
+        @chmod($filename, 0777);
         return $num_bytes;
     }
     /**
ViewGit