20 lines
4.3 KiB
PHP
20 lines
4.3 KiB
PHP
<?php
|
|
// Read-only recovery verification; publish readiness only after concrete restore/QA correspondence.
|
|
use Illuminate\Encryption\Encrypter;
|
|
$root=dirname(__DIR__);require $root.'/vendor/autoload.php';ini_set('zend.exception_ignore_args','1');
|
|
$dir=$root.'/storage/app/private/investmoz-v2/portal-audit';$read=static fn($p)=>json_decode(file_get_contents($p),true,512,JSON_THROW_ON_ERROR);
|
|
$prepared=$read($dir.'/stability-active-preparation-latest.json');$link=$prepared['backup_link'];$proof=$read($link['path']);$target=$proof['restored_target'];
|
|
throw_unless($prepared['result']==='verified_snapshots_ready_before_Laragon_stop'&&(int)$target['port']===55441&&preg_match('/^country_candidate_\d{8}_\d{6}_test$/D',$target['database']),RuntimeException::class,'Fresh matching QA restore required.');
|
|
$zip=new ZipArchive;throw_unless($zip->open($proof['files_path'])===true,RuntimeException::class,'Corresponding private archive required.');$runtime=json_decode($zip->getFromName('runtime/effective-runtime.json'),true,512,JSON_THROW_ON_ERROR);$zip->close();
|
|
$key=$runtime['app_key'];$key=str_starts_with($key,'base64:')?base64_decode(substr($key,7),true):$key;$crypt=new Encrypter($key,$runtime['cipher']);
|
|
$pdo=new PDO('pgsql:host=127.0.0.1;port=55441;dbname='.$target['database'],'postgres','',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$pdo->exec('BEGIN READ ONLY');
|
|
throw_unless((int)$pdo->query('SELECT inet_server_port()')->fetchColumn()===55441,RuntimeException::class,'Actual QA server required.');$mfa=0;
|
|
foreach($pdo->query('SELECT two_factor_secret,two_factor_recovery_codes FROM users WHERE two_factor_secret IS NOT NULL')->fetchAll(PDO::FETCH_ASSOC) as $u){$plain=$crypt->decrypt($u['two_factor_secret'],false);throw_unless(is_string($plain)&&$plain!=='',RuntimeException::class,'Restored original MFA envelope unreadable.');if($u['two_factor_recovery_codes']!==null)$crypt->decrypt($u['two_factor_recovery_codes'],false);$mfa++;}
|
|
$pdo->exec('ROLLBACK');throw_unless($mfa===count($proof['original_mfa_user_ids']),RuntimeException::class,'Original MFA coverage differs.');
|
|
$qa=$read($prepared['package'].'/country02-interface.json');$sql=$read($prepared['package'].'/country02-persistencia.json');$reversal=$read($prepared['package'].'/backup-pos-utilizacao-qa.json');
|
|
throw_unless($qa['result']==='passed'&&$sql['result']==='passed'&&$reversal['result']==='passed'&&$qa['build_sha256']===$prepared['production_manifest_sha256']&&$qa['code_hash']===$prepared['code_hash'],RuntimeException::class,'Exact final browser/persistence/restoration proofs required.');
|
|
foreach($prepared['backup_files'] as $file=>$v)throw_unless(hash_file('sha256',$file)===$v['sha256']&&hash_file('sha256',$v['backup'])===$v['sha256'],RuntimeException::class,'Preserved baseline snapshot differs.');
|
|
$originalHash=$proof['code_hash'];$proof=[...$proof,'source_code_hash'=>$originalHash,'code_hash'=>$prepared['code_hash'],'delivery_revision'=>$prepared['delivery_revision'],'production_manifest_sha256'=>$prepared['production_manifest_sha256'],'production_input_hash'=>$prepared['production_input_hash'],'original_mfa_envelopes_recovered'=>$mfa,'compatibility_verified'=>true,'reversal_verified'=>true,'qa_passed'=>true,'evidence_scope'=>'Fresh active READ ONLY dump restored in QA, original envelopes recovered, exact business baseline correspondence, final sealed browser/persistence/reversal proofs reused without repeating unchanged scenarios','QA_receipts_sha256'=>array_map(static fn($name)=>hash_file('sha256',$prepared['package'].'/'.$name),['country02-interface.json','country02-persistencia.json','backup-pos-utilizacao-qa.json','restauro-original.json']),'active_writes'=>0];
|
|
$file=$prepared['directory'].'/fresh-readiness.json';file_put_contents($file,json_encode($proof,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));file_put_contents($dir.'/stability-active-backup-latest.json',json_encode(['path'=>$file,'directory'=>$prepared['directory'],'restored_target'=>$target],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
|
|
echo json_encode(['result'=>'fresh_backup_restore_and_final_revision_correspond','at'=>$proof['verified_at'],'tables'=>count($proof['tables']),'sequences'=>count($proof['sequences']),'files'=>$proof['file_count'],'original_MFA_envelopes_recovered'=>$mfa,'revision'=>substr($proof['delivery_revision'],0,12),'existing_QA_proofs_reused'=>true,'active_writes'=>0]).PHP_EOL;
|