def post(self): form = bas_forms.bas_add_form() if not form.validates(source=self.get_params()): return self.render("base_form.html", form=form) if not any([form.d.ip_addr, form.d.dns_name]): return self.render("base_form.html", form=form, msg=u"ip地址或域名至少填写一项") if self.db.query( models.TrBas.id).filter_by(ip_addr=form.d.ip_addr).count() > 0: return self.render("base_form.html", form=form, msg=u"接入设备地址已经存在") bas = models.TrBas() bas.ip_addr = form.d.ip_addr bas.dns_name = form.d.dns_name bas.bas_name = form.d.bas_name bas.time_type = form.d.time_type bas.vendor_id = form.d.vendor_id bas.bas_secret = form.d.bas_secret bas.coa_port = form.d.coa_port self.db.add(bas) self.add_oplog(u'新增接入设备信息:%s' % bas.ip_addr) self.db.commit() self.redirect("/admin/bas", permanent=False)
except apiutils.SignError, err: return self.render_sign_err(err) except Exception as err: return self.render_parse_err(err) try: if not any([request.get('ip_addr'), request.get("dns_name")]): raise ValueError("ip_addr, dns_name required one") except Exception, err: return self.render_verify_err(err) try: if self.db.query(models.TrBas.id).filter_by( ip_addr=request.get("ip_addr")).count() > 0: return self.render_verify_err(msg=u"nas already exists") bas = models.TrBas() bas.ip_addr = request.get("ip_addr") bas.dns_name = request.get("dns_name") bas.bas_name = request.get("bas_name", "new bas") bas.time_type = request.get("time_type", 0) bas.vendor_id = request.get("vendor_id", 0) bas.bas_secret = request.get("bas_secret") bas.coa_port = request.get("coa_port", 3799) self.db.add(bas) self.db.commit() self.render_success() except Exception, err: return self.render_unknow(err)
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()