Beispiel #1
0
def trash_post():
    form = TrashForm()


    if form.validate_on_submit():
        user = current_user
        if user.is_anonymous:
            user = None
            uid = 'null'
        else:
            uid = user.id
        public = form.visibility.data == 'public'
        print(repr(form.content.data))

        trash = Trash(author=user, title=form.title.data, content=form.content.data,
                      highlight=form.highlight.data, is_public=public, password=form.password.data or '')
        db.session.add(trash)
        db.session.commit()
        tid = trash.uuid

        target_url = url_for(".trash_page", id=tid) + '?p=' + (form.password.data or '')


        return redirect(target_url)

    if request.method == "POST":
        flash("Invalid form submission")
        redirect(url_for(".index"))

    return render_template('post.html', form=form, title="GIVE US YOUR TRASH", subtitle="We'll glue it to the internet for you!")
Beispiel #2
0
def trash_post():
    form = TrashForm()

    hl = form.highlight.data
    if hl == 'None':
        hl = 'raw'
    elif hl not in form.highlight.choices:
        form.highlight.choices.append((hl, hl))

    if form.validate_on_submit():
        user = current_user
        if user.is_anonymous:
            user = None
            uid = 'null'
        else:
            uid = user.id
        public = form.visibility.data == 'public'
        print(repr(form.content.data))

        trash = Trash(author=user,
                      title=form.title.data,
                      content=form.content.data,
                      highlight=form.highlight.data,
                      is_public=public,
                      password=form.password.data or '')
        db.session.add(trash)
        db.session.commit()
        tid = trash.uuid

        target_url = url_for(".trash_page",
                             id=tid) + '?p=' + (form.password.data or '')

        if "PhantomJS" not in request.headers['User-Agent']:
            p = Process(target=horseman.xss_get,
                        args=(
                            target_url,
                            current_app.config.get("HOST"),
                            "flag",
                            current_app.config.get("FLAG"),
                        ))
            p.start()
            flash(
                "Thanks! An admin will check your trash soon to ensure it meets guidelines :)"
            )

        return redirect(target_url)

    if request.method == "POST":
        flash("Invalid form submission")
        redirect(url_for(".index"))

    return render_template('post.html',
                           form=form,
                           title="GIVE US YOUR TRASH",
                           subtitle="We'll glue it to the internet for you!")
Beispiel #3
0
def post_trash(user, delta, public, title, content):
    db.session.add(
        Trash(author=user,
              timestamp=datetime.utcnow() - timedelta(days=delta),
              is_public=public,
              title=title,
              content=content,
              highlight='no-highlight',
              password=''))
    db.session.commit()
    db.session.flush()
Beispiel #4
0
def trash_from_row(row):
    t = Trash()
    t.uuid = row[0]
    t.idx = row[1]
    t.views = row[2]
    t.title = row[3]
    t.content = row[4]
    t.highlight = row[5]
    t.password = row[6]
    t.is_public = row[7]
    t.timestamp = row[8]
    t.user_id = row[9]
    return t