diff options
Diffstat (limited to 'modules-available/webinterface/inc/webinterface.inc.php')
-rw-r--r-- | modules-available/webinterface/inc/webinterface.inc.php | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/modules-available/webinterface/inc/webinterface.inc.php b/modules-available/webinterface/inc/webinterface.inc.php index 20be6545..035b94e6 100644 --- a/modules-available/webinterface/inc/webinterface.inc.php +++ b/modules-available/webinterface/inc/webinterface.inc.php @@ -69,33 +69,61 @@ class WebInterface return Property::get(self::PROP_REDIRECT) === 'True'; } + private static function registerCallback($task, string $newState, string $logMessage): void + { + if (!Taskmanager::isTask($task)) + return; + TaskmanagerCallback::addCallback($task, 'webifCert', [ + 'state' => $newState, + 'message' => $logMessage . ' by ' . (User::getLogin() ?? 'system'), + ]); + } + + public static function certTaskFinishedCallback(array $task, $data): void + { + if (!Taskmanager::isFinished($task)) + return; + if (!isset($data['state']) || !isset($data['message'])) { + error_log('Invalid certTaskFinishedCallback: Missing fields'); + return; + } + if (Taskmanager::isFailed($task)) { + EventLog::failure($data['message'], json_encode($task, JSON_PRETTY_PRINT)); + return; + } + EventLog::info($data['message']); + Property::set(self::PROP_TYPE, $data['state']); + } + public static function tmDisableHttps(): ?string { - Property::set(WebInterface::PROP_TYPE, 'off'); Property::set(WebInterface::PROP_HSTS, 'off'); $task = Taskmanager::submit('LighttpdHttps', []); + self::registerCallback($task, 'off', 'HTTPS disabled'); return $task['id'] ?? null; } public static function tmGenerateRandomCert(): ?string { - Property::set(WebInterface::PROP_TYPE, 'generated'); $task = Taskmanager::submit('LighttpdHttps', [ 'proxyip' => Property::getServerIp(), 'redirect' => self::isHttpsRedirectEnabled(), ]); + self::registerCallback($task, 'generated', 'Self-signed HTTPS certificate generated'); return $task['id'] ?? null; } - public static function tmImportCustomCert(string $key, string $cert, ?string $chain = null): ?string + public static function tmImportCustomCert(string $key, string $cert, string $type, string $logMessage): ?string { - Property::set(WebInterface::PROP_TYPE, 'supplied'); + $key = preg_replace('/[\r\n]+/', "\n", $key); + $cert = preg_replace('/[\r\n]+/', "\n", $cert); + Property::set(WebInterface::PROP_TYPE, $type); $task = Taskmanager::submit('LighttpdHttps', [ 'importcert' => $cert, 'importkey' => $key, - 'importchain' => $chain, 'redirect' => self::isHttpsRedirectEnabled(), ]); + self::registerCallback($task, $type, $logMessage); return $task['id'] ?? null; } |