示例#1
0
文件: __init__.py 项目: ki11e3/CTFd
def truncate_database():
    # delete all table data (but keep tables)
    _pages = Pages.query.all()
    for p in _pages:
        for f in p.files:
            delete_file(file_id=f.id)

    Pages.query.delete()

    Notifications.query.delete()

    _challenges = Challenges.query.all()
    for c in _challenges:
        for f in c.files:
            delete_file(file_id=f.id)
    Challenges.query.delete()

    Users.query.delete()
    Teams.query.delete()

    Solves.query.delete()
    Submissions.query.delete()
    Awards.query.delete()
    Unlocks.query.delete()
    Tracking.query.delete()

    Configs.query.delete()
    clear_config()
    clear_pages()
    clear_standings()
    cache.clear()

    db.session.commit()
示例#2
0
	def patch(self, config_key):
		config = Configs.query.filter_by(key=config_key).first()
		data = request.get_json()
		if config:
			schema = ConfigSchema(instance=config, partial=True)
			response = schema.load(data)
		else:
			schema = ConfigSchema()
			data['key'] = config_key
			response = schema.load(data)
			db.session.add(response.data)

		if response.errors:
			return response.errors, 400

		db.session.commit()

		response = schema.dump(response.data)
		db.session.close()

		clear_config()
		clear_standings()

		return {
			'success': True,
			'data': response.data
		}
示例#3
0
 def chat_notifier_admin():
     clear_config()
     if request.method == "POST":
         if request.form['notifier_type'] and request.form['notifier_type'] not in NOTIFIER_CLASSES.keys():
             abort(400)
         set_config('notifier_type', request.form['notifier_type'])
         set_config('notifier_send_notifications', 'notifier_send_notifications' in request.form)
         set_config('notifier_send_solves', 'notifier_send_solves' in request.form)
         set_config('notifier_solve_msg', request.form['notifier_solve_msg'])
         if request.form['notifier_solve_count']:
             set_config('notifier_solve_count', int(request.form['notifier_solve_count']))
         else:
             set_config('notifier_solve_count', None)
         for setting in get_all_notifier_settings():
             set_config(setting, request.form[setting])
         return redirect(url_for('chat_notifier.chat_notifier_admin'))
     else:
         context = {
             'nonce': session['nonce'],
             'supported_notifier_types': NOTIFIER_CLASSES.keys(),
             'notifier_type': get_config('notifier_type'),
             'notifier_send_notifications': get_config('notifier_send_notifications'),
             'notifier_send_solves': get_config('notifier_send_solves'),
             'notifier_solve_msg': get_config('notifier_solve_msg'),
             'notifier_solve_count': get_config('notifier_solve_count'),
         }
         for setting in get_all_notifier_settings():
             context[setting] = get_config(setting)
         supported_notifier_settings = {}
         for k,v in NOTIFIER_CLASSES.items():
             supported_notifier_settings[k] = Markup(render_template('chat_notifier/admin_notifier_settings/{}.html'.format(k), **context))
         context['supported_notifier_settings'] = supported_notifier_settings
         return render_template('chat_notifier/admin.html', **context)
示例#4
0
def reset():
    if request.method == "POST":
        require_setup = False
        logout = False
        next_url = url_for("admin.statistics")

        data = request.form

        if data.get("pages"):
            _pages = Pages.query.all()
            for p in _pages:
                for f in p.files:
                    delete_file(file_id=f.id)

            Pages.query.delete()

        if data.get("notifications"):
            Notifications.query.delete()

        if data.get("challenges"):
            _challenges = Challenges.query.all()
            for c in _challenges:
                for f in c.files:
                    delete_file(file_id=f.id)
            Challenges.query.delete()

        if data.get("accounts"):
            Users.query.delete()
            Teams.query.delete()
            require_setup = True
            logout = True

        if data.get("submissions"):
            Solves.query.delete()
            Submissions.query.delete()
            Awards.query.delete()
            Unlocks.query.delete()
            Tracking.query.delete()

        if require_setup:
            set_config("setup", False)
            cache.clear()
            logout_user()
            next_url = url_for("views.setup")

        db.session.commit()

        clear_pages()
        clear_standings()
        clear_config()

        if logout is True:
            cache.clear()
            logout_user()

        db.session.close()
        return redirect(next_url)

    return render_template("admin/reset.html")
