示例#1
0
文件: user.py 项目: pegasy/Titan
def ban_unauthenticated_user():
    guild_id = request.form.get("guild_id", None)
    user_id = request.form.get("user_id", None)
    reason = request.form.get("reason", None)
    if guild_id in list_disabled_guilds():
        return ('', 423)
    if reason is not None:
        reason = reason.strip()
        if reason == "":
            reason = None
    if not guild_id or not user_id:
        abort(400)
    if not check_user_permission(guild_id, 2):
        abort(401)
    db_user = db.session.query(UnauthenticatedUsers).filter(
        UnauthenticatedUsers.guild_id == guild_id,
        UnauthenticatedUsers.id == user_id).order_by(
            UnauthenticatedUsers.id.desc()).first()
    if db_user is None:
        abort(404)
    db_ban = db.session.query(UnauthenticatedBans).filter(
        UnauthenticatedBans.guild_id == guild_id,
        UnauthenticatedBans.ip_address == db_user.ip_address).first()
    if db_ban is not None:
        if db_ban.lifter_id is None:
            abort(409)
        db.session.delete(db_ban)
    db_ban = UnauthenticatedBans(guild_id, db_user.ip_address,
                                 db_user.username, db_user.discriminator,
                                 reason, session["user_id"])
    db.session.add(db_ban)
    return ('', 204)
示例#2
0
def post_disabled_guilds():
    guild_id = request.form.get("guild_id", None)
    if guild_id in list_disabled_guilds():
        abort(409)
    guild = DisabledGuilds(guild_id)
    db.session.add(guild)
    return ('', 204)
示例#3
0
文件: admin.py 项目: safrant/Titan
def delete_disabled_guilds():
    guild_id = request.form.get("guild_id", None)
    if guild_id not in list_disabled_guilds():
        abort(409)
    guild = db.session.query(DisabledGuilds).filter(DisabledGuilds.guild_id == guild_id).first()
    db.session.delete(guild)
    return ('', 204)
示例#4
0
def guild_embed(guild_id):
    if check_guild_existance(guild_id):
        guild = redisqueue.get_guild(guild_id)
        dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
        if not dbguild:
            abort(404)
        guild_dict = {
            "id": guild["id"],
            "name": guild["name"],
            "unauth_users": dbguild.unauth_users,
            "icon": guild["icon"],
            "invite_link": dbguild.invite_link,
            "invite_domain": parse_url_domain(dbguild.invite_link),
            "post_timeout": dbguild.post_timeout,
        }
        customcss = get_custom_css()
        return render_template("embed.html.j2",
            disabled=guild_id in list_disabled_guilds(),
            login_greeting=get_logingreeting(),
            guild_id=guild_id,
            guild=guild_dict,
            generate_guild_icon=generate_guild_icon_url,
            unauth_enabled=guild_query_unauth_users_bool(guild_id),
            visitors_enabled=guild_accepts_visitors(guild_id),
            unauth_captcha_enabled=guild_unauthcaptcha_enabled(guild_id),
            client_id=config['client-id'],
            recaptcha_site_key=config["recaptcha-site-key"],
            css=customcss,
            cssvariables=parse_css_variable(customcss),
            same_target=request.args.get("sametarget", False) == "true",
            userscalable=request.args.get("userscalable", "True").lower().startswith("t"),
            fixed_sidenav=request.args.get("fixedsidenav", "False").lower().startswith("t"),
            is_peak=is_peak(guild_id)
        )
    abort(404)
示例#5
0
 def decorated_function(*args, **kwargs):
     guild_id = request.args.get("guild_id", None)
     if not guild_id and len(args) > 0:
         guild_id = args[0]
     if guild_id in list_disabled_guilds():
         return ('', 423)
     return f(*args, **kwargs)
示例#6
0
def unban_unauthenticated_user():
    guild_id = request.args.get("guild_id", None)
    user_id = request.args.get("user_id", None)
    if guild_id in list_disabled_guilds():
        return ('', 423)
    if not guild_id or not user_id:
        abort(400)
    if not check_user_permission(guild_id, 2):
        abort(401)
    db_user = db.session.query(UnauthenticatedUsers).filter(
        UnauthenticatedUsers.guild_id == guild_id,
        UnauthenticatedUsers.id == user_id).order_by(
            UnauthenticatedUsers.id.desc()).first()
    if db_user is None:
        abort(404)
    db_ban = db.session.query(UnauthenticatedBans).filter(
        UnauthenticatedBans.guild_id == guild_id,
        UnauthenticatedBans.ip_address == db_user.ip_address).first()
    if db_ban is None:
        abort(404)
    if db_ban.lifter_id is not None:
        abort(409)
    db_ban.liftBan(session["user_id"])
    db.session.commit()
    return ('', 204)
