opnsense / plugins

OPNsense plugin collection
https://opnsense.org/
BSD 2-Clause "Simplified" License
835 stars 625 forks source link

www/caddy: Diagnostics View #3967

Closed Monviech closed 4 months ago

Monviech commented 4 months ago

Adds a new Diagnostics view in which a download button can download the latest caddy configuration with timestamp.

The autosave.json file is used, since it's json, which makes it easy to validate that it is indeed valid json. Also, it includes all custom imports which users might have dropped into the filesystem, unlike the raw Caddyfile would.

The new API endpoint /api/caddy/diagnostics/showconfig can also be invoked, to show the json configuration in the Browser in real time. There is no view for that, to keep it simple. The API is only used for the Download button, and with a button that shows the json configuration in the browser.

Monviech commented 4 months ago

@fichtner Could you give this one a look? The part I'm unsure of, is if it violates coding guidelines to offer a button that directly redirects a user to an API endpoint. I can remove that.

The download button works as expected and everything uses the configd and API framework for security.

Monviech commented 4 months ago

Gonna cook this one for a little while longer since I want to show the Caddyfile in a modal in that diagnostic view, too. It's the most important human readable file for quick troubleshooting and getting help from the caddy community.

I just have to find out how to funnel it through all the API stuff and leave the indentations, whitespaces, etc... all intact.

Monviech commented 4 months ago

Does this look okay? I like it. (It's scrollable btw)

screendia01

screendia02

Monviech commented 4 months ago

Now it is pretty good and fleshed out. The only thing that is not included since it would inflate the code a lot, is error handling for the download button. It is displayed to the user, that there is an error with the file, in the display area for the Caddyfile or the JSON.

If somebody clicks on download, it will download the file containing the error message.

Implementing flags to track all errors is kinda meh so I would rather just leave it at that, these validation edge cases almost never happen.

Monviech commented 4 months ago

Also looks nice and responsive now and works like a charm on all sizes of displays, almost never hiding the buttons.

screen

fichtner commented 4 months ago

Nice work, merged. Thanks!