From ceff8cb313e0f2e339b6594ddbe7488df1c4b6b1 Mon Sep 17 00:00:00 2001 From: Vadim Misbakh-Soloviov Date: Fri, 14 Jun 2013 15:15:05 +0700 Subject: package{,c}path fixes for migration tools --- tools/ejabberd2prosody.lua | 10 ++++++---- tools/ejabberdsql2prosody.lua | 8 ++++++++ tools/jabberd14sql2prosody.lua | 9 ++++++++- tools/openfire2prosody.lua | 6 ++++++ tools/xep227toprosody.lua | 6 ++++++ 5 files changed, 34 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/ejabberd2prosody.lua b/tools/ejabberd2prosody.lua index c11e41d9..941bd4d5 100755 --- a/tools/ejabberd2prosody.lua +++ b/tools/ejabberd2prosody.lua @@ -11,8 +11,10 @@ package.path = package.path ..";../?.lua"; -if arg[0]:match("[/\\]") then - package.path = package.path .. ";"..arg[0]:gsub("[^/\\]*$", "?.lua"); +local my_name = arg[0]; +if my_name:match("[/\\]") then + package.path = package.path..";"..my_name:gsub("[^/\\]+$", "../?.lua"); + package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so"); end local erlparse = require "erlparse"; @@ -229,10 +231,10 @@ local help = "/? -? ? /h -h /help -help --help"; if not arg or help:find(arg, 1, true) then print([[ejabberd db dump importer for Prosody - Usage: ejabberd2prosody.lua filename.txt + Usage: ]]..my_name..[[ filename.txt The file can be generated from ejabberd using: - sudo ./bin/ejabberdctl dump filename.txt + sudo ejabberdctl dump filename.txt Note: The path of ejabberdctl depends on your ejabberd installation, and ejabberd needs to be running for ejabberdctl to work.]]); os.exit(1); diff --git a/tools/ejabberdsql2prosody.lua b/tools/ejabberdsql2prosody.lua index 43720643..d80b9e46 100644 --- a/tools/ejabberdsql2prosody.lua +++ b/tools/ejabberdsql2prosody.lua @@ -10,6 +10,14 @@ prosody = {}; package.path = package.path ..";../?.lua"; + +local my_name = arg[0]; +if my_name:match("[/\\]") then + package.path = package.path..";"..my_name:gsub("[^/\\]+$", "../?.lua"); + package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so"); +end + + local serialize = require "util.serialization".serialize; local st = require "util.stanza"; local parse_xml = require "util.xml".parse; diff --git a/tools/jabberd14sql2prosody.lua b/tools/jabberd14sql2prosody.lua index b85d2c20..d6a6753f 100644 --- a/tools/jabberd14sql2prosody.lua +++ b/tools/jabberd14sql2prosody.lua @@ -428,7 +428,14 @@ end end -- import modules -package.path = [[C:\Documents and Settings\Waqas\Desktop\mercurial\prosody-hg\?.lua;]]..package.path; +package.path = package.path.."..\?.lua;"; + +local my_name = arg[0]; +if my_name:match("[/\\]") then + package.path = package.path..";"..my_name:gsub("[^/\\]+$", "../?.lua"); + package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so"); +end + -- ugly workaround for getting datamanager to work outside of prosody :( prosody = { }; diff --git a/tools/openfire2prosody.lua b/tools/openfire2prosody.lua index bdea9a63..5ef47602 100644 --- a/tools/openfire2prosody.lua +++ b/tools/openfire2prosody.lua @@ -9,6 +9,12 @@ package.path = package.path..";../?.lua"; package.cpath = package.cpath..";../?.so"; -- needed for util.pposix used in datamanager +local my_name = arg[0]; +if my_name:match("[/\\]") then + package.path = package.path..";"..my_name:gsub("[^/\\]+$", "../?.lua"); + package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so"); +end + -- ugly workaround for getting datamanager to work outside of prosody :( prosody = { }; prosody.platform = "unknown"; diff --git a/tools/xep227toprosody.lua b/tools/xep227toprosody.lua index b5156f45..0862b0c1 100755 --- a/tools/xep227toprosody.lua +++ b/tools/xep227toprosody.lua @@ -25,6 +25,12 @@ package.path = package.path..";../?.lua"; package.cpath = package.cpath..";../?.so"; -- needed for util.pposix used in datamanager +local my_name = arg[0]; +if my_name:match("[/\\]") then + package.path = package.path..";"..my_name:gsub("[^/\\]+$", "../?.lua"); + package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so"); +end + -- ugly workaround for getting datamanager to work outside of prosody :( prosody = { }; prosody.platform = "unknown"; -- cgit v1.2.3 From c633ac92a9735172dddf844a737405d29de8e0aa Mon Sep 17 00:00:00 2001 From: Vadim Misbakh-Soloviov Date: Fri, 14 Jun 2013 15:43:35 +0700 Subject: additional fix for erlparse loading in ejabberd2prosody.lua --- tools/ejabberd2prosody.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/ejabberd2prosody.lua b/tools/ejabberd2prosody.lua index 941bd4d5..ff3004c2 100755 --- a/tools/ejabberd2prosody.lua +++ b/tools/ejabberd2prosody.lua @@ -14,6 +14,7 @@ package.path = package.path ..";../?.lua"; local my_name = arg[0]; if my_name:match("[/\\]") then package.path = package.path..";"..my_name:gsub("[^/\\]+$", "../?.lua"); + package.path = package.path..";"..my_name:gsub("[^/\\]+$", "?.lua"); package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so"); end -- cgit v1.2.3 From 0adfe40738f4e5f13168d39855a820c81bf82429 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 16 Jan 2014 14:03:27 -0500 Subject: tools/ejabberdsql2prosody: Skip invalid XML in data, and print out errors. --- tools/ejabberdsql2prosody.lua | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/ejabberdsql2prosody.lua b/tools/ejabberdsql2prosody.lua index d80b9e46..40be8190 100644 --- a/tools/ejabberdsql2prosody.lua +++ b/tools/ejabberdsql2prosody.lua @@ -291,11 +291,21 @@ for i, row in ipairs(t["rostergroups"] or NULL) do roster_group(row.username, host, row.jid, row.grp); end for i, row in ipairs(t["vcard"] or NULL) do - local ret, err = dm.store(row.username, host, "vcard", st.preserialize(parse_xml(row.vcard))); - print("["..(err or "success").."] vCard: "..row.username.."@"..host); + local stanza, err = parse_xml(row.vcard); + if stanza then + local ret, err = dm.store(row.username, host, "vcard", st.preserialize(stanza)); + print("["..(err or "success").."] vCard: "..row.username.."@"..host); + else + print("[error] vCard XML parse failed: "..row.username.."@"..host); + end end for i, row in ipairs(t["private_storage"] or NULL) do - private_storage(row.username, host, row.namespace, parse_xml(row.data)); + local stanza, err = parse_xml(row.data); + if stanza then + private_storage(row.username, host, row.namespace, stanza); + else + print("[error] Private XML parse failed: "..row.username.."@"..host); + end end table.sort(t["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case local time_offset = os.difftime(os.time(os.date("!*t")), os.time(os.date("*t"))) -- to deal with timezones @@ -304,11 +314,15 @@ local date_parse = function(s) return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec-time_offset}); end for i, row in ipairs(t["spool"] or NULL) do - local stanza = parse_xml(row.xml); - local last_child = stanza.tags[#stanza.tags]; - if not last_child or last_child ~= stanza[#stanza] then error("Last child of offline message is not a tag"); end - if last_child.name ~= "x" and last_child.attr.xmlns ~= "jabber:x:delay" then error("Last child of offline message is not a timestamp"); end - stanza[#stanza], stanza.tags[#stanza.tags] = nil, nil; - local t = date_parse(last_child.attr.stamp); - offline_msg(row.username, host, t, stanza); + local stanza, err = parse_xml(row.xml); + if stanza then + local last_child = stanza.tags[#stanza.tags]; + if not last_child or last_child ~= stanza[#stanza] then error("Last child of offline message is not a tag"); end + if last_child.name ~= "x" and last_child.attr.xmlns ~= "jabber:x:delay" then error("Last child of offline message is not a timestamp"); end + stanza[#stanza], stanza.tags[#stanza.tags] = nil, nil; + local t = date_parse(last_child.attr.stamp); + offline_msg(row.username, host, t, stanza); + else + print("[error] Offline message XML parsing failed: "..row.username.."@"..host); + end end -- cgit v1.2.3 From 21f6eb82cfd1ee4070cb7658f753b07478dac5a9 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 18 Jan 2014 10:37:12 -0500 Subject: tools/ejabberd2prosody: Add support for importing MUC rooms. --- tools/ejabberd2prosody.lua | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tools') diff --git a/tools/ejabberd2prosody.lua b/tools/ejabberd2prosody.lua index ff3004c2..a8bfad0e 100755 --- a/tools/ejabberd2prosody.lua +++ b/tools/ejabberd2prosody.lua @@ -152,6 +152,48 @@ function privacy(node, host, default, lists) local ret, err = dm.store(node, host, "privacy", privacy); print("["..(err or "success").."] privacy: " ..node.."@"..host.." - "..count.." list(s)"); end +local function _table_to_jid(t) + if type(t[2]) == "string" then + local jid = t[2]; + if type(t[1]) == "string" then jid = t[1].."@"..jid; end + if type(t[3]) == "string" then jid = jid.."/"..t[3]; end + return jid; + end +end +function muc_room(node, host, properties) + local store = { jid = node.."@"..host, _data = {}, _affiliations = {} }; + for _,aff in ipairs(properties.affiliations) do + store._affiliations[_table_to_jid(aff[1])] = aff[2]; + end + store._data.subject = properties.subject; + if properties.subject_author then + store._data.subject_from = store.jid .. "/" .. properties.subject_author; + end + store._data.name = properties.title; + store._data.description = properties.description; + store._data.password = properties.password; + store._data.moderated = (properties.moderated == "true") or nil; + store._data.members_only = (properties.members_only == "true") or nil; + store._data.persistent = (properties.persistent == "true") or nil; + store._data.changesubject = (properties.allow_change_subj == "true") or nil; + store._data.whois = properties.anonymous == "true" and "moderators" or "anyone"; + store._data.hidden = (properties.public_list == "false") or nil; + + if not store._data.persistent then + return print("[error] muc_room: skipping non-persistent room: "..node.."@"..host); + end + + local ret, err = dm.store(node, host, "config", store); + if ret then + ret, err = dm.load(nil, host, "persistent"); + if ret or not err then + ret = ret or {}; + ret[store.jid] = true; + ret, err = dm.store(nil, host, "persistent", ret); + end + end + print("["..(err or "success").."] muc_room: " ..node.."@"..host); +end local filters = { @@ -196,6 +238,15 @@ local filters = { privacy = function(tuple) privacy(tuple[2][1], tuple[2][2], tuple[3], tuple[4]); end; + muc_room = function(tuple) + local properties = {}; + for _,pair in ipairs(tuple[3]) do + if not(type(pair[2]) == "table" and #pair[2] == 0) then -- skip nil values + properties[pair[1]] = pair[2]; + end + end + muc_room(tuple[2][1], tuple[2][2], properties); + end; config = function(tuple) if tuple[2] == "hosts" then local output = io.output(); io.output("prosody.cfg.lua"); -- cgit v1.2.3