Exemplo n.º 1
0
def opr_add_update(db, render):
    nodes = [(n.node_name, n.node_desc) for n in db.query(models.SlcNode)]
    form = opr_forms.opr_update_form(nodes)
    if not form.validates(source=request.forms):
        rules = db.query(models.SlcOperatorRule.rule_path).filter_by(
            operator_name=opr.operator_name)
        rules = [r[0] for r in rules]
        return render("sys_opr_form", form=form, rules=rules)
    opr = db.query(models.SlcOperator).get(form.d.id)

    if form.d.operator_pass:
        opr.operator_pass = md5(form.d.operator_pass).hexdigest()
    opr.operator_desc = form.d.operator_desc
    opr.operator_status = form.d.operator_status

    db.query(models.SlcOperatorNodes).filter_by(
        operator_name=opr.operator_name).delete()
    for node in request.params.getall("operator_nodes"):
        onode = models.SlcOperatorNodes()
        onode.operator_name = form.d.operator_name
        onode.node_name = node
        db.add(onode)

    db.query(models.SlcOperatorProducts).filter_by(
        operator_name=opr.operator_name).delete()
    for product_id in request.params.getall("operator_products"):
        oproduct = models.SlcOperatorProducts()
        oproduct.operator_name = form.d.operator_name
        oproduct.product_id = product_id
        db.add(oproduct)

    # update rules
    db.query(models.SlcOperatorRule).filter_by(
        operator_name=opr.operator_name).delete()

    for path in request.params.getall("rule_item"):
        item = permit.get_route(path)
        if not item: continue
        rule = models.SlcOperatorRule()
        rule.operator_name = opr.operator_name
        rule.rule_name = item['name']
        rule.rule_path = item['path']
        rule.rule_category = item['category']
        db.add(rule)

    permit.unbind_opr(opr.operator_name)
    for rule in db.query(
            models.SlcOperatorRule).filter_by(operator_name=opr.operator_name):
        permit.bind_opr(rule.operator_name, rule.rule_path)

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改操作员信息:%s' % (get_cookie("username"),
                                                   opr.operator_name)
    db.add(ops_log)

    db.commit()
    redirect("/opr")
Exemplo n.º 2
0
def product_add_post(db, render):
    form = product_forms.product_add_form()
    if not form.validates(source=request.forms):
        return render("sys_product_form", form=form)
    product = models.SlcRadProduct()
    product.product_name = form.d.product_name
    product.product_policy = form.d.product_policy
    product.product_status = form.d.product_status
    product.fee_months = int(form.d.get("fee_months", 0))
    product.fee_times = utils.hour2sec(form.d.get("fee_times", 0))
    product.fee_flows = utils.mb2kb(form.d.get("fee_flows", 0))
    product.bind_mac = form.d.bind_mac
    product.bind_vlan = form.d.bind_vlan
    product.concur_number = form.d.concur_number
    product.fee_period = form.d.fee_period
    product.fee_price = utils.yuan2fen(form.d.fee_price)
    product.input_max_limit = utils.mbps2bps(form.d.input_max_limit)
    product.output_max_limit = utils.mbps2bps(form.d.output_max_limit)
    _datetime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    product.create_time = _datetime
    product.update_time = _datetime
    db.add(product)

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)新增资费信息:%s' % (get_cookie("username"),
                                                  product.product_name)
    db.add(ops_log)

    db.commit()
    redirect(__prefix__)
Exemplo n.º 3
0
def param_update(db):
    params = db.query(models.SlcParam)
    for param in params:
        if param.param_name in request.forms:
            _value = request.forms.get(param.param_name)
            if _value:
                param.param_value = _value

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改参数' % (get_cookie("username"))
    db.add(ops_log)
    db.commit()

    websock.reconnect(
        request.forms.get('radiusd_address'),
        request.forms.get('radiusd_admin_port'),
    )

    is_debug = request.forms.get('is_debug')
    bottle.debug(is_debug == '1')

    websock.update_cache("is_debug", is_debug=is_debug)
    websock.update_cache("reject_delay",
                         reject_delay=request.forms.get('reject_delay'))
    websock.update_cache("param")
    redirect("/param")
