Fri, 03 Dec 2010 04:11:18 +0000
plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
152
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | local uuid = require "util.uuid".generate; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | local xmlns_auth = "jabber:iq:auth"; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | function verse.plugins.legacy(stream) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | function handle_auth_form(result) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | 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
|
8 | 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
|
9 | local type, cond, text = result:get_error(); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | stream:event("authentication-failure", { condition = cond }); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | local auth_data = { |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | username = stream.username; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | password = stream.password; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | resource = stream.resource or uuid(); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | digest = false, sequence = false, token = false; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | }; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | 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
|
19 | :tag("query", { xmlns = xmlns_auth }); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | for tag in query:childtags() do |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | local field = tag.name; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | local value = auth_data[field]; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | if value then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | 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
|
25 | elseif value == nil then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | local cond = "feature-not-implemented"; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | stream:event("authentication-failure", { condition = cond }); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | return false; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | stream:send_iq(request, function (response) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | if response.attr.type == "result" then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | stream.resource = auth_data.resource; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | 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
|
35 | stream:event("authentication-success"); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | stream:event("bind-success", stream.jid); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | else |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | local type, cond, text = response:get_error(); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | stream:event("authentication-failure", { condition = cond }); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | end); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 | function handle_opened(attr) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | if not attr.version then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 | stream:send_iq(verse.iq({type="get"}) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 | :tag("query", { xmlns = "jabber:iq:auth" }) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 | :tag("username"):text(stream.username), |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 | handle_auth_form); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 | |
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 | stream:hook("opened", handle_opened); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 | end |