Ejemplo n.º 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))
Ejemplo n.º 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()