comparison src/server/server.py @ 694:82123705474b

massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
author souliane <souliane@mailoo.org>
date Thu, 16 Apr 2015 14:57:02 +0200
parents 7a9c7b9f6a28
children c2f22ca12e23
comparison
equal deleted inserted replaced
693:1d60fa4d25a4 694:82123705474b
129 reactor.callLater(self.ID_LIFETIME, self.purgeID, action_tuple) 129 reactor.callLater(self.ID_LIFETIME, self.purgeID, action_tuple)
130 130
131 def purgeID(self, action_tuple): 131 def purgeID(self, action_tuple):
132 """Called when an action_id has not be handled in time""" 132 """Called when an action_id has not be handled in time"""
133 if action_tuple in self.waiting_ids: 133 if action_tuple in self.waiting_ids:
134 log.warning("action of action_id %s [%s] has not been managed, action_id is now ignored" % action_tuple) 134 log.warning(u"action of action_id %s [%s] has not been managed, action_id is now ignored" % action_tuple)
135 del self.waiting_ids[action_tuple] 135 del self.waiting_ids[action_tuple]
136 136
137 def actionResultCb(self, answer_type, action_id, data, profile): 137 def actionResultCb(self, answer_type, action_id, data, profile):
138 """Manage the actionResult signal""" 138 """Manage the actionResult signal"""
139 action_tuple = (action_id, profile) 139 action_tuple = (action_id, profile)
373 sat_jid = sat_session.jid 373 sat_jid = sat_session.jid
374 if not sat_jid: 374 if not sat_jid:
375 # we keep a session cache for jid to avoir jid spoofing 375 # we keep a session cache for jid to avoir jid spoofing
376 sat_jid = sat_session.jid = JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile)) 376 sat_jid = sat_session.jid = JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile))
377 if JID(from_jid).userhost() != sat_jid.userhost() and JID(to_jid).userhost() != sat_jid.userhost(): 377 if JID(from_jid).userhost() != sat_jid.userhost() and JID(to_jid).userhost() != sat_jid.userhost():
378 log.error("Trying to get history from a different jid (given (browser): {}, real (backend): {}), maybe a hack attempt ?".format(from_jid, sat_jid)) 378 log.error(u"Trying to get history from a different jid (given (browser): {}, real (backend): {}), maybe a hack attempt ?".format(from_jid, sat_jid))
379 return {} 379 return {}
380 d = self.asyncBridgeCall("getHistory", from_jid, to_jid, size, between, search, profile) 380 d = self.asyncBridgeCall("getHistory", from_jid, to_jid, size, between, search, profile)
381 381
382 def show(result_dbus): 382 def show(result_dbus):
383 result = [] 383 result = []
543 def jsonrpc_setParam(self, name, value, category): 543 def jsonrpc_setParam(self, name, value, category):
544 profile = ISATSession(self.session).profile 544 profile = ISATSession(self.session).profile
545 if category in self.authorized_params and name in self.authorized_params[category]: 545 if category in self.authorized_params and name in self.authorized_params[category]:
546 return self.sat_host.bridge.setParam(name, value, category, C.SECURITY_LIMIT, profile) 546 return self.sat_host.bridge.setParam(name, value, category, C.SECURITY_LIMIT, profile)
547 else: 547 else:
548 log.warning("Trying to set parameter '%s' in category '%s' without authorization!!!" 548 log.warning(u"Trying to set parameter '%s' in category '%s' without authorization!!!"
549 % (name, category)) 549 % (name, category))
550 550
551 def jsonrpc_launchAction(self, callback_id, data): 551 def jsonrpc_launchAction(self, callback_id, data):
552 #FIXME: any action can be launched, this can be a huge security issue if callback_id can be guessed 552 #FIXME: any action can be launched, this can be a huge security issue if callback_id can be guessed
553 # a security system with authorised callback_id must be implemented, similar to the one for authorised params 553 # a security system with authorised callback_id must be implemented, similar to the one for authorised params
709 709
710 def auth_eb(failure): 710 def auth_eb(failure):
711 fault = failure.value.faultString 711 fault = failure.value.faultString
712 self.waiting_profiles.purgeRequest(login_) 712 self.waiting_profiles.purgeRequest(login_)
713 if fault == 'PasswordError': 713 if fault == 'PasswordError':
714 log.info("Profile %s doesn't exist or the submitted password is wrong" % login_) 714 log.info(u"Profile %s doesn't exist or the submitted password is wrong" % login_)
715 request.write(C.PROFILE_AUTH_ERROR) 715 request.write(C.PROFILE_AUTH_ERROR)
716 elif fault == 'SASLAuthError': 716 elif fault == 'SASLAuthError':
717 log.info("The XMPP password of profile %s is wrong" % login_) 717 log.info(u"The XMPP password of profile %s is wrong" % login_)
718 request.write(C.XMPP_AUTH_ERROR) 718 request.write(C.XMPP_AUTH_ERROR)
719 elif fault == 'NoReply': 719 elif fault == 'NoReply':
720 log.info(_("Did not receive a reply (the timeout expired or the connection is broken)")) 720 log.info(_("Did not receive a reply (the timeout expired or the connection is broken)"))
721 request.write(C.NO_REPLY) 721 request.write(C.NO_REPLY)
722 else: 722 else:
723 log.error('Unmanaged fault string %s in errback for the connection of profile %s' % (fault, login_)) 723 log.error(u'Unmanaged fault string %s in errback for the connection of profile %s' % (fault, login_))
724 request.write(C.UNKNOWN_ERROR % fault) 724 request.write(C.UNKNOWN_ERROR % fault)
725 request.finish() 725 request.finish()
726 726
727 self.waiting_profiles.setRequest(request, login_) 727 self.waiting_profiles.setRequest(request, login_)
728 d = self.asyncBridgeCall("asyncConnect", login_, password_) 728 d = self.asyncBridgeCall("asyncConnect", login_, password_)
763 if reason == "ConflictError": 763 if reason == "ConflictError":
764 request.write(C.ALREADY_EXISTS) 764 request.write(C.ALREADY_EXISTS)
765 elif reason == "InternalError": 765 elif reason == "InternalError":
766 request.write(C.INTERNAL_ERROR) 766 request.write(C.INTERNAL_ERROR)
767 else: 767 else:
768 log.error('Unknown registering error: %s' % (reason,)) 768 log.error(u'Unknown registering error: %s' % (reason,))
769 request.write(C.UNKNOWN_ERROR % reason) 769 request.write(C.UNKNOWN_ERROR % reason)
770 request.finish() 770 request.finish()
771 771
772 d = self.asyncBridgeCall("registerSatAccount", email, password, profile) 772 d = self.asyncBridgeCall("registerSatAccount", email, password, profile)
773 d.addCallback(registered) 773 d.addCallback(registered)
794 # we manage profile server side to avoid profile spoofing 794 # we manage profile server side to avoid profile spoofing
795 sat_session.profile = profile 795 sat_session.profile = profile
796 self.sat_host.prof_connected.add(profile) 796 self.sat_host.prof_connected.add(profile)
797 797
798 def onExpire(): 798 def onExpire():
799 log.info("Session expired (profile=%s)" % (profile,)) 799 log.info(u"Session expired (profile=%s)" % (profile,))
800 try: 800 try:
801 #We purge the queue 801 #We purge the queue
802 del self.sat_host.signal_handler.queue[profile] 802 del self.sat_host.signal_handler.queue[profile]
803 except KeyError: 803 except KeyError:
804 pass 804 pass
1130 self.site.sessionFactory = LiberviaSession 1130 self.site.sessionFactory = LiberviaSession
1131 1131
1132 self.bridge.getReady(lambda: self.initialised.callback(None), 1132 self.bridge.getReady(lambda: self.initialised.callback(None),
1133 lambda failure: self.initialised.errback(Exception(failure))) 1133 lambda failure: self.initialised.errback(Exception(failure)))
1134 self.initialised.addCallback(backendReady) 1134 self.initialised.addCallback(backendReady)
1135 self.initialised.addErrback(lambda failure: log.error("Init error: %s" % failure)) 1135 self.initialised.addErrback(lambda failure: log.error(u"Init error: %s" % failure))
1136 1136
1137 @property 1137 @property
1138 def version(self): 1138 def version(self):
1139 """Return the short version of Libervia""" 1139 """Return the short version of Libervia"""
1140 return C.APP_VERSION 1140 return C.APP_VERSION
1162 self._cleanup.insert(0, (callback, args, kwargs)) 1162 self._cleanup.insert(0, (callback, args, kwargs))
1163 1163
1164 def startService(self): 1164 def startService(self):
1165 """Connect the profile for Libervia and start the HTTP(S) server(s)""" 1165 """Connect the profile for Libervia and start the HTTP(S) server(s)"""
1166 def eb(e): 1166 def eb(e):
1167 log.error(_("Connection failed: %s") % e) 1167 log.error(_(u"Connection failed: %s") % e)
1168 self.stop() 1168 self.stop()
1169 1169
1170 def initOk(dummy): 1170 def initOk(dummy):
1171 if not self.bridge.isConnected(C.SERVICE_PROFILE): 1171 if not self.bridge.isConnected(C.SERVICE_PROFILE):
1172 self.bridge.asyncConnect(C.SERVICE_PROFILE, self.passphrase, 1172 self.bridge.asyncConnect(C.SERVICE_PROFILE, self.passphrase,
1187 try: 1187 try:
1188 with open(os.path.expanduser(self.ssl_certificate)) as keyAndCert: 1188 with open(os.path.expanduser(self.ssl_certificate)) as keyAndCert:
1189 try: 1189 try:
1190 cert = ssl.PrivateCertificate.loadPEM(keyAndCert.read()) 1190 cert = ssl.PrivateCertificate.loadPEM(keyAndCert.read())
1191 except OpenSSL.crypto.Error as e: 1191 except OpenSSL.crypto.Error as e:
1192 log.error(_("The file '%s' must contain both private and public parts of the certificate") % self.ssl_certificate) 1192 log.error(_(u"The file '%s' must contain both private and public parts of the certificate") % self.ssl_certificate)
1193 raise e 1193 raise e
1194 except IOError as e: 1194 except IOError as e:
1195 log.error(_("The file '%s' doesn't exist") % self.ssl_certificate) 1195 log.error(_(u"The file '%s' doesn't exist") % self.ssl_certificate)
1196 raise e 1196 raise e
1197 reactor.listenSSL(self.port_https, self.site, cert.options()) 1197 reactor.listenSSL(self.port_https, self.site, cert.options())
1198 if self.connection_type in ('http', 'both'): 1198 if self.connection_type in ('http', 'both'):
1199 if self.connection_type == 'both' and self.redirect_to_https: 1199 if self.connection_type == 'both' and self.redirect_to_https:
1200 reactor.listenTCP(self.port, server.Site(RedirectToHTTPS(self.port, self.port_https_ext))) 1200 reactor.listenTCP(self.port, server.Site(RedirectToHTTPS(self.port, self.port_https_ext)))