Beispiel #1
0
def blacklist():
    scope = ScopeItem.getBlacklist()
    blacklistSize = current_app.ScopeManager.get_blacklist_size()
    newForm = forms.NewScopeForm()
    delForm = forms.ScopeDeleteForm()
    editForm = forms.ScopeToggleForm()
    importForm = forms.ImportBlacklistForm()
    addTagForm = forms.TagScopeForm()
    addTagForm.tagname.choices = [(row.name, row.name) for row in Tag.query.all()]
    if newForm.validate_on_submit():
        target = ipaddress.ip_network(newForm.target.data, False)
        newTarget = ScopeItem(target=target.with_prefixlen, blacklist=True)
        db.session.add(newTarget)
        db.session.commit()
        current_app.ScopeManager.update()
        flash(f"{newTarget.target} blacklisted!", "success")
        return redirect(url_for("admin.blacklist"))
    return render_template(
        "admin/blacklist.html",
        scope=scope,
        blacklistSize=blacklistSize,
        delForm=delForm,
        editForm=editForm,
        newForm=newForm,
        importForm=importForm,
        addTagForm=addTagForm,
    )
Beispiel #2
0
def scope():
	scope = ScopeItem.get_scope()
	scopeSize = current_app.ScopeManager.get_scope_size()

	# if it's zero, let's make sure the ScopeManager is up to date
	if scopeSize == 0:
		current_app.ScopeManager.update()
		scopeSize = current_app.ScopeManager.get_scope_size()
		# if it's zero again that's fine, we just had to check

	newForm = forms.NewScopeForm()
	delForm = forms.ScopeDeleteForm()
	editForm = forms.ScopeToggleForm()
	importForm = forms.ImportScopeForm()
	addTagForm = forms.TagScopeForm()
	addTagForm.tagname.choices = [(row.name, row.name) for row in Tag.query.all()]
	if newForm.validate_on_submit():
		if '/' not in newForm.target.data:
			newForm.target.data = newForm.target.data + '/32'
		target = ipaddress.ip_network(newForm.target.data, False)
		newTarget = ScopeItem(target=target.with_prefixlen, blacklist=False)
		db.session.add(newTarget)
		db.session.commit()
		current_app.ScopeManager.update()
		flash('%s added!' % newTarget.target, 'success')
		return redirect(url_for('admin.scope'))
	return render_template(
		"admin/scope.html", scope=scope, scopeSize=scopeSize, delForm=delForm,
		editForm=editForm, newForm=newForm, importForm=importForm, addTagForm=addTagForm)
Beispiel #3
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)
Beispiel #4
0
def toggleScopeItem(id):
    toggleForm = forms.ScopeToggleForm()
    if toggleForm.validate_on_submit():
        item = ScopeItem.query.filter_by(id=id).first()
        if item.blacklist:
            item.blacklist = False
            flash('%s removed from blacklist!' % item.target, 'success')
        else:
            item.blacklist = True
            flash('%s blacklisted!' % item.target, 'success')
        db.session.commit()
        current_app.ScopeManager.update()
    else:
        flash("Form couldn't validate!", 'danger')
    return redirect(request.referrer)
Beispiel #5
0
def blacklist():
    render = {
        "scope": ScopeItem.getBlacklist(),
        "blacklistSize": current_app.ScopeManager.get_blacklist_size(),
        "effectiveScopeSize": current_app.ScopeManager.get_effective_scope_size(),
        "newForm": forms.NewScopeForm(),
        "delForm": forms.ScopeDeleteForm(),
        "editForm": forms.ScopeToggleForm(),
        "importForm": forms.ImportScopeForm(),
        "addTagForm": forms.TagScopeForm(),
    }
    render["addTagForm"].tagname.choices = [
        (row.name, row.name) for row in Tag.query.all()
    ]
    if render["newForm"].validate_on_submit():
        target = ipaddress.ip_network(render["newForm"].target.data, False)
        newTarget = ScopeItem(target=target.with_prefixlen, blacklist=True)
        db.session.add(newTarget)
        db.session.commit()
        current_app.ScopeManager.update()
        flash(f"{newTarget.target} blacklisted.", "success")
        return redirect(url_for("admin.blacklist"))
    return render_template("admin/blacklist.html", **render)