示例#1
0
def authorize(data):
  ldbg("authorize data: %s" % str(data))
###  ldbg("function authorize")
  d = utils.RadPacketToDict(data)
  
###  ldbg("function authorize (d variable) => %s " % d)

  if 'Service-Type' not in d:
    linfo("Service-Type is not present, noop")
###    ldbg("function authorize: Service-Type is not present")
    return radiusd.RLM_MODULE_NOOP
###  ldbg("function authorize: post check Service-Type")

  if d['Service-Type'] == 'Sip-Session':
    user = d.get("User-Name")
###    ldbg("function authorize: User-Name -> %s " % user)
    if not user:
      lerr("FAIL: couldn't extract 'User-Name' from packet")
###      ldbg("function authorize: couldn't extract User-Name")
      return radiusd.RLM_MODULE_FAIL
###    ldbg("function authorize: post check User-Name and Sip-Session")
    ldbg("process for get user-name by split -> %s " % user.split('@')[0])
###    kek = auth.Authorize(user.split('@')[0])
###    ldbg("function authorize: get kek -> %s " % str(kek))
    return auth.Authorize(user.split('@')[0])
###    return kek

  linfo("Unknown Service-Type")
  return radiusd.RLM_MODULE_NOOP
示例#2
0
def authorize(data):
    ldbg("authorize data: %s" % str(data))
    ###  ldbg("function authorize")
    d = utils.RadPacketToDict(data)

    ###  ldbg("function authorize (d variable) => %s " % d)

    if 'Service-Type' not in d:
        linfo("Service-Type is not present, noop")
        ###    ldbg("function authorize: Service-Type is not present")
        return radiusd.RLM_MODULE_NOOP
###  ldbg("function authorize: post check Service-Type")

    if d['Service-Type'] == 'Sip-Session':
        user = d.get("User-Name")
        ###    ldbg("function authorize: User-Name -> %s " % user)
        if not user:
            lerr("FAIL: couldn't extract 'User-Name' from packet")
            ###      ldbg("function authorize: couldn't extract User-Name")
            return radiusd.RLM_MODULE_FAIL
###    ldbg("function authorize: post check User-Name and Sip-Session")
        ldbg("process for get user-name by split -> %s " % user.split('@')[0])
        ###    kek = auth.Authorize(user.split('@')[0])
        ###    ldbg("function authorize: get kek -> %s " % str(kek))
        return auth.Authorize(user.split('@')[0])


###    return kek

    linfo("Unknown Service-Type")
    return radiusd.RLM_MODULE_NOOP
示例#3
0
 def __init__(self, config):
   self.db = None
   try:
     self.db = MySQLdb.connect(**config)
     self.db.lock = threading.RLock()
   except MySQLdb.Error, e:
     lerr(e)
示例#4
0
 def GetGatewayDset(self, num):
   addr = self.getGatewayAddr()
   if addr:
     dset = URISet()
     dset.append(num, addr)
     return dset
   else:
     lerr("FAIL: couldn't get gateway address")
示例#5
0
 def GetGatewayDset(self, num):
     addr = self.getGatewayAddr()
     if addr:
         dset = URISet()
         dset.append(num, addr)
         return dset
     else:
         lerr("FAIL: couldn't get gateway address")
示例#6
0
 def Connect(self, name=''):
   if name in self.__configs:
     conn = self.__connection_pool.get(name)
     if conn:
       if conn.is_valid():
         return conn.db
       else:
         del self.__connection_pool[name]
     # new connection
     for c in self.__configs[name]:
       conn = Connection(c)
       if conn.is_valid():
         self.__connection_pool[name] = conn
         return conn.db
     else:
       lerr("Couldn't connect to db")
示例#7
0
  def getDict(self, query, params):
###    linfo("storage module. Function getDict")
###    linfo("storage module. query => %s | params => %s | type of params => %s " % (query, params, str(type(params))))
    conn = self.engine.Connect()
    #ldbg("storage module. Function GetDict. post engine.Connect")
###    linfo("storage module. Function GetDict. print conn => %s " % conn)
    if conn:
      with conn.lock:
        try:
          cur = conn.cursor(MySQLdb.cursors.DictCursor)
	  if type(params)==type(()):
	    cur.execute(query, params)
	  else:
            cur.execute(query, (params,))
###          linfo("storage module. Function GetDict. post execute query cu [type:%s ; value: %s]" % (type(cur), str(cur)))
          return cur.fetchall()
        except MySQLdb.Error, e:
