HEX
Server: Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10
System: Windows NT ALTAIR 10.0 build 20348 (Windows Server 2022) AMD64
User: Administrator (0)
PHP: 8.1.10
Disabled: NONE
Upload Files
File: C:/laragon/www/beplocal/accessoRisorsaProtetta.php
<?php 
include_once 'DBClassOkta.php'; 
include_once 'Utilities.php';
require "vendor/autoload.php"; 
use \Firebase\JWT\JWT; 
$jwt = $_POST['jwt'];
$auth_level = $_POST['AUTH_LEVEL'];



if(verificaToken($jwt, $auth_level)){
	
				$databaseService = new DatabaseService(); 
				$conn = $databaseService->getConnection();
				//array('HS256')
				$secret_key = "OKTA2022@2202ATKO"; 
				if($jwt) { 
					try { 
						$decoded = JWT::decode($jwt, $secret_key, array('HS256'));
						$user = $decoded->data->Login;
						$nome = $decoded->data->Nome;
						$cognome = $decoded->data->Cognome;
						$scadenza = $decoded->exp;
						
						if(time() >= $scadenza){
							echo json_encode(array(

							"message" => "KO ! Token Scaduto",

						)); 
							die();
						}
						else{
							
							if($auth_level == "*"){
							echo json_encode(array(

								"message" => "OK",
								"nome" => $nome,
								"user" => $user,
								"tipo" => "AGENTE"
								)); 
							die();
								
							}
							
							else {
								
								//cerco se nel DB l'utente รจ abilitato al livello di autorizzazione richiesto
								$query = "Select ". 
										 "us.login, ".
										 "us.nome, ".
										 "us.cognome, ".
										 "us.tipoUtenza, ".
										 "al.CodificaLivello ".
										 "From Users as us ".
										 "inner join UserAuth as ua on us.idUsers = ua.idUser ".
										 "inner join AuthLevel as al on al.idAuthLevel = ua.IdAuth ".
										 "where us.login = '".$user."' and ( (al.CodificaLivello = '".$auth_level."' ) || (al.CodificaLivello = 'ALL' ))";

								$stmt = $conn->prepare( $query );
								$stmt->execute();
								$num = $stmt->rowCount();
								
								if($num > 0){
									
									$tipoUtenza ="";
									while ($row = $stmt->fetch())
									{
										$tipoUtenza = $row['tipoUtenza'];
									}
									
									echo json_encode(array(

										"message" => "OK",
										"nome" => $nome,
										"user" => $user,
										"tipo" => $tipoUtenza
										
									)); 
									die();
								
								}else {
									echo json_encode(array(

										"message" => "KO ! Utente non abilitato" 
										
									)); 
									die();
									
									
									
								}
									
									
									
									
							}
								
								
							}
							
							
							
							
						}
						catch (Exception $e) { 
					
						echo json_encode(array( 
							"message" => "SESSIONE SCADUTA !"
							
						)); 
					} 
				} 
				
}else{
	
	echo json_encode(array( 
		"message" => "TOKEN NON VALIDO !"
							
	)); 
}

?>