www/caddy: Fix that the setup.sh script is not executed with reloadssl (#3982)

This commit is contained in:
Monviech
2024-05-16 17:30:35 +02:00
committed by GitHub
parent 90fe67c97f
commit f59fb35e18
3 changed files with 14 additions and 2 deletions
+1
View File
@@ -1,5 +1,6 @@
PLUGIN_NAME= caddy
PLUGIN_VERSION= 1.5.5
PLUGIN_REVISION= 1
PLUGIN_DEPENDS= caddy-custom
PLUGIN_COMMENT= Easy to configure Reverse Proxy with Automatic HTTPS and Dynamic DNS
PLUGIN_MAINTAINER= cedrik@pischem.com
+4
View File
@@ -37,6 +37,10 @@ Plugin Changelog
* Cleanup: Javascript variables have been changed from var to let to reduce scope.
* Fix: Template has been fixed to allow any TLS option in Handlers to appear independant when filled out. This increases flexibility with the "tls_server_name" option.
* Add: Diagnostics view added where the current Caddyfile and JSON configuration can be displayed, validated and downloaded.
* Add: HTTP-01 Challenge Redirection can also be configured for subdomains.
* Cleanup: lang() and gettext() functions added for translations.
* Cleanup: Rewritten most help texts in forms for consistency.
* Fix: The newly introduced "configctl caddy reload" action, which calls the "service caddy reloadssl" command, will now also trigger the setup.sh script.
1.5.4
@@ -35,8 +35,6 @@ def run_service_command(action, action_message):
if action == "validate":
try:
# Call Setup script
subprocess.run(["/usr/local/opnsense/scripts/OPNsense/Caddy/setup.sh"], check=True)
# Validate the Caddyfile with explicit --config flag, capturing both stdout and stderr
validation_output = subprocess.check_output(["caddy", "validate", "--config", "/usr/local/etc/caddy/Caddyfile"], stderr=subprocess.STDOUT, text=True)
if "Valid configuration" in validation_output:
@@ -76,6 +74,15 @@ if __name__ == "__main__":
if action in actions:
service_action = actions[action]
message = f"{action.capitalize()}ing Caddy service" if action != "validate" else "Validating Caddy configuration"
# Call setup script for 'validate' and 'reloadssl' actions
# This is needed because the setup script triggers the caddy_certs.php script, which exports all certificates into the filesystem.
# Caddy reloads certificates when reloadssl is used. Because it is a non standard command, the caddy_setup script will not be triggered in /etc/rc.conf.d/caddy.
# The validate command needs it to make sure all certificates are in the filesystem, because otherwise the validation fails.
if service_action in ["validate", "reloadssl"]:
subprocess.run(["/usr/local/opnsense/scripts/OPNsense/Caddy/setup.sh"], check=True)
# Continue with the service action
print(run_service_command(service_action, message))
else:
print(json.dumps({"status": "failed", "message": f"Unknown action: {action}"}))