DefaultCategoriesSeeder.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. use Phinx\Seed\AbstractSeed;
  4. /**
  5. * Seeds the five default abuse categories. Idempotent: each category is
  6. * inserted only if no row with the same `slug` exists.
  7. *
  8. * Default decay function across all five is exponential with a 14-day half-life
  9. * (per SPEC §5 default).
  10. */
  11. final class DefaultCategoriesSeeder extends AbstractSeed
  12. {
  13. public function run(): void
  14. {
  15. $categories = [
  16. [
  17. 'slug' => 'brute_force',
  18. 'name' => 'Brute force',
  19. 'description' => 'Repeated authentication failures (SSH, web logins, SMTP AUTH).',
  20. ],
  21. [
  22. 'slug' => 'spam',
  23. 'name' => 'Spam',
  24. 'description' => 'Unsolicited email/comment/forum spam from this source.',
  25. ],
  26. [
  27. 'slug' => 'scanner',
  28. 'name' => 'Scanner',
  29. 'description' => 'Port/vulnerability scanning, recon traffic without follow-through exploitation.',
  30. ],
  31. [
  32. 'slug' => 'malware_c2',
  33. 'name' => 'Malware C2',
  34. 'description' => 'Suspected command-and-control endpoint or malware distribution host.',
  35. ],
  36. [
  37. 'slug' => 'web_attack',
  38. 'name' => 'Web attack',
  39. 'description' => 'Active web exploitation attempts: SQLi, XSS, LFI, RCE payloads.',
  40. ],
  41. ];
  42. $existing = $this->fetchAll('SELECT slug FROM categories');
  43. $existingSlugs = array_column($existing, 'slug');
  44. $rows = [];
  45. foreach ($categories as $cat) {
  46. if (in_array($cat['slug'], $existingSlugs, true)) {
  47. continue;
  48. }
  49. $rows[] = [
  50. 'slug' => $cat['slug'],
  51. 'name' => $cat['name'],
  52. 'description' => $cat['description'],
  53. 'decay_function' => 'exponential',
  54. 'decay_param' => '14.0000',
  55. 'is_active' => 1,
  56. ];
  57. }
  58. if ($rows !== []) {
  59. $this->table('categories')->insert($rows)->save();
  60. }
  61. }
  62. }