mirror of
https://github.com/crivion/laranode.git
synced 2026-09-03 06:24:09 +08:00
23 lines
598 B
PHP
23 lines
598 B
PHP
<?php
|
|
|
|
namespace App\Actions\Firewall;
|
|
|
|
use Illuminate\Support\Facades\Process;
|
|
use RuntimeException;
|
|
|
|
class AddUfwRuleAction
|
|
{
|
|
public function execute(string $ruleSpec): void
|
|
{
|
|
$ruleSpec = trim($ruleSpec);
|
|
if ($ruleSpec === '') {
|
|
throw new RuntimeException('Empty rule spec');
|
|
}
|
|
$bin = config('laranode.laranode_bin_path') . '/laranode-ufw.sh';
|
|
$proc = Process::run(['sudo', $bin, 'allow', $ruleSpec]);
|
|
if ($proc->failed()) {
|
|
throw new RuntimeException('UFW allow failed: ' . $proc->errorOutput());
|
|
}
|
|
}
|
|
}
|