예제 #1
0
def card_modify():
    args = utility.get_args(request)
    id = args.get('id', "")
    # card_type_id = args.get('card_type_id', "")
    # card_no = args.get('card_no', "")
    # password = args.get('password', "")
    remark = args.get('remark', "")
    is_enable = args.get('is_enable') == "1"

    card = None
    if admin_permission.can():
        card = Card.query.filter_by(id=id).first()
    else:
        card = db.session.query(Card).join(Card.admin).filter(
            or_(Admin.id == current_user.id,
                Admin.superior_id == current_user.id)).filter(
                    Card.id == id).first()
    if card is None:
        return "点卡不存在。"

    card.remark = remark
    card.is_enable = is_enable

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "修改点卡"
    operate_log.remark = "点卡:{},备注:{},启用:{}".format(card.card_no, card.remark,
                                                    card.is_enable)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "修改成功。"
예제 #2
0
def card_generate():
    args = utility.get_args(request)
    card_type_id = args.get('card_type_id', "")
    amount = args.get('amount', "")
    remark = args.get('remark', "")

    cardtype = db.session.query(CardType).join(CardType.software).join(
        Software.admins).filter(Admin.id == current_user.id).filter(
            CardType.id == card_type_id).first()
    if cardtype is None:
        return "卡类不存在。"

    for i in range(int(amount)):
        card = Card()
        card.admin_id = current_user.id
        card.card_type_id = card_type_id
        card.card_no = utility.get_uuid().replace("-", "")
        card.password = utility.get_uuid()[0:6]
        card.remark = remark
        card.is_used = False
        card.is_enable = True
        card.update_time = func.now()
        card.create_time = func.now()
        db.session.add(card)

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "生成点卡"
    operate_log.remark = "软件名称:{},数量:{}".format(cardtype.software.name, amount)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "生成成功!"
예제 #3
0
def setting_backup():
    result = ""

    __stdout = sys.stdout
    sys.stdout = io.StringIO()

    try:
        backup_db()
        result = sys.stdout.getvalue()
    except Exception as err:
        result = str(err)

    sys.stdout = __stdout


    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "备份数据"
    operate_log.remark = "备份内容:数据库"
    operate_log.create_time = datetime.now()
    db.session.add(operate_log)
    db.session.commit()

    return result
예제 #4
0
def cardtype_insert():
    args = utility.get_args(request)
    software_id = args.get('software_id', "")
    day = args.get('day', "")
    expired_day = args.get('expired_day', "")
    price = args.get('price', "")

    cardtype = CardType.query.filter_by(software_id=software_id,
                                        day=day,
                                        expired_day=expired_day).first()
    if cardtype != None:
        return "卡类已存在。"

    cardtype = CardType()
    cardtype.software_id = software_id
    cardtype.day = day
    cardtype.expired_day = expired_day
    cardtype.price = price
    cardtype.is_enable = True
    cardtype.update_time = func.now()
    cardtype.create_time = func.now()
    db.session.add(cardtype)
    db.session.commit()  #提交后才能获取name

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "添加卡类"
    operate_log.remark = "软件名称:{},点卡天数:{},过期天数:{},价格:{}".format(
        cardtype.software.name, day, expired_day, price)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "添加成功!"
예제 #5
0
def cardtype_modify():
    args = utility.get_args(request)
    id = args.get('id', "")
    software_id = args.get('software_id', "")
    day = args.get('day', "")
    expired_day = args.get('expired_day', "")
    price = args.get('price', "")
    is_enable = args.get('is_enable') == "1"

    cardtype = db.session.query(CardType).join(CardType.software).join(
        Software.admins).filter(Admin.id == current_user.id).filter(
            CardType.id == id).first()
    if cardtype is None:
        return "软件不存在。"

    cardtype.software_id = software_id
    cardtype.day = day
    cardtype.expired_day = expired_day
    cardtype.price = price
    cardtype.is_enable = is_enable

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "修改卡类"
    operate_log.remark = "软件名称:{},点卡天数:{},过期天数:{},价格:{},启用:{}".format(
        cardtype.software.name, day, expired_day, price, is_enable)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "修改成功。"
예제 #6
0
def user_modify():
    args = utility.get_args(request)
    id = args.get('id', "")
    software_name = args.get('software_name', "")
    user_name = args.get('user_name', "")
    password = args.get('password', "")
    password_question = args.get('password_question', "")
    password_answer = args.get('password_answer', "")
    qq = args.get('qq', "")
    email = args.get('email', "")
    phone = args.get('phone', "")
    version = args.get('version', "")
    serial_no = args.get('serial_no', "")
    token = args.get('token', "")
    client_count = args.get('client_count', "")
    is_bind = args.get('is_bind', "") == "1"
    remark = args.get('remark', "")
    unbind_date = args.get('unbind_date', "")
    terminate_date = args.get('terminate_date', "")
    is_enable = args.get('is_enable') == "1"

    user = db.session.query(User).join(User.software).join(
        Software.admins).filter(Admin.id == current_user.id).filter(
            User.id == id).first()
    if user is None:
        return "用户不存在。"

    # 调整客户端数量
    if client_count.isdigit(
    ) and client_count != 0 and user.client_count != int(
            client_count) and user.terminate_date > datetime.now():
        left_days = user.terminate_date - datetime.now()
        total_left_days = left_days * user.client_count
        new_left_days = total_left_days / int(client_count)
        # print(left_days)
        # print(total_left_days)
        # print(new_left_days)
        user.terminate_date = datetime.now() + new_left_days
        user.client_count = client_count

    user.qq = qq
    user.email = email
    user.phone = phone
    # user.version = version
    user.is_bind = is_bind
    user.remark = remark
    user.is_enable = is_enable

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "修改用户"
    operate_log.remark = "用户名:{},QQ:{},Email:{},手机:{},客户端限制:{},绑定机器:{},备注:{},启用:{}".format(
        user_name, qq, email, phone, client_count, is_bind, remark, is_enable)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "修改成功。"