Exemplo n.º 4
0
def account_delete(db, render):
    account_number = request.params.get("account_number")
    if not account_number:
        raise abort(404, 'account_number is empty')
    account = db.query(models.SlcRadAccount).get(account_number)
    member_id = account.member_id

    db.query(models.SlcRadAcceptLog).filter_by(account_number=account.account_number).delete()
    db.query(models.SlcRadAccountAttr).filter_by(account_number=account.account_number).delete()
    db.query(models.SlcRadBilling).filter_by(account_number=account.account_number).delete()
    db.query(models.SlcRadTicket).filter_by(account_number=account.account_number).delete()
    db.query(models.SlcRadOnline).filter_by(account_number=account.account_number).delete()
    db.query(models.SlcRechargeLog).filter_by(account_number=account.account_number).delete()
    db.query(models.SlcRadAccount).filter_by(account_number=account.account_number).delete()
    db.query(models.SlcMemberOrder).filter_by(account_number=account.account_number).delete()

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)删除用户账号%s' % (get_cookie("username"), account_number)
    db.add(ops_log)

    db.commit()
    return redirect("/member")
Exemplo n.º 5
0
def product_update(db, render):
    form = product_forms.product_update_form()
    if not form.validates(source=request.forms):
        return render("sys_product_form", form=form)
    product = db.query(models.SlcRadProduct).get(form.d.id)
    product.product_name = form.d.product_name
    product.product_status = form.d.product_status
    product.fee_months = int(form.d.get("fee_months", 0))
    product.fee_times = utils.hour2sec(form.d.get("fee_times", 0))
    product.fee_flows = utils.mb2kb(form.d.get("fee_flows", 0))
    product.bind_mac = form.d.bind_mac
    product.bind_vlan = form.d.bind_vlan
    product.concur_number = form.d.concur_number
    product.fee_period = form.d.fee_period
    product.fee_price = utils.yuan2fen(form.d.fee_price)
    product.input_max_limit = utils.mbps2bps(form.d.input_max_limit)
    product.output_max_limit = utils.mbps2bps(form.d.output_max_limit)
    product.update_time = utils.get_currtime()

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改资费信息:%s' % (get_cookie("username"),
                                                  product.product_name)
    db.add(ops_log)

    db.commit()
    websock.update_cache("product", product_id=product.id)
    redirect(__prefix__)
Exemplo n.º 6
0
def account_update_post(db, render):
    form = account_forms.account_update_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)

    account = db.query(models.SlcRadAccount).get(form.d.account_number)
    account.ip_address = form.d.ip_address
    account.install_address = form.d.install_address
    account.user_concur_number = form.d.user_concur_number
    account.bind_mac = form.d.bind_mac
    account.bind_vlan = form.d.bind_vlan
    account.account_desc = form.d.account_desc
    if form.d.new_password:
        account.password = utils.encrypt(form.d.new_password)

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改上网账号信息:%s' % (get_cookie("username"), account.account_number)
    db.add(ops_log)

    db.commit()
    websock.update_cache("account", account_number=account.account_number)
    redirect(member_detail_url_formatter(account.account_number))
Exemplo n.º 7
0
def member_update_post(db, render):
    nodes = [(n.id, n.node_name) for n in get_opr_nodes(db)]
    form = member_forms.member_update_form(nodes)
    if not form.validates(source=request.forms):
        return render("base_form", form=form)

    member = db.query(models.SlcMember).get(form.d.member_id)
    member.realname = form.d.realname
    if form.d.new_password:
        member.password = md5(form.d.new_password.encode()).hexdigest()
    member.email = form.d.email
    member.idcard = form.d.idcard
    member.mobile = form.d.mobile
    member.address = form.d.address
    member.member_desc = form.d.member_desc

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改用户信息:%s' % (get_cookie("username"),
                                                  member.member_name)
    db.add(ops_log)

    db.commit()
    redirect(member_detail_url_formatter(form.d.account_number))
