Files
osint/app/Osint/FindingDispatcher.php
T
cedry2k1992andClaude Sonnet 5 e4fa57c3d6 Add bulk-run actions and per-source rate limiting
Run-all buttons (per target and per investigation) queue every applicable,
not-already-in-flight source via a new FindingDispatcher, re-attempting
prior failures automatically. RunFinding now applies a per-source
RateLimited queue middleware so a bulk run can't hammer the free public
APIs (ip-api, crt.sh, whois, sherlock, theharvester) it depends on;
$tries raised to 30 to survive rate-limiter releases, with a failed()
handler so exhausted retries still resolve the Finding instead of leaving
it stuck pending.

Also fixes CrtShRunner treating crt.sh's intermittent 404/502 (a known
flaky free service) as fatal on the first try — added a bounded retry.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-20 11:29:26 +03:00

51 lines
1.3 KiB
PHP

<?php
namespace App\Osint;
use App\Jobs\RunFinding;
use App\Models\Source;
use App\Models\Target;
use App\Models\User;
class FindingDispatcher
{
public function __construct(private readonly RunnerRegistry $registry)
{
}
/**
* Queue a lookup for every enabled, registered source that applies to
* the target's type and doesn't already have a pending/running finding
* for it. Returns how many were queued.
*/
public function dispatchAllApplicable(Target $target, User $runBy): int
{
$applicableSources = Source::where('enabled', true)->get()
->filter(fn (Source $source) => in_array($target->type, $source->target_types, true)
&& $this->registry->has($source->key));
$busySourceIds = $target->findings()
->whereIn('status', ['pending', 'running'])
->pluck('source_id');
$queued = 0;
foreach ($applicableSources as $source) {
if ($busySourceIds->contains($source->id)) {
continue;
}
$finding = $target->findings()->create([
'source_id' => $source->id,
'run_by' => $runBy->id,
'status' => 'pending',
]);
RunFinding::dispatch($finding->id);
$queued++;
}
return $queued;
}
}