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.
191 righe
9.7 KiB
191 righe
9.7 KiB
<? |
|
|
|
$configPath = substr(__DIR__,0,strpos(__DIR__,"/public_html"))."/config.php"; |
|
include_once($configPath); |
|
if (!empty($_SESSION["utente"]->oe)) { |
|
$contratto = publicStipula::init($_POST["codice_contratto"]); |
|
if (!empty($contratto)) { |
|
$record = $contratto->info; |
|
if ($contratto->canUpload()) { |
|
$sottoscrizione = $contratto->getContrattoSottoscritto(false,$contratto->codice_firmatario); |
|
$originale = $contratto->getContrattoSottoscrivere(); |
|
if (!empty($originale)) { |
|
if (!empty($originale["content"])) { |
|
$chunkPath = $config["chunk_folder"]."/".$_SESSION["utente"]->codice."/".$_POST["filechunk"]; |
|
$p7m = new P7Manager($chunkPath); |
|
if ($p7m !== false) { |
|
$error = false; |
|
if ($p7m->checkSignatures()) { |
|
$path = sys_get_temp_dir()."/".$_SESSION["utente"]->codice."/".time(); |
|
if (is_dir($path) || mkdir($path)) { |
|
$path .= "/".$originale["name"]; |
|
if (file_put_contents($path,$originale["content"])) { |
|
$p7mOriginal = new P7Manager($path); |
|
if ($p7mOriginal !== false) { |
|
$fileMime = getTypeAndExtension($path)["type"]; |
|
$pdfOriginal = false; |
|
if (strpos($fileMime,"pdf") !== false) { $pdfOriginal = true; } |
|
$signedOriginal = false; |
|
$continue = true; |
|
if ($p7mOriginal->checkSignatures()) { |
|
$signedOriginal = true; |
|
$arrayOriginalSignatures = $p7mOriginal->extractSignatures(); |
|
$arrayNewSignatures = $p7m->extractSignatures(); |
|
ob_start(); |
|
print_r($arrayOriginalSignatures); |
|
$original_signatures = ob_get_clean(); |
|
ob_start(); |
|
print_r($arrayNewSignatures); |
|
$upload_signatures = ob_get_clean(); |
|
$checkMD5 = hash("md5", $original_signatures); |
|
$checkMD5Upload = hash("md5", $upload_signatures); |
|
if ($checkMD5 == $checkMD5Upload || count($arrayOriginalSignatures) >= count($arrayNewSignatures)) { |
|
$sameUpload = true; |
|
$continue = false; |
|
} else { |
|
if (strpos($fileMime,"pdf") === false) { |
|
$originale["content"] = $p7mOriginal->opensslExtract("","content"); |
|
} |
|
} |
|
} |
|
$hash_error = false; |
|
if ($continue) { |
|
$hash["md5"] = hash("md5", $originale["content"]); |
|
$hash["sha1"] = hash("sha1", $originale["content"]); |
|
$hash["sha256"] = hash("sha256", $originale["content"]); |
|
foreach ($hash as $method => $hash_string) { |
|
if(!empty($hash_string)) { |
|
if($p7m->find($hash_string, $method) === FALSE) $hash_error = TRUE; |
|
} |
|
} |
|
} else { |
|
$hash_error = true; |
|
} |
|
if ($hash_error && $pdfOriginal && !isset($sameUpload)) { |
|
try { |
|
$parser = new \Smalot\PdfParser\Parser(); |
|
$dataContent = $parser->parseFile($path)->getText(); |
|
$dataContent = preg_replace("/[^a-zA-Z0-9]/", '', $dataContent); |
|
} catch (Exception $e) { |
|
$dataContent = ""; |
|
} |
|
$hash_string = hash("sha256",$dataContent); |
|
if ($p7m->find($hash_string,"sha256",true,true) !== FALSE) { $hash_error = false; } |
|
} |
|
if(!$hash_error) { |
|
$crypt = generateStrongPassword(); |
|
$encrypted_content = simple_encrypt($p7m->fileContent, $crypt); |
|
$filepath = "{$config["mediaFolder"]}/{$_SESSION["ente"]->codice}/contratti-signed/{$contratto->info["codice"]}"; |
|
if(! is_dir($filepath)) { mkdir($filepath, 0755, 1); } |
|
$filepath = "{$filepath}/" . md5($crypt) . $p7m->getHash("sha1"); |
|
$sottoscrizione["md5"] = $p7m->getHash("md5"); |
|
$sottoscrizione["sha1"] = $p7m->getHash("sha1"); |
|
$sottoscrizione["sha256"] = $p7m->getHash("sha256"); |
|
$sottoscrizione["content"] = $crypt; |
|
$fileMime = getTypeAndExtension($chunkPath); |
|
$sottoscrizione["mime"] = $fileMime["type"]; |
|
$sottoscrizione["name"] = sanitize_string($_POST["filechunk"]); |
|
if (!empty($encrypted_content) && file_put_contents($filepath, $encrypted_content)) { |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_contratti_sottoscritti"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = $sottoscrizione; |
|
$codice_contratto = $salva->save(); |
|
if ($codice_contratto > 0) { |
|
ob_start(); |
|
?> |
|
<h3><?= __("Upload Contratto") ?></h3> |
|
<div class="alert alert-success h1"> |
|
<?= __("Trasmissione effettuata con successo") ?> |
|
</div> |
|
<div class="card card-body mb-2"> |
|
<h3><?= __('timestamp') ?> - <?= date("d/m/Y H:i:s") ?></h3> |
|
<ul> |
|
<li>HASH MD5: <strong><?= $sottoscrizione["md5"] ?></strong></li> |
|
<li>HASH SHA1: <strong><?= $sottoscrizione["sha1"] ?></strong></li> |
|
<li>HASH SHA256: <strong><?= $sottoscrizione["sha256"] ?></strong></li> |
|
</ul> |
|
</div> |
|
<? |
|
$html_msg = ob_get_clean(); |
|
|
|
$corpo = purify($html_msg); |
|
|
|
$mailer = new Communicator(); |
|
$mailer->oggetto = __("Upload Contratto"); |
|
$mailer->corpo = $corpo; |
|
$mailer->codice_pec = $contratto->info["codice_pec"] ?? 0; |
|
$mailer->comunicazione = true; |
|
$mailer->sezione = "contratti"; |
|
$mailer->codice_gara = $contratto->info["codice"]; |
|
$mailer->coda = false; |
|
$mailer->destinatari = $_SESSION["utente"]->oe["codice"]; |
|
$mailer->send(); |
|
|
|
$mailer->codice_pec = -1; |
|
$mailer->comunicazione = false; |
|
$mailer->destinatari = Communicator::getPecAddress($contratto->info["codice_pec"]); |
|
$mailer->send(); |
|
if (count($contratto->getContrattoSottoscritto()) - 1 == count($contratto->getContraenti("oe"))) { |
|
$stato = "25"; |
|
|
|
if (!empty($contratto->getExtraInfo()["sottoscritto"])) { |
|
$stato = "30"; |
|
} |
|
|
|
$contratto->updateStato($stato); |
|
publicStipula::updateBadges($contratto->info['codice']); |
|
} |
|
?> |
|
swal({title:js_dict["success-msg"],type:"success"}).then(function(){ window.location.reload(); }); |
|
<? |
|
} else { |
|
?> |
|
swal({title:"<?= __("Errore salvataggio contratto") ?> - #005",type:"error"}); |
|
<? |
|
} |
|
} else { |
|
?> |
|
swal({title:"<?= __("Errore criptazione contratto") ?> - #004",type:"error"}); |
|
<? |
|
} |
|
} else { |
|
?> |
|
swal({title:"<?= __("Impossibile trovare una copia sottoscritta del contratto originale") ?> - #003",type:"error"}); |
|
<? |
|
} |
|
} else { |
|
?> |
|
swal({title:"<?= __("Errore confronto originale") ?> - #002",type:"error"}); |
|
<? |
|
} |
|
unlink($path); |
|
} else { |
|
?> |
|
swal({title:"<?= __("Errore confronto originale") ?> - #001",type:"error"}); |
|
<? |
|
} |
|
} else { |
|
?> |
|
swal({title:"<?= __("Errore confronto originale") ?> - #000",type:"error"}); |
|
<? |
|
} |
|
} else { |
|
?> |
|
swal({title:"<?= __("errore firma digitale") ?>",type:"error"}); |
|
<? |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
if ($error) { |
|
header('HTTP/1.0 403 Forbidden'); |
|
die(); |
|
} |
|
?>
|
|
|