From 44ab6ad9b7af0c6fa327dd846f1c90ca5b899d9c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 10 Feb 2017 17:05:45 +0100 Subject: [PATCH] NEW Can control constants values into file integrity checker --- build/generate_filelist_xml.php | 65 ++++++++++++++++++++++--------- htdocs/admin/system/filecheck.php | 46 ++++++++++++++++++++++ htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/en_US/main.lang | 2 + 4 files changed, 95 insertions(+), 19 deletions(-) diff --git a/build/generate_filelist_xml.php b/build/generate_filelist_xml.php index 01809439bf1..36ea0e9542b 100755 --- a/build/generate_filelist_xml.php +++ b/build/generate_filelist_xml.php @@ -1,6 +1,6 @@ #!/usr/bin/env php +/* Copyright (C) 2015-2017 Laurent Destailleur * * 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 @@ -40,21 +40,33 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); * Main */ +$includeconstants=array(); + if (empty($argv[1])) { - print "Usage: ".$script_file." release=x.y.z[-...] [includecustom=1]\n"; + print "Usage: ".$script_file." release=x.y.z[-...] [includecustom=1] [includeconstant=MY_CONF_NAME:value]\n"; + print "Example: ".$script_file." release=6.0.0 includecustom=1 includeconstant=INVOICE_CAN_ALWAYS_BE_REMOVED:0 includeconstant=MAILING_NO_USING_PHPMAIL:1\n"; exit -1; } -parse_str($argv[1]); -if (! empty($argv[2])) parse_str($argv[2]); +$i=0; +while ($i < $argc) +{ + if (! empty($argv[$i])) parse_str($argv[$i]); + if (preg_match('/includeconstant=/',$argv[$i])) + { + $tmp=explode(':', $includeconstant); + if (count($tmp) == 2) $includeconstants[$tmp[0]] = $tmp[1]; + } + $i++; +} -if (empty($includecustom)) +if (empty($includecustom)) { $includecustom=0; - + if (DOL_VERSION != $release) { - print 'Error: When parameter "includecustom" is not set, version declared into filefunc.in.php ('.DOL_VERSION.') must be exact same value than "release" parmater.'."\n"; + print 'Error: When parameter "includecustom" is not set, version declared into filefunc.in.php ('.DOL_VERSION.') must be exact same value than "release" parameter ('.$release.')'."\n"; print "Usage: ".$script_file." release=x.y.z[-...] [includecustom=1]\n"; exit -1; } @@ -69,22 +81,37 @@ else } } -print "Version: ".$release."\n"; -print "Include custom: ".$includecustom."\n"; +print "Release : ".$release."\n"; +print "Include custom : ".$includecustom."\n"; +print "Include constants: "; +foreach ($includeconstants as $constname => $constvalue) +{ + print $constname.'='.$constvalue." "; +} +print "\n"; //$outputfile=dirname(__FILE__).'/../htdocs/install/filelist-'.$release.'.xml'; $outputdir=dirname(__FILE__).'/../htdocs/install'; print 'Delete current files '.$outputdir.'/filelist-'.$release.'.xml'."\n"; dol_delete_file($outputdir.'/filelist-'.$release.'.xml',0,1,1); +$checksumconcat=array(); + $outputfile=$outputdir.'/filelist-'.$release.'.xml'; $fp = fopen($outputfile,'w'); fputs($fp, ''."\n"); fputs($fp, ''."\n"); -fputs($fp, ''."\n"); +fputs($fp, ''."\n"); +foreach($includeconstants as $constname => $constvalue) +{ + $valueforchecksum=(empty($constvalue)?'0':$constvalue); + $checksumconcat[]=$valueforchecksum; + fputs($fp, ' '.$valueforchecksum.''."\n"); +} +fputs($fp, ''."\n"); -$checksumconcat=array(); +fputs($fp, ''."\n"); // TODO Replace RecursiveDirectoryIterator with dol_dir_list $dir_iterator1 = new RecursiveDirectoryIterator(dirname(__FILE__).'/../htdocs/'); @@ -97,18 +124,18 @@ foreach ($files as $file) { $newdir = str_replace(dirname(__FILE__).'/../htdocs', '', dirname($file)); if ($newdir!=$dir) { if ($needtoclose) - fputs($fp, ''."\n"); - fputs($fp, ''."\n"); + fputs($fp, ' '."\n"); + fputs($fp, ' '."\n"); $dir = $newdir; $needtoclose=1; } if (filetype($file)=="file") { $md5=md5_file($file); $checksumconcat[]=$md5; - fputs($fp, ''.$md5.''."\n"); + fputs($fp, ' '.$md5.''."\n"); } } -fputs($fp, ''."\n"); +fputs($fp, ' '."\n"); fputs($fp, ''."\n"); asort($checksumconcat); // Sort list of checksum @@ -133,18 +160,18 @@ foreach ($files as $file) { $newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file)); if ($newdir!=$dir) { if ($needtoclose) - fputs($fp, ''."\n"); - fputs($fp, ''."\n"); + fputs($fp, ' '."\n"); + fputs($fp, ' '."\n"); $dir = $newdir; $needtoclose=1; } if (filetype($file)=="file") { $md5=md5_file($file); $checksumconcat[]=$md5; - fputs($fp, ''.$md5.''."\n"); + fputs($fp, ' '.$md5.''."\n"); } } -fputs($fp, ''."\n"); +fputs($fp, ' '."\n"); fputs($fp, ''."\n"); asort($checksumconcat); // Sort list of checksum diff --git a/htdocs/admin/system/filecheck.php b/htdocs/admin/system/filecheck.php index 6499f16f76c..498e1ec54f0 100644 --- a/htdocs/admin/system/filecheck.php +++ b/htdocs/admin/system/filecheck.php @@ -160,6 +160,52 @@ if ($xml) $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.=''."\n"; + $var = true; + + $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++; + $var = !$var; + $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.='
'; + } + // Scan htdocs if (is_object($xml->dolibarr_htdocs_dir[0])) { diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 2597a995043..987f02fe314 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1611,6 +1611,7 @@ FixTZ=TimeZone fix FillFixTZOnlyIfRequired=Example: +2 (fill only if problem experienced) ExpectedChecksum=Expected Checksum CurrentChecksum=Current Checksum +ForcedConstants=Required constant values MailToSendProposal=To send customer proposal MailToSendOrder=To send customer order MailToSendInvoice=To send customer invoice diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 603aff0000f..106b0a9f240 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -599,6 +599,8 @@ SessionName=Session name Method=Method Receive=Receive CompleteOrNoMoreReceptionExpected=Complete or nothing more expected +ExpectedValue=Expected Value +CurrentValue=Current Value PartialWoman=Partial TotalWoman=Total NeverReceived=Never received