Completed
Push — master ( ac8e27...9493cd )
by -
01:40
created

explain()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125
Metric Value
dl 0
loc 3
ccs 1
cts 2
cp 0.5
rs 10
cc 1
crap 1.125
1 1
import logging
2
3 1
from time import time
4 1
from flask import Blueprint, render_template, request, redirect, flash, Response, url_for
5 1
from sqlalchemy.exc import SQLAlchemyError
0 ignored issues
show
Configuration introduced by
The import sqlalchemy.exc could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

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.

Loading history...
6
7 1
from spike.model import db
8 1
from spike.model.naxsi_whitelist import NaxsiWhitelist
9 1
from spike.model.naxsi_whitelistsets import NaxsiWhitelistSets
10 1
from spike.model.naxsi_rules import NaxsiRules
11 1
from spike.model import naxsi_mz
12
13 1
whitelists = Blueprint('whitelists', __name__)
14
15
16 1
@whitelists.route("/")
17
def index():
18
    _wlist = NaxsiWhitelist.query.order_by(NaxsiWhitelist.wid.desc()).all()
0 ignored issues
show
Bug introduced by
The Class NaxsiWhitelist does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
19
    if not _wlist:
20
        flash("No whitelist found, please create one", "success")
21
        return redirect(url_for('whitelists.new'))
22
    return render_template("whitelists/index.html", whitelists=_wlist)
23
24
25 1
@whitelists.route("/plain/<string:wid>", methods=["GET"])
26
def plain(wid):
27
    _wlist = NaxsiWhitelist.query.filter(NaxsiRules.sid == wid).first()
0 ignored issues
show
Bug introduced by
The Class NaxsiWhitelist does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
28
    if not _wlist:
29
        flash("no rules found, please create one", "error")
30
        return redirect(url_for('whitelists.index'))
31
    return Response(_wlist.fullstr(), mimetype='text/plain')
32
33
34 1
@whitelists.route("/view/<string:wid>", methods=["GET"])
35
def view(wid):
36
    _wlist = NaxsiWhitelist.query.filter(NaxsiRules.sid == wid).first()
0 ignored issues
show
Bug introduced by
The Class NaxsiWhitelist does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
37
    if _wlist is None:
38
        flash("no rules found, please create one", "error")
39
        return redirect(url_for('whitelists.index'))
40
41
    return render_template("rules/view.html", rule=_wlist, rtext=_wlist)
42
43
44 1
@whitelists.route("/edit/<string:wid>", methods=["GET"])
45
def edit(wid):
46
    return redirect(url_for('whitelists.new'))
47
48
49 1
@whitelists.route("/explain/", methods=["GET", "POST"])
50
def explain():
51
    return redirect(url_for('whitelists.new'))
52
53
54 1
@whitelists.route("/del/<string:wid>", methods=["GET"])
55
def del_sid(wid):
56
    return redirect(url_for('whitelists.new'))
57
58
59 1
@whitelists.route("/generate", methods=["GET", "POST"])
60
def generate():
61
    if request.method == "GET":
62
        return render_template("misc/whitelist_generator.html")
63
64
65 1
@whitelists.route('/new', methods=["GET", "POST"])
66
def new():
67
    if request.method == "GET":
68
        _whitelistesets = NaxsiWhitelistSets.query.all()
0 ignored issues
show
Bug introduced by
The Class NaxsiWhitelistSets does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
69
        return render_template('whitelists/new.html', matchzones=naxsi_mz, whitelistsets=_whitelistesets)
70
71
    logging.debug('Posted new request: %s', request.form)
72
    mz = "|".join(filter(len, request.form.getlist("mz") + request.form.getlist("custom_mz_val")))
73
74
    score = request.form.get("score", "")
0 ignored issues
show
Unused Code introduced by
The variable score seems to be unused.
Loading history...
75
    score += ':'
76
    score += request.form.get("score_%s" % request.form.get("score", ""), "")
77
78
    wlist = NaxsiWhitelist(wid=request.form.get("id", ""), timestamp=int(time()),
79
                            whitelistset=request.form.get("whitelistset", ""), mz=mz, active=1,
80
                            negative=request.form.get("negative", "") == 'checked')
81
82
    wlist.validate()
0 ignored issues
show
Bug introduced by
The Instance of NaxsiWhitelist does not seem to have a member named validate.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
83
84
    if wlist.error:
85
        flash("ERROR: {0}".format(",".join(wlist.error)))
86
        return redirect("/rules/new")
87
    elif wlist.warnings:
88
        flash("WARNINGS: {0}".format(",".join(wlist.warnings)))
89
    db.session.add(wlist)
90
91
    try:
92
        db.session.commit()
93
        flash('Created!')
94
    except SQLAlchemyError as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ([a-z_][a-z0-9_]{1,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
95
        flash("Error : %s" % e, "error")
96
97
    return redirect(url_for('whitelists.index'))
98