Пример #1
0
    def setup(self):
        if self.is_submitted():
            try:
                settings = Settings.query.get(1)

                settings.ctf_name = self.ctf_name.data
                settings.organization_name = self.organization_name.data
                settings.from_date = self.from_date.data
                settings.from_time = self.from_time.data
                settings.to_date = self.to_date.data
                settings.to_time = self.to_time.data
                settings.dummy = False

                db.session.commit()

                cache.delete(key="past_running_time")
                cache.delete(key="settings")
                step = 3

            except SQLAlchemyError:
                db.session.rollback()
                flash("Transaction failed. Please try again.", "danger")
                step = 2

        else:
            flash("Form validation failed. Please try again.", "danger")
            step = 2

        return redirect(url_for("main.setup", step=step))
Пример #2
0
def edit_machine(id):
    machine = Machine.query.get_or_404(id)
    form = MachineForm(obj=machine)
    if request.method == "GET":
        return render_template("new_machine.html",
                               form_title=f"Editing machine #{id}",
                               form=form)
    else:
        if form.validate_on_submit():
            form.populate_obj(machine)
            db.session.commit()
            cache.delete(key="machines")
            flash(f"{form.name.data} has been edited.", "success")
            return redirect(url_for("ctf.machines"))
        else:
            flash(form.errors, "danger")
            return redirect(request.url)
Пример #3
0
def new_machine():
    form = MachineForm(obj=Machine.query.get(1))
    if request.method == "GET":
        return render_template("new_machine.html",
                               form_title="Add New Machine",
                               form=form)
    else:
        if form.validate_on_submit():
            new_machine = Machine()
            form.populate_obj(new_machine)
            db.session.add(new_machine)
            db.session.commit()
            cache.delete(key="machines")
            flash(f"{form.name.data} has been added.", "success")
            return redirect(url_for("ctf.machines"))
        else:
            flash(form.errors, "danger")
            return redirect(request.url)
Пример #4
0
    def setup(self):
        if self.is_submitted():
            try:
                Website.query.delete()
                for w in zip(self.names.data, self.urls.data):
                    obj = Website(name=w[0], url=w[1])
                    db.session.add(obj)
                db.session.commit()
                cache.delete(key="websites")
                flash(
                    "CTF setup was successful! \
                        You can use admin controls for managing database tables.",
                    "success",
                )
                return redirect(url_for("main.home"))

            except SQLAlchemyError:
                db.session.rollback()
                flash("Transaction failed. Please try again.", "danger")

        else:
            flash("Error: Couldn't save form data.", "danger")

        return redirect(url_for("main.setup", step=3))