Ejemplo n.º 1
0
   def gxplogin(self, ip=None, mac=None, pwd=None):
      ''' Login to GXP phone (newer firmware)
      '''
      log.debug(u'gxplogin ip=%s, mac=%s, pwd=%s', (ip, mac, pwd))
      gs = Grandstream(ip, mac)

      if not gs.login(pwd):
         log.error(u'gxplogin error login')
         return {}

      return dict(sid=gs.sid)
Ejemplo n.º 2
0
   def check_phone(self, ip, pwd=None, mac=None):
      # Check phone is connected,  get hardware address
      log.debug('%s %s &> /dev/null' % (command_fping, ip))
      ret = system('%s %s &> /dev/null' % (command_fping, ip))
      if ret:
         return dict(status=1, msg=u"Téléphone injoignable, vérifiez l'adresse")
      if not mac:
         ret = popen('%s %s' % (command_arp, ip)).readlines()
         log.debug('arp -> ' + str(ret))
         if len(ret)!=2:
            return dict(status=2, msg=u"Téléphone injoignable, vérifiez l'adresse")
         mac = ret[1]
      match = re.search('(\w\w:\w\w:\w\w):(\w\w:\w\w:\w\w)', mac.lower())
      if not match:
         return dict(status=3, msg=u"Téléphone injoignable, vérifiez l'adresse")
      vendor, device = match.groups()
      log.debug('vendor=%s, device=%s' % (vendor,device))
      if vendor not in _vendors.keys():
         return dict(status=4, msg=u"Type de téléphone inconnu")

      mac = '%s:%s' % (vendor,device)
      p = DBSession.query(Phone).filter(Phone.mac==mac).all()
      if len(p):
         return dict(status=5, 
               msg = u'Téléphone existant, voulez-vous le \
                     <a href="/phones/%s/edit">modifier</a>.' % p[0].phone_id)

      if _vendors[vendor]=='Grandstream':
         new_phone = Grandstream(ip, mac)
         msg = u"Trouvé téléphone Grandstream : "
         if not new_phone.login(pwd):
            return dict(status=6, msg=msg+u'erreur login')
         infos = new_phone.infos()
         if not infos:
            return dict(status=6, msg=msg+u'erreur login')

         session['new_phone'] = new_phone
         session.save()

         return dict(status = 0, ip = ip, mac = mac, conf = 'grandstream_configure',
               msg = msg + infos['model'] + ', ' + infos['version'])

      elif _vendors[vendor]=='Cisco':
         new_phone = Cisco(ip, mac)
         msg = u"Trouvé téléphone Cisco : "
         if not new_phone.login(pwd):
            return dict(status=6, msg=msg+u'erreur login')
         infos = new_phone.infos()
         if not infos:
            return dict(status=6, msg=msg+u'erreur login')

         session['new_phone'] = new_phone
         session.save()

         return dict(status=0, ip=ip, mac=mac, conf='cisco_configure',
            msg = msg + infos['model'] + ', ' + infos['version'])

      elif _vendors[vendor]=='Polycom':
         return dict(status=0, ip=ip, mac=mac, conf='polycom_configure',
               msg=u"Trouvé téléphone Polycom")
Ejemplo n.º 3
0
      name, sip_id, ip = m.groups()

      if phones != [] and ip not in phones:
         continue

      try:
         p = DBSession.query(Phone).filter(Phone.sip_id==sip_id).one()
      except:
         print u'\tERREUR téléphone "%s" inexistant !\n' % sip_id

      if extens != [] and p.exten not in extens:
         continue

      print u'Téléphone %d: %s / %s (%s @%s)' % \
            (p.phone_id, sip_id, p.password, p.exten, ip)
      gs = Grandstream(ip, p.mac)

      if not gs.login(p.password):
         print u'\tERREUR login\n'
         continue

      infos = gs.infos()
      if not infos['model'].startswith('GXP'):
         print u'\tTrouvé téléphone inconnu (%s), abandon' % (infos),
         continue

      print u'\tTrouvé téléphone %s (%s)' % (infos['model'], infos['version']),

      if not force:
         x = None
         while (x not in ('o', 'n')):
Ejemplo n.º 4
0

# Main
force, phones = options( argv[1:] )
print phones

