def init_db(db): node = models.TrNode() node.id = 1 node.node_name = 'default' node.node_desc = u'测试区域' db.add(node) params = [ ('system_name', u'管理系统名称', u'ToughRADIUS管理控制台'), ('system_ticket_expire_days', u'上网日志保留天数', '90'), ('customer_system_name', u'自助服务系统名称', u'ToughRADIUS自助服务中心'), ('customer_system_url', u"自助服务系统地址", u"http://forum.toughradius.net"), ('is_debug', u'DEBUG模式', u'0'), ('customer_qrcode', u'微信公众号二维码图片(宽度230px)', u'http://img.toughradius.net/toughforum/jamiesun/1421820686.jpg!230'), ('customer_service_phone', u'客户服务电话', u'000000'), ('customer_service_qq', u'客户服务QQ号码', u'000000'), ('rcard_order_url', u'充值卡订购网站地址', u'http://www.tmall.com'), ('expire_notify_days', '到期提醒提前天数', u'7'), ('expire_notify_tpl', '到期提醒邮件模板', u'账号到期通知\n尊敬的会员您好:\n您的账号#account#即将在#expire#到期,请及时续费!'), ('expire_notify_url', u'到期通知url', u'http://your_notify_url?account={account}&expire={expire}&email={email}&mobile={mobile}' ), ('expire_addrpool', u'到期提醒下发地址池', u'expire'), ('expire_session_timeout', u'到期用户下发最大会话时长(秒)', u'120'), ('smtp_server', u'SMTP服务器地址', u'smtp.mailgun.org'), ('smtp_user', u'SMTP用户名', u'*****@*****.**'), ('smtp_pwd', u'SMTP密码', u'service2015'), ('smtp_sender', u'SMTP发送人名称', u'运营中心'), ('acct_interim_intelval', u'Radius记账间隔(秒)', u'120'), ('max_session_timeout', u'Radius最大会话时长(秒)', u'86400'), ('reject_delay', u'拒绝延迟时间(秒)(0-9)', '0') ] for p in params: param = models.TrParam() param.param_name = p[0] param.param_desc = p[1] param.param_value = p[2] db.add(param) opr = models.TrOperator() opr.id = 1 opr.operator_name = u'admin' opr.operator_type = 0 opr.operator_pass = md5('root').hexdigest() opr.operator_desc = 'admin' opr.operator_status = 0 db.add(opr) db.commit() db.close()
def post(self): nodes = [(n.node_name, n.node_desc) for n in self.db.query(models.TrNode)] products = [(p.id, p.product_name) for p in self.db.query(models.TrProduct)] form = operator_form.operator_add_form(nodes, products) if not form.validates(source=self.get_params()): return self.render("base_form.html", form=form) if self.db.query(models.TrOperator.id).filter_by( operator_name=form.d.operator_name).count() > 0: return self.render("base_form.html", form=form, msg=u"操作员已经存在") operator = models.TrOperator() operator.operator_name = form.d.operator_name operator.operator_pass = md5(form.d.operator_pass.encode()).hexdigest() operator.operator_type = 1 operator.operator_desc = form.d.operator_desc operator.operator_status = form.d.operator_status self.db.add(operator) self.add_oplog(u'新增操作员信息:%s' % utils.safeunicode(operator.operator_name)) for node in self.get_arguments("operator_nodes"): onode = models.TrOperatorNodes() onode.operator_name = form.d.operator_name onode.node_name = node self.db.add(onode) for product_id in self.get_arguments("operator_products"): oproduct = models.TrOperatorProducts() oproduct.operator_name = form.d.operator_name oproduct.product_id = product_id self.db.add(oproduct) for path in self.get_arguments("rule_item"): item = permit.get_route(path) if not item: continue rule = models.TrOperatorRule() rule.operator_name = operator.operator_name rule.rule_name = item['name'] rule.rule_path = item['path'] rule.rule_category = item['category'] self.db.add(rule) self.db.commit() for rule in self.db.query(models.TrOperatorRule).filter_by( operator_name=operator.operator_name): permit.bind_opr(rule.operator_name, rule.rule_path) self.redirect("/admin/operator", permanent=False)
def init_db(db): node = models.TrNode() node.id = 1 node.node_name = 'default' node.node_desc = u'默认区域' db.add(node) params = [ ('system_name', u'管理系统名称', u'ToughRADIUS管理控制台'), ('system_ticket_expire_days', u'上网日志保留天数', '90'), ('is_debug', u'DEBUG模式', u'0'), ('expire_notify_days', '到期提醒提前天数', u'7'), ('expire_notify_interval', '到期提醒提前间隔(分钟)', u'1440'), ('expire_notify_tpl', '到期提醒邮件模板', u'账号到期通知\n尊敬的会员您好:\n您的账号#account#即将在#expire#到期,请及时续费!'), ('expire_notify_url', u'到期通知url', u'http://your_notify_url?account={account}&expire={expire}&email={email}&mobile={mobile}' ), ('expire_addrpool', u'到期提醒下发地址池', u'expire'), ('expire_session_timeout', u'到期用户下发最大会话时长(秒)', u'120'), ('smtp_server', u'SMTP服务器地址', u'smtp.mailgun.org'), ('smtp_port', u'SMTP服务器端口', u'25'), ('smtp_user', u'SMTP用户名', u'*****@*****.**'), ('smtp_pwd', u'SMTP密码', u'service2015'), ('smtp_sender', u'SMTP发送人名称', u'运营中心'), ('smtp_from', u'SMTP邮件发送地址', u'*****@*****.**'), ('radius_bypass', u'Radius认证密码模式', u'0'), ('radius_acct_interim_intelval', u'Radius记账间隔(秒)', u'120'), ('radius_max_session_timeout', u'Radius最大会话时长(秒)', u'86400'), ('radius_auth_auto_unlock', u'并发自动解锁', '0') ] for p in params: param = models.TrParam() param.param_name = p[0] param.param_desc = p[1] param.param_value = p[2] db.add(param) opr = models.TrOperator() opr.id = 1 opr.operator_name = u'admin' opr.operator_type = 0 opr.operator_pass = md5('root').hexdigest() opr.operator_desc = 'admin' opr.operator_status = 0 db.add(opr) bas = models.TrBas() bas.ip_addr = '127.0.0.1' bas.vendor_id = '0' bas.bas_name = 'local bras' bas.bas_secret = 'secret' bas.coa_port = 3799 bas.time_type = 0 db.add(bas) free_product = models.TrProduct() free_product.id = FREE_FEE_PID free_product.product_name = u"自由资费" free_product.product_policy = FreeFee free_product.product_status = 0 free_product.fee_months = 0 free_product.fee_times = 0 free_product.fee_flows = 0 free_product.bind_mac = 0 free_product.bind_vlan = 0 free_product.concur_number = 0 free_product.fee_price = 0 free_product.fee_period = '' free_product.input_max_limit = 0 free_product.output_max_limit = 0 free_product.create_time = utils.get_currtime() free_product.update_time = utils.get_currtime() db.add(free_product) product = models.TrProduct() product.product_name = u"测试2M包月20元" product.product_policy = 0 product.product_status = 0 product.fee_months = 0 product.fee_times = 0 product.fee_flows = 0 product.bind_mac = 0 product.bind_vlan = 0 product.concur_number = 0 product.fee_price = 2000 product.fee_period = '' product.input_max_limit = 1048576 product.output_max_limit = 1048576 * 2 product.create_time = utils.get_currtime() product.update_time = utils.get_currtime() db.add(product) db.commit() db.close()