davide.cucurnia@vola.it
2024-02-01 555a537e2e5d9220e3777c30b185606823c817f2
app/Http/Controllers/FakeResponder/FakeResponder.php
@@ -5,7 +5,7 @@
use App\Http\Controllers\Controller;
use App\Vola\Services\VolaFakeHTTPResponder\VolaFakeHTTPResponder;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use App\Vola\Classes\Utils;
class FakeResponder extends Controller
{
@@ -14,7 +14,6 @@
    public string $cookieFakePicassoName = "SSOSESSIONID";
    public array $headers;
    public VolaFakeHTTPResponder $VolaFakeSSO;
    protected bool $openFakeSSO = true;
    function __construct()
    {
@@ -22,51 +21,43 @@
        $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)
    {
        $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 = '')
    {
        if (config('custom.log_all_requests', true) === TRUE) {
            $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);
        }
    }