davide.cucurnia@vola.it
2024-02-05 ca6434daa9ea96df47c3197391a75a06466ebfc0
app/Http/Controllers/FakeResponder/FakeResponder.php
@@ -3,9 +3,10 @@
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
{
@@ -28,12 +29,14 @@
    public function manageLegacyRequest(Request $request)
    {
        $this->logReceivedRequest($request);
        if (isset($_COOKIE[$this->cookieFakeSSOName])) {
            $profile = intval(str_replace("xno:", "", $_COOKIE[$this->cookieFakeSSOName]));
            $responseContent = $this->VolaFakeSSO->getResponses($request, $profile);
            $this->logProcessedRequest($request, $responseContent, "SSO Legacy");
            $responseContent = (config('custom.compressed_responses',false) === TRUE) ? gzencode($responseContent, 3) : $responseContent;
            $responseContent = $this->compressIfRequested($request, $responseContent);
            return response($responseContent, 200, $this->headers);
        } else {
@@ -42,36 +45,20 @@
        }
    }
    public function managePicassoRequest(Request $request)
    public function managePicassoRequest(genericPicasso $request)
    {
        $this->logReceivedRequest($request);
        if (isset($_COOKIE[$this->cookieFakePicassoName])) {
            $profile = intval(str_replace("xno:", "", $_COOKIE[$this->cookieFakePicassoName]));
            $responseContent = $this->VolaFakeSSO->getResponses($request, $profile, true);
            $this->logProcessedRequest($request, $responseContent, "Picasso");
            $responseContent = (config('custom.compressed_responses',false) === TRUE) ? gzencode($responseContent, 3) : $responseContent;
            $responseContent = $this->compressIfRequested($request, $responseContent);
            return response($responseContent, 200, $this->headers);
        } else {
            $this->logRejectedRequest($request);
            return response('No cookie no logged', 400, $this->headers);
        }
    }
    public function logProcessedRequest(Request $request, $responseContent = null, $system = '')
    {
        if (config('custom.log_all_requests', true) === TRUE) {
            $uriParts = explode("?", $request->url());
            $methodUri = Str::afterLast($uriParts[0], "/");
            if (isset($responseContent)) {
                \Log::channel('requests_managed')->debug("\n" . $system . " " . $request->getClientIp() . " " . $methodUri . " :\n" . print_r($responseContent, 1));
            }
        }
    }
    public function logRejectedRequest(Request $request, ?array $additionalInfo = null)
    {
        if (config('custom.log_rejected_requests', true) === TRUE) {
            \Log::channel('requests_failed')->debug("Picasso " . $request->url() . "\nNessun cookie di sessione " . print_r($additionalInfo, 1));
        }
    }