30 lines
2.1 KiB
PHP
30 lines
2.1 KiB
PHP
<?php
|
|
// Read only after the QA guard: encrypted originals and job metadata, no secrets/payloads.
|
|
$app = (static fn ($p) => require $p)(__DIR__.'/portal-service-followup-runtime.php');
|
|
$id = isset($argv[1]) ? (int) $argv[1] : null;
|
|
$rows = [];
|
|
foreach (['documents', 'images'] as $kind) {
|
|
$query = Illuminate\Support\Facades\DB::table('opportunity_'.$kind.' as r')->join('documents as d', 'd.id', '=', 'r.document_id');
|
|
if ($id) $query->where('r.opportunity_id', $id);
|
|
foreach ($query->get(['r.id AS resource_id', 'r.opportunity_id', 'r.version', 'r.payload', 'd.id AS document_id', 'd.sha256', 'd.malware_scan_status', 'd.storage_key']) as $row) {
|
|
$payload = json_decode($row->payload,true,512,JSON_THROW_ON_ERROR);
|
|
unset($row->payload);
|
|
$row->derivatives = [];
|
|
foreach ($payload['derivatives'] ?? [] as $derivative) {
|
|
$row->derivatives[] = (array) Illuminate\Support\Facades\DB::table('documents')->where('id',$derivative['document_id'])->first(['id','sha256','malware_scan_status','malware_scanned_sha256']);
|
|
}
|
|
$bytes = Illuminate\Support\Facades\Storage::disk('local')->get($row->storage_key);
|
|
$row->original_cipher_sha256 = hash('sha256', $bytes);
|
|
$plain = Illuminate\Support\Facades\Crypt::decryptString($bytes);
|
|
$row->plaintext_hash_matches = hash_equals(trim($row->sha256), hash('sha256', $plain));
|
|
unset($plain, $row->storage_key);
|
|
$row->kind = $kind;
|
|
$rows[] = $row;
|
|
}
|
|
}
|
|
$health = app(App\Services\Malware\MalwareScanner::class)->health();
|
|
if (($health['signatures_at'] ?? null) instanceof DateTimeInterface) $health['signatures_at'] = $health['signatures_at']->format('c');
|
|
echo json_encode(['target' => config('database.connections.pgsql.database').':55441', 'rows' => $rows, 'scanner' => $health,
|
|
'jobs' => Illuminate\Support\Facades\DB::table('jobs')->where('queue', 'services-followup-qa')->get(['id', 'queue', 'attempts', 'reserved_at', 'available_at']),
|
|
'failed_jobs' => Illuminate\Support\Facades\DB::table('failed_jobs')->count(), 'active_writes' => 0], JSON_THROW_ON_ERROR).PHP_EOL;
|