Mercurial > prosody-modules
view mod_stanza_counter/mod_stanza_counter_http.lua @ 5160:8474a3b80200
mod_firewall: Fix 'is_admin' internal dependency rule #1797 (thanks diane)
Looks like the boolean logic was inverted here. Instead, for now,
simply check if is_admin is there. It is deprecated in trunk and was
briefly removed before being brought back with a 'deprecated' warning as
part of the new roles and permissions work. Making this dependency
conditioned on the existence of the underlying function should make it
work until it actually goes away for real.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 27 Jan 2023 23:06:25 +0100 |
parents | 7dbde05b48a9 |
children |
line wrap: on
line source
-- (C) 2011, Marco Cirillo (LW.Org) -- Exposes stats on HTTP for the stanza counter module. module:depends("http") local base_path = module:get_option_string("stanza_counter_basepath", "/stanza-counter/") -- http handlers local r_200 = "\n<html>\n<head>\n<title>Prosody's Stanza Counter</title>\n<meta name=\"robots\" content=\"noindex, nofollow\" />\n</head>\n\n<body>\n<h3>Incoming and Outgoing stanzas divided per type</h3>\n<p><strong>Incoming IQs</strong>: %d<br/>\n<strong>Outgoing IQs</strong>: %d<br/>\n<strong>Incoming Messages</strong>: %d<br/>\n<strong>Outgoing Messages</strong>: %d<br/>\n<strong>Incoming Presences</strong>: %d<br/>\n<strong>Outgoing Presences</strong>: %d<p>\n</body>\n\n</html>\n" local r_err = "\n<html>\n<head>\n<title>Prosody's Stanza Counter - Error %s</title>\n<meta name=\"robots\" content=\"noindex, nofollow\" />\n</head>\n\n<body>\n<h3>%s</h3>\n</body>\n\n</html>\n" local function res(event, code, body, extras) local response = event.response if extras then for header, data in pairs(extras) do response.headers[header] = data end end response.status_code = code response:send(body) end local function req(event) if not prosody.stanza_counter then local err500 = r_err:format(event, 500, "Stats not found, is the counter module loaded?") return res(500, err500) end if method == "GET" then local forge_res = r_200:format(prosody.stanza_counter.iq["incoming"], prosody.stanza_counter.iq["outgoing"], prosody.stanza_counter.message["incoming"], prosody.stanza_counter.message["outgoing"], prosody.stanza_counter.presence["incoming"], prosody.stanza_counter.presence["outgoing"]) return res(event, 200, forge_res) else local err405 = r_err:format(405, "Only GET is supported") return res(event, 405, err405, {["Allow"] = "GET"}) end end -- initialization. module:provides("http", { default_path = base_path, route = { ["GET /"] = req, ["POST /"] = req } })