1
|
1 |
|
from flask import Blueprint, render_template, request, redirect, flash |
|
|
|
|
2
|
1 |
|
from sqlalchemy.exc import SQLAlchemyError |
|
|
|
|
3
|
|
|
|
4
|
1 |
|
from spike.model import db |
5
|
1 |
|
from spike.model.value_templates import ValueTemplates |
6
|
|
|
|
7
|
1 |
|
settings = Blueprint('settings', __name__) |
8
|
|
|
|
9
|
|
|
|
10
|
1 |
|
@settings.route("/mz") |
11
|
|
|
def mz_index(): |
12
|
1 |
|
mz = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_mz").order_by(ValueTemplates.value).all() |
13
|
1 |
|
if not mz: |
14
|
|
|
return redirect("/settings") |
15
|
1 |
|
return render_template("settings/mz.html", mz=mz) |
16
|
|
|
|
17
|
|
|
|
18
|
1 |
|
@settings.route("/mz/del", methods=["POST"]) |
|
|
|
|
19
|
|
|
def mz_del(): |
20
|
|
|
dmz = ValueTemplates.query.filter(ValueTemplates.id == request.form["mzid"]).first() |
21
|
|
|
if not dmz: |
22
|
|
|
flash("Nothing found in %s " % (request.form["mzid"]), "error") |
23
|
|
|
return redirect("/settings/mz") |
24
|
|
|
|
25
|
|
|
db.session.delete(dmz) |
26
|
|
|
try: |
27
|
|
|
db.session.commit() |
28
|
|
|
flash("OK: deleted %s " % dmz.value, "success") |
29
|
|
|
except SQLAlchemyError: |
30
|
|
|
flash("ERROR while trying to delete : %s" % dmz.value, "error") |
31
|
|
|
return redirect("/settings/mz") |
32
|
|
|
|
33
|
|
|
|
34
|
1 |
|
@settings.route("/mz/new", methods=["POST"]) |
35
|
|
|
def mz_new(): |
36
|
|
|
db.session.add(ValueTemplates("naxsi_mz", request.form["nmz"])) |
37
|
|
|
db.session.commit() |
38
|
|
|
flash("Updated MZ: %s" % request.form["nmz"], "success") |
39
|
|
|
return redirect("/settings/mz") |
40
|
|
|
|
41
|
|
|
|
42
|
1 |
|
@settings.route("/scores") |
43
|
|
|
def scores_index(): |
44
|
1 |
|
sc = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_score").order_by(ValueTemplates.value).all() |
45
|
1 |
|
if not sc: |
46
|
|
|
return redirect("/settings") |
47
|
1 |
|
return render_template("settings/scores.html", scores=sc) |
48
|
|
|
|
49
|
|
|
|
50
|
1 |
|
@settings.route("/scores/new", methods=["POST"]) |
51
|
|
|
def scores_new(): |
52
|
|
|
if not request.form["nscore"].startswith("$"): |
53
|
|
|
request.form["nscore"] = '$' + request.form["nscore"] |
54
|
|
|
|
55
|
|
|
db.session.add(ValueTemplates("naxsi_score", request.form["nscore"].upper())) |
56
|
|
|
db.session.commit() |
57
|
|
|
flash("Updated Score: %s" % request.form["nscore"], "success") |
58
|
|
|
return redirect("/settings/scores") |
59
|
|
|
|
60
|
|
|
|
61
|
1 |
|
@settings.route("/scores/del", methods=["POST"]) |
|
|
|
|
62
|
|
|
def scores_del(): |
63
|
|
|
dsc = ValueTemplates.query.filter(ValueTemplates.id == request.form["scid"]).first() |
64
|
|
|
if not dsc: |
65
|
|
|
flash("Nothing found in %s " % (request.form["scid"]), "error") |
66
|
|
|
return redirect("/settings/scores") |
67
|
|
|
db.session.delete(dsc) |
68
|
|
|
|
69
|
|
|
try: |
70
|
|
|
db.session.commit() |
71
|
|
|
flash("OK: deleted %s " % dsc.value, "success") |
72
|
|
|
except SQLAlchemyError: |
73
|
|
|
flash("ERROR while trying to delete : %s" % dsc.value, "error") |
74
|
|
|
return redirect("/settings/scores") |
75
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.