def get_imsi_from_msisdn(self, msisdn): try: sq_hlr = sqlite3.connect(self.hlr_db_path) sq_hlr_cursor = sq_hlr.cursor() sq_hlr_cursor.execute( 'SELECT extension,imsi from subscriber WHERE extension=?', [(msisdn)]) extension = sq_hlr_cursor.fetchone() if extension == None: raise NoDataException('Extension not found in the OsmoHLR') imsi = extension[1] except sqlite3.Error as e: raise OsmoHlrError('SQ_HLR error: %s' % e.args[0]) return str(imsi)
def get_all_5digits(self): try: msisdns = self._osmo_hlr.get_all_5digit_msisdns() results = [] for msisdn_tuple in msisdns: if msisdn_tuple[1] != config['smsc']: results.append(msisdn_tuple) if len(msisdns) == 0: raise NoDataException('No extensions found') else: return results except OsmoHlrError as e: raise SubscriberException('SQ_HLR error: %s' % e.args[0])
def get_all_expire(self): try: sq_hlr = sqlite3.connect(self.hlr_db_path) sq_hlr_cursor = sq_hlr.cursor() sq_hlr_cursor.execute( "SELECT extension,expire_lu FROM subscriber WHERE length(extension) = 11" ) subscribers = sq_hlr_cursor.fetchall() if subscribers == []: raise NoDataException('No subscribers found') else: sq_hlr.close() return subscribers except sqlite3.Error as e: sq_hlr.close() raise OsmoHlrError('SQ_HLR error: %s' % e.args[0])
def get_all_5digit_msisdns(self): try: sq_hlr = sqlite3.connect(self.hlr_db_path) sq_hlr_cursor = sq_hlr.cursor() sq_hlr_cursor.execute( "SELECT extension, imsi FROM subscriber WHERE length(extension) = 5" ) extensions = sq_hlr_cursor.fetchall() if extensions == []: raise NoDataException('No extensions found') else: sq_hlr.close() return extensions except sqlite3.Error as e: sq_hlr.close() raise OsmoHlrError('SQ_HLR error: %s' % e.args[0])
def get_all_unauthorized(self, location=False): cur = self._open_local_cursor() try: if location: cur.execute( 'SELECT * FROM subscribers WHERE authorized = 0 and location = %s', (location, )) else: cur.execute('SELECT * FROM subscribers WHERE authorized = 0') if cur.rowcount > 0: sub = cur.fetchall() return sub else: raise NoDataException('PG_HLR No subscribers found') except psycopg2.DatabaseError as e: raise SubscriberException('PG_HLR error getting subscribers: %s' % e) finally: cur.close()