summaryrefslogtreecommitdiff
path: root/src/UfwModule.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/UfwModule.php')
-rw-r--r--src/UfwModule.php28
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 [];
}
}