Software /
code /
verse
Annotate
plugins/legacy.lua @ 250:a5ac643a7fd6
added local verse var to all plugins
author | mva <mva@mva.name> |
---|---|
date | Fri, 02 Dec 2011 11:02:02 +0600 |
parent | 181:c61ba3d1b39a |
child | 380:0891b4e27766 |
rev | line source |
---|---|
250 | 1 local verse = require "verse"; |
152
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local uuid = require "util.uuid".generate; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local xmlns_auth = "jabber:iq:auth"; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 function verse.plugins.legacy(stream) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 function handle_auth_form(result) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local query = result:get_child("query", xmlns_auth); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 if result.attr.type ~= "result" or not query then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local type, cond, text = result:get_error(); |
169
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
11 stream:debug("warn", "%s %s: %s", type, cond, text); |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
12 --stream:event("authentication-failure", { condition = cond }); |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
13 -- COMPAT continue anyways |
152
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local auth_data = { |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 username = stream.username; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 password = stream.password; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 resource = stream.resource or uuid(); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 digest = false, sequence = false, token = false; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 }; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local request = verse.iq({ to = stream.host, type = "set" }) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 :tag("query", { xmlns = xmlns_auth }); |
169
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
23 if #query > 0 then |
152
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 for tag in query:childtags() do |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local field = tag.name; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local value = auth_data[field]; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 if value then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 request:tag(field):text(auth_data[field]):up(); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 elseif value == nil then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local cond = "feature-not-implemented"; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 stream:event("authentication-failure", { condition = cond }); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 return false; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 end |
169
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
35 else -- COMPAT for servers not following XEP 78 |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
36 for field, value in pairs(auth_data) do |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
37 if value then |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
38 request:tag(field):text(value):up(); |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
39 end |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
40 end |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
41 end |
152
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 stream:send_iq(request, function (response) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 if response.attr.type == "result" then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 stream.resource = auth_data.resource; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 stream.jid = auth_data.username.."@"..stream.host.."/"..auth_data.resource; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 stream:event("authentication-success"); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 stream:event("bind-success", stream.jid); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 else |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 local type, cond, text = response:get_error(); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 stream:event("authentication-failure", { condition = cond }); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 end); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 function handle_opened(attr) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 if not attr.version then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 stream:send_iq(verse.iq({type="get"}) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 :tag("query", { xmlns = "jabber:iq:auth" }) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 :tag("username"):text(stream.username), |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 handle_auth_form); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 stream:hook("opened", handle_opened); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 end |