davide cucurnia
2024-01-30 9f6455d9b12bda65377e8501e00557982be9ff36
commit | author | age
9f6455 1 <?php
DC 2
3 namespace App\Http\Controllers\FakeResponder;
4
5 use App\Http\Controllers\Controller;
6 use App\Vola\Services\VolaFakeHTTPResponder\VolaFakeHTTPResponder;
7 use Illuminate\Http\Request;
8 use Illuminate\Support\Str;
9
10 class FakeResponder extends Controller
11 {
12
13     public string $cookieFakeSSOName = "CAuthCookie";
14     public string $cookieFakePicassoName = "SSOSESSIONID";
15     public array $headers;
16     public VolaFakeHTTPResponder $VolaFakeSSO;
17     protected bool $openFakeSSO = true;
18
19     function __construct()
20     {
21         $this->VolaFakeSSO = new VolaFakeHTTPResponder();
22         $this->headers = [
23             "Content-Type" => 'text/xml',
24         ];
25     }
26
27     public function manageLegacyRequest(Request $request)
28     {
29         if (isset($_COOKIE[$this->cookieFakeSSOName])) {
30             /*
31             $params = $request->query();
32             if (!isset($_COOKIE[$this->cookieFakeSSOName]) && (isset($params["t"]))) {
33                 $testUser = $params["t"];
34             }
35             */
36             $testUser = intval(str_replace("xno:", "", $_COOKIE[$this->cookieFakeSSOName]));
37             $responseContent = $this->VolaFakeSSO->getResponses($request, $testUser);
38             $this->logRequest($request, $responseContent, "SSO Legacy");
39             return response($responseContent, 200, $this->headers);
40         } else {
41             \Log::channel('requests_failed')->debug($request->url() . ' : Nessun cookie di sessione '.$this->cookieFakeSSOName);
42             return response('No cookie', 400, $this->headers);
43         }
44     }
45
46     public function managePicassoRequest(Request $request)
47     {
48         if (isset($_COOKIE[$this->cookieFakePicassoName])) {
49             $testUser = intval(str_replace("xno:", "", $_COOKIE[$this->cookieFakePicassoName]));
50             $responseContent = $this->VolaFakeSSO->getResponses($request, $testUser, true);
51             $this->logRequest($request, $responseContent, "Picasso");
52             return response($responseContent, 200, $this->headers);
53         } else {
54             \Log::channel('requests_failed')->debug("Picasso " . $request->url() . ' : Nessun cookie di sessione '.$this->cookieFakePicassoName);
55             return response('No cookie', 400, $this->headers);
56         }
57     }
58
59     public function logRequest(Request $request, $responseContent = null, $system = '')
60     {
61         $uriParts = explode("?", $request->url());
62         $methodUri = Str::afterLast($uriParts[0], "/");
63         $reqParams = !empty($request->query()) ? $request->query() : [];
64         //\Log::channel('requests_managed')->debug($system . " " . $request->getClientIp() ." ". $methodUri . " with params ".print_r($reqParams,1));
65         //\Log::channel('requests_managed')->debug("Cookies received: " . print_r($_COOKIE,1));
66         if (isset($responseContent)) {
67             \Log::channel('requests_managed')->debug("\n" . $system . " " . $request->getClientIp() ." ". $methodUri . " :\n". print_r($responseContent,1));
68         }
69     }
70
71 }