Example #1
0
    def start(self):
        self.web = ConferenceWeb(self)
        web_server.register_resource('conference', self.web.resource())

        # cleanup old files
        for path in (ConferenceConfig.file_transfer_dir, ConferenceConfig.screensharing_images_dir):
            try:
                shutil.rmtree(path)
            except EnvironmentError:
                pass

        if ServerConfig.enable_bonjour and ServerConfig.default_application == 'conference':
            self.bonjour_focus_service = BonjourService(service='sipfocus')
            self.bonjour_focus_service.start()
            log.msg("Bonjour publication started for service 'sipfocus'")
            self.bonjour_room_service = BonjourService(service='sipuri', name='Conference Room', uri_user='******')
            self.bonjour_room_service.start()
            self.bonjour_room_service.presence_state = BonjourPresenceState('available', u'No participants')
            log.msg("Bonjour publication started for service 'sipuri'")
Example #2
0
    def start(self):
        self.web = ConferenceWeb(self)
        web_server.register_resource("conference", self.web.resource())

        # cleanup old files
        for path in (ConferenceConfig.file_transfer_dir, ConferenceConfig.screensharing_images_dir):
            try:
                shutil.rmtree(path)
            except EnvironmentError:
                pass

        if ServerConfig.enable_bonjour and ServerConfig.default_application == "conference":
            self.bonjour_focus_service = BonjourService(service="sipfocus")
            self.bonjour_focus_service.start()
            log.msg("Bonjour publication started for service 'sipfocus'")
            self.bonjour_room_service = BonjourService(service="sipuri", name="Conference Room", uri_user="******")
            self.bonjour_room_service.start()
            self.bonjour_room_service.presence_state = BonjourPresenceState("available", u"No participants")
            log.msg("Bonjour publication started for service 'sipuri'")
Example #3
0
class ConferenceApplication(SylkApplication):
    implements(IObserver)

    def __init__(self):
        self._rooms = {}
        self.invited_participants_map = {}
        self.bonjour_focus_service = Null
        self.bonjour_room_service = Null
        self.web = Null

    def start(self):
        self.web = ConferenceWeb(self)
        web_server.register_resource("conference", self.web.resource())

        # cleanup old files
        for path in (ConferenceConfig.file_transfer_dir, ConferenceConfig.screensharing_images_dir):
            try:
                shutil.rmtree(path)
            except EnvironmentError:
                pass

        if ServerConfig.enable_bonjour and ServerConfig.default_application == "conference":
            self.bonjour_focus_service = BonjourService(service="sipfocus")
            self.bonjour_focus_service.start()
            log.msg("Bonjour publication started for service 'sipfocus'")
            self.bonjour_room_service = BonjourService(service="sipuri", name="Conference Room", uri_user="******")
            self.bonjour_room_service.start()
            self.bonjour_room_service.presence_state = BonjourPresenceState("available", u"No participants")
            log.msg("Bonjour publication started for service 'sipuri'")

    def stop(self):
        self.bonjour_focus_service.stop()
        self.bonjour_room_service.stop()

    def get_room(self, uri, create=False):
        room_uri = "%s@%s" % (uri.user, uri.host)
        try:
            room = self._rooms[room_uri]
        except KeyError:
            if create:
                room = Room(room_uri)
                self._rooms[room_uri] = room
                return room
            else:
                raise RoomNotFoundError
        else:
            return room

    def remove_room(self, uri):
        room_uri = "%s@%s" % (uri.user, uri.host)
        self._rooms.pop(room_uri, None)

    def validate_acl(self, room_uri, from_uri):
        room_uri = "%s@%s" % (room_uri.user, room_uri.host)
        cfg = get_room_config(room_uri)
        if cfg.access_policy == "allow,deny":
            if cfg.allow.match(from_uri) and not cfg.deny.match(from_uri):
                return
            raise ACLValidationError
        else:
            if cfg.deny.match(from_uri) and not cfg.allow.match(from_uri):
                raise ACLValidationError

    def incoming_session(self, session):
        log.msg("New session from %s to %s" % (session.remote_identity.uri, session.local_identity.uri))
        audio_streams = [stream for stream in session.proposed_streams if stream.type == "audio"]
        chat_streams = [stream for stream in session.proposed_streams if stream.type == "chat"]
        transfer_streams = [stream for stream in session.proposed_streams if stream.type == "file-transfer"]
        if not audio_streams and not chat_streams and not transfer_streams:
            log.msg(u"Session rejected: invalid media, only RTP audio and MSRP chat are supported")
            session.reject(488)
            return
        audio_stream = audio_streams[0] if audio_streams else None
        chat_stream = chat_streams[0] if chat_streams else None
        transfer_stream = transfer_streams[0] if transfer_streams else None

        try:
            self.validate_acl(session.request_uri, session.remote_identity.uri)
        except ACLValidationError:
            log.msg(u"Session rejected: unauthorized by access list")
            session.reject(403)
            return

        if transfer_stream is not None:
            try:
                room = self.get_room(session.request_uri)
            except RoomNotFoundError:
                log.msg(u"Session rejected: room not found")
                session.reject(404)
                return
            if transfer_stream.direction == "sendonly":
                # file transfer 'pull'
                try:
                    file = next(file for file in room.files if file.hash == transfer_stream.file_selector.hash)
                except StopIteration:
                    log.msg(u"Session rejected: requested file not found")
                    session.reject(404)
                    return
                try:
                    transfer_stream.file_selector = file.file_selector
                except EnvironmentError, e:
                    log.msg(u"Session rejected: error opening requested file: %s" % e)
                    session.reject(404)
                    return
            else:
                transfer_stream.handler.save_directory = os.path.join(
                    ConferenceConfig.file_transfer_dir.normalized, room.uri
                )

        NotificationCenter().add_observer(self, sender=session)
        if audio_stream:
            session.send_ring_indication()
        streams = [stream for stream in (audio_stream, chat_stream, transfer_stream) if stream]
        reactor.callLater(4 if audio_stream is not None else 0, self.accept_session, session, streams)
