* Copyright (C) 2007 Rodolphe Quiedeville * Copyright (C) 2007-2012 Regis Houssin * Copyright (C) 2015 Frederic France * Copyright (C) 2017 Nicolas ZABOURI * * 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 . */ /** * \file htdocs/admin/system/filecheck.php * \brief Page to check Dolibarr files integrity */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; $langs->load("admin"); if (!$user->admin) accessforbidden(); $error=0; /* * View */ @set_time_limit(300); llxHeader(); print load_fiche_titre($langs->trans("FileCheckDolibarr"), '', 'title_setup'); print $langs->trans("FileCheckDesc").'

'; // Version print '
'; print ''; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print '
'.$langs->trans("Version").''.$langs->trans("Value").'
'.$langs->trans("VersionLastInstall").''.$conf->global->MAIN_VERSION_LAST_INSTALL.'
'.$langs->trans("VersionLastUpgrade").''.$conf->global->MAIN_VERSION_LAST_UPGRADE.'
'.$langs->trans("VersionProgram").''.DOL_VERSION; // If current version differs from last upgrade if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE)) { // Compare version with last install database version (upgrades never occured) if (DOL_VERSION != $conf->global->MAIN_VERSION_LAST_INSTALL) print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired", DOL_VERSION, $conf->global->MAIN_VERSION_LAST_INSTALL)); } else { // Compare version with last upgrade database version if (DOL_VERSION != $conf->global->MAIN_VERSION_LAST_UPGRADE) print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired", DOL_VERSION, $conf->global->MAIN_VERSION_LAST_UPGRADE)); } print '
'; print '
'; print '
'; // Modified or missing files $file_list = array('missing' => array(), 'updated' => array()); // Local file to compare to $xmlshortfile = GETPOST('xmlshortfile', 'alpha')?GETPOST('xmlshortfile', 'alpha'):'/install/filelist-'.DOL_VERSION.(empty($conf->global->MAIN_FILECHECK_LOCAL_SUFFIX)?'':$conf->global->MAIN_FILECHECK_LOCAL_SUFFIX).'.xml'; $xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile; // Remote file to compare to $xmlremote = GETPOST('xmlremote'); if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL; $param='MAIN_FILECHECK_URL_'.DOL_VERSION; if (empty($xmlremote) && ! empty($conf->global->$param)) $xmlremote = $conf->global->$param; if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml'; // Test if remote test is ok $enableremotecheck = true; if (preg_match('/beta|alpha|rc/i', DOL_VERSION) || ! empty($conf->global->MAIN_ALLOW_INTEGRITY_CHECK_ON_UNSTABLE)) $enableremotecheck=false; $enableremotecheck = true; print '
'; print $langs->trans("MakeIntegrityAnalysisFrom").':
'; print ''."\n"; if (dol_is_file($xmlfile)) { print ' '.$langs->trans("LocalSignature").' = '; print ''; print '
'; } else { print ' '.$langs->trans("LocalSignature").' = '; print ''; print ' ('.$langs->trans("AvailableOnlyOnPackagedVersions").')'; print '
'; } print ''."\n"; if ($enableremotecheck) { print ' '.$langs->trans("RemoteSignature").' = '; print '
'; } else { print ' '.$langs->trans("RemoteSignature").' = '.$xmlremote; if (! GETPOST('xmlremote')) print ' ('.$langs->trans("FeatureAvailableOnlyOnStable").')'; print '
'; } print '
'; print '
'; print '
'; print '
'; if (GETPOST('target') == 'local') { if (dol_is_file($xmlfile)) { $xml = simplexml_load_file($xmlfile); } else { print $langs->trans('XmlNotFound') . ': ' . $xmlfile; $error++; } } if (GETPOST('target') == 'remote') { $xmlarray = getURLContent($xmlremote); // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...) if (! $xmlarray['curl_error_no'] && $xmlarray['http_code'] != '404') { $xmlfile = $xmlarray['content']; //print "xmlfilestart".$xmlfile."xmlfileend"; $xml = simplexml_load_string($xmlfile); } else { $errormsg=$langs->trans('XmlNotFound') . ': ' . $xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg']; setEventMessages($errormsg, null, 'errors'); $error++; } } if (! $error && $xml) { $checksumconcat = array(); $file_list = array(); $out = ''; // Forced constants if (is_object($xml->dolibarr_constants[0])) { $out.=load_fiche_titre($langs->trans("ForcedConstants")); $out.='
'; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''."\n"; $i = 0; foreach ($xml->dolibarr_constants[0]->constant as $constant) // $constant is a simpleXMLElement { $constname=$constant['name']; $constvalue=(string) $constant; $constvalue = (empty($constvalue)?'0':$constvalue); // Value found $value=''; if ($constname && $conf->global->$constname != '') $value=$conf->global->$constname; $valueforchecksum=(empty($value)?'0':$value); $checksumconcat[]=$valueforchecksum; $i++; $out.=''; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.="\n"; } if ($i==0) { $out.=''; } $out.='
#' . $langs->trans("Constant") . '' . $langs->trans("ExpectedValue") . '' . $langs->trans("Value") . '
'.$i.''.$constname.''.$constvalue.''.$valueforchecksum.'
'.$langs->trans("None").'
'; $out.='
'; $out.='
'; } // Scan htdocs if (is_object($xml->dolibarr_htdocs_dir[0])) { //var_dump($xml->dolibarr_htdocs_dir[0]['includecustom']);exit; $includecustom=(empty($xml->dolibarr_htdocs_dir[0]['includecustom'])?0:$xml->dolibarr_htdocs_dir[0]['includecustom']); // Defined qualified files (must be same than into generate_filelist_xml.php) $regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$'; $regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude); // Fill file_list with files in signature, new files, modified files $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat, $scanfiles); // Fill array $file_list // Complete with list of new files foreach ($scanfiles as $keyfile => $valfile) { $tmprelativefilename=preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']); if (! in_array($tmprelativefilename, $file_list['insignature'])) { $md5newfile=@md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file $file_list['added'][]=array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile); } } // Files missings $out.=load_fiche_titre($langs->trans("FilesMissing")); $out.='
'; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''."\n"; $tmpfilelist = dol_sort_array($file_list['missing'], 'filename'); if (is_array($tmpfilelist) && count($tmpfilelist)) { $i = 0; foreach ($tmpfilelist as $file) { $i++; $out.=''; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.="\n"; } } else { $out.=''; } $out.='
#' . $langs->trans("Filename") . '' . $langs->trans("ExpectedChecksum") . '
'.$i.''.$file['filename'].''.$file['expectedmd5'].'
'.$langs->trans("None").'
'; $out.='
'; $out.='
'; // Files modified $out.=load_fiche_titre($langs->trans("FilesModified")); $totalsize=0; $out.='
'; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''."\n"; $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename'); if (is_array($tmpfilelist2) && count($tmpfilelist2)) { $i = 0; foreach ($tmpfilelist2 as $file) { $i++; $out.=''; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']); $totalsize += $size; $out.='' . "\n"; $out.='' . "\n"; $out.="\n"; } $out.=''; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.="\n"; } else { $out.=''; } $out.='
#' . $langs->trans("Filename") . '' . $langs->trans("ExpectedChecksum") . '' . $langs->trans("CurrentChecksum") . '' . $langs->trans("Size") . '' . $langs->trans("DateModification") . '
'.$i.''.$file['filename'].''.$file['expectedmd5'].''.$file['md5'].''.dol_print_size($size).''.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'
'.$langs->trans("Total").''.dol_print_size($totalsize).'
'.$langs->trans("None").'
'; $out.='
'; $out.='
'; // Files added $out.=load_fiche_titre($langs->trans("FilesAdded")); $totalsize = 0; $out.='
'; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''; $out.=''."\n"; $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename'); if (is_array($tmpfilelist3) && count($tmpfilelist3)) { $i = 0; foreach ($tmpfilelist3 as $file) { $i++; $out.=''; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']); $totalsize += $size; $out.='' . "\n"; $out.='' . "\n"; $out.="\n"; } $out.=''; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.='' . "\n"; $out.="\n"; } else { $out.=''; } $out.='
#' . $langs->trans("Filename") . '' . $langs->trans("ExpectedChecksum") . '' . $langs->trans("CurrentChecksum") . '' . $langs->trans("Size") . '' . $langs->trans("DateModification") . '
'.$i.''.$file['filename']; if (! preg_match('/^win/i', PHP_OS)) { $htmltext=$langs->trans("YouCanDeleteFileOnServerWith", 'rm '.DOL_DOCUMENT_ROOT.$file['filename']); // The slash is included int file['filename'] $out.=' '.$form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helprm'.$i); } $out.=''.$file['expectedmd5'].''.$file['md5'].''.dol_print_size($size).''.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'
'.$langs->trans("Total").''.dol_print_size($totalsize).'
'.$langs->trans("None").'
'; $out.='
'; // Show warning if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) { setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs'); } else { setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings'); } } else { print 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile; $error++; } // Scan scripts /* if (is_object($xml->dolibarr_script_dir[0])) { $file_list = array(); $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', ???, $checksumconcat); // Fill array $file_list }*/ asort($checksumconcat); // Sort list of checksum //var_dump($checksumconcat); $checksumget = md5(join(',', $checksumconcat)); $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum); /*var_dump(count($file_list['added'])); var_dump($checksumget); var_dump($checksumtoget); var_dump($checksumget == $checksumtoget);*/ $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown")); if ($checksumget == $checksumtoget) { if (count($file_list['added'])) { $resultcode = 'warning'; $resultcomment='FileIntegrityIsOkButFilesWereAdded'; $outcurrentchecksum = $checksumget.' - '.$langs->trans("FileIntegrityIsOkButFilesWereAdded").''; } else { $resultcode = 'ok'; $resultcomment='Success'; $outcurrentchecksum = ''.$checksumget.''; } } else { $resultcode = 'error'; $resultcomment='Error'; $outcurrentchecksum = ''.$checksumget.''; } print load_fiche_titre($langs->trans("GlobalChecksum")).'
'; print $langs->trans("ExpectedChecksum").' = '. $outexpectedchecksum .'
'; print $langs->trans("CurrentChecksum").' = '. $outcurrentchecksum; print '
'; print '
'; // Output detail print $out; } // End of page llxFooter(); $db->close(); exit($error);