1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# coding: utf-8
# This file is a part of VK4XMPP transport
# © simpleApps, 2014 — 2015.
from hashlib import sha1
def sendCaptcha(self):
logger.debug("VKLogin: sending message with captcha to %s" % self.source)
body = _("WARNING: VK sent captcha to you."
" Please, go to %s and enter text from image to chat."
" Example: !captcha my_captcha_key. Tnx") % self.engine.captcha["img"]
msg = xmpp.Message(self.source, body, "chat", frm=TransportID)
x = msg.setTag("x", namespace=xmpp.NS_OOB)
x.setTagData("url", self.engine.captcha["img"])
captcha = msg.setTag("captcha", namespace=xmpp.NS_CAPTCHA)
image = utils.getLinkData(self.engine.captcha["img"], False)
if image:
hash = sha1(image).hexdigest()
encoded = image.encode("base64")
form = utils.buildDataForm(type="form", fields = [
{"var": "FORM_TYPE", "value": xmpp.NS_CAPTCHA, "type": "hidden"},
{"var": "from", "value": TransportID, "type": "hidden"},
{"var": "ocr", "label": _("Enter shown text"),
"payload": [
xmpp.Node("required"),
xmpp.Node("media", {"xmlns": xmpp.NS_MEDIA},
[
xmpp.Node("uri", {"type": "image/jpg"},
["cid:sha1+%s@bob.xmpp.org" % hash]
)
])
]
}
])
captcha.addChild(node=form)
oob = msg.setTag("data", {"cid": "sha1+%s@bob.xmpp.org" % hash, "type": "image/jpg", "max-age": "0"}, xmpp.NS_URN_OOB)
oob.setData(encoded)
sender(Component, msg)
Presence = xmpp.protocol.Presence(self.source, show="xa", status=body, frm=TransportID)
sender(Component, Presence)
TransportFeatures.update({xmpp.NS_OOB,
xmpp.NS_MEDIA,
xmpp.NS_CAPTCHA,
xmpp.NS_URN_OOB})
registerHandler("evt04", sendCaptcha)
|