<?php
// Filesystem-only audit. No bootstrap, PDO or HTTP.
$lock=json_decode(file_get_contents(__DIR__.'/source-lock.json'),true);$actual=[];$walk=new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__.'/source/application',FilesystemIterator::SKIP_DOTS));foreach($walk as $f){if($f->isLink())throw new RuntimeException('Source symlink');if($f->isFile())$actual[substr($f->getPathname(),strlen(__DIR__.'/source/application/'))]=hash_file('sha256',$f->getPathname());}ksort($lock);ksort($actual);if(count($actual)!==959||$actual!==$lock)throw new RuntimeException('Source fileset drift');$all=[];$count=0;$tools=[];foreach(glob(__DIR__.'/private/wire-R12.json')as $file){$w=json_decode(file_get_contents($file),true);foreach($w['included_files']as $f){$path=$f['path'];if(strpos($path,__DIR__.'/')===0&&strpos($path,__DIR__.'/source/application/')!==0){$tools[$path][]=$f['sha256'];continue;}if(!is_file($path)||hash_file('sha256',$path)!==$f['sha256'])throw new RuntimeException('Actual source dependency changed');$all[$path]=$f['sha256'];$count++;}}$r=['source_files'=>959,'source_mapping_sha256'=>hash_file('sha256',__DIR__.'/source-lock.json'),'actual_non_tool_include_records_checked'=>$count,'unique_source_dependencies'=>$all,'request_tool_hashes'=>$tools,'DB'=>0,'HTTP'=>0];$f=__DIR__.'/private/resource-R12-proof.json';$h=fopen($f,'xb');fwrite($h,json_encode($r,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));fclose($h);chmod($f,0600);echo json_encode(['source_files'=>959,'include_records_verified'=>$count,'DB'=>0,'HTTP'=>0]),"\n";
