def process(req=None, resp=None, user=None): product = store.get_product(user['product_id']) session_timeout = int(store.get_param("max_session_timeout")) acct_policy = user['product_policy'] or FEE_BUYOUT if acct_policy in (FEE_BUYOUT, FEE_MONTH): expire_date = user.get('expire_date') _expire_datetime = datetime.datetime.strptime( expire_date + ' 23:59:59', "%Y-%m-%d %H:%M:%S") _datetime = datetime.datetime.now() if _datetime > _expire_datetime: session_timeout += (_expire_datetime - _datetime).seconds elif acct_policy == FEE_TIMES: balance = int(user.get("balance", 0)) if balance == 0: session_timeout = 0 else: time_len = balance * 3600 / product['fee_price'] session_timeout = time_len if "Framed-Pool" in resp: if store.get_param("9_expire_addrpool") in resp['Framed-Pool']: session_timeout = 120 resp['Session-Timeout'] = session_timeout input_limit = str(product['input_max_limit']) output_limit = str(product['output_max_limit']) _class = input_limit.zfill(8) + input_limit.zfill(8) + output_limit.zfill( 8) + output_limit.zfill(8) resp['Class'] = _class if user['ip_address']: resp['Framed-IP-Address'] = user['ip_address'] for attr in store.get_product_attrs(user['product_id']): try: _type = resp.dict[attr['attr_name']].type print _type resp[str(attr['attr_name'])] = get_type_val( _type, attr['attr_value']) except: import traceback traceback.print_exc() # for attr in store.get_user_attrs(user['account_number']): # try:resp[attr.attr_name] = attr.attr_value # except:pass return resp
def process(req=None,resp=None,user=None): product = store.get_product(user['product_id']) session_timeout = int(store.get_param("max_session_timeout")) acct_policy = user['product_policy'] or FEE_BUYOUT if acct_policy in (FEE_BUYOUT,FEE_MONTH): expire_date = user.get('expire_date') _expire_datetime = datetime.datetime.strptime(expire_date+' 23:59:59',"%Y-%m-%d %H:%M:%S") _datetime = datetime.datetime.now() if _datetime > _expire_datetime: session_timeout += (_expire_datetime - _datetime).seconds elif acct_policy == FEE_TIMES: balance = int(user.get("balance",0)) if balance == 0: session_timeout = 0 else: time_len = balance * 3600 / product['fee_price'] session_timeout = time_len if "Framed-Pool" in resp: if store.get_param("9_expire_addrpool") in resp['Framed-Pool']: session_timeout = 120 resp['Session-Timeout'] = session_timeout input_limit = str(product['input_max_limit']) output_limit = str(product['output_max_limit']) _class = input_limit.zfill(8) + input_limit.zfill(8) + output_limit.zfill(8) + output_limit.zfill(8) resp['Class'] = _class if user['ip_address']: resp['Framed-IP-Address'] = user['ip_address'] for attr in store.get_product_attrs(user['product_id']): try: _type = resp.dict[attr['attr_name']].type print _type resp[str(attr['attr_name'])] = get_type_val(_type,attr['attr_value']) except: import traceback traceback.print_exc() # for attr in store.get_user_attrs(user['account_number']): # try:resp[attr.attr_name] = attr.attr_value # except:pass return resp
def __init__(self, dict=None,trace=None,midware=None,runstat=None,debug=False): _dict = dictionary.Dictionary(dict) host.Host.__init__(self,dict=_dict) self.debug = debug self.user_trace = trace self.midware = midware self.runstat = runstat self.auth_delay = utils.AuthDelay(int(store.get_param("reject_delay") or 0))
def process(req=None,resp=None,user=None): """执行计费策略校验,用户到期检测,用户余额,时长检测""" acct_policy = user['product_policy'] or FEE_MONTH if acct_policy in ( FEE_MONTH,FEE_BUYOUT): if utils.is_expire(user.get('expire_date')): resp['Framed-Pool'] = store.get_param("9_expire_addrpool") elif acct_policy == FEE_TIMES: user_balance = store.get_user_balance(user['account_number']) if user_balance <= 0: return error_auth(resp,'user balance poor') if user['user_concur_number'] > 0 : if store.count_online(user['account_number']) >= user['user_concur_number']: return error_auth(resp,'user session to limit') return resp
def process(req=None, resp=None, user=None): if not user: return error_auth(resp, 'user %s not exists' % req.get_user_name()) if not req.is_valid_pwd(utils.decrypt(user['password'])): return error_auth(resp, 'user password not match') if user['status'] == 4: resp['Framed-Pool'] = store.get_param("9_expire_addrpool") return resp if user['status'] in (0, 2, 3): return error_auth(resp, 'user status not ok') return resp
def process(req=None,resp=None,user=None): if not user: return error_auth(resp,'user %s not exists'%req.get_user_name()) if not req.is_valid_pwd(utils.decrypt(user['password'])): return error_auth(resp,'user password not match') if user['status'] == 4: resp['Framed-Pool'] = store.get_param("9_expire_addrpool") return resp if user['status'] in (0,2,3): return error_auth(resp,'user status not ok') return resp