Software /
code /
prosody-modules
File
mod_http_health/mod_http_health.lua @ 5931:d194d1012fd3
Updating dox for mod_rest. Ideas expressed / clarified:
1) Making clear that mod_rest isn't to be installed under VirtualHosts AND as a component.
2) Understanding some of the implications of this choice:
A) Changes to user authentication
B) How it affects subdomains
3) More consistent use of domain names for clarity.
4) Using different heading sizes to show scope of section.
Essentially, I added all the tidbits I had to clarify in getting this to work in my
own example.
author | Ben Smith <bens@effortlessis.com> |
---|---|
date | Mon, 13 May 2024 13:25:13 -0700 |
parent | 5712:09233b625cb9 |
line wrap: on
line source
module:set_global(); local ip = require "util.ip"; local modulemanager = require "core.modulemanager"; local permitted_ips = module:get_option_set("http_health_allow_ips", { "::1", "127.0.0.1" }); local permitted_cidr = module:get_option_string("http_health_allow_cidr"); local function is_permitted(request) local ip_raw = request.ip; if permitted_ips:contains(ip_raw) or (permitted_cidr and ip.match(ip.new_ip(ip_raw), ip.parse_cidr(permitted_cidr))) then return true; end return false; end module:provides("http", { route = { GET = function(event) local request = event.request; if not is_permitted(request) then return 403; -- Forbidden end for host in pairs(prosody.hosts) do local mods = modulemanager.get_modules(host); for _, mod in pairs(mods) do if mod.module.status_type == "error" then return { status_code = 500; headers = { content_type = "text/plain" }; body = "HAS ERRORS\n" }; end end end return { status_code = 200; headers = { content_type = "text/plain" }; body = "OK\n" }; end; }; });