<?php
|
|
namespace App\Http\Controllers\FakeResponder;
|
|
use App\Http\Controllers\Controller;
|
use App\Vola\Services\VolaFakeHTTPResponder\VolaFakeHTTPResponder;
|
use Illuminate\Http\Request;
|
use Illuminate\Support\Str;
|
|
class FakeResponder extends Controller
|
{
|
|
public string $cookieFakeSSOName = "CAuthCookie";
|
public string $cookieFakePicassoName = "SSOSESSIONID";
|
public array $headers;
|
public VolaFakeHTTPResponder $VolaFakeSSO;
|
protected bool $openFakeSSO = true;
|
|
function __construct()
|
{
|
$this->VolaFakeSSO = new VolaFakeHTTPResponder();
|
$this->headers = [
|
"Content-Type" => 'text/xml',
|
];
|
}
|
|
public function manageLegacyRequest(Request $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");
|
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);
|
}
|
}
|
|
public function managePicassoRequest(Request $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");
|
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));
|
}
|
}
|
|
}
|