Пример #1
0
 def wxrouter_customer_service(self, msg, gdata = None, wechat = None, isp_code = None, **kwargs):
     """ 帮助信息 """
     yield
     articles = []
     mp_domain_addr = gdata.get_param_value('mp_domain_addr')
     if not mp_domain_addr:
         logger.error(u'未设置微信公众号域名')
         defer.returnValue(wechat.response_news(articles))
     article1 = Storage()
     article1.title = u'账号管理'
     article1.description = ''
     article1.url = '%s/mps/userbind' % mp_domain_addr
     article1.picurl = ''
     articles.append(article1)
     article2 = Storage()
     article2.title = u'交易记录'
     article2.description = ''
     article2.url = '%s/mps/userorder' % mp_domain_addr
     article2.picurl = ''
     articles.append(article2)
     article3 = Storage()
     article3.title = u'密码修改'
     article3.description = ''
     article3.url = '%s/mps/useruppw' % mp_domain_addr
     article3.picurl = ''
     articles.append(article3)
     article4 = Storage()
     article4.title = u'资费套餐'
     article4.description = ''
     article4.url = '%s/mps/products' % mp_domain_addr
     article4.picurl = ''
     articles.append(article4)
     defer.returnValue(wechat.response_news(articles))
Пример #2
0
 def acctounting(self):
     if not self.account:
         dispatch.pub(UNLOCK_ONLINE_EVENT,
                      self.request.account_number,
                      self.request.nas_addr,
                      self.request.acct_session_id,
                      async=True)
         return logger.error(u'收到用户:%s 记账更新请求,但用户资料不存在' %
                             self.request.account_number,
                             tag='radius_acct_update_error',
                             trace='radius',
                             username=self.request.account_number)
     ticket = Storage(**self.request)
     online = self.get_online(ticket.nas_addr, ticket.acct_session_id)
     if not online:
         sessiontime = ticket.acct_session_time
         updatetime = datetime.datetime.now()
         _starttime = updatetime - datetime.timedelta(seconds=sessiontime)
         online = Storage(
             account_number=self.account.account_number,
             nas_addr=ticket.nas_addr,
             acct_session_id=ticket.acct_session_id,
             acct_start_time=_starttime.strftime('%Y-%m-%d %H:%M:%S'),
             framed_ipaddr=ticket.framed_ipaddr or '',
             mac_addr=ticket.mac_addr or '',
             nas_port_id=ticket.nas_port_id or '',
             billing_times=ticket.acct_session_time,
             input_total=self.get_input_total(),
             output_total=self.get_output_total(),
             start_source=STATUS_TYPE_UPDATE)
         self.add_online(online)
     self.billing(online)
     logger.info(u'用户:%s 记账更新, 更新用户在线数据' % self.account.account_number,
                 trace='radius',
                 username=online.account_number)
Пример #3
0
 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
Пример #4
0
 def post(self):
     try:
         openid = self.session.get('mps_openid',
                                   os.environ.get('DEV_OPEN_ID'))
         customer = self.db.query(
             models.TrCustomer).filter_by(wechat_oid=openid).first()
         account = self.db.query(models.TrAccount).filter_by(
             customer_id=customer.customer_id).first()
         product = self.db.query(
             models.TrProduct).filter_by(id=account.product_id).first()
         fee_value = self.get_argument('fee_value', '')
         if not rules.is_rmb.valid(fee_value):
             return self.render('wxrecharge_order_form.html',
                                account=account,
                                product=product,
                                msg=u'金额校验错误',
                                **self.get_params())
         order_id = tools.gen_num_id(16)
         formdata = Storage({'order_attach': 'rechargeorder'})
         formdata['wxpay_body'] = u'套餐充值:%s' % product.product_name
         formdata['openid'] = openid
         formdata['order_id'] = order_id
         formdata['account_number'] = account.account_number
         formdata['product_id'] = account.product_id
         formdata['fee_value'] = fee_value
         formdata['accept_source'] = 'wechat'
         formdata['operate_desc'] = u'用户微信支付充值'
         self.paycache.set(order_wxpaycaache_key(order_id), formdata, 28800)
         self.redirect('/mps/wxorder/pay/%s' % order_id)
     except Exception as err:
         logger.exception(err, trace='wechat')
         self.render('error.html', msg=u'用户充值失败,请联系客服 %s' % repr(err))
