示例#1
0
def toggle_scope(scopetype, id):
    if scopetype not in ["scope", "blacklist"]:
        return abort(404)
    toggleForm = forms.ScopeToggleForm()
    if toggleForm.validate_on_submit():
        item = ScopeItem.query.filter_by(id=id).first()
        item.blacklist = not item.blacklist
        flash(f"Toggled scope status for {item.target}!", "success")
        db.session.commit()
        current_app.ScopeManager.update()
    else:
        flash("Form couldn't validate!", "danger")
    return redirects.get_scope_redirect(scopetype)
示例#2
0
def untag_scope(scopetype, id):
    if scopetype not in ["scope", "blacklist"]:
        return abort(404)
    delTagForm = forms.TagScopeForm()
    scope = ScopeItem.query.get(id)
    delTagForm.tagname.choices = [(row.name, row.name) for row in scope.tags]
    if delTagForm.validate_on_submit():
        mytag = Tag.query.filter_by(name=delTagForm.tagname.data).first()
        scope.delTag(mytag)
        db.session.commit()
        flash(f'Tag "{mytag.name}" removed from {scope.target}', "success")
    else:
        flash("Form couldn't validate!", "danger")
    return redirects.get_scope_redirect(scopetype)
示例#3
0
def tag_scope(scopetype, id):
    if scopetype not in ["scope", "blacklist"]:
        return abort(404)
    addTagForm = forms.TagScopeForm()
    addTagForm.tagname.choices = [(row.name, row.name) for row in Tag.query.all()]
    if addTagForm.validate_on_submit():
        scope = ScopeItem.query.get(id)
        mytag = Tag.query.filter_by(name=addTagForm.tagname.data).first()
        scope.addTag(mytag)
        db.session.commit()
        flash(f'Tag "{mytag.name}" added to {scope.target}.', "success")
    else:
        flash("Form couldn't validate!", "danger")
    return redirects.get_scope_redirect(scopetype)
示例#4
0
def delete_scope(scopetype, id):
    if scopetype not in ["scope", "blacklist"]:
        return abort(404)
    delForm = forms.ScopeDeleteForm()
    if delForm.validate_on_submit():
        item = ScopeItem.query.filter_by(id=id).first()
        for tag in item.tags:
            item.tags.remove(tag)
        ScopeItem.query.filter_by(id=id).delete()
        db.session.commit()
        current_app.ScopeManager.update()
        flash(f"{item.target} deleted!", "success")
    else:
        flash("Form couldn't validate!", "danger")
    return redirects.get_scope_redirect(scopetype)