mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
www/caddy: Add error message when OPNsense WebGUI settings conflict with Caddy (#3999)
* Add error message when OPNsense WebGUI settings conflict with Caddy. Caddy can not start when port 80 and 443 are in use. A conflict with other plugins can cause this, yet the majority of cases is a conflict with the WebGUI due to default settings. This error message in General Settings helps users to fix the most common error why Caddy refuses to start (without emitting usable logs in the Log Viewer). * Revert "Add error message when OPNsense WebGUI settings conflict with Caddy. Caddy can not start when port 80 and 443 are in use. A conflict with other plugins can cause this, yet the majority of cases is a conflict with the WebGUI due to default settings. This error message in General Settings helps users to fix the most common error why Caddy refuses to start (without emitting usable logs in the Log Viewer)." * Move validation logic of WebGUI port conflicts with caddy to model validation. * Refactor to get rid of some double variable declarations. * Refactor WebGUI validation to the AutoHTTPS setting. When the default ports are used for the WebGUI, AutoHTTPS can not be set to on. * Implement feedback from code review. Make message dynamic based on port overlap. * Simplify from constructed message to static message to make it translation friendly. Fix if statement for webGuiPorts, so that when it is not empty, the port can be actually compared.
This commit is contained in:
@@ -32,6 +32,7 @@ namespace OPNsense\Caddy;
|
||||
|
||||
use OPNsense\Base\BaseModel;
|
||||
use OPNsense\Base\Messages\Message;
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
class Caddy extends BaseModel
|
||||
{
|
||||
@@ -107,6 +108,39 @@ class Caddy extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Get the current OPNsense WebGUI ports
|
||||
private function getWebGuiPorts() {
|
||||
$webgui = Config::getInstance()->object()->system->webgui ?? null;
|
||||
$webGuiPorts = [];
|
||||
|
||||
// Only add ports to array if no specific interfaces for the WebGUI are set
|
||||
if (!empty($webgui) && empty((string)$webgui->interfaces)) {
|
||||
// Add port 443 if no specific port is set, otherwise set custom webgui port
|
||||
$webGuiPorts[] = !empty($webgui->port) ? (string)$webgui->port : '443';
|
||||
|
||||
// Add port 80 if HTTP redirect is not explicitly disabled
|
||||
if (empty((string)$webgui->disablehttpredirect)) {
|
||||
$webGuiPorts[] = '80';
|
||||
}
|
||||
}
|
||||
|
||||
return $webGuiPorts;
|
||||
}
|
||||
|
||||
// 4. Check for conflicts between Caddy and OPNsense WebGUI ports
|
||||
private function checkWebGuiSettings($messages) {
|
||||
$overlap = array_intersect($this->getWebGuiPorts(), ['80', '443']);
|
||||
$tlsAutoHttpsSetting = (string)$this->general->TlsAutoHttps;
|
||||
|
||||
if (!empty($overlap) && $tlsAutoHttpsSetting !== 'off') {
|
||||
$portOverlap = implode(', ', $overlap);
|
||||
$messages->appendMessage(new Message(
|
||||
sprintf(gettext('To use "Auto HTTPS", resolve these conflicting ports (%s) that are currently configured for the OPNsense WebGUI. Go to "System - Settings - Administration". To release port 80, enable "Disable web GUI redirect rule". To release port 443, change "TCP port" to a non-standard port, e.g., 8443.'), $portOverlap),
|
||||
"general.TlsAutoHttps"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Perform the actual validation
|
||||
public function performValidation($validateFullModel = false)
|
||||
{
|
||||
@@ -117,6 +151,8 @@ class Caddy extends BaseModel
|
||||
$this->checkForUniquePortCombos($this->reverseproxy->subdomain->iterateItems(), $messages);
|
||||
// 3. Check that subdomains are under a wildcard or exact domain
|
||||
$this->checkSubdomainsAgainstDomains($this->reverseproxy->subdomain->iterateItems(), $this->reverseproxy->reverse->iterateItems(), $messages);
|
||||
// 4. Check WebGUI conflicts
|
||||
$this->checkWebGuiSettings($messages);
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user