Пример #5
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)
Пример #6
0
 def userReg(self, wsbody):
     formdata = Storage()
     formdata.node_id = self.get_ws_attr(wsbody, 'areaCode')
     formdata.area_id = self.get_ws_attr(wsbody, 'courtyardCode', defval='')
     formdata.customer_id = self.get_ws_attr(wsbody, 'userName', notnull=True)
     formdata.account_number = self.get_ws_attr(wsbody, 'userName', notnull=True)
     formdata.password = self.get_ws_attr(wsbody, 'password', notnull=True)
     formdata.realname = self.get_ws_attr(wsbody, 'realName')
     formdata.product_id = self.get_ws_attr(wsbody, 'productCode', notnull=True)
     formdata.expire_date = self.get_ws_attr(wsbody, 'authEndDate', notnull=True)
     formdata.address = self.get_ws_attr(wsbody, 'installAddress')
     formdata.ip_address = self.get_ws_attr(wsbody, 'ipAddress')
     formdata.mobile = self.get_ws_attr(wsbody, 'mobile')
     formdata.idcard = self.get_ws_attr(wsbody, 'idcard')
     formdata.fee_value = 0
     formdata.giftdays = 0
     formdata.giftflows = 0
     formdata.agency_id = None
     formdata.charge_code = None
     formdata.months = 0
     formdata.status = 1
     formdata.builder_name = None
     formdata.customer_desc = 'BOSS\xe5\xbc\x80\xe9\x80\x9a\xe8\xb4\xa6\xe5\x8f\xb7'
     account = self.db.query(models.TrAccount).get(formdata.account_number)
     if account:
         return self.send_wsresp('userReg', code=Codes.ERROR_ALREADY_EXIST, UserCode='', error=u'\u7528\u6237\u5df2\u7ecf\u5b58\u5728')
     else:
         cmanager = CustomerAdd(self.db, self.aes)
         ret = cmanager.add(formdata)
         if not ret:
             self.send_wsresp('userReg', code=Codes.ERROR_UNKNOWN, UserCode='', error=cmanager.last_error)
         else:
             self.send_wsresp('userReg', code=Codes.SUCCESS, UserCode=formdata.account_number.strip())
         return
Пример #7
0
 def acctounting(self):
     if self.is_online(self.request.nas_addr, self.request.acct_session_id):
         return logger.error(u'用户:%s 已经在线' % self.request.acct_session_id,
                             tag='radius_acct_start_error')
     if not self.account:
         dispatch.pub(UNLOCK_ONLINE_EVENT,
                      self.request.account_number,
                      self.request.nas_addr,
                      self.request.acct_session_id,
                      async=True)
         return logger.error(u'用户:%s 不存在' % self.request.account_number,
                             tag='radius_acct_start_error')
     online = Storage(account_number=self.request.account_number,
                      nas_addr=self.request.nas_addr,
                      acct_session_id=self.request.acct_session_id,
                      acct_start_time=datetime.datetime.now().strftime(
                          '%Y-%m-%d %H:%M:%S'),
                      framed_ipaddr=self.request.framed_ipaddr,
                      mac_addr=self.request.mac_addr or '',
                      nas_port_id=self.request.nas_port_id,
                      billing_times=0,
                      input_total=0,
                      output_total=0,
                      start_source=STATUS_TYPE_START)
     self.add_online(online)
     logger.info(u'用户:%s 记账开始, 新增在线用户数据' % online.account_number,
                 trace='radius',
                 username=online.account_number)
