def test_ph_landline(self):
     """PH landline numbers are weird, make sure we
     canonicalize properly. """
     self.config_db['number_country'] = 'PH'
     number = '6323953489'
     self.assertEqual('6323953489', number_utilities.canonicalize(number))
     number = '63023953489'
     self.assertEqual('6323953489', number_utilities.canonicalize(number))
     number = '023953489'
     self.assertEqual('6323953489', number_utilities.canonicalize(number))
 def test_plus(self):
     """Call another country with via the plus sign."""
     # Setup the number_country as ID.
     self.config_db['number_country'] = 'ID'
     # But try to call the US with +1.
     number = '+19195551234'
     self.assertEqual('19195551234', number_utilities.canonicalize(number))
Esempio n. 3
0
 def get_imsi_from_number(self, number, canonicalize=True):
     """Gets the IMSI associated with a number."""
     if canonicalize:
         number = number_utilities.canonicalize(number)
     for imsi, data in list(self._hlr.items()):
         if number in data['numbers']:
             return imsi
     return None
Esempio n. 4
0
def fsapi(session, stream, env, number):
    """Handle FS API requests.

    Args:
      number: the number you want canonicalized
    """
    canon = nu.canonicalize(number)
    consoleLog('info', "Returned FSAPI: " + canon + "\n")
    stream.write(canon)
Esempio n. 5
0
def chat(message, number):
    """Handle chat requests.

    Args:
      number: the number you want canonicalized
    """
    canon = nu.canonicalize(number)
    consoleLog('info', "Returned Chat: " + canon + "\n")
    message.chat_execute('set', '_openbts_ret=%s' % canon)
Esempio n. 6
0
    def get_imsi_from_number(self, number, canonicalize=True):
        """Gets the IMSI associated with a number.

           Raises:
              SubscriberNotFound if IMSI is not found
        """
        if canonicalize:
            number = number_utilities.canonicalize(number)
        return self._hlr_query(
            lambda s: 'IMSI' + s.show('extension', number)['imsi'],
            lambda: SubscriberNotFound('MSISDN %s' % (number, )))
Esempio n. 7
0
    def get_imsi_from_number(self, number, canonicalize=True):
        """Gets the IMSI associated with a number.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        if canonicalize:
            number = number_utilities.canonicalize(number)
        try:
            return self.sip_auth_serve.get_imsi_from_number(number)
        except InvalidRequestError as e:
            raise SubscriberNotFound('MSISDN %s' % number)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
    def get_imsi_from_number(self, number, canonicalize=True):
        """Gets the IMSI associated with a number.

           Raises:
              SubscriberNotFound if imsi is not found
        """
        if canonicalize:
            number = number_utilities.canonicalize(number)
        try:
            with self.subscribers as s:
                try:
                    return 'IMSI' + s.show('extension', number)['imsi']
                except ValueError as e:
                    raise SubscriberNotFound('MSISDN %s' % number)
        except Exception as e:
            exc_type, exc_value, exc_trace = sys.exc_info()
            raise BSSError, "%s: %s" % (exc_type, exc_value), exc_trace
Esempio n. 9
0
def add_group_members(mems, group):
    """
        Adds group member entries
    Args:
        mems: CSV of member callerIDs
        group: Group instance in which callerIDs will be added

    Returns:
        invalid: list containing caller ids that the system failed to add
                 if all numbers were successfully added, this is an empty list
    """

    invalid = []
    for caller_id in str(mems).split(','):
        if not caller_id:
            continue
        try:
            caller_id = number_utilities.canonicalize(caller_id)

            if len(caller_id) < 10 or len(caller_id) > 12:
                raise Exception("Canonicalized cellphone numbers "
                                "must be 12 digits long and "
                                "canonicalized landline numbers "
                                "must be 10 digits long.")

            # Also handle caller_ids that are not within VBTS network
            try:
                mem = Contact.objects.get(callerid=caller_id)
            except BaseException:
                mem = Contact.objects.create(imsi="OFFNET" + caller_id,
                                             callerid=caller_id)

            GroupMembers.objects.create(user=mem, group=group)
        except BaseException:
            invalid.append(caller_id)

    return invalid
 def test_leading_zero(self):
     """If a number has a leading zero, remove it before canonicalizing."""
     self.config_db['number_country'] = 'ID'
     number = '035551234'
     self.assertEqual('6235551234', number_utilities.canonicalize(number))
 def test_country_code_already_added(self):
     """If the number already has the country code, we don't add it."""
     self.config_db['number_country'] = 'ID'
     number = '629195551234'
     self.assertEqual(number, number_utilities.canonicalize(number))
 def test_indonesia(self):
     self.config_db['number_country'] = 'ID'
     number = '9195551234'
     self.assertEqual('62' + number, number_utilities.canonicalize(number))
 def test_united_states(self):
     self.config_db['number_country'] = 'US'
     number = '9195551234'
     self.assertEqual('1' + number, number_utilities.canonicalize(number))