|
1
|
|
|
import os |
|
|
|
|
|
|
2
|
|
|
import logging |
|
3
|
|
|
|
|
4
|
|
|
from flask import current_app, Blueprint, render_template, request, redirect, flash |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
from spike.model import Settings, ValueTemplates, db |
|
7
|
|
|
|
|
8
|
|
|
settings = Blueprint('settings', __name__, url_prefix='/settings') |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
@settings.route("/") |
|
12
|
|
|
def index(): |
|
|
|
|
|
|
13
|
|
|
_settings = Settings.query.order_by(Settings.name).all() |
|
14
|
|
|
if not _settings: |
|
15
|
|
|
return redirect("/rules") |
|
16
|
|
|
return render_template("settings/index.html", settings=_settings) |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
@settings.route("/mz") |
|
20
|
|
|
def mz_index(): |
|
|
|
|
|
|
21
|
|
|
mz = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_mz").order_by(ValueTemplates.value).all() |
|
|
|
|
|
|
22
|
|
|
if not mz: |
|
23
|
|
|
return redirect("/settings") |
|
24
|
|
|
return render_template("settings/mz.html", mz=mz) |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
@settings.route("/mz/del", methods=["POST"]) |
|
|
|
|
|
|
28
|
|
|
def mz_del(): |
|
|
|
|
|
|
29
|
|
|
dmz = ValueTemplates.query.filter(ValueTemplates.id == request.form["mzid"]).first() |
|
30
|
|
|
if not dmz: |
|
31
|
|
|
flash("Nothing found in %s " % (request.form["mzid"]), "error") |
|
32
|
|
|
return redirect("/settings/mz") |
|
33
|
|
|
|
|
34
|
|
|
db.session.delete(dmz) |
|
35
|
|
|
try: |
|
36
|
|
|
db.session.commit() |
|
37
|
|
|
flash("OK: deleted %s " % dmz.value, "success") |
|
38
|
|
|
except: |
|
|
|
|
|
|
39
|
|
|
flash("ERROR while trying to delete : %s" % dmz.value, "error") |
|
40
|
|
|
return redirect("/settings/mz") |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
@settings.route("/mz/new", methods=["POST"]) |
|
44
|
|
|
def mz_new(): |
|
|
|
|
|
|
45
|
|
|
db.session.add(ValueTemplates("naxsi_mz", request.form["nmz"])) |
|
46
|
|
|
db.session.commit() |
|
47
|
|
|
flash("Updated MZ: %s" % request.form["nmz"], "success") |
|
48
|
|
|
return redirect("/settings/mz") |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
@settings.route("/scores") |
|
52
|
|
|
def score_index(): |
|
|
|
|
|
|
53
|
|
|
sc = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_score").order_by(ValueTemplates.value).all() |
|
|
|
|
|
|
54
|
|
|
if not sc: |
|
55
|
|
|
return redirect("/settings") |
|
56
|
|
|
return render_template("settings/scores.html", scores=sc) |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
@settings.route("/scores/new", methods=["POST"]) |
|
60
|
|
|
def score_new(): |
|
|
|
|
|
|
61
|
|
|
if not request.form["nscore"].startswith("$"): |
|
62
|
|
|
request.form["nscore"] = '$' + request.form["nscore"] |
|
63
|
|
|
|
|
64
|
|
|
db.session.add(ValueTemplates("naxsi_score", request.form["nscore"].upper())) |
|
65
|
|
|
db.session.commit() |
|
66
|
|
|
flash("Updated Score: %s" % request.form["nscore"], "success") |
|
67
|
|
|
return redirect("/settings/scores") |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
@settings.route("/scores/del", methods=["POST"]) |
|
|
|
|
|
|
71
|
|
|
def scores_del(): |
|
|
|
|
|
|
72
|
|
|
dsc = ValueTemplates.query.filter(ValueTemplates.id == request.form["scid"]).first() |
|
73
|
|
|
if not dsc: |
|
74
|
|
|
flash("Nothing found in %s " % (request.form["scid"]), "error") |
|
75
|
|
|
return redirect("/settings/scores") |
|
76
|
|
|
db.session.delete(dsc) |
|
77
|
|
|
|
|
78
|
|
|
try: |
|
79
|
|
|
db.session.commit() |
|
80
|
|
|
flash("OK: deleted %s " % dsc.value, "success") |
|
81
|
|
|
except: |
|
|
|
|
|
|
82
|
|
|
flash("ERROR while trying to delete : %s" % dsc.value, "error") |
|
83
|
|
|
return redirect("/settings/scores") |
|
84
|
|
|
|
|
85
|
|
|
@settings.route("/save", methods=["POST"]) |
|
86
|
|
|
def save_settings(): |
|
|
|
|
|
|
87
|
|
|
s = '' |
|
|
|
|
|
|
88
|
|
|
for s in request.form: |
|
|
|
|
|
|
89
|
|
|
sfind = Settings.query.filter(Settings.name == s).first() |
|
90
|
|
|
if not sfind: |
|
91
|
|
|
logging.error("no value for %s", sfind) |
|
92
|
|
|
continue |
|
93
|
|
|
|
|
94
|
|
|
if sfind.value != request.form[s]: |
|
95
|
|
|
sfind.value = request.form[s] |
|
96
|
|
|
db.session.add(sfind) |
|
97
|
|
|
|
|
98
|
|
|
flash("Updated setting: %s" % s, "success") |
|
99
|
|
|
db.session.commit() |
|
100
|
|
|
os.system("touch spike/__init__.py") |
|
101
|
|
|
return redirect("/settings") |
|
102
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.