Annotate

tools/ejabberd2prosody.lua @ 484:af499a5ee32f

Make ejabberd2prosody.lua eecutable
author Matthew Wild <mwild1@gmail.com>
date Sat, 29 Nov 2008 19:14:54 +0000
parent 482:b86082df0bc0
child 485:f8456f0da769
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
484
af499a5ee32f Make ejabberd2prosody.lua eecutable
Matthew Wild <mwild1@gmail.com>
parents: 482
diff changeset
1 #!/usr/bin/env lua
482
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 require "erlparse";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 require "serialize";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 package.path = package.path ..";../?.lua";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 local st = require "util.stanza";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8 package.loaded["util.logger"] = {init = function() return function() end; end}
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9 local dm = require "util.datamanager"
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 local data_path = "data";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 dm.set_data_path(data_path);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local _mkdir = {}
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 function mkdir(path)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 path = path:gsub("/", "\\");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 --print("mkdir",path);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 local x = io.popen("mkdir "..path.." 2>&1"):read("*a");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 function encode(s) return s and (s:gsub("%W", function (c) return string.format("%%%x", c:byte()); end)); end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 function getpath(username, host, datastore, ext)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 ext = ext or "dat";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 if username then
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 return format("%s/%s/%s/%s.%s", data_path, encode(host), datastore, encode(username), ext);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 elseif host then
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 return format("%s/%s/%s.%s", data_path, encode(host), datastore, ext);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 else
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 return format("%s/%s.%s", data_path, datastore, ext);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 function mkdirs(host)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 if not _mkdir[host] then
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 local host_dir = string.format("%s/%s", data_path, encode(host));
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 mkdir(host_dir);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 mkdir(host_dir.."/accounts");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 mkdir(host_dir.."/vcard");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 mkdir(host_dir.."/roster");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 mkdir(host_dir.."/private");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 mkdir(host_dir.."/offline");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 _mkdir[host] = true;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 mkdir(data_path);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 function build_stanza(tuple, stanza)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 if tuple[1] == "xmlelement" then
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 local name = tuple[2];
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 local attr = {};
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 for _, a in ipairs(tuple[3]) do attr[a[1]] = a[2]; end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 local up;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 if stanza then stanza:tag(name, attr); up = true; else stanza = st.stanza(name, attr); end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 for _, a in ipairs(tuple[4]) do build_stanza(a, stanza); end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 if up then stanza:up(); else return stanza end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 elseif tuple[1] == "xmlcdata" then
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 stanza:text(tuple[2]);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 else
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 error("unknown element type: "..serialize.serialize(tuple));
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59 function build_time(tuple)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60 local Megaseconds,Seconds,Microseconds = unpack(tuple);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 return Megaseconds * 1000000 + Seconds;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 function vcard(node, host, stanza)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 mkdirs(host);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 local ret, err = dm.store(node, host, "vcard", st.preserialize(stanza));
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67 print("["..(err or "success").."] vCard: "..node.."@"..host);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 function password(node, host, password)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70 mkdirs(host);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
71 local ret, err = dm.store(node, host, "accounts", {password = password});
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
72 print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
73 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
74 function roster(node, host, jid, item)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
75 mkdirs(host);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 local roster = dm.load(node, host, "roster") or {};
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77 roster[jid] = item;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
78 local ret, err = dm.store(node, host, "roster", roster);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
79 print("["..(err or "success").."] roster: " ..node.."@"..host.." - "..jid);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
80 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
81 function private_storage(node, host, xmlns, stanza)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
82 mkdirs(host);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
83 local private = dm.load(node, host, "private") or {};
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
84 private[xmlns] = st.preserialize(stanza);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
85 local ret, err = dm.store(node, host, "private", private);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
86 print("["..(err or "success").."] private: " ..node.."@"..host.." - "..xmlns);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
87 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
88 function offline_msg(node, host, t, stanza)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
89 mkdirs(host);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
90 stanza.attr.stamp = os.date("!%Y-%m-%dT%H:%M:%SZ", t);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
91 stanza.attr.stamp_legacy = os.date("!%Y%m%dT%H:%M:%S", t);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
92 local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza));
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
93 print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t));
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
94 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
95
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
96
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
97 local filters = {
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
98 passwd = function(tuple)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
99 password(tuple[2][1], tuple[2][2], tuple[3]);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
100 end;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
101 vcard = function(tuple)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
102 vcard(tuple[2][1], tuple[2][2], build_stanza(tuple[3]));
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
103 end;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
104 roster = function(tuple)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
105 local node = tuple[3][1]; local host = tuple[3][2];
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
106 local contact = tuple[4][1].."@"..tuple[4][2];
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
107 local name = tuple[5]; local subscription = tuple[6];
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
108 local ask = tuple[7]; local groups = tuple[8];
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
109 if type(name) ~= type("") then name = nil; end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
110 if ask == "none" then ask = nil; elseif ask == "out" then ask = "subscribe" else error(ask) end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
111 if subscription ~= "both" and subscription ~= "from" and subscription ~= "to" and subscription ~= "none" then error(subscription) end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
112 local item = {name = name, ask = ask, subscription = subscription, groups = {}};
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
113 for _, g in ipairs(groups) do item.groups[g] = true; end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
114 roster(node, host, contact, item);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
115 end;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
116 private_storage = function(tuple)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
117 private_storage(tuple[2][1], tuple[2][2], tuple[2][3], build_stanza(tuple[3]));
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
118 end;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
119 offline_msg = function(tuple)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
120 offline_msg(tuple[2][1], tuple[2][2], build_time(tuple[3]), build_stanza(tuple[7]));
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
121 end;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
122 config = function(tuple)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
123 if tuple[2] == "hosts" then
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
124 local output = io.output(); io.output("prosody.cfg.lua");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
125 io.write("-- Configuration imported from ejabberd --\n");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
126 io.write([[Host "*"
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
127 modules_enabled = {
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
128 "saslauth"; -- Authentication for clients and servers. Recommended if you want to log in.
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
129 "legacyauth"; -- Legacy authentication. Only used by some old clients and bots.
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
130 "roster"; -- Allow users to have a roster. Recommended ;)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
131 "register"; -- Allow users to register on this server using a client
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
132 "tls"; -- Add support for secure TLS on c2s/s2s connections
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
133 "vcard"; -- Allow users to set vCards
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
134 "private"; -- Private XML storage (for room bookmarks, etc.)
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
135 "version"; -- Replies to server version requests
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
136 "dialback"; -- s2s dialback support
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
137 "uptime";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
138 "disco";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
139 "time";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
140 "ping";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
141 --"selftests";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
142 };
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
143 ]]);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
144 for _, h in ipairs(tuple[3]) do
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
145 io.write("Host \"" .. h .. "\"\n");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
146 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
147 io.output(output);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
148 print("prosody.cfg.lua created");
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
149 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
150 end;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
151 };
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
152
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
153 local arg = ...;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
154 local help = "/? -? ? /h -h /help -help --help";
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
155 if not arg or help:find(arg, 1, true) then
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
156 print([[ejabberd db dump importer for Prosody
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
157
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
158 Usage: ejabberd2prosody.lua filename.txt
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
159
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
160 The file can be generated from ejabberd using:
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
161 sudo ./bin/ejabberdctl dump filename.txt
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
162
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
163 Note: The path of ejabberdctl depends on your ejabberd installation, and ejabberd needs to be running for ejabberdctl to work.]]);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
164 os.exit(1);
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
165 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
166 local count = 0;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
167 local t = {};
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
168 for item in erlparse.parseFile(arg) do
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
169 count = count + 1;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
170 local name = item[1];
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
171 t[name] = (t[name] or 0) + 1;
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
172 --print(count, serialize.serialize(item));
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
173 if filters[name] then filters[name](item); end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
174 end
b86082df0bc0 ejabberd db dump importer for Prosody
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
175 --print(serialize.serialize(t));