Пример #8
0
 def post(self):
     form = order_forms.vcard_charge_form()
     if not form.validates(source=self.get_params()):
         return self.render_json(code=1, msg=form.errors)
     account = self.db.query(models.TrAccount).get(
         form.d.account_number)
     if not account:
         return self.render_json(code=1, msg=u'账号不存在')
     try:
         order_id = utils.gen_order_id()
         formdata = Storage(form.d)
         formdata['order_id'] = order_id
         formdata['product_id'] = account.product_id
         formdata['fee_value'] = '0.00'
         formdata['accept_source'] = 'ssportal'
         formdata['operate_desc'] = u'用户自助充值卡充值'
         formdata['vcard_code'] = form.d.vcard_code
         formdata['vcard_pwd'] = form.d.vcard_pwd
         manager = AccountCharge(self.db, self.aes)
         ret = manager.charge(formdata)
         if ret:
             logger.info(u'充值卡充值成功')
             self.render_json(code=0, msg=u'充值卡充值成功')
         else:
             return self.render_json(code=1,
                                     msg=u'充值卡订单处理失败 %s' %
                                     manager.last_error)
     except Exception as err:
         logger.exception(err)
         return self.render_json(code=1, msg=u'无效的订单')
Пример #9
0
 def do_vcard(self, form, product):
     vcard_code = form.d.vcard_code
     vcard_pwd = form.d.vcard_pwd
     _feevalue, _expire = self.order_calc(form.d.product_id)
     order_id = utils.gen_order_id()
     formdata = Storage(form.d)
     formdata.order_id = order_id
     formdata['node_id'] = self.get_param_value('default_user_node_id', 1)
     formdata['area_id'] = ''
     formdata['fee_value'] = _feevalue
     formdata['expire_date'] = _expire
     formdata['accept_source'] = 'ssportal'
     formdata['giftdays'] = 0
     formdata['giftflows'] = 0
     formdata['ip_address'] = ''
     formdata['status'] = 1
     formdata['vcard_code'] = vcard_code
     formdata['vcard_pwd'] = vcard_pwd
     formdata['customer_desc'] = u'客户自助充值卡开户'
     formdata['product_name'] = product.product_name
     manager = CustomerAdd(self.db, self.aes)
     ret = manager.add(formdata)
     if ret:
         order = self.db.query(models.TrCustomerOrder).get(order_id)
         logger.info(u'充值卡开户成功')
         self.render('alipay_return.html', order=order)
     else:
         return self.render_error(code=1, msg=u'充值卡订单处理失败 %s' % manager.last_error)
Пример #10
0
 def post(self):
     try:
         product_id = self.get_argument('product_id', '')
         product = self.db.query(models.TrProduct).get(product_id)
         if not product:
             return self.render('neworder_form.html', form=form, msg=u'套餐不存在')
         form = order_forms.order_form(product.product_policy)
         if not form.validates(source=self.get_params()):
             return self.render('neworder_form.html', form=form, msg=form.errors)
         account_count = self.db.query(models.TrCustomer).filter_by(email=form.d.email).count()
         if account_count > 0:
             return self.render('neworder_form.html', form=form, msg=u'电子邮件已经存在')
         if form.d.vcard_code and form.d.vcard_pwd:
             return self.do_vcard(form, product)
         _feevalue, _expire = self.order_calc(form.d.product_id)
         order_id = utils.gen_order_id()
         formdata = Storage(form.d)
         formdata.order_id = order_id
         formdata['node_id'] = self.get_param_value('default_user_node_id', 1)
         formdata['area_id'] = ''
         formdata['fee_value'] = _feevalue
         formdata['expire_date'] = _expire
         formdata['accept_source'] = 'ssportal'
         formdata['giftdays'] = 0
         formdata['giftflows'] = 0
         formdata['ip_address'] = ''
         formdata['status'] = 1
         formdata['customer_desc'] = u'客户自助开户'
         formdata['product_name'] = product.product_name
         self.paycache.set(order_paycaache_key(order_id), formdata)
         return self.render('order_alipay.html', formdata=formdata)
     except Exception as err:
         logger.exception(err)
         return self.render('neworder_form.html', form=form, msg=u'无效的订单')
