mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-05 16:02:34 +00:00
Refactor firewall and add edit rule (#488)
This commit is contained in:
@ -4,7 +4,5 @@
|
||||
|
||||
interface Firewall
|
||||
{
|
||||
public function addRule(string $type, string $protocol, int $port, string $source, ?string $mask): void;
|
||||
|
||||
public function removeRule(string $type, string $protocol, int $port, string $source, ?string $mask): void;
|
||||
public function applyRules(): void;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\SSH\Services\Firewall;
|
||||
|
||||
use App\Enums\FirewallRuleStatus;
|
||||
use App\Exceptions\SSHError;
|
||||
|
||||
class Ufw extends AbstractFirewall
|
||||
@ -26,34 +27,16 @@ public function uninstall(): void
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function addRule(string $type, string $protocol, int $port, string $source, ?string $mask): void
|
||||
public function applyRules(): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
view('ssh.services.firewall.ufw.add-rule', [
|
||||
'type' => $type,
|
||||
'protocol' => $protocol,
|
||||
'port' => $port,
|
||||
'source' => $source,
|
||||
'mask' => $mask || $mask === 0 ? '/'.$mask : '',
|
||||
]),
|
||||
'add-firewall-rule'
|
||||
);
|
||||
}
|
||||
$rules = $this->service->server
|
||||
->firewallRules()
|
||||
->where('status', '!=', FirewallRuleStatus::DELETING)
|
||||
->get();
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function removeRule(string $type, string $protocol, int $port, string $source, ?string $mask): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
view('ssh.services.firewall.ufw.remove-rule', [
|
||||
'type' => $type,
|
||||
'protocol' => $protocol,
|
||||
'port' => $port,
|
||||
'source' => $source,
|
||||
'mask' => $mask || $mask === 0 ? '/'.$mask : '',
|
||||
]),
|
||||
'remove-firewall-rule'
|
||||
view('ssh.services.firewall.ufw.apply-rules', compact('rules')),
|
||||
'apply-rules'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user