annotate libervia/server/server.py @ 1203:251eba911d4d

server (websockets): fixed websocket handling on HTTPS connections: Original request used to retrieve a page was stored on dynamic pages, but after the end of it, the channel was deleted, resulting in a isSecure() always returning False, and troubles in chain leading to the the use of the wrong session object. This patch fixes this by reworking the way original request is used, and creating a new wrapping class allowing to keep an API similar to iweb.IRequest, with data coming from both the original request and the websocket request. fix 327
author Goffi <goffi@goffi.org>
date Sun, 14 Jul 2019 14:45:51 +0200
parents 3f791fbc1643
children a2df53dfbf46
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
1144
2af117bfe6cc dates update
Goffi <goffi@goffi.org>
parents: 1138
diff changeset
5 # Copyright (C) 2011-2019 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
1146
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
20 import re
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
21 import glob
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
22 import os.path
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
23 import sys
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
24 import tempfile
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
25 import shutil
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
26 import uuid
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
27 import urlparse
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
28 import urllib
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
29 import time
1203
251eba911d4d server (websockets): fixed websocket handling on HTTPS connections:
Goffi <goffi@goffi.org>
parents: 1202
diff changeset
30 import copy
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
31 from twisted.application import service
1152
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
32 from twisted.internet import reactor, defer, inotify
331
06a48d805547 server side: make Libervia a Twisted 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 from twisted.web import server
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
34 from twisted.web import static
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
35 from twisted.web import resource as web_resource
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
36 from twisted.web import util as web_util
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
37 from twisted.web import http
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
38 from twisted.web import vhost
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
39 from twisted.python.components import registerAdapter
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
40 from twisted.python import failure
1152
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
41 from twisted.python import filepath
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
42 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
43
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
44 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
45 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
46
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
47 from sat.core.log import getLogger
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
48
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
49 from sat_frontends.bridge.dbus_bridge import (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
50 Bridge,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
51 BridgeExceptionNoService,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
52 const_TIMEOUT as BRIDGE_TIMEOUT,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
53 )
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
54 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
55 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
56 from sat.tools import utils
1146
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
57 from sat.tools import config
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
58 from sat.tools.common import regex
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
59 from sat.tools.common import template
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
60 from sat.tools.common import uri as common_uri
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
61 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
62 import libervia
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
63 from libervia.server import websockets
984
f0fc28b3bd1e server: moved LiberviaPage code in its own module
Goffi <goffi@goffi.org>
parents: 980
diff changeset
64 from libervia.server.pages import LiberviaPage
1063
4b69f69c6ffd server: new ProgressHandler helper class, to handle progressing actions
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
65 from libervia.server.utils import quote, ProgressHandler
1146
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
66 from libervia.server.tasks import TasksManager
985
64826e69f365 pages: cache mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 984
diff changeset
67 from functools import partial
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
68
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
69 try:
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
70 import OpenSSL
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
71 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
72 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
73 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
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 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
76 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
77 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
78
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
79 log = getLogger(__name__)
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
80
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
81
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
82 # following value are set from twisted.plugins.libervia_server initialise
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
83 # (see the comment there)
514
530c88c1deee server_side: plugin refactoring:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
84 DATA_DIR_DEFAULT = OPT_PARAMETERS_BOTH = OPT_PARAMETERS_CFG = coerceDataDir = None
1152
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
85 DEFAULT_MASK = (inotify.IN_CREATE | inotify.IN_MODIFY | inotify.IN_MOVE_SELF
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
86 | inotify.IN_MOVED_TO)
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
87
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
88
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
89 class FilesWatcher(object):
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
90 """Class to check files modifications using iNotify"""
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
91 _notifier = None
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
92
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
93 def __init__(self, host):
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
94 self.host = host
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
95
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
96 @property
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
97 def notifier(self):
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
98 if self._notifier == None:
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
99 notifier = self.__class__._notifier = inotify.INotify()
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
100 notifier.startReading()
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
101 return self._notifier
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
102
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
103 def watchDir(self, dir_path, callback, mask=DEFAULT_MASK, auto_add=False,
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
104 recursive=False, **kwargs):
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
105 log.info(_(u"Watching directory {dir_path}").format(dir_path=dir_path))
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
106 callbacks = [lambda __, filepath, mask: callback(self.host, filepath,
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
107 inotify.humanReadableMask(mask), **kwargs)]
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
108 self.notifier.watch(
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
109 filepath.FilePath(dir_path), mask=mask, autoAdd=auto_add, recursive=recursive,
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
110 callbacks=callbacks)
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
111
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
112
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
113 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
114 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
115
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
116 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
117 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
118 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
119
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
120 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
121 """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
122 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
123 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
124
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
125 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
126 """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
127 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
128 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
129
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
130 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
131 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
132 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
133
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
134
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
135 class ProtectedFile(static.File):
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
136 """A static.File class which doesn'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
137
1196
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
138 def __init__(self, *args, **kwargs):
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
139 if "defaultType" not in kwargs and len(args) < 2:
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
140 # defaultType is second positional argument, and Twisted uses it
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
141 # in File.createSimilarFile, so we set kwargs only if it is missing
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
142 # in kwargs and it is not in a positional argument
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
143 kwargs["defaultType"] = "application/octet-stream"
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
144 super(ProtectedFile, self).__init__(*args, **kwargs)
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
145
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
146 def directoryListing(self):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
147 return web_resource.NoResource()
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
148
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
149
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
150 class LiberviaRootResource(ProtectedFile):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
151 """Specialized resource for Libervia root
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
152
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
153 handle redirections declared in sat.conf
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
154 """
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
155
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
156 def __init__(self, host, host_name, site_name, site_path, *args, **kwargs):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
157 ProtectedFile.__init__(self, *args, **kwargs)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
158 self.host = host
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
159 self.host_name = host_name
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
160 self.site_name = site_name
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
161 self.site_path = site_path
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
162 self.named_pages = {}
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
163 self.uri_callbacks = {}
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
164 self.pages_redirects = {}
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
165 self.cached_urls = {}
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
166 self.main_menu = None
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
167
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
168 def __unicode__(self):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
169 return (u"Root resource for {host_name} using {site_name} at {site_path} and "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
170 u"deserving files at {path}".format(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
171 host_name=self.host_name, site_name=self.site_name,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
172 site_path=self.site_path, path=self.path))
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
173
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
174 def __str__(self):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
175 return self.__unicode__.encode('utf-8')
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
176
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
177 def _initRedirections(self, options):
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
178 url_redirections = options["url_redirections_dict"]
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
179
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
180 url_redirections = url_redirections.get(self.site_name, {})
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
181
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
182 ## redirections
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
183 self.redirections = {}
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
184 self.inv_redirections = {} # new URL to old URL map
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
185
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
186 for old, new_data in url_redirections.iteritems():
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
187 # 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
188 if isinstance(new_data, dict):
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
189 # new_data dict must contain either "url", "page" or "path" key
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
190 # (exclusive)
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
191 # if "path" is used, a file url is constructed with it
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
192 if len({"path", "url", "page"}.intersection(new_data.keys())) != 1:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
193 raise ValueError(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
194 u'You must have one and only one of "url", "page" or "path" key '
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
195 u'in your url_redirections_dict data')
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
196 if "url" in new_data:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
197 new = new_data["url"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
198 elif "page" in new_data:
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
199 new = new_data
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
200 new["type"] = "page"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
201 new.setdefault("path_args", [])
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
202 if not isinstance(new["path_args"], list):
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
203 log.error(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
204 _(u'"path_args" in redirection of {old} must be a list. '
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
205 u'Ignoring the redirection'.format(old=old)))
980
bcacf970f970 core (pages redirection): inverted redirection + getSubPageURL:
Goffi <goffi@goffi.org>
parents: 979
diff changeset
206 continue
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
207 new.setdefault("query_args", {})
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
208 if not isinstance(new["query_args"], dict):
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
209 log.error(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
210 _(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
211 u'"query_args" in redirection of {old} must be a '
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
212 u'dictionary. Ignoring the redirection'.format(old=old)))
980
bcacf970f970 core (pages redirection): inverted redirection + getSubPageURL:
Goffi <goffi@goffi.org>
parents: 979
diff changeset
213 continue
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
214 new["path_args"] = [quote(a) for a in new["path_args"]]
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
215 # we keep an inversed dict of page redirection
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
216 # (page/path_args => redirecting URL)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
217 # so getURL can return the redirecting URL if the same arguments
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
218 # are used # making the URL consistent
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
219 args_hash = tuple(new["path_args"])
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
220 self.pages_redirects.setdefault(new_data["page"], {})[
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
221 args_hash
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
222 ] = old
980
bcacf970f970 core (pages redirection): inverted redirection + getSubPageURL:
Goffi <goffi@goffi.org>
parents: 979
diff changeset
223
bcacf970f970 core (pages redirection): inverted redirection + getSubPageURL:
Goffi <goffi@goffi.org>
parents: 979
diff changeset
224 # we need lists in query_args because it will be used
bcacf970f970 core (pages redirection): inverted redirection + getSubPageURL:
Goffi <goffi@goffi.org>
parents: 979
diff changeset
225 # as it in request.path_args
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
226 for k, v in new["query_args"].iteritems():
980
bcacf970f970 core (pages redirection): inverted redirection + getSubPageURL:
Goffi <goffi@goffi.org>
parents: 979
diff changeset
227 if isinstance(v, basestring):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
228 new["query_args"][k] = [v]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
229 elif "path" in new_data:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
230 new = "file:{}".format(urllib.quote(new_data["path"]))
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
231 elif isinstance(new_data, basestring):
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
232 new = new_data
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
233 new_data = {}
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
234 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
235 log.error(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
236 _(u"ignoring invalid redirection value: {new_data}").format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
237 new_data=new_data
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
238 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
239 )
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
240 continue
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
241
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
242 # 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
243 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
244 # root URL special case
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
245 old = ""
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
246 elif not old.startswith("/"):
1129
e6fe914c3eaf server: move first level dict where the key has "/" to default site in _moveFirstLevelToDict
Goffi <goffi@goffi.org>
parents: 1128
diff changeset
247 log.error(_(u"redirected url must start with '/', got {value}. Ignoring")
e6fe914c3eaf server: move first level dict where the key has "/" to default site in _moveFirstLevelToDict
Goffi <goffi@goffi.org>
parents: 1128
diff changeset
248 .format(value=old))
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
249 continue
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 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
251 old = self._normalizeURL(old)
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
252
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
253 if isinstance(new, dict):
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
254 # dict are handled differently, they contain data
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
255 # which ared use dynamically when the request is done
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
256 self.redirections[old] = new
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
257 if not old:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
258 if new[u"type"] == u"page":
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
259 log.info(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
260 _(u"Root URL redirected to page {name}").format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
261 name=new[u"page"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
262 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
263 )
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
264 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
265 if new[u"type"] == u"page":
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
266 page = self.getPageByName(new[u"page"])
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
267 url = page.getURL(*new.get(u"path_args", []))
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
268 self.inv_redirections[url] = old
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
269 continue
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
270
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
271 # at this point we have a redirection URL in new, we can parse it
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
272 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
273
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
274 # we handle the known URL schemes
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
275 if new_url.scheme == "xmpp":
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
276 location = self.getPagePathFromURI(new)
1038
6b906b1f419a pages: fixed XMPP URIs handling
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
277 if location is None:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
278 log.warning(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
279 _(u"ignoring redirection, no page found to handle this URI: "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
280 u"{uri}").format(uri=new))
1038
6b906b1f419a pages: fixed XMPP URIs handling
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
281 continue
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
282 request_data = self._getRequestData(location)
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
283 if old:
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
284 self.inv_redirections[location] = old
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
285
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
286 elif new_url.scheme in ("", "http", "https"):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
287 # direct redirection
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
288 if new_url.netloc:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
289 raise NotImplementedError(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
290 u"netloc ({netloc}) is not implemented yet for "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
291 u"url_redirections_dict, it is not possible to redirect to an "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
292 u"external website".format(netloc=new_url.netloc))
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
293 location = urlparse.urlunsplit(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
294 ("", "", new_url.path, new_url.query, new_url.fragment)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
295 ).decode("utf-8")
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
296 request_data = self._getRequestData(location)
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
297 if old:
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
298 self.inv_redirections[location] = old
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
299
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
300 elif new_url.scheme in ("file"):
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
301 # file or directory
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
302 if new_url.netloc:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
303 raise NotImplementedError(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
304 u"netloc ({netloc}) is not implemented for url redirection to "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
305 u"file system, it is not possible to redirect to an external "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
306 "host".format(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
307 netloc=new_url.netloc))
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
308 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
309 if not os.path.isabs(path):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
310 raise ValueError(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
311 u"file redirection must have an absolute path: e.g. "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
312 u"file:/path/to/my/file")
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
313 # for file redirection, we directly put child here
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
314 segments, __, last_segment = old.rpartition("/")
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
315 url_segments = segments.split("/") if segments else []
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
316 current = self
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
317 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
318 resource = web_resource.NoResource()
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
319 current.putChild(segment, resource)
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
320 current = resource
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
321 resource_class = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
322 ProtectedFile if new_data.get("protected", True) else static.File
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
323 )
1196
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
324 current.putChild(
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
325 last_segment,
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
326 resource_class(path, defaultType="application/octet-stream")
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
327 )
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
328 log.info(u"[{host_name}] Added redirection from /{old} to file system "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
329 u"path {path}".format(host_name=self.host_name,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
330 old=old.decode("utf-8"),
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
331 path=path.decode("utf-8")))
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
332 continue # we don't want to use redirection system, so we continue here
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
333
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
334 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
335 raise NotImplementedError(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
336 u"{scheme}: scheme is not managed for url_redirections_dict".format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
337 scheme=new_url.scheme
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
338 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
339 )
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
340
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
341 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
342 if not old:
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
343 log.info(_(u"[{host_name}] Root URL redirected to {uri}")
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
344 .format(host_name=self.host_name,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
345 uri=request_data[1].decode("utf-8")))
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
346
875
d9b98b8a1847 server: handling of dict and "file:" urls in url_redirections_dict:
Goffi <goffi@goffi.org>
parents: 873
diff changeset
347 # the default root URL, if not redirected
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
348 if not "" in self.redirections:
1202
3f791fbc1643 server: if "redirections" is not set, use "/login" page as default
Goffi <goffi@goffi.org>
parents: 1199
diff changeset
349 self.redirections[""] = self._getRequestData(C.LIBERVIA_PAGE_START)
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
350
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
351 def _setMenu(self, menus):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
352 menus = menus.get(self.site_name, [])
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
353 main_menu = []
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
354 for menu in menus:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
355 if not menu:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
356 msg = _(u"menu item can't be empty")
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
357 log.error(msg)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
358 raise ValueError(msg)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
359 elif isinstance(menu, list):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
360 if len(menu) != 2:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
361 msg = _(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
362 u"menu item as list must be in the form [page_name, absolue URL]"
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
363 )
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
364 log.error(msg)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
365 raise ValueError(msg)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
366 page_name, url = menu
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
367 else:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
368 page_name = menu
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
369 try:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
370 url = self.getPageByName(page_name).url
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
371 except KeyError as e:
1131
9cf592d1e6aa server: better error handling when a named page mentioned in menu_json is missing
Goffi <goffi@goffi.org>
parents: 1130
diff changeset
372 log_msg = _(u"Can'find a named page ({msg}), please check "
9cf592d1e6aa server: better error handling when a named page mentioned in menu_json is missing
Goffi <goffi@goffi.org>
parents: 1130
diff changeset
373 u"menu_json in configuration.").format(msg=e.args[0])
9cf592d1e6aa server: better error handling when a named page mentioned in menu_json is missing
Goffi <goffi@goffi.org>
parents: 1130
diff changeset
374 log.error(log_msg)
9cf592d1e6aa server: better error handling when a named page mentioned in menu_json is missing
Goffi <goffi@goffi.org>
parents: 1130
diff changeset
375 raise exceptions.ConfigError(log_msg)
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
376 main_menu.append((page_name, url))
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
377 self.main_menu = main_menu
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
378
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
379 def _normalizeURL(self, url, lower=True):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
380 """Return URL normalized for self.redirections dict
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
381
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
382 @param url(unicode): URL to normalize
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
383 @param lower(bool): lower case of url if True
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
384 @return (str): normalized URL
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
385 """
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
386 if lower:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
387 url = url.lower()
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
388 return "/".join((p for p in url.encode("utf-8").split("/") if p))
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
389
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
390 def _getRequestData(self, uri):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
391 """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
392
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
393 @param url(unicode): destination url
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
394 @return (tuple(list[str], str, str, dict): tuple with
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
395 splitted path as in Request.postpath
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
396 uri as in Request.uri
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
397 path as in Request.path
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
398 args as in Request.args
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
399 """
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
400 uri = uri.encode("utf-8")
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
401 # XXX: we reuse code from twisted.web.http.py here
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
402 # as we need to have the same behaviour
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
403 x = uri.split(b"?", 1)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
404
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
405 if len(x) == 1:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
406 path = uri
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
407 args = {}
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
408 else:
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
409 path, argstring = x
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
410 args = http.parse_qs(argstring, 1)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
411
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
412 # 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
413 # (e.g. for blog items)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
414 return (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
415 self._normalizeURL(path.decode("utf-8"), lower=False).split("/"),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
416 uri,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
417 path,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
418 args,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
419 )
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
420
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
421 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
422 """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
423
e3e2effc9a4c server: LiberviaRootResource now manages root url redirection, and former redirection has been replaced by it:
Goffi <goffi@goffi.org>
parents: 859
diff changeset
424 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
425 @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
426 @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
427 @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
428 """
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
429 # recursion check
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
430 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
431 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
432 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
433 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
434 else:
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
435 try:
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
436 __, uri, __, __ = request_data
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
437 except ValueError:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
438 uri = u""
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
439 log.error(D_( u"recursive redirection, please fix this URL:\n"
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
440 u"{old} ==> {new}").format(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
441 old=request.uri.decode("utf-8"), 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
442 return web_resource.NoResource()
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
443
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
444 request._redirected = True # here to avoid recursive redirections
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
445
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
446 if isinstance(request_data, dict):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
447 if request_data["type"] == "page":
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
448 try:
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
449 page = self.getPageByName(request_data["page"])
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
450 except KeyError:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
451 log.error(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
452 _(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
453 u'Can\'t find page named "{name}" requested in redirection'
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
454 ).format(name=request_data["page"])
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
455 )
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
456 return web_resource.NoResource()
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
457 request.postpath = request_data["path_args"][:] + request.postpath
980
bcacf970f970 core (pages redirection): inverted redirection + getSubPageURL:
Goffi <goffi@goffi.org>
parents: 979
diff changeset
458
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
459 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
460 request.args.update(request_data["query_args"])
980
bcacf970f970 core (pages redirection): inverted redirection + getSubPageURL:
Goffi <goffi@goffi.org>
parents: 979
diff changeset
461 except (TypeError, ValueError):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
462 log.error(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
463 _(u"Invalid args in redirection: {query_args}").format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
464 query_args=request_data["query_args"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
465 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
466 )
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
467 return web_resource.NoResource()
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
468 return page
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
469 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
470 raise exceptions.InternalError(u"unknown request_data type")
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
471 else:
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
472 path_list, uri, path, args = request_data
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
473 log.debug(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
474 u"Redirecting URL {old} to {new}".format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
475 old=request.uri.decode("utf-8"), new=uri.decode("utf-8")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
476 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
477 )
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
478 # we change the request to reflect the new url
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
479 request.postpath = path_list[1:] + request.postpath
1158
fb4b4da61132 backend: fixed args transmission on page redirection.
Goffi <goffi@goffi.org>
parents: 1153
diff changeset
480 request.args.update(args)
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
481
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
482 # we start again to look for a child with the new url
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
483 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
484
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
485 def getPageByName(self, name):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
486 """Retrieve page instance from its name
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
487
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
488 @param name(unicode): name of the page
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
489 @return (LiberviaPage): page instance
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
490 @raise KeyError: the page doesn't exist
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
491 """
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
492 return self.named_pages[name]
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
493
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
494 def getPagePathFromURI(self, uri):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
495 """Retrieve page URL from xmpp: URI
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
496
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
497 @param uri(unicode): URI with a xmpp: scheme
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
498 @return (unicode,None): absolute path (starting from root "/") to page handling
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
499 the URI.
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
500 None is returned if no page has been registered for this URI
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
501 """
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
502 uri_data = common_uri.parseXMPPUri(uri)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
503 try:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
504 page, cb = self.uri_callbacks[uri_data["type"], uri_data["sub_type"]]
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
505 except KeyError:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
506 url = None
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
507 else:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
508 url = cb(page, uri_data)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
509 if url is None:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
510 # no handler found
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
511 # we try to find a more generic one
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
512 try:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
513 page, cb = self.uri_callbacks[uri_data["type"], None]
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
514 except KeyError:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
515 pass
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
516 else:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
517 url = cb(page, uri_data)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
518 return url
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
519
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
520 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
521 # 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
522 # which is the only ones who need to be handled before other children
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
523 if name == "" and not request.postpath:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
524 return self._redirect(request, self.redirections[""])
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
525 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
526
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
527 def getChild(self, name, request):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
528 resource = super(LiberviaRootResource, self).getChild(name, request)
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
529
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
530 if isinstance(resource, web_resource.NoResource):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
531 # if nothing was found, we try our luck with redirections
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
532 # XXX: we want redirections to happen only if everything else failed
1047
3f6f4d907c30 server: better redirection (fixed issue in remaining path arguments)
Goffi <goffi@goffi.org>
parents: 1046
diff changeset
533 path_elt = request.prepath + request.postpath
3f6f4d907c30 server: better redirection (fixed issue in remaining path arguments)
Goffi <goffi@goffi.org>
parents: 1046
diff changeset
534 for idx in xrange(len(path_elt), 0, -1):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
535 test_url = "/".join(path_elt[:idx]).lower()
1047
3f6f4d907c30 server: better redirection (fixed issue in remaining path arguments)
Goffi <goffi@goffi.org>
parents: 1046
diff changeset
536 if test_url in self.redirections:
3f6f4d907c30 server: better redirection (fixed issue in remaining path arguments)
Goffi <goffi@goffi.org>
parents: 1046
diff changeset
537 request_data = self.redirections[test_url]
3f6f4d907c30 server: better redirection (fixed issue in remaining path arguments)
Goffi <goffi@goffi.org>
parents: 1046
diff changeset
538 request.postpath = path_elt[idx:]
979
1d558dfb32ca server: pages redirection:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
539 return self._redirect(request, request_data)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
540
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
541 return resource
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
542
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
543 def putChild(self, path, resource):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
544 """Add a child to the root resource"""
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
545 if not isinstance(resource, web_resource.EncodingResourceWrapper):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
546 # FIXME: check that no information is leaked (c.f. https://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#request-encoders)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
547 resource = web_resource.EncodingResourceWrapper(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
548 resource, [server.GzipEncoderFactory()])
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
549
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
550 super(LiberviaRootResource, self).putChild(path, resource)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
551
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
552 def createSimilarFile(self, path):
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
553 # 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
554
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
555 f = LiberviaRootResource.__base__(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
556 path, self.defaultType, self.ignoredExts, self.registry
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
557 )
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
558 # refactoring by steps, here - constructor should almost certainly take these
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
559 f.processors = self.processors
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
560 f.indexNames = self.indexNames[:]
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
561 f.childNotFound = self.childNotFound
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
562 return f
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
563
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
564
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
565 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
566 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
567 jsonrpc.JSONRPC.__init__(self)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
568 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
569
1138
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
570 def _bridgeCallEb(self, failure_):
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
571 """Raise a jsonrpclib failure for the frontend"""
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
572 return failure.Failure(
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
573 jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, failure_.value.classname)
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
574 )
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
575
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
576 def asyncBridgeCall(self, method_name, *args, **kwargs):
1138
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
577 d = self.sat_host.bridgeCall(method_name, *args, **kwargs)
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
578 d.addErrback(self._bridgeCallEb)
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
579 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
580
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
581
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
582 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
583 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
584 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
585
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
586 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
587 self.session = request.getSession()
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
588 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
589 if not profile:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
590 # user is not identified, we return a jsonrpc fault
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
591 parsed = jsonrpclib.loads(request.content.read())
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
592 fault = jsonrpclib.Fault(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
593 C.ERRNUM_LIBERVIA, C.NOT_ALLOWED
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
594 ) # FIXME: define some standard error codes for libervia
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
595 return jsonrpc.JSONRPC._cbRender(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
596 self, fault, request, parsed.get("id"), parsed.get("jsonrpc")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
597 ) # 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
598 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
599
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
600 @defer.inlineCallbacks
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
601 def jsonrpc_getVersion(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
602 """Return SàT version"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
603 try:
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
604 defer.returnValue(self._version_cache)
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
605 except AttributeError:
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
606 self._version_cache = yield self.sat_host.bridgeCall("getVersion")
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
607 defer.returnValue(self._version_cache)
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
608
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
609 def jsonrpc_getLiberviaVersion(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
610 """Return Libervia version"""
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
611 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
612
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
613 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
614 """Disconnect the profile"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
615 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
616 profile = sat_session.profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
617 self.sat_host.bridgeCall("disconnect", 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
618
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
619 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
620 """Return all passed args."""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
621 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
622 return self.sat_host.bridgeCall("getContacts", 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
623
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
624 @defer.inlineCallbacks
331
06a48d805547 server side: make Libervia a Twisted 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 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
626 """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
627 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
628 yield self.sat_host.bridgeCall("addContact", entity, profile)
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
629 yield self.sat_host.bridgeCall("updateContact", entity, name, groups, 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
630
06a48d805547 server side: make Libervia a Twisted 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 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
632 """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
633 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
634 return self.sat_host.bridgeCall("delContact", entity, 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
635
06a48d805547 server side: make Libervia a Twisted 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 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
637 """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
638 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
639 return self.sat_host.bridgeCall("updateContact", entity, name, groups, 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
640
623
4f7550a083b4 server and browser sides: fixes bad call to "subscription" bridge method
souliane <souliane@mailoo.org>
parents: 613
diff changeset
641 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
642 """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
643 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
644 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
645 return self.sat_host.bridgeCall("subscription", sub_type, entity, 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
646
06a48d805547 server side: make Libervia a Twisted 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 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
648 """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
649 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
650 return self.sat_host.bridgeCall("getWaitingSub", 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
651
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
652 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
653 """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
654 @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
655 @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
656 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
657 profile = session_iface.ISATSession(self.session).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
658 return self.sat_host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
659 "setPresence", "", presence, {"": status}, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
660 )
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
661
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
662 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
663 """send message"""
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
664 profile = session_iface.ISATSession(self.session).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
665 return self.asyncBridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
666 "messageSend", to_jid, msg, subject, type_, extra, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
667 )
331
06a48d805547 server side: make Libervia a Twisted 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
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
669 ## 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
670
921
cf527974a0fa both: renamed psDeleteNode to psNodeDelete to follow backend change
Goffi <goffi@goffi.org>
parents: 920
diff changeset
671 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
672 """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
673
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
674 @param service (unicode): service jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
675 @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
676 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
677 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
678 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
679
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
680 # 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
681 # """Delete a whole node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
682
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
683 # @param service (unicode): service jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
684 # @param node (unicode): node to delete
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
685 # @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
686 # @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
687 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
688 # profile = session_iface.ISATSession(self.session).profile
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
689 # return self.asyncBridgeCall("psRetractItem", service, node, item, notify,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
690 # profile)
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
691
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
692 # 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
693 # """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
694
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
695 # @param service (unicode): service jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
696 # @param node (unicode): node to delete
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
697 # @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
698 # @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
699 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
700 # profile = session_iface.ISATSession(self.session).profile
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
701 # return self.asyncBridgeCall("psRetractItems", service, node, items, notify,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
702 # 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
703
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
704 ## microblogging ##
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
705
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
706 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
707 """Send microblog data
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
708
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
709 @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
710 @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
711 @param mb_data(dict): microblog data
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
712 @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
713 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
714 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
715 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
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
717 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
718 """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
719
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
720 @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
721 @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
722 @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
723 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
724 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
725 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
726
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
727 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
728 """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
729
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
730 @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
731 @param node(unicode): mblogs node, or empty string to get the defaut one
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
732 @param max_items (int): maximum number of item to get or C.NO_LIMIT to get
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
733 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
734 @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
735 @param rsm (dict): TODO
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
736 @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
737 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
738 profile = session_iface.ISATSession(self.session).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
739 return self.asyncBridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
740 "mbGet", service_jid, node, max_items, item_ids, extra, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
741 )
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
742
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
743 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
744 """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
745
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
746 @param publishers_type (unicode): one of "ALL", "GROUP", "JID"
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
747 @param publishers (tuple(unicode)): tuple of publishers (empty list for all,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
748 list of groups or list of jids)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
749 @param max_items (int): maximum number of item to get or C.NO_LIMIT to get
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
750 everything
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
751 @param extra (dict): TODO
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
752 @return (str): RT Deferred session id
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
753 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
754 profile = session_iface.ISATSession(self.session).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
755 return self.sat_host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
756 "mbGetFromMany", publishers_type, publishers, max_items, extra, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
757 )
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
758
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
759 def jsonrpc_mbGetFromManyRTResult(self, rt_session):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
760 """Get results from RealTime mbGetFromMany session
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
761
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
762 @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
763 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
764 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
765 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
766
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
767 def jsonrpc_mbGetFromManyWithComments(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
768 self,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
769 publishers_type,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
770 publishers,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
771 max_items,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
772 max_comments,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
773 rsm_dict,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
774 rsm_comments_dict,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
775 ):
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
776 """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
777
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
778 @param publishers_type (str): type of the list of publishers (one of "GROUP" or
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
779 "JID" or "ALL")
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
780 @param publishers (list): list of publishers, according to publishers_type
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
781 (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
782 @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
783 @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
784 @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
785 @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
786 @param profile_key: profile key
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
787 @return (str): RT Deferred session id
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
788 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
789 profile = session_iface.ISATSession(self.session).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
790 return self.sat_host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
791 "mbGetFromManyWithComments",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
792 publishers_type,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
793 publishers,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
794 max_items,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
795 max_comments,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
796 rsm_dict,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
797 rsm_comments_dict,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
798 profile,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
799 )
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
800
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
801 def jsonrpc_mbGetFromManyWithCommentsRTResult(self, rt_session):
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
802 """Get results from RealTime mbGetFromManyWithComments session
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
803
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
804 @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
805 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
806 profile = session_iface.ISATSession(self.session).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
807 return self.asyncBridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
808 "mbGetFromManyWithCommentsRTResult", rt_session, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
809 )
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
810
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
811 # 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
812 # """ Send microblog message
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
813 # @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
814 # @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
815 # @param text (unicode): microblog's text
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
816 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
817 # 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
818 # extra['allow_comments'] = 'True'
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
819
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
820 # if not type_: # auto-detect
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
821 # type_ = "PUBLIC" if dest == [] else "GROUP"
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
822
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
823 # 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
824 # if type_ == "PUBLIC":
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
825 # #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
826 # log.debug("sending public blog")
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
827 # return self.sat_host.bridge.sendGroupBlog("PUBLIC", (), text, extra,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
828 # profile)
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
829 # else:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
830 # log.debug("sending group blog")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
831 # dest = dest if isinstance(dest, list) else [dest]
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
832 # return self.sat_host.bridge.sendGroupBlog("GROUP", dest, text, extra,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
833 # profile)
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
834 # else:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
835 # raise Exception("Invalid data")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
836
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
837 # 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
838 # """Delete a microblog node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
839 # @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
840 # @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
841 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
842 # profile = session_iface.ISATSession(self.session).profile
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
843 # return self.sat_host.bridge.deleteGroupBlog(pub_data, comments if comments
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
844 # else '', profile)
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
845
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
846 # 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
847 # """Modify a microblog node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
848 # @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
849 # @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
850 # @param message: new message
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
851 # @param extra: dict which option name as key, which can be:
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
852 # - allow_comments: True to accept an other level of comments, False else
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
853 # (default: False)
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
854 # - 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
855 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
856 # 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
857 # if comments:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
858 # extra['allow_comments'] = 'True'
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
859 # return self.sat_host.bridge.updateGroupBlog(pub_data, comments if comments
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
860 # 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
861
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
862 # 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
863 # """ Send microblog message
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
864 # @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
865 # @param text: comment
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
866 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
867 # 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
868 # if node and text:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
869 # 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
870 # else:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
871 # raise Exception("Invalid data")
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
872
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
873 # 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
874 # """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
875 # @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
876 # @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
877 # @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
878 # 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
879 # 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
880 # return d
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
881
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
882 # 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
883 # """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
884 # @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
885 # @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
886 # @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
887 # 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
888 # 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
889 # return d
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
890
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
891 # 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
892 # """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
893
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
894 # @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
895 # @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
896 # @param rsm (dict): TODO
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
897 # @return: dict{unicode: list[dict])
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
898 # key: publisher's jid
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
899 # value: list of microblog data (dict)
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
900 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
901 # 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
902 # if rsm is None:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
903 # 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
904 # 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
905 # 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
906 # return d
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
907
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
908 # 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
909 # """Get all comments of given node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
910 # @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
911 # @param node: comments node
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
912 # """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
913 # 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
914 # if rsm is None:
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 710
diff changeset
915 # 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
916 # 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
917 # 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
918
427
b5b440e6ea16 server + browser side, getPresenceStatuses has been renamed
Goffi <goffi@goffi.org>
parents: 421
diff changeset
919 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
920 """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
921 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
922 return self.sat_host.bridgeCall("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
923
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
924 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
925 """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
926 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
927 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
928 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
929 if not sat_jid:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
930 raise exceptions.InternalError("session jid should be set")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
931 if (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
932 jid.JID(from_jid).userhost() != sat_jid.userhost()
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
933 and jid.JID(to_jid).userhost() != sat_jid.userhost()
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
934 ):
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
935 log.error(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
936 u"Trying to get history from a different jid (given (browser): {}, real "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
937 u"(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
938 return {}
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
939 d = self.asyncBridgeCall(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
940 "historyGet", from_jid, to_jid, size, between, search, profile)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
941
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
942 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
943 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
944 for line in result_dbus:
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
945 # XXX: we have to do this stupid thing because Python D-Bus use its own
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
946 # types instead of standard types and txJsonRPC doesn't accept
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
947 # D-Bus types, resulting in a empty query
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
948 uuid, timestamp, from_jid, to_jid, message, subject, mess_type, extra = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
949 line
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
950 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
951 result.append(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
952 (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
953 unicode(uuid),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
954 float(timestamp),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
955 unicode(from_jid),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
956 unicode(to_jid),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
957 dict(message),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
958 dict(subject),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
959 unicode(mess_type),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
960 dict(extra),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
961 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
962 )
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
963 return result
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
964
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
965 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
966 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
967
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
968 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
969 """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
970
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
971 @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
972 @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
973 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
974 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
975 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
976 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
977
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
978 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
979 """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
980
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
981 @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
982 @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
983 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
984 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
985 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
986 service = room_jid.split("@")[1]
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
987 return self.sat_host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
988 "inviteMUC", contact_jid, service, room_id, {}, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
989 )
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
990
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
991 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
992 """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
993 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
994 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
995 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
996 except:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
997 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
998 return
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
999 return self.sat_host.bridgeCall("mucLeave", room_jid.userhost(), 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
1000
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
1001 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
1002 """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
1003 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1004 return self.sat_host.bridgeCall("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
1005
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 884
diff changeset
1006 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
1007 """@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
1008 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
1009 return d
7a9c7b9f6a28 browser_side: use host.default_muc instead of C.DEFAULT_MUC
souliane <souliane@mailoo.org>
parents: 689
diff changeset
1010
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1011 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
1012 """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
1013
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
1014 @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
1015 @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
1016 """
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(self.session).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1018 return self.sat_host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1019 "tarotGameLaunch", other_players, room_jid, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1020 )
331
06a48d805547 server side: make Libervia a Twisted 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
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1022 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
1023 """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
1024 _join = os.path.join
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1025 _media_dir = _join(self.sat_host.media_dir, "")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1026 return map(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1027 lambda x: _join(C.MEDIA_DIR, x[len(_media_dir) :]),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1028 glob.glob(_join(_media_dir, C.CARDS_DIR, "*_*.png")),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1029 )
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1030
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1031 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
1032 """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
1033 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1034 return self.sat_host.bridgeCall("tarotGameReady", player, referee, 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
1035
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1036 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
1037 """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
1038 profile = session_iface.ISATSession(self.session).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1039 return self.sat_host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1040 "tarotGamePlayCards", player_nick, referee, cards, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1041 )
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1042
06a48d805547 server side: make Libervia a Twisted 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 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
1044 """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
1045
a6adefddcb0a browser and server side: complete changeset 669 (a8fddccf5b84) about joining MUC:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
1046 @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
1047 @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
1048 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1049 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1050 return self.sat_host.bridgeCall("radiocolLaunch", invited, room_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
1051
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
1052 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
1053 """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
1054
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
1055 @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
1056 @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
1057 @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
1058 if not C.ALLOWED_ENTITY_DATA.issuperset(keys):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1059 raise exceptions.PermissionError(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1060 "Trying to access unallowed data (hack attempt ?)"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1061 )
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1062 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
1063 try:
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1064 return self.sat_host.bridgeCall("getEntitiesData", jids, keys, 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
1065 except Exception as e:
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1066 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
1067
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1068 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
1069 """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
1070
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1071 @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
1072 @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
1073 @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
1074 if not C.ALLOWED_ENTITY_DATA.issuperset(keys):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1075 raise exceptions.PermissionError(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1076 "Trying to access unallowed data (hack attempt ?)"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1077 )
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1078 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
1079 try:
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1080 return self.sat_host.bridgeCall("getEntityData", jid, keys, profile)
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 566
diff changeset
1081 except Exception as e:
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1082 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
1083
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
1084 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
1085 """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
1086 @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
1087 @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
1088 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1089 return self.sat_host.bridgeCall("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
1090
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1091 @defer.inlineCallbacks
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1092 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
1093 session_data = session_iface.ISATSession(self.session)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1094 profile = session_data.profile
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1095 # profile_uuid = session_data.uuid
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1096 avatar = yield self.asyncBridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1097 "avatarGet", entity, cache_only, hash_only, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1098 )
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1099 if hash_only:
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1100 defer.returnValue(avatar)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1101 else:
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1102 filename = os.path.basename(avatar)
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
1103 avatar_url = os.path.join(session_data.cache_dir, filename)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1104 defer.returnValue(avatar_url)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1105
391
c86d7a8d2c1e browser_side: added a dialog in Settings/Account to update/delete the XMPP account
souliane <souliane@mailoo.org>
parents: 389
diff changeset
1106 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
1107 """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
1108 @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
1109 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1110 return self.sat_host.bridgeCall("getAccountDialogUI", 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
1111
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1112 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
1113 """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
1114 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
1115 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
1116
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1117 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
1118 """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
1119 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
1120 if category == "Connection":
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1121 # we need to manage the followings params here, else SECURITY_LIMIT would
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1122 # block them
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
1123 if param == "JabberID":
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1124 return self.asyncBridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1125 "asyncGetParamA", param, category, attribute, profile_key=profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1126 )
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
1127 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
1128 return defer.succeed(C.BOOL_TRUE)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1129 d = self.asyncBridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1130 "asyncGetParamA",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1131 param,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1132 category,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1133 attribute,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1134 C.SECURITY_LIMIT,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1135 profile_key=profile,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1136 )
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1137 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
1138
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1139 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
1140 profile = session_iface.ISATSession(self.session).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1141 return self.sat_host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1142 "setParam", name, value, category, C.SECURITY_LIMIT, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1143 )
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1144
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1145 def jsonrpc_launchAction(self, callback_id, data):
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1146 # FIXME: any action can be launched, this can be a huge security issue if
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1147 # callback_id can be guessed a security system with authorised
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1148 # 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
1149 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
1150 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
1151 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
1152
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1153 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
1154 """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
1155 @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
1156 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1157 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1158 return self.sat_host.bridgeCall("chatStateComposing", to_jid_s, profile)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1159
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1160 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
1161 """@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
1162 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
1163 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
1164
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1165 def jsonrpc_syntaxConvert(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1166 self, text, syntax_from=C.SYNTAX_XHTML, syntax_to=C.SYNTAX_CURRENT
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1167 ):
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1168 """ 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
1169 @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
1170 @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
1171 @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
1172 @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
1173 @return: converted text """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1174 profile = session_iface.ISATSession(self.session).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1175 return self.sat_host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1176 "syntaxConvert", text, syntax_from, syntax_to, True, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1177 )
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1178
520
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
1179 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
1180 """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
1181 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1182 return self.sat_host.bridgeCall("getLastResource", jid_s, profile)
520
d58d4dd0cefe browser and server sides: add bridge method getLastResource
souliane <souliane@mailoo.org>
parents: 514
diff changeset
1183
751
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
1184 def jsonrpc_getFeatures(self):
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
1185 """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
1186 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1187 return self.sat_host.bridgeCall("getFeatures", profile)
751
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 750
diff changeset
1188
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
1189 def jsonrpc_skipOTR(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
1190 """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
1191 profile = session_iface.ISATSession(self.session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1192 return self.sat_host.bridgeCall("skipOTR", profile)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents: 521
diff changeset
1193
1106
09feea19d7b9 browser, server: added namespacesGet, so Libervia legacy app can run again
Goffi <goffi@goffi.org>
parents: 1105
diff changeset
1194 def jsonrpc_namespacesGet(self):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1195 return self.sat_host.bridgeCall("namespacesGet")
1106
09feea19d7b9 browser, server: added namespacesGet, so Libervia legacy app can run again
Goffi <goffi@goffi.org>
parents: 1105
diff changeset
1196
331
06a48d805547 server side: make Libervia a Twisted 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
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1198 class WaitingRequests(dict):
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
1199 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
1200 """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
1201
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1202 @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
1203 @param profile (str): %(doc_profile)s
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1204 @param register_with_ext_jid (bool): True if we will try to register the
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1205 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
1206 """
555
db1b330c1eb1 server_side: set the connection attempt timeout to the bridge timeout (2 minutes)
souliane <souliane@mailoo.org>
parents: 554
diff changeset
1207 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
1208 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
1209
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1210 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
1211 """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
1212
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1213 @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
1214 """
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1215 try:
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1216 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
1217 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
1218 return
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1219 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
1220 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
1221 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
1222
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1223 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
1224 """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
1225
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1226 @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
1227 @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
1228 """
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1229 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
1230
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
1231 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
1232 """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
1233
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
1234 @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
1235 @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
1236 """
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
1237 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
1238
554
471b6babe960 server_side: set a timeout to reset the waiting connection requests after 5 minutes
souliane <souliane@mailoo.org>
parents: 553
diff changeset
1239
331
06a48d805547 server side: make Libervia a Twisted 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 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
1241 """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
1242 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
1243
06a48d805547 server side: make Libervia a Twisted 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 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
1245 JSONRPCMethodManager.__init__(self, sat_host)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1246 self.profiles_waiting = {}
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1247 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
1248
06a48d805547 server side: make Libervia a Twisted 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 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
1250 """
06a48d805547 server side: make Libervia a Twisted 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 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
1252 - 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
1253 - except login, every method is jsonrpc
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1254 - user doesn't need to be authentified for explicitely listed methods,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1255 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
1256 """
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1257 if request.postpath == ["login"]:
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1258 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
1259 _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
1260 parsed = jsonrpclib.loads(request.content.read())
482
437eefa53a01 misc: remove some pylint errors and warnings
souliane <souliane@mailoo.org>
parents: 481
diff changeset
1261 method = parsed.get("method") # pylint: disable=E1103
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1262 if method not in ["getSessionMetadata", "registerParams", "menusGet"]:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1263 # 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
1264 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
1265 if not profile:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1266 # user is not identified, we return a jsonrpc fault
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1267 fault = jsonrpclib.Fault(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1268 C.ERRNUM_LIBERVIA, C.NOT_ALLOWED
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1269 ) # FIXME: define some standard error codes for libervia
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1270 return jsonrpc.JSONRPC._cbRender(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1271 self, fault, request, parsed.get("id"), parsed.get("jsonrpc")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1272 ) # 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
1273 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
1274 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
1275
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1276 def loginOrRegister(self, request):
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1277 """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
1278
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1279 @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
1280 @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
1281 - 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
1282 - 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
1283 """
331
06a48d805547 server side: make Libervia a Twisted 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 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1285 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
1286 except KeyError:
481
bbdc5357dc00 browser and server sides: refactor HTTP request result values + handle "NoReply" error
souliane <souliane@mailoo.org>
parents: 476
diff changeset
1287 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
1288
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1289 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
1290 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
1291 return server.NOT_DONE_YET
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1292 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
1293 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
1294 return server.NOT_DONE_YET
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1295 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
1296
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
1297 @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
1298 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
1299 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1300 login = request.args["register_login"][0]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1301 password = request.args["register_password"][0]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1302 email = request.args["email"][0]
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
1303 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
1304 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
1305 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
1306 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
1307 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
1308 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
1309 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
1310
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
1311 @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
1312 def _loginAccount(self, request):
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1313 """Try to authenticate the user with the request information.
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1314
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
1315 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
1316 - C.PROFILE_LOGGED: profile is connected
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1317 - C.PROFILE_LOGGED_EXT_JID: profile is connected and an external jid has
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1318 been used
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
1319 - 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
1320 - C.BAD_REQUEST: something is wrong in the request (bad arguments)
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1321 - C.PROFILE_AUTH_ERROR: either the profile (login) or the profile password
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1322 is wrong
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1323 - C.XMPP_AUTH_ERROR: the profile is authenticated but the XMPP password
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1324 is wrong
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1325 - C.ALREADY_WAITING: a request has already been submitted for this profile,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1326 C.PROFILE_LOGGED_EXT_JID)
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
1327 - 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
1328 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
1329 @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
1330 """
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1331 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1332 login = request.args["login"][0]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1333 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
1334 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
1335 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
1336 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
1337 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
1338
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
1339 assert login
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
1340
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
1341 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
1342 status = yield self.sat_host.connect(request, login, password)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1343 except (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1344 exceptions.DataError,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1345 exceptions.ProfileUnknownError,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1346 exceptions.PermissionError,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1347 ):
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
1348 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
1349 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
1350 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
1351 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
1352 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
1353 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
1354 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
1355 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
1356 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
1357 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
1358 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
1359 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
1360 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
1361 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
1362 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
1363 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
1364 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
1365 request.finish()
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1366 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
1367 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
1368 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
1369 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
1370 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
1371 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
1372 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
1373 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
1374
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
1375 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
1376 request.write(status)
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
1377 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
1378
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1379 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
1380 _session = self.request.getSession()
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1381 profile = session_iface.ISATSession(_session).profile
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1382 return self.sat_host.bridgeCall("isConnected", 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
1383
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1384 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
1385 _session = self.request.getSession()
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1386 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
1387 if self.waiting_profiles.getRequest(profile):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1388 raise jsonrpclib.Fault(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1389 1, C.ALREADY_WAITING
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1390 ) # 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
1391 self.waiting_profiles.setRequest(self.request, profile)
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
1392 self.sat_host.bridgeCall("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
1393 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
1394
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1395 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
1396 """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
1397
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1398 @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
1399 "plugged" (bool): True if a profile is already plugged
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1400 "warning" (unicode): a security warning message if plugged is False and if
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1401 it make sense.
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1402 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
1403 "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
1404 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
1405 @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
1406 - registered:
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1407 - message:
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1408 """
869
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1409 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
1410 _session = self.request.getSession()
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1411 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
1412 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
1413 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
1414 else:
fa7703642c0e server, browser: replaced isRegistered call by a more generic getSessionMetadata which return a dictionary
Goffi <goffi@goffi.org>
parents: 867
diff changeset
1415 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
1416 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
1417 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
1418 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
1419
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1420 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
1421 """Register the frontend specific parameters"""
696
c2f22ca12e23 browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents: 694
diff changeset
1422 # params = """<params><individual>...</category></individual>"""
c2f22ca12e23 browser and server side: remove unibox
souliane <souliane@mailoo.org>
parents: 694
diff changeset
1423 # 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
1424
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1425 def jsonrpc_menusGet(self):
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1426 """Return the parameters XML for profile"""
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1427 # XXX: we put this method in Register because we get menus before being logged
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1428 return self.sat_host.bridgeCall("menusGet", "", C.SECURITY_LIMIT)
336
629c99bbd031 browser + server side: refactored menus:
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1429
819
9b9c0fe0a75f server: fixed bad login check introduced in rev 6a2fd7807770
Goffi <goffi@goffi.org>
parents: 818
diff changeset
1430 def _getSecurityWarning(self):
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1431 """@return: a security warning message, or None if the connection is secure"""
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1432 if (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1433 self.request.URLPath().scheme == "https"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1434 or not self.sat_host.options["security_warning"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1435 ):
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
1436 return None
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1437 text = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1438 "<p>"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1439 + D_("You are about to connect to an unsecure service.")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1440 + "</p><p>&nbsp;</p><p>"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1441 )
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
1442
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1443 if self.sat_host.options["connection_type"] == "both":
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1444 new_port = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1445 (":%s" % self.sat_host.options["port_https_ext"])
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1446 if self.sat_host.options["port_https_ext"] != HTTPS_PORT
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1447 else ""
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1448 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1449 url = "https://%s" % self.request.URLPath().netloc.replace(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1450 ":%s" % self.sat_host.options["port"], new_port
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1451 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1452 text += D_(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1453 "Please read our %(faq_prefix)ssecurity notice%(faq_suffix)s regarding HTTPS"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1454 ) % {
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1455 "faq_prefix": '<a href="http://salut-a-toi.org/faq.html#https" target="#">',
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1456 "faq_suffix": "</a>",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1457 }
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1458 text += "</p><p>" + D_("and use the secure version of this website:")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1459 text += '</p><p>&nbsp;</p><p align="center"><a href="%(url)s">%(url)s</a>' % {
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1460 "url": url
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1461 }
706
fe03637fe5a6 server_side: add a link to the FAQ in the HTTP/HTTPS warning dialog
souliane <souliane@mailoo.org>
parents: 705
diff changeset
1462 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1463 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
1464
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
1465 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
1466
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1467
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1468 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
1469 def __init__(self, sat_host):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1470 web_resource.Resource.__init__(self)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1471 self.register = None
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1472 self.sat_host = sat_host
1008
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1473 self._last_service_prof_disconnect = time.time()
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1474 self.signalDeferred = {} # dict of deferred (key: profile, value: Deferred)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1475 # 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
1476 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
1477
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1478 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
1479 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
1480
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1481 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
1482 """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
1483 @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
1484 _session = self.request.getSession()
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1485 profile = session_iface.ISATSession(_session).profile
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1486 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
1487 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
1488 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
1489 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1490 # the queue is empty, we delete the profile from 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
1491 del self.queue[profile]
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1492 _session.lock() # we don't want the session to expire as long as this
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1493 # connection is active
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1494
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1495 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
1496 _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
1497 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
1498 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
1499 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
1500 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
1501 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
1502 _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
1503 except KeyError:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1504 #  FIXME: happen if session is ended using login page
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
1505 # when pyjamas page is also launched
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1506 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
1507 except IndexError:
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 435
diff changeset
1508 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
1509
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1510 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
1511 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
1512 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
1513
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1514 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
1515 """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
1516 function must have profile as last argument"""
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1517
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1518 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
1519 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
1520 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
1521 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
1522 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
1523 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
1524 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
1525 except KeyError:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1526 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
1527 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
1528 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
1529 del self.signalDeferred[profile]
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1530
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1531 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
1532
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
1533 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
1534 """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
1535
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1536 XXX: We need need a dedicated handler has actionNew use a security_limit
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1537 which must be managed
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
1538 @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
1539 @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
1540 @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
1541 @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
1542 """
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
1543 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
1544 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
1545 # 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
1546 # 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
1547 # 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
1548 if security_limit >= C.SECURITY_LIMIT:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1549 log.debug(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1550 u"Ignoring action {action_id}, blocked by security limit".format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1551 action_id=action_id
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1552 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1553 )
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
1554 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
1555 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
1556 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
1557 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
1558 except KeyError:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1559 self.queue.setdefault(profile, []).append(signal_data)
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
1560 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
1561 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
1562 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
1563
710
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1564 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
1565 """Connection is done.
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1566
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1567 @param profile (unicode): %(doc_profile)s
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1568 @param jid_s (unicode): the JID that we were assigned by the server, as the
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1569 resource might differ from the JID we asked for.
710
df8cb7bedfbf server_side: update connected signal handler according to sat changeset 1435 (7590bbf44eed)
souliane <souliane@mailoo.org>
parents: 707
diff changeset
1570 """
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
1571 # 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
1572 # 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
1573 # 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
1574 # 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
1575 # 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
1576 # 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
1577 # 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
1578
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1579 def disconnected(self, profile):
1008
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1580 if profile == C.SERVICE_PROFILE:
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1581 # if service profile has been disconnected, we try to reconnect it
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1582 # if we can't we show error message
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1583 # and if we have 2 disconnection in a short time, we don't try to reconnect
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1584 # and display an error message
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1585 disconnect_delta = time.time() - self._last_service_prof_disconnect
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1586 if disconnect_delta < 15:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1587 log.error(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1588 _(u"Service profile disconnected twice in a short time, please "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1589 u"check connection"))
1008
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1590 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1591 log.info(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1592 _(u"Service profile has been disconnected, but we need it! "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1593 u"Reconnecting it..."))
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1594 d = self.sat_host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1595 "connect", profile, self.sat_host.options["passphrase"], {}
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1596 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1597 d.addErrback(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1598 lambda failure_: log.error(_(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1599 u"Can't reconnect service profile, please check connection: "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1600 u"{reason}").format(reason=failure_)))
1008
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1601 self._last_service_prof_disconnect = time.time()
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1602 return
1593e00078d2 server: reconnect SERVICE_PROFILE if it has been disconnected:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
1603
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1604 if not profile in self.sat_host.prof_connected:
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1605 log.info(_(u"'disconnected' signal received for a not connected profile "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1606 u"({profile})").format(profile=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
1607 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
1608 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
1609 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
1610 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
1611 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
1612 else:
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1613 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
1614 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
1615 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
1616
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1617 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
1618 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1619 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
1620 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1621 _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
1622 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
1623 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
1624 if not profile:
1138
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
1625 # FIXME: this method should not use _cbRender
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
1626 # but all txJsonRPC code will be removed in 0.8 in favor of webRTC
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
1627 # and it is currently used only with Libervia legacy app,
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
1628 # so we do a is_jsonp workaround for now
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
1629 self.is_jsonp = False
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1630 # user is not identified, we return a jsonrpc fault
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1631 fault = jsonrpclib.Fault(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1632 C.ERRNUM_LIBERVIA, C.NOT_ALLOWED
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1633 ) # FIXME: define some standard error codes for libervia
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1634 return jsonrpc.JSONRPC._cbRender(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1635 self, fault, request, parsed.get("id"), parsed.get("jsonrpc")
1138
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
1636 )
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1637 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
1638 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
1639
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1640
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
1641 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
1642 """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
1643 It redirect the stream to SàT core backend"""
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1644
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1645 isLeaf = True
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1646 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
1647
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1648 def __init__(self, sat_host):
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1649 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
1650 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
1651 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
1652
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1653 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
1654 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
1655
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1656 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
1657 """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
1658 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
1659
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1660 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
1661 """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
1662 @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
1663 @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
1664 @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
1665 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
1666 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1667 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
1668
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1669 def 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
1670 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1671 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
1672 - 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
1673 - except login, every method is jsonrpc
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1674 - user doesn't need to be authentified for getSessionMetadata, but must be
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1675 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
1676 """
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1677 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
1678 filepath = os.path.join(self.upload_dir, filename)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1679 # FIXME: the uploaded file is fully loaded in memory at form parsing time so far
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1680 # (see twisted.web.http.Request.requestReceived). A custom requestReceived
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1681 # should be written in the futur. In addition, it is not yet possible to
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1682 # get progression informations (see
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1683 # http://twistedmatrix.com/trac/ticket/288)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1684
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1685 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
1686 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
1687
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1688 def finish(d):
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
1689 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
1690 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
1691 # 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
1692 # 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
1693 # 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
1694 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
1695
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1696 d = JSONRPCMethodManager(self.sat_host).asyncBridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1697 *self._fileWritten(request, filepath)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1698 )
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1699 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
1700 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
1701
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1702
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1703 class UploadManagerRadioCol(UploadManager):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1704 NAME = "song"
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1705
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1706 def _getFileName(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1707 extension = os.path.splitext(request.args["filename"][0])[1]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1708 return "%s%s" % (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1709 str(uuid.uuid4()),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1710 extension,
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1711 ) # XXX: chromium doesn't seem to play song without the .ogg extension, even
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1712 # 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
1713
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1714 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
1715 """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
1716 @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
1717 @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
1718 @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
1719 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
1720 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1721 profile = session_iface.ISATSession(request.getSession()).profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1722 return ("radiocolSongAdded", request.args["referee"][0], filepath, 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
1723
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1724
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1725 class UploadManagerAvatar(UploadManager):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1726 NAME = "avatar_path"
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1727
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1728 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
1729 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
1730
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1731 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
1732 """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
1733 @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
1734 @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
1735 @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
1736 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
1737 """
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
1738 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
1739 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
1740
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1741
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1742 class Libervia(service.Service):
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
1743 debug = defer.Deferred.debug # True if twistd/Libervia is launched in debug mode
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1744
810
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1745 def __init__(self, options):
3905bc24eb17 server: proper options handling
Goffi <goffi@goffi.org>
parents: 801
diff changeset
1746 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
1747 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
1748 self.waiting_profiles = WaitingRequests() # FIXME: should be removed
1146
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1749 self._main_conf = None
1152
1c23252958ed server: iNotify support:
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
1750 self.files_watcher = FilesWatcher(self)
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1751
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1752 if self.options["base_url_ext"]:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1753 self.base_url_ext = self.options.pop("base_url_ext")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1754 if self.base_url_ext[-1] != "/":
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1755 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
1756 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
1757 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
1758 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
1759 # 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
1760 # scheme = self.base_url_ext_data.scheme or 'https'
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1761 self.base_url_ext_data = urlparse.urlsplit("")
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
1762
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1763 if not self.options["port_https_ext"]:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1764 self.options["port_https_ext"] = self.options["port_https"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1765 if self.options["data_dir"] == DATA_DIR_DEFAULT:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1766 coerceDataDir(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1767 self.options["data_dir"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1768 ) # this is not done when using the default value
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1769
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1770 self.html_dir = os.path.join(self.options["data_dir"], C.HTML_DIR)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1771 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
1772
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1773 self._cleanup = []
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1774
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1775 self.signal_handler = SignalHandler(self)
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1776 self.sessions = {} # key = session value = user
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
1777 self.prof_connected = set() # Profiles connected
985
64826e69f365 pages: cache mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 984
diff changeset
1778 self.ns_map = {} # map of short name to namespaces
470
34ce41e014c4 server side: options managing improvments:
Goffi <goffi@goffi.org>
parents: 465
diff changeset
1779
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
1780 ## bridge ##
1126
7cd89277a129 server: fixed missing backend detection
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
1781 self.bridge = Bridge()
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1782 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
1783
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1784 @property
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1785 def roots(self):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1786 """Return available virtual host roots
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1787
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1788 Root resources are only returned once, even if they are present for multiple
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1789 named vhosts. Order is not relevant, except for default vhost which is always
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1790 returned first.
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1791 @return (list[web_resource.Resource]): all vhost root resources
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1792 """
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1793 roots = list(set(self.vhost_root.hosts.values()))
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1794 default = self.vhost_root.default
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1795 if default is not None and default not in roots:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1796 roots.insert(0, default)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1797 return roots
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1798
1146
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1799 @property
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1800 def main_conf(self):
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1801 """SafeConfigParser instance opened on configuration file (sat.conf)"""
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1802 if self._main_conf is None:
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1803 self._main_conf = config.parseMainConf()
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1804 return self._main_conf
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1805
1147
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1806 def getConfig(self, site_root_res, key, default=None, value_type=None):
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1807 """Retrieve configuration associated to a site
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1808
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1809 Section is automatically set to site name
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1810 @param site_root_res(LiberviaRootResource): resource of the site in use
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1811 @param key(unicode): key to use
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1812 @param default: value to use if not found (see [config.getConfig])
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1813 @param value_type(unicode, None): filter to use on value
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1814 Note that filters are already automatically used when the key finish
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1815 by a well known suffix ("_path", "_list", "_dict", or "_json")
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1816 None to use no filter, else can be:
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1817 - "path": a path is expected, will be normalized and expanded
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1818
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1819 """
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1820 section = site_root_res.site_name.lower().strip()
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1821 value = config.getConfig(self.main_conf, section, key, default=default)
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1822 if value_type is not None:
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1823 if value_type == u'path':
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1824 v_filter = lambda v: os.path.abspath(os.path.expanduser(v))
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1825 else:
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1826 raise ValueError(u"unknown value type {value_type}".format(
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1827 value_type = value_type))
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1828 if isinstance(value, list):
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1829 value = [v_filter(v) for v in value]
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1830 elif isinstance(value, dict):
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1831 value = {k:v_filter(v) for k,v in value.items()}
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1832 elif value is not None:
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1833 value = v_filter(v)
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1834 return value
02afab1b15c5 server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
Goffi <goffi@goffi.org>
parents: 1146
diff changeset
1835
985
64826e69f365 pages: cache mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 984
diff changeset
1836 def _namespacesGetCb(self, ns_map):
64826e69f365 pages: cache mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 984
diff changeset
1837 self.ns_map = ns_map
64826e69f365 pages: cache mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 984
diff changeset
1838
64826e69f365 pages: cache mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 984
diff changeset
1839 def _namespacesGetEb(self, failure_):
64826e69f365 pages: cache mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 984
diff changeset
1840 log.error(_(u"Can't get namespaces map: {msg}").format(msg=failure_))
64826e69f365 pages: cache mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 984
diff changeset
1841
1130
8a7d75c18d40 server: fixed front_url_filter in templates renderer
Goffi <goffi@goffi.org>
parents: 1129
diff changeset
1842 @template.contextfilter
1127
9234f29053b0 server, pages: update to handle multi sites themes, first draft:
Goffi <goffi@goffi.org>
parents: 1126
diff changeset
1843 def _front_url_filter(self, ctx, relative_url):
9234f29053b0 server, pages: update to handle multi sites themes, first draft:
Goffi <goffi@goffi.org>
parents: 1126
diff changeset
1844 template_data = ctx[u'template_data']
9234f29053b0 server, pages: update to handle multi sites themes, first draft:
Goffi <goffi@goffi.org>
parents: 1126
diff changeset
1845 return os.path.join(u'/', C.TPL_RESOURCE, template_data.site or u'sat',
9234f29053b0 server, pages: update to handle multi sites themes, first draft:
Goffi <goffi@goffi.org>
parents: 1126
diff changeset
1846 C.TEMPLATE_TPL_DIR, template_data.theme, relative_url)
9234f29053b0 server, pages: update to handle multi sites themes, first draft:
Goffi <goffi@goffi.org>
parents: 1126
diff changeset
1847
1132
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1848 def _moveFirstLevelToDict(self, options, key, keys_to_keep):
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1849 """Read a config option and put value at first level into u'' dict
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1850
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1851 This is useful to put values for Libervia official site directly in dictionary,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1852 and to use site_name as keys when external sites are used.
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1853 options will be modified in place
1132
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1854 @param options(dict): options to modify
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1855 @param key(unicode): setting key to modify
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1856 @param keys_to_keep(list(unicode)): keys allowed in first level
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1857 """
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1858 try:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1859 conf = options[key]
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1860 except KeyError:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1861 return
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1862 if not isinstance(conf, dict):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1863 options[key] = {u'': conf}
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1864 return
1132
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1865 default_dict = conf.get(u'', {})
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1866 to_delete = []
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1867 for key, value in conf.iteritems():
1132
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1868 if key not in keys_to_keep:
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1869 default_dict[key] = value
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1870 to_delete.append(key)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1871 for key in to_delete:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1872 del conf[key]
1132
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1873 if default_dict:
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1874 conf[u''] = default_dict
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1875
1146
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1876 @defer.inlineCallbacks
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1877 def backendReady(self, __):
1151
49ff1330c9d0 server: added "dev_mode" boolean option (not used yet but will be soon)
Goffi <goffi@goffi.org>
parents: 1147
diff changeset
1878 if self.options[u'dev_mode']:
49ff1330c9d0 server: added "dev_mode" boolean option (not used yet but will be soon)
Goffi <goffi@goffi.org>
parents: 1147
diff changeset
1879 log.info(_(u"Developer mode activated"))
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1880 self.media_dir = self.bridge.getConfig("", "media_dir")
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1881 self.local_dir = self.bridge.getConfig("", "local_dir")
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1882 self.cache_root_dir = os.path.join(self.local_dir, C.CACHE_DIR)
1132
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1883 self.renderer = template.Renderer(self, self._front_url_filter)
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1884 sites_names = self.renderer.sites_paths.keys()
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1885
1132
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1886 self._moveFirstLevelToDict(self.options, "url_redirections_dict", sites_names)
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1887 self._moveFirstLevelToDict(self.options, "menu_json", sites_names)
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1888 if not u'' in self.options["menu_json"]:
0cafb79ced6d server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
Goffi <goffi@goffi.org>
parents: 1131
diff changeset
1889 self.options["menu_json"][u''] = C.DEFAULT_MENU
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1890
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1891 # we create virtual hosts and import Libervia pages into them
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1892 self.vhost_root = vhost.NameVirtualHost()
1153
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1893 default_site_path = os.path.abspath(os.path.dirname(libervia.__file__))
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1894 # self.sat_root is official Libervia site
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1895 self.sat_root = default_root = LiberviaRootResource(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1896 host=self, host_name=u'', site_name=u'', site_path=default_site_path,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1897 path=self.html_dir)
1153
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1898 if self.options['dev_mode']:
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1899 self.files_watcher.watchDir(
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1900 default_site_path, auto_add=True, recursive=True,
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1901 callback=LiberviaPage.onFileChange, site_root=self.sat_root,
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1902 site_path=default_site_path)
1146
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1903 tasks_manager = TasksManager(self, self.sat_root)
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1904 yield tasks_manager.runTasks()
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1905 LiberviaPage.importPages(self, self.sat_root)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1906 # FIXME: handle _setMenu in a more generic way, taking care of external sites
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1907 self.sat_root._setMenu(self.options["menu_json"])
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1908 self.vhost_root.default = default_root
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1909 existing_vhosts = {u'': default_root}
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1910
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1911 for host_name, site_name in self.options["vhosts_dict"].iteritems():
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1912 try:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1913 site_path = self.renderer.sites_paths[site_name]
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1914 except KeyError:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1915 log.warning(_(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1916 u"host {host_name} link to non existing site {site_name}, ignoring "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1917 u"it").format(host_name=host_name, site_name=site_name))
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1918 continue
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1919 if site_name in existing_vhosts:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1920 # we have an alias host, we re-use existing resource
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1921 res = existing_vhosts[site_name]
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1922 else:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1923 # for root path we first check if there is a global static dir
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1924 # if not, we use default template's static dic
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1925 root_path = os.path.join(site_path, C.TEMPLATE_STATIC_DIR)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1926 if not os.path.isdir(root_path):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1927 root_path = os.path.join(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1928 site_path, C.TEMPLATE_TPL_DIR, C.TEMPLATE_THEME_DEFAULT,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1929 C.TEMPLATE_STATIC_DIR)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1930 res = LiberviaRootResource(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1931 host=self,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1932 host_name=host_name,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1933 site_name=site_name,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1934 site_path=site_path,
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1935 path=root_path)
1153
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1936
1191
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1937 existing_vhosts[site_name] = res
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1938
1153
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1939 if self.options['dev_mode']:
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1940 self.files_watcher.watchDir(
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1941 site_path, auto_add=True, recursive=True,
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1942 callback=LiberviaPage.onFileChange, site_root=res,
94f9d81a475e pages: auto reloading
Goffi <goffi@goffi.org>
parents: 1152
diff changeset
1943 site_path=site_path)
1146
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1944 tasks_manager = TasksManager(self, res)
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
1945 yield tasks_manager.runTasks()
1196
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
1946 res.putChild(
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
1947 C.BUILD_DIR,
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
1948 static.File(self.getBuildPath(site_name),
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
1949 defaultType="application/octet-stream"),
a15ac511390c server: changed defaultType for File resources to "application/octet-stream" instead of "text/html"
Goffi <goffi@goffi.org>
parents: 1191
diff changeset
1950 )
1191
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1951
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1952 LiberviaPage.importPages(self, res)
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1953 # FIXME: default pages are accessible if not overriden by external website
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1954 # while necessary for login or re-using existing pages
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1955 # we may want to disable access to the page by direct URL
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1956 # (e.g. /blog disabled except if called by external site)
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1957 LiberviaPage.importPages(self, res, root_path=default_site_path)
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1958 res._setMenu(self.options["menu_json"])
ba45dcdbeeaf server: fixed sites alias:
Goffi <goffi@goffi.org>
parents: 1184
diff changeset
1959
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1960 self.vhost_root.addHost(host_name.encode('utf-8'), res)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1961
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1962 templates_res = web_resource.Resource()
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1963 self.putChildAll(C.TPL_RESOURCE, templates_res)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1964 for site_name, site_path in self.renderer.sites_paths.iteritems():
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1965 templates_res.putChild(site_name or u'sat', ProtectedFile(site_path))
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1966
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1967 _register = Register(self)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1968 _upload_radiocol = UploadManagerRadioCol(self)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1969 _upload_avatar = UploadManagerAvatar(self)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1970 d = self.bridgeCall("namespacesGet")
985
64826e69f365 pages: cache mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 984
diff changeset
1971 d.addCallback(self._namespacesGetCb)
64826e69f365 pages: cache mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 984
diff changeset
1972 d.addErrback(self._namespacesGetEb)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1973 self.signal_handler.plugRegister(_register)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1974 self.bridge.register_signal("connected", self.signal_handler.connected)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
1975 self.bridge.register_signal("disconnected", self.signal_handler.disconnected)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1976 # core
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1977 for signal_name in [
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1978 "presenceUpdate",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1979 "messageNew",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1980 "subscribe",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1981 "contactDeleted",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1982 "newContact",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1983 "entityDataUpdated",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1984 "paramUpdate",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1985 ]:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1986 self.bridge.register_signal(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1987 signal_name, self.signal_handler.getGenericCb(signal_name)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1988 )
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1989 # XXX: actionNew is handled separately because the handler must manage
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
1990 # security_limit
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1991 self.bridge.register_signal("actionNew", self.signal_handler.actionNewHandler)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1992 # plugins
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1993 for signal_name in [
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1994 "psEvent",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1995 "mucRoomJoined",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1996 "tarotGameStarted",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1997 "tarotGameNew",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1998 "tarotGameChooseContrat",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
1999 "tarotGameShowCards",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2000 "tarotGameInvalidCards",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2001 "tarotGameCardsPlayed",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2002 "tarotGameYourTurn",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2003 "tarotGameScore",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2004 "tarotGamePlayers",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2005 "radiocolStarted",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2006 "radiocolPreload",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2007 "radiocolPlay",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2008 "radiocolNoUpload",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2009 "radiocolUploadOk",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2010 "radiocolSongRejected",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2011 "radiocolPlayers",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2012 "mucRoomLeft",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2013 "mucRoomUserChangedNick",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2014 "chatStateReceived",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2015 ]:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2016 self.bridge.register_signal(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2017 signal_name, self.signal_handler.getGenericCb(signal_name), "plugin"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2018 )
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2019
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2020 # JSON APIs
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2021 self.putChildSAT("json_signal_api", self.signal_handler)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2022 self.putChildSAT("json_api", MethodHandler(self))
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2023 self.putChildSAT("register_api", _register)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2024
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2025 # files upload
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2026 self.putChildSAT("upload_radiocol", _upload_radiocol)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2027 self.putChildSAT("upload_avatar", _upload_avatar)
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2028
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2029 # static pages
1199
b300eaec53b6 server: don't raise error anymore if themes_dir is invalid or legacy blog can't be created:
Goffi <goffi@goffi.org>
parents: 1196
diff changeset
2030 # FIXME: legacy blog must be removed entirely in 0.8
b300eaec53b6 server: don't raise error anymore if themes_dir is invalid or legacy blog can't be created:
Goffi <goffi@goffi.org>
parents: 1196
diff changeset
2031 try:
b300eaec53b6 server: don't raise error anymore if themes_dir is invalid or legacy blog can't be created:
Goffi <goffi@goffi.org>
parents: 1196
diff changeset
2032 micro_blog = MicroBlog(self)
b300eaec53b6 server: don't raise error anymore if themes_dir is invalid or legacy blog can't be created:
Goffi <goffi@goffi.org>
parents: 1196
diff changeset
2033 except Exception as e:
b300eaec53b6 server: don't raise error anymore if themes_dir is invalid or legacy blog can't be created:
Goffi <goffi@goffi.org>
parents: 1196
diff changeset
2034 log.warning(u"Can't load legacy microblog, ignoring it: {reason}".format(
b300eaec53b6 server: don't raise error anymore if themes_dir is invalid or legacy blog can't be created:
Goffi <goffi@goffi.org>
parents: 1196
diff changeset
2035 reason=e))
b300eaec53b6 server: don't raise error anymore if themes_dir is invalid or legacy blog can't be created:
Goffi <goffi@goffi.org>
parents: 1196
diff changeset
2036 else:
b300eaec53b6 server: don't raise error anymore if themes_dir is invalid or legacy blog can't be created:
Goffi <goffi@goffi.org>
parents: 1196
diff changeset
2037 self.putChildSAT("blog_legacy", micro_blog)
b300eaec53b6 server: don't raise error anymore if themes_dir is invalid or legacy blog can't be created:
Goffi <goffi@goffi.org>
parents: 1196
diff changeset
2038 self.putChildSAT(C.THEMES_URL, ProtectedFile(self.themes_dir))
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2039
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2040 # websocket
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2041 if self.options["connection_type"] in ("https", "both"):
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2042 wss = websockets.LiberviaPageWSProtocol.getResource(self, secure=True)
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2043 self.putChildAll("wss", wss)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2044 if self.options["connection_type"] in ("http", "both"):
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2045 ws = websockets.LiberviaPageWSProtocol.getResource(self, secure=False)
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2046 self.putChildAll("ws", ws)
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2047
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2048 ## following signal is needed for cache handling in Libervia pages
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2049 self.bridge.register_signal(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2050 "psEventRaw", partial(LiberviaPage.onNodeEvent, self), "plugin"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2051 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2052 self.bridge.register_signal(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2053 "messageNew", partial(LiberviaPage.onSignal, self, "messageNew")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2054 )
917
86563d6c83b0 server: Libervia pages:
Goffi <goffi@goffi.org>
parents: 915
diff changeset
2055
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2056 #  Progress handling
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2057 self.bridge.register_signal(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2058 "progressStarted", partial(ProgressHandler._signal, "started")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2059 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2060 self.bridge.register_signal(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2061 "progressFinished", partial(ProgressHandler._signal, "finished")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2062 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2063 self.bridge.register_signal(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2064 "progressError", partial(ProgressHandler._signal, "error")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2065 )
1063
4b69f69c6ffd server: new ProgressHandler helper class, to handle progressing actions
Goffi <goffi@goffi.org>
parents: 1055
diff changeset
2066
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2067 # media dirs
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2068 # FIXME: get rid of dirname and "/" in C.XXX_DIR
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2069 self.putChildAll(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir))
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2070 self.cache_resource = web_resource.NoResource()
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2071 self.putChildAll(C.CACHE_DIR, self.cache_resource)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2072
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2073 # special
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2074 self.putChildSAT(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2075 "radiocol",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2076 ProtectedFile(_upload_radiocol.getTmpDir(), defaultType="audio/ogg"),
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2077 ) # FIXME: We cheat for PoC because we know we are on the same host, so we use
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2078 # directly upload dir
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2079 # pyjamas tests, redirected only for dev versions
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2080 if self.version[-1] == "D":
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2081 self.putChildSAT("test", web_util.Redirect("/libervia_test.html"))
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2082
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
2083 # redirections
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2084 for root in self.roots:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2085 root._initRedirections(self.options)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2086
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2087 # no need to keep url_redirections_dict, it will not be used anymore
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2088 del self.options["url_redirections_dict"]
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2089
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2090 server.Request.defaultContentType = "text/html; charset=utf-8"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2091 wrapped = web_resource.EncodingResourceWrapper(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2092 self.vhost_root, [server.GzipEncoderFactory()]
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2093 )
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2094 self.site = server.Site(wrapped)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2095 self.site.sessionFactory = LiberviaSession
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
2096
1003
05cc33d8e328 server: better error message on init issue / menu_json trouble + stop reactor in this case.
Goffi <goffi@goffi.org>
parents: 995
diff changeset
2097 def initEb(self, failure):
05cc33d8e328 server: better error message on init issue / menu_json trouble + stop reactor in this case.
Goffi <goffi@goffi.org>
parents: 995
diff changeset
2098 log.error(_(u"Init error: {msg}").format(msg=failure))
05cc33d8e328 server: better error message on init issue / menu_json trouble + stop reactor in this case.
Goffi <goffi@goffi.org>
parents: 995
diff changeset
2099 reactor.stop()
05cc33d8e328 server: better error message on init issue / menu_json trouble + stop reactor in this case.
Goffi <goffi@goffi.org>
parents: 995
diff changeset
2100 return failure
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2101
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2102 def _bridgeCb(self):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2103 self.bridge.getReady(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2104 lambda: self.initialised.callback(None),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2105 lambda failure: self.initialised.errback(Exception(failure)),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2106 )
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2107 self.initialised.addCallback(self.backendReady)
1003
05cc33d8e328 server: better error message on init issue / menu_json trouble + stop reactor in this case.
Goffi <goffi@goffi.org>
parents: 995
diff changeset
2108 self.initialised.addErrback(self.initEb)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2109
1126
7cd89277a129 server: fixed missing backend detection
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
2110 def _bridgeEb(self, failure_):
7cd89277a129 server: fixed missing backend detection
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
2111 if isinstance(failure_, BridgeExceptionNoService):
7cd89277a129 server: fixed missing backend detection
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
2112 print(u"Can't connect to SàT backend, are you sure it's launched ?")
7cd89277a129 server: fixed missing backend detection
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
2113 else:
7cd89277a129 server: fixed missing backend detection
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
2114 log.error(u"Can't connect to bridge: {}".format(failure))
7cd89277a129 server: fixed missing backend detection
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
2115 sys.exit(1)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2116
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2117 @property
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2118 def version(self):
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2119 """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
2120 return C.APP_VERSION
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2121
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2122 @property
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2123 def full_version(self):
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2124 """Return the full version of Libervia (with extra data when in dev mode)"""
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2125 version = self.version
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2126 if version[-1] == "D":
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2127 # 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
2128 try:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2129 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2130 except AttributeError:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2131 self._version_cache = u"{} ({})".format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2132 version, utils.getRepositoryData(libervia)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2133 )
682
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2134 return self._version_cache
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2135 else:
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2136 return version
e6bb64bd6b4d server side: implemented methods to get SàT and Libervia versions
Goffi <goffi@goffi.org>
parents: 679
diff changeset
2137
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
2138 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
2139 """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
2140
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
2141 @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
2142 @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
2143
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
2144 """
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
2145 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
2146
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
2147 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
2148 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
2149 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
2150 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
2151 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
2152 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
2153 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
2154
1138
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
2155 def _errback(failure_):
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
2156 d.errback(failure.Failure(failure_))
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
2157
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
2158 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
2159 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
2160 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
2161 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
2162
1090
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2163 @defer.inlineCallbacks
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
2164 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
2165 """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
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 @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
2168 @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
2169 @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
2170 - 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
2171 - 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
2172 @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
2173 """
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 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
2175 self.waiting_profiles.purgeRequest(profile)
1090
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2176 session = request.getSession()
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2177 sat_session = session_iface.ISATSession(session)
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
2178 if sat_session.profile:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2179 log.error(_(u"/!\\ Session has already a profile, this should NEVER happen!"))
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
2180 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
2181
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 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
2183 self.prof_connected.add(profile)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2184 cache_dir = os.path.join(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2185 self.cache_root_dir, u"profiles", regex.pathEscape(profile)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2186 )
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2187 # FIXME: would be better to have a global /cache URL which redirect to
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2188 # profile's cache directory, without uuid
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
2189 self.cache_resource.putChild(sat_session.uuid, ProtectedFile(cache_dir))
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2190 log.debug(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2191 _(u"profile cache resource added from {uuid} to {path}").format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2192 uuid=sat_session.uuid, path=cache_dir
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2193 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2194 )
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
2195
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 def onExpire():
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2197 log.info(u"Session expired (profile={profile})".format(profile=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
2198 self.cache_resource.delEntity(sat_session.uuid)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2199 log.debug(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2200 _(u"profile cache resource {uuid} deleted").format(uuid=sat_session.uuid)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2201 )
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
2202 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2203 # We purge the queue
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
2204 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
2205 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
2206 pass
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2207 # and now we disconnect the profile
1098
01e95ec9df9e server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
2208 self.bridgeCall("disconnect", 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
2209
1090
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2210 session.notifyOnExpire(onExpire)
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
2211
1090
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2212 # FIXME: those session infos should be returned by connect or isConnected
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2213 infos = yield self.bridgeCall("sessionInfosGet", profile)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2214 sat_session.jid = jid.JID(infos["jid"])
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2215 sat_session.backend_started = int(infos["started"])
1090
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2216
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2217 state = C.PROFILE_LOGGED_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2218 defer.returnValue(state)
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
2219
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 @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
2221 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
2222 """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
2223
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 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
2225 @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
2226 @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
2227 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
2228 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
2229 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
2230 @param password(unicode): user password
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2231 @return (unicode, None): C.SESSION_ACTIVE: if session was aleady active else
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2232 self._logged value
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
2233 @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
2234 @raise exceptions.ProfileUnknownError: this login doesn't exist
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2235 @raise exceptions.PermissionError: a login is not accepted (e.g. empty password
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2236 not allowed)
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
2237 @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
2238 @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
2239 @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
2240 @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
2241 @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
2242 """
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2243
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2244 # XXX: all security checks must be done here, even if present in javascript
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2245 if login.startswith("@"):
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2246 raise failure.Failure(exceptions.DataError("No profile_key allowed"))
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
2247
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2248 if login.startswith("guest@@") and login.count("@") == 2:
1100
5976dcd42591 pages (g): use server's connect method to connect instead of bridge, this way normal Libervia workflow is used, and session attributes are initialised.
Goffi <goffi@goffi.org>
parents: 1099
diff changeset
2249 log.debug("logging a guest account")
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2250 elif "@" in login:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2251 if login.count("@") != 1:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2252 raise failure.Failure(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2253 exceptions.DataError("Invalid login: {login}".format(login=login))
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2254 )
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
2255 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
2256 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
2257 except (RuntimeError, jid.InvalidFormat, AttributeError):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2258 raise failure.Failure(exceptions.DataError("No profile_key allowed"))
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
2259
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2260 # 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
2261 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
2262
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2263 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
2264 # 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
2265 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
2266 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
2267 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
2268 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
2269
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2270 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
2271 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
2272 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
2273 # FIXME: find a better way to handle bridge errors
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2274 if (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2275 login_jid is not None and login_jid.user
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2276 ): # try to create a new sat profile using the XMPP credentials
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
2277 if not self.options["allow_registration"]:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2278 log.warning(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2279 u"Trying to register JID account while registration is not "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2280 u"allowed")
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2281 raise failure.Failure(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2282 exceptions.DataError(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2283 u"JID login while registration is not allowed"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2284 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2285 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2286 profile = login # FIXME: what if there is a resource?
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
2287 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
2288 register_with_ext_jid = True
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2289 else: # non existing username
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
2290 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
2291 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2292 if profile != login or (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2293 not password
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2294 and profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2295 not in self.options["empty_password_allowed_warning_dangerous_list"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2296 ):
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
2297 # 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
2298 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
2299 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
2300
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2301 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
2302
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2303 # 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
2304 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
2305 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
2306 # 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
2307 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
2308 # it's a different profile, we need to disconnect it
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2309 log.warning(_(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2310 u"{new_profile} requested login, but {old_profile} was already "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2311 u"connected, disconnecting {old_profile}").format(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2312 old_profile=sat_session.profile, new_profile=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
2313 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
2314
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2315 if self.waiting_profiles.getRequest(profile):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2316 #  FIXME: check if and when this can happen
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
2317 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
2318
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2319 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
2320 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
2321 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
2322 except Exception as failure_:
1138
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
2323 fault = failure_.classname
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
2324 self.waiting_profiles.purgeRequest(profile)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2325 if fault in ("PasswordError", "ProfileUnknownError"):
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2326 log.info(u"Profile {profile} doesn't exist or the submitted password is "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2327 u"wrong".format( profile=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
2328 raise failure.Failure(ValueError(C.PROFILE_AUTH_ERROR))
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2329 elif fault == "SASLAuthError":
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2330 log.info(u"The XMPP password of profile {profile} is wrong"
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2331 .format(profile=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
2332 raise failure.Failure(ValueError(C.XMPP_AUTH_ERROR))
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2333 elif fault == "NoReply":
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2334 log.info(_(u"Did not receive a reply (the timeout expired or the "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2335 u"connection is broken)"))
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
2336 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
2337 else:
1138
ef565839dada server: don't convert failure in errback to jsonrpclib.Fault anymore:
Goffi <goffi@goffi.org>
parents: 1132
diff changeset
2338 log.error(u'Unmanaged fault class "{fault}" in errback for the '
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2339 u'connection of profile {profile}'.format(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2340 fault=fault, profile=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
2341 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
2342
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2343 if connected:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2344 #  profile is already connected in backend
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
2345 # 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
2346 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
2347 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
2348 # 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
2349 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
2350 # 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
2351 # so this line should never be reached
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2352 log.error(_(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2353 u"session profile [{session_profile}] differs from login "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2354 u"profile [{profile}], this should not happen!")
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2355 .format(session_profile=sat_session.profile, profile=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
2356 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
2357 defer.returnValue(C.SESSION_ACTIVE)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2358 log.info(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2359 _(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2360 u"profile {profile} was already connected in backend".format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2361 profile=profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2362 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2363 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2364 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2365 #  no, we have to create it
1090
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2366
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2367 state = yield self._logged(profile, request)
9c41b7e91172 server: set jid and started time in session on log-in:
Goffi <goffi@goffi.org>
parents: 1066
diff changeset
2368 defer.returnValue(state)
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
2369
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2370 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
2371 """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
2372 @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
2373 @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
2374 @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
2375 @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
2376 @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
2377 - 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
2378 - 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
2379 - 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
2380 - 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
2381 - 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
2382 @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
2383 """
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2384 if not self.options["allow_registration"]:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2385 log.warning(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2386 _(u"Registration received while it is not allowed, hack attempt?")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2387 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2388 raise failure.Failure(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2389 exceptions.PermissionError(u"Registration is not allowed on this server")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2390 )
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
2391
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2392 if (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2393 not re.match(C.REG_LOGIN_RE, login)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2394 or not re.match(C.REG_EMAIL_RE, email, re.IGNORECASE)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2395 or len(password) < C.PASSWORD_MIN_LENGTH
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2396 ):
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
2397 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
2398
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2399 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
2400 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
2401
1184
eee7a896cf0e server: show BridgeException traceback on unknown registering status
Goffi <goffi@goffi.org>
parents: 1182
diff changeset
2402 def registeringError(failure_):
1164
ef3adc3f2078 handle invalid certificate on registration + fixed error handling on registration
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
2403 # FIXME: better error handling for bridge error is needed
1184
eee7a896cf0e server: show BridgeException traceback on unknown registering status
Goffi <goffi@goffi.org>
parents: 1182
diff changeset
2404 status = failure_.value.fullname.split('.')[-1]
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
2405 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
2406 return C.ALREADY_EXISTS
1164
ef3adc3f2078 handle invalid certificate on registration + fixed error handling on registration
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
2407 elif status == "InvalidCertificate":
ef3adc3f2078 handle invalid certificate on registration + fixed error handling on registration
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
2408 return C.INVALID_CERTIFICATE
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
2409 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
2410 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
2411 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2412 log.error(
1184
eee7a896cf0e server: show BridgeException traceback on unknown registering status
Goffi <goffi@goffi.org>
parents: 1182
diff changeset
2413 _(u"Unknown registering error status: {status}\n{traceback}").format(
eee7a896cf0e server: show BridgeException traceback on unknown registering status
Goffi <goffi@goffi.org>
parents: 1182
diff changeset
2414 status=status, traceback=failure_.value.message
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2415 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2416 )
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
2417 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
2418
22fe06569b1a server: moved logging worflow in separated method, so it can be used by Libervia Pages
Goffi <goffi@goffi.org>
parents: 959
diff changeset
2419 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
2420 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
2421 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
2422 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
2423
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2424 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
2425 """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
2426
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2427 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
2428 @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
2429 @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
2430 @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
2431 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
2432
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2433 def startService(self):
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
2434 """Connect the profile for Libervia and start the HTTP(S) server(s)"""
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2435
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
2436 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
2437 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
2438 self.stop()
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
2439
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2440 def initOk(__):
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
2441 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
2442 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
2443 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
2444 # we don't want the traceback
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2445 msg = [l for l in unicode(e).split("\n") if l][-1]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2446 log.error(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2447 u"Can't check service profile ({profile}), are you sure it exists ?"
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2448 u"\n{error}".format(profile=C.SERVICE_PROFILE, error=msg))
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
2449 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
2450 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
2451 if not connected:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2452 self.bridge.connect(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2453 C.SERVICE_PROFILE,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2454 self.options["passphrase"],
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2455 {},
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2456 callback=self._startService,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2457 errback=eb,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2458 )
472
42c8e91af048 server side: fixed start sequence when SERVICE_PROFILE is already connected
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2459 else:
42c8e91af048 server side: fixed start sequence when SERVICE_PROFILE is already connected
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2460 self._startService()
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
2461
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
2462 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
2463
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2464 ## URLs ##
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
2465
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2466 def putChildSAT(self, path, resource):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2467 """Add a child to the sat resource"""
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2468 self.sat_root.putChild(path, resource)
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2469
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2470 def putChildAll(self, path, resource):
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2471 """Add a child to all vhost root resources"""
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2472 # we wrap before calling putChild, to avoid having useless multiple instances
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2473 # of the resource
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2474 # FIXME: check that no information is leaked (c.f. https://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#request-encoders)
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2475 wrapped_res = web_resource.EncodingResourceWrapper(
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2476 resource, [server.GzipEncoderFactory()])
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2477 for root in self.roots:
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2478 root.putChild(path, wrapped_res)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
2479
1146
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2480 def getBuildPath(self, site_name):
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2481 """Generate build path for a given site name
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2482
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2483 @param site_name(unicode): name of the site
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2484 @return (unicode): path to the build directory
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2485 """
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2486 build_path_elts = [
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2487 config.getConfig(self.main_conf, "", "local_dir"),
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2488 C.CACHE_DIR,
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2489 C.LIBERVIA_CACHE,
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2490 regex.pathEscape(site_name)]
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2491 build_path = u"/".join(build_path_elts)
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2492 return os.path.abspath(os.path.expanduser(build_path))
76d75423ef53 server: tasks manager first draft:
Goffi <goffi@goffi.org>
parents: 1144
diff changeset
2493
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2494 def getExtBaseURLData(self, request):
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2495 """Retrieve external base URL Data
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2496
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2497 this method tried to retrieve the base URL found by external user
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2498 It does by checking in this order:
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2499 - base_url_ext option from configuration
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2500 - proxy x-forwarder-host headers
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2501 - URL of the request
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2502 @return (urlparse.SplitResult): SplitResult instance with only scheme and
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2503 netloc filled
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2504 """
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2505 ext_data = self.base_url_ext_data
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2506 url_path = request.URLPath()
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2507 if not ext_data.scheme or not ext_data.netloc:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2508 #  ext_data is not specified, we check headers
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2509 if request.requestHeaders.hasHeader("x-forwarded-host"):
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2510 # we are behing a proxy
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2511 # we fill proxy_scheme and proxy_netloc value
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2512 proxy_host = request.requestHeaders.getRawHeaders("x-forwarded-host")[0]
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2513 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2514 proxy_server = request.requestHeaders.getRawHeaders(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2515 "x-forwarded-server"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2516 )[0]
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2517 except TypeError:
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2518 # no x-forwarded-server found, we use proxy_host
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2519 proxy_netloc = proxy_host
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2520 else:
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2521 # if the proxy host has a port, we use it with server name
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2522 proxy_port = urlparse.urlsplit(u"//{}".format(proxy_host)).port
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2523 proxy_netloc = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2524 u"{}:{}".format(proxy_server, proxy_port)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2525 if proxy_port is not None
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2526 else proxy_server
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2527 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2528 proxy_netloc = proxy_netloc.decode("utf-8")
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2529 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2530 proxy_scheme = request.requestHeaders.getRawHeaders(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2531 "x-forwarded-proto"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2532 )[0].decode("utf-8")
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2533 except TypeError:
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2534 proxy_scheme = None
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2535 else:
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2536 proxy_scheme, proxy_netloc = None, None
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2537 else:
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2538 proxy_scheme, proxy_netloc = None, None
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2539
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2540 return urlparse.SplitResult(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2541 ext_data.scheme or proxy_scheme or url_path.scheme.decode("utf-8"),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2542 ext_data.netloc or proxy_netloc or url_path.netloc.decode("utf-8"),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2543 ext_data.path or u"/",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2544 "",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2545 "",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2546 )
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2547
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2548 def getExtBaseURL(self, request, path="", query="", fragment="", scheme=None):
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2549 """Get external URL according to given elements
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2550
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2551 external URL is the URL seen by external user
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2552 @param path(unicode): same as for urlsplit.urlsplit
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2553 path will be prefixed to follow found external URL if suitable
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2554 @param params(unicode): same as for urlsplit.urlsplit
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2555 @param query(unicode): same as for urlsplit.urlsplit
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2556 @param fragment(unicode): same as for urlsplit.urlsplit
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2557 @param scheme(unicode, None): if not None, will override scheme from base URL
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2558 @return (unicode): external URL
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2559 """
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2560 split_result = self.getExtBaseURLData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2561 return urlparse.urlunsplit(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2562 (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2563 split_result.scheme.decode("utf-8") if scheme is None else scheme,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2564 split_result.netloc.decode("utf-8"),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2565 os.path.join(split_result.path, path),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2566 query,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2567 fragment,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2568 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2569 )
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2570
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2571 def checkRedirection(self, vhost_root, url):
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
2572 """check is a part of the URL prefix is redirected then replace it
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
2573
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2574 @param vhost_root(web_resource.Resource): root of this virtual host
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
2575 @param url(unicode): url to check
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
2576 @return (unicode): possibly redirected URL which should link to the same location
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
2577 """
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2578 inv_redirections = vhost_root.inv_redirections
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2579 url_parts = url.strip(u"/").split(u"/")
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
2580 for idx in xrange(len(url), 0, -1):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2581 test_url = u"/" + u"/".join(url_parts[:idx])
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
2582 if test_url in inv_redirections:
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
2583 rem_url = url_parts[idx:]
1099
ea0d41ef3719 server: return absolute page in checkRedirection
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
2584 return os.path.join(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2585 u"/", u"/".join([inv_redirections[test_url]] + rem_url)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2586 )
1037
dc6c8c4d8ff6 server: redirection rework:
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
2587 return url
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2588
920
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2589 ## Sessions ##
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2590
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2591 def purgeSession(self, request):
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2592 """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
2593 session = request.session
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2594 if session is not None:
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2595 log.debug(_(u"session purge"))
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2596 session.expire()
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2597 # 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
2598 # session during request handling
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2599 request._secureSession = request._insecureSession = None
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2600
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2601 def getSessionData(self, request, *args):
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2602 """helper method to retrieve session data
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2603
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2604 @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
2605 @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
2606 @return (iterator(data)): requested session data
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2607 """
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2608 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
2609 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
2610 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
2611 else:
94f88277c2e7 libervia (pages): getSessionData return one session if used with one argument, else an iterator
Goffi <goffi@goffi.org>
parents: 923
diff changeset
2612 return (iface(session) for iface in args)
920
8cea8bf41b03 server: new purgeSession and getSessionData helper methods
Goffi <goffi@goffi.org>
parents: 919
diff changeset
2613
1093
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2614 @defer.inlineCallbacks
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2615 def getAffiliation(self, request, service, node):
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2616 """retrieve pubsub node affiliation for current user
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2617
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2618 use cache first, and request pubsub service if not cache is found
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2619 @param request(server.Request): request linked to the session
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2620 @param service(jid.JID): pubsub service
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2621 @param node(unicode): pubsub node
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2622 @return (unicode): affiliation
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2623 """
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2624 sat_session = self.getSessionData(request, session_iface.ISATSession)
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2625 if sat_session.profile is None:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2626 raise exceptions.InternalError(u"profile must be set to use this method")
1093
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2627 affiliation = sat_session.getAffiliation(service, node)
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2628 if affiliation is not None:
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2629 defer.returnValue(affiliation)
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2630 else:
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2631 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2632 affiliations = yield self.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2633 "psAffiliationsGet", service.full(), node, sat_session.profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2634 )
1093
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2635 except Exception as e:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2636 log.warning(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2637 "Can't retrieve affiliation for {service}/{node}: {reason}".format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2638 service=service, node=node, reason=e
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2639 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2640 )
1093
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2641 affiliation = u""
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2642 else:
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2643 try:
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2644 affiliation = affiliations[node]
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2645 except KeyError:
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2646 affiliation = u""
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2647 sat_session.setAffiliation(service, node, affiliation)
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2648 defer.returnValue(affiliation)
eda7a1c6532a server: new getAffiliation method:
Goffi <goffi@goffi.org>
parents: 1090
diff changeset
2649
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2650 ## Websocket (dynamic pages) ##
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2651
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2652 def getWebsocketURL(self, request):
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2653 base_url_split = self.getExtBaseURLData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2654 if base_url_split.scheme.endswith("s"):
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2655 scheme = u"wss"
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2656 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2657 scheme = u"ws"
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2658
1006
d0b27d1e2d50 server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
2659 return self.getExtBaseURL(request, path=scheme, scheme=scheme)
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2660
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2661 def registerWSToken(self, token, page, request):
1203
251eba911d4d server (websockets): fixed websocket handling on HTTPS connections:
Goffi <goffi@goffi.org>
parents: 1202
diff changeset
2662 # we make a shallow copy of request to avoid losing request.channel when
251eba911d4d server (websockets): fixed websocket handling on HTTPS connections:
Goffi <goffi@goffi.org>
parents: 1202
diff changeset
2663 # connection is lost (which would result as request.isSecure() being always
251eba911d4d server (websockets): fixed websocket handling on HTTPS connections:
Goffi <goffi@goffi.org>
parents: 1202
diff changeset
2664 # False). See #327
251eba911d4d server (websockets): fixed websocket handling on HTTPS connections:
Goffi <goffi@goffi.org>
parents: 1202
diff changeset
2665 request._signal_id = id(request)
251eba911d4d server (websockets): fixed websocket handling on HTTPS connections:
Goffi <goffi@goffi.org>
parents: 1202
diff changeset
2666 websockets.LiberviaPageWSProtocol.registerToken(token, page, copy.copy(request))
995
f88325b56a6a server: dynamic pages first draft:
Goffi <goffi@goffi.org>
parents: 990
diff changeset
2667
1019
34240d08f682 pages: HTTP cache headers handling:
Goffi <goffi@goffi.org>
parents: 1012
diff changeset
2668 ## Various utils ##
34240d08f682 pages: HTTP cache headers handling:
Goffi <goffi@goffi.org>
parents: 1012
diff changeset
2669
34240d08f682 pages: HTTP cache headers handling:
Goffi <goffi@goffi.org>
parents: 1012
diff changeset
2670 def getHTTPDate(self, timestamp=None):
34240d08f682 pages: HTTP cache headers handling:
Goffi <goffi@goffi.org>
parents: 1012
diff changeset
2671 now = time.gmtime(timestamp)
34240d08f682 pages: HTTP cache headers handling:
Goffi <goffi@goffi.org>
parents: 1012
diff changeset
2672 fmt_date = u"{day_name}, %d {month_name} %Y %H:%M:%S GMT".format(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2673 day_name=C.HTTP_DAYS[now.tm_wday], month_name=C.HTTP_MONTH[now.tm_mon - 1]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2674 )
1019
34240d08f682 pages: HTTP cache headers handling:
Goffi <goffi@goffi.org>
parents: 1012
diff changeset
2675 return time.strftime(fmt_date, now)
34240d08f682 pages: HTTP cache headers handling:
Goffi <goffi@goffi.org>
parents: 1012
diff changeset
2676
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
2677 ## 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
2678
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
2679 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
2680 """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
2681
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
2682 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
2683 """
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2684 if not self.options["tls_certificate"]:
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
2685 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
2686 self.quit(1)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2687 if not self.options["tls_private_key"]:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2688 self.options["tls_private_key"] = self.options["tls_certificate"]
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
2689
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2690 if not self.options["tls_private_key"]:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2691 self.options["tls_private_key"] = self.options["tls_certificate"]
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
2692
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
2693 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
2694 """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
2695
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
2696 @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
2697 @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
2698 @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
2699 """
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
2700 # 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
2701 # 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
2702 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
2703 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
2704 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
2705 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
2706 buf.append(line)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2707 if "-----END CERTIFICATE-----" in line:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2708 certificates.append(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2709 OpenSSL.crypto.load_certificate(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2710 OpenSSL.crypto.FILETYPE_PEM, "".join(buf)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2711 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2712 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2713 buf = []
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
2714 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
2715 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
2716 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
2717
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
2718 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
2719 """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
2720
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
2721 @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
2722 @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
2723 @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
2724 """
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
2725 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
2726
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
2727 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
2728 """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
2729
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
2730 @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
2731 @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
2732 @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
2733 """
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
2734 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
2735
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
2736 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
2737 """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
2738 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
2739 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
2740
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
2741 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
2742
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2743 for name, option, method in [
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2744 ("privateKey", "tls_private_key", self._loadPKey),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2745 ("certificate", "tls_certificate", self._loadCertificate),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2746 ("extraCertChain", "tls_chain", self._loadCertificates),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2747 ]:
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
2748 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
2749 if not path:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2750 assert option == "tls_chain"
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
2751 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
2752 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
2753 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
2754 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
2755 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
2756 except IOError as e:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2757 log.error(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2758 u"Error while reading file {path} for option {option}: {error}".format(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2759 path=path, option=option, error=e
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2760 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2761 )
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
2762 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
2763 except OpenSSL.crypto.Error:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2764 log.error(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2765 u"Error while parsing file {path} for option {option}, are you sure "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2766 u"it is a valid .pem file?".format( path=path, option=option))
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2767 if (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2768 option == "tls_private_key"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2769 and self.options["tls_certificate"] == path
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2770 ):
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2771 log.error(
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2772 u"You are using the same file for private key and public "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2773 u"certificate, make sure that both a in {path} or use "
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2774 u"--tls_private_key option".format(path=path))
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
2775 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
2776
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
2777 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
2778
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
2779 ## 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
2780
1128
6414fd795df4 server, pages: multi-sites refactoring:
Goffi <goffi@goffi.org>
parents: 1127
diff changeset
2781 def _startService(self, __=None):
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 448
diff changeset
2782 """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
2783
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
2784 @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
2785 @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
2786 @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
2787 """
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
2788 # 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
2789 service_path = regex.pathEscape(C.SERVICE_PROFILE)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2790 cache_dir = os.path.join(self.cache_root_dir, u"profiles", service_path)
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
2791 self.cache_resource.putChild(service_path, ProtectedFile(cache_dir))
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2792 self.service_cache_url = u"/" + os.path.join(C.CACHE_DIR, service_path)
1055
c2037b44f84e server: fixed cache_dir for service profile in session interface
Goffi <goffi@goffi.org>
parents: 1054
diff changeset
2793 session_iface.SATSession.service_cache_url = self.service_cache_url
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
2794
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2795 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
2796 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
2797 context_factory = self._getTLSContextFactory()
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2798 reactor.listenSSL(self.options["port_https"], self.site, context_factory)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2799 if self.options["connection_type"] in ("http", "both"):
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2800 if (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2801 self.options["connection_type"] == "both"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2802 and self.options["redirect_to_https"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2803 ):
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2804 reactor.listenTCP(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2805 self.options["port"],
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2806 server.Site(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2807 RedirectToHTTPS(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2808 self.options["port"], self.options["port_https_ext"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2809 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2810 ),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2811 )
446
c406e46fe9c0 server_side: update the connection mechanism to handle profile passwords
souliane <souliane@mailoo.org>
parents: 445
diff changeset
2812 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2813 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
2814
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
2815 @defer.inlineCallbacks
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2816 def stopService(self):
473
d1565906f228 server_side: fixed some forgotten print statement
Goffi <goffi@goffi.org>
parents: 472
diff changeset
2817 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
2818 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
2819 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
2820 try:
1108
7ec1ba86d38d server: replaced blocking calls to bridge by bridgeCall which is not blocking
Goffi <goffi@goffi.org>
parents: 1106
diff changeset
2821 yield self.bridgeCall("disconnect", C.SERVICE_PROFILE)
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
2822 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
2823 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
2824
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2825 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
2826 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
2827
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 330
diff changeset
2828 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
2829 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
2830
812
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
2831 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
2832 """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
2833
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
2834 @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
2835 """
fd6965c16e7e server: added "quit" method to exit with an exit code when reactor is running
Goffi <goffi@goffi.org>
parents: 810
diff changeset
2836 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
2837 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
2838
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2839
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2840 class RedirectToHTTPS(web_resource.Resource):
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2841 def __init__(self, old_port, new_port):
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2842 web_resource.Resource.__init__(self)
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2843 self.isLeaf = True
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2844 self.old_port = old_port
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2845 self.new_port = new_port
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2846
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2847 def render(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2848 netloc = request.URLPath().netloc.replace(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2849 ":%s" % self.old_port, ":%s" % self.new_port
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2850 )
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2851 url = "https://" + netloc + request.uri
858
7dde76708892 server: URL redirections + misc:
Goffi <goffi@goffi.org>
parents: 856
diff changeset
2852 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
2853
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 413
diff changeset
2854
919
7b267496da1d server: moved session interfaces to session_iface module + added SATGuestSession
Goffi <goffi@goffi.org>
parents: 917
diff changeset
2855 registerAdapter(session_iface.SATSession, server.Session, session_iface.ISATSession)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2856 registerAdapter(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2857 session_iface.SATGuestSession, server.Session, session_iface.ISATGuestSession
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1108
diff changeset
2858 )