| 1 | local verse = require "verse"; |
| 2 | short_opts.i = "interactive"; |
| 3 | local split_jid = require "prosody.util.jid".split; |
| 4 | local timer = require "prosody.util.timer"; |
| 5 | |
| 6 | local xmlns_pie = "urn:xmpp:pie:0"; |
| 7 | local xmlns_nodes = { |
| 8 | { "query", "jabber:iq:roster" }, |
| 9 | { "query", "jabber:iq:privacy" }, |
| 10 | { "vCard", "vcard-temp" }, |
| 11 | } |
| 12 | local xmlns_private = "jabber:iq:private"; |
| 13 | local xmlns_private_nodes = { |
| 14 | { "storage", "storage:bookmarks" }, |
| 15 | } |
| 16 | |
| 17 | local function on_connect(conn) |
| 18 | local export = verse.stanza("server-data", { xmlns = xmlns_pie }) |
| 19 | :tag("host", { jid = conn.host }) |
| 20 | :tag("user", { name = conn.username, password = conn.password }); |
| 21 | local out = 0; |
| 22 | |
| 23 | for i = 1,#xmlns_nodes do |
| 24 | out = out + 1; |
| 25 | local node = xmlns_nodes[i]; |
| 26 | conn:debug("requesting %s*%s", node[2], node[1]); |
| 27 | conn:send_iq(verse.iq{type="get"} |
| 28 | :tag(node[1], { xmlns = node[2] }) |
| 29 | , function(stanza) |
| 30 | conn:debug("got %s*%s", node[2], node[1]); |
| 31 | local query = stanza:get_child(node[1], node[2]); |
| 32 | if query then |
| 33 | export:add_child(query); |
| 34 | end |
| 35 | out = out - 1; |
| 36 | end); |
| 37 | end |
| 38 | |
| 39 | for i = 1,#xmlns_private_nodes do |
| 40 | out = out + 1; |
| 41 | local node = xmlns_private_nodes[i]; |
| 42 | conn:debug("requesting private node %s*%s", node[2], node[1]); |
| 43 | conn:send_iq(verse.iq{type="get"} |
| 44 | :tag("query", { xmlns = xmlns_private }) |
| 45 | :tag(node[1], { xmlns = node[2] }) |
| 46 | , function(stanza) |
| 47 | conn:debug("got private %s*%s", node[2], node[1]); |
| 48 | local query = stanza:get_child("query", xmlns_private); |
| 49 | if query and #query > 0 then |
| 50 | export:add_child(query); |
| 51 | end |
| 52 | out = out - 1; |
| 53 | end); |
| 54 | end |
| 55 | |
| 56 | timer.add_task(1, function () |
| 57 | if out > 0 then |
| 58 | return 1 |
| 59 | end |
| 60 | print("<?xml version='1.0' encoding='UTF-8'?>"); |
| 61 | print(export); |
| 62 | conn:close(); |
| 63 | end) |
| 64 | end |
| 65 | |
| 66 | return function (opts, arg) |
| 67 | if opts.short_help then |
| 68 | print("Export your account"); |
| 69 | return; |
| 70 | end |
| 71 | if opts.help then |
| 72 | return 0; |
| 73 | end |
| 74 | clix_connect(opts, on_connect); |
| 75 | end |