icons on service create, firewall rule remove/install

This commit is contained in:
2025-04-06 17:03:44 +01:00
parent 8f0e319a63
commit 587d10b074
13 changed files with 71 additions and 16 deletions

View File

@@ -11,4 +11,5 @@ enum FirewallRuleStatus: string
case NOT_APPLIED = 'not-applied';
case APPLIED = 'applied';
case FAILED = 'failed';
case REMOVED = 'removed';
}

View File

@@ -24,7 +24,7 @@ enum ServiceCategory: string
return match ($category) {
self::APPLICATION => 'The base container image for your application',
self::DATABASE => 'Postgres or MySQL',
self::GATEWAY => 'The gateway is the first point of contact for your application',
self::GATEWAY => 'The first point of contact for your application',
self::STORAGE => 'S3 or S3-compatible service',
self::CACHE => 'Redis, Memcached or similar',
};

View File

@@ -15,7 +15,7 @@ class FirewallRule extends Model
parent::boot();
static::created(function (self $firewallRule) {
$firewallRule->execute();
$firewallRule->install();
});
}
@@ -31,7 +31,7 @@ class FirewallRule extends Model
return $this->belongsTo(Server::class);
}
public function execute(): void
public function install(): void
{
$ssh = $this->server->sshClient();
@@ -62,4 +62,36 @@ class FirewallRule extends Model
'status' => FirewallRuleStatus::APPLIED,
]);
}
public function remove(): void
{
$ssh = $this->server->sshClient();
$command = "ufw";
if ($this->type === 'allow') {
$command .= " delete allow";
} elseif ($this->type === 'deny') {
$command .= " delete deny";
}
if ($this->from) {
$command .= " from {$this->from}";
$command .= " to any port";
}
$command .= " {$this->ports}";
$result = $ssh->execute($command);
if (! $result->isSuccessful()) {
$this->update([
'status' => FirewallRuleStatus::FAILED,
]);
return;
}
$this->update([
'status' => FirewallRuleStatus::REMOVED,
]);
}
}