Commit 2cc54931 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added a kill handler method to disconnect a connected account.

parent 162ade11
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ from sjrpc.server import SimpleSslRpcServer
from handlers import WelcomeHandler
from conf import CCConf
from client import CCClient
from exceptions import AlreadyRegistered
from exceptions import AlreadyRegistered, NotConnectedAccountError
from tql import TqlQuery, TqlCondition, TqlLimit

class CCServer(object):
@@ -156,6 +156,21 @@ class CCServer(object):

        return tags

    def kill(self, login):
        '''
        Disconnect from the server the client identified by provided login.

        :param login: the login of the user to disconnect
        :throws NotConnectedAccount: when provided account is not connected (or
            if account doesn't exists).
        '''

        client = self._connected.get(login)
        if client is None:
            raise NotConnectedAccountError('The account %s is not '
                                           'connected' % login)
        client.shutdown()

    def list(self, query):
        '''
        List objects on server.
+3 −0
Original line number Diff line number Diff line
@@ -37,3 +37,6 @@ class CCClient(object):

    def get_ip(self):
        return self.connection.getpeername()

    def shutdown(self):
        self.server.manager.shutdown_client(self.connection)
+4 −0
Original line number Diff line number Diff line
@@ -16,3 +16,7 @@ class RightError(Exception):

class BadObjectError(Exception):
    pass


class NotConnectedAccountError(Exception):
    pass
+13 −0
Original line number Diff line number Diff line
@@ -202,6 +202,19 @@ class ClientHandler(OnlineCCHandler):
        for obj in objects:
            self._server.conf.set_enabled(obj['a'], enable=True)

    @listed
    def kill(self, conn, query):
        '''
        Disconnect all connected accounts selected by query.
        '''

        objects = self._server.list(query)
        for obj in objects:
            if 'a' not in obj:
                raise BadObjectError('All objects must have the "a" tag.')
        for obj in objects:
            self._server.kill(obj['a'])

    @listed
    def rights(self, conn, query):
        '''