Mercurial > prosody-modules
comparison mod_muc_log_http/mod_muc_log_http.lua @ 102:a10ab09096e2
mod_muc_log_http: double check if muc_hosts is not nil, less logging, config var renamed to http_port back again
| author | Thilo Cestonaro <thilo@cestona.ro> |
|---|---|
| date | Wed, 02 Dec 2009 22:23:00 +0100 |
| parents | e3c09996cf7b |
| children | dc0fe152cadc |
comparison
equal
deleted
inserted
replaced
| 101:e3c09996cf7b | 102:a10ab09096e2 |
|---|---|
| 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 |
| 384 local room = nil; | 386 local room = nil; |
| 385 local attributes = nil; | 387 local attributes = nil; |
| 386 | 388 |
| 387 path = path:gsub("/[^/]*$", ""); | 389 path = path:gsub("/[^/]*$", ""); |
| 388 attributes = lfs.attributes(path); | 390 attributes = lfs.attributes(path); |
| 389 if muc_hosts[host] and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bareRoomJid] ~= nil then | 391 if muc_hosts ~= nil and muc_hosts[host] and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bareRoomJid] ~= nil then |
| 390 room = prosody.hosts[host].muc.rooms[bareRoomJid]; | 392 room = prosody.hosts[host].muc.rooms[bareRoomJid]; |
| 391 if room._data.hidden then | 393 if room._data.hidden then |
| 392 room = nil | 394 room = nil |
| 393 end | 395 end |
| 394 end | 396 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 |
| 744 end | 747 end |
| 745 module:log("debug", "loaded mod_muc_log_http"); | 748 module:log("debug", "loaded mod_muc_log_http"); |
| 746 end | 749 end |
| 747 | 750 |
| 748 function module.unload() | 751 function module.unload() |
| 749 module:log("debug", "unloading mod_muc_log_http"); | |
| 750 muc_hosts = nil; | 752 muc_hosts = nil; |
| 751 module:log("debug", "unloaded mod_muc_log_http"); | 753 module:log("debug", "unloaded mod_muc_log_http"); |
| 752 end | 754 end |
| 753 | 755 |
| 754 module:add_event_hook("component-activated", function(component, config) | 756 module:add_event_hook("component-activated", function(component, config) |