for l in popen("asterisk -rx 'sip show peers'"):
   m = re_sip.match(l)
   if m:
      name, sip_id, ip, x = m.groups()
      if phones != [] and ip not in phones:
         continue

      p = DBSession.query(Phone).filter(Phone.sip_id==sip_id).one()
      print u'Téléphone %d: %s / %s (%s)' % (p.phone_id, sip_id, p.password, ip)
      gs = Grandstream(ip, p.mac)

      if not gs.login(p.password):
         print u'\tERREUR login\n'
         continue

      infos = gs.infos()
      if not infos['model'].startswith('GXP'):
         print u'\tTrouvé téléphone inconnu (%s), abandon' % (infos),
         continue

      print u'\tTrouvé téléphone %s (%s)' % (infos['model'], infos['version']),

      if not force:
         x = None
         while (x not in ('o', 'n')):
Ejemplo n.º 5
0
   def put(self, phone_id, dptm_id, user_id, exten, dnis, contexts,
         hide_from_phonebook, fax, block_cid_in, block_cid_out,
         priority, phonebook_label, secretary, ringtone_id,
         callgroups=None, pickupgroups=None):
      ''' Update phone 

      User and exten information is independant from phone, there is no need
      to modify provisionning file.
      Create or update entry in Asterisk sip.conf.
      If a exten is attached to the phone, create exten in Asterisk database.
      If a user is attached to the phone, add callerid to SIP account ; if 
      the user has email, add voicemail info to sip.conf and add entry in 
      voicemail.conf.
      '''
      log.info('update %d' % phone_id)
      log.debug('Contexts %s' % contexts)
      log.debug('Callgroups %s' % callgroups)
      log.debug('Pickupgroups %s' % pickupgroups)
      log.debug('Hide from phonebook %s' % hide_from_phonebook)
      log.debug('Fax %s' % fax)
      log.debug('Block cid in %s' % block_cid_in)
      log.debug('Block cid out %s' % block_cid_out)

      p = DBSession.query(Phone).get(phone_id)
      old_exten = p.exten
      old_dnis = p.dnis

      if exten!=p.exten:
         exten = re.sub(r'\D', '', exten)
         log.debug('Exten has changed, %s -> %s' % (p.exten, exten))
         if exten=='':
            p.exten = None
         else:
            p.exten = exten

      if dnis!=p.dnis:
         dnis = re.sub(r'\D', '', dnis) if dnis is not None else ''
         log.debug('DNIS has changed, %s -> %s' % (p.dnis, dnis))
         if dnis=='':
            p.dnis = None
         else:
            p.dnis = dnis

      if p.department_id!=dptm_id:
         if dptm_id==-9999:
            p.department_id = None
         else:
            p.department_id = dptm_id

      if p.user_id!=user_id:
         if user_id==-9999:
            p.user_id = None
         else:
            p.user_id = user_id
      ringtone_id = int(ringtone_id)
      log.debug('before ringtone = %s', ringtone_id)
      if ringtone_id==-1:
          p.ringtone_id = None
          ringtone = None
      else:
          p.ringtone_id = ringtone_id
          try:
              ringtone = DBSession.query(Sound).get(int(ringtone_id)).name
          except:
              ringtone = None
              p.ringtone_id = None
      log.debug('after ringtone = %s (%s)', ringtone, ringtone_id)

      x = ','.join([str(x) for x in contexts])
      if p.contexts != x:
         log.debug('New contexts !')
         p.contexts = x

      x = ','.join([str(x) for x in callgroups])
      if p.callgroups != x:
         p.callgroups = x

      x = ','.join([str(x) for x in pickupgroups])
      if p.pickupgroups != x:
         p.pickupgroups = x

      p.hide_from_phonebook = hide_from_phonebook
      p.fax = fax
      p.block_cid_in = block_cid_in
      p.block_cid_out = block_cid_out
      p.priority = priority
      p.phonebook_label = phonebook_label 
      p.secretary = secretary 

      asterisk_update_phone(p, old_exten, old_dnis)

      if p.vendor == 'Grandstream':
         # Create provisionning file and configure phone
         ip, ua, state = peer_info(p.sip_id, p.exten)
         log.info('Configure %s %s %s %s', p.mac, ip, ua, state)
         gs = Grandstream(ip, p.mac)
         gs.login(p.password)
         gs.infos()
         mwi_subscribe = 0
         sip_display_name = None
         if p.user_id!='-9999':
            try:
               u = DBSession.query(User).get(p.user_id)
               sip_display_name = u.ascii_name
               if u.email_address:
                  mwi_subscribe = 1
            except:
               pass
         gs.configure( p.password, directory_tftp,
            server_firmware + '/phones/firmware', 
            server_config + '/phones/config', server_ntp,
            server_config, '', '', '',
            server_sip, p.sip_id, sip_display_name, mwi_subscribe,
            screen_url = server_config, exten=p.exten,
            sip_server2=server_sip2, secretary=secretary,
            ringtone=ringtone)

      flash(u'Téléphone modifié')
      redirect('/phones/%d/edit' % phone_id)