Exemplo n.º 8
0
def admin_login_post(db):
    uname = request.forms.get("username")
    upass = request.forms.get("password")
    if not uname: return dict(code=1, msg=u"请填写用户名")
    if not upass: return dict(code=1, msg=u"请填写密码")
    enpasswd = md5(upass.encode()).hexdigest()
    opr = db.query(models.SlcOperator).filter_by(
        operator_name=uname, operator_pass=enpasswd).first()
    if not opr: return dict(code=1, msg=u"用户名密码不符")
    if opr.operator_status == 1: return dict(code=1, msg=u"该操作员账号已被停用")
    set_cookie('username', uname)
    set_cookie('opr_type', opr.operator_type)
    set_cookie('login_time', utils.get_currtime())
    set_cookie('login_ip', request.remote_addr)

    if opr.operator_type > 0:
        permit.unbind_opr(uname)
        for rule in db.query(
                models.SlcOperatorRule).filter_by(operator_name=uname):
            permit.bind_opr(rule.operator_name, rule.rule_path)

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = uname
    ops_log.operate_ip = request.remote_addr
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)登陆' % (uname, )
    db.add(ops_log)
    db.commit()

    return dict(code=0, msg="ok")
Exemplo n.º 9
0
def opr_add_post(db, render):
    nodes = [(n.node_name, n.node_desc) for n in db.query(models.SlcNode)]
    products = [(p.id, p.product_name) for p in db.query(models.SlcRadProduct)]
    form = opr_forms.opr_add_form(nodes, products)
    if not form.validates(source=request.forms):
        return render("sys_opr_form", form=form, rules=[])
    if db.query(models.SlcOperator.id).filter_by(
            operator_name=form.d.operator_name).count() > 0:
        return render("sys_opr_form", form=form, rules=[], msg=u"操作员已经存在")

    opr = models.SlcOperator()
    opr.operator_name = form.d.operator_name
    opr.operator_type = 1
    opr.operator_pass = md5(form.d.operator_pass).hexdigest()
    opr.operator_desc = form.d.operator_desc
    opr.operator_status = form.d.operator_status
    db.add(opr)

    for node in request.params.getall("operator_nodes"):
        onode = models.SlcOperatorNodes()
        onode.operator_name = form.d.operator_name
        onode.node_name = node
        db.add(onode)

    for product_id in request.params.getall("operator_products"):
        oproduct = models.SlcOperatorProducts()
        oproduct.operator_name = form.d.operator_name
        oproduct.product_id = product_id
        db.add(oproduct)

    for path in request.params.getall("rule_item"):
        item = permit.get_route(path)
        if not item: continue
        rule = models.SlcOperatorRule()
        rule.operator_name = opr.operator_name
        rule.rule_name = item['name']
        rule.rule_path = item['path']
        rule.rule_category = item['category']
        db.add(rule)

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)新增操作员信息:%s' % (get_cookie("username"),
                                                   opr.operator_name)
    db.add(ops_log)

    db.commit()
    redirect("/opr")
Exemplo n.º 10
0
def admin_logout(db):
    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)登出' % (get_cookie("username"), )
    db.add(ops_log)
    db.commit()
    if get_cookie('opt_type') > 0:
        permit.unbind_opr(get_cookie("username"))
    set_cookie('username', None)
    set_cookie('login_time', None)
    set_cookie('opr_type', None)
    set_cookie('login_ip', None)
    request.cookies.clear()
    redirect('/login')
Exemplo n.º 11
0
def card_recycle(db, render):
    card_id = request.params.get("card_id")
    if not card_id:
        return dict(code=0, msg=u"非法的访问")
    card = db.query(models.SlcRechargerCard).get(card_id)
    if not card:
        return dict(code=0, msg=u"充值卡不存在")
    card.card_status = 3
    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)回收充值卡[%s]' % (get_cookie("username"),
                                                  card.card_number)
    db.add(ops_log)
    db.commit()
    return dict(code=0, msg=u"回收成功,充值卡已不可使用")