Example #4
0
class ConferenceApplication(SylkApplication):
    implements(IObserver)

    def __init__(self):
        self._rooms = {}
        self.invited_participants_map = {}
        self.bonjour_focus_service = Null
        self.bonjour_room_service = Null
        self.web = Null

    def start(self):
        self.web = ConferenceWeb(self)
        web_server.register_resource('conference', self.web.resource())

        # cleanup old files
        for path in (ConferenceConfig.file_transfer_dir, ConferenceConfig.screensharing_images_dir):
            try:
                shutil.rmtree(path)
            except EnvironmentError:
                pass

        if ServerConfig.enable_bonjour and ServerConfig.default_application == 'conference':
            self.bonjour_focus_service = BonjourService(service='sipfocus')
            self.bonjour_focus_service.start()
            log.msg("Bonjour publication started for service 'sipfocus'")
            self.bonjour_room_service = BonjourService(service='sipuri', name='Conference Room', uri_user='******')
            self.bonjour_room_service.start()
            self.bonjour_room_service.presence_state = BonjourPresenceState('available', u'No participants')
            log.msg("Bonjour publication started for service 'sipuri'")

    def stop(self):
        self.bonjour_focus_service.stop()
        self.bonjour_room_service.stop()

    def get_room(self, uri, create=False):
        room_uri = '%s@%s' % (uri.user, uri.host)
        try:
            room = self._rooms[room_uri]
        except KeyError:
            if create:
                room = Room(room_uri)
                self._rooms[room_uri] = room
                return room
            else:
                raise RoomNotFoundError
        else:
            return room

    def remove_room(self, uri):
        room_uri = '%s@%s' % (uri.user, uri.host)
        self._rooms.pop(room_uri, None)

    def validate_acl(self, room_uri, from_uri):
        room_uri = '%s@%s' % (room_uri.user, room_uri.host)
        cfg = get_room_config(room_uri)
        if cfg.access_policy == 'allow,deny':
            if cfg.allow.match(from_uri) and not cfg.deny.match(from_uri):
                return
            raise ACLValidationError
        else:
            if cfg.deny.match(from_uri) and not cfg.allow.match(from_uri):
                raise ACLValidationError

    def incoming_session(self, session):
        log.msg('New session from %s to %s' % (session.remote_identity.uri, session.local_identity.uri))
        audio_streams = [stream for stream in session.proposed_streams if stream.type=='audio']
        chat_streams = [stream for stream in session.proposed_streams if stream.type=='chat']
        transfer_streams = [stream for stream in session.proposed_streams if stream.type=='file-transfer']
        if not audio_streams and not chat_streams and not transfer_streams:
            log.msg(u'Session rejected: invalid media, only RTP audio and MSRP chat are supported')
            session.reject(488)
            return
        audio_stream = audio_streams[0] if audio_streams else None
        chat_stream = chat_streams[0] if chat_streams else None
        transfer_stream = transfer_streams[0] if transfer_streams else None

        try:
            self.validate_acl(session.request_uri, session.remote_identity.uri)
        except ACLValidationError:
            log.msg(u'Session rejected: unauthorized by access list')
            session.reject(403)
            return

        if transfer_stream is not None:
            try:
                room = self.get_room(session.request_uri)
            except RoomNotFoundError:
                log.msg(u'Session rejected: room not found')
                session.reject(404)
                return
            if transfer_stream.direction == 'sendonly':
                # file transfer 'pull'
                try:
                    file = next(file for file in room.files if file.hash == transfer_stream.file_selector.hash)
                except StopIteration:
                    log.msg(u'Session rejected: requested file not found')
                    session.reject(404)
                    return
                try:
                    transfer_stream.file_selector = file.file_selector
                except EnvironmentError, e:
                    log.msg(u'Session rejected: error opening requested file: %s' % e)
                    session.reject(404)
                    return
            else:
                transfer_stream.handler.save_directory = os.path.join(ConferenceConfig.file_transfer_dir.normalized, room.uri)

        NotificationCenter().add_observer(self, sender=session)
        if audio_stream:
            session.send_ring_indication()
        streams = [stream for stream in (audio_stream, chat_stream, transfer_stream) if stream]
        reactor.callLater(4 if audio_stream is not None else 0, self.accept_session, session, streams)