execute(); }); } protected function casts(): array { return [ 'status' => FirewallRuleStatus::class, ]; } public function server(): BelongsTo { return $this->belongsTo(Server::class); } public function execute(): void { $ssh = $this->server->sshClient(); $command = "ufw"; if ($this->type === 'allow') { $command .= " allow"; } elseif ($this->type === 'deny') { $command .= " 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::APPLIED, ]); } }