Example #1
0
 def __init__(self, last_event, config):
     self.log = logging.getLogger('Conference')
     self.last_event = last_event
     self.config = config
     self.conf_size = getUnquotedHeader(self.last_event, 'Conference-Size')
     self.conf_name = getUnquotedHeader(self.last_event, 'Conference-Name')
     self.conf_profile = getUnquotedHeader(self.last_event, 'Conference-Profile-Name')
     self.conf_uuid = getUnquotedHeader(self.last_event, 'Conference-Unique-ID')
                 
     self.confObj = Session.query(Conference).get(getUnquotedHeader(self.last_event, 'Conference-Unique-ID'))
     if self.confObj is None:
         self.log.debug('Conference does not exist on DB, we must create one.')
         owner = Session.query(ModeratorPin).get(getUnquotedHeader(last_event, 'Conference-Name'))
         if owner is None:
             self.log.warning('Error because we could not get owner.')
             Session.remove()
             return
         
         self.log.info('Creating a new conference for conference id: %s' % getUnquotedHeader(last_event, 'Conference-Unique-ID'))
         confObj = Conference(getUnquotedHeader(last_event, 'Conference-Unique-ID'), parseEventDate(last_event), unicode(getUnquotedHeader(last_event, 'Conference-Name')), unicode(getUnquotedHeader(last_event, 'Conference-Profile-Name')))
         owner.conferences.append(confObj)
         Session.add(confObj)
         Session.flush()
     
     Session.remove()    
Example #2
0
 def checkPin(self):
     """Check for PIN existence."""
     pin = request.params.get('val')
     try:
         Session.query(ModeratorPin).filter(or_(ModeratorPin.pin == pin, ParticipantPin.pin == pin)).one()
     except NoResultFound, e:
         return('Pin available')
Example #3
0
 def report_detail(self, id):
     """Generate a detailed report from the conference"""
     self.is_my_pin(id)
     try:
         c.conf = Session.query(Conference).join(ModeratorPin).filter(and_(ModeratorPin.username == session.get('username'), Conference.id == id)).one()
         c.actions = Session.query(ConferenceAction).join(Conference).filter(Conference.id == id).all()
     except Exception, e:
         log.critical(e)
Example #4
0
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
Example #5
0
 def generatePin(self):
     """Generate a new available PIN"""
     while True:
         mPin = ModeratorPin(session.get('username'), session.get('domain'))
         try:
             Session.query(ModeratorPin, ParticipantPin).filter(or_(ModeratorPin.pin == mPin.pin, ParticipantPin.pin == mPin.pin)).one()
         except NoResultFound, e:
             break
         except Exception, e:
             log.critical('We generated more then one PIN? %s' % e)
Example #6
0
 def index(self):
     c.confs = Session.query(ModeratorPin).filter(ModeratorPin.username == session.get('username')).all()
     oConfs = Session.query(ModeratorPin).filter(ModeratorPin.extraAdmin == session.get('username')).all()
     
     c.oConfs = {}
     for conf in oConfs:
         if c.oConfs.has_key(conf.username):
             c.oConfs[conf.username].append(conf)
         else:
             c.oConfs[conf.username] = [conf,]
     return render('/derived/main/reports_select.html')
Example #7
0
 def index(self):
     """Pin Management"""
     c.pins = []
     try:
         c.pins = Session.query(ModeratorPin).filter(and_(ModeratorPin.username==session.get('username'), ModeratorPin.domain == session.get('domain'))).all()
     except Exception, e:
         log.critical('Could not get the pins for the user: %s' % e)
Example #8
0
 def index(self):
     c.pins = []
     try:
         c.pins = Session.query(ModeratorPin).filter(ModeratorPin.username==session.get('username')).all()
     except Exception, e:
         log.critical('Could not get pins: %s' % e)
         abort(500)
