def test_add_update_ppmf_product(self): pid = None with make_db(self.db) as db: formdata = Storage({ 'input_max_limit': '10', 'output_max_limit': '10', 'bind_mac': '0', 'flow_price': '1', 'free_auth': '1', 'free_auth_uprate': '1', 'free_auth_downrate': '1', 'fee_flows': '10', 'concur_number': '0', 'bind_vlan': '0', 'fee_price': '10', 'max_giftflows': '10', 'product_name': u'\u6d4b\u8bd5\u6d41\u91cf\u5305\u6708\u8d44\u8d3930G10\u5143\u81ea\u52a8\u7eed\u8d39' }) serv = ProductService(db, self.aes) item = serv.add_ppmf(formdata) self.print_error(serv) raise item or AssertionError pid = item.id with make_db(self.db) as db: formdata2 = Storage({ 'input_max_limit': '10.000', 'bind_mac': '0', 'flow_price': '1', 'free_auth': '1', 'fee_flows': '10.00', 'product_name': u'\u6d4b\u8bd5\u6d41\u91cf\u5305\u6708\u8d44\u8d3930G10\u5143', 'concur_number': '10', 'free_auth_uprate': '2.000', 'output_max_limit': '10.000', 'bind_vlan': '0', 'fee_price': '10.00', 'max_giftflows': '10', 'free_auth_downrate': '2.000', 'product_status': '0', 'id': pid }) raise serv.update_ppmf(formdata2) or AssertionError with make_db(self.db) as db: raise serv.delete(pid) or AssertionError return
def test_add_agency_and_renew(self): product1 = self.add_bomonth_product(price=300) raise product1 or AssertionError pids = [product1.id] agency1 = self.add_agency( u'\u6d4b\u8bd5\u4ee3\u7406\u5546(\u7eed\u8d39\u6d4b\u8bd5)', 'agrenew', '1500', '50', pids) raise agency1 or AssertionError user1 = self.add_customer('auser_renew', product1, agency1) raise user1 or AssertionError with make_db(self.db) as db: formdata = Storage({ 'product_id': product1.id, 'old_expire': '2016-12-12', 'account_number': 'auser_renew', 'giftdays': '0', 'months': 0, 'fee_value': product1.fee_price / 100.0, 'expire_date': '2017-12-12', 'operate_desc': u'\u6d4b\u8bd5\u4ee3\u7406\u5546\u7528\u6237\u7eed\u8d39' }) serv = AccountRenew(db, self.aes) item = serv.renew(formdata) self.print_error(serv) raise item or AssertionError
def wxrouter_menu_products(self, msg, gdata=None, wechat=None, **kwargs): """ 套餐资费 """ yield with make_db(gdata.db) as db: try: mp_domain_addr = self.db.query( models.TrParam.param_value).filter_by( param_name='mp_domain_addr').scalar() products = db.query(models.TrProduct).filter_by( product_status=0, ispub=1).limit(7) articles = [] for p in products: article1 = Storage() article1.title = utils.safeunicode(p.product_name) article1.description = '' article1.url = '%s/mps/product/%s' % (mp_domain_addr, p.id) article1.picurl = '' articles.append(article1) defer.returnValue(wechat.response_news(articles)) except Exception as err: logger.exception(err, trace='wechat') defer.returnValue( wechat.response_text(u'服务器错误,请联系客服 %s' % utils.safeunicode(err)))
def process(self, *args, **kwargs): next_interval = self.get_next_interval() user_total = 0 online_total = 0 with make_db(self.db) as db: try: user_total = db.query(models.TrAccount).count() online_total = db.query(models.TrOnline).count() except Exception as err: pass try: api_url = 'http://www.taurusxcloud.net/api/v1/ping' api_token = yield tools.get_sys_token() params = dict(token=api_token, app='taurusxee', ver=__version__, release=os.environ.get('LICENSE_TYPE', 'taurusxee'), unum=user_total, onum=online_total, dist=pf.linux_distribution()) param_str = urlencode(params) resp = yield httpclient.fetch(api_url + '?' + param_str, followRedirect=True) logger.info('taurusxcloud ping resp code: %s' % resp.code) except Exception as err: logger.error(err) defer.returnValue(next_interval)
def test_agency_change(self): product1 = self.add_bomonth_product(price=400) raise product1 or AssertionError product2 = self.add_bomonth_product(price=500) raise product2 or AssertionError pids = [product1.id] agency1 = self.add_agency( u'\u6d4b\u8bd5\u4ee3\u7406\u5546(\u53d8\u66f4\u6d4b\u8bd5)', 'agency4', '1000', '50', pids) raise agency1 or AssertionError user1 = self.add_customer('chuser1', product1, agency1) raise user1 or AssertionError with make_db(self.db) as db: formdata = Storage({ 'account_number': 'chuser1', 'add_value': 100, 'product_id': product2.id, 'expire_date': '2017-12-12', 'operate_desc': u'\u6d4b\u8bd5\u53d8\u66f4\u8d44\u8d39', 'balance': '0.00', 'time_length': '0', 'flow_length': '0' }) serv = AccountChange(db, self.aes) self.print_error(serv) raise serv.change(formdata) or AssertionError
def add_customer(self, username, product, agency=None): from taurusxradius.modules.dbservice.customer_add import CustomerAdd with make_db(self.db) as db: formdata = Storage({ 'account_number': username, 'password': '******', 'area_id': '1', 'idcard': '000000', 'agency_id': str(agency.id) if agency else None, 'builder_name': None, 'giftflows': '0', 'giftdays': '0', 'charge_code': None, 'expire_date': '2017-06-27', 'fee_value': str(product.fee_price / 100.0), 'status': '1', 'realname': 'r_%s' % username, 'node_id': '1', 'account_rule': '1', 'address': u'\u6d4b\u8bd5\u7528\u6237\u5730\u5740', 'ip_address': None, 'product_id': str(product.id), 'mobile': '000000', 'months': '0', 'customer_desc': u'\u6d4b\u8bd5\u7528\u6237' }) serv = CustomerAdd(db, self.aes) cuser = serv.add(formdata) self.print_error(serv) return cuser return
def event_rossync_resync_pool(self, bas_id=None, **kwargs): if os.environ.get('LICENSE_TYPE', '') not in ('taurusxee', 'routeros-oem'): return try: logger.info('resync pool: bas_id={0}'.format(bas_id)) rcli = self.get_bas_ros(bas_id) def update_pools(poolresp, name, ranges, next_pool): if poolresp and '!re' not in poolresp[0]: d = rcli.add_pool(name, ranges, next_pool) d.addCallback(self.onresp, 'add pool', rcli.apiaddr) d.addErrback(self.onerror, 'add pool', rcli.apiaddr) else: d2 = rcli.set_pool(name, ranges, next_pool) d2.addCallback(self.onresp, 'set pool', rcli.apiaddr) d2.addErrback(self.onerror, 'set pool', rcli.apiaddr) with make_db(self.db) as db: for p in self.db.query(models.TrAddrPool).all(): dg = rcli.get_pool(p.pool_name) dg.addCallback(update_pools, p.pool_name, '%s-%s' % (p.start_ip, p.end_ip), p.next_pool) dg.addErrback(self.onerror, 'get pool', rcli.apiaddr) except Exception as err: logger.exception(err)
def process(self, *args, **kwargs): self.logtimes() next_interval = self.get_next_interval() billtask_last_day = int(self.get_param_value('billtask_last_day', 3)) if billtask_last_day > 28: billtask_last_day = 28 _now = datetime.datetime.now() if _now.day > billtask_last_day: return next_interval cmonth = _now.strftime('%Y-%m') with make_db(self.db) as db: try: uquery = db.query(models.TrAccount).filter( models.TrAccount.product_id == models.TrProduct.id, models.TrAccount.status == 1, models.TrProduct.product_policy == APMonth, models.TrAccount.create_time < cmonth + '-01 00:00:00') for account in uquery: alog = db.query(models.TrAcceptLog).filter( models.TrAcceptLog.accept_type == 'apm_bill', models.TrAcceptLog.account_number == account.account_number, models.TrAcceptLog.accept_time >= cmonth + '-01 00:00:00') if alog.count() == 0: rets = dispatch.pub('apm_user_billing', account.account_number, async=True) except Exception as err: logger.info(u'用户后付费包月自动出账执行失败,%s, 下次执行还需等待 %s' % (repr(err), self.format_time(next_interval)), trace='task') logger.exception(err) return next_interval
def test_update_agency(self): product1 = self.add_bomonth_product(price=1000) raise product1 or AssertionError pids = [product1.id] agency2 = self.add_agency( u'\u6d4b\u8bd5\u4ee3\u7406\u5546(\u6d4b\u8bd5\u4fee\u6539)', 'agencyup', '50000', '30', pids) raise agency2 or AssertionError with make_db(self.db) as db: formdata = Storage({ 'agency_id': agency2.id, 'agency_name': '\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbb\xa3\xe7\x90\x86\xe5\x95\x86(\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbf\xae\xe6\x94\xb9ok)', 'contact': 'wjt1', 'mobile': '13333333334', 'share_rate': 20, 'operator_status': 0, 'operator_name': 'agencyupopr', 'operator_pass': '******', 'agency_desc': u'\u6d4b\u8bd5\u4ee3\u7406\u5546' }) serv = AgencyService(db, self.aes) item = serv.update(formdata, operator_nodes=[1], operator_products=pids) self.print_error(serv) raise item or AssertionError
def event_rossync_set_pppoe_user(self, name, password, profile, node_id=None, **kwargs): if os.environ.get('LICENSE_TYPE', '') not in ('taurusxee', 'routeros-oem'): return with make_db(self.db) as db: if node_id and db.query(models.TrNode.id).filter_by( id=node_id, node_type='pppoe').count() == 0: logger.info('%s not pppoe user' % name) return logger.info('set pppoe user: name={0}, {1} {2} {3}'.format( name, '*******', profile, node_id)) allros = [] if node_id: allros = self.get_node_ross(node_id) else: allros = self.get_all_ros() print allros def update_user(resp, rcli, name, password, profile): ud = rcli.add_pppoe_user(name, password, profile) ud.addCallback(self.onresp, 'add pppoe user', rcli.apiaddr) ud.addErrback(self.onerror, 'add pppoe user', rcli.apiaddr) for rcli in allros: d = rcli.del_pppoe_user(name) d.addCallback(update_user, rcli, name, password, profile) d.addErrback(self.onerror, 'del pppoe user', rcli.apiaddr)
def process(self, *args, **kwargs): self.logtimes() with make_db(self.db) as db: try: onlines = db.query(models.TrOnline) for online in onlines: acct_start_time = datetime.datetime.strptime( online.acct_start_time, '%Y-%m-%d %H:%M:%S') acct_session_time = online.billing_times nowdate = datetime.datetime.now() dt = nowdate - acct_start_time online_times = dt.total_seconds() max_interim_intelval = int( self.get_param_value('radius_acct_interim_intelval', 240)) if online_times - acct_session_time > max_interim_intelval + 30: logger.info( 'online %s overtime, system auto clear this online' % online.account_number) dispatch.pub(CLEAR_ONLINE_EVENT, online.account_number, online.nas_addr, online.acct_session_id, async=True) except Exception as err: db.rollback() logger.exception(err) return 30.0
def event_rossync_resync_pppoe_user(self, bas_id=None, **kwargs): if os.environ.get('LICENSE_TYPE', '') not in ('taurusxee', 'routeros-oem'): return try: logger.info('resync pppoe user: bas_id={0}'.format(bas_id)) rcli = self.get_bas_ros(bas_id) def update_user(resp, name, password, profile): d = rcli.add_pppoe_user(name, password, profile) d.addCallback(self.onresp, 'add pppoe user', rcli.apiaddr) d.addErrback(self.onerror, 'add pppoe user', rcli.apiaddr) with make_db(self.db) as db: for node_id, in db.query(models.TrNode.id).filter( models.TrBasNode.node_id == models.TrNode.id, models.TrNode.node_type == 'pppoe', models.TrBasNode.bas_id == bas_id): for user in self.db.query(models.TrAccount).filter( models.TrAccount.status < 2, models.TrAccount.expire_date >= utils.get_currdate(), models.TrAccount.customer_id == models.TrCustomer.customer_id, models.TrCustomer.node_id == node_id): dg = rcli.del_pppoe_user(user.account_number) dg.addCallback(update_user, user.account_number, self.aes.decrypt(user.password), user.product_id) dg.addErrback(self.onerror, 'del pppoe user', rcli.apiaddr) except Exception as err: logger.exception(err)
def test_add_update_delete_bas(self): node = self.add_node() bas = None with make_db(self.db) as db: serv = BasService(db, self.aes, config=self.config) ret = serv.add( Storage({ 'ip_addr': '127.0.0.2', 'nas_id': '12121211', 'nodes': [node.id], 'dns_name': '', 'bas_name': 'taurusxac', 'bas_secret': '123456', 'vendor_id': '0', 'coa_port': '3799', 'sync_ver': tools.gen_sync_ver() })) if hasattr(serv, 'last_error'): print serv.last_error bas = self.warp(ret) raise bas or AssertionError with make_db(self.db) as db: serv = BasService(db, self.aes, config=self.config) ret = serv.update( Storage({ 'id': bas.id, 'ip_addr': '127.1.0.1', 'nas_id': '12121211', 'nodes': [node.id], 'dns_name': '', 'bas_name': 'taurusxac2', 'bas_secret': '123456', 'vendor_id': '0', 'coa_port': '3799', 'sync_ver': tools.gen_sync_ver() })) if hasattr(serv, 'last_error'): print serv.last_error bas = self.warp(ret) raise bas or AssertionError with make_db(self.db) as db: serv = BasService(db, self.aes, config=self.config) ret = serv.delete(bas.id) if hasattr(serv, 'last_error'): print serv.last_error raise ret or AssertionError return
def test_account_pause_resume(self): product1 = self.add_bomonth_product(price=500) raise product1 or AssertionError user1 = self.add_customer('atuser002', product1) raise user1 or AssertionError with make_db(self.db) as db: serv = AccountService(db, self.aes, config=self.config) ret = serv.pause('atuser002') if hasattr(serv, 'last_error'): print serv.last_error raise ret or AssertionError with make_db(self.db) as db: serv = AccountService(db, self.aes, config=self.config) ret = serv.resume('atuser002') if hasattr(serv, 'last_error'): print serv.last_error raise ret or AssertionError
def onSendError(self, err, disconnect_req): try: with make_db(self.db) as db: if disconnect_req and db.query(models.TrOnline).filter_by(nas_addr=disconnect_req.nas_addr, acct_session_id=disconnect_req.acct_session_id).count() > 0: radius_acct_stop.RadiusAcctStop(self.dbengine, self.mcache, self.aes, disconnect_req).acctounting() logger.info(u'系统触发用户强制下线失败: %s; OnlineInfo: %s ' % (err.getErrorMessage(), json.dumps(disconnect_req)), trace='event') logger.error(u'send disconnect done! %s' % err.getErrorMessage()) except Exception as err: logger.exception(err)
def onSendResp(self, resp, disconnect_req): try: with make_db(self.db) as db: if disconnect_req and db.query(models.TrOnline).filter_by(nas_addr=disconnect_req.nas_addr, acct_session_id=disconnect_req.acct_session_id).count() > 0: radius_acct_stop.RadiusAcctStop(self.dbengine, self.mcache, self.aes, disconnect_req).acctounting() logger.info(u'系统触发用户强制下线成功: %s; OnlineInfo: %s ' % (str(resp), json.dumps(disconnect_req)), trace='event') logger.info(u'send disconnect ok! coa resp : %s' % resp) except Exception as err: logger.exception(err)
def test_add_and_delete_node(self): node_id = None with make_db(self.db) as db: serv = NodeService(db, self.aes, config=self.config) ret = serv.add(Storage({'node_name': '\xe6\xb5\x8b\xe8\xaf\x95\xe5\x88\xa0\xe9\x99\xa4\xe5\x8c\xba\xe5\x9f\x9f', 'node_desc': '\xe6\xb5\x8b\xe8\xaf\x95\xe5\x88\xa0\xe9\x99\xa4\xe5\x8c\xba\xe5\x9f\x9f', 'rule_id': '0', 'sync_ver': tools.gen_sync_ver()})) if hasattr(serv, 'last_error'): print serv.last_error node_id = ret.id raise ret or AssertionError with make_db(self.db) as db: serv = NodeService(db, self.aes, config=self.config) ret = serv.delete(node_id) if hasattr(serv, 'last_error'): print serv.last_error raise ret or AssertionError return
def wxrouter_event_subscribe(self, msg, gdata=None, wechat=None, **kwargs): yield with make_db(gdata.db) as db: try: welcome_text = db.query(models.TrParam.param_value).filter( models.TrParam.param_name == 'mps_welcome_text').scalar() or '' defer.returnValue( wechat.response_text(utils.safeunicode(welcome_text))) except Exception as err: logger.exception(err, trace='wechat')
def wxrouter_oprbind_qr_scan(self, msg, gdata = None, wechat = None, builder_id = None, **kwargs): yield with make_db(gdata.db) as db: builder = db.query(models.TrBuilder).get(builder_id) if not builder: defer.returnValue(wechat.response_text(u'无效的绑定码')) if builder.wechat_oid: defer.returnValue(wechat.response_text(u'微信账号已经绑定')) else: builder.wechat_oid = msg.source db.commit() defer.returnValue(wechat.response_text(u'微信账号绑定成功'))
def get_customer_info(self, account_number): with make_db(self.db) as db: return db.query( models.TrCustomer.mobile, models.TrCustomer.email, models.TrCustomer.wechat_oid, models.TrCustomer.realname, models.TrProduct.product_name, models.TrAccount.account_number, models.TrAccount.install_address, models.TrAccount.expire_date, models.TrAccount.password).filter( models.TrCustomer.customer_id == models.TrAccount.customer_id, models.TrAccount.product_id == models.TrProduct.id, models.TrAccount.account_number == account_number).first()
def test_add_and_update_node(self): node = None with make_db(self.db) as db: serv = NodeService(db, self.aes, config=self.config) ret = serv.add(Storage({'node_name': 'node2', 'node_desc': '\xe6\xb5\x8b\xe8\xaf\x95\xe5\x8c\xba\xe5\x9f\x9f2', 'rule_id': '0', 'sync_ver': tools.gen_sync_ver()})) if hasattr(serv, 'last_error'): print serv.last_error node = self.warp(ret) raise node or AssertionError with make_db(self.db) as db: serv = NodeService(db, self.aes, config=self.config) ret = serv.update(Storage({'id': node.id, 'node_name': '\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbf\xae\xe6\x94\xb9\xe5\x8c\xba\xe5\x9f\x9f', 'node_desc': '\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbf\xae\xe6\x94\xb9\xe5\x8c\xba\xe5\x9f\x9f', 'rule_id': '0', 'sync_ver': tools.gen_sync_ver()})) if hasattr(serv, 'last_error'): print serv.last_error raise self.warp(ret) or AssertionError return
def get_node_ross(self, node_id): ros_array = [] basnode_array = [] with make_db(self.db) as db: basnode_array = self.db.query(models.TrBasNode).filter(models.TrNode.id == models.TrBasNode.node_id, models.TrNode.id == node_id).all() for bn in basnode_array: try: api_addr, api_port, api_user, api_pwd = self.get_bas_ros_params(bn.bas_id) if all([api_addr, api_port, api_user]): roscli = rospool.get_client(api_addr, api_port, api_user, api_pwd) ros_array.append(roscli) except Exception as err: logger.error('ros connect fail: %s' % repr(err)) return ros_array
def get_all_ros(self): ros_array = [] bas_array = [] with make_db(self.db) as db: bas_array = self.db.query(models.TrBas.id).all() for bas_id, in bas_array: api_addr, api_port, api_user, api_pwd = self.get_bas_ros_params(bas_id) try: if all([api_addr, api_port, api_user]): roscli = rospool.get_client(api_addr, api_port, api_user, api_pwd) ros_array.append(roscli) except Exception as err: logger.error('ros connect fail: %s' % repr(err), trace='routeros') return ros_array
def event_clear_online(self, account_number, nas_addr, acct_session_id): try: with make_db(self.db) as db: logger.info('event clear expire online [username:{0}] {1} {2}'.format(account_number, nas_addr, acct_session_id), username=account_number) nas = db.query(models.TrBas).filter_by(ip_addr=nas_addr).first() if nas_addr and not nas: db.query(models.TrOnline).filter_by(nas_addr=nas_addr, acct_session_id=acct_session_id).delete() db.commit() dispatch.pub(DBSYNC_STATUS_ADD, models.warp_sdel_obj(models.TrOnline.__tablename__, dict(nas_addr=nas_addr, acct_session_id=acct_session_id)), async=True) return online = db.query(models.TrOnline).filter_by(nas_addr=nas_addr, acct_session_id=acct_session_id).first() clear_req = self.get_request(online) radius_acct_stop.RadiusAcctStop(self.dbengine, self.mcache, self.aes, clear_req).acctounting() logger.info(u'系统触发用户过期清理成功: [username:%s] OnlineInfo: %s ' % (str(account_number), json.dumps(clear_req)), trace='event', username=account_number) except Exception as err: logger.exception(err)
def add_node(self): with make_db(self.db) as db: serv = NodeService(db, self.aes, config=self.config) ret = serv.add( Storage({ 'node_name': '(BAS\xe6\xb5\x8b\xe8\xaf\x95)\xe5\x8c\xba\xe5\x9f\x9f', 'node_desc': '(BAS\xe6\xb5\x8b\xe8\xaf\x95)\xe5\x8c\xba\xe5\x9f\x9f', 'rule_id': '0', 'sync_ver': tools.gen_sync_ver() })) if hasattr(serv, 'last_error'): print serv.last_error node = self.warp(ret) raise node or AssertionError return node
def event_check_online(self, account_number): with make_db(self.db) as db: try: logger.info('event check online [username:{0}] '.format(account_number), username=account_number) onlines = db.query(models.TrOnline).filter_by(account_number=account_number) for online in onlines: acct_start_time = datetime.datetime.strptime(online.acct_start_time, '%Y-%m-%d %H:%M:%S') acct_session_time = online.billing_times nowdate = datetime.datetime.now() dt = nowdate - acct_start_time online_times = dt.total_seconds() max_interim_intelval = int(self.get_param_value('radius_acct_interim_intelval', 240)) if online_times - acct_session_time > max_interim_intelval + 30: logger.info('online %s overtime, system auto clear this online' % online.account_number, username=account_number) dispatch.pub(CLEAR_ONLINE_EVENT, online.account_number, online.nas_addr, online.acct_session_id, async=True) except Exception as err: logger.exception(err)
def test_account_update(self): product1 = self.add_bomonth_product(price=500) raise product1 or AssertionError user1 = self.add_customer('atuser001', product1) raise user1 or AssertionError with make_db(self.db) as db: formdata = Storage({'account_number': 'atuser001', 'ip_address': '', 'install_address': 'address', 'user_concur_number': '2', 'bind_mac': '1', 'bind_vlan': '1', 'account_desc': 'desc'}) serv = AccountService(db, self.aes, config=self.config) ret = serv.update(formdata) if hasattr(serv, 'last_error'): print serv.last_error raise ret or AssertionError
def event_unlock_online(self, account_number, nas_addr, acct_session_id): with make_db(self.db) as db: logger.info('event unlock online [username:{0}] {1} {2}'.format(account_number, nas_addr, acct_session_id), username=account_number) nas = db.query(models.TrBas).filter_by(ip_addr=nas_addr).first() if nas_addr and not nas: db.query(models.TrOnline).filter_by(nas_addr=nas_addr, acct_session_id=acct_session_id).delete() db.commit() dispatch.pub(DBSYNC_STATUS_ADD, models.warp_sdel_obj(models.TrOnline.__tablename__, dict(nas_addr=nas_addr, acct_session_id=session_id)), async=True) return online = db.query(models.TrOnline).filter_by(nas_addr=nas_addr, acct_session_id=acct_session_id).first() dm_params = dict(User_Name=account_number, Framed_IP_Address=online.framed_ipaddr, Acct_Session_Id=acct_session_id) if int(self.get_param_value('radius_coa_send_nasaddr', 0)): dm_params['NAS_IP_Address'] = nas.ip_addr deferd = authorize.disconnect(int(nas.vendor_id or 0), self.dictionary, nas.bas_secret, nas.ip_addr, coa_port=int(nas.coa_port or 3799), debug=True, **dm_params).addCallback(self.onSendResp, self.get_request(online)).addErrback(self.onSendError, self.get_request(online)) logreq = u'nas_addr=%s;coa_port=%s; username=%s; session_id=%s' % (nas.ip_addr, int(nas.coa_port or 3799), account_number, acct_session_id) logger.info(u'%s - 系统触发用户强制下线请求: CoaRequest: %s ' % logreq, trace='event', username=account_number)
def process(self, *args, **kwargs): self.logtimes() next_interval = self.get_next_interval() try: logger.info('start process wechat_notify task') _ndays = self.get_param_value('expire_notify_days') with make_db(self.db) as db: _now = datetime.datetime.now() _date = (datetime.datetime.now() + datetime.timedelta(days=int(_ndays))).strftime('%Y-%m-%d') expire_query = db.query(models.TrAccount).filter(models.TrAccount.customer_id == models.TrCustomer.customer_id, models.TrAccount.expire_date <= _date, models.TrAccount.expire_date >= _now.strftime('%Y-%m-%d'), models.TrAccount.status == 1) logger.info('wechat_notify total: %s' % expire_query.count()) for account in expire_query: dispatch.pub('wechat_account_expire', account.account_number, async=False) logger.info(u'微信到期通知任务已执行(%s个已通知)。下次执行还需等待 %s' % (expire_query.count(), self.format_time(next_interval)), trace='task') except Exception as err: logger.info(u'微信到期通知任务执行失败,%s。下次执行还需等待 %s' % (repr(err), self.format_time(next_interval)), trace='task') return next_interval
def add_agency(self, name, opr, amount, rate, pids=[]): from taurusxradius.modules.dbservice.agency_service import AgencyService with make_db(self.db) as db: formdata = Storage({ 'agency_name': name, 'contact': 'wjt', 'mobile': '13333333333', 'amount': amount, 'share_rate': rate, 'operator_name': opr, 'operator_pass': '******', 'agency_desc': u'\u6d4b\u8bd5\u4ee3\u7406\u5546' }) serv = AgencyService(db, self.aes) item = serv.add(formdata, operator_nodes=[1], operator_products=pids) self.print_error(serv) return self.warp(item)