$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_HSTS, 'off'); $task = Taskmanager::submit('LighttpdHttps', []); self::registerCallback($task, 'off', 'HTTPS disabled'); return $task['id'] ?? null; } public static function tmGenerateRandomCert(): ?string { $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 $type, string $logMessage): ?string { $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, 'redirect' => self::isHttpsRedirectEnabled(), ]); self::registerCallback($task, $type, $logMessage); return $task['id'] ?? null; } public static function tmSetHttpRedirectMode(): ?string { if (Property::get(WebInterface::PROP_TYPE) === 'off') return null; $task = Taskmanager::submit('LighttpdHttps', array( 'redirectOnly' => true, 'redirect' => self::isHttpsRedirectEnabled(), )); return $task['id'] ?? null; } public static function getApiKey(): ?string { $key = Property::get(self::PROP_API_KEY, null); if (empty($key)) return null; return $key; } public static function setApiKey(?string $key): void { Property::set(self::PROP_API_KEY, empty($key) ? null : $key); } }