Add logging the user when a torrent is added or removed
This commit is contained in:
parent
3cd30ea96a
commit
bc5aa1bf71
|
@ -254,7 +254,7 @@ class DelugeRPCProtocol(Protocol):
|
||||||
try:
|
try:
|
||||||
ret = component.get("AuthManager").authorize(*args, **kwargs)
|
ret = component.get("AuthManager").authorize(*args, **kwargs)
|
||||||
if ret:
|
if ret:
|
||||||
self.factory.authorized_sessions[self.transport.sessionno] = ret
|
self.factory.authorized_sessions[self.transport.sessionno] = (ret, args[0])
|
||||||
self.factory.session_protocols[self.transport.sessionno] = self
|
self.factory.session_protocols[self.transport.sessionno] = self
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
sendError()
|
sendError()
|
||||||
|
@ -283,7 +283,7 @@ class DelugeRPCProtocol(Protocol):
|
||||||
if method in self.factory.methods and self.transport.sessionno in self.factory.authorized_sessions:
|
if method in self.factory.methods and self.transport.sessionno in self.factory.authorized_sessions:
|
||||||
try:
|
try:
|
||||||
method_auth_requirement = self.factory.methods[method]._rpcserver_auth_level
|
method_auth_requirement = self.factory.methods[method]._rpcserver_auth_level
|
||||||
auth_level = self.factory.authorized_sessions[self.transport.sessionno]
|
auth_level = self.factory.authorized_sessions[self.transport.sessionno][0]
|
||||||
if auth_level < method_auth_requirement:
|
if auth_level < method_auth_requirement:
|
||||||
# This session is not allowed to call this method
|
# This session is not allowed to call this method
|
||||||
log.debug("Session %s is trying to call a method it is not authorized to call!", self.transport.sessionno)
|
log.debug("Session %s is trying to call a method it is not authorized to call!", self.transport.sessionno)
|
||||||
|
@ -424,6 +424,21 @@ class RPCServer(component.Component):
|
||||||
"""
|
"""
|
||||||
return self.factory.session_id
|
return self.factory.session_id
|
||||||
|
|
||||||
|
def get_session_user(self):
|
||||||
|
"""
|
||||||
|
Returns the username calling the current RPC.
|
||||||
|
|
||||||
|
:returns: the username of the user calling the current RPC
|
||||||
|
:rtype: string
|
||||||
|
|
||||||
|
"""
|
||||||
|
session_id = self.get_session_id()
|
||||||
|
if session_id > -1:
|
||||||
|
return self.factory.authorized_sessions[session_id][1]
|
||||||
|
else:
|
||||||
|
# No connections made yet
|
||||||
|
return ""
|
||||||
|
|
||||||
def is_session_valid(self, session_id):
|
def is_session_valid(self, session_id):
|
||||||
"""
|
"""
|
||||||
Checks if the session is still valid, eg, if the client is still connected.
|
Checks if the session is still valid, eg, if the client is still connected.
|
||||||
|
|
|
@ -476,6 +476,7 @@ class TorrentManager(component.Component):
|
||||||
# Emit the torrent_added signal
|
# Emit the torrent_added signal
|
||||||
component.get("EventManager").emit(TorrentAddedEvent(torrent.torrent_id))
|
component.get("EventManager").emit(TorrentAddedEvent(torrent.torrent_id))
|
||||||
|
|
||||||
|
log.info("Torrent %s added by user: %s", torrent.get_status(["name"])["name"], component.get("RPCServer").get_session_user())
|
||||||
return torrent.torrent_id
|
return torrent.torrent_id
|
||||||
|
|
||||||
def load_torrent(self, torrent_id):
|
def load_torrent(self, torrent_id):
|
||||||
|
@ -515,6 +516,8 @@ class TorrentManager(component.Component):
|
||||||
if torrent_id not in self.torrents:
|
if torrent_id not in self.torrents:
|
||||||
raise InvalidTorrentError("torrent_id not in session")
|
raise InvalidTorrentError("torrent_id not in session")
|
||||||
|
|
||||||
|
torrent_name = self.torrents[torrent_id].get_status(["name"])["name"]
|
||||||
|
|
||||||
# Emit the signal to the clients
|
# Emit the signal to the clients
|
||||||
component.get("EventManager").emit(PreTorrentRemovedEvent(torrent_id))
|
component.get("EventManager").emit(PreTorrentRemovedEvent(torrent_id))
|
||||||
|
|
||||||
|
@ -562,7 +565,7 @@ class TorrentManager(component.Component):
|
||||||
|
|
||||||
# Emit the signal to the clients
|
# Emit the signal to the clients
|
||||||
component.get("EventManager").emit(TorrentRemovedEvent(torrent_id))
|
component.get("EventManager").emit(TorrentRemovedEvent(torrent_id))
|
||||||
|
log.info("Torrent %s removed by user: %s", torrent_name, component.get("RPCServer").get_session_user())
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def load_state(self):
|
def load_state(self):
|
||||||
|
|
Loading…
Reference in New Issue