1
|
1 |
|
from time import time, localtime, strftime |
2
|
|
|
|
3
|
1 |
|
from flask import current_app, Blueprint, render_template, request, redirect, flash, Response, url_for |
4
|
|
|
|
5
|
1 |
|
from spike.model import db |
6
|
1 |
|
from spike.model.naxsi_whitelistsets import NaxsiWhitelistSets |
7
|
1 |
|
from spike.model.naxsi_whitelist import NaxsiWhitelist |
8
|
|
|
|
9
|
|
|
|
10
|
1 |
|
whitelistsets = Blueprint('whitelistsets', __name__) |
11
|
|
|
|
12
|
|
|
|
13
|
1 |
|
@whitelistsets.route("/") |
14
|
|
|
def index(): |
15
|
|
|
_wlset = NaxsiWhitelistSets.query.order_by(NaxsiWhitelistSets.name).all() |
|
|
|
|
16
|
|
|
return render_template("whitelistsets/index.html", whitelistsets=_wlset) |
17
|
|
|
|
18
|
|
|
|
19
|
1 |
|
@whitelistsets.route("/plain/") |
20
|
1 |
|
@whitelistsets.route("/plain/<int:wid>") |
21
|
1 |
|
def plain(wid=0): |
22
|
|
|
if not wid: |
23
|
|
|
out = ''.join(map(__get_whitelist_for_whitelistset, NaxsiWhitelistSets.query.all())) |
|
|
|
|
24
|
|
|
else: |
25
|
|
|
out = __get_whitelist_for_whitelistset(NaxsiWhitelistSets.query.filter(NaxsiWhitelistSets.id == wid).first()) |
|
|
|
|
26
|
|
|
return Response(out, mimetype='text/plain') |
27
|
|
|
|
28
|
|
|
|
29
|
1 |
|
@whitelistsets.route("/new", methods=["POST"]) |
30
|
|
|
def new(): |
31
|
|
|
wname = request.form["wname"].strip().upper() |
32
|
|
|
|
33
|
|
|
if NaxsiWhitelistSets.query.filter(NaxsiWhitelistSets.name == wname).first(): |
|
|
|
|
34
|
|
|
flash("ERROR, ruleset exists: %s " % wname, "error") |
35
|
|
|
return redirect(url_for("whitelistsets.index")) |
36
|
|
|
|
37
|
|
|
db.session.add(NaxsiWhitelistSets(wname, "naxsi-whitelistset: %s" % wname, int(time()))) |
38
|
|
|
db.session.commit() |
39
|
|
|
|
40
|
|
|
flash("OK created: %s " % wname, "success") |
41
|
|
|
return redirect(url_for("whitelistsets.index")) |
42
|
|
|
|
43
|
|
|
|
44
|
1 |
|
@whitelistsets.route("/view/<int:wid>") |
45
|
|
|
def view(wid): |
46
|
|
|
ruleset = NaxsiWhitelistSets.query.filter(NaxsiWhitelistSets.id == wid).first() |
|
|
|
|
47
|
|
|
return render_template("rulesets/view.html", r=ruleset, rout=__get_whitelist_for_whitelistset(ruleset)) |
48
|
|
|
|
49
|
1 |
|
@whitelistsets.route("/select/<string:selector>", methods=["GET"]) |
50
|
|
|
def select(selector): |
51
|
|
|
_wlset = NaxsiWhitelist.query.filter(NaxsiWhitelist.whitelistset == selector).order_by(NaxsiWhitelist.wid.desc()).all() |
|
|
|
|
52
|
|
|
_selection = "Search wid: %s " % selector |
53
|
|
|
return render_template("whitelistsets/index.html", whitelistsets=_wlset, selection=_selection) |
54
|
|
|
|
55
|
|
|
|
56
|
1 |
|
@whitelistsets.route("/del/<int:wid>", methods=["POST"]) |
57
|
|
|
def remove(wid): |
58
|
|
|
_wlset = NaxsiWhitelistSets.query.filter(NaxsiWhitelistSets.id == wid).first() |
|
|
|
|
59
|
|
|
if _wlset is None: |
60
|
|
|
flash("ERROR, ruleset doesn't exists: %s " % wid, "error") |
61
|
|
|
return redirect(url_for("whitelistsets.index")) |
62
|
|
|
|
63
|
|
|
db.session.delete(_wlset) |
64
|
|
|
db.session.commit() |
65
|
|
|
|
66
|
|
|
flash("OK deleted: %s " % wid, "success") |
67
|
|
|
return redirect(url_for("whitelistsets.index")) |
68
|
|
|
|
69
|
|
|
|
70
|
1 |
|
def __get_whitelist_for_whitelistset(whitelistset): |
|
|
|
|
71
|
|
|
if not whitelistset: |
72
|
|
|
return '' |
73
|
|
|
|
74
|
|
|
_rules = NaxsiWhitelist.query.filter( |
|
|
|
|
75
|
|
|
NaxsiWhitelist.whitelistset == whitelistset.name, |
76
|
|
|
NaxsiWhitelist.active == 1 |
77
|
|
|
).all() |
78
|
|
|
|
79
|
|
|
nxruleset = NaxsiWhitelistSets.query.filter(NaxsiWhitelistSets.name == whitelistset.name).first() |
|
|
|
|
80
|
|
|
db.session.add(nxruleset) |
81
|
|
|
db.session.commit() |
82
|
|
|
|
83
|
|
|
text_rules = ''.join([r.fullstr() for r in _rules]) |
84
|
|
|
|
85
|
|
|
header = current_app.config["RULESET_HEADER"] |
86
|
|
|
header = header.replace("RULESET_DESC", whitelistset.name) |
87
|
|
|
header = header.replace("RULESET_DATE", strftime("%F - %H:%M", localtime(time()))) |
88
|
|
|
|
89
|
|
|
return header + text_rules |
90
|
|
|
|
This check looks for calls to members that are non-existent. These calls will fail.
The member could have been renamed or removed.