1 -- Copyright (C) 2009 Thilo Cestonaro |
1 -- Copyright (C) 2009 Thilo Cestonaro |
2 -- |
2 -- |
3 -- This project is MIT/X11 licensed. Please see the |
3 -- This project is MIT/X11 licensed. Please see the |
4 -- COPYING file in the source package for more information. |
4 -- COPYING file in the source package for more information. |
5 -- |
5 -- |
|
6 |
6 local prosody = prosody; |
7 local prosody = prosody; |
7 local tabSort = table.sort; |
8 local tabSort = table.sort; |
8 local tonumber = _G.tonumber; |
9 local tonumber = _G.tonumber; |
9 local tostring = _G.tostring; |
10 local tostring = _G.tostring; |
10 local strformat = string.format; |
11 local strformat = string.format; |
12 local config_get = require "core.configmanager".get; |
13 local config_get = require "core.configmanager".get; |
13 local httpserver = require "net.httpserver"; |
14 local httpserver = require "net.httpserver"; |
14 local datamanager = require "util.datamanager"; |
15 local datamanager = require "util.datamanager"; |
15 local data_load, data_getpath = datamanager.load, datamanager.getpath; |
16 local data_load, data_getpath = datamanager.load, datamanager.getpath; |
16 local datastore = "muc_log"; |
17 local datastore = "muc_log"; |
|
18 local urlBase = "muc_log"; |
17 local muc_hosts = {}; |
19 local muc_hosts = {}; |
18 local config = nil; |
20 local config = nil; |
19 local tostring = _G.tostring; |
21 local tostring = _G.tostring; |
20 local tonumber = _G.tonumber; |
22 local tonumber = _G.tonumber; |
21 local os_date, os_time = os.date, os.time; |
23 local os_date, os_time = os.date, os.time; |
222 return room, component, day; |
224 return room, component, day; |
223 end |
225 end |
224 |
226 |
225 local function generateComponentListSiteContent() |
227 local function generateComponentListSiteContent() |
226 local components = ""; |
228 local components = ""; |
227 for component,muc_host in pairs(muc_hosts) do |
229 for component,muc_host in pairs(muc_hosts or {}) do |
228 components = components .. html.components.bit:gsub("###COMPONENT###", component); |
230 components = components .. html.components.bit:gsub("###COMPONENT###", component); |
229 end |
231 end |
230 if components ~= "" then |
232 if components ~= "" then |
231 return html.components.body:gsub("###COMPONENTS_STUFF###", components); |
233 return html.components.body:gsub("###COMPONENTS_STUFF###", components); |
232 end |
234 end |
686 end |
688 end |
687 |
689 |
688 function handle_request(method, body, request) |
690 function handle_request(method, body, request) |
689 local node, host, day = splitUrl(request.url.path); |
691 local node, host, day = splitUrl(request.url.path); |
690 |
692 |
691 if node ~= nil and host ~= nil then |
693 if muc_hosts ~= nil then |
692 local bare = node .. "@" .. host; |
694 if node ~= nil and host ~= nil then |
693 if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil then |
695 local bare = node .. "@" .. host; |
694 if prosody.hosts[host].muc.rooms[bare] ~= nil then |
696 if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil then |
695 local room = prosody.hosts[host].muc.rooms[bare]; |
697 if prosody.hosts[host].muc.rooms[bare] ~= nil then |
696 if day == nil then |
698 local room = prosody.hosts[host].muc.rooms[bare]; |
697 return createDoc(generateDayListSiteContentByRoom(bare)); |
699 if day == nil then |
|
700 return createDoc(generateDayListSiteContentByRoom(bare)); |
|
701 else |
|
702 local subject = "" |
|
703 if room._data ~= nil and room._data.subject ~= nil then |
|
704 subject = room._data.subject; |
|
705 end |
|
706 return createDoc(parseDay(bare, subject, day)); |
|
707 end |
698 else |
708 else |
699 local subject = "" |
709 return createDoc(generateRoomListSiteContent(host)); |
700 if room._data ~= nil and room._data.subject ~= nil then |
|
701 subject = room._data.subject; |
|
702 end |
|
703 return createDoc(parseDay(bare, subject, day)); |
|
704 end |
710 end |
705 else |
711 else |
706 return createDoc(generateRoomListSiteContent(host)); |
712 return createDoc(generateComponentListSiteContent()); |
707 end |
713 end |
|
714 elseif host ~= nil then |
|
715 return createDoc(generateRoomListSiteContent(host)); |
708 else |
716 else |
709 return createDoc(generateComponentListSiteContent()); |
717 return createDoc(generateComponentListSiteContent()); |
710 end |
718 end |
711 elseif host ~= nil then |
|
712 return createDoc(generateRoomListSiteContent(host)); |
|
713 else |
|
714 return createDoc(generateComponentListSiteContent()); |
|
715 end |
719 end |
716 return; |
720 return; |
717 end |
721 end |
718 |
722 |
719 function module.load() |
723 function module.load() |
720 module:log("debug", "loading mod_muc_log_http"); |
|
721 config = config_get("*", "core", "muc_log_http") or {}; |
724 config = config_get("*", "core", "muc_log_http") or {}; |
722 if config.showStatus == nil then |
725 if config.showStatus == nil then |
723 config.showStatus = true; |
726 config.showStatus = true; |
724 end |
727 end |
725 if config.showJoin == nil then |
728 if config.showJoin == nil then |
726 config.showJoin = true; |
729 config.showJoin = true; |
727 end |
730 end |
728 module:log("debug", "opening httpserver port: " .. tostring(config.port)); |
731 |
729 httpserver.new_from_config({ config.port or true }, handle_request, { base = "muc_log", ssl = false, port = 5290 }); |
732 httpserver.new_from_config({ config.http_port or true }, handle_request, { base = urlBase, ssl = false, port = 5290 }); |
730 |
733 |
731 for jid, host in pairs(prosody.hosts) do |
734 for jid, host in pairs(prosody.hosts) do |
732 if host.muc then |
735 if host.muc then |
733 local enabledModules = config_get(jid, "core", "modules_enabled"); |
736 local enabledModules = config_get(jid, "core", "modules_enabled"); |
734 if enabledModules then |
737 if enabledModules then |