openstamanager/modules/aggiornamenti/checksum.php

119 lines
3.2 KiB
PHP
Raw Permalink Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2024-03-03 17:52:50 +01:00
use Models\OperationLog;
include_once __DIR__.'/../../core.php';
$file = basename(__FILE__);
$effettua_controllo = filter('effettua_controllo');
// Schermata di caricamento delle informazioni
if (empty($effettua_controllo)) {
echo '
<div id="righe_controlli">
</div>
2024-05-16 18:02:50 +02:00
<div class="alert alert-info" id="card-loading">
<i class="fa fa-spinner fa-spin"></i> '.tr('Caricamento in corso').'...
</div>
<script>
var content = $("#righe_controlli");
2024-05-16 18:02:50 +02:00
var loader = $("#card-loading");
$(document).ready(function () {
loader.show();
content.html("");
2024-03-03 17:52:50 +01:00
content.load("'.$structure->fileurl($file).'?effettua_controllo=1&id_module='.$id_module.'", function() {
loader.hide();
});
})
</script>';
return;
}
$contents = file_get_contents(base_dir().'/checksum.json');
$checksum = json_decode($contents);
if (empty($checksum)) {
echo '
<div class="alert alert-warning">
<i class="fa fa-warning"></i> '.tr('Impossibile effettuare controlli di integrità in assenza del file _FILE_', [
'_FILE_' => '<b>checksum.json</b>',
]).'.
</div>';
return;
}
// Controllo degli errori
$errors = [];
foreach ($checksum as $file => $md5) {
$verifica = md5_file(base_dir().'/'.$file);
if ($verifica != $md5) {
$errors[] = $file;
}
}
2024-03-03 17:52:50 +01:00
OperationLog::setInfo('id_module', $id_module);
// Schermata di visualizzazione degli errori
if (!empty($errors)) {
2024-03-03 17:52:50 +01:00
OperationLog::setInfo('options', 'KO');
echo '
<p>'.tr("Segue l'elenco dei file che presentano checksum diverso rispetto a quello registrato nella versione ufficiale").'.</p>
<div class="alert alert-warning">
<i class="fa fa-warning"></i>
'.tr('Attenzione: questa funzionalità può presentare dei risultati falsamente positivi, sulla base del contenuto del file _FILE_', [
2024-03-22 15:52:24 +01:00
'_FILE_' => '<b>checksum.json</b>',
]).'.
</div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>'.tr('File con integrità errata').'</th>
</tr>
</thead>
<tbody>';
foreach ($errors as $error) {
echo '
<tr>
<td>
'.$error.'
</td>
</tr>';
}
echo '
</tbody>
</table>';
} else {
2024-03-03 17:52:50 +01:00
OperationLog::setInfo('options', 'OK');
echo '
<div class="alert alert-info">
<i class="fa fa-info-circle"></i> '.tr('Nessun file con problemi di integrità').'.
</div>';
}
2024-03-22 15:52:24 +01:00
OperationLog::build('effettua_controllo');