Commit db050e1c authored by sreg's avatar sreg

- Mise en open source (oss)

parents
Pipeline #1392 failed with stages
<?php
function displayErrors($errors)
{
$cnt=count($errors);
printf("failed - %ld error%s\n",$cnt,$cnt>1?'s':'');
foreach($errors as $error)
echo "$error\n";
}
function checkingName($dir,$authorized,$path='',$mode='EXACT')
{
$errors=array();
if($mode=='EXACT')
foreach($dir as $name=>$value)
if(!in_array($name,$authorized))
$errors[]=sprintf(" WTF: %s%s ???",$path,$name);
if($mode=='EXACT' || $mode=='EXISTS')
foreach($authorized as $k=>$name)
if(!array_key_exists($name,$dir))
$errors[]=sprintf(" Where is: %s%s ???",$path,$name);
return $errors;
}
function checkingPattern(&$array,$pattern,$recurse='')
{
$errors=array();
foreach($array as $name=>$value)
{
$isRep=preg_match('#^.*/$#',$name);
if($recurse!==false && $isRep)
$errors=array_merge($errors,checkingPattern($array[$name],$pattern,"$recurse$name"));
if(!$isRep && !preg_match($pattern,$name))
$errors[]=sprintf(" %s%s ???",$recurse,$name);
}
return $errors;
}
function checkingContent(&$array,$patternFiles,$callback,$recurse='')
{
$errors=array();
foreach($array as $name=>$value)
{
$isRep=preg_match('#^.*/$#',$name);
if($recurse!==false && $isRep)
$errors=array_merge($errors,checkingContent($array[$name],$patternFiles,$callback,"$recurse$name"));
if(!$isRep && preg_match($patternFiles,$name))
if($error=$callback($recurse,$name)) //sprintf(" %s%s ???",$recurse,$name);
$errors[]=$error;
}
return $errors;
}
function recalcIntegrity()
{
$array=array();
showDir('../',true,0,$array);
//print_r($array); die;
checkingContent($array['sys/']['quark/'],'#^.*\.php$#',
function($path,$name)
{
$fileName=__DIR__."/../$path$name";
if($content=file_get_contents($fileName))
if($content=preg_replace('#//Integrity:.*$#mi','//Integrity:',$content))
{
$content=preg_replace('#//Integrity:.*$#mi','//Integrity: '.sha1($content),$content);
file_put_contents($fileName,$content);
}
},'sys/quark/');
}
//print_r(scandir('../../')); die;
function showDir($path,$recurs=false,$level=0,&$array)
{
if($dir=@opendir($path))
{
if(($oldPath=getcwd())!==false)
if(chdir($path))
{
while(($f=@readdir($dir))!==false)
{
if(preg_match('#^\..*$#',$f)) continue;
$p=is_dir("$f")?'/':'';
//echo str_repeat(' ',$level*4)."$f$p\n";
if($p=='/') $array["$f$p"]=array();
else $array[$f]=$f;
if($recurs && $p) showDir($f,$recurs,$level+1,$array["$f$p"]);
}
chdir($oldPath);
}
closedir($dir);
}
}
function checkQuarky()
{
$array=array();
showDir('../',true,0,$array);
printf("Checking base directory structure: ");
if($errors=checkingName($array,array('batch/','cache/','config/','logs/','sys/','view/','web/'),'./'))
{
displayErrors($errors);
} else echo "ok\n";
printf("Checking sys/ directory structure: ");
if($errors=checkingName($array['sys/'],array('class/','quark/','param.php'),'sys/','EXISTS'))
{
displayErrors($errors);
} else echo "ok\n";
if(empty($errors))
{
printf("Checking framework integrity : ");
//excel.php mysqli.php mysql.php odbc.php oracle.php postgresql.php sqlserver.php
$errors=checkingName($array['sys/']['quark/'],array('db/','qasset.php','qcache.php','qcontentparser.php','qdb.php','qform.php','qmail.php','qsmtp.php','qstring.php','quark.php','quarky.php'),'sys/quark/');
if(empty($errors))
{
if($errors=checkingName($array['sys/']['quark/']['db/'],array('excel.php','mysqli.php','mysql.php','odbc.php','oracle.php','postgresql.php','sqlserver.php'),'sys/quark/db/'))
{
displayErrors($errors);
}
if(empty($errors))
if($errors=checkingContent($array['sys/']['quark/'],'#^.*\.php$#',
function($path,$name)
{
$fileName=__DIR__."/../$path$name";
if(!($content=file_get_contents($fileName)))
return sprintf(" %s%s: empty file ???",$path,$name);
if(!preg_match('#//Integrity: (.*)$#mi',$content,$m))
return sprintf(" %s%s: unable to find integrity check ???",$path,$name);
if($content=preg_replace('#//Integrity:.*$#mi','//Integrity:',$content))
{
if($m[1]!=sha1($content))
return sprintf(" %s%s: integrity failure ???",$path,$name);
} else
return sprintf(" %s%s: integrity failure ???",$path,$name);
return false;
},'sys/quark/'))
{