Răsfoiți Sursa

add protection

andre 4 ani în urmă
părinte
comite
22dc793704
2 a modificat fișierele cu 21 adăugiri și 3 ștergeri
  1. 11 2
      index.php
  2. 10 1
      list.php

+ 11 - 2
index.php

@@ -9,9 +9,18 @@ require_once 'stats.php';
 $ip = ip2long(substr(trim($_GET['ip']),0,15));
 $ip = ip2long(substr(trim($_GET['ip']),0,15));
 $token = substr(trim($_GET['token']),0,32);
 $token = substr(trim($_GET['token']),0,32);
 $action = substr(trim($_GET['action']),0,9);
 $action = substr(trim($_GET['action']),0,9);
+$clientIP = ip2long(substr(trim($_SERVER['REMOTE_ADDR']),0,15));
+
 $stats = true;
 $stats = true;
+$act = new action;
+
+if($act->isBlocked($clientIP)) {
+    http_response_code(403);
+    exit;
+}
 
 
 if (!(new token)->isReporter($token)) {
 if (!(new token)->isReporter($token)) {
+    $act->block($clientIP);
     echo "client access denied";
     echo "client access denied";
     exit;
     exit;
 }
 }
@@ -20,14 +29,14 @@ if($stats == true) {
 }
 }
 switch($action) {
 switch($action) {
     case 'delist':
     case 'delist':
-        if((new action)->delist($ip)){
+        if($act->delist($ip)){
             echo long2ip($ip) . " delisted\n";
             echo long2ip($ip) . " delisted\n";
         } else {
         } else {
             echo long2ip($ip) . " not delisted\n";
             echo long2ip($ip) . " not delisted\n";
         };
         };
         break;
         break;
     default:
     default:
-        if((new action)->list($ip)){
+        if($act->list($ip)){
             echo " inserted " . long2ip($ip) ."\n";
             echo " inserted " . long2ip($ip) ."\n";
         } else {
         } else {
             echo " fehler\n";
             echo " fehler\n";

+ 10 - 1
list.php

@@ -5,13 +5,22 @@ require_once 'action.php';
 require_once 'db.php';
 require_once 'db.php';
 require_once 'token.php';
 require_once 'token.php';
 
 
+$clientIP = ip2long(substr(trim($_SERVER['REMOTE_ADDR']),0,15));
 $token = substr(trim($_GET['token']),0,32);
 $token = substr(trim($_GET['token']),0,32);
 
 
+$act= new act;
+
+if($act->isBlocked($clientIP)) {
+    http_response_code(403);
+    exit;
+}
+
 if (!(new token)->isConsumer($token)) {
 if (!(new token)->isConsumer($token)) {
+    $act->block($clientIP);
     echo "user access denied";
     echo "user access denied";
     exit;
     exit;
 }
 }
-$list = (new action)->getBlockList();
+$list = $act->getBlockList();
 foreach($list as $ip) {
 foreach($list as $ip) {
     echo long2ip($ip) . PHP_EOL;
     echo long2ip($ip) . PHP_EOL;
 }
 }