aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-10-27 13:27:35 +0200
committerKim Alvefur <zash@zash.se>2017-10-27 13:27:35 +0200
commitb8d1d533fdf9b9e0d348a4f8d4204e6a1f87a5bd (patch)
tree15f925ba515e96ed182d7eb27f114a148559d046 /plugins
parenta624cae351afc239ee1ebe08d29bfbadce8b0a81 (diff)
downloadprosody-b8d1d533fdf9b9e0d348a4f8d4204e6a1f87a5bd.tar.gz
prosody-b8d1d533fdf9b9e0d348a4f8d4204e6a1f87a5bd.zip
mod_http_errors: Use util.interpolation to render HTML template
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_http_errors.lua61
1 files changed, 28 insertions, 33 deletions
diff --git a/plugins/mod_http_errors.lua b/plugins/mod_http_errors.lua
index d8646268..13473219 100644
--- a/plugins/mod_http_errors.lua
+++ b/plugins/mod_http_errors.lua
@@ -2,6 +2,8 @@ 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);
@@ -21,53 +23,46 @@ local html = [[
<!DOCTYPE html>
<html>
<head>
- <meta charset="utf-8">
- <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>
+<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>
+<h1>{title}</h1>
+<p>{message}</p>
+<p>{extra?}</p>
</body>
</html>
]];
-html = html:gsub("%s%s+", "");
-
-local entities = {
- ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;",
- ["'"] = "&apos;", ["\""] = "&quot;", ["\n"] = "<br/>",
-};
-
-local function tohtml(plain)
- return (plain:gsub("[<>&'\"\n]", entities));
-
-end
local function get_page(code, extra)
local message = messages[code];
if always_serve or message then
message = message or default_message;
- return (html:gsub("$(%a+)", {
+ 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 = tohtml(extra or "");
- }));
+ extra = extra;
+ });
end
end