Beispiel #1
0
   def record(self, name, channel, queue, custom1=None, custom2=None):
      '''Record a queue member
         Called from call center monitor web page

Action: Monitor
Mix: 1
File: test
Channel: SIP/pEpSNlcv-000001b9
   '''
      log.debug('Record request "%s" (%s) on "%s"' % (name, channel, queue))

      # Check channel exists, else abort
      for cha in Globals.asterisk.channels.keys():
         if cha.startswith(channel):
            unique_id = Globals.asterisk.channels[cha]['Uniqueid']
            break
      else:
         log.warning('No active channel for %s ?' % channel)
         return dict(status=0)

      # XXX Authentification

      # Gather data from database
      user_id = DBSession.query(User).filter(
         User.user_name==request.identity['repoze.who.userid']).one().user_id
      member_id = DBSession.query(Phone).filter(
         Phone.sip_id==channel[-8:]).one().user_id
      queue_id = DBSession.query(Queue).filter(
            Queue.name==queue).one().queue_id

      # Create filename and send record action to Asterisk via manager
      f = 'rec-%s' % unique_id
      res = Globals.manager.send_action(
            {  'Action': 'Monitor',
               'Mix': 1,
               'Channel': cha,
               'File': f})
      log.info('Record request from userid "%s" to channel %s returns "%s"' % ( 
         user_id, cha, res))

      if res.get_header('Response')=='Success':
         status = 0
         # Set "recorded" flag on member
         Globals.asterisk.members[name]['Recorded'] = True
         # Insert record info into database
         r = Record()
         r.uniqueid = unique_id
         r.queue_id = queue_id
         r.member_id = member_id
         r.user_id = user_id
         r.custom1 = custom1
         r.custom2 = custom2
         DBSession.add(r)

      else:
         status = 1

      return dict(status=status)
Beispiel #2
0
   def auto_record(self, name, channel, queue, uid, custom1, custom2):
      ''' Auto record
      Called from Asterisk dialplan / func_curl
      '''

      log.debug('auto_record: name %s, channel %s, queue %s, uid %s, custom1 %s, custom2 %s' % (
         name, channel, queue, uid, custom1, custom2))
      # Check channel exists, else abort
      for cha in Globals.asterisk.channels.keys():
         if cha.startswith(channel):
            unique_id = Globals.asterisk.channels[cha]['Uniqueid']
            break
      else:
         log.warning('auto_record: no active channel for %s ?' % channel)
         return '1'

      # Poor man's authentification!
      if uid!=unique_id: 
         log.warning('auto_record: unique_id "%s" != "%s"' % (unique_id, uid))
         return '1'

      # Set "recorded" flag on member
      Globals.asterisk.members[name]['Recorded'] = True

      # Insert record info into database
      r = Record()
      r.user_id = -2 # Auto_record pseudo-user!
      r.uniqueid = unique_id
      r.queue_id = DBSession.query(Queue).filter(
            Queue.name==queue).one().queue_id
      try:
         u = DBSession.query(User).filter(User.ascii_name==name).first()
         log.debug(u' * * * %s' % u)
         r.member_id = u.user_id
      except:
         r.member_id = 1
         log.error('user "%s" not found' % name)
      r.custom1 = custom1
      r.custom2 = custom2
      DBSession.add(r)

      return '0'