Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
0
def accounting(data):
  ldbg("accounting packet: %s" % str(data))

  d = utils.RadPacketToDict(data)
###  ldbg("mod. radser. fun. acc. post utils.RadPacketToDict")

  if ('Service-Type' not in d) or (d['Service-Type'] != 'Sip-Session'):
    linfo("Service-Type is not Sip-Session, noop")
    return radiusd.RLM_MODULE_NOOP

###  ldbg("mod. radser. fun. acc. before return value of function")
  return acct.Account(d)
Esempio n. 6
0
def instantiate(data):
  global auth, acct
  ldbg("instantiate data: %s" % str(data))

  cfg = ConfigParser.ConfigParser()
  cfg.read("/etc/radser.cfg")

  db = ParseConfig(cfg)
  ldbg("db config: %s" % str(db))

  auth = Auth(storage.UnetmapAuthStorage(db['auth']))
  acct = Acct(storage.AcctStorage(db['acct']))
Esempio n. 7
0
def instantiate(data):
    global auth, acct
    ldbg("instantiate data: %s" % str(data))

    cfg = ConfigParser.ConfigParser()
    cfg.read("/etc/radser.cfg")

    db = ParseConfig(cfg)
    ldbg("db config: %s" % str(db))

    auth = Auth(storage.UnetmapAuthStorage(db['auth']))
    acct = Acct(storage.AcctStorage(db['acct']))
Esempio n. 8
0
def accounting(data):
    ldbg("accounting packet: %s" % str(data))

    d = utils.RadPacketToDict(data)
    ###  ldbg("mod. radser. fun. acc. post utils.RadPacketToDict")

    if ('Service-Type' not in d) or (d['Service-Type'] != 'Sip-Session'):
        linfo("Service-Type is not Sip-Session, noop")
        return radiusd.RLM_MODULE_NOOP


###  ldbg("mod. radser. fun. acc. before return value of function")
    return acct.Account(d)
Esempio n. 9
0
  def GetDset(self, num, default_addr):
    query = """
      SELECT PG.id, PG.groupnumber AS inum, PG.externalnumber AS exnum, PG.servergroup_id AS sgid, INET_NTOA(SG.ip) AS addr, SG.name as sg, PG.metagroup AS is_meta
      FROM phones_phonegroup AS PG
      LEFT JOIN phones_servergroup AS SG
      ON SG.id = PG.servergroup_id
      WHERE PG.groupnumber = %s OR PG.externalnumber = %s
      LIMIT 1
    """
    res = self.getDict(query, (num, num))

    if len(res):
      info = res[0]
      if info['is_meta']:
        ldbg("call to meta-group '%s'" % info['exnum'])
        return self.getMetaDset(num, info['addr'], info['id'], info['sgid'], default_addr)
      if info['sg'] != "opensers":
        ldbg("call to PBX '%s@%s" % (num, info['addr']))
        dset = URISet()
        dset.append(num, info['addr'])
        return dset
      ldbg("call to group '%s'" % num)
      return self.getGroupDset(info['id'], default_addr)
    dset = self.getPhoneDset(num, default_addr)
    if dset:
      ldbg("call to phone '%s'" % num)
    return dset
Esempio n. 10
0
    def GetDset(self, num, default_addr):
        query = """
      SELECT PG.id, PG.groupnumber AS inum, PG.externalnumber AS exnum, PG.servergroup_id AS sgid, INET_NTOA(SG.ip) AS addr, SG.name as sg, PG.metagroup AS is_meta
      FROM phones_phonegroup AS PG
      LEFT JOIN phones_servergroup AS SG
      ON SG.id = PG.servergroup_id
      WHERE PG.groupnumber = %s OR PG.externalnumber = %s
      LIMIT 1
    """
        res = self.getDict(query, (num, num))

        if len(res):
            info = res[0]
            if info['is_meta']:
                ldbg("call to meta-group '%s'" % info['exnum'])
                return self.getMetaDset(num, info['addr'], info['id'],
                                        info['sgid'], default_addr)
            if info['sg'] != "opensers":
                ldbg("call to PBX '%s@%s" % (num, info['addr']))
                dset = URISet()
                dset.append(num, info['addr'])
                return dset
            ldbg("call to group '%s'" % num)
            return self.getGroupDset(info['id'], default_addr)
        dset = self.getPhoneDset(num, default_addr)
        if dset:
            ldbg("call to phone '%s'" % num)
        return dset