Example #9
0
    def new_pin(self):
        """Request a new PIN"""
        if len(request.params.get('participant_pin', '')) < 7 or len(request.params.get('moderator_pin', '')) < 7:
            h.flash("Your PINs need to be 7 numbers.")
            redirect(url('/main/new_pin/new_pin_form'))
        
        if Session.query(ModeratorPin).filter(ModeratorPin.username == session.get('username')).count() >= 5:
            redirect(url('/main/conferences/index'))

        mPin = ModeratorPin(session.get('username'), session.get('domain'))
        mPin.pin = request.params.get('moderator_pin')
        try:
            Session.query(ModeratorPin).filter(or_(ModeratorPin.pin == mPin.pin, ParticipantPin.pin == mPin.pin)).one()
            h.flash('Moderator PIN was taken.')
            redirect(url('/main/new_pin/new_pin_form'))
        except NoResultFound, e:
            Session.add(mPin)
Example #10
0
 def changeNote(self, id):
     """ Change the note """
     try:
         pin = Session.query(ModeratorPin).get(id)
     except Exception, e:
         log.critical('Could not fetch the pin because: %s' % e)
         h.flash('Could not find PIN.')
         redirect(url(controller='main/new_pin', action='index'))
Example #11
0
 def is_my_pin(self, pin):
     """Checks if this is my pin, if not, raise a 403"""
     if self.checkAdmin(asbool=True):
         return
         
     obj = Session.query(ModeratorPin).get(pin)
     if obj is not None and session.get('username') != obj.username:
         abort(403, 'You are not allowed to view this page.')
Example #12
0
    def checkPin(self):
        """Check for PIN existence."""
        pin = request.params.get('val')
        pins = Session.query(ModeratorPin).join(ParticipantPin).filter(or_(ModeratorPin.pin == pin, ParticipantPin.pin == pin)).all()
        if not pins:
            return('Pin available')

        response.status = '500 Pin Unavailable'
        return
Example #13
0
 def index(self):
     # Check if this user is really an admin...
     self.checkAdmin()
     
     c.users = []
     try:
         c.users = Session.query(ModeratorPin.username, ModeratorPin.domain).distinct().all()
     except SQLAlchemyError, e:
         log.critical('Something went wrong... %s' % e)
Example #14
0
 def toggle(self, id):
     """Toggle secure or record for a conference"""
     f = request.params.get('f')
     self.is_my_pin(id)
     pin = Session.query(ModeratorPin).get(id)
     
     if pin:
         if f == 'record':
             if pin.record:
                 pin.record = False
             else:
                 pin.record = True
         
         if f == 'secure':
             if pin.secure:
                 pin.secure = False
             else:
                 pin.secure = True
                 
         if f == 'userRecord':
             if pin.userRecord:
                 pin.userRecord = False
             else:
                 pin.userRecord = True
                 
         if f == 'mute_on_entry':
             if pin.mute_entry:
                 pin.mute_entry = False
             else:
                 pin.mute_entry = True
                 
         if f == 'beeps':
             if pin.beeps:
                 pin.beeps = False
             else:
                 pin.beeps = True
             if app_globals.confMonitor.conferences.has_key(pin.pin):
                 app_globals.confMonitor.conferences[pin.pin].toggleSilence()
                 
     Session.commit()
         
     redirect(request.headers.get('REFERER', url(controller='main/conferences', action='index')))
Example #15
0
 def index(self, id):
     self.is_my_pin(id)
     c.id = id
     c.mod_pin = None
     c.part_pin = None
     try:
         conf = Session.query(ModeratorPin).filter(ModeratorPin.pin == id).one()
         c.mod_pin = conf.pin
         c.part_pin = conf.participant_pin.pin
     except Exception, e:
         log.critical("Could not get conference pin %s" % e)
Example #16
0
 def is_my_pin(self, pin):
     """Checks if this is my pin, if not, raise a 403"""
     if self.checkAdmin(asbool=True):
         return
         
     try:
         obj = Session.query(ModeratorPin).filter(or_(and_(ModeratorPin.pin == pin, ModeratorPin.username == session.get('username')),
                                                      and_(ModeratorPin.pin == pin, ModeratorPin.extraAdmin == session.get('username')))).one()
     except NoResultFound:
         abort(403, 'You are not allowed to view this page.')
     
     return
