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