Software /
code /
prosody
Annotate
tools/ejabberd2prosody.lua @ 910:27d909db4714
mod_component: Use net_activate_ports to start port listener based on config
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 22 Mar 2009 15:02:07 +0000 |
parent | 896:2c0b9e3c11c3 |
child | 1126:f6dc334d9836 |
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 |
896 | 2 -- Prosody IM v0.4 |
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 | 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 |
489
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
11 |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
12 require "erlparse"; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
13 |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
14 package.path = package.path ..";../?.lua"; |
547
265c4b8f0a8a
Changed the ejabberd import script to use util.serialization
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
15 local serialize = require "util.serialization".serialize; |
489
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
16 local st = require "util.stanza"; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
17 package.loaded["util.logger"] = {init = function() return function() end; end} |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
18 local dm = require "util.datamanager" |
643
8ff454831f7d
Moved directory auto-creation to datamanager
Waqas Hussain <waqas20@gmail.com>
parents:
628
diff
changeset
|
19 dm.set_data_path("data"); |
489
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
20 |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
21 function build_stanza(tuple, stanza) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
22 if tuple[1] == "xmlelement" then |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
23 local name = tuple[2]; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
24 local attr = {}; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
25 for _, a in ipairs(tuple[3]) do attr[a[1]] = a[2]; end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
26 local up; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
27 if stanza then stanza:tag(name, attr); up = true; else stanza = st.stanza(name, attr); end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
28 for _, a in ipairs(tuple[4]) do build_stanza(a, stanza); end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
29 if up then stanza:up(); else return stanza end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
30 elseif tuple[1] == "xmlcdata" then |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
31 stanza:text(tuple[2]); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
32 else |
547
265c4b8f0a8a
Changed the ejabberd import script to use util.serialization
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
33 error("unknown element type: "..serialize(tuple)); |
489
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
34 end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
35 end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
36 function build_time(tuple) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
37 local Megaseconds,Seconds,Microseconds = unpack(tuple); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
38 return Megaseconds * 1000000 + Seconds; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
39 end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
40 |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
41 function vcard(node, host, stanza) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
42 local ret, err = dm.store(node, host, "vcard", st.preserialize(stanza)); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
43 print("["..(err or "success").."] vCard: "..node.."@"..host); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
44 end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
45 function password(node, host, password) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
46 local ret, err = dm.store(node, host, "accounts", {password = password}); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
47 print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
48 end |
753
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
49 function roster(node, host, jid, item) |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
50 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
|
51 roster[jid] = item; |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
52 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
|
53 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
|
54 end |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
55 function roster_pending(node, host, jid) |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
56 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
|
57 roster.pending = roster.pending or {}; |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
58 roster.pending[jid] = true; |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
59 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
|
60 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
|
61 end |
489
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
62 function private_storage(node, host, xmlns, stanza) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
63 local private = dm.load(node, host, "private") or {}; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
64 private[xmlns] = st.preserialize(stanza); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
65 local ret, err = dm.store(node, host, "private", private); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
66 print("["..(err or "success").."] private: " ..node.."@"..host.." - "..xmlns); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
67 end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
68 function offline_msg(node, host, t, stanza) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
69 stanza.attr.stamp = os.date("!%Y-%m-%dT%H:%M:%SZ", t); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
70 stanza.attr.stamp_legacy = os.date("!%Y%m%dT%H:%M:%S", t); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
71 local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza)); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
72 print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t)); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
73 end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
74 |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
75 |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
76 local filters = { |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
77 passwd = function(tuple) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
78 password(tuple[2][1], tuple[2][2], tuple[3]); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
79 end; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
80 vcard = function(tuple) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
81 vcard(tuple[2][1], tuple[2][2], build_stanza(tuple[3])); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
82 end; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
83 roster = function(tuple) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
84 local node = tuple[3][1]; local host = tuple[3][2]; |
606
f8f1534a4e06
Make the ejabberd importer work with host-only roster items
Waqas Hussain <waqas20@gmail.com>
parents:
547
diff
changeset
|
85 local contact = (type(tuple[4][1]) == "table") and tuple[4][2] or tuple[4][1].."@"..tuple[4][2]; |
489
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
86 local name = tuple[5]; local subscription = tuple[6]; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
87 local ask = tuple[7]; local groups = tuple[8]; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
88 if type(name) ~= type("") then name = nil; end |
753
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
89 if ask == "none" then ask = nil; elseif ask == "out" then ask = "subscribe" elseif ask == "in" then |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
90 roster_pending(node, host, contact); |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
91 return; |
3a0f9cf38f99
tools/ejabberd2prosody: Support for pending-in roster items
Waqas Hussain <waqas20@gmail.com>
parents:
643
diff
changeset
|
92 else error(ask) end |
489
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
93 if subscription ~= "both" and subscription ~= "from" and subscription ~= "to" and subscription ~= "none" then error(subscription) end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
94 local item = {name = name, ask = ask, subscription = subscription, groups = {}}; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
95 for _, g in ipairs(groups) do item.groups[g] = true; end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
96 roster(node, host, contact, item); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
97 end; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
98 private_storage = function(tuple) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
99 private_storage(tuple[2][1], tuple[2][2], tuple[2][3], build_stanza(tuple[3])); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
100 end; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
101 offline_msg = function(tuple) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
102 offline_msg(tuple[2][1], tuple[2][2], build_time(tuple[3]), build_stanza(tuple[7])); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
103 end; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
104 config = function(tuple) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
105 if tuple[2] == "hosts" then |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
106 local output = io.output(); io.output("prosody.cfg.lua"); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
107 io.write("-- Configuration imported from ejabberd --\n"); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
108 io.write([[Host "*" |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
109 modules_enabled = { |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
110 "saslauth"; -- Authentication for clients and servers. Recommended if you want to log in. |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
111 "legacyauth"; -- Legacy authentication. Only used by some old clients and bots. |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
112 "roster"; -- Allow users to have a roster. Recommended ;) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
113 "register"; -- Allow users to register on this server using a client |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
114 "tls"; -- Add support for secure TLS on c2s/s2s connections |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
115 "vcard"; -- Allow users to set vCards |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
116 "private"; -- Private XML storage (for room bookmarks, etc.) |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
117 "version"; -- Replies to server version requests |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
118 "dialback"; -- s2s dialback support |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
119 "uptime"; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
120 "disco"; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
121 "time"; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
122 "ping"; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
123 --"selftests"; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
124 }; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
125 ]]); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
126 for _, h in ipairs(tuple[3]) do |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
127 io.write("Host \"" .. h .. "\"\n"); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
128 end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
129 io.output(output); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
130 print("prosody.cfg.lua created"); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
131 end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
132 end; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
133 }; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
134 |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
135 local arg = ...; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
136 local help = "/? -? ? /h -h /help -help --help"; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
137 if not arg or help:find(arg, 1, true) then |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
138 print([[ejabberd db dump importer for Prosody |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
139 |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
140 Usage: ejabberd2prosody.lua filename.txt |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
141 |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
142 The file can be generated from ejabberd using: |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
143 sudo ./bin/ejabberdctl dump filename.txt |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
144 |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
145 Note: The path of ejabberdctl depends on your ejabberd installation, and ejabberd needs to be running for ejabberdctl to work.]]); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
146 os.exit(1); |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
147 end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
148 local count = 0; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
149 local t = {}; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
150 for item in erlparse.parseFile(arg) do |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
151 count = count + 1; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
152 local name = item[1]; |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
153 t[name] = (t[name] or 0) + 1; |
547
265c4b8f0a8a
Changed the ejabberd import script to use util.serialization
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
154 --print(count, serialize(item)); |
489
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
155 if filters[name] then filters[name](item); end |
237cddb1a785
Fixed the ejabberd importer to work with the pipe sign "|" as a separator in erlang lists
Waqas Hussain <waqas20@gmail.com>
parents:
485
diff
changeset
|
156 end |
547
265c4b8f0a8a
Changed the ejabberd import script to use util.serialization
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
157 --print(serialize(t)); |