| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- declare(strict_types=1);
- use Phinx\Seed\AbstractSeed;
- /**
- * Seeds the five default abuse categories. Idempotent: each category is
- * inserted only if no row with the same `slug` exists.
- *
- * Default decay function across all five is exponential with a 14-day half-life
- * (per SPEC §5 default).
- */
- final class DefaultCategoriesSeeder extends AbstractSeed
- {
- public function run(): void
- {
- $categories = [
- [
- 'slug' => 'brute_force',
- 'name' => 'Brute force',
- 'description' => 'Repeated authentication failures (SSH, web logins, SMTP AUTH).',
- ],
- [
- 'slug' => 'spam',
- 'name' => 'Spam',
- 'description' => 'Unsolicited email/comment/forum spam from this source.',
- ],
- [
- 'slug' => 'scanner',
- 'name' => 'Scanner',
- 'description' => 'Port/vulnerability scanning, recon traffic without follow-through exploitation.',
- ],
- [
- 'slug' => 'malware_c2',
- 'name' => 'Malware C2',
- 'description' => 'Suspected command-and-control endpoint or malware distribution host.',
- ],
- [
- 'slug' => 'web_attack',
- 'name' => 'Web attack',
- 'description' => 'Active web exploitation attempts: SQLi, XSS, LFI, RCE payloads.',
- ],
- ];
- $existing = $this->fetchAll('SELECT slug FROM categories');
- $existingSlugs = array_column($existing, 'slug');
- $rows = [];
- foreach ($categories as $cat) {
- if (in_array($cat['slug'], $existingSlugs, true)) {
- continue;
- }
- $rows[] = [
- 'slug' => $cat['slug'],
- 'name' => $cat['name'],
- 'description' => $cat['description'],
- 'decay_function' => 'exponential',
- 'decay_param' => '14.0000',
- 'is_active' => 1,
- ];
- }
- if ($rows !== []) {
- $this->table('categories')->insert($rows)->save();
- }
- }
- }
|