예제 #7
0
def admin_insert():
    args = utility.get_args(request)
    user_name = args.get('user_name', "")
    password = args.get('password', "")
    software_names = request.form.getlist("software_names")  # dict会丢失数据
    role_name = args.get('role_name', "")

    if len(software_names) == 0:
        return "未授权软件。"

    softwares = db.session.query(Software).join(
        Software.admins).filter(Admin.id == current_user.id).filter(
            Software.name.in_(software_names)).all()
    if len(softwares) == 0:
        return "无权限添加"

    role = Role.query.filter_by(name=role_name).first()
    if role is None:
        return "身份不存在。"

    if not admin_permission.can():
        if role.id <= current_user.roles[0].id:
            return "无权限添加。"

    admin = Admin.query.filter_by(user_name=user_name).first()
    if admin != None:
        return "用户名已存在。"

    admin = Admin()
    admin.user_name = user_name
    admin.password = utility.get_md5(password)
    admin.superior_id = current_user.id
    admin.is_enable = True
    admin.update_time = func.now()
    admin.create_time = func.now()
    admin.roles.append(role)
    for software_name in software_names:
        software = Software.query.filter_by(name=software_name).first()
        if software is None:
            return "软件不存在。"
        admin.softwares.append(software)
    db.session.add(admin)

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "添加{}".format(role.description)
    operate_log.remark = "用户名:{},密码:{},授权软件:{}".format(
        user_name, password, "、".join(software_names))
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "添加成功!"
예제 #8
0
def software_insert():
    args = utility.get_args(request)
    name = args.get('name', "")
    register_hour = args.get('register_hour', "")
    unbind_hour = args.get('unbind_hour', "")
    wait_hour = args.get('wait_hour', "")
    client_count = args.get('client_count', "")
    is_bind = args.get('is_bind', "") == "1"
    message = args.get('message', "")
    script = args.get('script', "")
    version = args.get('version', "")
    new_version = args.get('new_version', "")
    new_url = args.get('new_url', "")

    software = Software.query.filter_by(name=name).first()
    if software != None:
        return "软件名已存在。"

    software = Software()
    software.name = name
    software.register_hour = register_hour
    software.unbind_hour = unbind_hour
    software.wait_hour = wait_hour
    software.client_count = client_count
    software.is_bind = is_bind
    software.message = message
    software.script = script
    software.version = version
    software.new_version = new_version
    software.new_url = new_url
    software.is_enable = True
    software.update_time = func.now()
    software.create_time = func.now()
    software.admins.append(current_user)
    db.session.add(software)

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "添加软件"
    operate_log.remark = "软件名称:{},注册赠送时间:{},解绑扣除时间:{},解绑冷却时间:{},客户端限制:{},绑定机器:{},版本号:{}".format(
        name, register_hour, unbind_hour, wait_hour, client_count, is_bind,
        version)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "添加成功!"
예제 #9
0
def software_modify():
    args = utility.get_args(request)
    id = args.get('id', "")
    name = args.get('name', "")
    register_hour = args.get('register_hour', "")
    unbind_hour = args.get('unbind_hour', "")
    wait_hour = args.get('wait_hour', "")
    client_count = args.get('client_count', "")
    is_bind = args.get('is_bind', "") == "1"
    message = args.get('message', "")
    script = args.get('script', "")
    version = args.get('version', "")
    new_version = args.get('new_version', "")
    new_url = args.get('new_url', "")
    is_enable = args.get('is_enable') == "1"

    software = db.session.query(Software).join(Software.admins).filter(
        Admin.id == current_user.id).filter(Software.id == id).first()
    if software is None:
        return "软件不存在。"

    software.name = name
    software.register_hour = register_hour
    software.unbind_hour = unbind_hour
    software.wait_hour = wait_hour
    software.client_count = client_count
    software.is_bind = is_bind
    software.message = message
    software.script = script
    software.version = version
    software.new_version = new_version
    software.new_url = new_url
    software.is_enable = is_enable

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "修改软件"
    operate_log.remark = "软件名称:{},注册赠送时间:{},解绑扣除时间:{},解绑冷却时间:{},客户端限制:{},绑定机器:{},登录版本:{},最新版本:{},下载网址:{},启用:{}".format(
        name, register_hour, unbind_hour, wait_hour, client_count, is_bind,
        version, new_version, new_url, is_enable)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "修改成功。"