Пример #11
0
 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
Пример #12
0
 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
Пример #13
0
 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
Пример #14
0
 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
Пример #15
0
    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)))
Пример #16
0
 def userModify(self, wsbody):
     formdata = Storage()
     formdata.customer_id = self.get_ws_attr(wsbody, 'userCode')
     formdata.realname = self.get_ws_attr(wsbody, 'realName')
     formdata.install_address = self.get_ws_attr(wsbody, 'installAddress')
     formdata.ip_address = self.get_ws_attr(wsbody, 'ipAddress')
     formdata.mobile = self.get_ws_attr(wsbody, 'mobile')
     formdata.idcard = self.get_ws_attr(wsbody, 'idcard')
     account = self.db.query(models.TrAccount).filter_by(
         customer_id=formdata.customer_id).first()
     if not account:
         return self.send_wsresp('userModify',
                                 code=Codes.ERROR_NOT_EXIST,
                                 error=u'用户不存在')
     formdata.account_number = account.account_number
     formdata.user_concur_number = account.user_concur_number
     formdata.bind_vlan = account.bind_vlan
     formdata.bind_mac = account.bind_mac
     formdata.account_desc = account.account_desc
     customer = self.db.query(models.TrCustomer).get(formdata.customer_id)
     customer.realname = formdata.realname
     customer.address = formdata.install_address
     customer.mobile = formdata.mobile
     customer.idcard = formdata.idcard
     manager = AccountService(self.db, self.aes)
     ret = manager.update(formdata)
     if not ret:
         self.send_wsresp('userModify',
                          code=Codes.ERROR_UNKNOWN,
                          error=manager.last_error)
     else:
         self.send_wsresp('userModify', code=Codes.SUCCESS)
Пример #17
0
 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
Пример #18
0
    def warp(self, mdl):
        if not hasattr(mdl, '__table__'):
            return
        data = Storage()
        for c in mdl.__table__.columns:
            data[c.name] = getattr(mdl, c.name)

        return data
Пример #19
0
 def dataReceived(self, msgid, request):
     if 'HASYNC_DISABLE' in os.environ:
         return
     try:
         message = msgpack.unpackb(request)
         self.que.appendleft([msgid, Storage(message)])
     except:
         logger.error(traceback.print_exc())
Пример #20
0
 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
Пример #21
0
 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
Пример #22
0
        def fetch_result():
            domain_code = self.db.query(
                models.TrDomainAp.domain_code).filter_by(ssid=ssid).scalar()
            tpl_name = self.db.query(models.TrDomain.tpl_name).filter_by(
                domain_code=domain_code).scalar()
            tpl_name = tpl_name or 'default'
            print ssid, domain_code
            tplattrs = Storage(tpl_path=tpl_name,
                               ssid=ssid,
                               domain=domain_code)
            dmattrs = self.db.query(
                models.TrDomainAttr).filter_by(domain_code=domain_code)
            for dattr in dmattrs:
                tplattrs[dattr.attr_name] = dattr.attr_value

            return tplattrs
Пример #23
0
 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
Пример #24
0
 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
