diff options
Diffstat (limited to 'modules-available/webinterface/page.inc.php')
-rw-r--r-- | modules-available/webinterface/page.inc.php | 61 |
1 files changed, 19 insertions, 42 deletions
diff --git a/modules-available/webinterface/page.inc.php b/modules-available/webinterface/page.inc.php index 35f21b38..318dd82c 100644 --- a/modules-available/webinterface/page.inc.php +++ b/modules-available/webinterface/page.inc.php @@ -33,6 +33,7 @@ class Page_WebInterface extends Page private function actionConfigureHttps() { + $this->setRedirectFromPost(); $mode = Request::post('mode'); switch ($mode) { case 'off': @@ -48,7 +49,7 @@ class Page_WebInterface extends Page $taskId = $this->setAcmeMode(); break; default: - $taskId = $this->setRedirectMode(); + $taskId = $this->updateHttpsRedirectModeOnly(); break; } if ($mode !== 'off') { @@ -211,47 +212,40 @@ class Page_WebInterface extends Page Render::addTemplate('customization', $data); } + private function setRedirectFromPost(): void + { + $force = Request::post('httpsredirect', false, 'string') === 'on'; + Property::set(WebInterface::PROP_REDIRECT, $force ? 'True' : 'False'); + } + + private function updateHttpsRedirectModeOnly(): ?string + { + return WebInterface::tmSetHttpRedirectMode(); + } + private function setHttpsOff(): ?string { - Property::set(WebInterface::PROP_TYPE, 'off'); - Property::set(WebInterface::PROP_HSTS, 'off'); Header('Strict-Transport-Security: max-age=0', true); Session::deleteCookie(); - $task = Taskmanager::submit('LighttpdHttps', array()); - return $task['id'] ?? null; + return WebInterface::tmDisableHttps(); } private function setHttpsRandomCert(): ?string { - $force = Request::post('httpsredirect', false, 'string') === 'on'; - Property::set(WebInterface::PROP_TYPE, 'generated'); - Property::set(WebInterface::PROP_REDIRECT, $force ? 'True' : 'False'); - $task = Taskmanager::submit('LighttpdHttps', array( - 'proxyip' => Property::getServerIp(), - 'redirect' => $force, - )); - return $task['id'] ?? null; + return WebInterface::tmGenerateRandomCert(); } private function setHttpsCustomCert(): ?string { - $force = Request::post('httpsredirect', false, 'string') === 'on'; - Property::set(WebInterface::PROP_TYPE, 'supplied'); - Property::set(WebInterface::PROP_REDIRECT, $force ? 'True' : 'False'); - $task = Taskmanager::submit('LighttpdHttps', array( - 'importcert' => Request::post('certificate', 'bla'), - 'importkey' => Request::post('privatekey', 'bla'), - 'importchain' => Request::post('cachain', ''), - 'redirect' => $force, - )); - return $task['id'] ?? null; + $cert = Request::post('certificate', Request::REQUIRED, 'string'); + $key = Request::post('privatekey', Request::REQUIRED, 'string'); + $chain = Request::post('cachain', '', 'string'); + return WebInterface::tmImportCustomCert($key, $cert, $chain); } private function setAcmeMode(): ?string { - $force = Request::post('httpsredirect', false, 'string') === 'on'; Property::set(WebInterface::PROP_TYPE, 'acme'); - Property::set(WebInterface::PROP_REDIRECT, $force ? 'True' : 'False'); $wipeAll = Request::post('acme-wipe-all', false, 'bool'); // Get params $provider = Request::post('acme-provider', Request::REQUIRED, 'string'); @@ -281,7 +275,6 @@ class Page_WebInterface extends Page && empty(array_diff($domains, Acme::getDomains()))) { if (Acme::tryEnable()) return null; // Nothing to do, old setup works - error_log('FUUUU'); return Acme::renew(); // Hope for the best, otherwise user needs to check "force reissue" } if (!Acme::setConfig($provider, $mail, $kid, $hmac)) @@ -290,21 +283,5 @@ class Page_WebInterface extends Page return Acme::issueNewCertificate($wipeAll); } - private function setRedirectMode(): ?string - { - $force = Request::post('httpsredirect', false, 'string') === 'on'; - Property::set(WebInterface::PROP_REDIRECT, $force ? 'True' : 'False'); - if (Property::get(WebInterface::PROP_TYPE) === 'off') { - // Don't bother running the task if https isn't enabled - just - // update the state in DB - return null; - } - $task = Taskmanager::submit('LighttpdHttps', array( - 'redirectOnly' => true, - 'redirect' => $force, - )); - return $task['id'] ?? null; - } - } |