예제 #10
0
def admin_modify():
    args = utility.get_args(request)
    id = args.get('id', "")
    user_name = args.get('user_name', "")
    software_names = request.form.getlist("software_names")  # dict会丢失数据
    role_name = args.get('role_name', "")
    is_enable = args.get('is_enable') == "1"

    if len(software_names) == 0:
        return "未授权软件。"

    admin = None
    if admin_permission.can():
        admin = Admin.query.filter_by(id=id).first()
    else:
        admin = db.session.query(Admin).filter(
            Admin.superior_id == current_user.id).first()

    if admin is None:
        return "管理员不存在。"

    admin.user_name = user_name
    admin.is_enable = is_enable
    admin.softwares = []
    for software_name in software_names:
        software = Software.query.filter_by(name=software_name).first()
        if software is None:
            return "软件不存在。"
        admin.softwares.append(software)

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "修改{}".format(admin.get_roles_names())
    operate_log.remark = "用户名:{},授权软件:{},启用:{}".format(
        user_name, "、".join(software_names), is_enable)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "修改成功。"
예제 #11
0
def login():
    if request.method == 'GET':
        return render_template('login.html')

    args = utility.get_args(request)
    user_name = args.get('user_name', "")
    password = args.get('password', "")

    admin = Admin.query.filter(
        Admin.user_name == user_name,
        Admin.password == utility.get_md5(password)).first()
    if admin is None:
        flash('用户名或密码错误。')
        return redirect(url_for('login'))
    elif not admin.is_enable:
        flash('账号已停用。')
        return redirect(url_for('login'))
    else:
        login_user(admin)

        # Tell Flask-Principal the identity changed
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(admin.id))

        # session["id"] = admin.id
        # session["user_name"] = admin.user_name
        # session["is_super"] = admin.is_super
        # session["permissions"] = admin.permissions
        # app.permanent_session_lifetime = timedelta(minutes=30)

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = admin.id
    operate_log.operate = "管理登陆"
    operate_log.remark = "IP:{}".format(request.remote_addr)
    operate_log.create_time = datetime.now()
    db.session.add(operate_log)
    db.session.commit()

    return redirect(url_for('index'))
예제 #12
0
def card_set_enable_batch():
    args = utility.get_args(request)
    card_list = args.get('card_list', "")
    is_enable = args.get('is_enable') == "1"

    result = ""
    card_nos = card_list.strip().split("\n")
    for card_no in card_nos:
        result += card_no

        card = None
        if admin_permission.can():
            card = Card.query.filter(Card.card_no == card_no).first()
        else:
            card = db.session.query(Card).join(Card.admin).filter(
                or_(Admin.id == current_user.id,
                    Admin.superior_id == current_user.id)).filter(
                        Card.card_no == card_no).first()

        if card is None:
            result += "(点卡不存在)"
        else:
            if card.is_used:
                result += "(点卡已使用)"
            else:
                card.is_enable = is_enable
                result += "(修改成功)"
        result += "\n"

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "批量操作点卡"
    operate_log.remark = "数量:{},启用:{}".format(len(card_nos), is_enable)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return result
예제 #13
0
def user_set_unbind():
    args = utility.get_args(request)
    user_name = args.get('user_name', "")

    user = db.session.query(User).join(User.software).join(
        Software.admins).filter(Admin.id == current_user.id).filter(
            User.user_name == user_name).first()
    if user is None:
        return "用户不存在。"

    user.serial_no = ""

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "解绑用户"
    operate_log.remark = "用户名:{}".format(user_name)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "修改成功。"
예제 #14
0
def user_set_terminate():
    args = utility.get_args(request)
    user_name = args.get('user_name', "")
    day = args.get('day', "")

    user = db.session.query(User).join(User.software).join(
        Software.admins).filter(Admin.id == current_user.id).filter(
            User.user_name == user_name).first()
    if user is None:
        return "用户不存在。"

    user.terminate_date = user.terminate_date + timedelta(days=int(day))

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "增减天数"
    operate_log.remark = "用户名:{},天数:{}".format(user_name, day)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "修改成功。"
예제 #15
0
def setting_modify():
    args = utility.get_args(request)
    domain = args.get('domain', "")
    ua_regex = args.get('ua_regex', "")
    des_key = args.get('des_key', "")
    is_encrypt = args.get('is_encrypt', "") == "1"
    is_offline = args.get('is_offline', "") == "1"

    utility.set_domain(domain)
    utility.set_ua_regex(ua_regex)
    utility.set_des_key(des_key)
    utility.set_is_encrypt(is_encrypt)
    utility.set_is_offline(is_offline)

    # 操作记录
    operate_log = OperateLog()
    operate_log.admin_id = current_user.id
    operate_log.operate = "修改秘钥"
    operate_log.remark = "域名:{},匹配:{},秘钥:{},加密:{},维护:{}".format(domain, ua_regex, des_key, is_encrypt, is_offline)
    operate_log.create_time = func.now()
    db.session.add(operate_log)
    db.session.commit()

    return "修改成功。"