Ejemplo n.º 1
0
    def post(self):
        """
            Creates a New Channel
        """
        if 'X-API-KEY' in request.headers:
            requestAPIKey = apikey.apikey.query.filter_by(key=request.headers['X-API-KEY']).first()
            if requestAPIKey is not None:
                if requestAPIKey.isValid():
                    args = channelParserPost.parse_args()
                    newChannel = Channel.Channel(int(requestAPIKey.userID), str(uuid.uuid4()), args['channelName'], int(args['topicID']), args['recordEnabled'], args['chatEnabled'], args['commentsEnabled'], args['description'])

                    userQuery = Sec.User.query.filter_by(id=int(requestAPIKey.userID)).first()

                    # Establish XMPP Channel
                    from app import ejabberd
                    sysSettings = settings.settings.query.all()[0]
                    ejabberd.create_room(newChannel.channelLoc, 'conference.' + sysSettings.siteAddress, sysSettings.siteAddress)
                    ejabberd.set_room_affiliation(newChannel.channelLoc, 'conference.' + sysSettings.siteAddress, int(requestAPIKey.userID) + "@" + sysSettings.siteAddress, "owner")

                    # Default values
                    for key, value in globalvars.room_config.items():
                        ejabberd.change_room_option(newChannel.channelLoc, 'conference.' + sysSettings.siteAddress, key, value)

                    # Name and title
                    ejabberd.change_room_option(newChannel.channelLoc, 'conference.' + sysSettings.siteAddress, 'title', newChannel.channelName)
                    ejabberd.change_room_option(newChannel.channelLoc, 'conference.' + sysSettings.siteAddress, 'description', userQuery.username + 's chat room for the channel "' + newChannel.channelName + '"')

                    db.session.add(newChannel)
                    db.session.commit()

                    return {'results': {'message':'Channel Created', 'apiKey':newChannel.streamKey}}, 200
        return {'results': {'message':"Request Error"}}, 400
Ejemplo n.º 2
0
def addMod(message):
    sysSettings = settings.settings.query.first()
    if '@' in str(message['JID']):
        JID = str(message['JID'])
    else:
        username = str(message['JID'])
        userQuery = Sec.User.query.filter(
            func.lower(Sec.User.username) == func.lower(username)).first()
        if userQuery is not None:
            JID = username + '@' + sysSettings.siteAddress

    channelLoc = str(message['channelLoc'])
    channelQuery = Channel.Channel.query.filter_by(
        channelLoc=channelLoc, owningUser=current_user.id).first()

    if channelQuery is not None and JID != "":
        from app import ejabberd
        ejabberd.set_room_affiliation(channelLoc,
                                      'conference.' + sysSettings.siteAddress,
                                      JID, 'admin')
        emit('addMod', {
            'mod': str(JID),
            'channelLoc': str(channelLoc)
        },
             broadcast=False)
    else:
        pass
    db.session.commit()
    db.session.close()
    return 'OK'
Ejemplo n.º 3
0
def buildMissingRooms():
    sysSettings = settings.query.first()
    channelQuery = Channel.Channel.query.all()
    for channel in channelQuery:
        try:
            xmppQuery = ejabberd.get_room_affiliations(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress)
        except:
            print({
                "level":
                "info",
                "message":
                "Rebuilding missing ejabberd room - " + str(channel.channelLoc)
            })
            ejabberd.create_room(channel.channelLoc,
                                 'conference.' + sysSettings.siteAddress,
                                 sysSettings.siteAddress)

            for key, value in room_config.items():
                ejabberd.change_room_option(
                    channel.channelLoc,
                    'conference.' + sysSettings.siteAddress, key, value)

            ejabberd.set_room_affiliation(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                channel.owner.uuid + '@' + sysSettings.siteAddress, 'owner')

    return True
Ejemplo n.º 4
0
def verifyExistingRooms():
    sysSettings = settings.query.first()
    print({"level": "info", "message": "Verifying existing ejabberd Rooms"})
    channelQuery = Channel.Channel.query.join(User, Channel.Channel.owningUser == User.id) \
        .with_entities(Channel.Channel.channelLoc, Channel.Channel.xmppToken, Channel.Channel.protected, User.uuid.label('userUUID'))
    for channel in channelQuery:
        xmppQuery = ejabberd.get_room_affiliations(
            channel.channelLoc, 'conference.' + sysSettings.siteAddress)

        affiliationList = []
        for affiliation in xmppQuery['affiliations']:
            user = {}
            for entry in affiliation['affiliation']:
                for key, value in entry.items():
                    user[key] = value
            affiliationList.append(user)

        for user in affiliationList:
            if user['domain'] != sysSettings.siteAddress:
                userQuery = User.query.filter_by(uuid=user['username']).first()
                if userQuery is not None:
                    ejabberd.set_room_affiliation(
                        channel.channelLoc,
                        'conference.' + sysSettings.siteAddress,
                        userQuery.uuid + '@' + sysSettings.siteAddress,
                        user['affiliation'])

        if not all((d['username'] == channel.userUUID
                    and d['domain'] == sysSettings.siteAddress)
                   for d in affiliationList):
            ejabberd.set_room_affiliation(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                channel.userUUID + '@' + sysSettings.siteAddress, 'owner')

        if channel.protected:
            ejabberd.change_room_option(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                'password_protected', 'true')
            ejabberd.change_room_option(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                'password', channel.xmppToken)
        else:
            ejabberd.change_room_option(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                'password', '')
            ejabberd.change_room_option(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                'password_protected', 'false')
