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
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
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')
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
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')