50 accounts[current_account or "default"][k] = v; |
50 accounts[current_account or "default"][k] = v; |
51 end |
51 end |
52 end |
52 end |
53 end |
53 end |
54 |
54 |
|
55 local function read_password() |
|
56 io.write("Password: ") |
|
57 local stty_ret = os.execute("stty -echo 2>/dev/null"); |
|
58 if stty_ret ~= 0 then |
|
59 io.write("\027[08m"); -- ANSI 'hidden' text attribute |
|
60 end |
|
61 local ok, pass = pcall(io.read, "*l"); |
|
62 if stty_ret == 0 then |
|
63 os.execute("stty sane"); |
|
64 else |
|
65 io.write("\027[00m"); |
|
66 end |
|
67 io.write("\n"); |
|
68 if ok then return pass; end |
|
69 end |
|
70 |
55 function clix_connect(opts, on_connect, plugins) |
71 function clix_connect(opts, on_connect, plugins) |
56 local account = accounts[opts.account or "default"]; |
72 local account = accounts[opts.account or "default"]; |
57 if not (account and account.jid) then |
73 if not (account and account.jid) then |
58 io.stderr:write("The specified account (", opts.account or "default", ") wasn't found in the config file\n"); |
74 io.stderr:write("The specified account (", opts.account or "default", ") wasn't found in the config file\n"); |
59 return nil; |
75 return nil; |
92 verse.quit(); |
108 verse.quit(); |
93 end); |
109 end); |
94 -- Optional config parameters |
110 -- Optional config parameters |
95 conn.connect_host = account.address; |
111 conn.connect_host = account.address; |
96 conn.connect_port = account.port; |
112 conn.connect_port = account.port; |
|
113 |
|
114 if not account.password and opts.interactive then |
|
115 account.password = read_password() |
|
116 end |
97 |
117 |
98 -- Connect! |
118 -- Connect! |
99 conn:connect_client(account.jid, opts.password or account.password); |
119 conn:connect_client(account.jid, account.password); |
100 |
120 |
101 -- COMPAT: Tigase discards stanzas sent at the same time as </stream:stream> |
121 -- COMPAT: Tigase discards stanzas sent at the same time as </stream:stream> |
102 local _real_close = conn.close; |
122 local _real_close = conn.close; |
103 function conn:close() |
123 function conn:close() |
104 conn:debug("Delaying close..."); |
124 conn:debug("Delaying close..."); |