Пример #25
0
 def insertProduct(self, wsbody):
     formdata = Storage()
     formdata.product_id = self.get_ws_attr(wsbody,
                                            'productCode',
                                            notnull=True)
     formdata.product_name = self.get_ws_attr(wsbody,
                                              'productName',
                                              notnull=True)
     formdata.bind_mac = self.get_ws_attr(wsbody, 'bindMac', defval=0)
     formdata.bind_vlan = self.get_ws_attr(wsbody, 'bindVlan', defval=0)
     formdata.concur_number = self.get_ws_attr(wsbody,
                                               'concurNumber',
                                               defval=0)
     formdata.bandwidthCode = self.get_ws_attr(wsbody,
                                               'bandwidthCode',
                                               defval='')
     formdata.input_max_limit = utils.bb2mb(
         self.get_ws_attr(wsbody, 'inputMaxLimit', defval=0))
     formdata.output_max_limit = utils.bb2mb(
         self.get_ws_attr(wsbody, 'outputMaxLimit', defval=0))
     formdata.fee_months = self.get_ws_attr(wsbody, 'feeNum', defval=0)
     formdata.fee_price = self.get_ws_attr(wsbody, 'feePrice', defval=0)
     formdata.product_policy = BOMonth
     formdata.fee_times = 0
     formdata.fee_flows = 0
     formdata.product_charges = None
     formdata.free_auth = 0
     formdata.free_auth_uprate = 0
     formdata.free_auth_downrate = 0
     pkg = self.db.query(models.TrProduct).get(formdata.product_id)
     if pkg:
         return self.send_wsresp('insertProduct',
                                 code=Codes.ERROR_ALREADY_EXIST,
                                 error=u'套餐已经存在')
     else:
         manager = ProductService(self.db, self.aes)
         ret = manager.add(formdata)
         if not ret:
             self.send_wsresp('insertProduct',
                              code=Codes.ERROR_UNKNOWN,
                              error=manager.last_error)
         else:
             self.send_wsresp('insertProduct', code=Codes.SUCCESS)
         return
Пример #26
0
 def updateArea(self, wsbody):
     formdata = Storage()
     formdata.id = self.get_ws_attr(wsbody, 'areaCode', notnull=True)
     formdata.node_name = self.get_ws_attr(wsbody, 'areaName', notnull=True)
     formdata.node_desc = u'BOSS 接入区域'
     formdata.rule_id = 0
     node = self.db.query(models.TrNode).get(formdata.id)
     if not node:
         return self.send_wsresp('updateArea',
                                 code=Codes.ERROR_ALREADY_EXIST,
                                 error=u'区域不存在')
     manager = NodeService(self.db, self.aes)
     ret = manager.update(formdata)
     if not ret:
         self.send_wsresp('updateArea',
                          code=Codes.ERROR_UNKNOWN,
                          error=manager.last_error)
     else:
         self.send_wsresp('updateArea', code=Codes.SUCCESS)
Пример #27
0
 def userPasswordUpdate(self, wsbody):
     formdata = Storage()
     formdata.customer_id = self.get_ws_attr(wsbody, 'userCode')
     formdata.password = self.get_ws_attr(wsbody, 'password')
     account = self.db.query(models.TrAccount).filter_by(
         customer_id=formdata.customer_id).first()
     if not account:
         return self.send_wsresp('userPasswordUpdate',
                                 code=Codes.ERROR_NOT_EXIST,
                                 error=u'用户不存在')
     formdata.account_number = account.account_number
     manager = AccountService(self.db, self.aes)
     ret = manager.password(formdata)
     if not ret:
         self.send_wsresp('userPasswordUpdate',
                          code=Codes.ERROR_UNKNOWN,
                          error=manager.last_error)
     else:
         self.send_wsresp('userPasswordUpdate', code=Codes.SUCCESS)
Пример #28
0
 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
Пример #29
0
 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)
Пример #30
0
 def userProductModify(self, wsbody):
     customer_id = self.get_ws_attr(wsbody, 'userCode', notnull=True)
     account = self.db.query(models.TrAccount).filter_by(customer_id=customer_id).first()
     if not account:
         return self.send_wsresp('userReg', code=Codes.ERROR_NOT_EXIST, error=u'\u7528\u6237\u4e0d\u5b58\u5728')
     formdata = Storage()
     formdata.account_number = account.account_number
     formdata.product_id = self.get_ws_attr(wsbody, 'productCode', notnull=True)
     formdata.add_value = 0
     formdata.expire_date = account.expire_date
     formdata.balance = 0
     formdata.time_length = 0
     formdata.flow_length = 0
     formdata.operate_desc = u'SOAPAPI userProductModify'
     manager = AccountChange(self.db, self.aes)
     if not manager.change(formdata):
         self.send_wsresp('userProductModify', code=Codes.ERROR_UNKNOWN, error=manager.last_error)
     else:
         self.send_wsresp('userProductModify', code=Codes.SUCCESS)