Refactor firewall and add edit rule (#488)

This commit is contained in:
Richard Anderson
2025-02-16 19:31:58 +00:00
committed by GitHub
parent e2b9d18a71
commit 8c7c3d2192
23 changed files with 443 additions and 210 deletions

View File

@ -12,6 +12,7 @@ class FirewallRuleFactory extends Factory
public function definition(): array
{
return [
'name' => $this->faker->word,
'type' => 'allow',
'protocol' => 'tcp',
'port' => $this->faker->numberBetween(1, 65535),

View File

@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('firewall_rules', function (Blueprint $table) {
$table->string('name')->default('Undefined')->after('id');
$table->ipAddress('source')->default(null)->nullable()->change();
});
DB::statement("UPDATE firewall_rules SET name = UPPER(protocol) WHERE protocol IN ('ssh', 'http', 'https')");
DB::statement("UPDATE firewall_rules SET protocol = 'tcp' WHERE protocol IN ('ssh', 'http', 'https')");
DB::statement("UPDATE firewall_rules SET source = null WHERE source = '0.0.0.0'");
DB::statement("UPDATE firewall_rules SET mask = null WHERE mask = '0'");
}
/**
* Reverse the migrations.
*/
public function down(): void
{
DB::statement("UPDATE firewall_rules SET protocol = LOWER(name) WHERE protocol = 'tcp' AND LOWER(name) IN ('ssh', 'http', 'https')");
DB::statement("UPDATE firewall_rules SET source = '0.0.0.0' WHERE source is null");
DB::statement("UPDATE firewall_rules SET mask = '0' WHERE mask is null");
Schema::table('firewall_rules', function (Blueprint $table) {
$table->dropColumn('name');
$table->ipAddress('source')->default('0.0.0.0')->change();
});
}
};