Ejemplo n.º 5
0
def verifyExistingRooms():
    sysSettings = settings.query.first()
    for channel in Channel.Channel.query.all():
        xmppQuery = ejabberd.get_room_affiliations(
            channel.channelLoc, 'conference.' + sysSettings.siteAddress)

        affiliationList = []
        for affiliation in xmppQuery['affiliations']:
            user = {}
            for entry in affiliation['affiliation']:
                for key, value in entry.items():
                    user[key] = value
            affiliationList.append(user)

        for user in affiliationList:
            if user['domain'] != sysSettings.siteAddress:
                userQuery = User.query.filter_by(
                    username=user['username']).first()
                if userQuery is not None:
                    ejabberd.set_room_affiliation(
                        channel.channelLoc,
                        'conference.' + sysSettings.siteAddress,
                        userQuery.username + '@' + sysSettings.siteAddress,
                        user['affiliation'])

        if not all((d['username'] == channel.owner.username
                    and d['domain'] == sysSettings.siteAddress)
                   for d in affiliationList):
            ejabberd.set_room_affiliation(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                channel.owner.username + '@' + sysSettings.siteAddress,
                'owner')

        if channel.protected:
            ejabberd.change_room_option(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                'password_protected', 'true')
            ejabberd.change_room_option(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                'password', channel.xmppToken)
        else:
            ejabberd.change_room_option(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                'password', '')
            ejabberd.change_room_option(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                'password_protected', 'false')
Ejemplo n.º 6
0
def deleteMod(message):
    sysSettings = settings.settings.query.first()
    JID = str(message['JID'])
    channelLoc = str(message['channelLoc'])

    channelQuery = Channel.Channel.query.filter_by(
        channelLoc=channelLoc, owningUser=current_user.id).first()

    user = JID.split('@')[0]
    userQuery = Sec.User.query.filter(
        func.lower(Sec.User.username) == func.lower(user)).first()

    if channelQuery is not None:
        if userQuery and current_user != user:
            from app import ejabberd
            ejabberd.set_room_affiliation(
                channelLoc, 'conference.' + sysSettings.siteAddress, JID,
                'member')
            emit('deleteMod', {
                'mod': str(JID),
                'channelLoc': str(channelLoc)
            },
                 broadcast=False)
        elif userQuery is None:
            from app import ejabberd
            ejabberd.set_room_affiliation(
                channelLoc, 'conference.' + sysSettings.siteAddress, JID,
                'none')
            emit('deleteMod', {
                'mod': str(JID),
                'channelLoc': str(channelLoc)
            },
                 broadcast=False)
    else:
        pass
    db.session.commit()
    db.session.close()
    return 'OK'
Ejemplo n.º 7
0
def buildMissingRooms():
    sysSettings = settings.query.first()
    channelQuery = Channel.Channel.query.all()
    for channel in channelQuery:
        try:
            xmppQuery = ejabberd.get_room_affiliations(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress)
        except:
            ejabberd.create_room(channel.channelLoc,
                                 'conference.' + sysSettings.siteAddress,
                                 sysSettings.siteAddress)

            for key, value in room_config.items():
                ejabberd.change_room_option(
                    channel.channelLoc,
                    'conference.' + sysSettings.siteAddress, key, value)

            ejabberd.set_room_affiliation(
                channel.channelLoc, 'conference.' + sysSettings.siteAddress,
                channel.owner.username + '@' + sysSettings.siteAddress,
                'owner')

    return True
Ejemplo n.º 8
0
def deleteMod(message):
    sysSettings = settings.settings.query.first()
    JID = str(message['JID'])
    channelLoc = str(message['channelLoc'])

    channelQuery = Channel.Channel.query.filter_by(
        channelLoc=channelLoc, owningUser=current_user.id).first()

    user = JID.split('@')[0]

    if channelQuery is not None:
        from app import ejabberd
        ejabberd.set_room_affiliation(channelLoc,
                                      'conference.' + sysSettings.siteAddress,
                                      JID, 'none')
        emit('deleteMod', {
            'mod': str(JID),
            'channelLoc': str(channelLoc)
        },
             broadcast=False)
    db.session.commit()
    db.session.close()
    return 'OK'