Software /
code /
prosody-modules
Annotate
mod_xml_status/mod_xml_status.lua @ 525:a9cd75cc9563
mod_xml_status: small cleanup.
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Fri, 06 Jan 2012 23:43:52 +0000 |
parent | 524:ff3ea8735d61 |
child | 526:0529658efd1e |
rev | line source |
---|---|
524
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
1 -- (C) 2011, Marco Cirillo (LW.Org) |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
2 -- Display server stats in readable XML format |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
3 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
4 module:set_global() |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
5 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
6 local ports = module:get_option_array("xml_status_http_ports", {{ port = 5280 }}) |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
7 local show_hosts = module:get_option_array("xml_status_show_hosts", nil) |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
8 local show_comps = module:get_option_array("xml_status_show_comps", nil) |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
9 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
10 local httpserver = require "net.httpserver" |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
11 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
12 -- code begin |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
13 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
14 if not prosody.stanza_counter and not show_hosts and not show_comps then |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
15 module:log ("error", "mod_xml_status requires at least one of the following things:") |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
16 module:log ("error", "mod_stanza_counter loaded, or either xml_status_show_hosts or xml_status_show_comps configuration values set.") |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
17 module:log ("error", "check the module wiki at: http://code.google.com/p/prosody-modules/wiki/mod_xml_status") |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
18 return false |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
19 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
20 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
21 local r_err = "\n<html>\n<head>\n<title>Prosody's XML Status - 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" |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
22 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
23 local response_table = {} |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
24 response_table.header = '<?xml version="1.0" encoding="UTF-8" ?>' |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
25 response_table.doc_header = '<document>' |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
26 response_table.doc_closure = '</document>' |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
27 response_table.stanzas = { |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
28 elem_header = ' <stanzas>', elem_closure = ' </stanzas>', |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
29 incoming = ' <incoming iq="%d" message="%d" presence="%d" />', |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
30 outgoing = ' <outgoing iq="%d" message="%d" presence="%d" />' |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
31 } |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
32 response_table.hosts = { |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
33 elem_header = ' <hosts>', elem_closure = ' </hosts>', |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
34 status = ' <status name="%s" current="%s" />' |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
35 } |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
36 response_table.comps = { |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
37 elem_header = ' <components>', elem_closure = ' </components>', |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
38 status = ' <status name="%s" current="%s" />' |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
39 } |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
40 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
41 local function forge_response() |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
42 local hosts_s = {}; local components = {}; local stats = {}; local hosts_stats = {}; local comps_stats = {} |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
43 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
44 -- add headers |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
45 local result = {}; result[#result+1] = response_table.header; result[#result+1] = response_table.doc_header |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
46 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
47 if show_hosts then for _, name in ipairs(show_hosts) do hosts_s[#hosts_s+1] = name end end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
48 if show_comps then for _, name in ipairs(show_comps) do components[#components+1] = name end end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
49 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
50 -- build stanza stats if there |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
51 if prosody.stanza_counter then |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
52 stats[1] = response_table.stanzas.elem_header |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
53 stats[2] = response_table.stanzas.incoming:format(prosody.stanza_counter.iq["incoming"], |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
54 prosody.stanza_counter.message["incoming"], |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
55 prosody.stanza_counter.presence["incoming"]) |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
56 stats[3] = response_table.stanzas.outgoing:format(prosody.stanza_counter.iq["outgoing"], |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
57 prosody.stanza_counter.message["outgoing"], |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
58 prosody.stanza_counter.presence["outgoing"]) |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
59 stats[4] = response_table.stanzas.elem_closure |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
60 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
61 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
62 -- build hosts stats if there |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
63 if hosts_s[1] then |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
64 hosts_stats[1] = response_table.hosts.elem_header |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
65 for _, name in ipairs(hosts_s) do |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
66 hosts_stats[#hosts_stats+1] = response_table.hosts.status:format( |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
67 name, hosts[name] and "online" or "offline") |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
68 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
69 hosts_stats[#hosts_stats+1] = response_table.hosts.elem_closure |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
70 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
71 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
72 -- build components stats if there |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
73 if components[1] then |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
74 comps_stats[1] = response_table.comps.elem_header |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
75 for _, name in ipairs(components) do |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
76 comps_stats[#comps_stats+1] = response_table.comps.status:format( |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
77 name, hosts[name].modules.component and hosts[name].modules.component.connected and "online" or |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
78 hosts[name] and hosts[name].modules.component == nil and "online" or "offline") |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
79 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
80 comps_stats[#comps_stats+1] = response_table.comps.elem_closure |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
81 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
82 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
83 -- finish building xml stats document |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
84 for _, bstring in ipairs(stats) do result[#result+1] = bstring end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
85 for _, bstring in ipairs(hosts_stats) do result[#result+1] = bstring end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
86 for _, bstring in ipairs(comps_stats) do result[#result+1] = bstring end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
87 result[#result+1] = response_table.doc_closure |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
88 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
89 return table.concat(result, "\n") |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
90 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
91 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
92 -- http handlers |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
93 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
94 local function response(code, r, h) |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
95 local response = { |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
96 status = code; |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
97 body = r; |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
98 } |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
99 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
100 if h then response.headers = h; end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
101 return response |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
102 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
103 |
525
a9cd75cc9563
mod_xml_status: small cleanup.
Marco Cirillo <maranda@lightwitch.org>
parents:
524
diff
changeset
|
104 local function request(method, body, request) |
524
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
105 if method == "GET" then |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
106 return response(200, forge_response()) |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
107 else |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
108 local err405 = r_err:format("405", "Only GET is supported") |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
109 return response(405, err405, {["Allow"] = "GET"}) |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
110 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
111 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
112 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
113 -- initialization. |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
114 -- init http interface |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
115 local function setup() |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
116 httpserver.new_from_config(ports, request, { base = "xml-status" }) |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
117 end |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
118 |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
119 if prosody.start_time then |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
120 setup(); |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
121 else |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
122 module:hook("server-started", setup); |
ff3ea8735d61
mod_xml_status: initial commit. Expose server status in xml format to be used on external webapps.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
123 end |