Annotate

tools/ejabberd2prosody.lua @ 2515:50517948705c

prosodyctl: Don't load luarocks as util.dependencies now does this
author Matthew Wild <mwild1@gmail.com>
date Thu, 28 Jan 2010 18:11:24 +0000
parent 1784:b2bfd3b93da6
child 2693:e60494fbf23f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
760
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
3 -- Copyright (C) 2008-2009 Matthew Wild
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
4 -- Copyright (C) 2008-2009 Waqas Hussain
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 489
diff changeset
5 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 753
diff changeset
6 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 753
diff changeset
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
85518cb866dd ejabberd2prosody: More intelligent searching for erlparse library
Matthew Wild <mwild1@gmail.com>
parents: 1567
diff changeset
14 if arg[0]:match("^./") then
85518cb866dd ejabberd2prosody: More intelligent searching for erlparse library
Matthew Wild <mwild1@gmail.com>
parents: 1567
diff changeset
15 package.path = package.path .. ";"..arg[0]:gsub("/ejabberd2prosody.lua$", "/?.lua");
85518cb866dd ejabberd2prosody: More intelligent searching for erlparse library
Matthew Wild <mwild1@gmail.com>
parents: 1567
diff changeset
16 end
85518cb866dd ejabberd2prosody: More intelligent searching for erlparse library
Matthew Wild <mwild1@gmail.com>
parents: 1567
diff changeset
17
1567
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
18 require "erlparse";
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
19
547
265c4b8f0a8a Changed the ejabberd import script to use util.serialization
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
20 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
21 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
22 package.loaded["util.logger"] = {init = function() return function() end; end}
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
23 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
24 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
25
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
26 function build_stanza(tuple, stanza)
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
27 if tuple[1] == "xmlelement" then
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
28 local name = tuple[2];
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
29 local attr = {};
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
30 for _, a in ipairs(tuple[3]) do attr[a[1]] = a[2]; end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
31 local up;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
32 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
33 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
34 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
35 elseif tuple[1] == "xmlcdata" then
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
36 stanza:text(tuple[2]);
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
37 else
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
38 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
39 end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
40 end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
41 function build_time(tuple)
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
42 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
43 return Megaseconds * 1000000 + Seconds;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
44 end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
45
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
46 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
47 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
48 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
49 end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
50 function password(node, host, password)
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
51 local ret, err = dm.store(node, host, "accounts", {password = password});
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
52 print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password);
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
53 end
753
3a0f9cf38f99 tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents: 643
diff changeset
54 function roster(node, host, jid, item)
3a0f9cf38f99 tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents: 643
diff changeset
55 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
56 roster[jid] = item;
3a0f9cf38f99 tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents: 643
diff changeset
57 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
58 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
59 end
3a0f9cf38f99 tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents: 643
diff changeset
60 function roster_pending(node, host, jid)
3a0f9cf38f99 tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents: 643
diff changeset
61 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
62 roster.pending = roster.pending or {};
3a0f9cf38f99 tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents: 643
diff changeset
63 roster.pending[jid] = true;
3a0f9cf38f99 tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents: 643
diff changeset
64 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
65 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
66 end
1567
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
67 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
68 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
69 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
70 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
71 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
72 end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
73 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
74 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
75 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
76 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
77 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
78 end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
79
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
80
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
81 local filters = {
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
82 passwd = function(tuple)
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
83 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
84 end;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
85 vcard = function(tuple)
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
86 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
87 end;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
88 roster = function(tuple)
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
89 local node = tuple[3][1]; local host = tuple[3][2];
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
90 local contact = (type(tuple[4][1]) == "table") and tuple[4][2] or tuple[4][1].."@"..tuple[4][2];
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
91 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
92 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
93 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
94 if ask == "none" then
dd819e5bb0b8 ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents: 1726
diff changeset
95 ask = nil;
dd819e5bb0b8 ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents: 1726
diff changeset
96 elseif ask == "out" then
dd819e5bb0b8 ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents: 1726
diff changeset
97 ask = "subscribe"
dd819e5bb0b8 ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents: 1726
diff changeset
98 elseif ask == "in" then
753
3a0f9cf38f99 tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents: 643
diff changeset
99 roster_pending(node, host, contact);
1782
dd819e5bb0b8 ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents: 1726
diff changeset
100 ask = nil;
dd819e5bb0b8 ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents: 1726
diff changeset
101 elseif ask == "both" then
dd819e5bb0b8 ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents: 1726
diff changeset
102 roster_pending(node, host, contact);
dd819e5bb0b8 ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents: 1726
diff changeset
103 ask = "subscribe";
dd819e5bb0b8 ejabberd2prosody: Added support for ask='both' in subscriptions.
Waqas Hussain <waqas20@gmail.com>
parents: 1726
diff changeset
104 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
105 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
106 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
107 for _, g in ipairs(groups) do
b2bfd3b93da6 ejabberd2prosody: Fixed a problem with null roster groups.
Waqas Hussain <waqas20@gmail.com>
parents: 1782
diff changeset
108 if type(g) == "string" then
b2bfd3b93da6 ejabberd2prosody: Fixed a problem with null roster groups.
Waqas Hussain <waqas20@gmail.com>
parents: 1782
diff changeset
109 item.groups[g] = true;
b2bfd3b93da6 ejabberd2prosody: Fixed a problem with null roster groups.
Waqas Hussain <waqas20@gmail.com>
parents: 1782
diff changeset
110 end
b2bfd3b93da6 ejabberd2prosody: Fixed a problem with null roster groups.
Waqas Hussain <waqas20@gmail.com>
parents: 1782
diff changeset
111 end
1567
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
112 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
113 end;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
114 private_storage = function(tuple)
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
115 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
116 end;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
117 offline_msg = function(tuple)
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
118 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
119 end;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
120 config = function(tuple)
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
121 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
122 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
123 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
124 io.write([[Host "*"
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
125 modules_enabled = {
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
126 "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
127 "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
128 "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
129 "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
130 "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
131 "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
132 "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
133 "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
134 "dialback"; -- s2s dialback support
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
135 "uptime";
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
136 "disco";
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
137 "time";
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
138 "ping";
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
139 --"selftests";
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
140 };
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
141 ]]);
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
142 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
143 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
144 end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
145 io.output(output);
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
146 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
147 end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
148 end;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
149 };
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
150
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
151 local arg = ...;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
152 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
153 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
154 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
155
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
156 Usage: ejabberd2prosody.lua filename.txt
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
157
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
158 The file can be generated from ejabberd using:
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
159 sudo ./bin/ejabberdctl dump filename.txt
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
160
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
161 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
162 os.exit(1);
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
163 end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
164 local count = 0;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
165 local t = {};
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
166 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
167 count = count + 1;
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
168 local name = item[1];
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
169 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
170 --print(count, serialize(item));
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
171 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
172 end
e052a3bdb8b5 ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
173 --print(serialize(t));