Example #1
0
    def start_accounting(self,req,nas):
        service.incr_stat(service.STAT_ACCT_START)
        _key = '%s_%s'%(nas.ip_addr,req.get_acctsessionid())
        if service.is_online(_key):
            radiuslog.error('[Acct] accounting of start is repeated')
            return

        user = service.get_user(req.get_username())

        if not user:
            radiuslog.error("[Acct] Received an accounting request but user[%s] not exists"%req.get_username())
            return

        online = dict(user = user,
            nas = nas,
            sessionid = req.get_acctsessionid(),
            acctstarttime = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S"),
            framedipaddr = req.get_framedipaddr(),
            macaddr = req.get_macaddr(),
            nasportid = req.get_nasportid(),
            startsource = STATUS_TYPE_START)

        service.add_online(_key,online)

        if radiuslog.isEnabledFor(DEBUG):
            radiuslog.info('[Acct] User[%s],Nas[%s] billing starting'%(user.user_name,nas.ip_addr))
Example #2
0
    def update_accounting(self,req,nas):
        service.incr_stat(service.STAT_ACCT_UPDATE)
        _key = '%s_%s'%(nas.ip_addr,req.get_acctsessionid())

        online = service.get_online(_key)
        if online is None:
            user = service.get_user(req.get_username())
            if not user:
                radiuslog.error("[Acct] Received an accounting request but user[%s] not exists"%req.get_username())
                return            
            sessiontime = req.get_acctsessiontime()
            updatetime = datetime.datetime.now()

            _starttime = updatetime + datetime.timedelta(seconds=-sessiontime)       

            online = dict(user = user,
                nas = nas,
                sessionid = req.get_acctsessionid(),
                acctstarttime = _starttime,
                framedipaddr = req.get_framedipaddr(),
                macaddr = req.get_macaddr(),
                nasportid = req.get_nasportid(),
                startsource = STATUS_TYPE_UPDATE)

            service.add_online(_key,online)       
        else:
            online['framedipaddr'] = req.get_framedipaddr()
Example #3
0
 def set_special_int(self, vendor, name, value):
     try:
         if not vendor_cfg.has_key(int(vendor)):
             return
         key = vendor_cfg[int(vendor)][name]
         self.AddAttribute(key, tools.EncodeInteger(value))
     except Exception, e:
         radiuslog.error("set_special error,vendor=%s,name=%s,value=%s;err=%s"\
             %(vendor,name,value,str(e)))
Example #4
0
 def set_filter_id(self, vendor, filterid):
     if not filterid: return
     try:
         if not vendor_cfg.has_key(int(vendor)):
             return
         if vendor_cfg[int(vendor)]['filter_id']:
             self.AddAttribute(11, tools.EncodeString(filterid))
     except Exception, e:
         radiuslog.error("set_filter_id error,%s" % (str(e)))
Example #5
0
 def set_special_int(self,vendor,name,value):
     try:
         if not vendor_cfg.has_key(int(vendor)):
             return
         key = vendor_cfg[int(vendor)][name]
         self.AddAttribute(key,tools.EncodeInteger(value))
     except Exception, e:
         radiuslog.error("set_special error,vendor=%s,name=%s,value=%s;err=%s"\
             %(vendor,name,value,str(e)))            
Example #6
0
 def set_filter_id(self,vendor,filterid):
     if not filterid:return
     try:
         if not vendor_cfg.has_key(int(vendor)):
             return
         if vendor_cfg[int(vendor)]['filter_id']:
             self.AddAttribute(11,tools.EncodeString(filterid))
     except Exception, e:
         radiuslog.error("set_filter_id error,%s"%(str(e)))        
Example #7
0
    def send_reject(self, req, nas, err):
        service.incr_stat(service.STAT_AUTH_REJECT)
        reply = req.CreateReply(msg=err)
        reply.source = req.source
        reply.code = packet.AccessReject
        # import pdb
        # pdb.set_trace()
        req.sock.sendto(reply.ReplyPacket(), reply.source)

        radiuslog.error("[Auth]  send an authentication reject,err:%s" % err)
Example #8
0
    def send_reject(self,req,nas,err):
        service.incr_stat(service.STAT_AUTH_REJECT)
        reply = req.CreateReply(msg=err)
        reply.source = req.source
        reply.code=packet.AccessReject
        # import pdb
        # pdb.set_trace()
        req.sock.sendto(reply.ReplyPacket(), reply.source)   

        radiuslog.error("[Auth]  send an authentication reject,err:%s"%err)        
Example #9
0
    def handle(self,data, address):
        nas = self.nases.get(address[0])
        if not nas:
            radiuslog.error(u'Illegal request from %s:%s' % address)
            return 

        try:
            pkt = utils.AcctPacket2(packet=data,dict=self.dict,secret=str(nas.acct_secret))
            pkt.source,pkt.sock = address,self.socket
            gevent.spawn(accountingHandler,pkt)    
        except Exception as err:
            radiuslog.error(u'process packet error:' + str(err))     
Example #10
0
    def handle(self, data, address):
        nas = self.nases.get(address[0])
        if not nas:
            radiuslog.error(u'Illegal request from %s:%s' % address)
            return

        try:
            pkt = utils.AcctPacket2(packet=data,
                                    dict=self.dict,
                                    secret=str(nas.acct_secret))
            pkt.source, pkt.sock = address, self.socket
            gevent.spawn(accountingHandler, pkt)
        except Exception as err:
            radiuslog.error(u'process packet error:' + str(err))