annotate src/server/server.py @ 978:c8cafe316f6f

pages: removed trailing_slash option: this option is used for relative URLs, but it seems more reasonable to build absolute URL from the server, so templates are not dependants of the way the pages hierarchy is done.
author Goffi <goffi@goffi.org>
date Sun, 12 Nov 2017 12:51:56 +0100
parents 4aa38c49bff7
children 1d558dfb32ca
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
964
fd4eae654182 misc: date update (yes it's a bit late :p )
Goffi <goffi@goffi.org>
parents: 962
diff changeset
5 # Copyright (C) 2011-2017 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
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
28 from twisted.python 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__)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
36 from sat_frontends.bridge.dbus_bridge import Bridge, 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
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
40 from sat.tools.common import regex
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
41 from sat.tools.common import template
927
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
42 from sat.tools.common import uri as common_uri
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
43
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
44 import re
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
45 import glob
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
46 import os.path
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
47 import sys
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
48 import tempfile
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
49 import shutil
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
50 import uuid
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
51 import urlparse
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
52 import urllib
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
53 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
54 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
55
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
56 try:
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
57 import OpenSSL
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
58 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
59 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
60 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
61
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
62 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
63 from libervia.server.blog import MicroBlog
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
64 from libervia.server import session_iface
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
65
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
66
514
530c88c1deee server_side: plugin refactoring:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
67 # 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
68 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
69
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
70
972
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
71 def quote(value):
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
72 """shortcut to quote an unicode value for URL"""
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
73 return urllib.quote_plus(value.encode('utf-8')).replace('%40','@')
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
74
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
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 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
77 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
78
06a48d805547 server side: make Libervia a Twisted 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 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
80 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
81 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
82
06a48d805547 server side: make Libervia a Twisted 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 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
84 """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
85 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
86 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
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 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
89 """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
90 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
91 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
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 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
94 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
95 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
96
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
97
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
98 class ProtectedFile(static.File):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
99 """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
100
06a48d805547 server side: make Libervia a Twisted 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 def directoryListing(self):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
102 return web_resource.NoResource()
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
103
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
104
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
105 class LiberviaRootResource(ProtectedFile):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
106 """Specialized resource for Libervia root
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
107
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
108 handle redirections declared in sat.conf
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
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
111 def __init__(self, options, *args, **kwargs):
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 @param options(dict): configuration options, same as Libervia.options
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 super(LiberviaRootResource, self).__init__(*args, **kwargs)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
116
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
117 ## redirections
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
118 self.redirections = {}
866
782ba105f5c7 reverted changeset f024fc5744d0 (there is already a default value)
Goffi <goffi@goffi.org>
parents: 865
diff changeset
119 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
120 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
121
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
122 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
123 # 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
124 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
125 # 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
126 # 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
127 try:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
128 new = new_data['url']
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
129 except KeyError:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
130 try:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
131 path = new_data['path']
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
132 except KeyError:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
133 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
134 else:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
135 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
136 else:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
137 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
138 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
139 else:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
140 new = new_data
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
141 new_data = {}
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
142
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
143 # 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
144 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
145 # 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
146 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
147 elif not old.startswith('/'):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
148 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
149 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
150 old = self._normalizeURL(old)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
151 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
152
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
153 # we handle the known URL schemes
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
154 if new_url.scheme == 'xmpp':
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
155 # XMPP URI
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
156 parsed_qs = urlparse.parse_qs(new_url.geturl())
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
157 try:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
158 item = parsed_qs['item'][0]
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
159 if not item:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
160 raise KeyError
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
161 except (IndexError, KeyError):
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
162 raise NotImplementedError(u"only item for PubSub URI is handled for the moment for url_redirections_dict")
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
163 location = "/blog/{profile}/{item}".format(
972
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
164 profile=quote(options['url_redirections_profile']),
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
165 item = urllib.quote_plus(item),
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
166 ).decode('utf-8')
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
167 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
168
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
169 elif new_url.scheme in ('', 'http', 'https'):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
170 # direct redirection
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
171 if new_url.netloc:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
172 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
173 netloc = new_url.netloc))
867
12d0e7bd0dd1 server: fixed encoding issues on url redirection
Goffi <goffi@goffi.org>
parents: 866
diff changeset
174 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
175 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
176
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
177 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
178 # file or directory
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
179 if new_url.netloc:
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
180 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
181 netloc = new_url.netloc))
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
182 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
183 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
184 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
185 # 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
186 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
187 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
188 current = self
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
189 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
190 resource = web_resource.NoResource()
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
191 current.putChild(segment, resource)
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
192 current = resource
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
193 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
194 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
195 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
196 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
197
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
198 else:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
199 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
200
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
201 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
202 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
203 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
204
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
205 # 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
206 del options['url_redirections_dict']
782ba105f5c7 reverted changeset f024fc5744d0 (there is already a default value)
Goffi <goffi@goffi.org>
parents: 865
diff changeset
207 del options['url_redirections_profile']
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
208
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
209 # 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
210 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
211 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
212
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
213 def _normalizeURL(self, url, lower=True):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
214 """Return URL normalized for self.redirections dict
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
215
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
216 @param url(unicode): URL to normalize
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
217 @param lower(bool): lower case of url if True
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
218 @return (str): normalized URL
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
219 """
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
220 if lower:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
221 url = url.lower()
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
222 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
223
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
224 def _getRequestData(self, uri):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
225 """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
226
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
227 @param url(unicode): destination url
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
228 @return (tuple(list[str], str, str, dict): tuple with
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
229 splitted path as in Request.postpath
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
230 uri as in Request.uri
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
231 path as in Request.path
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
232 args as in Request.args
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
233 """
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
234 uri = uri.encode('utf-8')
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
235 # XXX: we reuse code from twisted.web.http.py here
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
236 # as we need to have the same behaviour
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
237 x = uri.split(b'?', 1)
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 if len(x) == 1:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
240 path = uri
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
241 args = {}
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
242 else:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
243 path, argstring = x
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
244 args = http.parse_qs(argstring, 1)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
245
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
246 # 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
247 # (e.g. for blog items)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
248 return self._normalizeURL(path, lower=False).split('/'), uri, path, args
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
249
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
250 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
251 """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
252
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
253 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
254 @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
255 @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
256 @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
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 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
259 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
260 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
261 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
262 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
263 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
264 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
265 old=request.uri.decode('utf-8'),
12d0e7bd0dd1 server: fixed encoding issues on url redirection
Goffi <goffi@goffi.org>
parents: 866
diff changeset
266 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
267 ))
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 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
269 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
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 # 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
274 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
275 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
276 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
277 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
278 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
279 # 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
280 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
281
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 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
283 # 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
284 # 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
285 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
286 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
287 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
288
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
289 def getChild(self, name, request):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
290 resource = super(LiberviaRootResource, self).getChild(name, request)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
291
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
292 if isinstance(resource, web_resource.NoResource):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
293 # if nothing was found, we try our luck with redirections
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
294 # XXX: we want redirections to happen only if everything else failed
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
295 current_url = '/'.join([name] + request.postpath).lower()
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
296 try:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
297 request_data = self.redirections[current_url]
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
298 except KeyError:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
299 # no redirection for this url
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
300 pass
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
301 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
302 return self._redirect(request, request_data)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
303
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
304 return resource
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
305
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
306 def createSimilarFile(self, path):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
307 # 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
308
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
309 f = LiberviaRootResource.__base__(path, self.defaultType, self.ignoredExts, self.registry)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
310 # refactoring by steps, here - constructor should almost certainly take these
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
311 f.processors = self.processors
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
312 f.indexNames = self.indexNames[:]
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
313 f.childNotFound = self.childNotFound
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
314 return f
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
315
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
316
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
317 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
318
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
319 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
320 jsonrpc.JSONRPC.__init__(self)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
321 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
322
06a48d805547 server side: make Libervia a Twisted 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 def asyncBridgeCall(self, method_name, *args, **kwargs):
935
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
324 return self.sat_host.bridgeCall(method_name, *args, **kwargs)
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
325
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
326
06a48d805547 server side: make Libervia a Twisted 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 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
328
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
329 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
330 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
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
332 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
333 self.session = request.getSession()
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
334 profile = session_iface.ISATSession(self.session).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
335 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
336 #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
337 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
338 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
339 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
340 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
341
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
342 def jsonrpc_getVersion(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
343 """Return SàT version"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
344 try:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
345 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
346 except AttributeError:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
347 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
348 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
349
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
350 def jsonrpc_getLiberviaVersion(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
351 """Return Libervia version"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
352 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
353
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
354 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
355 """Disconnect the profile"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
356 sat_session = session_iface.ISATSession(self.session)
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
357 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
358 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
359
06a48d805547 server side: make Libervia a Twisted 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 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
361 """Return all passed args."""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
362 profile = session_iface.ISATSession(self.session).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
363 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
364
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
365 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
366 """Subscribe to contact presence, and add it to the given groups"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
367 profile = session_iface.ISATSession(self.session).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
368 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
369 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
370
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
371 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
372 """Remove contact from contacts list"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
373 profile = session_iface.ISATSession(self.session).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
374 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
375
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
376 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
377 """Update contact's roster item"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
378 profile = session_iface.ISATSession(self.session).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
379 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
380
623
4f7550a083b4 server and browser sides: fixes bad call to "subscription" bridge method
souliane <souliane@mailoo.org>
parents: 613
diff changeset
381 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
382 """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
383 and setup user roster in case of subscription"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
384 profile = session_iface.ISATSession(self.session).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
385 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
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_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
388 """Return list of room already joined by user"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
389 profile = session_iface.ISATSession(self.session).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
390 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
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_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
393 """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
394 @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
395 @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
396 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
397 profile = session_iface.ISATSession(self.session).profile
413
7a8991cda2fa browser_side: display presence with the highest priority
souliane <souliane@mailoo.org>
parents: 408
diff changeset
398 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
399
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
400 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
401 """send message"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
402 profile = session_iface.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
403 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
404
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
405 ## 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
406
921
cf527974a0fa both: renamed psDeleteNode to psNodeDelete to follow backend change
Goffi <goffi@goffi.org>
parents: 920
diff changeset
407 def jsonrpc_psNodeDelete(self, service, node):
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
408 """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
409
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
410 @param service (unicode): service jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
411 @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
412 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
413 profile = session_iface.ISATSession(self.session).profile
921
cf527974a0fa both: renamed psDeleteNode to psNodeDelete to follow backend change
Goffi <goffi@goffi.org>
parents: 920
diff changeset
414 return self.asyncBridgeCall("psNodeDelete", service, node, profile)
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
415
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
416 # 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
417 # """Delete a whole node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
418
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
419 # @param service (unicode): service jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
420 # @param node (unicode): node to delete
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
421 # @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
422 # @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
423 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
424 # profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
425 # 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
426
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
427 # 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
428 # """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
429
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
430 # @param service (unicode): service jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
431 # @param node (unicode): node to delete
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
432 # @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
433 # @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
434 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
435 # profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
436 # 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
437
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
438 ## microblogging ##
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
439
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
440 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
441 """Send microblog data
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 @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
444 @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
445 @param mb_data(dict): microblog data
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
446 @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
447 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
448 profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
449 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
450
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
451 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
452 """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
453
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
454 @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
455 @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
456 @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
457 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
458 profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
459 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
460
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
461 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
462 """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
463
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
464 @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
465 @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
466 @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
467 @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
468 @param rsm (dict): TODO
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
469 @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
470 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
471 profile = session_iface.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
472 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
473
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
474 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
475 """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
476
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
477 @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
478 @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
479 @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
480 @param extra (dict): TODO
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
481 @return (str): RT Deferred session id
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
482 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
483 profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
484 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
485
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
486 def jsonrpc_mbGetFromManyRTResult(self, rt_session):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
487 """Get results from RealTime mbGetFromMany session
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
488
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
489 @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
490 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
491 profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
492 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
493
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
494 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
495 """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
496
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
497 @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
498 @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
499 @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
500 @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
501 @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
502 @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
503 @param profile_key: profile key
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
504 @return (str): RT Deferred session id
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
505 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
506 profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
507 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
508
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
509 def jsonrpc_mbGetFromManyWithCommentsRTResult(self, rt_session):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
510 """Get results from RealTime mbGetFromManyWithComments session
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
511
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
512 @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
513 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
514 profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
515 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
516
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 # 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
519 # """ Send microblog message
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
520 # @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
521 # @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
522 # @param text (unicode): microblog's text
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
523 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
524 # profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
525 # extra['allow_comments'] = 'True'
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
526
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
527 # if not type_: # auto-detect
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
528 # type_ = "PUBLIC" if dest == [] else "GROUP"
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
529
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
530 # 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
531 # if type_ == "PUBLIC":
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
532 # #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
533 # log.debug("sending public blog")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
534 # 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
535 # else:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
536 # log.debug("sending group blog")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
537 # 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
538 # 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
539 # else:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
540 # raise Exception("Invalid data")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
541
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
542 # 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
543 # """Delete a microblog node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
544 # @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
545 # @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
546 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
547 # profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
548 # 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
549
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
550 # 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
551 # """Modify a microblog node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
552 # @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
553 # @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
554 # @param message: new message
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
555 # @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
556 # - 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
557 # - 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
558 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
559 # profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
560 # if comments:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
561 # extra['allow_comments'] = 'True'
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
562 # 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
563
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
564 # 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
565 # """ Send microblog message
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
566 # @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
567 # @param text: comment
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
568 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
569 # profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
570 # if node and text:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
571 # 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
572 # else:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
573 # raise Exception("Invalid data")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
574
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
575 # 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
576 # """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
577 # @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
578 # @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
579 # @return list of microblog data (dict)"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
580 # profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
581 # 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
582 # return d
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
583
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
584 # 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
585 # """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
586 # @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
587 # @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
588 # @return list of couple (microblog data, list of microblog data)"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
589 # profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
590 # 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
591 # return d
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
592
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
593 # 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
594 # """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
595
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
596 # @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
597 # @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
598 # @param rsm (dict): TODO
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
599 # @return: dict{unicode: list[dict])
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
600 # key: publisher's jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
601 # value: list of microblog data (dict)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
602 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
603 # profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
604 # if rsm is None:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
605 # 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
606 # 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
607 # 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
608 # return d
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
609
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
610 # 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
611 # """Get all comments of given node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
612 # @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
613 # @param node: comments node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
614 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
615 # profile = session_iface.ISATSession(self.session).profile
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
616 # if rsm is None:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
617 # 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
618 # 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
619 # 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
620
427
b5b440e6ea16 server + browser side, getPresenceStatuses has been renamed
Goffi <goffi@goffi.org>
parents: 421
diff changeset
621 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
622 """Get Presence information for connected contacts"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
623 profile = session_iface.ISATSession(self.session).profile
427
b5b440e6ea16 server + browser side, getPresenceStatuses has been renamed
Goffi <goffi@goffi.org>
parents: 421
diff changeset
624 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
625
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
626 def jsonrpc_historyGet(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
627 """Return history for the from_jid/to_jid couple"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
628 sat_session = session_iface.ISATSession(self.session)
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
629 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
630 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
631 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
632 # 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
633 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
634 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
635 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
636 return {}
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
637 d = self.asyncBridgeCall("historyGet", from_jid, to_jid, size, between, search, profile)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
638
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
639 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
640 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
641 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
642 #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
643 # and txJsonRPC doesn't accept D-Bus types, resulting in a empty query
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
644 uuid, timestamp, from_jid, to_jid, message, subject, mess_type, extra = line
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
645 result.append((unicode(uuid), float(timestamp), unicode(from_jid), unicode(to_jid), dict(message), dict(subject), unicode(mess_type), dict(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
646 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
647 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
648 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
649
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
650 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
651 """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
652
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
653 @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
654 @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
655 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
656 profile = session_iface.ISATSession(self.session).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
657 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
658 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
659
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
660 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
661 """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
662
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
663 @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
664 @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
665 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
666 profile = session_iface.ISATSession(self.session).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
667 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
668 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
669 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
670
06a48d805547 server side: make Libervia a Twisted 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 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
672 """Quit a Multi-User Chat room"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
673 profile = session_iface.ISATSession(self.session).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
674 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
675 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
676 except:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
677 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
678 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
679 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
680
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
681 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
682 """Return list of room already joined by user"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
683 profile = session_iface.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
684 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
685
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
686 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
687 """@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
688 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
689 return d
7a9c7b9f6a28 browser_side: use host.default_muc instead of C.DEFAULT_MUC
souliane <souliane@mailoo.org>
parents: 689
diff changeset
690
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
691 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
692 """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
693
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
694 @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
695 @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
696 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
697 profile = session_iface.ISATSession(self.session).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
698 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
699
06a48d805547 server side: make Libervia a Twisted 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 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
701 """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
702 _join = os.path.join
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
703 _media_dir = _join(self.sat_host.media_dir, '')
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
704 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
705
06a48d805547 server side: make Libervia a Twisted 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 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
707 """Tell to the server that we are ready to start the game"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
708 profile = session_iface.ISATSession(self.session).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
709 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
710
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
711 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
712 """Tell to the server the cards we want to put on the table"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
713 profile = session_iface.ISATSession(self.session).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
714 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
715
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
716 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
717 """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
718
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
719 @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
720 @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
721 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
722 profile = session_iface.ISATSession(self.session).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
723 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
724
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
725 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
726 """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
727
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
728 @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
729 @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
730 @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
731 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
732 raise exceptions.PermissionError("Trying to access unallowed data (hack attempt ?)")
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
733 profile = session_iface.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
734 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
735 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
736 except Exception as e:
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
737 raise failure.Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(e)))
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
738
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
739 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
740 """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
741
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
742 @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
743 @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
744 @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
745 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
746 raise exceptions.PermissionError("Trying to access unallowed data (hack attempt ?)")
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
747 profile = session_iface.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
748 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
749 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
750 except Exception as e:
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
751 raise failure.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
752
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
753 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
754 """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
755 @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
756 @return: id to retrieve the profile"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
757 profile = session_iface.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
758 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
759
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
760 @defer.inlineCallbacks
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
761 def jsonrpc_avatarGet(self, entity, cache_only, hash_only):
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
762 session_data = session_iface.ISATSession(self.session)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
763 profile = session_data.profile
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
764 # profile_uuid = session_data.uuid
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
765 avatar = yield self.asyncBridgeCall("avatarGet", entity, cache_only, hash_only, profile)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
766 if hash_only:
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
767 defer.returnValue(avatar)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
768 else:
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
769 filename = os.path.basename(avatar)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
770 avatar_url = os.path.join(C.CACHE_DIR, session_data.uuid, filename)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
771 defer.returnValue(avatar_url)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
772
391
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
773 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
774 """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
775 @return: XML string of the XMLUI"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
776 profile = session_iface.ISATSession(self.session).profile
391
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
777 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
778
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 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
780 """Return the parameters XML for profile"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
781 profile = session_iface.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
782 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
783
06a48d805547 server side: make Libervia a Twisted 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 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
785 """Return the parameter value for profile"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
786 profile = session_iface.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
787 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
788 # 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
789 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
790 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
791 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
792 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
793 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
794 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
795
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
796 def jsonrpc_setParam(self, name, value, category):
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
797 profile = session_iface.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
798 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
799
06a48d805547 server side: make Libervia a Twisted 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 def jsonrpc_launchAction(self, callback_id, data):
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
801 #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
802 # a security system with authorised callback_id must be implemented, similar to the one for authorised params
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
803 profile = session_iface.ISATSession(self.session).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
804 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
805 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
806
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
807 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
808 """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
809 @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
810 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
811 profile = session_iface.ISATSession(self.session).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
812 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
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_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
815 """@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
816 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
817 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
818
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 427
diff changeset
819 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
820 """ 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
821 @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
822 @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
823 @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
824 @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
825 @return: converted text """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
826 profile = session_iface.ISATSession(self.session).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
827 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
828
520
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
829 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
830 """Get the last active resource of that contact."""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
831 profile = session_iface.ISATSession(self.session).profile
520
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
832 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
833
751
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
834 def jsonrpc_getFeatures(self):
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
835 """Return the available features in the backend for profile"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
836 profile = session_iface.ISATSession(self.session).profile
751
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
837 return self.sat_host.bridge.getFeatures(profile)
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
838
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
839 def jsonrpc_skipOTR(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
840 """Tell the backend to leave OTR handling to Libervia."""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
841 profile = session_iface.ISATSession(self.session).profile
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
842 return self.sat_host.bridge.skipOTR(profile)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
843
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
844
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
845 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
846
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
847 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
848 """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
849
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
850 @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
851 @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
852 @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
853 """
555
db1b330c1eb1 server_side: set the connection attempt timeout to the bridge timeout (2 minutes)
souliane <souliane@mailoo.org>
parents: 554
diff changeset
854 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
855 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
856
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
857 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
858 """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
859
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
860 @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
861 """
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
862 try:
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
863 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
864 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
865 return
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
866 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
867 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
868 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
869
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
870 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
871 """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
872
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
873 @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
874 @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
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 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
877
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
878 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
879 """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
880
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
881 @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
882 @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
883 """
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
884 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
885
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
886
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
887 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
888 """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
889 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
890
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
891 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
892 JSONRPCMethodManager.__init__(self, sat_host)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
893 self.profiles_waiting = {}
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
894 self.request = 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
895
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
896 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
897 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
898 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
899 - 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
900 - 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
901 - 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
902 """
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
903 if request.postpath == ['login']:
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
904 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
905 _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
906 parsed = jsonrpclib.loads(request.content.read())
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
907 method = parsed.get("method") # pylint: disable=E1103
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
908 if method not in ['getSessionMetadata', 'registerParams', 'menusGet']:
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
909 #if we don't call these methods, we need to be identified
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
910 profile = session_iface.ISATSession(_session).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
911 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
912 #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
913 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
914 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
915 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
916 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
917
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
918 def loginOrRegister(self, request):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
919 """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
920
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
921 @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
922 @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
923 - 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
924 - 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
925 """
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
926 try:
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
927 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
928 except KeyError:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
929 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
930
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
931 if submit_type == 'register':
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
932 self._registerNewAccount(request)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
933 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
934 elif submit_type == 'login':
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
935 self._loginAccount(request)
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
936 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
937 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
938
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
939 @defer.inlineCallbacks
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
940 def _registerNewAccount(self, request):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
941 try:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
942 login = request.args['register_login'][0]
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
943 password = request.args['register_password'][0]
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
944 email = request.args['email'][0]
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
945 except KeyError:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
946 request.write(C.BAD_REQUEST)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
947 request.finish()
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
948 return
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
949 status = yield self.sat_host.registerNewAccount(request, login, password, email)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
950 request.write(status)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
951 request.finish()
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
952
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
953 @defer.inlineCallbacks
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
954 def _loginAccount(self, request):
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
955 """Try to authenticate the user with the request information.
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
956
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
957 will write to request a constant indicating the state:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
958 - C.PROFILE_LOGGED: profile is connected
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
959 - C.PROFILE_LOGGED_EXT_JID: profile is connected and an external jid has been used
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
960 - C.SESSION_ACTIVE: session was already active
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
961 - 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
962 - 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
963 - C.XMPP_AUTH_ERROR: the profile is authenticated but the XMPP password is wrong
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
964 - C.ALREADY_WAITING: a request has already been submitted for this profil, C.PROFILE_LOGGED_EXT_JID)e
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
965 - C.NOT_CONNECTED: connection has not been established
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
966 the request will then be finished
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
967 @param request: request of the register form
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
968 """
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
969 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
970 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
971 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
972 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
973 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
974 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
975 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
976
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
977 assert login
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
978
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
979 try:
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
980 status = yield self.sat_host.connect(request, login, password)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
981 except (exceptions.DataError,
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
982 exceptions.ProfileUnknownError,
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
983 exceptions.PermissionError):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
984 request.write(C.PROFILE_AUTH_ERROR)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
985 request.finish()
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
986 return
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
987 except exceptions.NotReady:
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
988 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
989 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
990 return
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
991 except exceptions.TimeOutError:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
992 request.write(C.NO_REPLY)
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
993 request.finish()
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
994 return
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
995 except exceptions.InternalError as e:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
996 request.write(e.message)
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
997 request.finish()
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
998 return
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
999 except exceptions.ConflictError:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1000 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
1001 request.finish()
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1002 return
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1003 except ValueError as e:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1004 if e.message in (C.PROFILE_AUTH_ERROR, C.XMPP_AUTH_ERROR):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1005 request.write(e.message)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1006 request.finish()
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1007 return
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1008 else:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1009 raise 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
1010
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1011 assert status
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1012 request.write(status)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1013 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
1014
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1015 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
1016 _session = self.request.getSession()
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1017 profile = session_iface.ISATSession(_session).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
1018 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
1019
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1020 def jsonrpc_connect(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
1021 _session = self.request.getSession()
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1022 profile = session_iface.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
1023 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
1024 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
1025 self.waiting_profiles.setRequest(self.request, profile)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1026 self.sat_host.bridge.connect(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
1027 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
1028
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1029 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
1030 """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
1031
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1032 @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
1033 "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
1034 "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
1035 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
1036 "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
1037 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
1038 @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
1039 - registered:
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1040 - message:
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1041 """
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1042 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
1043 _session = self.request.getSession()
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1044 profile = session_iface.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
1045 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
1046 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
1047 else:
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1048 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
1049 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
1050 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
1051 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
1052
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1053 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
1054 """Register the frontend specific parameters"""
696
c2f22ca12e23 browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents: 694
diff changeset
1055 # params = """<params><individual>...</category></individual>"""
c2f22ca12e23 browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents: 694
diff changeset
1056 # 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
1057
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1058 def jsonrpc_menusGet(self):
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1059 """Return the parameters XML for profile"""
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1060 # XXX: we put this method in Register because we get menus before being logged
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1061 return self.sat_host.bridge.menusGet('', C.SECURITY_LIMIT)
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1062
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
1063 def _getSecurityWarning(self):
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1064 """@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
1065 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
1066 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
1067 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
1068
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1069 if self.sat_host.options['connection_type'] == 'both':
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1070 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
1071 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
1072 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
1073 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
1074 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
1075 else:
841
4a01be961fd2 server: removed unused %(url)s for formatting HTTP warning message
Goffi <goffi@goffi.org>
parents: 823
diff changeset
1076 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
1077
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
1078 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
1079
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
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1081 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
1082
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1083 def __init__(self, sat_host):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1084 web_resource.Resource.__init__(self)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1085 self.register = None
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1086 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
1087 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
1088 # 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
1089 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
1090
06a48d805547 server side: make Libervia a Twisted 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 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
1092 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
1093
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1094 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
1095 """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
1096 @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
1097 _session = self.request.getSession()
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1098 profile = session_iface.ISATSession(_session).profile
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1099 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
1100 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
1101 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
1102 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
1103 #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
1104 del self.queue[profile]
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1105 _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
1106
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
1107 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
1108 _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
1109 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
1110 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
1111 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
1112 log.info(u"[%s] disconnected" % (profile,))
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1113 try:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1114 _session.expire()
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1115 except KeyError:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1116 # FIXME: happen if session is ended using login page
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1117 # when pyjamas page is also launched
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1118 log.warning(u'session is already expired')
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
1119 except IndexError:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
1120 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
1121
06a48d805547 server side: make Libervia a Twisted 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 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
1123 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
1124 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
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 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
1127 """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
1128 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
1129 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
1130 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
1131 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
1132 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
1133 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
1134 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
1135 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
1136 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
1137 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
1138 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
1139 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
1140 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
1141 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
1142
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
1143 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
1144 """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
1145
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
1146 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
1147 @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
1148 @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
1149 @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
1150 @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
1151 """
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
1152 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
1153 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
1154 # 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
1155 # 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
1156 # 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
1157 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
1158 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
1159 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
1160 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
1161 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
1162 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
1163 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
1164 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
1165 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
1166 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
1167 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
1168
710
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1169 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
1170 """Connection is done.
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1171
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1172 @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
1173 @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
1174 """
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1175 # FIXME: _logged should not be called from here, check this code
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1176 # FIXME: check if needed to connect with external jid
710
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1177 # jid_s is handled in QuickApp.connectionHandler already
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1178 # assert self.register # register must be plugged
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1179 # request = self.sat_host.waiting_profiles.getRequest(profile)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1180 # if request:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1181 # self.sat_host._logged(profile, 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
1182
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1183 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
1184 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
1185 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
1186 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
1187 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
1188 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
1189 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
1190 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
1191 else:
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1192 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
1193 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
1194 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
1195
06a48d805547 server side: make Libervia a Twisted 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 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
1197 """
06a48d805547 server side: make Libervia a Twisted 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 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
1199 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1200 _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
1201 parsed = jsonrpclib.loads(request.content.read())
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1202 profile = session_iface.ISATSession(_session).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
1203 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
1204 #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
1205 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
1206 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
1207 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
1208 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
1209
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1210
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1211 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
1212 """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
1213 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
1214 isLeaf = True
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1215 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
1216
06a48d805547 server side: make Libervia a Twisted 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 def __init__(self, sat_host):
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1218 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
1219 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
1220 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
1221
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1222 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
1223 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
1224
06a48d805547 server side: make Libervia a Twisted 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 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
1226 """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
1227 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
1228
06a48d805547 server side: make Libervia a Twisted 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 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
1230 """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
1231 @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
1232 @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
1233 @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
1234 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
1235 """
06a48d805547 server side: make Libervia a Twisted 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 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
1237
06a48d805547 server side: make Libervia a Twisted 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 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
1239 """
06a48d805547 server side: make Libervia a Twisted 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 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
1241 - 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
1242 - 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
1243 - 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
1244 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1245 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
1246 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
1247 #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
1248 # (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
1249 # 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
1250 # (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
1251
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1252 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
1253 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
1254
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1255 def finish(d):
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1256 error = isinstance(d, Exception) or isinstance(d, failure.Failure)
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1257 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
1258 # 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
1259 # 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
1260 # 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
1261 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
1262
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1263 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
1264 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
1265 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
1266
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1267
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1268 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
1269 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
1270
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1271 def _getFileName(self, request):
394
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 391
diff changeset
1272 extension = os.path.splitext(request.args['filename'][0])[1]
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 391
diff changeset
1273 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
1274
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1275 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
1276 """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
1277 @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
1278 @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
1279 @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
1280 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
1281 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1282 profile = session_iface.ISATSession(request.getSession()).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
1283 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
1284
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1285
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1286 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
1287 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
1288
06a48d805547 server side: make Libervia a Twisted 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 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
1290 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
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 _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
1293 """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
1294 @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
1295 @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
1296 @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
1297 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
1298 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1299 profile = session_iface.ISATSession(request.getSession()).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
1300 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
1301
06a48d805547 server side: make Libervia a Twisted 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
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1303 class LiberviaPage(web_resource.Resource):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1304 isLeaf = True # we handle subpages ourself
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1305 named_pages = {}
925
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1306 uri_callbacks = {}
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1307
978
c8cafe316f6f pages: removed trailing_slash option:
Goffi <goffi@goffi.org>
parents: 974
diff changeset
1308 def __init__(self, host, root_dir, url, name=None, redirect=None, access=None, parse_url=None,
931
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1309 prepare_render=None, render=None, template=None, on_data_post=None):
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1310 """initiate LiberviaPages
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1311
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1312 LiberviaPages are the main resources of Libervia, using easy to set python files
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1313 The arguments are the variables found in page_meta.py
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1314 @param host(Libervia): the running instance of Libervia
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1315 @param root_dir(unicode): aboslute file path of the page
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1316 @param url(unicode): relative URL to the page
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1317 this URL may not be valid, as pages may require path arguments
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1318 @param name(unicode, None): if not None, a unique name to identify the page
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1319 can then be used for e.g. redirection
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1320 "/" is not allowed in names (as it can be used to construct URL paths)
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1321 @param redirect(unicode, None): if not None, this page will be redirected. A redirected
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1322 parameter is used as in self.pageRedirect. parse_url will not be skipped
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1323 using this redirect parameter is called "full redirection"
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1324 using self.pageRedirect is called "partial redirection" (because some rendering method
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1325 can still be used, e.g. parse_url)
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1326 @param access(unicode, None): permission needed to access the page
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1327 None means public access.
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1328 Pages inherit from parent pages: e.g. if a "settings" page is restricted to admins,
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1329 and if "settings/blog" is public, it still can only be accessed by admins.
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1330 see C.PAGES_ACCESS_* for details
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1331 @param parse_url(callable, None): if set it will be called to handle the URL path
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1332 after this method, the page will be rendered if noting is left in path (request.postpath)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1333 else a the request will be transmitted to a subpage
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1334 @param prepare_render(callable, None): if set, will be used to prepare the rendering
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1335 that often means gathering data using the bridge
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1336 @param render(callable, None): if not template is set, this method will be called and
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1337 what it returns will be rendered.
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1338 This method is mutually exclusive with template and must return a unicode string.
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1339 @param template(unicode, None): path to the template to render.
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1340 This method is mutually exclusive with render
931
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1341 @param on_data_post(callable, None): method to call when data is posted
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1342 None if not post is handled
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1343 on_data_post can return a string with following value:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1344 - C.POST_NO_CONFIRM: confirm flag will not be set
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1345 """
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1346
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1347 web_resource.Resource.__init__(self)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1348 self.host = host
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1349 self.root_dir = root_dir
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1350 self.url = url
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1351 if name is not None:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1352 if name in self.named_pages:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1353 raise exceptions.ConflictError(_(u'a Libervia page named "{}" already exists'.format(name)))
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1354 if u'/' in name:
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1355 raise ValueError(_(u'"/" is not allowed in page names'))
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1356 if not name:
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1357 raise ValueError(_(u"a page name can't be empty"))
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1358 self.named_pages[name] = self
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1359 if access is None:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1360 access = C.PAGES_ACCESS_PUBLIC
922
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1361 if access not in (C.PAGES_ACCESS_PUBLIC, C.PAGES_ACCESS_PROFILE, C.PAGES_ACCESS_NONE):
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1362 raise NotImplementedError(_(u"{} access is not implemented yet").format(access))
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1363 self.access = access
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1364 if redirect is not None:
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1365 # only page access and name make sense in case of full redirection
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1366 if not all(lambda x: x is not None
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1367 for x in (parse_url, prepare_render, render, template)):
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1368 raise ValueError(_(u"you can't use full page redirection with other rendering method,"
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1369 u"check self.pageRedirect if you need to use them"))
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1370 self.redirect = redirect
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1371 else:
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1372 self.redirect = None
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1373 self.parse_url = parse_url
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1374 self.prepare_render = prepare_render
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1375 self.template = template
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1376 self.render_method = render
931
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1377 self.on_data_post = on_data_post
922
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1378 if access == C.PAGES_ACCESS_NONE:
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1379 # none pages just return a 404, no further check is needed
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1380 return
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1381 if template is None:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1382 if not callable(render):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1383 log.error(_(u"render must be implemented and callable if template is not set"))
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1384 else:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1385 if render is not None:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1386 log.error(_(u"render can't be used at the same time as template"))
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1387 if parse_url is not None and not callable(parse_url):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1388 log.error(_(u"parse_url must be a callable"))
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1389
925
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1390 @classmethod
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1391 def importPages(cls, host, parent=None, path=None):
937
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1392 """Recursively import Libervia pages"""
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1393 if path is None:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1394 path = []
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1395 if parent is None:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1396 root_dir = os.path.join(os.path.dirname(libervia.__file__), C.PAGES_DIR)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1397 parent = host
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1398 else:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1399 root_dir = parent.root_dir
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1400 for d in os.listdir(root_dir):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1401 dir_path = os.path.join(root_dir, d)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1402 if not os.path.isdir(dir_path):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1403 continue
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1404 meta_path = os.path.join(dir_path, C.PAGES_META_FILE)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1405 if os.path.isfile(meta_path):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1406 page_data = {}
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1407 new_path = path + [d]
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1408 # we don't want to force the presence of __init__.py
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1409 # so we use execfile instead of import.
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1410 # TODO: when moved to Python 3, __init__.py is not mandatory anymore
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1411 # so we can switch to import
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1412 execfile(meta_path, page_data)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1413 resource = LiberviaPage(
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1414 host,
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1415 dir_path,
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1416 u'/' + u'/'.join(new_path),
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1417 name=page_data.get('name'),
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1418 redirect=page_data.get('redirect'),
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1419 access=page_data.get('access'),
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1420 parse_url=page_data.get('parse_url'),
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1421 prepare_render=page_data.get('prepare_render'),
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1422 render=page_data.get('render'),
931
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1423 template=page_data.get('template'),
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1424 on_data_post=page_data.get('on_data_post'))
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1425 parent.putChild(d, resource)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1426 log.info(u"Added /{path} page".format(path=u'[...]/'.join(new_path)))
925
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1427 if 'uri_handlers' in page_data:
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1428 if not isinstance(page_data, dict):
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1429 log.error(_(u'uri_handlers must be a dict'))
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1430 else:
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1431 for uri_tuple, cb_name in page_data['uri_handlers'].iteritems():
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1432 if len(uri_tuple) != 2 or not isinstance(cb_name, basestring):
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1433 log.error(_(u"invalid uri_tuple"))
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1434 continue
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1435 log.info(_(u'setting {}/{} URIs handler').format(*uri_tuple))
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1436 try:
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1437 cb = page_data[cb_name]
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1438 except KeyError:
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1439 log.error(_(u'missing {name} method to handle {1}/{2}').format(
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1440 name = cb_name, *uri_tuple))
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1441 continue
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1442 else:
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1443 cls.registerURI(uri_tuple, cb, new_path)
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1444
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1445 LiberviaPage.importPages(host, resource, new_path)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1446
925
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1447 @classmethod
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1448 def registerURI(cls, uri_tuple, get_uri_cb, pre_path):
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1449 """register a URI handler
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1450
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1451 @param uri_tuple(tuple[unicode, unicode]): type or URIs handler
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1452 type/subtype as returned by tools/common/parseXMPPUri
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1453 @param get_uri_cb(callable): method which take uri_data dict as only argument
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1454 and return path with correct arguments relative to page itself
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1455 @param pre_path(list[unicode]): prefix path to reference the handler page
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1456 """
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1457 if uri_tuple in cls.uri_callbacks:
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1458 log.info(_(u"{}/{} URIs are already handled, replacing by the new handler").format(*uri_tuple))
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1459 cls.uri_callbacks[uri_tuple] = {u'callback': get_uri_cb,
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1460 u'pre_path': pre_path}
e00151140f77 server (pages): URIs handling:
Goffi <goffi@goffi.org>
parents: 924
diff changeset
1461
927
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1462 def getPagePathFromURI(self, uri):
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1463 """Retrieve page URL from xmpp: URI
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1464
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1465 @param uri(unicode): URI with a xmpp: scheme
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1466 @return (unicode,None): absolute path (starting from root "/") to page handling the URI
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1467 None is returned if not page has been registered for this URI
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1468 """
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1469 uri_data = common_uri.parseXMPPUri(uri)
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1470 try:
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1471 callback_data = self.uri_callbacks[uri_data['type'], uri_data.get('sub_type')]
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1472 except KeyError:
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1473 return
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1474 else:
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1475 url = os.path.join(u'/', u'/'.join(callback_data['pre_path']), callback_data['callback'](self, uri_data))
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1476 return url
bb4dfc2802c0 server (pages): added getPagePathFromURI method to retrieve page handling an URI
Goffi <goffi@goffi.org>
parents: 926
diff changeset
1477
936
78692d47340d server (pages): added getPageByName
Goffi <goffi@goffi.org>
parents: 935
diff changeset
1478 def getPageByName(self, name):
78692d47340d server (pages): added getPageByName
Goffi <goffi@goffi.org>
parents: 935
diff changeset
1479 """retrieve page instance from its name
78692d47340d server (pages): added getPageByName
Goffi <goffi@goffi.org>
parents: 935
diff changeset
1480
78692d47340d server (pages): added getPageByName
Goffi <goffi@goffi.org>
parents: 935
diff changeset
1481 @param name(unicode): name of the page
78692d47340d server (pages): added getPageByName
Goffi <goffi@goffi.org>
parents: 935
diff changeset
1482 @return (LiberviaPage): page instance
78692d47340d server (pages): added getPageByName
Goffi <goffi@goffi.org>
parents: 935
diff changeset
1483 @raise KeyError: the page doesn't exist
78692d47340d server (pages): added getPageByName
Goffi <goffi@goffi.org>
parents: 935
diff changeset
1484 """
78692d47340d server (pages): added getPageByName
Goffi <goffi@goffi.org>
parents: 935
diff changeset
1485 return self.named_pages[name]
78692d47340d server (pages): added getPageByName
Goffi <goffi@goffi.org>
parents: 935
diff changeset
1486
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1487 def getPageRedirectURL(self, request, page_name=u'login', url=None):
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1488 """generate URL for a page with redirect_url parameter set
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1489
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1490 mainly used for login page with redirection to current page
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1491 @param request(server.Request): current HTTP request
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1492 @param page_name(unicode): name of the page to go
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1493 @param url(None, unicode): url to redirect to
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1494 None to use request path (i.e. current page)
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1495 @return (unicode): URL to use
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1496 """
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1497 return u'{root_url}?redirect_url={redirect_url}'.format(
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1498 root_url = self.getPageByName(page_name).url,
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1499 redirect_url=urllib.quote_plus(request.uri) if url is None else url.encode('utf-8'))
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1500
972
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1501 def getURL(self, *args):
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1502 """retrieve URL of the page set arguments
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1503
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1504 *args(list[unicode]): argument to add to the URL as path elements
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1505 """
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1506 url_args = [quote(a) for a in args]
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1507 return os.path.join(self.url, *url_args)
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1508
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1509 def getChildWithDefault(self, path, request):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1510 # we handle children ourselves
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1511 raise exceptions.InternalError(u"this method should not be used with LiberviaPage")
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1512
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1513 def nextPath(self, request):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1514 """get next URL path segment, and update request accordingly
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1515
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1516 will move first segment of postpath in prepath
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1517 @param request(server.Request): current HTTP request
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1518 @return (unicode): unquoted segment
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1519 @raise IndexError: there is no segment left
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1520 """
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1521 pathElement = request.postpath.pop(0)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1522 request.prepath.append(pathElement)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1523 return urllib.unquote(pathElement).decode('utf-8')
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1524
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1525 def HTTPRedirect(self, request, url):
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1526 """redirect to an URL using HTTP redirection
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1527
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1528 @param request(server.Request): current HTTP request
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1529 @param url(unicode): url to redirect to
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1530 """
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1531
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1532 web_util.redirectTo(url.encode('utf-8'), request)
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1533 request.finish()
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1534 raise failure.Failure(exceptions.CancelError(u'HTTP redirection is used'))
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1535
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1536 def redirectOrContinue(self, request, redirect_arg=u'redirect_url'):
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1537 """helper method to redirect a page to an url given as arg
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1538
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1539 if the arg is not present, the page will continue normal workflow
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1540 @param request(server.Request): current HTTP request
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1541 @param redirect_arg(unicode): argument to use to get redirection URL
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1542 @interrupt: redirect the page to requested URL
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1543 @interrupt pageError(C.HTTP_BAD_REQUEST): empty or non local URL is used
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1544 """
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1545 try:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1546 url = self.getPostedData(request, 'redirect_url')
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1547 except KeyError:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1548 pass
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1549 else:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1550 # a redirection is requested
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1551 if not url or url[0] != u'/':
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1552 # we only want local urls
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1553 self.pageError(request, C.HTTP_BAD_REQUEST)
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1554 else:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1555 self.HTTPRedirect(request, url)
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1556
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1557 def pageRedirect(self, page_path, request, skip_parse_url=True):
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1558 """redirect a page to a named page
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1559
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1560 the workflow will continue with the workflow of the named page,
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1561 skipping named page's parse_url method if it exist.
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1562 If you want to do a HTTP redirection, use HTTPRedirect
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1563 @param page_path(unicode): path to page (elements are separated by "/"):
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1564 if path starts with a "/":
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1565 path is a full path starting from root
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1566 else:
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1567 - first element is name as registered in name variable
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1568 - following element are subpages path
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1569 e.g.: "blog" redirect to page named "blog"
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1570 "blog/atom.xml" redirect to atom.xml subpage of "blog"
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1571 "/common/blog/atom.xml" redirect to the page at the fiven full path
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1572 @param request(server.Request): current HTTP request
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1573 @param skip_parse_url(bool): if True, parse_url method on redirect page will be skipped
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1574 @raise KeyError: there is no known page with this name
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1575 """
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1576 # FIXME: render non LiberviaPage resources
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1577 path = page_path.rstrip(u'/').split(u'/')
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1578 if not path[0]:
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1579 redirect_page = self.host.root
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1580 else:
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1581 redirect_page = self.named_pages[path[0]]
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1582
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1583 for subpage in path[1:]:
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1584 if redirect_page is self.host.root:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1585 redirect_page = redirect_page.children[subpage]
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1586 else:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1587 redirect_page = redirect_page.original.children[subpage]
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1588
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1589 redirect_page.renderPage(request, skip_parse_url=True)
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1590 raise failure.Failure(exceptions.CancelError(u'page redirection is used'))
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1591
922
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1592 def pageError(self, request, code=C.HTTP_NOT_FOUND):
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1593 """generate an error page and terminate the request
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1594
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1595 @param request(server.Request): HTTP request
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1596 @param core(int): error code to use
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1597 """
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1598 template = u'error/' + unicode(code) + '.html'
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1599
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1600 request.setResponseCode(code)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1601
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1602 rendered = self.host.renderer.render(
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1603 template,
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1604 root_path = '/templates/',
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1605 error_code = code,
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1606 **request.template_data)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1607
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1608 self.writeData(rendered, request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1609 raise failure.Failure(exceptions.CancelError(u'error page is used'))
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1610
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1611 def writeData(self, data, request):
937
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1612 """write data to transport and finish the request"""
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1613 if data is None:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1614 self.pageError(request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1615 request.write(data.encode('utf-8'))
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1616 request.finish()
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1617
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1618 def _subpagesHandler(self, dummy, request):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1619 """render subpage if suitable
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1620
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1621 this method checks if there is still an unmanaged part of the path
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1622 and check if it corresponds to a subpage. If so, it render the subpage
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1623 else it render a NoResource.
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1624 If there is no unmanaged part of the segment, current page workflow is pursued
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1625 """
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1626 if request.postpath:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1627 subpage = self.nextPath(request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1628 try:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1629 child = self.children[subpage]
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1630 except KeyError:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1631 self.pageError(request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1632 else:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1633 child.render(request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1634 raise failure.Failure(exceptions.CancelError(u'subpage page is used'))
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1635
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1636 def _prepare_render(self, dummy, request):
926
612e33fd32a8 server (pages): fixed _prepare_render handling
Goffi <goffi@goffi.org>
parents: 925
diff changeset
1637 return defer.maybeDeferred(self.prepare_render, self, request)
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1638
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1639 def _render_method(self, dummy, request):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1640 return defer.maybeDeferred(self.render_method, self, request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1641
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1642 def _render_template(self, dummy, request):
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1643 template_data = request.template_data
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1644
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1645 # if confirm variable is set in case of successfuly data post
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1646 session_data = self.host.getSessionData(request, session_iface.ISATSession)
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1647 if session_data.popPageFlag(self, C.FLAG_CONFIRM):
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1648 template_data[u'confirm'] = True
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1649
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1650 return self.host.renderer.render(
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1651 self.template,
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1652 root_path = '/templates/',
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1653 media_path = '/' + C.MEDIA_DIR,
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1654 **template_data)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1655
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1656 def _renderEb(self, failure_, request):
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1657 """don't raise error on CancelError"""
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1658 failure_.trap(exceptions.CancelError)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1659
937
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1660 def _internalError(self, failure_, request):
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1661 """called if an error is not catched"""
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1662 log.error(_(u"Uncatched error for HTTP request on {url}: {msg}").format(
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1663 url = request.URLPath(),
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1664 msg = failure_))
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1665 self.pageError(request, C.HTTP_INTERNAL_ERROR)
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1666
956
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1667 def _on_data_post_redirect(self, ret, request):
968
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1668 """called when page's on_data_post has been done successfuly
956
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1669
968
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1670 This will do a Post/Redirect/Get pattern.
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1671 this method redirect to the same page or to request.data['post_redirect_page']
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1672 post_redirect_page can be either a page or a tuple with page as first item, then a list of unicode arguments to append to the url.
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1673 if post_redirect_page is not used, initial request.uri (i.e. the same page as where the data have been posted) will be used for redirection.
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1674 HTTP status code "See Other" (303) is used as it is the recommanded code in this case.
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1675 @param ret(None, unicode, iterable): on_data_post return value
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1676 see LiberviaPage.__init__ on_data_post docstring
956
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1677 """
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1678 if ret is None:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1679 ret = ()
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1680 elif isinstance(ret, basestring):
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1681 ret = (ret,)
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1682 else:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1683 ret = tuple(ret)
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1684 raise NotImplementedError(_(u'iterable in on_data_post return value is not used yet'))
957
67bf14c91d5c server (pages): added a confirm flag on successful post:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
1685 session_data = self.host.getSessionData(request, session_iface.ISATSession)
974
4aa38c49bff7 pages: fixed use of request data in _on_data_post_redirect
Goffi <goffi@goffi.org>
parents: 972
diff changeset
1686 request_data = self.getRData(request)
4aa38c49bff7 pages: fixed use of request data in _on_data_post_redirect
Goffi <goffi@goffi.org>
parents: 972
diff changeset
1687 if 'post_redirect_page' in request_data:
4aa38c49bff7 pages: fixed use of request data in _on_data_post_redirect
Goffi <goffi@goffi.org>
parents: 972
diff changeset
1688 redirect_page_data = request_data['post_redirect_page']
968
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1689 if isinstance(redirect_page_data, tuple):
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1690 redirect_page = redirect_page_data[0]
972
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1691 redirect_page_args = redirect_page_data[1:]
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1692 redirect_uri = redirect_page.getURL(*redirect_page_args)
968
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1693 else:
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1694 redirect_page = redirect_page_data
972
c4e58c4dba75 server: getURL + minor improvments:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
1695 redirect_uri = redirect_page.url
968
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1696 else:
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1697 redirect_page = self
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1698 redirect_uri = request.uri
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1699
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1700 if not C.POST_NO_CONFIRM in ret:
968
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1701 session_data.setPageFlag(redirect_page, C.FLAG_CONFIRM)
956
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1702 request.setResponseCode(C.HTTP_SEE_OTHER)
968
4d37b23777c3 pages (core, tickets/new): replaced post_redirect_uri mechanism by post_redirect_page:
Goffi <goffi@goffi.org>
parents: 966
diff changeset
1703 request.setHeader("location", redirect_uri)
955
4f7cb6335a33 server(pages): do Post/Redirect/Get pattern when on_data_post is used (avoid double posting on refresh)
Goffi <goffi@goffi.org>
parents: 950
diff changeset
1704 request.finish()
4f7cb6335a33 server(pages): do Post/Redirect/Get pattern when on_data_post is used (avoid double posting on refresh)
Goffi <goffi@goffi.org>
parents: 950
diff changeset
1705 raise failure.Failure(exceptions.CancelError(u'Post/Redirect/Get is used'))
4f7cb6335a33 server(pages): do Post/Redirect/Get pattern when on_data_post is used (avoid double posting on refresh)
Goffi <goffi@goffi.org>
parents: 950
diff changeset
1706
956
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1707 def _on_data_post(self, dummy, request):
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1708 csrf_token = self.host.getSessionData(request, session_iface.ISATSession).csrf_token
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1709 try:
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1710 given_csrf = self.getPostedData(request, u'csrf_token')
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1711 except KeyError:
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1712 given_csrf = None
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1713 if given_csrf is None or given_csrf != csrf_token:
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1714 log.warning(_(u"invalid CSRF token, hack attempt? URL: {url}, IP: {ip}").format(
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1715 url=request.uri,
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1716 ip=request.getClientIP()))
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1717 self.pageError(request, C.HTTP_UNAUTHORIZED)
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1718 d = defer.maybeDeferred(self.on_data_post, self, request)
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1719 d.addCallback(self._on_data_post_redirect, request)
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1720 return d
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1721
931
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1722 def getPostedData(self, request, keys, multiple=False):
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1723 """get data from a POST request and decode it
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1724
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1725 @param request(server.Request): request linked to the session
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1726 @param keys(unicode, iterable[unicode]): name of the value(s) to get
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1727 unicode to get one value
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1728 iterable to get more than one
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1729 @param multiple(bool): True if multiple values are possible/expected
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1730 if False, the first value is returned
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1731 @return (iterator[unicode], list[iterator[unicode], unicode, list[unicode]): values received for this(these) key(s)
956
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1732 @raise KeyError: one specific key has been requested, and it is missing
931
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1733 """
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1734 if isinstance(keys, basestring):
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1735 keys = [keys]
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1736 get_first = True
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1737 else:
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1738 get_first = False
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1739
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1740 ret = []
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1741 for key in keys:
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1742 gen = (urllib.unquote(v).decode('utf-8') for v in request.args.get(key,[]))
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1743 if multiple:
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1744 ret.append(gen)
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1745 else:
956
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1746 try:
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1747 ret.append(next(gen))
dabecab10faa server (pages): impleted CSRF protection:
Goffi <goffi@goffi.org>
parents: 955
diff changeset
1748 except StopIteration:
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1749 raise KeyError(key)
931
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1750
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1751 return ret[0] if get_first else ret
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1752
959
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1753 def getAllPostedData(self, request, except_=()):
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1754 """get all posted data
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1755
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1756 @param request(server.Request): request linked to the session
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1757 @param except_(iterable[unicode]): key of values to ignore
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1758 csrf_token will always be ignored
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1759 @return (dict[unicode, list[unicode]]): post values
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1760 """
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1761 except_ = tuple(except_) + (u'csrf_token',)
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1762 ret = {}
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1763 for key, values in request.args.iteritems():
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1764 key = urllib.unquote(key).decode('utf-8')
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1765 if key in except_:
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1766 continue
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1767 ret[key] = [urllib.unquote(v).decode('utf-8') for v in values]
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1768 return ret
968eda9e982a server: added getAllPostedData
Goffi <goffi@goffi.org>
parents: 957
diff changeset
1769
922
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1770 def getProfile(self, request):
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1771 """helper method to easily get current profile
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1772
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1773 @return (unicode, None): current profile
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1774 None if no profile session is started
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1775 """
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1776 sat_session = self.host.getSessionData(request, session_iface.ISATSession)
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1777 return sat_session.profile
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1778
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1779 def getRData(self, request):
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1780 """helper method to get request data dict
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1781
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1782 this dictionnary if for the request only, it is not saved in session
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1783 It is mainly used to pass data between pages/methods called during request workflow
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1784 @return (dict): request data
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1785 """
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1786 try:
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1787 return request.data
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1788 except AttributeError:
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1789 request.data = {}
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1790 return request.data
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1791
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1792 def _checkAccess(self, data, request):
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1793 """Check access according to self.access
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1794
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1795 if access is not granted, show a HTTP_UNAUTHORIZED pageError and stop request,
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1796 else return data (so it can be inserted in deferred chain
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1797 """
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1798 if self.access == C.PAGES_ACCESS_PUBLIC:
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1799 pass
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1800 elif self.access == C.PAGES_ACCESS_PROFILE:
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1801 profile = self.getProfile(request)
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1802 if not profile:
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1803 # no session started
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1804 if not self.host.options["allow_registration"]:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1805 # registration not allowed, access is not granted
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1806 self.pageError(request, C.HTTP_UNAUTHORIZED)
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1807 else:
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1808 # registration allowed, we redirect to login page
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1809 login_url = self.getPageRedirectURL(request)
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1810 self.HTTPRedirect(request, login_url)
922
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1811
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1812 return data
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1813
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1814 def renderPage(self, request, skip_parse_url=False):
937
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1815 """Main method to handle the workflow of a LiberviaPage"""
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1816 # template_data are the variables passed to template
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1817 if not hasattr(request, 'template_data'):
957
67bf14c91d5c server (pages): added a confirm flag on successful post:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
1818 session_data = self.host.getSessionData(request, session_iface.ISATSession)
67bf14c91d5c server (pages): added a confirm flag on successful post:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
1819 csrf_token = session_data.csrf_token
67bf14c91d5c server (pages): added a confirm flag on successful post:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
1820 request.template_data = {u'csrf_token': csrf_token}
922
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1821
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1822 # XXX: here is the code which need to be executed once
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1823 # at the beginning of the request hanling
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1824 if request.postpath and not request.postpath[-1]:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1825 # we don't differenciate URLs finishing with '/' or not
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1826 del request.postpath[-1]
922
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1827
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1828 d = defer.Deferred()
922
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1829 d.addCallback(self._checkAccess, request)
16d1084d1371 server (pages): added "None" access (page is not rendered at all) and some HTTP code constants + helper methods to get session data
Goffi <goffi@goffi.org>
parents: 921
diff changeset
1830
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1831 if self.redirect is not None:
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1832 self.pageRedirect(self.redirect, request, skip_parse_url=False)
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1833
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1834 if self.parse_url is not None and not skip_parse_url:
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1835 d.addCallback(self.parse_url, request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1836
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1837 d.addCallback(self._subpagesHandler, request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1838
931
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1839 if request.method not in (C.HTTP_METHOD_GET, C.HTTP_METHOD_POST):
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1840 # only HTTP GET and POST are handled so far
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1841 d.addCallback(lambda dummy: self.pageError(request, C.HTTP_BAD_REQUEST))
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1842
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1843 if request.method == C.HTTP_METHOD_POST:
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1844 if self.on_data_post is None:
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1845 # if we don't have on_data_post, the page was not expecting POST
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1846 # so we return an error
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1847 d.addCallback(lambda dummy: self.pageError(request, C.HTTP_BAD_REQUEST))
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1848 else:
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1849 d.addCallback(self._on_data_post, request)
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1850 # by default, POST follow normal behaviour after on_data_post is called
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1851 # this can be changed by a redirection or other method call in on_data_post
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1852
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1853 if self.prepare_render:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1854 d.addCallback(self._prepare_render, request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1855
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1856 if self.template:
962
c7fba7709d05 Pages: various improvments:
Goffi <goffi@goffi.org>
parents: 961
diff changeset
1857 d.addCallback(self._render_template, request)
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1858 elif self.render_method:
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1859 d.addCallback(self._render_method, request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1860
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1861 d.addCallback(self.writeData, request)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1862 d.addErrback(self._renderEb, request)
937
00236973e138 server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
Goffi <goffi@goffi.org>
parents: 936
diff changeset
1863 d.addErrback(self._internalError, request)
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1864 d.callback(self)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1865 return server.NOT_DONE_YET
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1866
923
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1867 def render_GET(self, request):
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1868 return self.renderPage(request)
edb322c87ea4 server (pages): pages now handle redirection, check self.pageRedirect docstring for details
Goffi <goffi@goffi.org>
parents: 922
diff changeset
1869
931
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1870 def render_POST(self, request):
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1871 return self.renderPage(request)
8a393ae90f8c server (pages): post requests are now handled:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
1872
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1873
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
1874 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
1875
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1876 def __init__(self, options):
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1877 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
1878 self.initialised = defer.Deferred()
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1879 self.waiting_profiles = WaitingRequests() # FIXME: should be removed
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1880
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
1881 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
1882 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
1883 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
1884 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
1885 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
1886 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
1887 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
1888 # 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
1889 # 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
1890 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
1891
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1892 if not self.options['port_https_ext']:
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1893 self.options['port_https_ext'] = self.options['port_https']
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1894 if self.options['data_dir'] == DATA_DIR_DEFAULT:
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1895 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
1896
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1897 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
1898 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
1899
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
1900 self._cleanup = []
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1901
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
1902 self.signal_handler = SignalHandler(self)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1903 self.sessions = {} # key = session value = user
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1904 self.prof_connected = set() # Profiles connected
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1905
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
1906 ## 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
1907 try:
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1908 self.bridge = Bridge()
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
1909 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
1910 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
1911 sys.exit(1)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1912 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb)
553
8492c2bb463b server_side: enable HTTP gzip compression
souliane <souliane@mailoo.org>
parents: 522
diff changeset
1913
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1914 def backendReady(self, dummy):
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1915 self.root = root = LiberviaRootResource(self.options, self.html_dir)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1916 _register = Register(self)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1917 _upload_radiocol = UploadManagerRadioCol(self)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1918 _upload_avatar = UploadManagerAvatar(self)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1919 self.signal_handler.plugRegister(_register)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1920 self.bridge.register_signal("connected", self.signal_handler.connected)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1921 self.bridge.register_signal("disconnected", self.signal_handler.disconnected)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1922 #core
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1923 for signal_name in ['presenceUpdate', 'messageNew', 'subscribe', 'contactDeleted',
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1924 'newContact', 'entityDataUpdated', 'paramUpdate']:
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1925 self.bridge.register_signal(signal_name, self.signal_handler.getGenericCb(signal_name))
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1926 # XXX: actionNew is handled separately because the handler must manage security_limit
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1927 self.bridge.register_signal('actionNew', self.signal_handler.actionNewHandler)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1928 #plugins
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1929 for signal_name in ['psEvent', 'mucRoomJoined', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1930 'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore', 'tarotGamePlayers',
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1931 'radiocolStarted', 'radiocolPreload', 'radiocolPlay', 'radiocolNoUpload', 'radiocolUploadOk', 'radiocolSongRejected', 'radiocolPlayers',
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1932 'mucRoomLeft', 'mucRoomUserChangedNick', 'chatStateReceived']:
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1933 self.bridge.register_signal(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin")
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1934 self.media_dir = self.bridge.getConfig('', 'media_dir')
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1935 self.local_dir = self.bridge.getConfig('', 'local_dir')
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1936 self.cache_root_dir = os.path.join(
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1937 self.local_dir,
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1938 C.CACHE_DIR)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1939
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1940 # JSON APIs
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1941 self.putChild('json_signal_api', self.signal_handler)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1942 self.putChild('json_api', MethodHandler(self))
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1943 self.putChild('register_api', _register)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1944
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1945 # files upload
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1946 self.putChild('upload_radiocol', _upload_radiocol)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1947 self.putChild('upload_avatar', _upload_avatar)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1948
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1949 # static pages
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1950 self.putChild('blog', MicroBlog(self))
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1951 self.putChild(C.THEMES_URL, ProtectedFile(self.themes_dir))
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1952
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1953 LiberviaPage.importPages(self)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1954
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1955 # media dirs
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1956 # FIXME: get rid of dirname and "/" in C.XXX_DIR
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1957 self.putChild(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir))
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1958 self.cache_resource = web_resource.NoResource()
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1959 self.putChild(C.CACHE_DIR, self.cache_resource)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1960
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1961 # special
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1962 self.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
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1963 # pyjamas tests, redirected only for dev versions
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1964 if self.version[-1] == 'D':
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1965 self.putChild('test', web_util.Redirect('/libervia_test.html'))
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1966
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1967
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1968 wrapped = web_resource.EncodingResourceWrapper(root, [server.GzipEncoderFactory()])
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1969 self.site = server.Site(wrapped)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1970 self.site.sessionFactory = LiberviaSession
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1971 self.renderer = template.Renderer(self)
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1972 self.putChild('templates', ProtectedFile(self.renderer.base_dir))
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
1973
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1974
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1975 def _bridgeCb(self):
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
1976 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
1977 lambda failure: self.initialised.errback(Exception(failure)))
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1978 self.initialised.addCallback(self.backendReady)
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
1979 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
1980
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1981 def _bridgeEb(self, failure):
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1982 log.error(u"Can't connect to bridge: {}".format(failure))
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1983
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1984 @property
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1985 def version(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1986 """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
1987 return C.APP_VERSION
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1988
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1989 @property
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1990 def full_version(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1991 """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
1992 version = self.version
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1993 if version[-1] == 'D':
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1994 # 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
1995 try:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1996 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1997 except AttributeError:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
1998 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
1999 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2000 else:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2001 return version
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2002
935
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2003 def bridgeCall(self, method_name, *args, **kwargs):
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2004 """Call an asynchronous bridge method and return a deferred
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2005
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2006 @param method_name: name of the method as a unicode
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2007 @return: a deferred which trigger the result
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2008
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2009 """
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2010 d = defer.Deferred()
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2011
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2012 def _callback(*args):
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2013 if not args:
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2014 d.callback(None)
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2015 else:
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2016 if len(args) != 1:
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2017 Exception("Multiple return arguments not supported")
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2018 d.callback(args[0])
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2019
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2020 def _errback(result):
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2021 d.errback(failure.Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, result.classname)))
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2022
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2023 kwargs["callback"] = _callback
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2024 kwargs["errback"] = _errback
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2025 getattr(self.bridge, method_name)(*args, **kwargs)
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2026 return d
c3ae008f7a0f server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
Goffi <goffi@goffi.org>
parents: 931
diff changeset
2027
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2028 def _logged(self, profile, request):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2029 """Set everything when a user just logged in
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2030
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2031 @param profile
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2032 @param request
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2033 @return: a constant indicating the state:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2034 - C.PROFILE_LOGGED
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2035 - C.PROFILE_LOGGED_EXT_JID
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2036 @raise exceptions.ConflictError: session is already active
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2037 """
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2038 register_with_ext_jid = self.waiting_profiles.getRegisterWithExtJid(profile)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2039 self.waiting_profiles.purgeRequest(profile)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2040 _session = request.getSession()
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2041 sat_session = session_iface.ISATSession(_session)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2042 if sat_session.profile:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2043 log.error(_(u'/!\\ Session has already a profile, this should NEVER happen!'))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2044 raise failure.Failure(exceptions.ConflictError("Already active"))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2045
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2046 sat_session.profile = profile
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2047 self.prof_connected.add(profile)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2048 cache_dir = os.path.join(self.cache_root_dir, regex.pathEscape(profile))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2049 # FIXME: would be better to have a global /cache URL which redirect to profile's cache directory, without uuid
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2050 self.cache_resource.putChild(sat_session.uuid, ProtectedFile(cache_dir))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2051 log.debug(_(u"profile cache resource added from {uuid} to {path}").format(uuid=sat_session.uuid, path=cache_dir))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2052
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2053 def onExpire():
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2054 log.info(u"Session expired (profile={profile})".format(profile=profile,))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2055 self.cache_resource.delEntity(sat_session.uuid)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2056 log.debug(_(u"profile cache resource {uuid} deleted").format(uuid = sat_session.uuid))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2057 try:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2058 #We purge the queue
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2059 del self.signal_handler.queue[profile]
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2060 except KeyError:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2061 pass
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2062 #and now we disconnect the profile
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2063 self.bridge.disconnect(profile)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2064
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2065 _session.notifyOnExpire(onExpire)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2066
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2067 return C.PROFILE_LOGGED_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2068
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2069 @defer.inlineCallbacks
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2070 def connect(self, request, login, password):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2071 """log user in
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2072
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2073 If an other user was already logged, it will be unlogged first
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2074 @param request(server.Request): request linked to the session
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2075 @param login(unicode): user login
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2076 can be profile name
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2077 can be profile@[libervia_domain.ext]
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2078 can be a jid (a new profile will be created with this jid if needed)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2079 @param password(unicode): user password
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2080 @return (unicode, None): C.SESSION_ACTIVE: if session was aleady active else self._logged value
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2081 @raise exceptions.DataError: invalid login
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2082 @raise exceptions.ProfileUnknownError: this login doesn't exist
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2083 @raise exceptions.PermissionError: a login is not accepted (e.g. empty password not allowed)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2084 @raise exceptions.NotReady: a profile connection is already waiting
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2085 @raise exceptions.TimeoutError: didn't received and answer from Bridge
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2086 @raise exceptions.InternalError: unknown error
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2087 @raise ValueError(C.PROFILE_AUTH_ERROR): invalid login and/or password
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2088 @raise ValueError(C.XMPP_AUTH_ERROR): invalid XMPP account password
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2089 """
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2090
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2091 # XXX: all security checks must be done here, even if present in javascript
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2092 if login.startswith('@'):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2093 raise failure.Failure(exceptions.DataError('No profile_key allowed'))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2094
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2095 if '@' in login:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2096 try:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2097 login_jid = jid.JID(login)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2098 except (RuntimeError, jid.InvalidFormat, AttributeError):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2099 raise failure.Failure(exceptions.DataError('No profile_key allowed'))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2100
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2101 # FIXME: should it be cached?
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2102 new_account_domain = yield self.bridgeCall("getNewAccountDomain")
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2103
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2104 if login_jid.host == new_account_domain:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2105 # redirect "user@libervia.org" to the "user" profile
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2106 login = login_jid.user
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2107 login_jid = None
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2108 else:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2109 login_jid = None
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2110
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2111 try:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2112 profile = yield self.bridgeCall("profileNameGet", login)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2113 except Exception: # XXX: ProfileUnknownError wouldn't work, it's encapsulated
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2114 # FIXME: find a better way to handle bridge errors
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2115 if login_jid is not None and login_jid.user: # try to create a new sat profile using the XMPP credentials
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2116 if not self.options["allow_registration"]:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2117 log.warning(u"Trying to register JID account while registration is not allowed")
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2118 raise failure.Failure(exceptions.DataError(u"JID login while registration is not allowed"))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2119 profile = login # FIXME: what if there is a resource?
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2120 connect_method = "asyncConnectWithXMPPCredentials"
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2121 register_with_ext_jid = True
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2122 else: # non existing username
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2123 raise failure.Failure(exceptions.ProfileUnknownError())
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2124 else:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2125 if profile != login or (not password and profile not in self.options['empty_password_allowed_warning_dangerous_list']):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2126 # profiles with empty passwords are restricted to local frontends
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2127 raise exceptions.PermissionError
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2128 register_with_ext_jid = False
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2129
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2130 connect_method = "connect"
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2131
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2132 # we check if there is not already an active session
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2133 sat_session = session_iface.ISATSession(request.getSession())
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2134 if sat_session.profile:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2135 # yes, there is
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2136 if sat_session.profile != profile:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2137 # it's a different profile, we need to disconnect it
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2138 log.warning(_(u"{new_profile} requested login, but {old_profile} was already connected, disconnecting {old_profile}").format(
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2139 old_profile = sat_session.profile,
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2140 new_profile = profile))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2141 self.purgeSession(request)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2142
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2143 if self.waiting_profiles.getRequest(profile):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2144 # FIXME: check if and when this can happen
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2145 raise failure.Failure(exceptions.NotReady("Already waiting"))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2146
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2147 self.waiting_profiles.setRequest(request, profile, register_with_ext_jid)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2148 try:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2149 connected = yield self.bridgeCall(connect_method, profile, password)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2150 except Exception as failure_:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2151 fault = failure_.faultString
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2152 self.waiting_profiles.purgeRequest(profile)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2153 if fault in ('PasswordError', 'ProfileUnknownError'):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2154 log.info(u"Profile {profile} doesn't exist or the submitted password is wrong".format(profile=profile))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2155 raise failure.Failure(ValueError(C.PROFILE_AUTH_ERROR))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2156 elif fault == 'SASLAuthError':
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2157 log.info(u"The XMPP password of profile {profile} is wrong".format(profile=profile))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2158 raise failure.Failure(ValueError(C.XMPP_AUTH_ERROR))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2159 elif fault == 'NoReply':
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2160 log.info(_("Did not receive a reply (the timeout expired or the connection is broken)"))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2161 raise exceptions.TimeOutError
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2162 else:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2163 log.error(u'Unmanaged fault string "{fault}" in errback for the connection of profile {profile}'.format(
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2164 fault=fault, profile=profile))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2165 raise failure.Failure(exceptions.InternalError(fault))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2166
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2167 if connected:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2168 # profile is already connected in backend
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2169 # do we have a corresponding session in Libervia?
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2170 sat_session = session_iface.ISATSession(request.getSession())
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2171 if sat_session.profile:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2172 # yes, session is active
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2173 if sat_session.profile != profile:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2174 # existing session should have been ended above
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2175 # so this line should never be reached
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2176 log.error(_(u'session profile [{session_profile}] differs from login profile [{profile}], this should not happen!').format(
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2177 session_profile = sat_session.profile,
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2178 profile = profile
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2179 ))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2180 raise exceptions.InternalError("profile mismatch")
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2181 defer.returnValue(C.SESSION_ACTIVE)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2182 log.info(_(u"profile {profile} was already connected in backend".format(profile=profile)))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2183 # no, we have to create it
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2184 defer.returnValue(self._logged(profile, request))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2185
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2186 def registerNewAccount(self, request, login, password, email):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2187 """Create a new account, or return error
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2188 @param request(server.Request): request linked to the session
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2189 @param login(unicode): new account requested login
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2190 @param email(unicode): new account email
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2191 @param password(unicode): new account password
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2192 @return(unicode): a constant indicating the state:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2193 - C.BAD_REQUEST: something is wrong in the request (bad arguments)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2194 - C.INVALID_INPUT: one of the data is not valid
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2195 - C.REGISTRATION_SUCCEED: new account has been successfully registered
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2196 - C.ALREADY_EXISTS: the given profile already exists
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2197 - C.INTERNAL_ERROR or any unmanaged fault string
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2198 @raise PermissionError: registration is now allowed in server configuration
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2199 """
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2200 if not self.options["allow_registration"]:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2201 log.warning(_(u"Registration received while it is not allowed, hack attempt?"))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2202 raise failure.Failure(exceptions.PermissionError(u"Registration is not allowed on this server"))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2203
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2204 if not re.match(C.REG_LOGIN_RE, login) or \
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2205 not re.match(C.REG_EMAIL_RE, email, re.IGNORECASE) or \
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2206 len(password) < C.PASSWORD_MIN_LENGTH:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2207 return C.INVALID_INPUT
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2208
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2209 def registered(result):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2210 return C.REGISTRATION_SUCCEED
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2211
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2212 def registeringError(failure):
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2213 status = failure.value.faultString
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2214 if status == "ConflictError":
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2215 return C.ALREADY_EXISTS
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2216 elif status == "InternalError":
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2217 return C.INTERNAL_ERROR
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2218 else:
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2219 log.error(_(u'Unknown registering error status: {status }').format(
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2220 status = status))
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2221 return status
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2222
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2223 d = self.bridgeCall("registerSatAccount", email, password, login)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2224 d.addCallback(registered)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2225 d.addErrback(registeringError)
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2226 return d
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2227
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
2228 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
2229 """Add cleaning method to call when service is stopped
961
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2230
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
2231 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
2232 @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
2233 @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
2234 @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
2235 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
2236
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2237 def startService(self):
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
2238 """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
2239 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
2240 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
2241 self.stop()
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
2242
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
2243 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
2244 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
2245 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
2246 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
2247 # 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
2248 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
2249 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
2250 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
2251 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
2252 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
2253 if not connected:
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2254 self.bridge.connect(C.SERVICE_PROFILE, self.options['passphrase'],
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2255 {}, 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
2256 else:
42c8e91af048 server side: fixed start sequence when SERVICE_PROFILE is already connected
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2257 self._startService()
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
2258
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
2259 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
2260
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2261 ## URLs ##
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
2262
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2263 def putChild(self, path, resource):
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2264 """Add a child to the root resource"""
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2265 # FIXME: check that no information is leaked (c.f. https://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#request-encoders)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2266 self.root.putChild(path, web_resource.EncodingResourceWrapper(resource, [server.GzipEncoderFactory()]))
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2267
920
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2268 ## Sessions ##
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2269
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2270 def purgeSession(self, request):
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2271 """helper method to purge a session during request handling"""
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2272 session = request.session
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2273 if session is not None:
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2274 log.debug(_(u"session purge"))
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2275 session.expire()
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2276 # FIXME: not clean but it seems that it's the best way to reset
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2277 # session during request handling
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2278 request._secureSession = request._insecureSession = None
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2279
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2280 def getSessionData(self, request, *args):
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2281 """helper method to retrieve session data
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2282
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2283 @param request(server.Request): request linked to the session
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2284 @param *args(zope.interface.Interface): interface of the session to get
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2285 @return (iterator(data)): requested session data
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2286 """
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2287 session = request.getSession()
924
94f88277c2e7 libervia (pages): getSessionData return one session if used with one argument, else an iterator
Goffi <goffi@goffi.org>
parents: 923
diff changeset
2288 if len(args) == 1:
94f88277c2e7 libervia (pages): getSessionData return one session if used with one argument, else an iterator
Goffi <goffi@goffi.org>
parents: 923
diff changeset
2289 return args[0](session)
94f88277c2e7 libervia (pages): getSessionData return one session if used with one argument, else an iterator
Goffi <goffi@goffi.org>
parents: 923
diff changeset
2290 else:
94f88277c2e7 libervia (pages): getSessionData return one session if used with one argument, else an iterator
Goffi <goffi@goffi.org>
parents: 923
diff changeset
2291 return (iface(session) for iface in args)
920
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2292
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
2293 ## 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
2294
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
2295 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
2296 """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
2297
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
2298 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
2299 """
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
2300 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
2301 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
2302 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
2303 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
2304 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
2305
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
2306
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
2307 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
2308 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
2309
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
2310 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
2311 """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
2312
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
2313 @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
2314 @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
2315 @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
2316 """
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
2317 # 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
2318 # 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
2319 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
2320 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
2321 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
2322 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
2323 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
2324 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
2325 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
2326 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
2327 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
2328 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
2329 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
2330
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
2331 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
2332 """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
2333
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
2334 @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
2335 @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
2336 @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
2337 """
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
2338 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
2339
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
2340 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
2341 """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
2342
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
2343 @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
2344 @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
2345 @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
2346 """
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
2347 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
2348
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
2349 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
2350 """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
2351 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
2352 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
2353
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
2354 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
2355
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
2356 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
2357 ('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
2358 ('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
2359 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
2360 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
2361 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
2362 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
2363 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
2364 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
2365 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
2366 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
2367 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
2368 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
2369 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
2370 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
2371 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
2372 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
2373 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
2374 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
2375
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
2376 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
2377
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
2378 ## 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
2379
472
42c8e91af048 server side: fixed start sequence when SERVICE_PROFILE is already connected
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2380 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
2381 """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
2382
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
2383 @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
2384 @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
2385 @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
2386 """
950
67a59552f3e3 server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents: 937
diff changeset
2387 # now that we have service profile connected, we add resource for its cache
67a59552f3e3 server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents: 937
diff changeset
2388 service_path = regex.pathEscape(C.SERVICE_PROFILE)
67a59552f3e3 server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents: 937
diff changeset
2389 cache_dir = os.path.join(self.cache_root_dir, service_path)
67a59552f3e3 server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents: 937
diff changeset
2390 self.cache_resource.putChild(service_path, ProtectedFile(cache_dir))
67a59552f3e3 server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents: 937
diff changeset
2391 self.service_cache_url = os.path.join(C.CACHE_DIR, service_path)
67a59552f3e3 server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents: 937
diff changeset
2392
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
2393 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
2394 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
2395 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
2396 reactor.listenSSL(self.options['port_https'], self.site, context_factory)
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
2397 if self.options['connection_type'] in ('http', 'both'):
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
2398 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
2399 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
2400 else:
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
2401 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
2402
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
2403 def stopService(self):
473
d1565906f228 server_side: fixed some forgotten print statement
Goffi <goffi@goffi.org>
parents: 472
diff changeset
2404 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
2405 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
2406 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
2407 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
2408 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
2409 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
2410 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
2411
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2412 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
2413 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
2414
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2415 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
2416 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
2417
812
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
2418 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
2419 """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
2420
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
2421 @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
2422 """
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
2423 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
2424 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
2425
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2426
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2427 class RedirectToHTTPS(web_resource.Resource):
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2428
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2429 def __init__(self, old_port, new_port):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2430 web_resource.Resource.__init__(self)
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2431 self.isLeaf = True
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2432 self.old_port = old_port
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2433 self.new_port = new_port
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2434
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2435 def render(self, request):
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2436 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
2437 url = "https://" + netloc + request.uri
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2438 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
2439
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2440
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
2441 registerAdapter(session_iface.SATSession, server.Session, session_iface.ISATSession)
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
2442 registerAdapter(session_iface.SATGuestSession, server.Session, session_iface.ISATGuestSession)