| | |
| | | namespace App\Http\Controllers\FakeResponder; |
| | | |
| | | use App\Http\Controllers\Controller; |
| | | use App\Http\Requests\genericPicasso; |
| | | use App\Vola\Services\VolaFakeHTTPResponder\VolaFakeHTTPResponder; |
| | | use Illuminate\Http\Request; |
| | | use Illuminate\Support\Str; |
| | | use App\Vola\Classes\Utils; |
| | | |
| | | class FakeResponder extends Controller |
| | | { |
| | |
| | | public string $cookieFakePicassoName = "SSOSESSIONID"; |
| | | public array $headers; |
| | | public VolaFakeHTTPResponder $VolaFakeSSO; |
| | | protected bool $openFakeSSO = true; |
| | | |
| | | function __construct() |
| | | { |
| | |
| | | $this->headers = [ |
| | | "Content-Type" => 'text/xml', |
| | | ]; |
| | | if (config('custom.compressed_responses',false) === TRUE) { |
| | | $this->headers['content-encoding'] = 'gzip'; |
| | | } |
| | | } |
| | | |
| | | public function manageLegacyRequest(Request $request) |
| | | { |
| | | $this->logReceivedRequest($request); |
| | | if (isset($_COOKIE[$this->cookieFakeSSOName])) { |
| | | /* |
| | | $params = $request->query(); |
| | | if (!isset($_COOKIE[$this->cookieFakeSSOName]) && (isset($params["t"]))) { |
| | | $testUser = $params["t"]; |
| | | } |
| | | */ |
| | | $testUser = intval(str_replace("xno:", "", $_COOKIE[$this->cookieFakeSSOName])); |
| | | $responseContent = $this->VolaFakeSSO->getResponses($request, $testUser); |
| | | $this->logRequest($request, $responseContent, "SSO Legacy"); |
| | | $profile = intval(str_replace("xno:", "", $_COOKIE[$this->cookieFakeSSOName])); |
| | | $responseContent = $this->VolaFakeSSO->getResponses($request, $profile); |
| | | |
| | | $this->logProcessedRequest($request, $responseContent, "SSO Legacy"); |
| | | $responseContent = $this->compressIfRequested($request, $responseContent); |
| | | |
| | | return response($responseContent, 200, $this->headers); |
| | | |
| | | } else { |
| | | \Log::channel('requests_failed')->debug($request->url() . ' : Nessun cookie di sessione '.$this->cookieFakeSSOName); |
| | | return response('No cookie', 400, $this->headers); |
| | | $this->logRejectedRequest($request); |
| | | return response('No cookie, no logged', 400, $this->headers); |
| | | } |
| | | } |
| | | |
| | | public function managePicassoRequest(Request $request) |
| | | public function managePicassoRequest(genericPicasso $request) |
| | | { |
| | | $this->logReceivedRequest($request); |
| | | if (isset($_COOKIE[$this->cookieFakePicassoName])) { |
| | | $testUser = intval(str_replace("xno:", "", $_COOKIE[$this->cookieFakePicassoName])); |
| | | $responseContent = $this->VolaFakeSSO->getResponses($request, $testUser, true); |
| | | $this->logRequest($request, $responseContent, "Picasso"); |
| | | $profile = intval(str_replace("xno:", "", $_COOKIE[$this->cookieFakePicassoName])); |
| | | $responseContent = $this->VolaFakeSSO->getResponses($request, $profile, true); |
| | | |
| | | $this->logProcessedRequest($request, $responseContent, "Picasso"); |
| | | $responseContent = $this->compressIfRequested($request, $responseContent); |
| | | |
| | | return response($responseContent, 200, $this->headers); |
| | | } else { |
| | | \Log::channel('requests_failed')->debug("Picasso " . $request->url() . ' : Nessun cookie di sessione '.$this->cookieFakePicassoName); |
| | | return response('No cookie', 400, $this->headers); |
| | | } |
| | | } |
| | | |
| | | public function logRequest(Request $request, $responseContent = null, $system = '') |
| | | { |
| | | $uriParts = explode("?", $request->url()); |
| | | $methodUri = Str::afterLast($uriParts[0], "/"); |
| | | $reqParams = !empty($request->query()) ? $request->query() : []; |
| | | //\Log::channel('requests_managed')->debug($system . " " . $request->getClientIp() ." ". $methodUri . " with params ".print_r($reqParams,1)); |
| | | //\Log::channel('requests_managed')->debug("Cookies received: " . print_r($_COOKIE,1)); |
| | | if (isset($responseContent)) { |
| | | \Log::channel('requests_managed')->debug("\n" . $system . " " . $request->getClientIp() ." ". $methodUri . " :\n". print_r($responseContent,1)); |
| | | $this->logRejectedRequest($request); |
| | | return response('No cookie no logged', 400, $this->headers); |
| | | } |
| | | } |
| | | |