Mercurial > libervia-backend
annotate src/plugins/plugin_misc_account.py @ 728:e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 10 Dec 2013 17:25:31 +0100 |
parents | 712e3782af12 |
children | 32bbabe809da |
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 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for parrot mode (experimental) |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
10 # (at your option) any later version. |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
15 # GNU Affero General Public License for more details. |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 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
|
21 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
|
22 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
|
23 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
|
24 from twisted.python.procutils import which |
644
53de6954e94e
plugin misc_account: fix for sending a failure message
souliane <souliane@mailoo.org>
parents:
641
diff
changeset
|
25 from twisted.python.failure import Failure |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
26 from email.mime.text import MIMEText |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
27 from twisted.mail.smtp import sendmail |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 PLUGIN_INFO = { |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
30 "name": "Account Plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
31 "import_name": "MISC-ACCOUNT", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
32 "type": "MISC", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
33 "protocols": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
34 "dependencies": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
35 "main": "MiscAccount", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
36 "handler": "no", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
37 "description": _(u"""SàT account creation""") |
569
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 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 #You need do adapt the following consts to your server |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
41 _REG_EMAIL_FROM = "NOREPLY@example.net" |
569
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_EMAIL_SERVER = "localhost" |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
43 _REG_ADMIN_EMAIL = "admin@example.net" |
569
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_SERVER = "localhost" |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
45 _NEW_ACCOUNT_DOMAIN = "example.net" |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 _NEW_ACCOUNT_RESOURCE = "libervia" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
47 _PROSODY_PATH = None # prosody path (where prosodyctl will be executed from), or None to automaticaly find it |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 _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
|
49 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 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
|
51 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
52 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 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
|
54 """ Try to register an account with prosody """ |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
55 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
56 def __init__(self, password, deferred=None): |
569
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.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
|
58 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
|
59 self.data = '' |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
60 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 def connectionMade(self): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
62 self.transport.write("%s\n%s" % ((self.password.encode('utf-8'), ) * 2)) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 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
|
64 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 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
|
66 self.data += data |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
67 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 def errReceived(self, data): |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
69 self.data += data |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
70 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 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
|
75 else: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 error(_(u"Can't register Prosody account (error code: %(code)d): %(message)s") % {'code': reason.value.exitCode, 'message': self.data}) |
644
53de6954e94e
plugin misc_account: fix for sending a failure message
souliane <souliane@mailoo.org>
parents:
641
diff
changeset
|
77 self.deferred.errback(Failure(u"INTERNAL")) |
569
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 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
80 class MiscAccount(object): |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 """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
|
82 #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
|
83 # 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
|
84 _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
|
85 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 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
|
87 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
|
88 self.host = host |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
89 host.bridge.addMethod("registerSatAccount", ".plugin", in_sign='sss', out_sign='', method=self._registerAccount, async=True) |
672
712e3782af12
plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents:
644
diff
changeset
|
90 host.bridge.addMethod("getNewAccountDomain", ".plugin", in_sign='', out_sign='s', method=self._getNewAccountDomain, async=False) |
569
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 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
|
92 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
|
93 if not paths: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
94 error(_("Can't find %s") % (_PROSODYCTL, )) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 else: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 self._prosody_path = dirname(paths[0]) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
97 info(_('Prosody path found: %s') % (self._prosody_path, )) |
569
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 def _registerAccount(self, email, password, profile): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
100 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 #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
|
103 #_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
|
104 _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
|
105 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
|
106 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
|
107 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
|
108 """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 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
|
110 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
|
111 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 if profile.lower() in RESERVED: |
644
53de6954e94e
plugin misc_account: fix for sending a failure message
souliane <souliane@mailoo.org>
parents:
641
diff
changeset
|
113 return defer.fail(Failure(u'CONFLICT')) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 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
|
116 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
|
117 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
|
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 def _profileRegistered(self, result, email, password, profile): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
120 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 #FIXME: values must be in a config file instead of hardcoded |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
122 self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE), |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
123 "Connection", profile_key=profile) |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
124 self.host.memory.setParam("Server", _NEW_ACCOUNT_SERVER, |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
125 "Connection", profile_key=profile) |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
126 self.host.memory.setParam("Password", password, |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
127 "Connection", profile_key=profile) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 #and the account |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
129 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 #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
|
131 # 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
|
132 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
|
133 prosody_reg = ProsodyRegisterProtocol(password, d) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
134 prosody_exe = join(self._prosody_path, _PROSODYCTL) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 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
|
136 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
137 d.addCallback(self._accountCreated, profile, email, password) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 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
|
139 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
140 def _accountCreated(self, result, login, email, password): |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
141 #time to send the email |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
142 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
143 _email_host = _REG_EMAIL_SERVER |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
144 _email_from = _REG_EMAIL_FROM |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
145 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
146 def email_ok(ignore): |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
147 print ("Account creation email sent to %s" % email) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
149 def email_ko(ignore): |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
150 #TODO: return error code to user |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
151 error("Failed to send email to %s" % email) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
152 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
153 body = (u"""Welcome to Libervia, a Salut à Toi project part |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
154 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
155 /!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\ |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
157 Here are your connection informations: |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
158 --- |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
159 login: %(login)s |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
160 password: %(password)s |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
162 Your Jabber ID (JID) is: %(jid)s |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
163 --- |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
165 SàT website: http://sat.goffi.org |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
166 follow SàT news: http://www.goffi.org |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
167 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
168 Any feedback welcome |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
169 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
170 Cheers |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
171 Goffi""" % {'login': login, 'password': password, 'jid': "%s@%s" % (login, _NEW_ACCOUNT_DOMAIN)}).encode('utf-8') |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
172 msg = MIMEText(body, 'plain', 'UTF-8') |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
173 msg['Subject'] = 'Libervia account created' |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
174 msg['From'] = _email_from |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
175 msg['To'] = email |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
177 d = sendmail(_email_host, _email_from, email, msg.as_string()) |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
178 d.addCallbacks(email_ok, email_ko) |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
179 #email to the administrator |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
181 body = (u"""New account created: %(login)s [%(email)s]""" % {'login': login, 'email': email}).encode('utf-8') |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
182 msg = MIMEText(body, 'plain', 'UTF-8') |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
183 msg['Subject'] = 'Libervia new account created' |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
184 msg['From'] = _email_from |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
185 msg['To'] = _REG_ADMIN_EMAIL |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
187 d = sendmail(_email_host, _email_from, _REG_ADMIN_EMAIL, msg.as_string()) |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
188 d.addCallbacks(email_ok, email_ko) |
672
712e3782af12
plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents:
644
diff
changeset
|
189 |
712e3782af12
plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents:
644
diff
changeset
|
190 def _getNewAccountDomain(self): |
712e3782af12
plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents:
644
diff
changeset
|
191 """@return: the domain that will be set to new account""" |
712e3782af12
plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents:
644
diff
changeset
|
192 return _NEW_ACCOUNT_DOMAIN |
712e3782af12
plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents:
644
diff
changeset
|
193 |