###          ldbg("hello! I'm here!")
          lerr("FAILED: %s" % e)
示例#8
0
    def getDict(self, query, params):
        ###    linfo("storage module. Function getDict")
        ###    linfo("storage module. query => %s | params => %s | type of params => %s " % (query, params, str(type(params))))
        conn = self.engine.Connect()
        #ldbg("storage module. Function GetDict. post engine.Connect")
        ###    linfo("storage module. Function GetDict. print conn => %s " % conn)
        if conn:
            with conn.lock:
                try:
                    cur = conn.cursor(MySQLdb.cursors.DictCursor)
                    if type(params) == type(()):
                        cur.execute(query, params)
                    else:
                        cur.execute(query, (params, ))


###          linfo("storage module. Function GetDict. post execute query cu [type:%s ; value: %s]" % (type(cur), str(cur)))
                    return cur.fetchall()
                except MySQLdb.Error, e:
                    ###          ldbg("hello! I'm here!")
                    lerr("FAILED: %s" % e)
示例#9
0
def authenticate(data):
  '''using as Post-Auth'''
  ldbg("authenticate data: %s" % str(data))
###  ldbg("function authenticate")
  d = utils.RadPacketToDict(data)

  if 'Service-Type' not in d:
    linfo("Service-Type is not present, noop")
    return radiusd.RLM_MODULE_NOOP

  if 'Digest-Method' not in d:
    linfo("Digest-Method is not present, noop")
    return radiusd.RLM_MODULE_NOOP

  if d['Service-Type'] == 'Sip-Session':
    if d['Digest-Method'] == 'INVITE':
      src = d.get("Sip-Uri-User")
      if not src:
        lerr("FAIL: couldn't extract 'Sip-Uri-User' from packet")
        return radiusd.RLM_MODULE_FAIL

      dst = d.get("Digest-URI")
      if not dst:
        lerr("FAIL: couldn't extract 'Sip-Uri-User' from packet")
        return radiusd.RLM_MODULE_FAIL
      dst = dst.split('@')[0][4:]

      proxy = d.get("NAS-IP-Address")
      if not proxy:
        lerr("FAIL: couldn't extract 'Sip-Uri-User' from packet")
        return radiusd.RLM_MODULE_FAIL

      return auth.AuthInvite(src, dst, proxy)

  return radiusd.RLM_MODULE_NOOP
示例#10
0
def authenticate(data):
    '''using as Post-Auth'''
    ldbg("authenticate data: %s" % str(data))
    ###  ldbg("function authenticate")
    d = utils.RadPacketToDict(data)

    if 'Service-Type' not in d:
        linfo("Service-Type is not present, noop")
        return radiusd.RLM_MODULE_NOOP

    if 'Digest-Method' not in d:
        linfo("Digest-Method is not present, noop")
        return radiusd.RLM_MODULE_NOOP

    if d['Service-Type'] == 'Sip-Session':
        if d['Digest-Method'] == 'INVITE':
            src = d.get("Sip-Uri-User")
            if not src:
                lerr("FAIL: couldn't extract 'Sip-Uri-User' from packet")
                return radiusd.RLM_MODULE_FAIL

            dst = d.get("Digest-URI")
            if not dst:
                lerr("FAIL: couldn't extract 'Sip-Uri-User' from packet")
                return radiusd.RLM_MODULE_FAIL
            dst = dst.split('@')[0][4:]

            proxy = d.get("NAS-IP-Address")
            if not proxy:
                lerr("FAIL: couldn't extract 'Sip-Uri-User' from packet")
                return radiusd.RLM_MODULE_FAIL

            return auth.AuthInvite(src, dst, proxy)

    return radiusd.RLM_MODULE_NOOP
示例#11
0
 def Insert(self, data):
   query = """
           INSERT statistics_radacct
           (AcctTime, AcctStatusType, SipToTag, SipFromTag, AcctSessionId, SipMethod, SipResponseCode, CalledStationId, CallingStationId)
           VALUES
           (%(Event-Timestamp)s, %(Acct-Status-Type)s, %(Sip-To-Tag)s, %(Sip-From-Tag)s, %(Acct-Session-Id)s, %(Sip-Method)s, %(Sip-Response-Code)s, %(Called-Station-Id)s, %(Calling-Station-Id)s)
   """
   data['Event-Timestamp'] = datetime.strptime(data['Event-Timestamp'], "%b %d %Y %H:%M:%S %Z")
   conn = self.engine.Connect()
   if conn:
     with conn.lock:
       cu = conn.cursor()
       try:
         cu.execute(query, data)
         return 1
       except MySQLdb.Error, e:
         lerr(e)
       except KeyError, e:
         lerr(e)
         lerr("Bad data: %s" % data)
