diff options
author | Daniel Weipert <code@drogueronin.de> | 2021-04-28 13:58:55 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2021-04-28 13:58:55 +0200 |
commit | 20d9f63918d3b2bd75853182063f43eb36d7cd8a (patch) | |
tree | b6f48898297f761dcec8532b524844cc968ec565 /src/UfwModule.php | |
parent | 11dc8c730dda2c5bd38cb386f96331c5ce3cac9c (diff) |
Adjusts modulesv1.0.0
Diffstat (limited to 'src/UfwModule.php')
-rw-r--r-- | src/UfwModule.php | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/UfwModule.php b/src/UfwModule.php index 1ec4452..02be515 100644 --- a/src/UfwModule.php +++ b/src/UfwModule.php @@ -18,13 +18,35 @@ class UfwModule extends Module */ public function checkState(): bool { - return false; + $state = false; + + Connection::enablePty(); + + Connection::exec('sudo ufw status'); + $status = Connection::read(); + + if ($this->state === State::ENABLED) { + $rule = strtoupper($this->rule); + Connection::exec("sudo ufw status | grep '$this->name\|$rule'"); + $statusGrep = Connection::read(); + + $state = + str_contains($status, 'Status: active') && + str_contains($statusGrep, $this->name) && str_contains($statusGrep, $rule); + } + else if ($this->state === State::DISABLED) { + $state = str_contains($status, 'Status: inactive'); + } + + Connection::disablePty(); + + return $state; } /** * @inheritDoc */ - public function getCommands(): array + public function execute(): void { Connection::exec(implode(PHP_EOL, [ "sudo ufw $this->rule $this->name", @@ -33,7 +55,5 @@ class UfwModule extends Module State::DISABLED => "sudo ufw disable", }, ])); - - return []; } } |