Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
434 righe
18 KiB
434 righe
18 KiB
<!-- Permessi ANAC --> |
|
<?php |
|
|
|
$configPath = substr(__DIR__, 0, strpos(__DIR__, "/public_html")) . "/config.php"; |
|
include_once $configPath; |
|
|
|
function debugPanelNotAvailable() |
|
{ |
|
die("<h4>Non hai i permessi per visualizzare questo pannello.</h4>"); |
|
} |
|
$codice = $_REQUEST["codice"] ?? null; |
|
$npa = NuovaPiattaformaAppalti::init(null, $codice); |
|
|
|
|
|
// Verifica utente |
|
if (!$npa->verifyUtente()) { |
|
debugPanelNotAvailable(); |
|
} |
|
|
|
$npa->disableLogs = true; |
|
|
|
if (empty($npa->fascicolo)) debugPanelNotAvailable(); |
|
|
|
if ( |
|
empty($npa->fascicolo) || |
|
empty($npa->scheda) || |
|
!$_SESSION["utente"]->isSupportoOrRoot() |
|
) { |
|
debugPanelNotAvailable(); |
|
} |
|
|
|
$npa_fascicolo = NuovaPiattaformaAppalti::init($npa->fascicolo["codice"]); |
|
|
|
$dataFascicolo = unserialize($npa->fascicolo["data"]); |
|
|
|
if (isset($_POST["toggleFlag"])) { |
|
$flag = $_POST["toggleFlag"]; |
|
$dataFascicolo[$flag] = ($dataFascicolo[$flag] ?? false) ? false : true; |
|
$npa->updateFascicolo(["data" => serialize($dataFascicolo)]); |
|
} |
|
|
|
$abilitaModifiche = $dataFascicolo["abilita_modifica_appalto"] ?? false; |
|
$abilitaResync = $dataFascicolo["abilita_resync"] ?? false; |
|
|
|
if (DEVELOP_ENV && isset($_GET["fascicolo"]) && valid_json($_GET["fascicolo"], $modFascicolo, true)) { |
|
die($npa->updateFascicolo($modFascicolo) ? "OK" : "KO"); |
|
} |
|
if (DEVELOP_ENV && isset($_GET["scheda"]) && valid_json($_GET["scheda"], $modScheda, true)) { |
|
die($npa->updateScheda($modScheda) ? "OK" : "KO"); |
|
} |
|
|
|
if(!empty($npa->scheda["codice_lotto"])) { |
|
$npa->setLotto($npa->scheda["codice_lotto"]); |
|
} |
|
$npa->_loadSuggestions(); |
|
|
|
$scheda = $npa->scheda; |
|
$scheda["info"] = unserialize($scheda["info"]); |
|
unset($scheda["dati"]); |
|
|
|
|
|
// Forziamoci come RP per le richieste |
|
if (DEVELOP_ENV) { |
|
define("__CMDS_JOB_EXEC", true); |
|
} |
|
$server_data = $server_scheda = null; |
|
if (DEVELOP_ENV) { |
|
if (!empty($scheda["info"]->idAvviso)) { |
|
$server_data = $npa->readNotice(); |
|
} else { |
|
$server_data = $npa->read(); |
|
} |
|
} |
|
$server_scheda = $server_data->_scheda->body ?? null; |
|
|
|
function debugPanelProcessScheda($scheda) |
|
{ |
|
if (isset($scheda->eform)) { |
|
try { |
|
$eform = base64_decode($scheda["eform"]); |
|
$eform_xml = new DOMDocument(); |
|
$eform_xml->loadXML($eform); |
|
$xpath10 = new DOMXPath($eform_xml); |
|
|
|
$scheda->eform_notice_id = $xpath10->evaluate("string(/*/cbc:ContractFolderID)"); |
|
} catch (\Throwable $t) {/* no */} |
|
} |
|
return $scheda; |
|
} |
|
|
|
if (!empty($server_scheda)) { |
|
$server_scheda = debugPanelProcessScheda($server_scheda); |
|
} |
|
$client_scheda = $npa->getCardData(); |
|
$npa->organizeRepeteableGroups($client_scheda); |
|
$client_scheda = debugPanelProcessScheda($client_scheda); |
|
$operations = $npa->getLastOperation(null, null, false, true); |
|
$logs = $npa->getAvailableLogs(); |
|
if(isset($_REQUEST["log"])) { |
|
$logs = $npa->retrieveLogs($_REQUEST["log"]); |
|
} |
|
$logs_fascicolo = $npa_fascicolo->getAvailableLogs(); |
|
if(isset($_REQUEST["log_fascicolo"])) { |
|
$logs = $npa_fascicolo->retrieveLogs($_REQUEST["log_fascicolo"]); |
|
} |
|
$suggestions = $npa->getSuggestions(); |
|
?> |
|
|
|
|
|
<h3>Strumenti di debug</h3> |
|
|
|
<div class="row mx-0"> |
|
<button class="btn btn-primary ignore-lock mx-1" type="button" data-toggle="collapse" data-target="#physical_model_collapse"> |
|
Dati |
|
</button> |
|
<?php if (!empty($server_data)) : ?> |
|
<button class="btn btn-primary ignore-lock mx-1" type="button" data-toggle="collapse" data-target="#debug_read"> |
|
ANAC: Read |
|
</button> |
|
<?php endif; ?> |
|
<button class="btn btn-primary ignore-lock mx-1" type="button" data-toggle="collapse" data-target="#debug_segnalazione"> |
|
Segnalazione |
|
</button> |
|
<button class="btn btn-primary ignore-lock mx-1" type="button" data-toggle="collapse" data-target="#debug_card"> |
|
Scheda |
|
</button> |
|
<?php if (!empty($logs) || !empty($logs_fascicolo)) : ?> |
|
<button class="btn btn-primary ignore-lock mx-1" type="button" data-toggle="collapse" data-target="#debug_logs"> |
|
Log |
|
</button> |
|
<?php endif; ?> |
|
<?php if (!empty($operations)) : ?> |
|
<button class="btn btn-primary ignore-lock mx-1" type="button" data-toggle="collapse" data-target="#debug_operations"> |
|
Operazioni |
|
</button> |
|
<?php endif; ?> |
|
<?php if (!empty($suggestions)) : ?> |
|
<button class="btn btn-primary mx-1" type="button" data-toggle="collapse" data-target="#suggestions_collapse"> |
|
Suggerimenti |
|
</button> |
|
<?php endif; ?> |
|
<button class="btn btn-danger ignore-lock mx-1" onclick="window.toggleFlag('abilita_modifica_appalto');"> |
|
<?php if ($abilitaModifiche) : ?> |
|
Disattiva modifica |
|
<?php else : ?> |
|
Abilita modifica |
|
<?php endif ?> |
|
</button> |
|
<button class="btn btn-danger ignore-lock mx-1" onclick="window.toggleFlag('abilita_resync');"> |
|
<?php if ($abilitaResync) : ?> |
|
Disattiva resync |
|
<?php else : ?> |
|
Abilita resync |
|
<?php endif ?> |
|
</button> |
|
</div> |
|
<div class="collapse my-2" id="debug_segnalazione"> |
|
<?php $metadata = $npa->metadataSchede[$npa->scheda["id_scheda"]]; ?> |
|
<?php |
|
$procedura = $npa->integration["MODULO"] ?? "Sconosciuta"; |
|
if(!empty($npa->integration["PROCEDURA"]["titolo"])) { |
|
$procedura = $npa->integration["PROCEDURA"]["titolo"]; |
|
} |
|
if(method_exists($npa->oggetto, "getSogliaGara")) { |
|
$soglia = $npa->oggetto->getSogliaGara(); |
|
$procedura .= " - $soglia"; |
|
} |
|
if(method_exists($npa->oggetto, "getRisposteElaborazione")) { |
|
$elaborazione = $npa->oggetto->getRisposteElaborazione(); |
|
if(!empty($elaborazione["settoreRiferimento"])) { |
|
$procedura .= " - Settore {$elaborazione["settoreRiferimento"]}"; |
|
} |
|
} |
|
if(!empty($npa->scheda["info"])) { |
|
$infoScheda = unserialize($npa->scheda["info"]); |
|
$transactionId = $infoScheda->lastTransactionID ?? ""; |
|
$lastCantDoRequest = $infoScheda->lastCantDoRequest ?? []; |
|
} |
|
|
|
?> |
|
<code> |
|
Piattaforma: <br> |
|
Tipologia di gara: <?= $procedura ?> <br> |
|
Valore economico dell'Appalto: <?= currency_format($npa->integration["GENERAL"]["prezzoRiferimento"] ?? 0, "EUR " )?> <br> |
|
<?php if(isset($npa->fascicolo["id_appalto"])): ?> |
|
idAppalto: <?= $npa->fascicolo["id_appalto"] ?> <br> |
|
<?php elseif(isset($npa->fascicolo["id_pianificazione"])): ?> |
|
idPianificazione: <?= $npa->fascicolo["id_pianificazione"] ?> <br> |
|
<?php endif; ?> |
|
Scheda: <?= $npa->scheda["id_scheda"] ?> <br> |
|
<?php if($npa->scheda["errore"] == "SI") : ?> |
|
<?php |
|
$operazione = $npa->getLastOperation(null, null, "KO"); |
|
$dictionary = $npa->getErrorsDictionary(); |
|
?> |
|
<?php if(! empty($operazione) && $operazione["esito"] == "KO") : ?> |
|
<?php |
|
$errori = unserialize($operazione["risultato"]) ?? null; |
|
if(isset($errori->errori)) { $errori = $errori->errori; } |
|
if(!is_array($errori)) { $errori = [$errori]; } |
|
foreach ($errori as $errore) { |
|
$codice = $errore->codice ?? "SCONOSCIUTO"; |
|
$errorMessage = $dictionary[$errore->codice]["descrizione"]["it"] ?? "Errore sconosciuto " . json_encode($errore, JSON_PRETTY_PRINT) ; |
|
$detail = $errore->dettaglio ?? null; |
|
|
|
$timestamp = mysql2datetime($operazione["timestamp"]); |
|
$tipoOperazione = ucfirst(strtolower(str_replace("_", " ", $operazione["operazione"]))); |
|
$message = "<strong>{$codice}</strong> - {$errorMessage}"; |
|
$message .= " - <i>Errore registrato il <strong>{$timestamp}</strong> in fase di <strong>{$tipoOperazione}</strong></i>"; |
|
if(! empty($detail)) { $message .= "<br>{$detail}"; } |
|
?> |
|
Errore: <?= $message ?><br> |
|
<?php |
|
} |
|
?> |
|
<?php endif; ?> |
|
<?php endif; ?> |
|
<?php if(!empty($transactionId)) : ?> |
|
Govway Transaction id: <?= $transactionId ?> |
|
<?php endif; ?> |
|
|
|
</code> |
|
<hr> |
|
<code> |
|
Extra info: <br> |
|
<?php if(!empty($lastCantDoRequest)): ?> |
|
Ultimo cantDoRequest: <?= $lastCantDoRequest["msg"] ?> |
|
<?php endif; ?> |
|
</code> |
|
</div> |
|
<div class="collapse my-2" id="debug_card"> |
|
<?php dump($scheda) ?> |
|
<?php dump($npa->fascicolo ?? []) ?> |
|
<?php dump($npa->check) ?> |
|
</div> |
|
<?php $collapse = isset($_REQUEST["log"]) || isset($_REQUEST["log_fascicolo"]) ? "" : "collapse"; ?> |
|
<div class="<?= $collapse ?> my-2" id="debug_logs"> |
|
<?php if(isset($_REQUEST["log"]) || isset($_REQUEST["log_fascicolo"])): ?> |
|
<?php foreach ($logs as $log) : ?> |
|
<?php |
|
$color = "success"; |
|
$status = $log["result"]["detail"] ?? ""; |
|
if(isset($log["error"])) { |
|
$color = "danger"; |
|
$status = $log["error"]; |
|
unset($log["error"]); |
|
} |
|
if(($log["result"]["status"] ?? 200) != 200) { |
|
$color = "danger"; |
|
$status = isset($log["result"]["errori"]) ? json_encode($log["result"]["errori"]) : ""; |
|
} elseif(isset($log["request"]) && is_string($log["request"])) { |
|
if(preg_match("/(HTTP\/)(\d*\.*\d*) (20\d)/", $log["request"]) !== 1) { |
|
$color = "danger"; |
|
$status = "Sconosciuto"; |
|
} |
|
} |
|
|
|
$datetime = ""; |
|
if(isset($log["_datetime"])) { |
|
$datetime = date('d/m/Y H:i:s', strtotime($log["_datetime"])); |
|
unset($log["_datetime"]); |
|
} |
|
foreach($log as $name => $entry) { |
|
if($name === "request") { |
|
foreach(explode("\n", $entry) as $line) { |
|
if(str_starts_with($line, "Agid-JWT-TrackingEvidence: ")) { |
|
$line = str_replace("Agid-JWT-TrackingEvidence: ", "", $line); |
|
list($headersB64, $payloadB64, $sig) = explode('.', $line); |
|
$log["jwt"] = json_decode(base64_decode($payloadB64), true); |
|
foreach(["traceID", "spanID", "aud", "iss", "jti", "iat", "nbf", "exp"] as $e) { |
|
if(isset($log["jwt"][$e])) unset($log["jwt"][$e]); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
?> |
|
<div class="card my-1 status-border-<?= $color ?> bg-dark text-light text-left"> |
|
<div class="card-body p-1 pt-2 pl-3"> |
|
<i><?= $datetime ?></i> <code class="ml-3"><?= $status ?></code> |
|
<hr> |
|
<?php foreach($log as $name => $entry): ?> |
|
<strong class="mt-2"><?= ucfirst($name) ?>:</strong> |
|
<?php if(is_string($entry) && valid_json($entry, $entry_json, true)): ?> |
|
<div class="mx-2" style="max-height: 300px; overflow-y: scroll;"> |
|
<pre style='width:100%; color:var(--light); background:var(--dark);'><?= htmlspecialchars(json_encode($entry_json, JSON_PRETTY_PRINT)) ?></pre> |
|
</div> |
|
<?php elseif(is_string($entry)): ?> |
|
<div class="mx-2" style="max-height: 300px; overflow-y: scroll;"> |
|
<pre style='width:100%; color:var(--light); background:var(--dark);'><?= htmlspecialchars($entry) ?></pre> |
|
</div> |
|
<?php else: ?> |
|
<div class="mx-2" style="max-height: 200px; overflow-y: scroll;"> |
|
<pre style='width:100%; color:var(--light); background:var(--dark);'><?= htmlspecialchars(json_encode($entry, JSON_PRETTY_PRINT)) ?></pre> |
|
</div> |
|
<?php endif; ?> |
|
<?php endforeach; ?> |
|
</div> |
|
</div> |
|
<?php endforeach; ?> |
|
<?php else: ?> |
|
<?php foreach ($logs as $name => $path) : ?> |
|
<?php |
|
$query = []; |
|
parse_str($_SERVER['QUERY_STRING'], $query); |
|
$query["log"] = $path; |
|
$query = http_build_query($query); |
|
$url = "/backend/npa/ajax/debug_panel.php?{$query}"; |
|
?> |
|
<button class="btn btn-info btn-block text-left pl-3" onclick="showModalWithURL(`<?= $url ?>`)"> |
|
<span class="fa fa-file mr-2"></span> <?= $name ?> |
|
</button> |
|
<?php endforeach; ?> |
|
<?php if(!empty($logs_fascicolo)): ?> |
|
<hr> |
|
<h6>Log Fascicolo:</h6> |
|
<?php foreach ($logs_fascicolo as $name => $path) : ?> |
|
<?php |
|
$query = []; |
|
parse_str($_SERVER['QUERY_STRING'], $query); |
|
$query["log_fascicolo"] = $path; |
|
$query = http_build_query($query); |
|
$url = "/backend/npa/ajax/debug_panel.php?{$query}"; |
|
?> |
|
<button class="btn btn-info btn-block text-left pl-3" onclick="showModalWithURL(`<?= $url ?>`)"> |
|
<span class="fa fa-file mr-2"></span> <?= $name ?> |
|
</button> |
|
<?php endforeach; ?> |
|
<?php endif; ?> |
|
<?php endif; ?> |
|
</div> |
|
<div class="collapse my-2" id="debug_operations"> |
|
<?php $__cache_info_utente = [] ?> |
|
<?php foreach ($operations as $operation) : ?> |
|
<?php |
|
|
|
$esito = empty($operation["esito"]) ? "In corso..." : $operation["esito"]; |
|
$color = ["KO" => "danger", "OK" => "success"][$operation["esito"]] ?? "secondary"; |
|
// Ottieni info utente (con cache per evitare mille query) |
|
$idUtente = $operation["utente_modifica"]; |
|
if ($idUtente > 0) { |
|
$utente = $__cache_info_utente[$idUtente] ?? false; |
|
if ($utente === false) { |
|
$utente = Utente::getInfoFromID($idUtente); |
|
$__cache_info_utente[$idUtente] = $utente; |
|
} |
|
} |
|
$info_utente = empty($utente) ? $operation["utente_modifica"] : "{$utente["nome"]} {$utente["cognome"]} - ID {$utente["codice"]}"; |
|
// Ottieni risultato |
|
$risultato = unserialize($operation["risultato"]); |
|
// Rendi associativo |
|
if (!empty($risultato)) { |
|
$risultato = json_decode(json_encode($risultato), true); |
|
} |
|
?> |
|
<div class="card my-1 status-border-<?= $color ?> bg-dark text-light text-left"> |
|
<div class="card-body p-1 pt-2 pl-3"> |
|
[<?= $esito ?>] <strong><?= $operation["operazione"] ?></strong> - <i><?= mysql2datetime($operation["timestamp"]) ?></i> <br> |
|
Effettuata da <?= $info_utente ?> <br> |
|
<?php if (!empty($risultato)) : ?> |
|
<?php dump($risultato) ?> |
|
<?php endif; ?> |
|
</div> |
|
</div> |
|
<?php endforeach; ?> |
|
</div> |
|
<?php if (!empty($server_data)) : ?> |
|
<div class="collapse my-2" id="debug_read"> |
|
<?php dump($server_data) ?> |
|
</div> |
|
<?php endif; ?> |
|
|
|
<div class="collapse my-2" id="physical_model_collapse"> |
|
<div class="row" style="max-height: 300px; overflow-y: scroll;"> |
|
<div class="col col-<?= empty($server_scheda) ? 12 : 6 ?>"> |
|
<button class="btn btn-primary d-block ignore-lock" onclick="downloadElementContents(document.getElementById('client_physical_model'), 'scheda_client.json')"> |
|
Download JSON (Client) |
|
</button> |
|
<pre id='client_physical_model' style='width:100%; color:var(--light); background:var(--dark);'><?= print_r(htmlspecialchars(json_encode($client_scheda, JSON_PRETTY_PRINT)), true) ?></pre> |
|
|
|
</div> |
|
<?php if (!empty($server_scheda)) : ?> |
|
<div class="col col-6"> |
|
<button class="btn btn-primary d-block ignore-lock" onclick="downloadElementContents(document.getElementById('server_physical_model'), 'scheda_server.json')"> |
|
Download JSON (Server) |
|
</button> |
|
<pre id='server_physical_model' style='width:100%; color:var(--light); background:var(--dark);'><?= print_r(htmlspecialchars(json_encode($server_scheda, JSON_PRETTY_PRINT)), true) ?></pre> |
|
</div> |
|
|
|
|
|
<?php endif; ?> |
|
</div> |
|
</div> |
|
<?php if (!empty($suggestions)) : ?> |
|
<div class="collapse my-2" id="suggestions_collapse"> |
|
Matches: |
|
<?php dump($suggestions) ?> |
|
Integration: |
|
<?php if (!empty($npa->integration)) dump($npa->integration) ?> |
|
</div> |
|
<?php endif; ?> |
|
|
|
<script type="text/javascript"> |
|
window.toggleFlag = function(flag) { |
|
$.ajax({ |
|
|
|
type: "POST", |
|
url: `ajax/debug_panel.php`, |
|
data: { |
|
'codice': `<?= $npa->scheda['codice'] ?>`, |
|
'toggleFlag': flag |
|
}, |
|
dataType: "script", |
|
beforeSend: function() { |
|
|
|
$("#wait_div").show(); |
|
|
|
} |
|
|
|
}).fail(function(response) { |
|
|
|
swal(js_dict["error-retry"]); |
|
|
|
}).done(function(response) { |
|
|
|
window.location.reload(); |
|
|
|
}).always(function() { |
|
|
|
$("#wait_div").slideUp('fast'); |
|
|
|
}); |
|
} |
|
</script>
|
|
|