Software /
code /
prosody
File
plugins/mod_http_errors.lua @ 10399:270cb2821566
mod_ping: Remove ad-hoc command
17:27:40 <Ge0rG> Zash: the Ping thing is absolutely worthless
17:27:55 <Zash> The command provided by mod_ping?
17:27:59 <pep.> To own server?
17:28:14 <Ge0rG> the Ping command in mod_admin_web, whatever it maps to
17:28:29 <Ge0rG> > Pong
> 2019-11-07T16:28:16Z
What am I supposed to do with that result?
17:28:29 <Zash> Yeah, mod_ping provides that
17:28:41 <Ge0rG> Is it a ping to my own server? Where's the RTT?
17:28:48 <Zash> Dunno if it's useful for more than verifying that the adhoc command system works
17:29:02 <Ge0rG> (it lags, but there is no indication of how much)
17:29:14 <Zash> It can't really test that itself
17:29:52 <Zash> Anyone opposed to deleting it?
17:30:42 <Zash> Half the module
17:42:47 <MattJ> Zash, I'm fine with removing it
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 07 Nov 2019 19:23:42 +0100 |
parent | 9760:88640b3ea6b8 |
child | 10430:46dd9df2db0c |
line wrap: on
line source
module:set_global(); local server = require "net.http.server"; local codes = require "net.http.codes"; local xml_escape = require "util.stanza".xml_escape; local render = require "util.interpolation".new("%b{}", xml_escape); local show_private = module:get_option_boolean("http_errors_detailed", false); local always_serve = module:get_option_boolean("http_errors_always_show", true); local default_message = { module:get_option_string("http_errors_default_message", "That's all I know.") }; local default_messages = { [400] = { "What kind of request do you call that??" }; [403] = { "You're not allowed to do that." }; [404] = { "Whatever you were looking for is not here. %"; "Where did you put it?", "It's behind you.", "Keep looking." }; [500] = { "% Check your error log for more info."; "Gremlins.", "It broke.", "Don't look at me." }; }; local messages = setmetatable(module:get_option("http_errors_messages", {}), { __index = default_messages }); local html = [[ <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>{title}</title> <style> body { margin-top : 14%; text-align : center; background-color : #F8F8F8; font-family : sans-serif } h1 { font-size : xx-large } p { font-size : x-large } p+p { font-size : large; font-family : courier } </style> </head> <body> <h1>{title}</h1> <p>{message}</p> <p>{extra?}</p> </body> </html> ]]; local function get_page(code, extra) local message = messages[code]; if always_serve or message then message = message or default_message; return render(html, { title = rawget(codes, code) or ("Code "..tostring(code)); message = message[1]:gsub("%%", function () return message[math.random(2, math.max(#message,2))]; end); extra = extra; }); end end module:hook_object_event(server, "http-error", function (event) if event.response then event.response.headers.content_type = "text/html; charset=utf-8"; end return get_page(event.code, (show_private and event.private_message) or event.message); end);