Ver Fonte

added debugging feature, fix graph misreporting request ranges in header

lolcat há 1 semana atrás
pai
commit
1f394883bf
3 ficheiros alterados com 53 adições e 34 exclusões
  1. 31 18
      api/v2/graph.php
  2. 15 16
      data/config.php
  3. 7 0
      lib/frontend.php

+ 31 - 18
api/v2/graph.php

@@ -1,5 +1,6 @@
 <?php
 
+header("Content-Type: image/png");
 date_default_timezone_set('America/Toronto');
 include "../../data/config.php";
 
@@ -40,25 +41,37 @@ function get_requests($slug){
 $bot_requests = get_requests("bot_requests");
 $real_requests = get_requests("real_requests");
 
-$real_reqs_24h = 0;
-for($i=0; $i<count($real_requests); $i++){
-	
-	if($real_requests[$i][1] !== false){
-		
-		$real_reqs_24h += $real_requests[$i][1];
-	}
-}
+$real_reqs_8h =
+	array_sum(
+		array_column(
+			array_slice(
+				$real_requests,
+				0,
+				8
+			),
+			1
+		)
+	);
 
-$real_reqs_72h = 0;
-for($i=0; $i<count($real_requests); $i++){
-	
-	if($real_requests[$i][1] !== false){
-		
-		$real_reqs_72h += $real_requests[$i][1];
-	}
-}
+$real_reqs_24h =
+	array_sum(
+		array_column(
+			array_slice(
+				$real_requests,
+				0,
+				24
+			),
+			1
+		)
+	);
 
-header("Content-Type: image/png");
+$real_reqs_72h =
+	array_sum(
+		array_column(
+			$real_requests,
+			1
+		)
+	);
 
 include "../../lib/graph_gen.php";
 $graph = new graph();
@@ -75,7 +88,7 @@ if($c > 25){
 
 echo $graph->render([
 	"title" => "Number of requests within the last 72 hours (non-cummulative)",
-	"subtitle" => date("jS M y @ g:ia", time()) . " || 24h=" . number_format($real_reqs_24h) . ", 72h=" . number_format($real_reqs_72h) . " || " . config::SERVER_NAME,
+	"subtitle" => date("jS M y @ g:ia", time()) . " || 8h=" . number_format($real_reqs_8h) . " - 24h=" . number_format($real_reqs_24h) . " - 72h=" . number_format($real_reqs_72h) . " || " . config::SERVER_NAME,
 	"x_label" => "<= Hours passed =>",
 	"y_label" => "<= Request count/hour =>",
 	"grad_x" => $c,

+ 15 - 16
data/config.php

@@ -23,6 +23,9 @@ class config{
 	// Enable the API?
 	const API_ENABLED = true;
 	
+	// Display errors. This should ONLY be enabled for debugging and constitutes a security risk.
+	const DISPLAY_ERRORS = false;
+	
 	//
 	// 4play settings
 	//
@@ -106,30 +109,26 @@ class config{
 	// eachother your serber should appear everywhere.
 	const INSTANCES = [
 		"https://4get.ca",
-		"https://4get.zzls.xyz",
-		"https://4getus.zzls.xyz",
+		"https://search.fischbytes.de",
+		"https://4get.nadeko.net",
 		"https://4get.silly.computer",
-		"https://4get.konakona.moe",
-		"https://4get.lvkaszus.pl",
-		"https://4g.ggtyler.dev",
-		"https://4get.perennialte.ch",
 		"https://4get.sijh.net",
 		"https://4get.hbubli.cc",
-		"https://4get.plunked.party",
-		"https://4get.etenie.pl",
 		"https://4get.lunar.icu",
 		"https://4get.dcs0.hu",
-		"https://4get.kizuki.lol",
-		"https://4get.psily.garden",
-		"https://search.milivojevic.in.rs",
-		"https://4get.snine.nl",
-		"https://4get.datura.network",
 		"https://4get.neco.lol",
-		"https://4get.lol",
-		"https://4get.ch",
 		"https://4get.edmateo.site",
 		"https://4get.sudovanilla.org",
-		"https://search.mint.lgbt"
+		"https://search.mint.lgbt",
+		"https://4get.aishiteiru.moe",
+		"https://4.nboeck.de",
+		"https://search.yonderly.org",
+		"https://4get.lurx.net",
+		"https://4get.canine.tools",
+		"https://4get.sny.sh",
+		"https://4g.opnxng.com",
+		"https://s.307200.xyz",
+		"https://4get.privadency.com/"
 	];
 	
 	// Default user agent to use for scraper requests. Sometimes ignored to get specific webpages

+ 7 - 0
lib/frontend.php

@@ -595,6 +595,13 @@ class frontend{
 	
 	public function getscraperfilters($page){
 		
+		// hack: enable error reporting if configured
+		if(config::DISPLAY_ERRORS === true){
+			
+			ini_set('display_errors', 1);
+			ini_set('display_startup_errors', 1);
+		}
+		
 		$get_scraper = isset($_COOKIE["scraper_$page"]) ? $_COOKIE["scraper_$page"] : null;
 		
 		if(