Mercurial > libervia-backend
annotate src/plugins/plugin_misc_account.py @ 569:06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 07 Jan 2013 01:03:49 +0100 |
parents | |
children | 1cb24325485c |
rev | line source |
---|---|
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 SAT plugin for parrot mode (experimental) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from logging import debug, info, warning, error |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.core import exceptions |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.internet import reactor, defer, protocol |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from os.path import join, dirname |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from twisted.python.procutils import which |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 PLUGIN_INFO = { |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 "name": "Account Plugin", |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 "import_name": "MISC-ACCOUNT", |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 "type": "MISC", |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 "protocols": [], |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 "dependencies": [], |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 "main": "MiscAccount", |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 "handler": "no", |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 "description": _(u"""SàT account creation""") |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 } |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 #You need do adapt the following consts to your server |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 _REG_EMAIL_FROM = "NOREPLY@libervia.org" |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 _REG_EMAIL_SERVER = "localhost" |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 _REG_ADMIN_EMAIL = "goffi@goffi.org" |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 _NEW_ACCOUNT_SERVER = "localhost" |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 _NEW_ACCOUNT_DOMAIN = "necton3.int" |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 _NEW_ACCOUNT_RESOURCE = "libervia" |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 _PROSODY_PATH = None #prosody path (where prosodyctl will be executed from), or None to automaticaly find it |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 _PROSODYCTL = "prosodyctl" |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 RESERVED = ['libervia'] |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 class ProsodyRegisterProtocol(protocol.ProcessProtocol): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 """ Try to register an account with prosody """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 def __init__(self, password, deferred = None): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 self.password = password |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 self.deferred = deferred |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 self.data = '' |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 def connectionMade(self): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 self.transport.write("%s\n%s" % ((self.password.encode('utf-8'),)*2)) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 self.transport.closeStdin() |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 def outReceived(self, data): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 self.data += data |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 def errReceived(self, data): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 self.err += data |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 def processEnded(self, reason): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 if (reason.value.exitCode == 0): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 info(_('Prosody registration success')) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 self.deferred.callback(None) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 else: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 error(_(u"Can't register Prosody account (error code: %(code)d): %(message)s") % {'code': reason.value.exitCode, 'message': self.data}) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 self.deferred.errback("INTERNAL") |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 class MiscAccount(): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 """Account plugin: create a SàT + Prosody account, used by Libervia""" |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 #XXX: This plugin is a Q&D one used for the demo. Something more generic (and not |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 # only focused on Prosody) is planed |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 _prosody_path = _PROSODY_PATH or '' |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 def __init__(self, host): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 info(_(u"Plugin Account initialization")) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 self.host = host |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 host.bridge.addMethod("registerSatAccount", ".plugin", in_sign='sss', out_sign='', method=self._registerAccount, async = True) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 if not self._prosody_path: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 paths = which(_PROSODYCTL) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 if not paths: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 error(_("Can't find %s") % (_PROSODYCTL,)) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 else: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 self._prosody_path = dirname(paths[0]) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 info(_('Prosody path found: %s') % (self._prosody_path,)) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 def _registerAccount(self, email, password, profile): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 #Password Generation |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 #_charset = [chr(i) for i in range(0x21,0x7F)] #XXX: this charset seems to have some issues with openfire |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 _charset = [chr(i) for i in range(0x30,0x3A) + range(0x41,0x5B) + range (0x61,0x7B)] |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 import random |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 random.seed() |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 password = ''.join([random.choice(_charset) for i in range(15)]) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 if not email or not password or not profile: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 raise exceptions.DataError |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 if profile.lower() in RESERVED: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 return defer.fail('CONFLICT') |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 d = self.host.memory.asyncCreateProfile(profile) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 d.addCallback(self._profileRegistered, email, password, profile) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 return d |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 def _profileRegistered(self, result, email, password, profile): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 #FIXME: values must be in a config file instead of hardcoded |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE), "Connection", profile) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 self.host.memory.setParam("Server", _NEW_ACCOUNT_SERVER, "Connection", profile) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 self.host.memory.setParam("Password", password, "Connection", profile) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 #and the account |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 #XXX: we use "prosodyctl adduser" because "register" doesn't check conflict |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 # and just change the password if the account already exists |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 d = defer.Deferred() |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 prosody_reg = ProsodyRegisterProtocol(password, d) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 prosody_exe = join (self._prosody_path, _PROSODYCTL) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 reactor.spawnProcess(prosody_reg, prosody_exe, [prosody_exe, 'adduser', "%s@%s" % (profile, _NEW_ACCOUNT_DOMAIN)], path=self._prosody_path) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 d.addCallback(self._accountCreated) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 return d |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 def _accountCreated(self, result): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 print "_accountCreated" |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 #action_id = self.sat_host.bridge.registerNewAccount(login, password, email, _NEW_ACCOUNT_DOMAIN, 5222) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 #self.sat_host.action_handler.waitForId(self._postAccountCreation, action_id, profile) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 ##time to send the email |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 #_email_host = _REG_EMAIL_SERVER |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 #_email_from = _REG_EMAIL_FROM |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 #def email_ok(ignore): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 # print ("Account creation email sent to %s" % email) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 #def email_ko(ignore): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 # #TODO: return error code to user |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 # error ("Failed to send email to %s" % email) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 # |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 #body = (u"""Welcome to Libervia, a Salut à Toi project part |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 # |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 #/!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 # |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 #Here are your connection informations: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 #login: %(login)s |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 #password: %(password)s |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 # |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 #Your Jabber ID (JID) is: %(jid)s |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 # |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 #Any feedback welcome |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 # |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 #Cheers |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 #Goffi""" % { 'login': login, 'password': password, 'jid':"%s@%s" % (login, _NEW_ACCOUNT_DOMAIN) }).encode('utf-8') |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 #msg = MIMEText(body, 'plain', 'UTF-8') |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 #msg['Subject'] = 'Libervia account created' |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 #msg['From'] = _email_from |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 #msg['To'] = email |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 #d = sendmail(_email_host, _email_from, email, msg.as_string()) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 #d.addCallbacks(email_ok, email_ko) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 ##email to the administrator |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 #body = (u"""New account created: %(login)s [%(email)s]""" % { 'login': login, 'email': email }).encode('utf-8') |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 #msg = MIMEText(body, 'plain', 'UTF-8') |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 #msg['Subject'] = 'Libervia new account created' |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 #msg['From'] = _email_from |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 #msg['To'] = _REG_ADMIN_EMAIL |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 #d = sendmail(_email_host, _email_from, _REG_ADMIN_EMAIL, msg.as_string()) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 #d.addCallbacks(email_ok, email_ko) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 #return "REGISTRATION" |