Example #17
0
 def admin_user(self):
     """Administrate a certain user"""
     self.checkAdmin()
     
     c.username = request.params.get('username').split('@')[0]
     c.domain = request.params.get('username').split('@')[1]
     
     try:
         # Get the user conferences
         c.pins = Session.query(ModeratorPin).filter(and_(ModeratorPin.username==c.username, ModeratorPin.domain==c.domain)).all()
     except SQLAlchemyError, e:
         log.critical("Could not fetch: %s" % e)
Example #18
0
 def toggle(self, id):
     """Toggle secure or record for a conference"""
     f = request.params.get('f')
     self.is_my_pin(id)
     pin = Session.query(ModeratorPin).get(id)
     
     if pin:
         if f == 'record':
             if pin.record:
                 pin.record = False
             else:
                 pin.record = True
         
         if f == 'secure':
             if pin.secure:
                 pin.secure = False
             else:
                 pin.secure = True
                 
     Session.commit()
         
     redirect(request.headers.get('REFERER', url(controller='main/conferences', action='index')))
Example #19
0
    def new_pin(self):
        """Request a new PIN"""
        if len(request.params.get('participant_pin', '')) != 7 or len(request.params.get('moderator_pin', '')) != 7:
            h.flash("Your PINs need to be 7 numbers.")
            redirect(url('/main/new_pin/new_pin_form'))
        
        if Session.query(ModeratorPin).filter(ModeratorPin.username == session.get('username')).count() >= 5:
            redirect(url('/main/conferences/index'))

        try:            
            mPin = ModeratorPin(session.get('username'), session.get('domain'), request.params.get('moderator_pin'), note=request.params.get('note') or None)
        except Exception, e:
            h.flash(str(e))
            redirect(url('/main/new_pin/new_pin_form'))
Example #20
0
    def gen_report(self):
        """View the reports"""
        conf_name = request.params.get('conf_name')
        date_from = request.params.get('date_from')
        date_to = request.params.get('date_to')
        stmt = Session.query(Conference).join(ModeratorPin).filter(ModeratorPin.username == session.get('username'))

        if date_from and date_to:
            try:
                ddate_from = datetime(*strptime(date_from, '%m/%d/%Y')[:3])
                ds = strptime(date_to, '%m/%d/%Y')
                ddate_to = datetime(ds[0], ds[1], ds[2] , 23, 59, 59)
                stmt = stmt.filter(and_(Conference.created >= ddate_from, Conference.ended <= ddate_to))
            except ValueError, e:
                log.warning('User has supplied the wrong time format, disregarding filter: %s %s' % (date_from, date_to))
                h.flash('Invalid date format.')
                redirect(url(controller='main/reports', action='index'))
Example #21
0
 def addAction(self, e):
     """Create and add a new action to the DB"""
     self.log.debug('Action taken on %s. %s' % (self.conf_name, getUnquotedHeader(e, 'Action')))
     confObj = Session.query(Conference).get(getUnquotedHeader(self.last_event, 'Conference-Unique-ID'))
     if confObj is None:
         self.log.warning("Conference does not exist, so we can't add this action to the DB.")
         return
         
     actionObj = ConferenceAction(getUnquotedHeader(e, 'Action'), 
                                 getUnquotedHeader(e, 'Caller-Caller-ID-Name'),
                                 getUnquotedHeader(e, 'Caller-Caller-ID-Number'),
                                 self.conf_size,
                                 getUnquotedHeader(e, 'Member-Type'),
                                 parseEventDate(e),
                                 self.conf_uuid)
     confObj.actions.append(actionObj)
     Session.add(actionObj)
     Session.commit()
     Session.remove()
Example #22
0
 def dl_recording(self, id):
     """Download the recording for a conference"""
     try:
         conf = Session.query(Conference).join(ModeratorPin).filter(and_(ModeratorPin.username == session.get('username'), Conference.id == id)).one()
     except NoResultFound, e:
         return 'No such conference.'
