コード例 #1
0
 def acctounting(self):
     if not self.account:
         return logger.error(u'收到用户:%s 记账结束请求,但用户资料不存在' %
                             self.request.account_number,
                             tag='radius_acct_stop_error',
                             trace='radius',
                             username=self.request.account_number)
     ticket = Storage(**self.request)
     _datetime = datetime.datetime.now()
     online = self.get_online(ticket.nas_addr, ticket.acct_session_id)
     if not online:
         session_time = ticket.acct_session_time
         stop_time = _datetime.strftime('%Y-%m-%d %H:%M:%S')
         start_time = (_datetime - datetime.timedelta(
             seconds=int(session_time))).strftime('%Y-%m-%d %H:%M:%S')
         ticket.acct_start_time = start_time
         ticket.acct_stop_time = stop_time
         ticket.start_source = STATUS_TYPE_STOP
         ticket.stop_source = STATUS_TYPE_STOP
         self.add_ticket(ticket)
     else:
         self.del_online(ticket.nas_addr, ticket.acct_session_id)
         ticket.acct_start_time = online.acct_start_time
         ticket.acct_stop_time = _datetime.strftime('%Y-%m-%d %H:%M:%S')
         ticket.start_source = online.start_source
         ticket.stop_source = STATUS_TYPE_STOP
         self.add_ticket(ticket)
         self.billing(online)
         logger.info(u'用户:%s 记账结束, 清除在线用户数据' % self.account.account_number,
                     trace='radius',
                     username=online.account_number)
コード例 #2
0
ファイル: radius_basic.py プロジェクト: sailorhdx/taurusxr
 def new_ticket(online):
     _datetime = datetime.datetime.now()
     _starttime = datetime.datetime.strptime(online.acct_start_time, '%Y-%m-%d %H:%M:%S')
     session_time = (_datetime - _starttime).seconds
     stop_time = _datetime.strftime('%Y-%m-%d %H:%M:%S')
     ticket = Storage()
     ticket.id = utils.get_uuid()
     ticket.account_number = (online.account_number,)
     ticket.acct_session_id = (online.acct_session_id,)
     ticket.acct_start_time = (online.acct_start_time,)
     ticket.nas_addr = (online.nas_addr,)
     ticket.framed_ipaddr = (online.framed_ipaddr,)
     ticket.acct_session_time = (session_time,)
     ticket.acct_stop_time = (stop_time,)
     ticket.sync_ver = tools.gen_sync_ver()
     return ticket