示例#12
0
 def Insert(self, data):
     query = """
         INSERT statistics_radacct
         (AcctTime, AcctStatusType, SipToTag, SipFromTag, AcctSessionId, SipMethod, SipResponseCode, CalledStationId, CallingStationId)
         VALUES
         (%(Event-Timestamp)s, %(Acct-Status-Type)s, %(Sip-To-Tag)s, %(Sip-From-Tag)s, %(Acct-Session-Id)s, %(Sip-Method)s, %(Sip-Response-Code)s, %(Called-Station-Id)s, %(Calling-Station-Id)s)
 """
     data['Event-Timestamp'] = datetime.strptime(data['Event-Timestamp'],
                                                 "%b %d %Y %H:%M:%S %Z")
     conn = self.engine.Connect()
     if conn:
         with conn.lock:
             cu = conn.cursor()
             try:
                 cu.execute(query, data)
                 return 1
             except MySQLdb.Error, e:
                 lerr(e)
             except KeyError, e:
                 lerr(e)
                 lerr("Bad data: %s" % data)
示例#13
0
  def Account(self, d):
###    ldbg("mod. radser. class Acct. begin def Account")
    if self.storage.Insert(d):
      return radiusd.RLM_MODULE_OK
    lerr("FAIL: Couldn't account call")
    return radiusd.RLM_MODULE_INVALID
示例#14
0
class AcctStorage(object):
  def __init__(self, config):
    self.engine = db.Engine()
    self.engine.Register(config)
    self.engine.Connect()

  def Insert(self, data):
    query = """
            INSERT statistics_radacct
            (AcctTime, AcctStatusType, SipToTag, SipFromTag, AcctSessionId, SipMethod, SipResponseCode, CalledStationId, CallingStationId)
            VALUES
            (%(Event-Timestamp)s, %(Acct-Status-Type)s, %(Sip-To-Tag)s, %(Sip-From-Tag)s, %(Acct-Session-Id)s, %(Sip-Method)s, %(Sip-Response-Code)s, %(Called-Station-Id)s, %(Calling-Station-Id)s)
    """
    data['Event-Timestamp'] = datetime.strptime(data['Event-Timestamp'], "%b %d %Y %H:%M:%S %Z")
    conn = self.engine.Connect()
    if conn:
      with conn.lock:
        cu = conn.cursor()
        try:
          cu.execute(query, data)
          return 1
        except MySQLdb.Error, e:
          lerr(e)
        except KeyError, e:
          lerr(e)
          lerr("Bad data: %s" % data)
    else:
      lerr("Could not connect to db")

示例#15
0
class AcctStorage(object):
    def __init__(self, config):
        self.engine = db.Engine()
        self.engine.Register(config)
        self.engine.Connect()

    def Insert(self, data):
        query = """
            INSERT statistics_radacct
            (AcctTime, AcctStatusType, SipToTag, SipFromTag, AcctSessionId, SipMethod, SipResponseCode, CalledStationId, CallingStationId)
            VALUES
            (%(Event-Timestamp)s, %(Acct-Status-Type)s, %(Sip-To-Tag)s, %(Sip-From-Tag)s, %(Acct-Session-Id)s, %(Sip-Method)s, %(Sip-Response-Code)s, %(Called-Station-Id)s, %(Calling-Station-Id)s)
    """
        data['Event-Timestamp'] = datetime.strptime(data['Event-Timestamp'],
                                                    "%b %d %Y %H:%M:%S %Z")
        conn = self.engine.Connect()
        if conn:
            with conn.lock:
                cu = conn.cursor()
                try:
                    cu.execute(query, data)
                    return 1
                except MySQLdb.Error, e:
                    lerr(e)
                except KeyError, e:
                    lerr(e)
                    lerr("Bad data: %s" % data)
        else:
            lerr("Could not connect to db")
示例#16
0
 def Account(self, d):
     ###    ldbg("mod. radser. class Acct. begin def Account")
     if self.storage.Insert(d):
         return radiusd.RLM_MODULE_OK
     lerr("FAIL: Couldn't account call")
     return radiusd.RLM_MODULE_INVALID