|
21 | 21 |
|
22 | 22 | include_once __DIR__.'/../../core.php'; |
23 | 23 |
|
24 | | -// Aggiunta della classe per il modulo |
| 24 | +// ======================================================================== |
| 25 | +// FUNZIONI HELPER PER CONTROLLO CHECKSUM |
| 26 | +// ======================================================================== |
| 27 | + |
| 28 | +/** |
| 29 | + * Carica i checksum dal file principale e dai moduli premium |
| 30 | + */ |
| 31 | +function loadAllChecksums() |
| 32 | +{ |
| 33 | + $checksum = []; |
| 34 | + |
| 35 | + // Carica checksum principale |
| 36 | + $main_checksum_file = base_dir().'/checksum.json'; |
| 37 | + if (file_exists($main_checksum_file)) { |
| 38 | + $contents = file_get_contents($main_checksum_file); |
| 39 | + $checksum = json_decode($contents, true) ?: []; |
| 40 | + } |
| 41 | + |
| 42 | + // Carica checksum dai moduli premium |
| 43 | + $module_checksum_files = glob(base_dir().'/modules/*/checksum.json') ?: []; |
| 44 | + foreach ($module_checksum_files as $module_checksum_file) { |
| 45 | + $module_contents = file_get_contents($module_checksum_file); |
| 46 | + $module_checksum = json_decode($module_contents, true); |
| 47 | + if (!empty($module_checksum)) { |
| 48 | + $checksum = array_merge($checksum, $module_checksum); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + return $checksum; |
| 53 | +} |
| 54 | + |
| 55 | +/** |
| 56 | + * Verifica l'integrità dei file rispetto ai checksum |
| 57 | + */ |
| 58 | +function verifyFileIntegrity($checksum) |
| 59 | +{ |
| 60 | + $errors = []; |
| 61 | + foreach ($checksum as $file => $md5) { |
| 62 | + $verifica = md5_file(base_dir().'/'.$file); |
| 63 | + if ($verifica != $md5) { |
| 64 | + $errors[] = $file; |
| 65 | + } |
| 66 | + } |
| 67 | + return $errors; |
| 68 | +} |
| 69 | + |
| 70 | +/** |
| 71 | + * Renderizza la tabella degli errori di integrità |
| 72 | + */ |
| 73 | +function renderIntegrityErrorsTable($errors) |
| 74 | +{ |
| 75 | + $html = '<p>'.tr("Segue l'elenco dei file che presentano checksum diverso rispetto a quello registrato nella versione ufficiale").'.</p>'; |
| 76 | + $html .= '<div class="alert alert-warning"><i class="fa fa-exclamation-triangle"></i> '.tr('Attenzione: questa funzionalità può presentare dei risultati falsamente positivi, sulla base del contenuto del file _FILE_', ['_FILE_' => '<b>checksum.json</b>']).'.'. |
| 77 | + '</div>'; |
| 78 | + $html .= '<table class="table table-bordered table-striped table-hover"><thead><tr><th>'.tr('File con integrità errata').'</th></tr></thead><tbody>'; |
| 79 | + |
| 80 | + foreach ($errors as $error) { |
| 81 | + $html .= '<tr><td class="file-integrity-error"><i class="fa fa-exclamation-triangle"></i> '.$error.'</td></tr>'; |
| 82 | + } |
| 83 | + |
| 84 | + $html .= '</tbody></table>'; |
| 85 | + return $html; |
| 86 | +} |
| 87 | + |
| 88 | +// ======================================================================== |
| 89 | +// LOGICA PRINCIPALE |
| 90 | +// ======================================================================== |
| 91 | + |
25 | 92 | echo '<div class="module-aggiornamenti">'; |
26 | 93 |
|
27 | 94 | $file = basename(__FILE__); |
28 | 95 | $effettua_controllo = filter('effettua_controllo'); |
29 | 96 |
|
30 | | -// Schermata di caricamento delle informazioni |
| 97 | +// Schermata di caricamento |
31 | 98 | if (empty($effettua_controllo)) { |
32 | 99 | echo ' |
33 | | -<div id="righe_controlli"> |
34 | | -
|
35 | | -</div> |
36 | | -
|
| 100 | +<div id="righe_controlli"></div> |
37 | 101 | <div class="alert alert-info" id="card-loading"> |
38 | 102 | <i class="fa fa-spinner fa-spin"></i> '.tr('Caricamento in corso').'... |
39 | 103 | </div> |
40 | | -
|
41 | 104 | <script> |
42 | 105 | var content = $("#righe_controlli"); |
43 | 106 | var loader = $("#card-loading"); |
44 | 107 | $(document).ready(function () { |
45 | 108 | loader.show(); |
46 | | -
|
47 | 109 | content.html(""); |
48 | 110 | content.load("'.$structure->fileurl($file).'?effettua_controllo=1&id_module='.$id_module.'", function() { |
49 | 111 | loader.hide(); |
50 | 112 | }); |
51 | 113 | }) |
52 | 114 | </script>'; |
53 | | - |
| 115 | + echo '</div>'; |
54 | 116 | return; |
55 | 117 | } |
56 | 118 |
|
57 | | -$contents = file_get_contents(base_dir().'/checksum.json'); |
58 | | -$checksum = json_decode($contents, true); |
59 | | - |
60 | | -// Carica e accoda i checksum dei moduli premium |
61 | | -$modules_dir = base_dir().'/modules/'; |
62 | | -$module_checksum_files = glob($modules_dir.'*/checksum.json'); |
63 | | - |
64 | | -if (!empty($module_checksum_files)) { |
65 | | - foreach ($module_checksum_files as $module_checksum_file) { |
66 | | - $module_contents = file_get_contents($module_checksum_file); |
67 | | - $module_checksum = json_decode($module_contents, true); |
68 | | - |
69 | | - if (!empty($module_checksum)) { |
70 | | - // Accoda i checksum del modulo a quello principale |
71 | | - $checksum = array_merge($checksum, $module_checksum); |
72 | | - } |
73 | | - } |
74 | | -} |
| 119 | +// Carica checksum |
| 120 | +$checksum = loadAllChecksums(); |
75 | 121 |
|
76 | 122 | if (empty($checksum)) { |
77 | | - echo ' |
78 | | -<div class="alert alert-warning"> |
79 | | - <i class="fa fa-warning"></i> '.tr('Impossibile effettuare controlli di integrità in assenza del file _FILE_', [ |
80 | | - '_FILE_' => '<b>checksum.json</b>', |
81 | | - ]).'. |
82 | | -</div>'; |
83 | | - |
| 123 | + 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>']).'.'. |
| 124 | + '</div></div>'; |
84 | 125 | return; |
85 | 126 | } |
86 | 127 |
|
87 | | -// Controllo degli errori |
88 | | -$errors = []; |
89 | | -foreach ($checksum as $file => $md5) { |
90 | | - $verifica = md5_file(base_dir().'/'.$file); |
91 | | - if ($verifica != $md5) { |
92 | | - $errors[] = $file; |
93 | | - } |
94 | | -} |
| 128 | +// Verifica integrità |
| 129 | +$errors = verifyFileIntegrity($checksum); |
95 | 130 | OperationLog::setInfo('id_module', $id_module); |
96 | 131 |
|
97 | | -// Schermata di visualizzazione degli errori |
| 132 | +// Renderizza risultati |
98 | 133 | if (!empty($errors)) { |
99 | | - echo ' |
100 | | -<p>'.tr("Segue l'elenco dei file che presentano checksum diverso rispetto a quello registrato nella versione ufficiale").'.</p> |
101 | | -<div class="alert alert-warning"> |
102 | | - <i class="fa fa-exclamation-triangle"></i> |
103 | | - '.tr('Attenzione: questa funzionalità può presentare dei risultati falsamente positivi, sulla base del contenuto del file _FILE_', [ |
104 | | - '_FILE_' => '<b>checksum.json</b>', |
105 | | - ]).'. |
106 | | -</div> |
107 | | -
|
108 | | -<table class="table table-bordered table-striped table-hover"> |
109 | | - <thead> |
110 | | - <tr> |
111 | | - <th>'.tr('File con integrità errata').'</th> |
112 | | - </tr> |
113 | | - </thead> |
114 | | -
|
115 | | - <tbody>'; |
116 | | - |
117 | | - foreach ($errors as $error) { |
118 | | - echo ' |
119 | | - <tr> |
120 | | - <td class="file-integrity-error"> |
121 | | - <i class="fa fa-exclamation-triangle"></i> '.$error.' |
122 | | - </td> |
123 | | - </tr>'; |
124 | | - } |
125 | | - |
126 | | - echo ' |
127 | | - </tbody> |
128 | | -</table>'; |
| 134 | + echo renderIntegrityErrorsTable($errors); |
129 | 135 | } else { |
130 | | - echo ' |
131 | | -<div class="alert alert-info"> |
132 | | - <i class="fa fa-info-circle"></i> '.tr('Nessun file con problemi di integrità').'. |
133 | | -</div>'; |
| 136 | + echo '<div class="alert alert-info"><i class="fa fa-info-circle"></i> '.tr('Nessun file con problemi di integrità').'.'. |
| 137 | + '</div>'; |
134 | 138 | } |
| 139 | + |
135 | 140 | OperationLog::setInfo('options', json_encode(['controllo_name' => 'Controllo file'], JSON_UNESCAPED_UNICODE)); |
136 | 141 | OperationLog::build('effettua_controllo'); |
137 | 142 |
|
138 | | -// Chiusura del div module-aggiornamenti |
139 | 143 | echo '</div>'; |
0 commit comments