예제 #1
0
def add_plugin():
    # 添加模块
    referer = check_referer(request, url_for('submit_plugin_page'))
    if referer == True:
        name = request.form.get("name")
        src = request.form.get("src")
        callback = request.form.get("callback")
        columns = request.form.get("columns")
        url = request.form.get("url")
        commit = request.form.get("commit")
        # 判断name和callback的长度是否大于100
        if len(name) < 100 and len(callback) < 100:
            plugin = Plugins(name=name,
                             src=src,
                             callback=callback,
                             columns=columns,
                             url=url,
                             commit=commit)
            db.session.add(plugin)
            db.session.commit()
            return json_data(1, message="插件添加成功!", url=url_for('plugin_page'))
        else:
            return json_data(0, message="Name或Callback字段大于长度100!")
    else:
        return referer
예제 #2
0
def edit_plugin(pid):
    # 编辑插件
    referer = check_referer(request, url_for('plugins_detail', pid=pid))
    if referer == True:
        plugin = Plugins.query.filter(Plugins.pid == pid).first()
        # 判断是否存在该插件
        if plugin:
            name = request.form.get("name")
            src = request.form.get("src")
            callback = request.form.get("callback")
            columns = request.form.get("columns")
            url = request.form.get("url")
            commit = request.form.get("commit")
            # 判断name和callback的长度
            if len(name) < 100 and len(callback) < 100:
                plugin.name = name
                plugin.src = src
                plugin.callback = callback
                plugin.columns = columns
                plugin.url = url
                plugin.commit = commit
                db.session.commit()
                return json_data(1,
                                 message="插件编辑成功!",
                                 url=url_for('plugins_detail', pid=pid))
            else:
                return json_data(0, message="Name或Callback字段大于长度100!")
        else:
            return redirect(url_for('plugin_page'))
    else:
        return referer
예제 #3
0
def add_api():
    # 增加授权
    referer = check_referer(request, url_for('api_page'))
    if referer == True:
        host = request.form.get('host')
        # 判断是否是域名
        host_regex = r"^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})(:{0,1}[0-9]{0,5})+$"
        host_result = re.findall(host_regex, host)
        # 判断是否是IP
        ip_regex = r"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$"
        ip_result = re.findall(ip_regex, host)
        if host_result != [] or ip_result != []:
            apis = Apis.query.filter(Apis.host == host).first()
            if apis:
                return json_data(0, message="该授权已存在!")
            else:
                apis = Apis(host=host)
                db.session.add(apis)
                db.session.commit()
                return json_data(1,
                                 message="授权已添加成功!",
                                 url=url_for('api_page'))
        else:
            return json_data(0, message="这不是一个正确的域名或IP!")
    else:
        return referer
예제 #4
0
def locations():
    # 获取详细地址
    lat = request.form.get('lat')
    lng = request.form.get('lng')
    try:
        address = get_address(lat, lng, config.TX_KEY)
        return json_data(1, message=address)
    except:
        return json_data(0, message=None)
예제 #5
0
def get_country():
    ip = request.form.get('ip')
    if not is_internal_ip(ip):
        try:
            en, cn, city = check_ip2country(ip)
            if en != "China":
                return json_data(1, message=cn)
        except:
            return json_data(0, message="None")
    return json_data(
        1,
        message="<img src='{0}' style='height: 30px; width: 30px'>".format(
            url_for('static', filename='images/flags/china.png')))
예제 #6
0
def del_api(aid):
    # 删除授权
    referer = check_referer(request, url_for('api_page'))
    if referer == True:
        apis = Apis.query.filter(Apis.aid == aid).first()
        if apis:
            db.session.delete(apis)
            db.session.commit()
            return json_data(1, message="该授权已经删除!", url=url_for('api_page'))
        else:
            return json_data(0, message="该授权不存在!")
    else:
        return referer
예제 #7
0
def del_user(uid):
    # 删除用户
    referer = check_referer(request, url_for('setting_page'))
    if referer == True:
        user = Admin.query.filter(Admin.id == uid).first()
        if user:
            db.session.delete(user)
            db.session.commit()
            return json_data(1, message="用户删除成功!", url=url_for('setting_page'))
        else:
            return json_data(0, message="用户名不存在!")
    else:
        return referer
예제 #8
0
def mofidy_pwd():
    # 修改密码
    old_password = request.form.get('oldpassword')
    new_password = request.form.get('newpassword')
    # 查询
    admin = Admin.query.filter(Admin.id == g.user.id).first()
    # 判断old_password是否与原密码一致 and 判断old_password是否和new_password一致
    if admin.check_password(old_password) and (old_password != new_password):
        admin.password = generate_password(new_password)
        db.session.commit()
        session.clear()
        return json_data(1, message="密码修改成功,请重新登陆!", url=url_for("login_page"))
    else:
        return json_data(0, message="当前密码输入错误或当前密码与新密码相同!")
예제 #9
0
def login():
    # 登录
    username = request.form.get('username')
    password = request.form.get('password')
    admin = Admin.query.filter(Admin.username == username).first()
    if admin:
        if admin.check_password(password):
            session['user_id'] = admin.id
            session.permanent = True
            return json_data(1, "用户登陆成功!", url_for('index_page'))
        else:
            return json_data(0, "用户密码错误!")
    else:
        return json_data(0, "用户名不存在!")
예제 #10
0
def del_plugin(pid):
    # 删除模块
    referer = check_referer(request, url_for('plugin_page'))
    if referer == True:
        plugin = Plugins.query.filter(Plugins.pid == pid).first()
        # 判断是否存在该模块
        if plugin:
            db.session.delete(plugin)
            db.session.commit()
            return json_data(1, message="插件删除成功!", url=url_for('plugin_page'))
        else:
            return json_data(0, message="插件不存在!")
    else:
        return referer
예제 #11
0
def add_user():
    # 添加用户
    referer = check_referer(request, url_for('setting_page'))
    if referer == True:
        username = request.form.get('username')
        password = request.form.get('password')
        admin = Admin.query.filter(Admin.username == username).first()
        # username check
        if (not admin) and (len(username) < 20):
            user = Admin(username=username, password=password)
            db.session.add(user)
            db.session.commit()
            return json_data(1, message="用户创建成功!", url=url_for('setting_page'))
        else:
            return json_data(0, message="用户名已经存在或超出20长度!")
    else:
        return referer