示例#7
0
文件: user.py 项目: pegasy/Titan
def update_administrate_guild(guild_id):
    if guild_id in list_disabled_guilds():
        return ('', 423)
    if not check_user_can_administrate_guild(guild_id):
        abort(403)
    db_guild = db.session.query(Guilds).filter(
        Guilds.guild_id == guild_id).first()
    if not db_guild:
        abort(400)
    if not check_user_permission(guild_id, 5):
        abort(403)
    db_guild.unauth_users = request.form.get(
        "unauth_users", db_guild.unauth_users) in ["true", True]
    db_guild.visitor_view = request.form.get(
        "visitor_view", db_guild.visitor_view) in ["true", True]
    db_guild.webhook_messages = request.form.get(
        "webhook_messages", db_guild.webhook_messages) in ["true", True]
    db_guild.chat_links = request.form.get(
        "chat_links", db_guild.chat_links) in ["true", True]
    db_guild.bracket_links = request.form.get(
        "bracket_links", db_guild.bracket_links) in ["true", True]
    db_guild.mentions_limit = request.form.get("mentions_limit",
                                               db_guild.mentions_limit)
    db_guild.unauth_captcha = request.form.get(
        "unauth_captcha", db_guild.unauth_captcha) in ["true", True]

    invite_link = request.form.get("invite_link", db_guild.invite_link)
    if invite_link != None and invite_link.strip() == "":
        invite_link = None
    db_guild.invite_link = invite_link

    guest_icon = request.form.get("guest_icon", db_guild.guest_icon)
    if guest_icon != None and guest_icon.strip() == "":
        guest_icon = None
    db_guild.guest_icon = guest_icon

    emit("guest_icon_change", {
        "guest_icon":
        guest_icon if guest_icon else url_for(
            'static', filename='img/titanembeds_square.png')
    },
         room="GUILD_" + guild_id,
         namespace="/gateway")
    return jsonify(
        guild_id=db_guild.guild_id,
        unauth_users=db_guild.unauth_users,
        visitor_view=db_guild.visitor_view,
        webhook_messages=db_guild.webhook_messages,
        chat_links=db_guild.chat_links,
        bracket_links=db_guild.bracket_links,
        mentions_limit=db_guild.mentions_limit,
        invite_link=db_guild.invite_link,
        guest_icon=guest_icon,
        unauth_captcha=db_guild.unauth_captcha,
    )
示例#8
0
def administrate_guild(guild_id):
    if not check_user_can_administrate_guild(guild_id):
        return redirect(url_for("user.dashboard"))
    db_guild = db.session.query(Guilds).filter(
        Guilds.guild_id == guild_id).first()
    if not db_guild:
        session["redirect"] = url_for("user.administrate_guild",
                                      guild_id=guild_id,
                                      _external=True)
        return redirect(url_for("user.add_bot", guild_id=guild_id))
    session["redirect"] = None
    permissions = []
    if check_user_permission(guild_id, 5):
        permissions.append("Manage Embed Settings")
    if check_user_permission(guild_id, 2):
        permissions.append("Ban Members")
    if check_user_permission(guild_id, 1):
        permissions.append("Kick Members")
    cosmetics = db.session.query(Cosmetics).filter(
        Cosmetics.user_id == session['user_id']).first()
    all_members = db.session.query(UnauthenticatedUsers).filter(
        UnauthenticatedUsers.guild_id == guild_id).order_by(
            UnauthenticatedUsers.id).all()
    all_bans = db.session.query(UnauthenticatedBans).filter(
        UnauthenticatedBans.guild_id == guild_id).all()
    users = prepare_guild_members_list(all_members, all_bans)
    dbguild_dict = {
        "id": db_guild.guild_id,
        "name": db_guild.name,
        "unauth_users": db_guild.unauth_users,
        "visitor_view": db_guild.visitor_view,
        "webhook_messages": db_guild.webhook_messages,
        "chat_links": db_guild.chat_links,
        "bracket_links": db_guild.bracket_links,
        "mentions_limit": db_guild.mentions_limit,
        "unauth_captcha": db_guild.unauth_captcha,
        "icon": db_guild.icon,
        "invite_link":
        db_guild.invite_link if db_guild.invite_link != None else "",
        "guest_icon":
        db_guild.guest_icon if db_guild.guest_icon != None else "",
        "post_timeout": db_guild.post_timeout,
        "max_message_length": db_guild.max_message_length,
        "banned_words_enabled": db_guild.banned_words_enabled,
        "banned_words_global_included": db_guild.banned_words_global_included,
        "banned_words": json.loads(db_guild.banned_words),
    }
    return render_template("administrate_guild.html.j2",
                           guild=dbguild_dict,
                           members=users,
                           permissions=permissions,
                           cosmetics=cosmetics,
                           disabled=(guild_id in list_disabled_guilds()))
