Enhance the file checker

This commit is contained in:
Laurent Destailleur 2017-03-26 01:45:09 +01:00
parent 8c2b70c4a7
commit 9a85e5ef00
2 changed files with 23 additions and 11 deletions

View File

@ -123,16 +123,21 @@ foreach ($includeconstants as $countrycode => $tmp)
fputs($fp, '<dolibarr_htdocs_dir includecustom="'.$includecustom.'">'."\n"); fputs($fp, '<dolibarr_htdocs_dir includecustom="'.$includecustom.'">'."\n");
// TODO Replace RecursiveDirectoryIterator with dol_dir_list /*$dir_iterator1 = new RecursiveDirectoryIterator(dirname(__FILE__).'/../htdocs/');
$dir_iterator1 = new RecursiveDirectoryIterator(dirname(__FILE__).'/../htdocs/');
$iterator1 = new RecursiveIteratorIterator($dir_iterator1); $iterator1 = new RecursiveIteratorIterator($dir_iterator1);
// Need to ignore document custom etc. Note: this also ignore natively symbolic links. // Need to ignore document custom etc. Note: this also ignore natively symbolic links.
$files = new RegexIterator($iterator1, '#^(?:[A-Z]:)?(?:/(?!(?:'.($includecustom?'':'custom\/|').'documents\/|conf\/|install\/))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i'); $files = new RegexIterator($iterator1, '#^(?:[A-Z]:)?(?:/(?!(?:'.($includecustom?'':'custom\/|').'documents\/|conf\/|install\/))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i');
*/
$regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$';
$regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install)$'; // Exclude dirs
$files = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude, 'fullname');
$dir=''; $dir='';
$needtoclose=0; $needtoclose=0;
foreach ($files as $file) { foreach ($files as $filetmp) {
$newdir = str_replace(dirname(__FILE__).'/../htdocs', '', dirname($file)); $file = $filetmp['fullname'];
if ($newdir!=$dir) { //$newdir = str_replace(dirname(__FILE__).'/../htdocs', '', dirname($file));
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
if ($newdir!=$dir) {
if ($needtoclose) if ($needtoclose)
fputs($fp, ' </dir>'."\n"); fputs($fp, ' </dir>'."\n");
fputs($fp, ' <dir name="'.$newdir.'" >'."\n"); fputs($fp, ' <dir name="'.$newdir.'" >'."\n");
@ -160,14 +165,21 @@ $checksumconcat=array();
fputs($fp, '<dolibarr_script_dir version="'.$release.'">'."\n"); fputs($fp, '<dolibarr_script_dir version="'.$release.'">'."\n");
// TODO Replace RecursiveDirectoryIterator with dol_dir_list // TODO Replace RecursiveDirectoryIterator with dol_dir_list
$dir_iterator2 = new RecursiveDirectoryIterator(dirname(__FILE__).'/../scripts/'); /*$dir_iterator2 = new RecursiveDirectoryIterator(dirname(__FILE__).'/../scripts/');
$iterator2 = new RecursiveIteratorIterator($dir_iterator2); $iterator2 = new RecursiveIteratorIterator($dir_iterator2);
// Need to ignore document custom etc. Note: this also ignore natively symbolic links. // Need to ignore document custom etc. Note: this also ignore natively symbolic links.
$files = new RegexIterator($iterator2, '#^(?:[A-Z]:)?(?:/(?!(?:custom|documents|conf|install))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i'); $files = new RegexIterator($iterator2, '#^(?:[A-Z]:)?(?:/(?!(?:custom|documents|conf|install))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i');
*/
$regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$';
$regextoexclude='(custom|documents|conf|install)$'; // Exclude dirs
$files = dol_dir_list(dirname(__FILE__).'/../scripts/', 'files', 1, $regextoinclude, $regextoexclude, 'fullname');
$dir=''; $dir='';
$needtoclose=0; $needtoclose=0;
foreach ($files as $file) { foreach ($files as $filetmp) {
$newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file)); $file = $filetmp['fullname'];
//$newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file));
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
$newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file));
if ($newdir!=$dir) { if ($newdir!=$dir) {
if ($needtoclose) if ($needtoclose)
fputs($fp, ' </dir>'."\n"); fputs($fp, ' </dir>'."\n");

View File

@ -95,13 +95,13 @@ print '<!-- for a local check target=local&xmlshortfile=... -->'."\n";
if (dol_is_file($xmlfile)) if (dol_is_file($xmlfile))
{ {
print '<input type="radio" name="target" value="local"'.((! GETPOST('target') || GETPOST('target') == 'local') ? 'checked="checked"':'').'"> '.$langs->trans("LocalSignature").' = '; print '<input type="radio" name="target" value="local"'.((! GETPOST('target') || GETPOST('target') == 'local') ? 'checked="checked"':'').'"> '.$langs->trans("LocalSignature").' = ';
print '<input name="xmlshortfile" class="flat minwidth200 quatrevingtpercent" value="'.dol_escape_htmltag($xmlshortfile).'">'; print '<input name="xmlshortfile" class="flat minwidth400" value="'.dol_escape_htmltag($xmlshortfile).'">';
print '<br>'; print '<br>';
} }
else else
{ {
print '<input type="radio" name="target" value="local"> '.$langs->trans("LocalSignature").' = '; print '<input type="radio" name="target" value="local"> '.$langs->trans("LocalSignature").' = ';
print '<input name="xmlshortfile" class="flat minwidth200 quatrevingtpercent" value="'.dol_escape_htmltag($xmlshortfile).'">'; print '<input name="xmlshortfile" class="flat minwidth400" value="'.dol_escape_htmltag($xmlshortfile).'">';
print ' <span class="warning">('.$langs->trans("AvailableOnlyOnPackagedVersions").')</span>'; print ' <span class="warning">('.$langs->trans("AvailableOnlyOnPackagedVersions").')</span>';
print '<br>'; print '<br>';
} }
@ -109,7 +109,7 @@ print '<!-- for a remote target=remote&xmlremote=... -->'."\n";
if ($enableremotecheck) if ($enableremotecheck)
{ {
print '<input type="radio" name="target" value="remote"'.(GETPOST('target') == 'remote' ? 'checked="checked"':'').'> '.$langs->trans("RemoteSignature").' = '; print '<input type="radio" name="target" value="remote"'.(GETPOST('target') == 'remote' ? 'checked="checked"':'').'> '.$langs->trans("RemoteSignature").' = ';
print '<input name="xmlremote" class="flat quatrevingtpercent" value="'.dol_escape_htmltag($xmlremote).'"><br>'; print '<input name="xmlremote" class="flat minwidth400" value="'.dol_escape_htmltag($xmlremote).'"><br>';
} }
else else
{ {