Software /
code /
prosody
Annotate
tools/ejabberd2prosody.lua @ 9781:161411a41377
util.prosodyctl: Allow passing path to Lua runtime to the start() function
By default the shebang is used. Being able to override it is useful in
cases where the shebang does not match the configured runtime.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 10 Jan 2019 14:57:26 +0100 |
parent | 6798:8b4c8e957211 |
child | 11841:94534717ffca |
rev | line source |
---|---|
485
f8456f0da769
Make ejabberd2prosody.lua a little more cross-platform :)
Matthew Wild <mwild1@gmail.com>
parents:
484
diff
changeset
|
1 #!/usr/bin/env lua |
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1126
diff
changeset
|
2 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2693
diff
changeset
|
3 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2693
diff
changeset
|
4 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5697
diff
changeset
|
5 -- |
758 | 6 -- This project is MIT/X11 licensed. Please see the |
7 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
489
diff
changeset
|
8 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
489
diff
changeset
|
9 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
489
diff
changeset
|
10 |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
11 |
1726
85518cb866dd
ejabberd2prosody: More intelligent searching for erlparse library
Matthew Wild <mwild1@gmail.com>
parents:
1567
diff
changeset
|
12 package.path = package.path ..";../?.lua"; |
85518cb866dd
ejabberd2prosody: More intelligent searching for erlparse library
Matthew Wild <mwild1@gmail.com>
parents:
1567
diff
changeset
|
13 |
5696
9fba74a28e0c
package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
5310
diff
changeset
|
14 local my_name = arg[0]; |
9fba74a28e0c
package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
5310
diff
changeset
|
15 if my_name:match("[/\\]") then |
9fba74a28e0c
package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
5310
diff
changeset
|
16 package.path = package.path..";"..my_name:gsub("[^/\\]+$", "../?.lua"); |
5697
956df0f1cb70
additional fix for erlparse loading in ejabberd2prosody.lua
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
5696
diff
changeset
|
17 package.path = package.path..";"..my_name:gsub("[^/\\]+$", "?.lua"); |
5696
9fba74a28e0c
package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
5310
diff
changeset
|
18 package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so"); |
1726
85518cb866dd
ejabberd2prosody: More intelligent searching for erlparse library
Matthew Wild <mwild1@gmail.com>
parents:
1567
diff
changeset
|
19 end |
85518cb866dd
ejabberd2prosody: More intelligent searching for erlparse library
Matthew Wild <mwild1@gmail.com>
parents:
1567
diff
changeset
|
20 |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4380
diff
changeset
|
21 local erlparse = require "erlparse"; |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
22 |
2943
9236a7856688
tools/ejabberd2prosody: Create prosody singleton so datamanager can detect the platform (set no platform to use lfs, pposix isn't necessary here)
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
23 prosody = {}; |
9236a7856688
tools/ejabberd2prosody: Create prosody singleton so datamanager can detect the platform (set no platform to use lfs, pposix isn't necessary here)
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
24 |
5309
2da869d95271
ejabberd2prosody.lua: Replace util.logger with a dummy before requiring util.serialization
Kim Alvefur <zash@zash.se>
parents:
5023
diff
changeset
|
25 package.loaded["util.logger"] = {init = function() return function() end; end} |
547
265c4b8f0a8a
Changed the ejabberd import script to use util.serialization
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
26 local serialize = require "util.serialization".serialize; |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
27 local st = require "util.stanza"; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
28 local dm = require "util.datamanager" |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
29 dm.set_data_path("data"); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
30 |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
31 function build_stanza(tuple, stanza) |
4380
9f1c61805817
ejabberd2prosody: Added a lot more type checks to ensure XML data has proper data types. Ignore attributes of invalid types. Fixes the cause of issue#261.
Waqas Hussain <waqas20@gmail.com>
parents:
4360
diff
changeset
|
32 assert(type(tuple) == "table", "XML node is of unexpected type: "..type(tuple)); |
5998
60d86c9e02ec
tools/ejabberd2prosody: “xmlelement” can be “xmlel” in newer ejabberd (thanks cr).
Waqas Hussain <waqas20@gmail.com>
parents:
5992
diff
changeset
|
33 if tuple[1] == "xmlelement" or tuple[1] == "xmlel" then |
4380
9f1c61805817
ejabberd2prosody: Added a lot more type checks to ensure XML data has proper data types. Ignore attributes of invalid types. Fixes the cause of issue#261.
Waqas Hussain <waqas20@gmail.com>
parents:
4360
diff
changeset
|
34 assert(type(tuple[2]) == "string", "element name has type: "..type(tuple[2])); |
9f1c61805817
ejabberd2prosody: Added a lot more type checks to ensure XML data has proper data types. Ignore attributes of invalid types. Fixes the cause of issue#261.
Waqas Hussain <waqas20@gmail.com>
parents:
4360
diff
changeset
|
35 assert(type(tuple[3]) == "table", "element attribute array has type: "..type(tuple[3])); |
9f1c61805817
ejabberd2prosody: Added a lot more type checks to ensure XML data has proper data types. Ignore attributes of invalid types. Fixes the cause of issue#261.
Waqas Hussain <waqas20@gmail.com>
parents:
4360
diff
changeset
|
36 assert(type(tuple[4]) == "table", "element children array has type: "..type(tuple[4])); |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
37 local name = tuple[2]; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
38 local attr = {}; |
4380
9f1c61805817
ejabberd2prosody: Added a lot more type checks to ensure XML data has proper data types. Ignore attributes of invalid types. Fixes the cause of issue#261.
Waqas Hussain <waqas20@gmail.com>
parents:
4360
diff
changeset
|
39 for _, a in ipairs(tuple[3]) do |
9f1c61805817
ejabberd2prosody: Added a lot more type checks to ensure XML data has proper data types. Ignore attributes of invalid types. Fixes the cause of issue#261.
Waqas Hussain <waqas20@gmail.com>
parents:
4360
diff
changeset
|
40 if type(a[1]) == "string" and type(a[2]) == "string" then attr[a[1]] = a[2]; end |
9f1c61805817
ejabberd2prosody: Added a lot more type checks to ensure XML data has proper data types. Ignore attributes of invalid types. Fixes the cause of issue#261.
Waqas Hussain <waqas20@gmail.com>
parents:
4360
diff
changeset
|
41 end |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
42 local up; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
43 if stanza then stanza:tag(name, attr); up = true; else stanza = st.stanza(name, attr); end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
44 for _, a in ipairs(tuple[4]) do build_stanza(a, stanza); end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
45 if up then stanza:up(); else return stanza end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
46 elseif tuple[1] == "xmlcdata" then |
6024
c352d97cf137
tools/ejabberd2prosody: Don't throw an error if XML CDATA is null ([] in Erlang, instead of a string or being missing).
Waqas Hussain <waqas20@gmail.com>
parents:
6006
diff
changeset
|
47 if type(tuple[2]) ~= "table" then |
c352d97cf137
tools/ejabberd2prosody: Don't throw an error if XML CDATA is null ([] in Erlang, instead of a string or being missing).
Waqas Hussain <waqas20@gmail.com>
parents:
6006
diff
changeset
|
48 assert(type(tuple[2]) == "string", "XML CDATA has unexpected type: "..type(tuple[2])); |
c352d97cf137
tools/ejabberd2prosody: Don't throw an error if XML CDATA is null ([] in Erlang, instead of a string or being missing).
Waqas Hussain <waqas20@gmail.com>
parents:
6006
diff
changeset
|
49 stanza:text(tuple[2]); |
c352d97cf137
tools/ejabberd2prosody: Don't throw an error if XML CDATA is null ([] in Erlang, instead of a string or being missing).
Waqas Hussain <waqas20@gmail.com>
parents:
6006
diff
changeset
|
50 end -- else it's [], i.e., the null value, used for the empty string |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
51 else |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
52 error("unknown element type: "..serialize(tuple)); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
53 end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
54 end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
55 function build_time(tuple) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
56 local Megaseconds,Seconds,Microseconds = unpack(tuple); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
57 return Megaseconds * 1000000 + Seconds; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
58 end |
6280
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
59 function build_jid(tuple, full) |
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
60 local node, jid, resource = tuple[1], tuple[2], tuple[3] |
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
61 if type(node) == "string" and node ~= "" then |
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
62 jid = tuple[1] .. "@" .. jid; |
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
63 end |
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
64 if full and type(resource) == "string" and resource ~= "" then |
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
65 jid = jid .. "/" .. resource; |
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
66 end |
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
67 return jid; |
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
68 end |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
69 |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
70 function vcard(node, host, stanza) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
71 local ret, err = dm.store(node, host, "vcard", st.preserialize(stanza)); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
72 print("["..(err or "success").."] vCard: "..node.."@"..host); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
73 end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
74 function password(node, host, password) |
6797
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
75 local data = {}; |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
76 if type(password) == "string" then |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
77 data.password = password; |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
78 elseif type(password) == "table" and password[1] == "scram" then |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
79 local unb64 = require"mime".unb64; |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
80 local function hex(s) |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
81 return s:gsub(".", function (c) |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
82 return ("%02x"):format(c:byte()); |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
83 end); |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
84 end |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
85 data.stored_key = hex(unb64(password[2])); |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
86 data.server_key = hex(unb64(password[3])); |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
87 data.salt = unb64(password[4]); |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
88 data.iteration_count = password[5]; |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
89 end |
509b70437035
ejabberd2prosody: Support password stored as SCRAM hashes
Kim Alvefur <zash@zash.se>
parents:
6280
diff
changeset
|
90 local ret, err = dm.store(node, host, "accounts", data); |
2693
e60494fbf23f
ejabberd2prosody: Don't print passwords of imported accounts
Matthew Wild <mwild1@gmail.com>
parents:
1784
diff
changeset
|
91 print("["..(err or "success").."] accounts: "..node.."@"..host); |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
92 end |
753
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
93 function roster(node, host, jid, item) |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
94 local roster = dm.load(node, host, "roster") or {}; |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
95 roster[jid] = item; |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
96 local ret, err = dm.store(node, host, "roster", roster); |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
97 print("["..(err or "success").."] roster: " ..node.."@"..host.." - "..jid); |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
98 end |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
99 function roster_pending(node, host, jid) |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
100 local roster = dm.load(node, host, "roster") or {}; |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
101 roster.pending = roster.pending or {}; |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
102 roster.pending[jid] = true; |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
103 local ret, err = dm.store(node, host, "roster", roster); |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
104 print("["..(err or "success").."] roster: " ..node.."@"..host.." - "..jid); |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
105 end |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
106 function private_storage(node, host, xmlns, stanza) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
107 local private = dm.load(node, host, "private") or {}; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
108 private[stanza.name..":"..xmlns] = st.preserialize(stanza); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
109 local ret, err = dm.store(node, host, "private", private); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
110 print("["..(err or "success").."] private: " ..node.."@"..host.." - "..xmlns); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
111 end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
112 function offline_msg(node, host, t, stanza) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
113 stanza.attr.stamp = os.date("!%Y-%m-%dT%H:%M:%SZ", t); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
114 stanza.attr.stamp_legacy = os.date("!%Y%m%dT%H:%M:%S", t); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
115 local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza)); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
116 print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t)); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
117 end |
4360
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
118 function privacy(node, host, default, lists) |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
119 local privacy = { lists = {} }; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
120 local count = 0; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
121 if default then privacy.default = default; end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
122 for _, inlist in ipairs(lists) do |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
123 local name, items = inlist[1], inlist[2]; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
124 local list = { name = name; items = {}; }; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
125 local orders = {}; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
126 for _, item in pairs(items) do |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
127 repeat |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
128 if item[1] ~= "listitem" then print("[error] privacy: unhandled item: "..tostring(item[1])); break; end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
129 local _type, value = item[2], item[3]; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
130 if _type == "jid" then |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
131 if type(value) ~= "table" then print("[error] privacy: jid value is not valid: "..tostring(value)); break; end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
132 local _node, _host, _resource = value[1], value[2], value[3]; |
6280
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
133 value = build_jid(value, true) |
4360
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
134 elseif _type == "none" then |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
135 _type = nil; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
136 value = nil; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
137 elseif _type == "group" then |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
138 if type(value) ~= "string" then print("[error] privacy: group value is not string: "..tostring(value)); break; end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
139 elseif _type == "subscription" then |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
140 if value~="both" and value~="from" and value~="to" and value~="none" then |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
141 print("[error] privacy: subscription value is invalid: "..tostring(value)); break; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
142 end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
143 else print("[error] privacy: invalid item type: "..tostring(_type)); break; end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
144 local action = item[4]; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
145 if action ~= "allow" and action ~= "deny" then print("[error] privacy: unhandled action: "..tostring(action)); break; end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
146 local order = item[5]; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
147 if type(order) ~= "number" or order<0 then print("[error] privacy: order is not numeric: "..tostring(order)); break; end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
148 if orders[order] then print("[error] privacy: duplicate order value: "..tostring(order)); break; end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
149 orders[order] = true; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
150 local match_all = item[6]; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
151 local match_iq = item[7]; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
152 local match_message = item[8]; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
153 local match_presence_in = item[9]; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
154 local match_presence_out = item[10]; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
155 list.items[#list.items+1] = { |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
156 type = _type; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
157 value = value; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
158 action = action; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
159 order = order; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
160 message = match_message == "true"; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
161 iq = match_iq == "true"; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
162 ["presence-in"] = match_presence_in == "true"; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
163 ["presence-out"] = match_presence_out == "true"; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
164 }; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
165 until true; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
166 end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
167 table.sort(list.items, function(a, b) return a.order < b.order; end); |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
168 if privacy.lists[list.name] then print("[warn] duplicate privacy list: "..tostring(list.name)); end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
169 privacy.lists[list.name] = list; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
170 count = count + 1; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
171 end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
172 if default and not privacy.lists[default] then |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
173 if default == "none" then privacy.default = nil; |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
174 else print("[warn] default privacy list doesn't exist: "..tostring(default)); end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
175 end |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
176 local ret, err = dm.store(node, host, "privacy", privacy); |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
177 print("["..(err or "success").."] privacy: " ..node.."@"..host.." - "..count.." list(s)"); |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
178 end |
5992
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
179 function muc_room(node, host, properties) |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
180 local store = { jid = node.."@"..host, _data = {}, _affiliations = {} }; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
181 for _,aff in ipairs(properties.affiliations) do |
6280
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
182 store._affiliations[build_jid(aff[1])] = aff[2][1] or aff[2]; |
5992
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
183 end |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
184 store._data.subject = properties.subject; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
185 if properties.subject_author then |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
186 store._data.subject_from = store.jid .. "/" .. properties.subject_author; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
187 end |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
188 store._data.name = properties.title; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
189 store._data.description = properties.description; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
190 store._data.password = properties.password; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
191 store._data.moderated = (properties.moderated == "true") or nil; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
192 store._data.members_only = (properties.members_only == "true") or nil; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
193 store._data.persistent = (properties.persistent == "true") or nil; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
194 store._data.changesubject = (properties.allow_change_subj == "true") or nil; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
195 store._data.whois = properties.anonymous == "true" and "moderators" or "anyone"; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
196 store._data.hidden = (properties.public_list == "false") or nil; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
197 |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
198 if not store._data.persistent then |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
199 return print("[error] muc_room: skipping non-persistent room: "..node.."@"..host); |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
200 end |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
201 |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
202 local ret, err = dm.store(node, host, "config", store); |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
203 if ret then |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
204 ret, err = dm.load(nil, host, "persistent"); |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
205 if ret or not err then |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
206 ret = ret or {}; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
207 ret[store.jid] = true; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
208 ret, err = dm.store(nil, host, "persistent", ret); |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
209 end |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
210 end |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
211 print("["..(err or "success").."] muc_room: " ..node.."@"..host); |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
212 end |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
213 |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
214 |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
215 local filters = { |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
216 passwd = function(tuple) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
217 password(tuple[2][1], tuple[2][2], tuple[3]); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
218 end; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
219 vcard = function(tuple) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
220 vcard(tuple[2][1], tuple[2][2], build_stanza(tuple[3])); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
221 end; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
222 roster = function(tuple) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
223 local node = tuple[3][1]; local host = tuple[3][2]; |
6280
ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
Kim Alvefur <zash@zash.se>
parents:
6024
diff
changeset
|
224 local contact = build_jid(tuple[4]); |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
225 local name = tuple[5]; local subscription = tuple[6]; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
226 local ask = tuple[7]; local groups = tuple[8]; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
227 if type(name) ~= type("") then name = nil; end |
1782
dd819e5bb0b8
ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents:
1726
diff
changeset
|
228 if ask == "none" then |
dd819e5bb0b8
ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents:
1726
diff
changeset
|
229 ask = nil; |
dd819e5bb0b8
ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents:
1726
diff
changeset
|
230 elseif ask == "out" then |
dd819e5bb0b8
ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents:
1726
diff
changeset
|
231 ask = "subscribe" |
dd819e5bb0b8
ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents:
1726
diff
changeset
|
232 elseif ask == "in" then |
753
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
233 roster_pending(node, host, contact); |
1782
dd819e5bb0b8
ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents:
1726
diff
changeset
|
234 ask = nil; |
dd819e5bb0b8
ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents:
1726
diff
changeset
|
235 elseif ask == "both" then |
dd819e5bb0b8
ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents:
1726
diff
changeset
|
236 roster_pending(node, host, contact); |
dd819e5bb0b8
ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents:
1726
diff
changeset
|
237 ask = "subscribe"; |
dd819e5bb0b8
ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents:
1726
diff
changeset
|
238 else error("Unknown ask type: "..ask); end |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
239 if subscription ~= "both" and subscription ~= "from" and subscription ~= "to" and subscription ~= "none" then error(subscription) end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
240 local item = {name = name, ask = ask, subscription = subscription, groups = {}}; |
1784
b2bfd3b93da6
ejabberd2prosody: Fixed a problem with null roster groups.
Waqas Hussain <waqas20@gmail.com>
parents:
1782
diff
changeset
|
241 for _, g in ipairs(groups) do |
b2bfd3b93da6
ejabberd2prosody: Fixed a problem with null roster groups.
Waqas Hussain <waqas20@gmail.com>
parents:
1782
diff
changeset
|
242 if type(g) == "string" then |
b2bfd3b93da6
ejabberd2prosody: Fixed a problem with null roster groups.
Waqas Hussain <waqas20@gmail.com>
parents:
1782
diff
changeset
|
243 item.groups[g] = true; |
b2bfd3b93da6
ejabberd2prosody: Fixed a problem with null roster groups.
Waqas Hussain <waqas20@gmail.com>
parents:
1782
diff
changeset
|
244 end |
b2bfd3b93da6
ejabberd2prosody: Fixed a problem with null roster groups.
Waqas Hussain <waqas20@gmail.com>
parents:
1782
diff
changeset
|
245 end |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
246 roster(node, host, contact, item); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
247 end; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
248 private_storage = function(tuple) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
249 private_storage(tuple[2][1], tuple[2][2], tuple[2][3], build_stanza(tuple[3])); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
250 end; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
251 offline_msg = function(tuple) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
252 offline_msg(tuple[2][1], tuple[2][2], build_time(tuple[3]), build_stanza(tuple[7])); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
253 end; |
4360
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
254 privacy = function(tuple) |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
255 privacy(tuple[2][1], tuple[2][2], tuple[3], tuple[4]); |
a993a4a2ea0a
ejabberd2prosody: Add support for privacy lists.
Waqas Hussain <waqas20@gmail.com>
parents:
2943
diff
changeset
|
256 end; |
5992
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
257 muc_room = function(tuple) |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
258 local properties = {}; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
259 for _,pair in ipairs(tuple[3]) do |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
260 if not(type(pair[2]) == "table" and #pair[2] == 0) then -- skip nil values |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
261 properties[pair[1]] = pair[2]; |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
262 end |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
263 end |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
264 muc_room(tuple[2][1], tuple[2][2], properties); |
72157e928c23
tools/ejabberd2prosody: Add support for importing MUC rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5697
diff
changeset
|
265 end; |
5999
e49c0c677c5d
tools/ejabberd2prosody: Disable generating a config, as the format it generates is completely out of date.
Waqas Hussain <waqas20@gmail.com>
parents:
5998
diff
changeset
|
266 --[=[config = function(tuple) |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
267 if tuple[2] == "hosts" then |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
268 local output = io.output(); io.output("prosody.cfg.lua"); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
269 io.write("-- Configuration imported from ejabberd --\n"); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
270 io.write([[Host "*" |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
271 modules_enabled = { |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
272 "saslauth"; -- Authentication for clients and servers. Recommended if you want to log in. |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
273 "legacyauth"; -- Legacy authentication. Only used by some old clients and bots. |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
274 "roster"; -- Allow users to have a roster. Recommended ;) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
275 "register"; -- Allow users to register on this server using a client |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
276 "tls"; -- Add support for secure TLS on c2s/s2s connections |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
277 "vcard"; -- Allow users to set vCards |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
278 "private"; -- Private XML storage (for room bookmarks, etc.) |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
279 "version"; -- Replies to server version requests |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
280 "dialback"; -- s2s dialback support |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
281 "uptime"; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
282 "disco"; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
283 "time"; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
284 "ping"; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
285 --"selftests"; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
286 }; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
287 ]]); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
288 for _, h in ipairs(tuple[3]) do |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
289 io.write("Host \"" .. h .. "\"\n"); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
290 end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
291 io.output(output); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
292 print("prosody.cfg.lua created"); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
293 end |
5999
e49c0c677c5d
tools/ejabberd2prosody: Disable generating a config, as the format it generates is completely out of date.
Waqas Hussain <waqas20@gmail.com>
parents:
5998
diff
changeset
|
294 end;]=] |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
295 }; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
296 |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
297 local arg = ...; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
298 local help = "/? -? ? /h -h /help -help --help"; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
299 if not arg or help:find(arg, 1, true) then |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
300 print([[ejabberd db dump importer for Prosody |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
301 |
5696
9fba74a28e0c
package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
5310
diff
changeset
|
302 Usage: ]]..my_name..[[ filename.txt |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
303 |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
304 The file can be generated from ejabberd using: |
5696
9fba74a28e0c
package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents:
5310
diff
changeset
|
305 sudo ejabberdctl dump filename.txt |
1567
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
306 |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
307 Note: The path of ejabberdctl depends on your ejabberd installation, and ejabberd needs to be running for ejabberdctl to work.]]); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
308 os.exit(1); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
309 end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
310 local count = 0; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
311 local t = {}; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
312 for item in erlparse.parseFile(arg) do |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
313 count = count + 1; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
314 local name = item[1]; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
315 t[name] = (t[name] or 0) + 1; |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
316 --print(count, serialize(item)); |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
317 if filters[name] then filters[name](item); end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
318 end |
e052a3bdb8b5
ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
319 --print(serialize(t)); |