Example #23
0
 def report_detail(self, id):
     """Generate a detailed report from the conference"""
     try:
         c.conf = Session.query(Conference).join(ModeratorPin).filter(Conference.id == id).one()
     except NoResultFound, e:
         log.critical(e)
Example #24
0
            
        try:
            c.confs = stmt.all()
        except Exception, e:
            print e
        return render('/derived/main/reports_gen.html')
        
    def report_detail(self, id):
        """Generate a detailed report from the conference"""
        try:
            c.conf = Session.query(Conference).join(ModeratorPin).filter(Conference.id == id).one()
        except NoResultFound, e:
            log.critical(e)
            
        self.is_my_pin(c.conf.owner)
        c.actions = Session.query(ConferenceAction).join(Conference).filter(Conference.id == id).all()
        return render('/derived/main/reports_detail.html')

    def dl_recording(self, id):
        """Download the recording for a conference"""
        try:
            conf = Session.query(Conference).join(ModeratorPin).filter(and_(ModeratorPin.username == session.get('username'), Conference.id == id)).one()
        except NoResultFound, e:
            return 'No such conference.'
            
        if not os.path.exists(conf.recording):
            return 'No recording available for this conference.'

        return self._send_file_response(conf.recording)
        
    def _send_file_response(self, filepath):
Example #25
0
 def del_member(self, e):
     """Remove members from the conference"""
     self.last_event = e
     self.conf_size = int(getUnquotedHeader(e, 'Conference-Size')) # Adjust the conference size
     self.addAction(e)
     confObj = Session.query(Conference).get(getUnquotedHeader(e, 'Conference-Unique-ID'))
     if confObj is None:
         self.log.debug('Conference does not exist on DB, we must create one.')
         owner = Session.query(ModeratorPin).get(getUnquotedHeader(e, 'Conference-Name'))
         if owner is None:
             self.log.warning('Error because we could not get owner.')
             Session.remove()
             return
         
         self.log.info('Creating a new conference for conference id: %s' % getUnquotedHeader(last_event, 'Conference-Unique-ID'))
         confObj = Conference(getUnquotedHeader(last_event, 'Conference-Unique-ID'), parseEventDate(last_event), unicode(getUnquotedHeader(last_event, 'Conference-Name')), unicode(getUnquotedHeader(last_event, 'Conference-Profile-Name')))
         owner.conferences.append(confObj)
         Session.add(confObj)
         Session.flush()
     if self.conf_size == 0:
         confObj.ended = parseEventDate(e)
         try:
             self.log.debug("Conference %s has ended. Removing session %s." % (self.conf_name, Session))
             Session.commit()
         except Exception, e:
             Session.rollback()
             Session.remove()
             self.log.exception('Could not commit to the DB.')
             return
Example #26
0
 def add_member(self, e):
     """Add a new member to the conference"""
     self.last_event = e
     self.conf_size = int(getUnquotedHeader(e, 'Conference-Size')) # Adjust the conference size
     confObj = Session.query(Conference).get(getUnquotedHeader(self.last_event, 'Conference-Unique-ID'))
     if confObj is None:
         try:
             owner = Session.query(ModeratorPin).get(self.conf_name)
         except Exception, err:
             self.log.exception("Could not obtain owner.")
             Session.remove()
             return
         if owner is None:
             self.log.warning('Error because we could not get owner.')
             Session.remove()
             return
         self.log.debug('Conference does not exist, we must create one.')
         self.log.info('Creating a new conference for conference id: %s' % self.conf_uuid)
         confObj = Conference(self.conf_uuid, parseEventDate(e), unicode(self.conf_name), unicode(self.conf_profile))
         owner.conferences.append(confObj)
         Session.add(confObj)
         Session.commit()
         Session.remove()
         self.addAction(e)
         self.log.debug('Conference %s has been created. Assigning the pointer.' % self.conf_name)
         return
