davide cucurnia
2024-01-30 9f6455d9b12bda65377e8501e00557982be9ff36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?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));
        }
    }
 
}