Current state with latest updates
This commit is contained in:
@@ -49,10 +49,10 @@ final class BuildSitemapsCommand extends Command
|
||||
$t = microtime(true);
|
||||
$this->line(' Building sitemap index…');
|
||||
$index = $build->buildIndex(force: true, persist: false, families: $families);
|
||||
$disk->put('sitemap.xml', $index['content']);
|
||||
$disk->put('sitemaps/sitemap.xml', $index['content']);
|
||||
$written++;
|
||||
$this->line(sprintf(
|
||||
' <info>✔</info> sitemap.xml %d entries <comment>%.3fs</comment>',
|
||||
' <info>✔</info> sitemaps/sitemap.xml %d entries <comment>%.3fs</comment>',
|
||||
$index['url_count'],
|
||||
microtime(true) - $t,
|
||||
));
|
||||
@@ -112,6 +112,36 @@ final class BuildSitemapsCommand extends Command
|
||||
));
|
||||
}
|
||||
|
||||
foreach ($build->enabledGroupIndexes() as $groupName => $groupFamilies) {
|
||||
foreach ($groupFamilies as $family) {
|
||||
if (! in_array($family, $families, true)) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$t = microtime(true);
|
||||
$this->line(sprintf(' Building grouped sitemap %s…', $groupName));
|
||||
|
||||
$built = $build->buildNamed($groupName, force: true, persist: false);
|
||||
|
||||
if ($built === null) {
|
||||
$this->line(sprintf(' <comment>–</comment> %s.xml <fg=red>SKIPPED</> (group builder returned null)', $groupName));
|
||||
$failed++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$disk->put('sitemaps/' . $groupName . '.xml', $built['content']);
|
||||
$written++;
|
||||
|
||||
$this->line(sprintf(
|
||||
' <info>✔</info> %s %d entries <comment>%.3fs</comment>',
|
||||
$groupName . '.xml',
|
||||
$built['url_count'] ?? 0,
|
||||
microtime(true) - $t,
|
||||
));
|
||||
}
|
||||
|
||||
// ── Summary ───────────────────────────────────────────────────────
|
||||
$this->newLine();
|
||||
$this->info(sprintf(
|
||||
@@ -295,4 +325,4 @@ final class BuildSitemapsCommand extends Command
|
||||
|
||||
return array_values(array_filter($enabled, fn (string $family): bool => in_array($family, $only, true)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,35 @@ final class GenerateSitemapsCommand extends Command
|
||||
));
|
||||
}
|
||||
|
||||
foreach ($build->enabledGroupIndexes() as $groupName => $groupFamilies) {
|
||||
foreach ($groupFamilies as $family) {
|
||||
if (! in_array($family, $families, true)) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$t = microtime(true);
|
||||
$built = $build->buildNamed($groupName, force: true, persist: false);
|
||||
|
||||
if ($built === null) {
|
||||
$this->line(sprintf(' <comment>–</comment> %s.xml <fg=red>SKIPPED</> (group builder returned null)', $groupName));
|
||||
$failed++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = 'sitemaps/' . $groupName . '.xml';
|
||||
$disk->put($path, $built['content']);
|
||||
$written++;
|
||||
|
||||
$this->line(sprintf(
|
||||
' <info>✔</info> %s %d entries <comment>%.3fs</comment>',
|
||||
$groupName . '.xml',
|
||||
$built['url_count'] ?? 0,
|
||||
microtime(true) - $t,
|
||||
));
|
||||
}
|
||||
|
||||
// ── Summary ───────────────────────────────────────────────────────
|
||||
$this->newLine();
|
||||
$this->info(sprintf(
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Notifications\SecurityReportDangerNotification;
|
||||
use App\Services\SecurityReport\SecurityReportScanner;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
final class SecurityReportScanCommand extends Command
|
||||
{
|
||||
protected $signature = 'security:scan
|
||||
{--notify : Send configured email notification when high or critical findings exist}
|
||||
{--triggered-by=artisan : Mark the scan source}
|
||||
{--user-id= : Associate the scan with a specific user id}';
|
||||
|
||||
protected $description = 'Run Composer and npm security audits and store a private admin report.';
|
||||
|
||||
public function handle(SecurityReportScanner $scanner): int
|
||||
{
|
||||
if (! (bool) config('security-report.enabled', true)) {
|
||||
$this->warn('Security report scanning is disabled.');
|
||||
|
||||
return self::INVALID;
|
||||
}
|
||||
|
||||
$this->info('Running security report scan...');
|
||||
|
||||
$report = $scanner->scan(
|
||||
(string) $this->option('triggered-by'),
|
||||
$this->option('user-id') !== null ? (int) $this->option('user-id') : null,
|
||||
);
|
||||
|
||||
if ($report->status === 'failed') {
|
||||
$this->error('Security scan failed: ' . (string) ($report->error_message ?? 'Unknown error'));
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->table(
|
||||
['Status', 'Critical', 'High', 'Medium', 'Low', 'Unknown', 'Composer outdated', 'npm outdated'],
|
||||
[[
|
||||
$report->status,
|
||||
$report->total_critical,
|
||||
$report->total_high,
|
||||
$report->total_medium,
|
||||
$report->total_low,
|
||||
$report->total_unknown,
|
||||
$report->composer_outdated_count,
|
||||
$report->npm_outdated_count,
|
||||
]],
|
||||
);
|
||||
|
||||
if ((bool) $this->option('notify') && $report->hasDangerFindings()) {
|
||||
$this->sendDangerNotification($report);
|
||||
$this->info('Danger notification sent.');
|
||||
}
|
||||
|
||||
if ($report->hasCriticalFindings() && (bool) config('security-report.fail_on.critical', false)) {
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
if ($report->hasHighFindings() && (bool) config('security-report.fail_on.high', false)) {
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
private function sendDangerNotification(\App\Models\SecurityReport $report): void
|
||||
{
|
||||
$email = trim((string) config('security-report.notify_email', ''));
|
||||
|
||||
if ($email === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
Notification::route('mail', $email)
|
||||
->notify(new SecurityReportDangerNotification($report));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user