annotate src/server/server.py @ 913:58f611481e6d

server, browser: removed deprecated methods which have been removed from backend, and associated code
author Goffi <goffi@goffi.org>
date Sun, 28 Aug 2016 19:25:52 +0200
parents e8b133b77aa4
children 0c0551967bdf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1 #!/usr/bin/python
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2 # -*- coding: utf-8 -*-
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
4 # Libervia: a Salut à Toi frontend
818
f8a7a046ff9c copyright update
Goffi <goffi@goffi.org>
parents: 817
diff changeset
5 # Copyright (C) 2011-2016 Jérôme Poisson <goffi@goffi.org>
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
10 # (at your option) any later version.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
15 # GNU Affero General Public License for more details.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
19
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
20 from twisted.application import service
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
21 from twisted.internet import reactor, defer
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
22 from twisted.web import server
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
23 from twisted.web import static
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
24 from twisted.web import resource as web_resource
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
25 from twisted.web import util as web_util
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
26 from twisted.web import http
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
27 from twisted.python.components import registerAdapter
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
28 from twisted.python.failure import Failure
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
29 from twisted.words.protocols.jabber import jid
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
30
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
31 from txjsonrpc.web import jsonrpc
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
32 from txjsonrpc import jsonrpclib
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
33
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
34 from sat.core.log import getLogger
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
35 log = getLogger(__name__)
555
db1b330c1eb1 server_side: set the connection attempt timeout to the bridge timeout (2 minutes)
souliane <souliane@mailoo.org>
parents: 554
diff changeset
36 from sat_frontends.bridge.DBus import DBusBridgeFrontend, BridgeExceptionNoService, const_TIMEOUT as BRIDGE_TIMEOUT
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
37 from sat.core.i18n import _, D_
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
38 from sat.core import exceptions
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
39 from sat.tools import utils
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
40
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
41 import re
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
42 import glob
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
43 import os.path
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
44 import sys
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
45 import tempfile
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
46 import shutil
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
47 import uuid
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
48 import urlparse
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
49 import urllib
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
50 from zope.interface import Interface, Attribute, implements
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
51 from httplib import HTTPS_PORT
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
52 import libervia
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
53
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
54 try:
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
55 import OpenSSL
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
56 from twisted.internet import ssl
813
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
57 except ImportError:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
58 ssl = None
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
59
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
60 from libervia.server.constants import Const as C
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
61 from libervia.server.blog import MicroBlog
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
62
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
63
514
530c88c1deee server_side: plugin refactoring:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
64 # following value are set from twisted.plugins.libervia_server initialise (see the comment there)
530c88c1deee server_side: plugin refactoring:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
65 DATA_DIR_DEFAULT = OPT_PARAMETERS_BOTH = OPT_PARAMETERS_CFG = coerceDataDir = None
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
66
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
67
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
68 class ISATSession(Interface):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
69 profile = Attribute("Sat profile")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
70 jid = Attribute("JID associated with the profile")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
71
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
72
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
73 class SATSession(object):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
74 implements(ISATSession)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
75
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
76 def __init__(self, session):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
77 self.profile = None
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
78 self.jid = None
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
79
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
80
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
81 class LiberviaSession(server.Session):
555
db1b330c1eb1 server_side: set the connection attempt timeout to the bridge timeout (2 minutes)
souliane <souliane@mailoo.org>
parents: 554
diff changeset
82 sessionTimeout = C.SESSION_TIMEOUT
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
83
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
84 def __init__(self, *args, **kwargs):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
85 self.__lock = False
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
86 server.Session.__init__(self, *args, **kwargs)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
87
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
88 def lock(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
89 """Prevent session from expiring"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
90 self.__lock = True
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
91 self._expireCall.reset(sys.maxint)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
92
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
93 def unlock(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
94 """Allow session to expire again, and touch it"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
95 self.__lock = False
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
96 self.touch()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
97
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
98 def touch(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
99 if not self.__lock:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
100 server.Session.touch(self)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
101
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
102
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
103 class ProtectedFile(static.File):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
104 """A static.File class which doens't show directory listing"""
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
105
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
106 def directoryListing(self):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
107 return web_resource.NoResource()
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
108
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
109
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
110 class LiberviaRootResource(ProtectedFile):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
111 """Specialized resource for Libervia root
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
112
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
113 handle redirections declared in sat.conf
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
114 """
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
115
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
116 def __init__(self, options, *args, **kwargs):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
117 """
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
118 @param options(dict): configuration options, same as Libervia.options
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
119 """
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
120 super(LiberviaRootResource, self).__init__(*args, **kwargs)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
121
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
122 ## redirections
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
123 self.redirections = {}
866
782ba105f5c7 reverted changeset f024fc5744d0 (there is already a default value)
Goffi <goffi@goffi.org>
parents: 865
diff changeset
124 if options['url_redirections_dict'] and not options['url_redirections_profile']:
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
125 raise ValueError(u"url_redirections_profile need to be filled if you want to use url_redirections_dict")
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
126
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
127 for old, new_data in options['url_redirections_dict'].iteritems():
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
128 # new_data can be a dictionary or a unicode url
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
129 if isinstance(new_data, dict):
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
130 # new_data dict must contain either "url" or "path" key (exclusive)
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
131 # if "path" is used, a file url is constructed with it
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
132 try:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
133 new = new_data['url']
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
134 except KeyError:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
135 try:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
136 path = new_data['path']
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
137 except KeyError:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
138 raise ValueError(u'if you use a dict for url_redirections data, it must contain the "url" or a "file" key')
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
139 else:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
140 new = 'file:{}'.format(urllib.quote(path))
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
141 else:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
142 if 'path' in new_data:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
143 raise ValueError(u'You can\'t have "url" and "path" keys at the same time in url_redirections')
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
144 else:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
145 new = new_data
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
146 new_data = {}
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
147
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
148 # some normalization
862
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
149 if not old.strip():
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
150 # root URL special case
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
151 old = ''
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
152 elif not old.startswith('/'):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
153 raise ValueError(u"redirected url must start with '/', got {}".format(old))
862
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
154 else:
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
155 old = self._normalizeURL(old)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
156 new_url = urlparse.urlsplit(new.encode('utf-8'))
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
157
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
158 # we handle the known URL schemes
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
159 if new_url.scheme == 'xmpp':
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
160 # XMPP URI
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
161 parsed_qs = urlparse.parse_qs(new_url.geturl())
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
162 try:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
163 item = parsed_qs['item'][0]
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
164 if not item:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
165 raise KeyError
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
166 except (IndexError, KeyError):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
167 raise NotImplementedError(u"only item for PubSub URI is handler for the moment for url_redirections_dict")
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
168 location = "/blog/{profile}/{item}".format(
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
169 profile=urllib.quote(options['url_redirections_profile'].encode('utf-8')),
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
170 item = urllib.quote_plus(item),
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
171 ).decode('utf-8')
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
172 request_data = self._getRequestData(location)
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
173
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
174 elif new_url.scheme in ('', 'http', 'https'):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
175 # direct redirection
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
176 if new_url.netloc:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
177 raise NotImplementedError(u"netloc ({netloc}) is not implemented yet for url_redirections_dict, it is not possible to redirect to an external website".format(
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
178 netloc = new_url.netloc))
867
12d0e7bd0dd1 server: fixed encoding issues on url redirection
Goffi <goffi@goffi.org>
parents: 866
diff changeset
179 location = urlparse.urlunsplit(('', '', new_url.path, new_url.query, new_url.fragment)).decode('utf-8')
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
180 request_data = self._getRequestData(location)
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
181
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
182 elif new_url.scheme in ('file'):
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
183 # file or directory
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
184 if new_url.netloc:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
185 raise NotImplementedError(u"netloc ({netloc}) is not implemented for url redirection to file system, it is not possible to redirect to an external host".format(
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
186 netloc = new_url.netloc))
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
187 path = urllib.unquote(new_url.path)
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
188 if not os.path.isabs(path):
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
189 raise ValueError(u'file redirection must have an absolute path: e.g. file:/path/to/my/file')
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
190 # for file redirection, we directly put child here
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
191 segments, dummy, last_segment = old.rpartition('/')
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
192 url_segments = segments.split('/') if segments else []
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
193 current = self
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
194 for segment in url_segments:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
195 resource = web_resource.NoResource()
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
196 current.putChild(segment, resource)
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
197 current = resource
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
198 resource_class = ProtectedFile if new_data.get('protected',True) else static.File
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
199 current.putChild(last_segment, resource_class(path))
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
200 log.debug(u"Added redirection from /{old} to file system path {path}".format(old=old.decode('utf-8'), path=path.decode('utf-8')))
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
201 continue # we don't want to use redirection system, so we continue here
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
202
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
203 else:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
204 raise NotImplementedError(u"{scheme}: scheme is not managed for url_redirections_dict".format(scheme=new_url.scheme))
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
205
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
206 self.redirections[old] = request_data
862
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
207 if not old:
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
208 log.info(u"Root URL redirected to {uri}".format(uri=request_data[1].decode('utf-8')))
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
209
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
210 # no need to keep url_redirections*, they will not be used anymore
866
782ba105f5c7 reverted changeset f024fc5744d0 (there is already a default value)
Goffi <goffi@goffi.org>
parents: 865
diff changeset
211 del options['url_redirections_dict']
782ba105f5c7 reverted changeset f024fc5744d0 (there is already a default value)
Goffi <goffi@goffi.org>
parents: 865
diff changeset
212 del options['url_redirections_profile']
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
213
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
214 # the default root URL, if not redirected
862
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
215 if not '' in self.redirections:
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
216 self.redirections[''] = self._getRequestData(C.LIBERVIA_MAIN_PAGE)
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
217
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
218 def _normalizeURL(self, url, lower=True):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
219 """Return URL normalized for self.redirections dict
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
220
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
221 @param url(unicode): URL to normalize
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
222 @param lower(bool): lower case of url if True
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
223 @return (str): normalized URL
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
224 """
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
225 if lower:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
226 url = url.lower()
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
227 return '/'.join((p for p in url.encode('utf-8').split('/') if p))
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
228
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
229 def _getRequestData(self, uri):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
230 """Return data needed to redirect request
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
231
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
232 @param url(unicode): destination url
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
233 @return (tuple(list[str], str, str, dict): tuple with
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
234 splitted path as in Request.postpath
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
235 uri as in Request.uri
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
236 path as in Request.path
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
237 args as in Request.args
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
238 """
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
239 uri = uri.encode('utf-8')
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
240 # XXX: we reuse code from twisted.web.http.py here
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
241 # as we need to have the same behaviour
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
242 x = uri.split(b'?', 1)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
243
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
244 if len(x) == 1:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
245 path = uri
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
246 args = {}
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
247 else:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
248 path, argstring = x
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
249 args = http.parse_qs(argstring, 1)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
250
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
251 # XXX: splitted path case must not be changed, as it may be significant
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
252 # (e.g. for blog items)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
253 return self._normalizeURL(path, lower=False).split('/'), uri, path, args
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
254
862
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
255 def _redirect(self, request, request_data):
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
256 """Redirect an URL by rewritting request
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
257
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
258 this is *NOT* a HTTP redirection, but equivalent to URL rewritting
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
259 @param request(web.http.request): original request
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
260 @param request_data(tuple): data returned by self._getRequestData
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
261 @return (web_resource.Resource): resource to use
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
262 """
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
263 path_list, uri, path, args = request_data
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
264 try:
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
265 request._redirected
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
266 except AttributeError:
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
267 pass
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
268 else:
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
269 log.warning(D_(u"recursive redirection, please fix this URL:\n{old} ==> {new}").format(
867
12d0e7bd0dd1 server: fixed encoding issues on url redirection
Goffi <goffi@goffi.org>
parents: 866
diff changeset
270 old=request.uri.decode('utf-8'),
12d0e7bd0dd1 server: fixed encoding issues on url redirection
Goffi <goffi@goffi.org>
parents: 866
diff changeset
271 new=uri.decode('utf-8'),
862
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
272 ))
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
273 return web_resource.NoResource()
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
274 log.debug(u"Redirecting URL {old} to {new}".format(
867
12d0e7bd0dd1 server: fixed encoding issues on url redirection
Goffi <goffi@goffi.org>
parents: 866
diff changeset
275 old=request.uri.decode('utf-8'),
12d0e7bd0dd1 server: fixed encoding issues on url redirection
Goffi <goffi@goffi.org>
parents: 866
diff changeset
276 new=uri.decode('utf-8'),
862
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
277 ))
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
278 # we change the request to reflect the new url
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
279 request._redirected = True # here to avoid recursive redirections
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
280 request.postpath = path_list[1:]
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
281 request.uri = uri
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
282 request.path = path
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
283 request.args = args
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
284 # and we start again to look for a child with the new url
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
285 return self.getChildWithDefault(path_list[0], request)
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
286
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
287 def getChildWithDefault(self, name, request):
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
288 # XXX: this method is overriden only for root url
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
289 # which is the only ones who need to be handled before other children
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
290 if name == '' and not request.postpath:
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
291 return self._redirect(request, self.redirections[''])
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
292 return super(LiberviaRootResource, self).getChildWithDefault(name, request)
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
293
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
294 def getChild(self, name, request):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
295 resource = super(LiberviaRootResource, self).getChild(name, request)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
296
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
297 if isinstance(resource, web_resource.NoResource):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
298 # if nothing was found, we try our luck with redirections
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
299 # XXX: we want redirections to happen only if everything else failed
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
300 current_url = '/'.join([name] + request.postpath).lower()
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
301 try:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
302 request_data = self.redirections[current_url]
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
303 except KeyError:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
304 # no redirection for this url
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
305 pass
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
306 else:
862
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
307 return self._redirect(request, request_data)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
308
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
309 return resource
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
310
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
311 def createSimilarFile(self, path):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
312 # XXX: this method need to be overriden to avoid recreating a LiberviaRootResource
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
313
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
314 f = LiberviaRootResource.__base__(path, self.defaultType, self.ignoredExts, self.registry)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
315 # refactoring by steps, here - constructor should almost certainly take these
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
316 f.processors = self.processors
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
317 f.indexNames = self.indexNames[:]
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
318 f.childNotFound = self.childNotFound
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
319 return f
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
320
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
321
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
322 class JSONRPCMethodManager(jsonrpc.JSONRPC):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
323
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
324 def __init__(self, sat_host):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
325 jsonrpc.JSONRPC.__init__(self)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
326 self.sat_host = sat_host
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
327
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
328 def asyncBridgeCall(self, method_name, *args, **kwargs):
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
329 """Call an asynchronous bridge method and return a deferred
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
330
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
331 @param method_name: name of the method as a unicode
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
332 @return: a deferred which trigger the result
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
333
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
334 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
335 d = defer.Deferred()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
336
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
337 def _callback(*args):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
338 if not args:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
339 d.callback(None)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
340 else:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
341 if len(args) != 1:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
342 Exception("Multiple return arguments not supported")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
343 d.callback(args[0])
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
344
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
345 def _errback(result):
465
33ec27ef4b6a server side: adapt passing the async failure from server to browser side, according to the new class BridgeException
souliane <souliane@mailoo.org>
parents: 464
diff changeset
346 d.errback(Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, result.classname)))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
347
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
348 kwargs["callback"] = _callback
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
349 kwargs["errback"] = _errback
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
350 getattr(self.sat_host.bridge, method_name)(*args, **kwargs)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
351 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
352
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
353
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
354 class MethodHandler(JSONRPCMethodManager):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
355
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
356 def __init__(self, sat_host):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
357 JSONRPCMethodManager.__init__(self, sat_host)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
358
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
359 def render(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
360 self.session = request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
361 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
362 if not profile:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
363 #user is not identified, we return a jsonrpc fault
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
364 parsed = jsonrpclib.loads(request.content.read())
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
365 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
366 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
367 return jsonrpc.JSONRPC.render(self, request)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
368
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
369 def jsonrpc_getVersion(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
370 """Return SàT version"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
371 try:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
372 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
373 except AttributeError:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
374 self._version_cache = self.sat_host.bridge.getVersion()
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
375 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
376
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
377 def jsonrpc_getLiberviaVersion(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
378 """Return Libervia version"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
379 return self.sat_host.full_version
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
380
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
381 def jsonrpc_disconnect(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
382 """Disconnect the profile"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
383 sat_session = ISATSession(self.session)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
384 profile = sat_session.profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
385 self.sat_host.bridge.disconnect(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
386
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
387 def jsonrpc_getContacts(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
388 """Return all passed args."""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
389 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
390 return self.sat_host.bridge.getContacts(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
391
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
392 def jsonrpc_addContact(self, entity, name, groups):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
393 """Subscribe to contact presence, and add it to the given groups"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
394 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
395 self.sat_host.bridge.addContact(entity, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
396 self.sat_host.bridge.updateContact(entity, name, groups, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
397
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
398 def jsonrpc_delContact(self, entity):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
399 """Remove contact from contacts list"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
400 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
401 self.sat_host.bridge.delContact(entity, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
402
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
403 def jsonrpc_updateContact(self, entity, name, groups):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
404 """Update contact's roster item"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
405 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
406 self.sat_host.bridge.updateContact(entity, name, groups, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
407
623
4f7550a083b4 server and browser sides: fixes bad call to "subscription" bridge method
souliane <souliane@mailoo.org>
parents: 613
diff changeset
408 def jsonrpc_subscription(self, sub_type, entity):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
409 """Confirm (or infirm) subscription,
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
410 and setup user roster in case of subscription"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
411 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
412 self.sat_host.bridge.subscription(sub_type, entity, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
413
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
414 def jsonrpc_getWaitingSub(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
415 """Return list of room already joined by user"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
416 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
417 return self.sat_host.bridge.getWaitingSub(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
418
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
419 def jsonrpc_setStatus(self, presence, status):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
420 """Change the presence and/or status
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
421 @param presence: value from ("", "chat", "away", "dnd", "xa")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
422 @param status: any string to describe your status
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
423 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
424 profile = ISATSession(self.session).profile
413
7a8991cda2fa browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents: 408
diff changeset
425 self.sat_host.bridge.setPresence('', presence, {'': status}, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
426
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
427 def jsonrpc_messageSend(self, to_jid, msg, subject, type_, extra={}):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
428 """send message"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
429 profile = ISATSession(self.session).profile
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
430 return self.asyncBridgeCall("messageSend", to_jid, msg, subject, type_, extra, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
431
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
432 ## PubSub ##
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
433
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
434 def jsonrpc_psDeleteNode(self, service, node):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
435 """Delete a whole node
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
436
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
437 @param service (unicode): service jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
438 @param node (unicode): node to delete
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
439 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
440 profile = ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
441 return self.asyncBridgeCall("psDeleteNode", service, node, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
442
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
443 # def jsonrpc_psRetractItem(self, service, node, item, notify):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
444 # """Delete a whole node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
445
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
446 # @param service (unicode): service jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
447 # @param node (unicode): node to delete
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
448 # @param items (iterable): id of item to retract
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
449 # @param notify (bool): True if notification is required
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
450 # """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
451 # profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
452 # return self.asyncBridgeCall("psRetractItem", service, node, item, notify, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
453
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
454 # def jsonrpc_psRetractItems(self, service, node, items, notify):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
455 # """Delete a whole node
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
456
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
457 # @param service (unicode): service jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
458 # @param node (unicode): node to delete
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
459 # @param items (iterable): ids of items to retract
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
460 # @param notify (bool): True if notification is required
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
461 # """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
462 # profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
463 # return self.asyncBridgeCall("psRetractItems", service, node, items, notify, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
464
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
465 ## microblogging ##
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
466
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
467 def jsonrpc_mbSend(self, service, node, mb_data):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
468 """Send microblog data
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
469
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
470 @param service (unicode): service jid or empty string to use profile's microblog
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
471 @param node (unicode): publishing node, or empty string to use microblog node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
472 @param mb_data(dict): microblog data
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
473 @return: a deferred
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
474 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
475 profile = ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
476 return self.asyncBridgeCall("mbSend", service, node, mb_data, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
477
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
478 def jsonrpc_mbRetract(self, service, node, items):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
479 """Delete a whole node
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
480
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
481 @param service (unicode): service jid, empty string for PEP
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
482 @param node (unicode): node to delete, empty string for default node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
483 @param items (iterable): ids of items to retract
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
484 """
389
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
485 profile = ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
486 return self.asyncBridgeCall("mbRetract", service, node, items, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
487
724
994be887e843 browser and server sides: bridge method mbGetLast has been renamed to mbGet and takes a new parameter "item_ids"
souliane <souliane@mailoo.org>
parents: 718
diff changeset
488 def jsonrpc_mbGet(self, service_jid, node, max_items, item_ids, extra):
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
489 """Get last microblogs from publisher_jid
389
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
490
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
491 @param service_jid (unicode): pubsub service, usually publisher jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
492 @param node(unicode): mblogs node, or empty string to get the defaut one
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
493 @param max_items (int): maximum number of item to get or C.NO_LIMIT to get everything
724
994be887e843 browser and server sides: bridge method mbGetLast has been renamed to mbGet and takes a new parameter "item_ids"
souliane <souliane@mailoo.org>
parents: 718
diff changeset
494 @param item_ids (list[unicode]): list of item IDs
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
495 @param rsm (dict): TODO
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
496 @return: a deferred couple with the list of items and metadatas.
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
497 """
389
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
498 profile = ISATSession(self.session).profile
724
994be887e843 browser and server sides: bridge method mbGetLast has been renamed to mbGet and takes a new parameter "item_ids"
souliane <souliane@mailoo.org>
parents: 718
diff changeset
499 return self.asyncBridgeCall("mbGet", service_jid, node, max_items, item_ids, extra, profile)
389
2d782349b88a server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents: 381
diff changeset
500
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
501 def jsonrpc_mbGetFromMany(self, publishers_type, publishers, max_items, extra):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
502 """Get many blog nodes at once
651
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
503
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
504 @param publishers_type (unicode): one of "ALL", "GROUP", "JID"
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
505 @param publishers (tuple(unicode)): tuple of publishers (empty list for all, list of groups or list of jids)
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
506 @param max_items (int): maximum number of item to get or C.NO_LIMIT to get everything
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
507 @param extra (dict): TODO
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
508 @return (str): RT Deferred session id
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
509 """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
510 profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
511 return self.sat_host.bridge.mbGetFromMany(publishers_type, publishers, max_items, extra, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
512
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
513 def jsonrpc_mbGetFromManyRTResult(self, rt_session):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
514 """Get results from RealTime mbGetFromMany session
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
515
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
516 @param rt_session (str): RT Deferred session id
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
517 """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
518 profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
519 return self.asyncBridgeCall("mbGetFromManyRTResult", rt_session, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
520
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
521 def jsonrpc_mbGetFromManyWithComments(self, publishers_type, publishers, max_items, max_comments, rsm_dict, rsm_comments_dict):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
522 """Helper method to get the microblogs and their comments in one shot
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
523
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
524 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
525 @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
526 @param max_items (int): optional limit on the number of retrieved items.
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
527 @param max_comments (int): maximum number of comments to retrieve
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
528 @param rsm_dict (dict): RSM data for initial items only
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
529 @param rsm_comments_dict (dict): RSM data for comments only
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
530 @param profile_key: profile key
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
531 @return (str): RT Deferred session id
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
532 """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
533 profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
534 return self.sat_host.bridge.mbGetFromManyWithComments(publishers_type, publishers, max_items, max_comments, rsm_dict, rsm_comments_dict, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
535
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
536 def jsonrpc_mbGetFromManyWithCommentsRTResult(self, rt_session):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
537 """Get results from RealTime mbGetFromManyWithComments session
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
538
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
539 @param rt_session (str): RT Deferred session id
651
2df91d0308ac browser_side, server_side: MicroblogPanel.onGroupDrop and bridge method getMassiveLastMBlogs now only accepts the publishers as a set of unicode (no more None value or single unicode).
souliane <souliane@mailoo.org>
parents: 623
diff changeset
540 """
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
541 profile = ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
542 return self.asyncBridgeCall("mbGetFromManyWithCommentsRTResult", rt_session, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
543
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
544
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
545 # def jsonrpc_sendMblog(self, type_, dest, text, extra={}):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
546 # """ Send microblog message
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
547 # @param type_ (unicode): one of "PUBLIC", "GROUP"
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
548 # @param dest (tuple(unicode)): recipient groups (ignored for "PUBLIC")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
549 # @param text (unicode): microblog's text
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
550 # """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
551 # profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
552 # extra['allow_comments'] = 'True'
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
553
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
554 # if not type_: # auto-detect
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
555 # type_ = "PUBLIC" if dest == [] else "GROUP"
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
556
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
557 # if type_ in ("PUBLIC", "GROUP") and text:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
558 # if type_ == "PUBLIC":
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
559 # #This text if for the public microblog
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
560 # log.debug("sending public blog")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
561 # return self.sat_host.bridge.sendGroupBlog("PUBLIC", (), text, extra, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
562 # else:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
563 # log.debug("sending group blog")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
564 # dest = dest if isinstance(dest, list) else [dest]
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
565 # return self.sat_host.bridge.sendGroupBlog("GROUP", dest, text, extra, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
566 # else:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
567 # raise Exception("Invalid data")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
568
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
569 # def jsonrpc_deleteMblog(self, pub_data, comments):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
570 # """Delete a microblog node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
571 # @param pub_data: a tuple (service, comment node identifier, item identifier)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
572 # @param comments: comments node identifier (for main item) or False
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
573 # """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
574 # profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
575 # return self.sat_host.bridge.deleteGroupBlog(pub_data, comments if comments else '', profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
576
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
577 # def jsonrpc_updateMblog(self, pub_data, comments, message, extra={}):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
578 # """Modify a microblog node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
579 # @param pub_data: a tuple (service, comment node identifier, item identifier)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
580 # @param comments: comments node identifier (for main item) or False
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
581 # @param message: new message
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
582 # @param extra: dict which option name as key, which can be:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
583 # - allow_comments: True to accept an other level of comments, False else (default: False)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
584 # - rich: if present, contain rich text in currently selected syntax
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
585 # """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
586 # profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
587 # if comments:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
588 # extra['allow_comments'] = 'True'
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
589 # return self.sat_host.bridge.updateGroupBlog(pub_data, comments if comments else '', message, extra, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
590
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
591 # def jsonrpc_sendMblogComment(self, node, text, extra={}):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
592 # """ Send microblog message
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
593 # @param node: url of the comments node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
594 # @param text: comment
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
595 # """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
596 # profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
597 # if node and text:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
598 # return self.sat_host.bridge.sendGroupBlogComment(node, text, extra, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
599 # else:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
600 # raise Exception("Invalid data")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
601
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
602 # def jsonrpc_getMblogs(self, publisher_jid, item_ids, max_items=C.RSM_MAX_ITEMS):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
603 # """Get specified microblogs posted by a contact
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
604 # @param publisher_jid: jid of the publisher
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
605 # @param item_ids: list of microblogs items IDs
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
606 # @return list of microblog data (dict)"""
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
607 # profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
608 # d = self.asyncBridgeCall("getGroupBlogs", publisher_jid, item_ids, {'max_': unicode(max_items)}, False, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
609 # return d
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
610
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
611 # def jsonrpc_getMblogsWithComments(self, publisher_jid, item_ids, max_comments=C.RSM_MAX_COMMENTS):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
612 # """Get specified microblogs posted by a contact and their comments
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
613 # @param publisher_jid: jid of the publisher
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
614 # @param item_ids: list of microblogs items IDs
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
615 # @return list of couple (microblog data, list of microblog data)"""
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
616 # profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
617 # d = self.asyncBridgeCall("getGroupBlogsWithComments", publisher_jid, item_ids, {}, max_comments, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
618 # return d
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
619
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
620 # def jsonrpc_getMassiveMblogs(self, publishers_type, publishers, rsm=None):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
621 # """Get lasts microblogs posted by several contacts at once
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
622
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
623 # @param publishers_type (unicode): one of "ALL", "GROUP", "JID"
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
624 # @param publishers (tuple(unicode)): tuple of publishers (empty list for all, list of groups or list of jids)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
625 # @param rsm (dict): TODO
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
626 # @return: dict{unicode: list[dict])
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
627 # key: publisher's jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
628 # value: list of microblog data (dict)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
629 # """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
630 # profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
631 # if rsm is None:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
632 # rsm = {'max_': unicode(C.RSM_MAX_ITEMS)}
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
633 # d = self.asyncBridgeCall("getMassiveGroupBlogs", publishers_type, publishers, rsm, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
634 # self.sat_host.bridge.massiveSubscribeGroupBlogs(publishers_type, publishers, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
635 # return d
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
636
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
637 # def jsonrpc_getMblogComments(self, service, node, rsm=None):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
638 # """Get all comments of given node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
639 # @param service: jid of the service hosting the node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
640 # @param node: comments node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
641 # """
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
642 # profile = ISATSession(self.session).profile
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
643 # if rsm is None:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
644 # rsm = {'max_': unicode(C.RSM_MAX_COMMENTS)}
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
645 # d = self.asyncBridgeCall("getGroupBlogComments", service, node, rsm, profile)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
646 # return d
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
647
427
b5b440e6ea16 server + browser side, getPresenceStatuses has been renamed
Goffi <goffi@goffi.org>
parents: 421
diff changeset
648 def jsonrpc_getPresenceStatuses(self):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
649 """Get Presence information for connected contacts"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
650 profile = ISATSession(self.session).profile
427
b5b440e6ea16 server + browser side, getPresenceStatuses has been renamed
Goffi <goffi@goffi.org>
parents: 421
diff changeset
651 return self.sat_host.bridge.getPresenceStatuses(profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
652
566
8a607044ecfa server_side: adapt to the new signatures of bridge method getHistory
souliane <souliane@mailoo.org>
parents: 555
diff changeset
653 def jsonrpc_getHistory(self, from_jid, to_jid, size, between, search=''):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
654 """Return history for the from_jid/to_jid couple"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
655 sat_session = ISATSession(self.session)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
656 profile = sat_session.profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
657 sat_jid = sat_session.jid
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
658 if not sat_jid:
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
659 # we keep a session cache for jid to avoir jid spoofing
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
660 sat_jid = sat_session.jid = jid.JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile))
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
661 if jid.JID(from_jid).userhost() != sat_jid.userhost() and jid.JID(to_jid).userhost() != sat_jid.userhost():
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
662 log.error(u"Trying to get history from a different jid (given (browser): {}, real (backend): {}), maybe a hack attempt ?".format(from_jid, sat_jid))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
663 return {}
566
8a607044ecfa server_side: adapt to the new signatures of bridge method getHistory
souliane <souliane@mailoo.org>
parents: 555
diff changeset
664 d = self.asyncBridgeCall("getHistory", from_jid, to_jid, size, between, search, profile)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
665
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
666 def show(result_dbus):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
667 result = []
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
668 for line in result_dbus:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
669 #XXX: we have to do this stupid thing because Python D-Bus use its own types instead of standard types
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
670 # and txJsonRPC doesn't accept D-Bus types, resulting in a empty query
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
671 timestamp, from_jid, to_jid, message, mess_type, extra = line
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
672 result.append((float(timestamp), unicode(from_jid), unicode(to_jid), unicode(message), unicode(mess_type), dict(extra)))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
673 return result
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
674 d.addCallback(show)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
675 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
676
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
677 def jsonrpc_mucJoin(self, room_jid, nick):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
678 """Join a Multi-User Chat room
689
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
679
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
680 @param room_jid (unicode): room JID or empty string to generate a unique name
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
681 @param nick (unicode): user nick
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
682 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
683 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
684 d = self.asyncBridgeCall("joinMUC", room_jid, nick, {}, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
685 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
686
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
687 def jsonrpc_inviteMUC(self, contact_jid, room_jid):
689
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
688 """Invite a user to a Multi-User Chat room
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
689
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
690 @param contact_jid (unicode): contact to invite
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
691 @param room_jid (unicode): room JID or empty string to generate a unique name
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
692 """
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
693 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
694 room_id = room_jid.split("@")[0]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
695 service = room_jid.split("@")[1]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
696 self.sat_host.bridge.inviteMUC(contact_jid, service, room_id, {}, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
697
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
698 def jsonrpc_mucLeave(self, room_jid):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
699 """Quit a Multi-User Chat room"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
700 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
701 try:
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
702 room_jid = jid.JID(room_jid)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
703 except:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
704 log.warning('Invalid room jid')
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
705 return
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
706 self.sat_host.bridge.mucLeave(room_jid.userhost(), profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
707
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
708 def jsonrpc_mucGetRoomsJoined(self):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
709 """Return list of room already joined by user"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
710 profile = ISATSession(self.session).profile
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
711 return self.sat_host.bridge.mucGetRoomsJoined(profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
712
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
713 def jsonrpc_mucGetDefaultService(self):
692
7a9c7b9f6a28 browser_side: use host.default_muc instead of C.DEFAULT_MUC
souliane <souliane@mailoo.org>
parents: 689
diff changeset
714 """@return: the default MUC"""
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
715 d = self.asyncBridgeCall("mucGetDefaultService")
692
7a9c7b9f6a28 browser_side: use host.default_muc instead of C.DEFAULT_MUC
souliane <souliane@mailoo.org>
parents: 689
diff changeset
716 return d
7a9c7b9f6a28 browser_side: use host.default_muc instead of C.DEFAULT_MUC
souliane <souliane@mailoo.org>
parents: 689
diff changeset
717
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
718 def jsonrpc_launchTarotGame(self, other_players, room_jid=""):
689
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
719 """Create a room, invite the other players and start a Tarot game.
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
720
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
721 @param other_players (list[unicode]): JIDs of the players to play with
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
722 @param room_jid (unicode): room JID or empty string to generate a unique name
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
723 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
724 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
725 self.sat_host.bridge.tarotGameLaunch(other_players, room_jid, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
726
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
727 def jsonrpc_getTarotCardsPaths(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
728 """Give the path of all the tarot cards"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
729 _join = os.path.join
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
730 _media_dir = _join(self.sat_host.media_dir, '')
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
731 return map(lambda x: _join(C.MEDIA_DIR, x[len(_media_dir):]), glob.glob(_join(_media_dir, C.CARDS_DIR, '*_*.png')))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
732
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
733 def jsonrpc_tarotGameReady(self, player, referee):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
734 """Tell to the server that we are ready to start the game"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
735 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
736 self.sat_host.bridge.tarotGameReady(player, referee, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
737
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
738 def jsonrpc_tarotGamePlayCards(self, player_nick, referee, cards):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
739 """Tell to the server the cards we want to put on the table"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
740 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
741 self.sat_host.bridge.tarotGamePlayCards(player_nick, referee, cards, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
742
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
743 def jsonrpc_launchRadioCollective(self, invited, room_jid=""):
689
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
744 """Create a room, invite people, and start a radio collective.
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
745
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
746 @param invited (list[unicode]): JIDs of the contacts to play with
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
747 @param room_jid (unicode): room JID or empty string to generate a unique name
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
748 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
749 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
750 self.sat_host.bridge.radiocolLaunch(invited, room_jid, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
751
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
752 def jsonrpc_getEntitiesData(self, jids, keys):
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
753 """Get cached data for several entities at once
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
754
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
755 @param jids: list jids from who we wants data, or empty list for all jids in cache
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
756 @param keys: name of data we want (list)
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
757 @return: requested data"""
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
758 if not C.ALLOWED_ENTITY_DATA.issuperset(keys):
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
759 raise exceptions.PermissionError("Trying to access unallowed data (hack attempt ?)")
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
760 profile = ISATSession(self.session).profile
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
761 try:
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
762 return self.sat_host.bridge.getEntitiesData(jids, keys, profile)
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
763 except Exception as e:
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
764 raise Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(e)))
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
765
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
766 def jsonrpc_getEntityData(self, jid, keys):
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
767 """Get cached data for an entity
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
768
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
769 @param jid: jid of contact from who we want data
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
770 @param keys: name of data we want (list)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
771 @return: requested data"""
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
772 if not C.ALLOWED_ENTITY_DATA.issuperset(keys):
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
773 raise exceptions.PermissionError("Trying to access unallowed data (hack attempt ?)")
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
774 profile = ISATSession(self.session).profile
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
775 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
776 return self.sat_host.bridge.getEntityData(jid, keys, profile)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
777 except Exception as e:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
778 raise Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(e)))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
779
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
780 def jsonrpc_getCard(self, jid_):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
781 """Get VCard for entiry
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
782 @param jid_: jid of contact from who we want data
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
783 @return: id to retrieve the profile"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
784 profile = ISATSession(self.session).profile
605
917e271975d9 server + browser side: implementation of new getEntitiesData bridge method + added a security check: only a white list of entities can be gotten
Goffi <goffi@goffi.org>
parents: 589
diff changeset
785 return self.sat_host.bridge.getCard(jid_, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
786
391
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
787 def jsonrpc_getAccountDialogUI(self):
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
788 """Get the dialog for managing user account
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
789 @return: XML string of the XMLUI"""
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
790 profile = ISATSession(self.session).profile
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
791 return self.sat_host.bridge.getAccountDialogUI(profile)
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
792
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
793 def jsonrpc_getParamsUI(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
794 """Return the parameters XML for profile"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
795 profile = ISATSession(self.session).profile
745
ad733b670cc3 server side: fixed params, and removed self.authorized_params as authorisation is handled by the backend
Goffi <goffi@goffi.org>
parents: 744
diff changeset
796 return self.asyncBridgeCall("getParamsUI", C.SECURITY_LIMIT, C.APP_NAME, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
797
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
798 def jsonrpc_asyncGetParamA(self, param, category, attribute="value"):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
799 """Return the parameter value for profile"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
800 profile = ISATSession(self.session).profile
746
25984ca4aef2 server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents: 745
diff changeset
801 if category == "Connection":
25984ca4aef2 server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents: 745
diff changeset
802 # we need to manage the followings params here, else SECURITY_LIMIT would block them
25984ca4aef2 server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents: 745
diff changeset
803 if param == "JabberID":
25984ca4aef2 server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents: 745
diff changeset
804 return self.asyncBridgeCall("asyncGetParamA", param, category, attribute, profile_key=profile)
25984ca4aef2 server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents: 745
diff changeset
805 elif param == "autoconnect":
25984ca4aef2 server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents: 745
diff changeset
806 return defer.succeed(C.BOOL_TRUE)
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 427
diff changeset
807 d = self.asyncBridgeCall("asyncGetParamA", param, category, attribute, C.SECURITY_LIMIT, profile_key=profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
808 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
809
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
810 def jsonrpc_setParam(self, name, value, category):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
811 profile = ISATSession(self.session).profile
745
ad733b670cc3 server side: fixed params, and removed self.authorized_params as authorisation is handled by the backend
Goffi <goffi@goffi.org>
parents: 744
diff changeset
812 return self.sat_host.bridge.setParam(name, value, category, C.SECURITY_LIMIT, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
813
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
814 def jsonrpc_launchAction(self, callback_id, data):
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
815 #FIXME: any action can be launched, this can be a huge security issue if callback_id can be guessed
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
816 # a security system with authorised callback_id must be implemented, similar to the one for authorised params
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
817 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
818 d = self.asyncBridgeCall("launchAction", callback_id, data, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
819 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
820
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
821 def jsonrpc_chatStateComposing(self, to_jid_s):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
822 """Call the method to process a "composing" state.
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
823 @param to_jid_s: contact the user is composing to
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
824 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
825 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
826 self.sat_host.bridge.chatStateComposing(to_jid_s, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
827
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
828 def jsonrpc_getNewAccountDomain(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
829 """@return: the domain for new account creation"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
830 d = self.asyncBridgeCall("getNewAccountDomain")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
831 return d
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
832
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 427
diff changeset
833 def jsonrpc_syntaxConvert(self, text, syntax_from=C.SYNTAX_XHTML, syntax_to=C.SYNTAX_CURRENT):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
834 """ Convert a text between two syntaxes
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
835 @param text: text to convert
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
836 @param syntax_from: source syntax (e.g. "markdown")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
837 @param syntax_to: dest syntax (e.g.: "XHTML")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
838 @param safe: clean resulting XHTML to avoid malicious code if True (forced here)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
839 @return: converted text """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
840 profile = ISATSession(self.session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
841 return self.sat_host.bridge.syntaxConvert(text, syntax_from, syntax_to, True, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
842
520
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
843 def jsonrpc_getLastResource(self, jid_s):
521
69bffcf37ce3 browser_side: add minimal requirements for generic plugins handling
souliane <souliane@mailoo.org>
parents: 520
diff changeset
844 """Get the last active resource of that contact."""
520
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
845 profile = ISATSession(self.session).profile
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
846 return self.sat_host.bridge.getLastResource(jid_s, profile)
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
847
751
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
848 def jsonrpc_getFeatures(self):
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
849 """Return the available features in the backend for profile"""
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
850 profile = ISATSession(self.session).profile
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
851 return self.sat_host.bridge.getFeatures(profile)
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
852
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
853 def jsonrpc_skipOTR(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
854 """Tell the backend to leave OTR handling to Libervia."""
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
855 profile = ISATSession(self.session).profile
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
856 return self.sat_host.bridge.skipOTR(profile)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
857
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
858
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
859 class WaitingRequests(dict):
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
860
796
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
861 def setRequest(self, request, profile, register_with_ext_jid=False):
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
862 """Add the given profile to the waiting list.
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
863
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
864 @param request (server.Request): the connection request
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
865 @param profile (str): %(doc_profile)s
796
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
866 @param register_with_ext_jid (bool): True if we will try to register the profile with an external XMPP account credentials
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
867 """
555
db1b330c1eb1 server_side: set the connection attempt timeout to the bridge timeout (2 minutes)
souliane <souliane@mailoo.org>
parents: 554
diff changeset
868 dc = reactor.callLater(BRIDGE_TIMEOUT, self.purgeRequest, profile)
796
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
869 self[profile] = (request, dc, register_with_ext_jid)
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
870
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
871 def purgeRequest(self, profile):
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
872 """Remove the given profile from the waiting list.
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
873
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
874 @param profile (str): %(doc_profile)s
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
875 """
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
876 try:
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
877 dc = self[profile][1]
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
878 except KeyError:
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
879 return
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
880 if dc.active():
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
881 dc.cancel()
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
882 del self[profile]
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
883
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
884 def getRequest(self, profile):
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
885 """Get the waiting request for the given profile.
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
886
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
887 @param profile (str): %(doc_profile)s
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
888 @return: the waiting request or None
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
889 """
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
890 return self[profile][0] if profile in self else None
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
891
796
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
892 def getRegisterWithExtJid(self, profile):
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
893 """Get the value of the register_with_ext_jid parameter.
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
894
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
895 @param profile (str): %(doc_profile)s
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
896 @return: bool or None
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
897 """
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
898 return self[profile][2] if profile in self else None
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
899
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
900
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
901 class Register(JSONRPCMethodManager):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
902 """This class manage the registration procedure with SàT
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
903 It provide an api for the browser, check password and setup the web server"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
904
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
905 def __init__(self, sat_host):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
906 JSONRPCMethodManager.__init__(self, sat_host)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
907 self.profiles_waiting = {}
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
908 self.request = None
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
909 self.waiting_profiles = WaitingRequests()
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
910
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
911 def render(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
912 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
913 Render method with some hacks:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
914 - if login is requested, try to login with form data
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
915 - except login, every method is jsonrpc
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
916 - user doesn't need to be authentified for explicitely listed methods, but must be for all others
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
917 """
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
918 if request.postpath == ['login']:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
919 return self.loginOrRegister(request)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
920 _session = request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
921 parsed = jsonrpclib.loads(request.content.read())
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
922 method = parsed.get("method") # pylint: disable=E1103
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
923 if method not in ['getSessionMetadata', 'registerParams', 'getMenus']:
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
924 #if we don't call these methods, we need to be identified
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
925 profile = ISATSession(_session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
926 if not profile:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
927 #user is not identified, we return a jsonrpc fault
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
928 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
929 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
930 self.request = request
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
931 return jsonrpc.JSONRPC.render(self, request)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
932
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
933 def loginOrRegister(self, request):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
934 """This method is called with the POST information from the registering form.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
935
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
936 @param request: request of the register form
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
937 @return: a constant indicating the state:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
938 - C.BAD_REQUEST: something is wrong in the request (bad arguments)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
939 - a return value from self._loginAccount or self._registerNewAccount
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
940 """
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
941 try:
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
942 submit_type = request.args['submit_type'][0]
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
943 except KeyError:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
944 return C.BAD_REQUEST
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
945
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
946 if submit_type == 'register':
871
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
947 if not self.sat_host.options["allow_registration"]:
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
948 log.warning(u"Registration received while it is not allowed, hack attempt?")
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
949 return exceptions.PermissionError(u"Registration is not allowed on this server")
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
950 return self._registerNewAccount(request)
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
951 elif submit_type == 'login':
794
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
952 d = self.asyncBridgeCall("getNewAccountDomain")
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
953 d.addCallback(lambda domain: self._loginAccount(request, domain))
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
954 return server.NOT_DONE_YET
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
955 return Exception('Unknown submit type')
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
956
794
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
957 def _loginAccount(self, request, new_account_domain):
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
958 """Try to authenticate the user with the request information.
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
959
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
960 @param request: request of the register form
794
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
961 @param new_account_domain (unicode): host corresponding to the local domain
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
962 @return: a constant indicating the state:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
963 - C.BAD_REQUEST: something is wrong in the request (bad arguments)
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
964 - C.PROFILE_AUTH_ERROR: either the profile (login) or the profile password is wrong
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
965 - C.XMPP_AUTH_ERROR: the profile is authenticated but the XMPP password is wrong
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
966 - C.ALREADY_WAITING: a request has already been submitted for this profile
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
967 - server.NOT_DONE_YET: the profile is being processed, the return
464
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
968 value will be given by self._logged or auth_eb
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
969 """
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
970 try:
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
971 login = request.args['login'][0]
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
972 password = request.args['login_password'][0]
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
973 except KeyError:
794
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
974 request.write(C.BAD_REQUEST)
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
975 request.finish()
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
976 return
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
977
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
978 assert login
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
979
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
980 if login.startswith('@'): # this is checked by javascript but also here for security reason
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
981 # FIXME: return an error instead of an Exception?
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
982 raise Exception('No profile_key allowed')
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
983
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
984 if '@' in login:
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
985 try:
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
986 login_jid = jid.JID(login)
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
987 except (RuntimeError, jid.InvalidFormat, AttributeError):
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
988 request.write(C.PROFILE_AUTH_ERROR)
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
989 request.finish()
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
990 return
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
991
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
992 if login_jid.host == new_account_domain:
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
993 # redirect "user@libervia.org" to the "user" profile
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
994 login = login_jid.user
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
995 login_jid = None
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
996 else:
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
997 login_jid = None
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
998
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
999 try:
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
1000 profile = self.sat_host.bridge.getProfileName(login)
796
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
1001 except Exception: # XXX: ProfileUnknownError wouldn't work, it's encapsulated
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
1002 if login_jid is not None and login_jid.user: # try to create a new sat profile using the XMPP credentials
871
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
1003 if not self.sat_host.options["allow_registration"]:
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
1004 log.warning(u"Trying to register JID account while registration is not allowed")
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
1005 request.write(C.PROFILE_AUTH_ERROR)
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
1006 request.finish()
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
1007 return
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
1008 profile = login # FIXME: what if there is a resource?
801
68eadda8a59a server_side: fixed confusion between jid user and host when there's not arobase
souliane <souliane@mailoo.org>
parents: 796
diff changeset
1009 connect_method = "asyncConnectWithXMPPCredentials"
68eadda8a59a server_side: fixed confusion between jid user and host when there's not arobase
souliane <souliane@mailoo.org>
parents: 796
diff changeset
1010 register_with_ext_jid = True
68eadda8a59a server_side: fixed confusion between jid user and host when there's not arobase
souliane <souliane@mailoo.org>
parents: 796
diff changeset
1011 else: # non existing username
68eadda8a59a server_side: fixed confusion between jid user and host when there's not arobase
souliane <souliane@mailoo.org>
parents: 796
diff changeset
1012 request.write(C.PROFILE_AUTH_ERROR)
68eadda8a59a server_side: fixed confusion between jid user and host when there's not arobase
souliane <souliane@mailoo.org>
parents: 796
diff changeset
1013 request.finish()
68eadda8a59a server_side: fixed confusion between jid user and host when there's not arobase
souliane <souliane@mailoo.org>
parents: 796
diff changeset
1014 return
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
1015 else:
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
1016 if profile != login or (not password and profile not in self.sat_host.options['empty_password_allowed_warning_dangerous_list']):
794
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
1017 # profiles with empty passwords are restricted to local frontends
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
1018 request.write(C.PROFILE_AUTH_ERROR)
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
1019 request.finish()
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
1020 return
796
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
1021 register_with_ext_jid = False
794
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
1022
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
1023 connect_method = "asyncConnect"
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1024
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
1025 if self.waiting_profiles.getRequest(profile):
794
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
1026 request.write(C.ALREADY_WAITING)
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
1027 request.finish()
6a2fd7807770 server_side: if a user tries to login with a full JID but his host is the local domain, login with the user part only
souliane <souliane@mailoo.org>
parents: 793
diff changeset
1028 return
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1029
464
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
1030 def auth_eb(failure):
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
1031 fault = failure.value.faultString
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
1032 self.waiting_profiles.purgeRequest(profile)
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
1033 if fault in ('PasswordError', 'ProfileUnknownError'):
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
1034 log.info(u"Profile %s doesn't exist or the submitted password is wrong" % profile)
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1035 request.write(C.PROFILE_AUTH_ERROR)
464
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
1036 elif fault == 'SASLAuthError':
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
1037 log.info(u"The XMPP password of profile %s is wrong" % profile)
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1038 request.write(C.XMPP_AUTH_ERROR)
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1039 elif fault == 'NoReply':
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1040 log.info(_("Did not receive a reply (the timeout expired or the connection is broken)"))
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1041 request.write(C.NO_REPLY)
464
bea9788f3170 browser and server sides: don't handle the "connectionError" signal anymore, we now use asyncConnect errback:
souliane <souliane@mailoo.org>
parents: 462
diff changeset
1042 else:
793
249e49f56f67 browser and server sides: removed constant UNMANAGED_FAULT_STRING which is used only to be displayed to the user, but it doesn't mean anything to him
souliane <souliane@mailoo.org>
parents: 751
diff changeset
1043 log.error(u'Unmanaged fault string "%s" in errback for the connection of profile %s' % (fault, profile))
249e49f56f67 browser and server sides: removed constant UNMANAGED_FAULT_STRING which is used only to be displayed to the user, but it doesn't mean anything to him
souliane <souliane@mailoo.org>
parents: 751
diff changeset
1044 request.write(fault)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1045 request.finish()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1046
796
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
1047 self.waiting_profiles.setRequest(request, profile, register_with_ext_jid)
750
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
1048 d = self.asyncBridgeCall(connect_method, profile, password)
8ac862f6e5b3 browser and server sides: allow to connect with a JID that is not registered on the local server
souliane <souliane@mailoo.org>
parents: 746
diff changeset
1049 d.addCallbacks(lambda connected: self._logged(profile, request) if connected else None, auth_eb)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1050
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1051 def _registerNewAccount(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1052 """Create a new account, or return error
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1053 @param request: request of the register form
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1054 @return: a constant indicating the state:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1055 - C.BAD_REQUEST: something is wrong in the request (bad arguments)
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1056 - C.REGISTRATION_SUCCEED: new account has been successfully registered
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1057 - C.ALREADY_EXISTS: the given profile already exists
793
249e49f56f67 browser and server sides: removed constant UNMANAGED_FAULT_STRING which is used only to be displayed to the user, but it doesn't mean anything to him
souliane <souliane@mailoo.org>
parents: 751
diff changeset
1058 - C.INTERNAL_ERROR or any unmanaged fault string
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1059 - server.NOT_DONE_YET: the profile is being processed, the return
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1060 value will be given later (one of those previously described)
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1061 """
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1062 try:
487
e588335b6aa8 browser and server side: force lower case for the profile name at new account creation + fixes CSS for textarea
souliane <souliane@mailoo.org>
parents: 482
diff changeset
1063 # XXX: for now libervia forces the creation to lower case
e588335b6aa8 browser and server side: force lower case for the profile name at new account creation + fixes CSS for textarea
souliane <souliane@mailoo.org>
parents: 482
diff changeset
1064 profile = login = request.args['register_login'][0].lower()
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1065 password = request.args['register_password'][0]
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1066 email = request.args['email'][0]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1067 except KeyError:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1068 return C.BAD_REQUEST
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1069 if not re.match(r'^[a-z0-9_-]+$', login, re.IGNORECASE) or \
445
c0ff91cabea0 server_side, browser_side: new account password must contain at least 6 chars + cosmetic change for register warning message
souliane <souliane@mailoo.org>
parents: 444
diff changeset
1070 not re.match(r'^.+@.+\..+', email, re.IGNORECASE) or \
c0ff91cabea0 server_side, browser_side: new account password must contain at least 6 chars + cosmetic change for register warning message
souliane <souliane@mailoo.org>
parents: 444
diff changeset
1071 len(password) < C.PASSWORD_MIN_LENGTH:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1072 return C.BAD_REQUEST
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1073
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1074 def registered(result):
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1075 request.write(C.REGISTRATION_SUCCEED)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1076 request.finish()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1077
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1078 def registeringError(failure):
374
f22a4bf9a67e server_side: fix error management at account creation
souliane <souliane@mailoo.org>
parents: 351
diff changeset
1079 reason = failure.value.faultString
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1080 if reason == "ConflictError":
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1081 request.write(C.ALREADY_EXISTS)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1082 elif reason == "InternalError":
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1083 request.write(C.INTERNAL_ERROR)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1084 else:
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
1085 log.error(u'Unknown registering error: %s' % (reason,))
793
249e49f56f67 browser and server sides: removed constant UNMANAGED_FAULT_STRING which is used only to be displayed to the user, but it doesn't mean anything to him
souliane <souliane@mailoo.org>
parents: 751
diff changeset
1086 request.write(reason)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1087 request.finish()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1088
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1089 d = self.asyncBridgeCall("registerSatAccount", email, password, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1090 d.addCallback(registered)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1091 d.addErrback(registeringError)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1092 return server.NOT_DONE_YET
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1093
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1094 def _logged(self, profile, request):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1095 """Set everything when a user just logged in
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1096
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1097 @param profile
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1098 @param request
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1099 @return: a constant indicating the state:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1100 - C.PROFILE_LOGGED
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1101 - C.SESSION_ACTIVE
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1102 """
796
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
1103 register_with_ext_jid = self.waiting_profiles.getRegisterWithExtJid(profile)
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1104 self.waiting_profiles.purgeRequest(profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1105 _session = request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1106 sat_session = ISATSession(_session)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1107 if sat_session.profile:
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1108 log.error(('/!\\ Session has already a profile, this should NEVER happen!'))
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1109 request.write(C.SESSION_ACTIVE)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1110 request.finish()
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1111 return
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
1112 # we manage profile server side to avoid profile spoofing
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1113 sat_session.profile = profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1114 self.sat_host.prof_connected.add(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1115
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1116 def onExpire():
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
1117 log.info(u"Session expired (profile=%s)" % (profile,))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1118 try:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1119 #We purge the queue
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1120 del self.sat_host.signal_handler.queue[profile]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1121 except KeyError:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1122 pass
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1123 #and now we disconnect the profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1124 self.sat_host.bridge.disconnect(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1125
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1126 _session.notifyOnExpire(onExpire)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1127
796
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
1128 request.write(C.PROFILE_LOGGED_REGISTERED_WITH_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1129 request.finish()
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1130
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1131 def jsonrpc_isConnected(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1132 _session = self.request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1133 profile = ISATSession(_session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1134 return self.sat_host.bridge.isConnected(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1135
456
da2a7f2b34c9 browser and server sides: use asyncConnect instead of connect
souliane <souliane@mailoo.org>
parents: 451
diff changeset
1136 def jsonrpc_asyncConnect(self):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1137 _session = self.request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1138 profile = ISATSession(_session).profile
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1139 if self.waiting_profiles.getRequest(profile):
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1140 raise jsonrpclib.Fault(1, C.ALREADY_WAITING) # FIXME: define some standard error codes for libervia
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1141 self.waiting_profiles.setRequest(self.request, profile)
456
da2a7f2b34c9 browser and server sides: use asyncConnect instead of connect
souliane <souliane@mailoo.org>
parents: 451
diff changeset
1142 self.sat_host.bridge.asyncConnect(profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1143 return server.NOT_DONE_YET
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1144
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1145 def jsonrpc_getSessionMetadata(self):
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1146 """Return metadata useful on session start
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1147
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1148 @return (dict): metadata which can have the following keys:
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1149 "plugged" (bool): True if a profile is already plugged
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1150 "warning" (unicode): a security warning message if plugged is False and if it make sense
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1151 this key may not be present
871
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
1152 "allow_registration" (bool): True if registration is allowed
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
1153 this key is only present if profile is unplugged
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1154 @return: a couple (registered, message) with:
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1155 - registered:
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1156 - message:
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1157 """
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1158 metadata = {}
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1159 _session = self.request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1160 profile = ISATSession(_session).profile
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1161 if profile:
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1162 metadata["plugged"] = True
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1163 else:
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1164 metadata["plugged"] = False
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1165 metadata["warning"] = self._getSecurityWarning()
871
54f6c5b86a87 server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
Goffi <goffi@goffi.org>
parents: 869
diff changeset
1166 metadata["allow_registration"] = self.sat_host.options["allow_registration"]
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1167 return metadata
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1168
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1169 def jsonrpc_registerParams(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1170 """Register the frontend specific parameters"""
696
c2f22ca12e23 browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents: 694
diff changeset
1171 # params = """<params><individual>...</category></individual>"""
c2f22ca12e23 browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents: 694
diff changeset
1172 # self.sat_host.bridge.paramsRegisterApp(params, C.SECURITY_LIMIT, C.APP_NAME)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1173
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1174 def jsonrpc_getMenus(self):
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1175 """Return the parameters XML for profile"""
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1176 # XXX: we put this method in Register because we get menus before being logged
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 427
diff changeset
1177 return self.sat_host.bridge.getMenus('', C.SECURITY_LIMIT)
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1178
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
1179 def _getSecurityWarning(self):
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1180 """@return: a security warning message, or None if the connection is secure"""
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1181 if self.request.URLPath().scheme == 'https' or not self.sat_host.options['security_warning']:
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1182 return None
707
dfe4b0291daa server_side: remove unwanted "target" property in the HTTP to HTTPS link + use "<p>" instead of "<br>"
souliane <souliane@mailoo.org>
parents: 706
diff changeset
1183 text = "<p>" + D_("You are about to connect to an unsecure service.") + "</p><p>&nbsp;</p><p>"
dfe4b0291daa server_side: remove unwanted "target" property in the HTTP to HTTPS link + use "<p>" instead of "<br>"
souliane <souliane@mailoo.org>
parents: 706
diff changeset
1184
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1185 if self.sat_host.options['connection_type'] == 'both':
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1186 new_port = (':%s' % self.sat_host.options['port_https_ext']) if self.sat_host.options['port_https_ext'] != HTTPS_PORT else ''
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1187 url = "https://%s" % self.request.URLPath().netloc.replace(':%s' % self.sat_host.options['port'], new_port)
707
dfe4b0291daa server_side: remove unwanted "target" property in the HTTP to HTTPS link + use "<p>" instead of "<br>"
souliane <souliane@mailoo.org>
parents: 706
diff changeset
1188 text += D_('Please read our %(faq_prefix)ssecurity notice%(faq_suffix)s regarding HTTPS') % {'faq_prefix': '<a href="http://salut-a-toi.org/faq.html#https" target="#">', 'faq_suffix': '</a>'}
dfe4b0291daa server_side: remove unwanted "target" property in the HTTP to HTTPS link + use "<p>" instead of "<br>"
souliane <souliane@mailoo.org>
parents: 706
diff changeset
1189 text += "</p><p>" + D_('and use the secure version of this website:')
dfe4b0291daa server_side: remove unwanted "target" property in the HTTP to HTTPS link + use "<p>" instead of "<br>"
souliane <souliane@mailoo.org>
parents: 706
diff changeset
1190 text += '</p><p>&nbsp;</p><p align="center"><a href="%(url)s">%(url)s</a>' % {'url': url}
706
fe03637fe5a6 server_side: add a link to the FAQ in the HTTP/HTTPS warning dialog
souliane <souliane@mailoo.org>
parents: 705
diff changeset
1191 else:
841
4a01be961fd2 server: removed unused %(url)s for formatting HTTP warning message
Goffi <goffi@goffi.org>
parents: 823
diff changeset
1192 text += D_('You should ask your administrator to turn on HTTPS.')
707
dfe4b0291daa server_side: remove unwanted "target" property in the HTTP to HTTPS link + use "<p>" instead of "<br>"
souliane <souliane@mailoo.org>
parents: 706
diff changeset
1193
dfe4b0291daa server_side: remove unwanted "target" property in the HTTP to HTTPS link + use "<p>" instead of "<br>"
souliane <souliane@mailoo.org>
parents: 706
diff changeset
1194 return text + "</p><p>&nbsp;</p>"
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1195
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1196
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1197 class SignalHandler(jsonrpc.JSONRPC):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1198
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1199 def __init__(self, sat_host):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1200 web_resource.Resource.__init__(self)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1201 self.register = None
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1202 self.sat_host = sat_host
744
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1203 self.signalDeferred = {} # dict of deferred (key: profile, value: Deferred)
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1204 # which manages the long polling HTTP request with signals
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1205 self.queue = {}
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1206
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1207 def plugRegister(self, register):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1208 self.register = register
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1209
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1210 def jsonrpc_getSignals(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1211 """Keep the connection alive until a signal is received, then send it
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1212 @return: (signal, *signal_args)"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1213 _session = self.request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1214 profile = ISATSession(_session).profile
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1215 if profile in self.queue: # if we have signals to send in queue
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1216 if self.queue[profile]:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1217 return self.queue[profile].pop(0)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1218 else:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1219 #the queue is empty, we delete the profile from queue
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1220 del self.queue[profile]
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1221 _session.lock() # we don't want the session to expire as long as this connection is active
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1222
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1223 def unlock(signal, profile):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1224 _session.unlock()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1225 try:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1226 source_defer = self.signalDeferred[profile]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1227 if source_defer.called and source_defer.result[0] == "disconnected":
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
1228 log.info(u"[%s] disconnected" % (profile,))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1229 _session.expire()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1230 except IndexError:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
1231 log.error("Deferred result should be a tuple with fonction name first")
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1232
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1233 self.signalDeferred[profile] = defer.Deferred()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1234 self.request.notifyFinish().addBoth(unlock, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1235 return self.signalDeferred[profile]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1236
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1237 def getGenericCb(self, function_name):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1238 """Return a generic function which send all params to signalDeferred.callback
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1239 function must have profile as last argument"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1240 def genericCb(*args):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1241 profile = args[-1]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1242 if not profile in self.sat_host.prof_connected:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1243 return
744
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1244 signal_data = (function_name, args[:-1])
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1245 try:
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1246 signal_callback = self.signalDeferred[profile].callback
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1247 except KeyError:
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1248 self.queue.setdefault(profile,[]).append(signal_data)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1249 else:
744
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1250 signal_callback(signal_data)
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1251 del self.signalDeferred[profile]
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1252 return genericCb
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1253
744
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1254 def actionNewHandler(self, action_data, action_id, security_limit, profile):
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1255 """actionNew handler
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1256
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1257 XXX: We need need a dedicated handler has actionNew use a security_limit which must be managed
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1258 @param action_data(dict): see bridge documentation
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1259 @param action_id(unicode): identitifer of the action
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1260 @param security_limit(int): %(doc_security_limit)s
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1261 @param profile(unicode): %(doc_profile)s
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1262 """
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1263 if not profile in self.sat_host.prof_connected:
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1264 return
796
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
1265 # FIXME: manage security limit in a dedicated method
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
1266 # raise an exception if it's not OK
fad9c9f82ae3 browser and server sides: alert the user after he created a new profile using his XMPP account credentials
souliane <souliane@mailoo.org>
parents: 794
diff changeset
1267 # and read value in sat.conf
744
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1268 if security_limit >= C.SECURITY_LIMIT:
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1269 log.debug(u"Ignoring action {action_id}, blocked by security limit".format(action_id=action_id))
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1270 return
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1271 signal_data = ("actionNew", (action_data, action_id, security_limit))
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1272 try:
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1273 signal_callback = self.signalDeferred[profile].callback
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1274 except KeyError:
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1275 self.queue.setdefault(profile,[]).append(signal_data)
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1276 else:
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1277 signal_callback(signal_data)
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1278 del self.signalDeferred[profile]
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1279
710
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1280 def connected(self, profile, jid_s):
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1281 """Connection is done.
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1282
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1283 @param profile (unicode): %(doc_profile)s
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1284 @param jid_s (unicode): the JID that we were assigned by the server, as the resource might differ from the JID we asked for.
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1285 """
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1286 # jid_s is handled in QuickApp.connectionHandler already
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1287 assert(self.register) # register must be plugged
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1288 request = self.register.waiting_profiles.getRequest(profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1289 if request:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1290 self.register._logged(profile, request)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1291
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1292 def disconnected(self, profile):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1293 if not profile in self.sat_host.prof_connected:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
1294 log.error("'disconnected' signal received for a not connected profile")
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1295 return
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1296 self.sat_host.prof_connected.remove(profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1297 if profile in self.signalDeferred:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1298 self.signalDeferred[profile].callback(("disconnected",))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1299 del self.signalDeferred[profile]
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1300 else:
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1301 if profile not in self.queue:
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1302 self.queue[profile] = []
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1303 self.queue[profile].append(("disconnected",))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1304
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1305 def render(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1306 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1307 Render method wich reject access if user is not identified
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1308 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1309 _session = request.getSession()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1310 parsed = jsonrpclib.loads(request.content.read())
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1311 profile = ISATSession(_session).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1312 if not profile:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1313 #user is not identified, we return a jsonrpc fault
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1314 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
1315 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1316 self.request = request
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1317 return jsonrpc.JSONRPC.render(self, request)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1318
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1319
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1320 class UploadManager(web_resource.Resource):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1321 """This class manage the upload of a file
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1322 It redirect the stream to SàT core backend"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1323 isLeaf = True
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1324 NAME = 'path' # name use by the FileUpload
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1325
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1326 def __init__(self, sat_host):
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1327 self.sat_host = sat_host
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1328 self.upload_dir = tempfile.mkdtemp()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1329 self.sat_host.addCleanup(shutil.rmtree, self.upload_dir)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1330
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1331 def getTmpDir(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1332 return self.upload_dir
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1333
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1334 def _getFileName(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1335 """Generate unique filename for a file"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1336 raise NotImplementedError
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1337
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1338 def _fileWritten(self, request, filepath):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1339 """Called once the file is actually written on disk
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1340 @param request: HTTP request object
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1341 @param filepath: full filepath on the server
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1342 @return: a tuple with the name of the async bridge method
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1343 to be called followed by its arguments.
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1344 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1345 raise NotImplementedError
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1346
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1347 def render(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1348 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1349 Render method with some hacks:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1350 - if login is requested, try to login with form data
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1351 - except login, every method is jsonrpc
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1352 - user doesn't need to be authentified for getSessionMetadata, but must be for all other methods
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1353 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1354 filename = self._getFileName(request)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1355 filepath = os.path.join(self.upload_dir, filename)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1356 #FIXME: the uploaded file is fully loaded in memory at form parsing time so far
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1357 # (see twisted.web.http.Request.requestReceived). A custom requestReceived should
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1358 # be written in the futur. In addition, it is not yet possible to get progression informations
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1359 # (see http://twistedmatrix.com/trac/ticket/288)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1360
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1361 with open(filepath, 'w') as f:
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1362 f.write(request.args[self.NAME][0])
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1363
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1364 def finish(d):
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1365 error = isinstance(d, Exception) or isinstance(d, Failure)
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1366 request.write(C.UPLOAD_KO if error else C.UPLOAD_OK)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1367 # TODO: would be great to re-use the original Exception class and message
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1368 # but it is lost in the middle of the backtrace and encapsulated within
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1369 # a DBusException instance --> extract the data from the backtrace?
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1370 request.finish()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1371
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1372 d = JSONRPCMethodManager(self.sat_host).asyncBridgeCall(*self._fileWritten(request, filepath))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1373 d.addCallbacks(lambda d: finish(d), lambda failure: finish(failure))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1374 return server.NOT_DONE_YET
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1375
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1376
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1377 class UploadManagerRadioCol(UploadManager):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1378 NAME = 'song'
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1379
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1380 def _getFileName(self, request):
394
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 391
diff changeset
1381 extension = os.path.splitext(request.args['filename'][0])[1]
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 391
diff changeset
1382 return "%s%s" % (str(uuid.uuid4()), extension) # XXX: chromium doesn't seem to play song without the .ogg extension, even with audio/ogg mime-type
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1383
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1384 def _fileWritten(self, request, filepath):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1385 """Called once the file is actually written on disk
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1386 @param request: HTTP request object
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1387 @param filepath: full filepath on the server
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1388 @return: a tuple with the name of the async bridge method
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1389 to be called followed by its arguments.
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1390 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1391 profile = ISATSession(request.getSession()).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1392 return ("radiocolSongAdded", request.args['referee'][0], filepath, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1393
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1394
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1395 class UploadManagerAvatar(UploadManager):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1396 NAME = 'avatar_path'
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1397
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1398 def _getFileName(self, request):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1399 return str(uuid.uuid4())
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1400
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1401 def _fileWritten(self, request, filepath):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1402 """Called once the file is actually written on disk
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1403 @param request: HTTP request object
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1404 @param filepath: full filepath on the server
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1405 @return: a tuple with the name of the async bridge method
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1406 to be called followed by its arguments.
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1407 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1408 profile = ISATSession(request.getSession()).profile
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1409 return ("setAvatar", filepath, profile)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1410
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1411
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1412 class Libervia(service.Service):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1413
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1414
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1415 def __init__(self, options):
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1416 self.options = options
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1417 self.initialised = defer.Deferred()
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1418
881
6bdee34fa2f4 server: added base_url_ext option to handle different external URLs (e.g.: if there is a proxy)
Goffi <goffi@goffi.org>
parents: 875
diff changeset
1419 if self.options['base_url_ext']:
6bdee34fa2f4 server: added base_url_ext option to handle different external URLs (e.g.: if there is a proxy)
Goffi <goffi@goffi.org>
parents: 875
diff changeset
1420 self.base_url_ext = self.options.pop('base_url_ext')
6bdee34fa2f4 server: added base_url_ext option to handle different external URLs (e.g.: if there is a proxy)
Goffi <goffi@goffi.org>
parents: 875
diff changeset
1421 if self.base_url_ext[-1] != '/':
6bdee34fa2f4 server: added base_url_ext option to handle different external URLs (e.g.: if there is a proxy)
Goffi <goffi@goffi.org>
parents: 875
diff changeset
1422 self.base_url_ext += '/'
884
763da94ba28b blog (atom): base_url_ext can now only specify scheme, or netloc, or path, it will be used to complete data coming from request's path
Goffi <goffi@goffi.org>
parents: 881
diff changeset
1423 self.base_url_ext_data = urlparse.urlsplit(self.base_url_ext)
881
6bdee34fa2f4 server: added base_url_ext option to handle different external URLs (e.g.: if there is a proxy)
Goffi <goffi@goffi.org>
parents: 875
diff changeset
1424 else:
6bdee34fa2f4 server: added base_url_ext option to handle different external URLs (e.g.: if there is a proxy)
Goffi <goffi@goffi.org>
parents: 875
diff changeset
1425 self.base_url_ext = None
884
763da94ba28b blog (atom): base_url_ext can now only specify scheme, or netloc, or path, it will be used to complete data coming from request's path
Goffi <goffi@goffi.org>
parents: 881
diff changeset
1426 # we split empty string anyway so we can do things like
763da94ba28b blog (atom): base_url_ext can now only specify scheme, or netloc, or path, it will be used to complete data coming from request's path
Goffi <goffi@goffi.org>
parents: 881
diff changeset
1427 # scheme = self.base_url_ext_data.scheme or 'https'
763da94ba28b blog (atom): base_url_ext can now only specify scheme, or netloc, or path, it will be used to complete data coming from request's path
Goffi <goffi@goffi.org>
parents: 881
diff changeset
1428 self.base_url_ext_data = urlparse.urlsplit('')
763da94ba28b blog (atom): base_url_ext can now only specify scheme, or netloc, or path, it will be used to complete data coming from request's path
Goffi <goffi@goffi.org>
parents: 881
diff changeset
1429
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1430 if not self.options['port_https_ext']:
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1431 self.options['port_https_ext'] = self.options['port_https']
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1432 if self.options['data_dir'] == DATA_DIR_DEFAULT:
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1433 coerceDataDir(self.options['data_dir']) # this is not done when using the default value
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1434
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1435 self.html_dir = os.path.join(self.options['data_dir'], C.HTML_DIR)
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1436 self.themes_dir = os.path.join(self.options['data_dir'], C.THEMES_DIR)
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1437
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1438 self._cleanup = []
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1439
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1440 root = LiberviaRootResource(self.options, self.html_dir)
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1441
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1442 self.signal_handler = SignalHandler(self)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1443 _register = Register(self)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1444 _upload_radiocol = UploadManagerRadioCol(self)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1445 _upload_avatar = UploadManagerAvatar(self)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1446 self.signal_handler.plugRegister(_register)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1447 self.sessions = {} # key = session value = user
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1448 self.prof_connected = set() # Profiles connected
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1449
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1450 ## bridge ##
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1451 try:
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1452 self.bridge = DBusBridgeFrontend()
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1453 except BridgeExceptionNoService:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1454 print(u"Can't connect to SàT backend, are you sure it's launched ?")
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1455 sys.exit(1)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1456
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1457 def backendReady(dummy):
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1458 self.bridge.register("connected", self.signal_handler.connected)
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1459 self.bridge.register("disconnected", self.signal_handler.disconnected)
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1460 #core
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
1461 for signal_name in ['presenceUpdate', 'messageNew', 'subscribe', 'contactDeleted',
913
58f611481e6d server, browser: removed deprecated methods which have been removed from backend, and associated code
Goffi <goffi@goffi.org>
parents: 909
diff changeset
1462 'newContact', 'entityDataUpdated', 'paramUpdate']:
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1463 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name))
744
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1464 # XXX: actionNew is handled separately because the handler must manage security_limit
03ccd68a6dab server side: actionNew now use a dedicated signal handler, which block it if security limit is exceeded
Goffi <goffi@goffi.org>
parents: 724
diff changeset
1465 self.bridge.register('actionNew', self.signal_handler.actionNewHandler)
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1466 #plugins
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
1467 for signal_name in ['psEvent', 'mucRoomJoined', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1468 'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore', 'tarotGamePlayers',
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1469 'radiocolStarted', 'radiocolPreload', 'radiocolPlay', 'radiocolNoUpload', 'radiocolUploadOk', 'radiocolSongRejected', 'radiocolPlayers',
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
1470 'mucRoomLeft', 'mucRoomUserChangedNick', 'chatStateReceived']:
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1471 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin")
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1472 self.media_dir = self.bridge.getConfig('', 'media_dir')
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1473 self.local_dir = self.bridge.getConfig('', 'local_dir')
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1474
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1475 ## URLs ##
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1476 def putChild(path, resource):
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1477 """Add a child to the root resource"""
823
027139763511 server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents: 819
diff changeset
1478 # FIXME: check that no information is leaked (c.f. https://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#request-encoders)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1479 root.putChild(path, web_resource.EncodingResourceWrapper(resource, [server.GzipEncoderFactory()]))
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1480
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1481 # JSON APIs
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1482 putChild('json_signal_api', self.signal_handler)
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1483 putChild('json_api', MethodHandler(self))
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1484 putChild('register_api', _register)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1485
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1486 # files upload
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1487 putChild('upload_radiocol', _upload_radiocol)
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1488 putChild('upload_avatar', _upload_avatar)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1489
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1490 # static pages
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1491 putChild('blog', MicroBlog(self))
823
027139763511 server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents: 819
diff changeset
1492 putChild(C.THEMES_URL, ProtectedFile(self.themes_dir))
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1493
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1494 # media dirs
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1495 putChild(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir))
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1496 putChild(os.path.dirname(C.AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, C.AVATARS_DIR)))
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1497
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1498 # special
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1499 putChild('radiocol', ProtectedFile(_upload_radiocol.getTmpDir(), defaultType="audio/ogg")) # FIXME: We cheat for PoC because we know we are on the same host, so we use directly upload dir
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1500 # pyjamas tests, redirected only for dev versions
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1501 if self.version[-1] == 'D':
873
0cf250066b8a server: replaced libervia_test.html redirection by an absolute URL
Goffi <goffi@goffi.org>
parents: 871
diff changeset
1502 putChild('test', web_util.Redirect('/libervia_test.html'))
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1503
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1504
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1505 wrapped = web_resource.EncodingResourceWrapper(root, [server.GzipEncoderFactory()])
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1506 self.site = server.Site(wrapped)
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1507 self.site.sessionFactory = LiberviaSession
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1508
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1509 self.bridge.getReady(lambda: self.initialised.callback(None),
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1510 lambda failure: self.initialised.errback(Exception(failure)))
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1511 self.initialised.addCallback(backendReady)
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
1512 self.initialised.addErrback(lambda failure: log.error(u"Init error: %s" % failure))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1513
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1514 @property
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1515 def version(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1516 """Return the short version of Libervia"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1517 return C.APP_VERSION
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1518
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1519 @property
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1520 def full_version(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1521 """Return the full version of Libervia (with extra data when in development mode)"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1522 version = self.version
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1523 if version[-1] == 'D':
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1524 # we are in debug version, we add extra data
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1525 try:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1526 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1527 except AttributeError:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1528 self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(libervia))
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1529 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1530 else:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1531 return version
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1532
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1533 def addCleanup(self, callback, *args, **kwargs):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1534 """Add cleaning method to call when service is stopped
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1535 cleaning method will be called in reverse order of they insertion
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1536 @param callback: callable to call on service stop
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1537 @param *args: list of arguments of the callback
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1538 @param **kwargs: list of keyword arguments of the callback"""
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1539 self._cleanup.insert(0, (callback, args, kwargs))
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1540
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1541 def startService(self):
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1542 """Connect the profile for Libervia and start the HTTP(S) server(s)"""
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1543 def eb(e):
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
1544 log.error(_(u"Connection failed: %s") % e)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1545 self.stop()
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1546
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1547 def initOk(dummy):
859
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1548 try:
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1549 connected = self.bridge.isConnected(C.SERVICE_PROFILE)
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1550 except Exception as e:
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1551 # we don't want the traceback
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1552 msg = [l for l in unicode(e).split('\n') if l][-1]
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1553 log.error(u"Can't check service profile ({profile}), are you sure it exists ?\n{error}".format(
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1554 profile=C.SERVICE_PROFILE, error=msg))
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1555 self.stop()
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1556 return
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1557 if not connected:
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1558 self.bridge.asyncConnect(C.SERVICE_PROFILE, self.options['passphrase'],
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1559 callback=self._startService, errback=eb)
472
42c8e91af048 server side: fixed start sequence when SERVICE_PROFILE is already connected
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1560 else:
42c8e91af048 server side: fixed start sequence when SERVICE_PROFILE is already connected
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1561 self._startService()
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1562
444
b64e528fb524 server side: use of bridge's getReady to be sure that backend is initialised at launch
Goffi <goffi@goffi.org>
parents: 438
diff changeset
1563 self.initialised.addCallback(initOk)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1564
813
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1565 ## TLS related methods ##
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1566
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1567 def _TLSOptionsCheck(self):
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1568 """Check options coherence if TLS is activated, and update missing values
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1569
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1570 Must be called only if TLS is activated
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1571 """
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1572 if not self.options['tls_certificate']:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1573 log.error(u"a TLS certificate is needed to activate HTTPS connection")
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1574 self.quit(1)
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1575 if not self.options['tls_private_key']:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1576 self.options['tls_private_key'] = self.options['tls_certificate']
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1577
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1578
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1579 if not self.options['tls_private_key']:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1580 self.options['tls_private_key'] = self.options['tls_certificate']
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1581
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1582 def _loadCertificates(self, f):
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1583 """Read a .pem file with a list of certificates
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1584
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1585 @param f (file): file obj (opened .pem file)
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1586 @return (list[OpenSSL.crypto.X509]): list of certificates
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1587 @raise OpenSSL.crypto.Error: error while parsing the file
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1588 """
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1589 # XXX: didn't found any method to load a .pem file with several certificates
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1590 # so the certificates split is done here
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1591 certificates = []
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1592 buf = []
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1593 while True:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1594 line = f.readline()
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1595 buf.append(line)
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1596 if '-----END CERTIFICATE-----' in line:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1597 certificates.append(OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, ''.join(buf)))
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1598 buf=[]
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1599 elif not line:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1600 log.debug(u"{} certificate(s) found".format(len(certificates)))
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1601 return certificates
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1602
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1603 def _loadPKey(self, f):
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1604 """Read a private key from a .pem file
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1605
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1606 @param f (file): file obj (opened .pem file)
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1607 @return (list[OpenSSL.crypto.PKey]): private key object
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1608 @raise OpenSSL.crypto.Error: error while parsing the file
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1609 """
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1610 return OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, f.read())
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1611
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1612 def _loadCertificate(self, f):
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1613 """Read a public certificate from a .pem file
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1614
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1615 @param f (file): file obj (opened .pem file)
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1616 @return (list[OpenSSL.crypto.X509]): public certificate
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1617 @raise OpenSSL.crypto.Error: error while parsing the file
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1618 """
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1619 return OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, f.read())
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1620
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1621 def _getTLSContextFactory(self):
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1622 """Load TLS certificate and build the context factory needed for listenSSL"""
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1623 if ssl is None:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1624 raise ImportError(u"Python module pyOpenSSL is not installed!")
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1625
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1626 cert_options = {}
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1627
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1628 for name, option, method in [('privateKey', 'tls_private_key', self._loadPKey),
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1629 ('certificate', 'tls_certificate', self._loadCertificate),
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1630 ('extraCertChain', 'tls_chain', self._loadCertificates)]:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1631 path = self.options[option]
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1632 if not path:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1633 assert option=='tls_chain'
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1634 continue
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1635 log.debug(u"loading {option} from {path}".format(option=option, path=path))
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1636 try:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1637 with open(path) as f:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1638 cert_options[name] = method(f)
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1639 except IOError as e:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1640 log.error(u"Error while reading file {path} for option {option}: {error}".format(path=path, option=option, error=e))
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1641 self.quit(2)
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1642 except OpenSSL.crypto.Error:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1643 log.error(u"Error while parsing file {path} for option {option}, are you sure it is a valid .pem file?".format(path=path, option=option))
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1644 if option=='tls_private_key' and self.options['tls_certificate'] == path:
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1645 log.error(u"You are using the same file for private key and public certificate, make sure that both a in {path} or use --tls_private_key option".format(path=path))
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1646 self.quit(2)
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1647
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1648 return ssl.CertificateOptions(**cert_options)
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1649
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1650 ## service management ##
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1651
472
42c8e91af048 server side: fixed start sequence when SERVICE_PROFILE is already connected
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1652 def _startService(self, dummy=None):
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1653 """Actually start the HTTP(S) server(s) after the profile for Libervia is connected.
813
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1654
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1655 @raise ImportError: OpenSSL is not available
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1656 @raise IOError: the certificate file doesn't exist
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1657 @raise OpenSSL.crypto.Error: the certificate file is invalid
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
1658 """
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1659 if self.options['connection_type'] in ('https', 'both'):
813
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1660 self._TLSOptionsCheck()
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1661 context_factory = self._getTLSContextFactory()
6e27604ec95a server: added --tls_private_key and --tls_chain options. --tls_certificate .pem file will be used for private_key if --tls_private_key is not specified.
Goffi <goffi@goffi.org>
parents: 812
diff changeset
1662 reactor.listenSSL(self.options['port_https'], self.site, context_factory)
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1663 if self.options['connection_type'] in ('http', 'both'):
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1664 if self.options['connection_type'] == 'both' and self.options['redirect_to_https']:
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1665 reactor.listenTCP(self.options['port'], server.Site(RedirectToHTTPS(self.options['port'], self.options['port_https_ext'])))
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1666 else:
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1667 reactor.listenTCP(self.options['port'], self.site)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1668
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1669 def stopService(self):
473
d1565906f228 server_side: fixed some forgotten print statement
Goffi <goffi@goffi.org>
parents: 472
diff changeset
1670 log.info(_("launching cleaning methods"))
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1671 for callback, args, kwargs in self._cleanup:
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1672 callback(*args, **kwargs)
859
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1673 try:
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1674 self.bridge.disconnect(C.SERVICE_PROFILE)
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1675 except Exception:
0e9341e537d6 server: catch exceptions on service profile connection check, and show an helping message if an error is caught
Goffi <goffi@goffi.org>
parents: 858
diff changeset
1676 log.warning(u"Can't disconnect service profile")
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1677
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1678 def run(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1679 reactor.run()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1680
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1681 def stop(self):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1682 reactor.stop()
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1683
812
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
1684 def quit(self, exit_code=None):
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
1685 """Exit app when reactor is running
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
1686
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
1687 @param exit_code(None, int): exit code
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
1688 """
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
1689 self.stop()
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
1690 sys.exit(exit_code or 0)
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
1691
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1692
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1693 class RedirectToHTTPS(web_resource.Resource):
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1694
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1695 def __init__(self, old_port, new_port):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1696 web_resource.Resource.__init__(self)
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1697 self.isLeaf = True
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1698 self.old_port = old_port
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1699 self.new_port = new_port
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1700
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1701 def render(self, request):
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1702 netloc = request.URLPath().netloc.replace(':%s' % self.old_port, ':%s' % self.new_port)
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1703 url = "https://" + netloc + request.uri
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1704 return web_util.redirectTo(url, request)
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1705
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1706
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1707 registerAdapter(SATSession, server.Session, ISATSession)