<?


$o=[]; 
foreach(glob("$p/mail/*",GLOB_ONLYDIR) as $dp){ 
    if(strpos($D=basename($dp),'.')===false) continue;
    foreach(glob("$dp/*",GLOB_ONLYDIR) as $fp) if(is_file($f=$fp."/maildirsize")) {  
    	$s=$c=0;
    	foreach (file($f) as $index => $line)  if($index > 0) {
    	    LIST($v0,$v1) = explode(' ', $line);
    	    $s += $v0;
    	    $c += $v1;
    	} 
	    $o['Domains'][$D]['Emails'][basename($fp)]=['Size'=>$s,'Count'=>$c,'Modified'=>filemtime($f)];  
    } 
}


function WAF_ScanForWebLogs(&$o,$dir,$level=0){
    foreach(glob("$dir/*.website.log") as $f){
    	$a=pathinfo($f); $a=str_replace(".website.log","",$a['basename']); 
    	$o['Domains'][$a]=json_decode(file_get_contents($f));  
    }
    if(Level<3) foreach(glob("$dir/*",GLOB_ONLYDIR) as $d) WAF_ScanForWebLogs($o,$d); 
}


WAF_ScanForWebLogs($o,"$p/public_html");
  
  
$o['_STAT']['WAF_LOCATION']=__FILE__; 
$o['_STAT']['WAF_RPCTIME']=time(); 


header('Content-Type: application/json; charset=utf-8');
echo json_encode($o,JSON_PRETTY_PRINT);
die;