示例#9
0
def revoke_unauthenticated_user():
    guild_id = request.form.get("guild_id", None)
    user_id = request.form.get("user_id", None)
    if guild_id in list_disabled_guilds():
        return ('', 423)
    if not guild_id or not user_id:
        abort(400)
    if not check_user_permission(guild_id, 1):
        abort(401)
    db_user = db.session.query(UnauthenticatedUsers).filter(UnauthenticatedUsers.guild_id == guild_id, UnauthenticatedUsers.id == user_id).order_by(UnauthenticatedUsers.id.desc()).first()
    if db_user is None:
        abort(404)
    if db_user.isRevoked():
        abort(409)
    db_user.revokeUser()
    db.session.commit()
    return ('', 204)
示例#10
0
def get_disabled_guilds():
    return render_template("admin_disabled_guilds.html.j2",
                           guilds=list_disabled_guilds())
示例#11
0
def update_administrate_guild(guild_id):
    if guild_id in list_disabled_guilds():
        return ('', 423)
    if not check_user_can_administrate_guild(guild_id):
        abort(403)
    db_guild = db.session.query(Guilds).filter(
        Guilds.guild_id == guild_id).first()
    if not db_guild:
        abort(400)
    if not check_user_permission(guild_id, 5):
        abort(403)
    db_guild.unauth_users = request.form.get(
        "unauth_users", db_guild.unauth_users) in ["true", True]
    db_guild.visitor_view = request.form.get(
        "visitor_view", db_guild.visitor_view) in ["true", True]
    db_guild.webhook_messages = request.form.get(
        "webhook_messages", db_guild.webhook_messages) in ["true", True]
    db_guild.chat_links = request.form.get(
        "chat_links", db_guild.chat_links) in ["true", True]
    db_guild.bracket_links = request.form.get(
        "bracket_links", db_guild.bracket_links) in ["true", True]
    db_guild.mentions_limit = request.form.get("mentions_limit",
                                               db_guild.mentions_limit)
    db_guild.unauth_captcha = request.form.get(
        "unauth_captcha", db_guild.unauth_captcha) in ["true", True]
    db_guild.post_timeout = request.form.get("post_timeout",
                                             db_guild.post_timeout)
    db_guild.max_message_length = request.form.get("max_message_length",
                                                   db_guild.max_message_length)
    db_guild.banned_words_enabled = request.form.get(
        "banned_words_enabled",
        db_guild.banned_words_enabled) in ["true", True]
    db_guild.banned_words_global_included = request.form.get(
        "banned_words_global_included",
        db_guild.banned_words_global_included) in ["true", True]

    invite_link = request.form.get("invite_link", db_guild.invite_link)
    if invite_link != None and invite_link.strip() == "":
        invite_link = None
    db_guild.invite_link = invite_link

    guest_icon = request.form.get("guest_icon", db_guild.guest_icon)
    if guest_icon != None and guest_icon.strip() == "":
        guest_icon = None
    db_guild.guest_icon = guest_icon

    banned_word = request.form.get("banned_word", None)
    if banned_word:
        delete_banned_word = request.form.get("delete_banned_word",
                                              False) in ["true", True]
        banned_words = set(json.loads(db_guild.banned_words))
        if delete_banned_word:
            banned_words.discard(banned_word)
        else:
            banned_words.add(banned_word)
        db_guild.banned_words = json.dumps(list(banned_words))

    db.session.commit()
    emit("guest_icon_change", {
        "guest_icon":
        guest_icon if guest_icon else url_for(
            'static', filename='img/titanembeds_square.png')
    },
         room="GUILD_" + guild_id,
         namespace="/gateway")
    return jsonify(
        guild_id=db_guild.guild_id,
        unauth_users=db_guild.unauth_users,
        visitor_view=db_guild.visitor_view,
        webhook_messages=db_guild.webhook_messages,
        chat_links=db_guild.chat_links,
        bracket_links=db_guild.bracket_links,
        mentions_limit=db_guild.mentions_limit,
        invite_link=db_guild.invite_link,
        guest_icon=guest_icon,
        unauth_captcha=db_guild.unauth_captcha,
        post_timeout=db_guild.post_timeout,
        max_message_length=db_guild.max_message_length,
        banned_words_enabled=db_guild.banned_words_enabled,
        banned_words_global_included=db_guild.banned_words_global_included,
        banned_words=json.loads(db_guild.banned_words),
    )