Пример #1
0
    def process_botimes():
        #买断时长
        log.msg('%s > Buyout long time billing ' % req.get_user_name(),
                level=logging.INFO)
        time_length = store.get_user_time_length(user['account_number'])
        sessiontime = req.get_acct_sessiontime()
        billing_times = online['billing_times']
        acct_times = sessiontime - billing_times
        user_time_length = time_length - acct_times
        if user_time_length < 0:
            user_time_length = 0

        store.update_billing(utils.Storage(
            account_number=online['account_number'],
            nas_addr=online['nas_addr'],
            acct_session_id=online['acct_session_id'],
            acct_start_time=online['acct_start_time'],
            acct_session_time=req.get_acct_sessiontime(),
            input_total=req.get_input_total(),
            output_total=req.get_output_total(),
            acct_times=acct_times,
            acct_flows=0,
            acct_fee=0,
            actual_fee=0,
            balance=0,
            time_length=user_time_length,
            flow_length=0,
            is_deduct=1,
            create_time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
                             time_length=user_time_length)

        if user_time_length == 0:
            send_dm(coa_clients, online)
Пример #2
0
def process(req=None, user=None, radiusd=None, **kwargs):
    if not req.get_acct_status_type() == STATUS_TYPE_START:
        return

    runstat = radiusd.runstat
    store = radiusd.store

    if store.is_online(req.get_nas_addr(), req.get_acct_sessionid()):
        runstat.acct_drop += 1
        return log.err('online %s is exists' % req.get_acct_sessionid())

    if not user:
        runstat.acct_drop += 1
        return log.err('user %s not exists' % req.get_user_name())

    runstat.acct_start += 1
    online = utils.Storage(
        account_number=user['account_number'],
        nas_addr=req.get_nas_addr(),
        acct_session_id=req.get_acct_sessionid(),
        acct_start_time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        framed_ipaddr=req.get_framed_ipaddr(),
        mac_addr=req.get_mac_addr(),
        nas_port_id=req.get_nas_portid(),
        billing_times=0,
        input_total=0,
        output_total=0,
        start_source=STATUS_TYPE_START)

    store.add_online(online)

    log.msg('%s Accounting start request, add new online' %
            req.get_user_name(),
            level=logging.INFO)
Пример #3
0
    def process_boflows():
        #买断流量
        radiusd.syslog.debug('[username:%s] > Buyout flow billing ' %
                             req.get_user_name())
        flow_length = store.get_user_flow_length(user['account_number'])
        output_total = req.get_output_total()
        billing_output_total = online['output_total']
        acct_flows = output_total - billing_output_total
        user_flow_length = flow_length - acct_flows
        if user_flow_length < 0:
            user_flow_length = 0
            send_dm(coa_clients, online)

        store.update_billing(utils.Storage(
            account_number=online['account_number'],
            nas_addr=online['nas_addr'],
            acct_session_id=online['acct_session_id'],
            acct_start_time=online['acct_start_time'],
            acct_session_time=req.get_acct_sessiontime(),
            input_total=req.get_input_total(),
            output_total=req.get_output_total(),
            acct_times=0,
            acct_flows=acct_flows,
            acct_fee=0,
            actual_fee=0,
            balance=0,
            time_length=0,
            flow_length=user_flow_length,
            is_deduct=1,
            create_time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
                             flow_length=user_flow_length)

        if user_flow_length == 0:
            send_dm(coa_clients, online)
Пример #4
0
    def process_pptimes():
        # 预付费时长
        radiusd.syslog.debug('[username:%s] > Prepaid long time billing ' %
                             req.get_user_name())
        user_balance = store.get_user_balance(user['account_number'])
        sessiontime = decimal.Decimal(req.get_acct_sessiontime())
        billing_times = decimal.Decimal(online['billing_times'])
        acct_times = sessiontime - billing_times
        fee_price = decimal.Decimal(product['fee_price'])
        usedfee = acct_times / decimal.Decimal(3600) * fee_price
        usedfee = actual_fee = int(usedfee.to_integral_value())
        balance = user_balance - usedfee

        if balance < 0:
            balance = 0
            actual_fee = user_balance

        store.update_billing(
            utils.Storage(account_number=online['account_number'],
                          nas_addr=online['nas_addr'],
                          acct_session_id=online['acct_session_id'],
                          acct_start_time=online['acct_start_time'],
                          acct_session_time=req.get_acct_sessiontime(),
                          input_total=req.get_input_total(),
                          output_total=req.get_output_total(),
                          acct_times=int(acct_times.to_integral_value()),
                          acct_flows=0,
                          acct_fee=usedfee,
                          actual_fee=actual_fee,
                          balance=balance,
                          time_length=0,
                          flow_length=0,
                          is_deduct=1,
                          create_time=datetime.datetime.now().strftime(
                              "%Y-%m-%d %H:%M:%S")))

        if balance == 0:
            radiusd.syslog.warn(
                "[username:%s] insufficient Balance, disconnect" %
                req.get_user_name())
            send_dm(coa_clients, online)
Пример #5
0
    def process_ppflows():
        #预付费流量
        log.msg('%s > Prepaid flow billing ' % req.get_user_name(),
                level=logging.INFO)
        user_balance = store.get_user_balance(user['account_number'])
        output_total = decimal.Decimal(req.get_output_total())
        billing_output_total = decimal.Decimal(online['output_total'])
        acct_flows = output_total - billing_output_total
        fee_price = decimal.Decimal(product['fee_price'])
        usedfee = acct_flows / decimal.Decimal(1024) * fee_price
        usedfee = actual_fee = int(usedfee.to_integral_value())
        balance = user_balance - usedfee

        if balance < 0:
            balance = 0
            actual_fee = user_balance

        store.update_billing(
            utils.Storage(account_number=online['account_number'],
                          nas_addr=online['nas_addr'],
                          acct_session_id=online['acct_session_id'],
                          acct_start_time=online['acct_start_time'],
                          acct_session_time=req.get_acct_sessiontime(),
                          input_total=req.get_input_total(),
                          output_total=req.get_output_total(),
                          acct_times=0,
                          acct_flows=int(acct_flows.to_integral_value()),
                          acct_fee=usedfee,
                          actual_fee=actual_fee,
                          balance=balance,
                          time_length=0,
                          flow_length=0,
                          is_deduct=1,
                          create_time=datetime.datetime.now().strftime(
                              "%Y-%m-%d %H:%M:%S")))

        if balance == 0:
            send_dm(coa_clients, online)
def process(req=None, user=None, radiusd=None, **kwargs):
    if not req.get_acct_status_type() == STATUS_TYPE_UPDATE:
        return

    if not user:
        return log.err(
            "[Acct] Received an accounting update request but user[%s] not exists"
            % req.get_user_name())

    runstat = radiusd.runstat
    store = radiusd.store

    runstat.acct_update += 1
    online = store.get_online(req.get_nas_addr(), req.get_acct_sessionid())

    if not online:
        sessiontime = req.get_acct_sessiontime()
        updatetime = datetime.datetime.now()
        _starttime = updatetime - datetime.timedelta(seconds=sessiontime)
        online = utils.Storage(
            account_number=user['account_number'],
            nas_addr=req.get_nas_addr(),
            acct_session_id=req.get_acct_sessionid(),
            acct_start_time=_starttime.strftime("%Y-%m-%d %H:%M:%S"),
            framed_ipaddr=req.get_framed_ipaddr(),
            mac_addr=req.get_mac_addr(),
            nas_port_id=req.get_nas_portid(),
            billing_times=req.get_acct_sessiontime(),
            input_total=req.get_input_total(),
            output_total=req.get_output_total(),
            start_source=STATUS_TYPE_UPDATE)
        store.add_online(online)

    log.msg('%s Accounting update request, update online' %
            req.get_user_name(),
            level=logging.INFO)