示例#5
0
    def patch(self):
        req = request.get_json()

        for key, value in req.items():
            set_config(key=key, value=value)

        clear_config()
        clear_standings()

        return {"success": True}
示例#6
0
    def delete(self, config_key):
        config = Configs.query.filter_by(key=config_key).first_or_404()

        db.session.delete(config)
        db.session.commit()
        db.session.close()

        clear_config()
        clear_standings()

        return {"success": True}
示例#7
0
def config():
    # Clear the config cache so that we don't get stale values
    clear_config()

    configs = Configs.query.all()
    configs = dict([(c.key, get_config(c.key)) for c in configs])

    themes = ctf_config.get_themes()
    themes.remove(get_config("ctf_theme"))

    return render_template("admin/config.html", themes=themes, **configs)
示例#8
0
    def patch(self):
        req = request.get_json()
        schema = ConfigSchema()

        for key, value in req.items():
            response = schema.load({"key": key, "value": value})
            if response.errors:
                return {"success": False, "errors": response.errors}, 400
            set_config(key=key, value=value)

        clear_config()
        clear_standings()

        return {"success": True}
示例#9
0
def config():
    # Clear the config cache so that we don't get stale values
    clear_config()

    database_tables = sorted(db.metadata.tables.keys())

    configs = Configs.query.all()
    configs = dict([(c.key, get_config(c.key)) for c in configs])

    themes = ctf_config.get_themes()
    themes.remove(get_config('ctf_theme'))

    return render_template('admin/config.html',
                           database_tables=database_tables,
                           themes=themes,
                           **configs)
示例#10
0
def config():
    # Clear the config cache so that we don't get stale values
    clear_config()

    configs = Configs.query.all()
    configs = {c.key: get_config(c.key) for c in configs}

    themes = ctf_config.get_themes()

    # Remove current theme but ignore failure
    try:
        themes.remove(get_config("ctf_theme"))
    except ValueError:
        pass

    return render_template("admin/config.html", themes=themes, **configs)
示例#11
0
    def post(self):
        req = request.get_json()
        schema = ConfigSchema()
        response = schema.load(req)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        clear_config()
        clear_standings()

        return {"success": True, "data": response.data}
示例#12
0
    def patch(self):
        req = request.get_json()
        schema = ConfigSchema()

        for key, value in req.items():
            response = schema.load({"key": key, "value": value})
            if response.errors:
                # Inject config key into error
                config_key = response.data["key"]
                response.errors["value"][
                    0] = f"{config_key} config is too long"
                return {"success": False, "errors": response.errors}, 400
            set_config(key=key, value=value)

        clear_config()
        clear_standings()

        return {"success": True}
示例#13
0
def plugin(plugin):
    if request.method == 'GET':
        plugins_path = os.path.join(app.root_path, 'plugins')

        config_html_plugins = [name for name in os.listdir(plugins_path)
                               if os.path.isfile(os.path.join(plugins_path, name, 'config.html'))]

        if plugin in config_html_plugins:
            config_html = open(os.path.join(app.root_path, 'plugins', plugin, 'config.html')).read()
            return render_template_string(config_html)
        abort(404)
    elif request.method == 'POST':
        for k, v in request.form.items():
            if k == "nonce":
                continue
            set_config(k, v)
        with app.app_context():
            clear_config()
        return '1'
示例#14
0
    def post(self):
        req = request.get_json()
        schema = ConfigSchema()
        response = schema.load(req)

        if response.errors:
            # Inject config key into error
            config_key = response.data["key"]
            response.errors["value"][0] = f"{config_key} config is too long"
            return {"success": False, "errors": response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        clear_config()
        clear_standings()

        return {"success": True, "data": response.data}
            for y in range(random.randint(1, CHAL_AMOUNT * 20)):
                chalid = random.randint(1, CHAL_AMOUNT)
                if chalid not in used:
                    used.append(chalid)
                    user = Users.query.filter_by(id=x + 1).first()
                    wrong = Fails(
                        user_id=user.id,
                        team_id=user.team_id,
                        challenge_id=chalid,
                        ip="127.0.0.1",
                        provided=gen_word(),
                    )

                    new_base = random_date(
                        base_time,
                        base_time +
                        datetime.timedelta(minutes=random.randint(30, 60)),
                    )
                    wrong.date = new_base
                    base_time = new_base

                    db.session.add(wrong)
                    db.session.commit()

        db.session.commit()
        db.session.close()

        clear_config()
        clear_standings()
        clear_pages()