Exemplo n.º 12
0
def product_attr_update(db, render):
    attr_id = request.params.get("attr_id")
    attr = db.query(models.SlcRadProductAttr).get(attr_id)
    product_id = attr.product_id
    db.query(models.SlcRadProductAttr).filter_by(id=attr_id).delete()

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)删除资费属性信息:%s' % (get_cookie("username"),
                                                    serial_json(attr))
    db.add(ops_log)

    db.commit()
    websock.update_cache("product", product_id=product_id)
    redirect("%s/detail?product_id=%s" % (__prefix__, product_id))
Exemplo n.º 13
0
def user_release(db, render):
    account_number = request.params.get('account_number')
    user = db.query(
        models.SlcRadAccount).filter_by(account_number=account_number).first()
    user.mac_addr = ''
    user.vlan_id = 0
    user.vlan_id2 = 0

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'释放用户账号(%s)绑定信息' % (account_number, )
    db.add(ops_log)

    db.commit()
    websock.update_cache("account", account_number=account_number)
    return dict(code=0, msg=u"解绑成功")
Exemplo n.º 14
0
def node_add_update(db):
    form = forms.node_update_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)
    node = db.query(models.SlcNode).get(form.d.id)
    node.node_name = form.d.node_name
    node.node_desc = form.d.node_desc

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改区域信息:%s' % (get_cookie("username"),
                                                  node.node_name)
    db.add(ops_log)

    db.commit()
    redirect("/node")
Exemplo n.º 15
0
def product_attr_update(db, render):
    form = product_forms.product_attr_update_form()
    if not form.validates(source=request.forms):
        return render("pattr_form", form=form, pattrs=radius_attrs)
    attr = db.query(models.SlcRadProductAttr).get(form.d.id)
    attr.attr_name = form.d.attr_name
    attr.attr_value = form.d.attr_value
    attr.attr_desc = form.d.attr_desc

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改资费属性信息:%s' % (get_cookie("username"),
                                                    attr.attr_name)
    db.add(ops_log)

    db.commit()
    websock.update_cache("product", product_id=form.d.product_id)
    redirect("%s/detail?product_id=%s" % (__prefix__, form.d.product_id))
Exemplo n.º 16
0
def product_delete(db):
    product_id = request.params.get("product_id")
    if db.query(models.SlcRadAccount).filter_by(product_id=product_id).count() > 0:
        return render("error", msg=u"该套餐有用户使用,不允许删除")
    if db.query(models.SlcRechargerCard).filter_by(product_id=product_id).count() > 0:
        return render("error", msg=u"该套餐有发行充值卡,不允许删除")

    db.query(models.SlcRadProduct).filter_by(id=product_id).delete()

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)删除资费信息:%s' % (
        get_cookie("username"), product_id)
    db.add(ops_log)

    db.commit()
    websock.update_cache("product", product_id=product_id)
    redirect(__prefix__)
Exemplo n.º 17
0
def param_update(db, render):
    params = db.query(models.SlcParam)
    active = request.params.get("active", "syscfg")
    for param_name in request.forms:
        if param_name in ("active", "submit"):
            continue

        param = db.query(
            models.SlcParam).filter_by(param_name=param_name).first()
        if not param:
            param = models.SlcParam()
            param.param_name = param_name
            param.param_value = request.forms.get(param_name)
            db.add(param)
        else:
            param.param_value = request.forms.get(param_name)

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改参数' % (get_cookie("username"))
    db.add(ops_log)
    db.commit()

    if "radiusd_address" in request.forms:
        websock.reconnect(
            request.forms.get('radiusd_address'),
            request.forms.get('radiusd_admin_port'),
        )

    if "is_debug" in request.forms:
        is_debug = request.forms.get('is_debug')
        bottle.debug(is_debug == '1')
        websock.update_cache("is_debug", is_debug=is_debug)
    if "reject_delay" in request.forms:
        websock.update_cache("reject_delay",
                             reject_delay=request.forms.get('reject_delay'))

    websock.update_cache("param")
    redirect("/param?active=%s" % active)