fixed greppr, again

This commit is contained in:
2025-09-06 11:25:09 -04:00
parent c44d6292a0
commit 6d34d43a01

View File

@@ -1,4 +1,6 @@
<?php <?php
// greppr dev probably monitors 4get code, lol
// hello greppr dude, add an API you moron
class greppr{ class greppr{
@@ -16,7 +18,7 @@ class greppr{
return []; return [];
} }
private function get($proxy, $url, $get = [], $cookie = false, $post){ private function get($proxy, $url, $get = [], $cookies = [], $post = false){
$curlproc = curl_init(); $curlproc = curl_init();
@@ -24,6 +26,14 @@ class greppr{
curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
$cookie = [];
foreach($cookies as $k => $v){
$cookie[] = "{$k}={$v}";
}
$cookie = implode("; ", $cookie);
if($post === false){ if($post === false){
if($get !== []){ if($get !== []){
@@ -31,7 +41,7 @@ class greppr{
$url .= "?" . $get; $url .= "?" . $get;
} }
if($cookie === false){ if($cookie == ""){
curl_setopt($curlproc, CURLOPT_HTTPHEADER, curl_setopt($curlproc, CURLOPT_HTTPHEADER,
["User-Agent: " . config::USER_AGENT, ["User-Agent: " . config::USER_AGENT,
@@ -57,7 +67,7 @@ class greppr{
"Sec-GPC: 1", "Sec-GPC: 1",
"Connection: keep-alive", "Connection: keep-alive",
"Referer: https://greppr.org/search", "Referer: https://greppr.org/search",
"Cookie: PHPSESSID=$cookie", "Cookie: {$cookie}",
"Upgrade-Insecure-Requests: 1", "Upgrade-Insecure-Requests: 1",
"Sec-Fetch-Dest: document", "Sec-Fetch-Dest: document",
"Sec-Fetch-Mode: navigate", "Sec-Fetch-Mode: navigate",
@@ -85,7 +95,7 @@ class greppr{
"Sec-GPC: 1", "Sec-GPC: 1",
"Connection: keep-alive", "Connection: keep-alive",
"Referer: https://greppr.org/", "Referer: https://greppr.org/",
"Cookie: PHPSESSID=$cookie", "Cookie: {$cookie}",
"Upgrade-Insecure-Requests: 1", "Upgrade-Insecure-Requests: 1",
"Sec-Fetch-Dest: document", "Sec-Fetch-Dest: document",
"Sec-Fetch-Mode: navigate", "Sec-Fetch-Mode: navigate",
@@ -119,7 +129,7 @@ class greppr{
return $len; return $len;
} }
$headers[strtolower(trim($header[0]))] = trim($header[1]); $headers[strtolower(trim($header[0]))][] = trim($header[1]);
return $len; return $len;
} }
@@ -157,7 +167,7 @@ class greppr{
$proxy, $proxy,
"https://greppr.org" . $tokens["get"], "https://greppr.org" . $tokens["get"],
[], [],
$tokens["cookie"], $tokens["cookies"],
false false
); );
}catch(Exception $error){ }catch(Exception $error){
@@ -185,12 +195,12 @@ class greppr{
$proxy, $proxy,
"https://greppr.org", "https://greppr.org",
[], [],
false, [],
false false
); );
}catch(Exception $error){ }catch(Exception $error){
throw new Exception("Failed to fetch search tokens"); throw new Exception("Failed to fetch homepage");
} }
// //
@@ -198,7 +208,11 @@ class greppr{
// //
$this->fuckhtml->load($html["data"]); $this->fuckhtml->load($html["data"]);
$tokens = []; $tokens = [
"req" => null,
"data" => null,
"cookies" => null
];
$inputs = $inputs =
$this->fuckhtml $this->fuckhtml
@@ -213,63 +227,66 @@ class greppr{
continue; continue;
} }
switch($input["attributes"]["name"]){ if(
isset($input["attributes"]["value"]) &&
!empty($input["attributes"]["value"])
){
case "var1": $tokens
case "var2": ["data"]
case "n": [$this->fuckhtml
$tokens[$input["attributes"]["name"]] = ->getTextContent(
$input["attributes"]["name"]
)] =
$this->fuckhtml $this->fuckhtml
->getTextContent( ->getTextContent(
$input["attributes"]["value"] $input["attributes"]["value"]
); );
break; }else{
default:
$tokens["req"] = $tokens["req"] =
$this->fuckhtml $this->fuckhtml
->getTextContent( ->getTextContent(
$input["attributes"]["name"] $input["attributes"]["name"]
); );
break;
} }
} }
// get cookie if($tokens["req"] === null){
throw new Exception("Failed to get request ID");
}
if(isset($html["headers"]["set-cookie"])){
foreach($html["headers"]["set-cookie"] as $cookie){
if(
preg_match( preg_match(
'/PHPSESSID=([^;]+)/', '/([^=]+)=([^;]+)/',
$html["headers"]["set-cookie"], $cookie,
$cookie $matches
); )
){
if(!isset($cookie[1])){ $tokens["cookies"][$matches[1]] = $matches[2];
}
// server sent an unexpected cookie
throw new Exception("Got malformed cookie");
} }
$tokens["cookie"] = $cookie[1];
if($tokens === false){
throw new Exception("Failed to grep search tokens");
} }
// //
// Get initial search page // Get initial search page
// //
$tokens_req = $tokens["data"];
$tokens_req[$tokens["req"]] = $search;
try{ try{
$html = $this->get( $html = $this->get(
$proxy, $proxy,
"https://greppr.org/search", "https://greppr.org/search",
[ $tokens_req,
"var1" => $tokens["var1"], $tokens["cookies"],
"var2" => $tokens["var2"],
$tokens["req"] => $search,
"n" => $tokens["n"]
],
$tokens["cookie"],
true true
); );
}catch(Exception $error){ }catch(Exception $error){
@@ -338,7 +355,7 @@ class greppr{
->getTextContent( ->getTextContent(
$a["attributes"]["href"] $a["attributes"]["href"]
), ),
"cookie" => $tokens["cookie"] "cookies" => $tokens["cookies"]
]), ]),
"web", "web",
$proxy $proxy