diff options
author | Simon Rettberg | 2024-10-09 16:14:39 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-10-09 16:14:39 +0200 |
commit | 36fa9ba7863cf68a8c37613d6ff37cce72555653 (patch) | |
tree | 978b2b19a324fc326abbed809199191cac42297a /modules-available/webinterface/inc | |
parent | [webinterface] Add support for ACME, add option to redirect to cert domain (diff) | |
download | slx-admin-36fa9ba7863cf68a8c37613d6ff37cce72555653.tar.gz slx-admin-36fa9ba7863cf68a8c37613d6ff37cce72555653.tar.xz slx-admin-36fa9ba7863cf68a8c37613d6ff37cce72555653.zip |
[webinterface] Refactor TM-Calls for https changes
Move actual calls to WebInterface helper class, move a few common things
to their own functions.
Diffstat (limited to 'modules-available/webinterface/inc')
-rw-r--r-- | modules-available/webinterface/inc/webinterface.inc.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/modules-available/webinterface/inc/webinterface.inc.php b/modules-available/webinterface/inc/webinterface.inc.php index 6dfd924f..276110eb 100644 --- a/modules-available/webinterface/inc/webinterface.inc.php +++ b/modules-available/webinterface/inc/webinterface.inc.php @@ -9,6 +9,8 @@ class WebInterface public const PROP_REDIRECT_DOMAIN = 'webinterface.redirect-domain'; + public const PROP_API_KEY = 'webinterface.api-key'; + /** * Read data all handled domains from current certificate. * SAN takes precedence, if empty, we fall back to CN. @@ -62,4 +64,50 @@ class WebInterface return !empty(Property::get(self::PROP_REDIRECT_DOMAIN, false)); } + public static function isHttpsRedirectEnabled(): bool + { + return Property::get(self::PROP_REDIRECT) === 'True'; + } + + public static function tmDisableHttps(): ?string + { + Property::set(WebInterface::PROP_TYPE, 'off'); + Property::set(WebInterface::PROP_HSTS, 'off'); + $task = Taskmanager::submit('LighttpdHttps', []); + 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(), + ]); + return $task['id'] ?? null; + } + + public static function tmImportCustomCert(string $key, string $cert, ?string $chain = null): ?string + { + Property::set(WebInterface::PROP_TYPE, 'supplied'); + $task = Taskmanager::submit('LighttpdHttps', [ + 'importcert' => $cert, + 'importkey' => $key, + 'importchain' => $chain, + 'redirect' => self::isHttpsRedirectEnabled(), + ]); + 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; + } + }
\ No newline at end of file |