Mercurial > prosody-modules
annotate mod_pastebin/mod_pastebin.lua @ 515:e98fe28c50b0
mod_host_guard: added exceptions/whitelisting to the blockall logic (makes little sense otherwise has s2s_disallow = true does the same)
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Tue, 20 Dec 2011 20:19:53 +0000 |
parents | 46e1983486e9 |
children | 3d3687fef751 |
rev | line source |
---|---|
5 | 1 |
2 local st = require "util.stanza"; | |
3 local httpserver = require "net.httpserver"; | |
4 local uuid_new = require "util.uuid".generate; | |
12
316e8437f233
mod_pastebin: Allow configurable message length threshold
Matthew Wild <mwild1@gmail.com>
parents:
5
diff
changeset
|
5 local os_time = os.time; |
24
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
6 local t_insert, t_remove = table.insert, table.remove; |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
7 local add_task = require "util.timer".add_task; |
5 | 8 |
444
82ccfba5ac2f
mod_pastebin: Support for changing the summary length (pastebin_summary_length), and including it even in the plaintext version of the generated message
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
9 local utf8_pattern = "[\194-\244][\128-\191]*$"; |
190
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
10 local function drop_invalid_utf8(seq) |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
11 local start = seq:byte(); |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
12 module:log("utf8: %d, %d", start, #seq); |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
13 if (start <= 223 and #seq < 2) |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
14 or (start >= 224 and start <= 239 and #seq < 3) |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
15 or (start >= 240 and start <= 244 and #seq < 4) |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
16 or (start > 244) then |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
17 return ""; |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
18 end |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
19 return seq; |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
20 end |
7a695ee3884b
mod_pastebin: Better fix for stripping truncated UFT-8 sequences
Matthew Wild <mwild1@gmail.com>
parents:
189
diff
changeset
|
21 |
501
e851f386c904
mod_pastebin: Threshold is now UTF-8 characters (thanks Grom_PE for initial patch)
Matthew Wild <mwild1@gmail.com>
parents:
454
diff
changeset
|
22 local function utf8_length(str) |
e851f386c904
mod_pastebin: Threshold is now UTF-8 characters (thanks Grom_PE for initial patch)
Matthew Wild <mwild1@gmail.com>
parents:
454
diff
changeset
|
23 local _, count = string.gsub(str, "[^\128-\193]", ""); |
e851f386c904
mod_pastebin: Threshold is now UTF-8 characters (thanks Grom_PE for initial patch)
Matthew Wild <mwild1@gmail.com>
parents:
454
diff
changeset
|
24 return count; |
e851f386c904
mod_pastebin: Threshold is now UTF-8 characters (thanks Grom_PE for initial patch)
Matthew Wild <mwild1@gmail.com>
parents:
454
diff
changeset
|
25 end |
e851f386c904
mod_pastebin: Threshold is now UTF-8 characters (thanks Grom_PE for initial patch)
Matthew Wild <mwild1@gmail.com>
parents:
454
diff
changeset
|
26 |
444
82ccfba5ac2f
mod_pastebin: Support for changing the summary length (pastebin_summary_length), and including it even in the plaintext version of the generated message
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
27 local pastebin_private_messages = module:get_option_boolean("pastebin_private_messages", hosts[module.host].type ~= "component"); |
445
66ca5e4d9f7b
mod_pastebin: Update to use module:get_option()
Matthew Wild <mwild1@gmail.com>
parents:
444
diff
changeset
|
28 local length_threshold = module:get_option_number("pastebin_threshold", 500); |
66ca5e4d9f7b
mod_pastebin: Update to use module:get_option()
Matthew Wild <mwild1@gmail.com>
parents:
444
diff
changeset
|
29 local line_threshold = module:get_option_number("pastebin_line_threshold", 4); |
446
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
30 local max_summary_length = module:get_option_number("pastebin_summary_length", 150); |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
31 local html_preview = module:get_option_boolean("pastebin_html_preview", true); |
5 | 32 |
445
66ca5e4d9f7b
mod_pastebin: Update to use module:get_option()
Matthew Wild <mwild1@gmail.com>
parents:
444
diff
changeset
|
33 local base_url = module:get_option_string("pastebin_url"); |
5 | 34 |
24
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
35 -- Seconds a paste should live for in seconds (config is in hours), default 24 hours |
445
66ca5e4d9f7b
mod_pastebin: Update to use module:get_option()
Matthew Wild <mwild1@gmail.com>
parents:
444
diff
changeset
|
36 local expire_after = math.floor(module:get_option_number("pastebin_expire_after", 24) * 3600); |
24
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
37 |
445
66ca5e4d9f7b
mod_pastebin: Update to use module:get_option()
Matthew Wild <mwild1@gmail.com>
parents:
444
diff
changeset
|
38 local trigger_string = module:get_option_string("pastebin_trigger"); |
167
0d37d18ea073
mod_pastebin: Fix trigger_string matching when no trigger is set, and add support for counting lines (pastebin_line_threshold, default: 4)
Matthew Wild <mwild1@gmail.com>
parents:
156
diff
changeset
|
39 trigger_string = (trigger_string and trigger_string .. " "); |
156
b51741b7e86d
mod_pastebin: Optionally bin if message starts with a configurable trigger string
Florian Zeitz <florob@babelmonkeys.de>
parents:
76
diff
changeset
|
40 |
5 | 41 local pastes = {}; |
76
1fc4e8dc66a6
mod_pastebin: Send Content-Type header to specify plain UTF-8 text
Matthew Wild <mwild1@gmail.com>
parents:
75
diff
changeset
|
42 local default_headers = { ["Content-Type"] = "text/plain; charset=utf-8" }; |
5 | 43 |
44 local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im"; | |
45 local xmlns_xhtml = "http://www.w3.org/1999/xhtml"; | |
46 | |
514
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
47 if expire_after == 0 then |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
48 local dm = require "util.datamanager"; |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
49 setmetatable(pastes, { |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
50 __index = function (pastes, id) |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
51 if type(id) == "string" then |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
52 return dm.load(id, module.host, "pastebin"); |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
53 end |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
54 end; |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
55 __newindex = function (pastes, id, data) |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
56 if type(id) == "string" then |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
57 dm.store(id, module.host, "pastebin", data); |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
58 end |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
59 end; |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
60 }); |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
61 else |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
62 setmetatable(pastes, nil); |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
63 end |
46e1983486e9
mod_pastebin: Support for persistent pastes (set pastebin_expire_after = 0)
Matthew Wild <mwild1@gmail.com>
parents:
513
diff
changeset
|
64 |
75
3c7189e26848
mod_pastebin: Rename pastebin_message() to pastebin_text() and make it global so it can be called by other plugins
Matthew Wild <mwild1@gmail.com>
parents:
71
diff
changeset
|
65 function pastebin_text(text) |
5 | 66 local uuid = uuid_new(); |
76
1fc4e8dc66a6
mod_pastebin: Send Content-Type header to specify plain UTF-8 text
Matthew Wild <mwild1@gmail.com>
parents:
75
diff
changeset
|
67 pastes[uuid] = { body = text, time = os_time(), headers = default_headers }; |
24
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
68 pastes[#pastes+1] = uuid; |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
69 if not pastes[2] then -- No other pastes, give the timer a kick |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
70 add_task(expire_after, expire_pastes); |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
71 end |
5 | 72 return base_url..uuid; |
73 end | |
74 | |
75 function handle_request(method, body, request) | |
76 local pasteid = request.url.path:match("[^/]+$"); | |
77 if not pasteid or not pastes[pasteid] then | |
78 return "Invalid paste id, perhaps it expired?"; | |
79 end | |
80 | |
81 --module:log("debug", "Received request, replying: %s", pastes[pasteid].text); | |
82 | |
76
1fc4e8dc66a6
mod_pastebin: Send Content-Type header to specify plain UTF-8 text
Matthew Wild <mwild1@gmail.com>
parents:
75
diff
changeset
|
83 return pastes[pasteid]; |
5 | 84 end |
85 | |
86 function check_message(data) | |
87 local origin, stanza = data.origin, data.stanza; | |
88 | |
89 local body, bodyindex, htmlindex; | |
90 for k,v in ipairs(stanza) do | |
91 if v.name == "body" then | |
92 body, bodyindex = v, k; | |
71
3c18c2d03bc2
mod_pastebin: Fix finding of XHTML content.
Paul Aurich <paul@darkrain42.org>
parents:
25
diff
changeset
|
93 elseif v.name == "html" and v.attr.xmlns == xmlns_xhtmlim then |
5 | 94 htmlindex = k; |
95 end | |
96 end | |
97 | |
98 if not body then return; end | |
99 body = body:get_text(); | |
100 | |
25
ea59a8d98b03
mod_pastebin: Comment some debug logging on every message
Matthew Wild <mwild1@gmail.com>
parents:
24
diff
changeset
|
101 --module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); |
5 | 102 |
167
0d37d18ea073
mod_pastebin: Fix trigger_string matching when no trigger is set, and add support for counting lines (pastebin_line_threshold, default: 4)
Matthew Wild <mwild1@gmail.com>
parents:
156
diff
changeset
|
103 if body and ( |
501
e851f386c904
mod_pastebin: Threshold is now UTF-8 characters (thanks Grom_PE for initial patch)
Matthew Wild <mwild1@gmail.com>
parents:
454
diff
changeset
|
104 ((#body > length_threshold) |
512
c819365ac6ab
mod_pastebin: Fix call to undefined function introduced in previous commit
Matthew Wild <mwild1@gmail.com>
parents:
501
diff
changeset
|
105 and (utf8_length(body) > length_threshold)) or |
167
0d37d18ea073
mod_pastebin: Fix trigger_string matching when no trigger is set, and add support for counting lines (pastebin_line_threshold, default: 4)
Matthew Wild <mwild1@gmail.com>
parents:
156
diff
changeset
|
106 (trigger_string and body:find(trigger_string, 1, true) == 1) or |
0d37d18ea073
mod_pastebin: Fix trigger_string matching when no trigger is set, and add support for counting lines (pastebin_line_threshold, default: 4)
Matthew Wild <mwild1@gmail.com>
parents:
156
diff
changeset
|
107 (select(2, body:gsub("\n", "%0")) >= line_threshold) |
0d37d18ea073
mod_pastebin: Fix trigger_string matching when no trigger is set, and add support for counting lines (pastebin_line_threshold, default: 4)
Matthew Wild <mwild1@gmail.com>
parents:
156
diff
changeset
|
108 ) then |
0d37d18ea073
mod_pastebin: Fix trigger_string matching when no trigger is set, and add support for counting lines (pastebin_line_threshold, default: 4)
Matthew Wild <mwild1@gmail.com>
parents:
156
diff
changeset
|
109 if trigger_string then |
0d37d18ea073
mod_pastebin: Fix trigger_string matching when no trigger is set, and add support for counting lines (pastebin_line_threshold, default: 4)
Matthew Wild <mwild1@gmail.com>
parents:
156
diff
changeset
|
110 body = body:gsub("^" .. trigger_string, "", 1); |
0d37d18ea073
mod_pastebin: Fix trigger_string matching when no trigger is set, and add support for counting lines (pastebin_line_threshold, default: 4)
Matthew Wild <mwild1@gmail.com>
parents:
156
diff
changeset
|
111 end |
75
3c7189e26848
mod_pastebin: Rename pastebin_message() to pastebin_text() and make it global so it can be called by other plugins
Matthew Wild <mwild1@gmail.com>
parents:
71
diff
changeset
|
112 local url = pastebin_text(body); |
5 | 113 module:log("debug", "Pasted message as %s", url); |
114 --module:log("debug", " stanza[bodyindex] = %q", tostring( stanza[bodyindex])); | |
446
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
115 local summary = (body:sub(1, max_summary_length):gsub(utf8_pattern, drop_invalid_utf8) or ""):match("[^\n]+") or ""; |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
116 summary = summary:match("^%s*(.-)%s*$"); |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
117 local summary_prefixed = summary:match("[,:]$"); |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
118 stanza[bodyindex][1] = (summary_prefixed and (summary.." ") or "")..url; |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
119 |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
120 if html_preview then |
513
5e8843a869a3
mod_pastebin: Fix off-by-one in line counting (display issue only)
Matthew Wild <mwild1@gmail.com>
parents:
512
diff
changeset
|
121 local line_count = select(2, body:gsub("\n", "%0")) + 1; |
446
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
122 local link_text = ("[view %spaste (%d line%s)]"):format(summary_prefixed and "" or "rest of ", line_count, line_count == 1 and "" or "s"); |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
123 local html = st.stanza("html", { xmlns = xmlns_xhtmlim }):tag("body", { xmlns = xmlns_xhtml }); |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
124 html:tag("p"):text(summary.." "):up(); |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
125 html:tag("a", { href = url }):text(link_text):up(); |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
126 stanza[htmlindex or #stanza+1] = html; |
56f1c29ee7f1
mod_pastebin: Some experimental summary changes
Matthew Wild <mwild1@gmail.com>
parents:
445
diff
changeset
|
127 end |
5 | 128 end |
129 end | |
130 | |
131 module:hook("message/bare", check_message); | |
438
7f0cdde1e42a
mod_pastebin: Add option 'pastebin_private_messages', defaults to false for components and true for other hosts (thanks Kelden/Maranda)
Matthew Wild <mwild1@gmail.com>
parents:
190
diff
changeset
|
132 if pastebin_private_messages then |
7f0cdde1e42a
mod_pastebin: Add option 'pastebin_private_messages', defaults to false for components and true for other hosts (thanks Kelden/Maranda)
Matthew Wild <mwild1@gmail.com>
parents:
190
diff
changeset
|
133 module:hook("message/full", check_message); |
7f0cdde1e42a
mod_pastebin: Add option 'pastebin_private_messages', defaults to false for components and true for other hosts (thanks Kelden/Maranda)
Matthew Wild <mwild1@gmail.com>
parents:
190
diff
changeset
|
134 end |
5 | 135 |
24
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
136 function expire_pastes(time) |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
137 time = time or os_time(); -- COMPAT with 0.5 |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
138 if pastes[1] then |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
139 pastes[pastes[1]] = nil; |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
140 t_remove(pastes, 1); |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
141 if pastes[1] then |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
142 return (expire_after - (time - pastes[pastes[1]].time)) + 1; |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
143 end |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
144 end |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
145 end |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
146 |
72bcc0475e2f
mod_pastebin: Expire pastes after 'pastebin_expire_after' hours, 24 by default
Matthew Wild <mwild1@gmail.com>
parents:
23
diff
changeset
|
147 |
445
66ca5e4d9f7b
mod_pastebin: Update to use module:get_option()
Matthew Wild <mwild1@gmail.com>
parents:
444
diff
changeset
|
148 local ports = module:get_option("pastebin_ports", { 5280 }); |
5 | 149 for _, options in ipairs(ports) do |
150 local port, base, ssl, interface = 5280, "pastebin", false, nil; | |
151 if type(options) == "number" then | |
152 port = options; | |
153 elseif type(options) == "table" then | |
154 port, base, ssl, interface = options.port or 5280, options.path or "pastebin", options.ssl or false, options.interface; | |
155 elseif type(options) == "string" then | |
156 base = options; | |
157 end | |
158 | |
159 base_url = base_url or ("http://"..module:get_host()..(port ~= 80 and (":"..port) or "").."/"..base.."/"); | |
160 | |
161 httpserver.new{ port = port, base = base, handler = handle_request, ssl = ssl } | |
162 end | |
454
3f101f7a26d0
mod_pastebin: Preserve pastes through a reload
Matthew Wild <mwild1@gmail.com>
parents:
446
diff
changeset
|
163 |
3f101f7a26d0
mod_pastebin: Preserve pastes through a reload
Matthew Wild <mwild1@gmail.com>
parents:
446
diff
changeset
|
164 function module.save() |
3f101f7a26d0
mod_pastebin: Preserve pastes through a reload
Matthew Wild <mwild1@gmail.com>
parents:
446
diff
changeset
|
165 return { pastes = pastes }; |
3f101f7a26d0
mod_pastebin: Preserve pastes through a reload
Matthew Wild <mwild1@gmail.com>
parents:
446
diff
changeset
|
166 end |
3f101f7a26d0
mod_pastebin: Preserve pastes through a reload
Matthew Wild <mwild1@gmail.com>
parents:
446
diff
changeset
|
167 |
3f101f7a26d0
mod_pastebin: Preserve pastes through a reload
Matthew Wild <mwild1@gmail.com>
parents:
446
diff
changeset
|
168 function module.restore(data) |
3f101f7a26d0
mod_pastebin: Preserve pastes through a reload
Matthew Wild <mwild1@gmail.com>
parents:
446
diff
changeset
|
169 pastes = data.pastes or pastes; |
3f101f7a26d0
mod_pastebin: Preserve pastes through a reload
Matthew Wild <mwild1@gmail.com>
parents:
446
diff
changeset
|
170 end |