Example #27
0
 def stop_recording(e, config):
     """Process the process of recording being stopped"""
     log = logging.getLogger('Conference')
     
     owner = Session.query(ModeratorPin).get(getUnquotedHeader(e, 'Conference-Name'))
     if owner is None:
         log.warning('Error because we could not get owner.')
         Session.remove()
         return
     
     confObj = Session.query(Conference).get(getUnquotedHeader(e, 'Conference-Unique-ID'))
     if confObj is None:
         log.info('Creating a new conference for conference id: %s' % getUnquotedHeader(e, 'Conference-Unique-ID'))
         confObj = Conference(getUnquotedHeader(e, 'Conference-Unique-ID'), parseEventDate(e), unicode(getUnquotedHeader(e, 'Conference-Name')), unicode(getUnquotedHeader(e, 'Conference-Profile-Name')))
         owner.conferences.append(confObj)
         Session.add(confObj)
         Session.flush()
         actionObj = ConferenceAction(unicode(getUnquotedHeader(e, 'Action')), 
                                     unicode(getUnquotedHeader(e, 'Caller-Caller-ID-Name')),
                                     unicode(getUnquotedHeader(e, 'Caller-Caller-ID-Number')),
                                     unicode(getUnquotedHeader(e, 'Conference-Size')),
                                     unicode(getUnquotedHeader(e, 'Member-Type')),
                                     parseEventDate(e),
                                     confObj.id)
         confObj.actions.append(actionObj)
         Session.add(actionObj)
         log.debug('Conference %s has been created. Assigning the pointer.' % getUnquotedHeader(e, 'Conference-Name'))
         
     confObj.recording = os.path.join(config.get('mp3', 'store_to'), getUnquotedHeader(e, 'Path').split('/').pop()[:-3] + 'mp3')
     host = unicode(getUnquotedHeader(e, 'FreeSWITCH-IPv4'))
         
     try:
         try:
             t = Thread(target=postRecordingThread, args=(config, getUnquotedHeader(e, 'Path'), confObj, host, owner))
             t.start()
         except:
             log.exception('Could not run thread and commit to database!')
             Session.remove()
             return
     finally:
         try:
             sendEmail(config, getUnquotedHeader(e, 'Path'), confObj, owner)
             Session.commit()
             Session.remove()
         except Exception, e:
             log.exception('Could not commit to database!')
             Session.rollback()
             Session.remove()
             return
Example #28
0
 def delete(self, id):
     """Delete a certain PIN"""
     try:
         obj = Session.query(ModeratorPin).get(id)
     except Exception, e:
         log.critical('Could not fetch the pin because: %s' % e)
Example #29
0
         self.log.info('Creating a new conference for conference id: %s' % getUnquotedHeader(last_event, 'Conference-Unique-ID'))
         confObj = Conference(getUnquotedHeader(last_event, 'Conference-Unique-ID'), parseEventDate(last_event), unicode(getUnquotedHeader(last_event, 'Conference-Name')), unicode(getUnquotedHeader(last_event, 'Conference-Profile-Name')))
         owner.conferences.append(confObj)
         Session.add(confObj)
         Session.flush()
     if self.conf_size == 0:
         confObj.ended = parseEventDate(e)
         try:
             self.log.debug("Conference %s has ended. Removing session %s." % (self.conf_name, Session))
             Session.commit()
         except Exception, e:
             Session.rollback()
             Session.remove()
             self.log.exception('Could not commit to the DB.')
             return
     Session.remove()
 
 #def kick_member(self, e):
 #    self.addAction(e)
     
 def undeaf_member(self, e):
     self.addAction(e)
     
 def deaf_member(self, e):
     self.addAction(e)
     
 def gain_level(self, e):
     self.addAction(e)
     
 def volume_level(self, e):
     self.addAction(e)
Example #30
0
 def index(self):
     c.pins = []
     try:
         c.pins = Session.query(ModeratorPin).filter(ModeratorPin.username==session.get('username')).all()
     except Exception, e:
         print e