Test Setup Failed
Push — master ( 63da58...9fdcd8 )
by -
01:30
created

rule_plain()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 4
rs 10
1
import logging
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import re
3
import string
4
from time import time, localtime, strftime
5
6
from flask import current_app, Blueprint, render_template, request, redirect, flash, Response
1 ignored issue
show
Coding Style introduced by
This line is too long as per the coding-style (93/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Configuration introduced by
The import flask 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...
Unused Code introduced by
Unused current_app imported from flask
Loading history...
7
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...
8
9
from spike.model import NaxsiRules, NaxsiRuleSets
10
from spike.model import check_constraint, db, get_latest_sid
0 ignored issues
show
Unused Code introduced by
Unused check_constraint imported from spike.model
Loading history...
11
from spike.model.naxsi_rules import ValueTemplates
12
13
rules = Blueprint('rules', __name__, url_prefix='/rules')
0 ignored issues
show
Coding Style Naming introduced by
The name rules does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

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...
14
15
# TODO : merge `ruleset_plain` and `ruleset_view`
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
16
17
18
@rules.route("/")
19
def index():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
20
    _rules = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).all()
21
    if not _rules:
22
        flash("no rules found, please create one", "success")
23
        return redirect("/rules/new")
24
    return render_template("rules/index.html", rules=_rules)
25
26
@rules.route("/plain/<int:sid>")
27
def plain(sid):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
28
    sid = NaxsiRules.query.filter(NaxsiRules.sid == sid).first()
29
    if not sid:
30
        flash("no rules found, please create one", "error")
31
        return redirect("/rules/new")
32
    return Response(__get_textual_representation_rule(sid), mimetype='text/plain')
33
34
35
@rules.route("/select/<path:selector>", methods=["GET"])
36
def select(selector=''):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
37
    if not selector:
38
        return redirect("/rules/")
39
40
    sel = str(selector)
41
    logging.info("sel: %s ", sel)
42
    try:
43
        rs_val = sel.split(":")[1]
44
    except SQLAlchemyError:
45
        return redirect("/rules/")
46
47
    if sel.startswith('r:'):
48
        _rules = NaxsiRules.query.filter(NaxsiRules.ruleset == rs_val).order_by(NaxsiRules.sid.desc()).all()
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
49
        selection = "Search ruleset: %s " % rs_val
50
    elif sel.startswith('id:'):
51
        _rules = NaxsiRules.query.filter(NaxsiRules.sid == rs_val).order_by(NaxsiRules.sid.desc()).all()
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
52
        selection = "Search sid: %s " % rs_val
53
    else:
54
        return redirect("/rules/")
55
56
    return render_template("rules/index.html", rules=_rules, selection=selection)
57
58
59
@rules.route("/search/", methods=["GET"])
60
def search():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
61
    terms = request.args.get('s', '')
62
63
    if len(terms) < 2:
64
        return redirect('/rules')
65
66
    # No fancy injections
67
    whitelist = set(string.ascii_letters + string.digits + ':-_ ')
68
    filtered = ''.join(filter(whitelist.__contains__, terms))
69
70
    if filtered.isdigit():  # get rule by id
71
        _rules = db.session.query(NaxsiRules).filter(NaxsiRules.sid == int(filtered)).all()
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (91/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
72
    else:
73
        expression = '%' + filtered + '%'
74
        _rules = db.session.query(NaxsiRules).filter(
75
            db.or_(
76
                NaxsiRules.msg.like(expression),
77
                NaxsiRules.rmks.like(expression),
78
                NaxsiRules.detection.like(expression)
79
            )
80
        ).order_by(NaxsiRules.sid.desc()).all()
81
    return render_template("rules/index.html", rules=_rules, selection="Search: %s" % filtered, lsearch=terms)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
82
83
84
@rules.route("/new", methods=["GET", "POST"])
85
def new():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
86
    sid = get_latest_sid()
87
88
    if request.method == "GET":
89
        mz = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_mz").all()
0 ignored issues
show
Coding Style Naming introduced by
The name mz does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
Bug introduced by
The Class ValueTemplates 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...
90
        _rulesets = NaxsiRuleSets.query.all()
91
        score = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_score").all()
0 ignored issues
show
Bug introduced by
The Class ValueTemplates 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...
92
        return render_template("rules/new.html", mz=mz, rulesets=_rulesets, score=score, latestn=sid)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
93
94
    # create new rule
95
    logging.debug('Posted new request: %s', request.form)
96
97
    detect = str(request.form["detection"]).strip()
98
    if not detect.startswith("str:") and not detect.startswith("rx:"):
99
        detect = "str:%s" % detect
100
101
    mz = "|".join(request.form.getlist("mz"))
0 ignored issues
show
Coding Style Naming introduced by
The name mz does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
102
103
    try:
104
        if request.form["custom_mz"] == "on":
105
            mz = "%s|%s" % (mz, request.form["custom_mz_val"])
0 ignored issues
show
Coding Style Naming introduced by
The name mz does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
106
    except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
107
        pass
0 ignored issues
show
Unused Code introduced by
This except handler seems to be unused and could be removed.

Except handlers which only contain pass and do not have an else clause can usually simply be removed:

try:
    raises_exception()
except:  # Could be removed
    pass
Loading history...
108
109
    score_raw = request.form["score"].strip()
110
    score_val = request.form["score_%s" % score_raw].strip()
111
    score = "%s:%s" % (score_raw, score_val)
112
    rmks = request.form["rmks"]
113
    ruleset = request.form["ruleset"]
114
    negative = 'negative' in request.form and request.form['negative'] == 'checked'
115
116
    nrule = NaxsiRules(request.form["msg"], detect, mz, score, sid, ruleset, rmks, "1", negative, int(time()))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
117
    db.session.add(nrule)
118
119
    try:
120
        db.session.commit()
121
        flash("OK: created %s : %s" % (sid, request.form["msg"]), "success")
122
        return redirect("/rules/edit/%s" % sid)
123
    except SQLAlchemyError:
124
        flash("ERROR while trying to create %s : %s" % (sid, request.form["msg"]), "error")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (91/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
125
126
    return redirect("/rules/new")
127
128
129
@rules.route("/edit/<path:sid>", methods=["GET", "POST"])
130
def edit(sid=''):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
131
    if not sid:
132
        return redirect("/rules/")
133
134
    rinfo = NaxsiRules.query.filter(NaxsiRules.sid == sid).first()
135
    if not rinfo:
136
        return redirect("/rules/")
137
138
    mz = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_mz").all()
0 ignored issues
show
Coding Style Naming introduced by
The name mz does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
Bug introduced by
The Class ValueTemplates 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...
139
    score = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_score").all()
0 ignored issues
show
Bug introduced by
The Class ValueTemplates 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...
140
    _rulesets = NaxsiRuleSets.query.all()
141
    rruleset = NaxsiRuleSets.query.filter(NaxsiRuleSets.name == rinfo.ruleset).first()
142
    custom_mz = ""
143
    mz_check = rinfo.mz
144
    if re.search(r"^\$[A-Z]+:(.*)\|[A-Z]+", mz_check):
145
        custom_mz = mz_check
146
        rinfo.mz = "custom"
147
    return render_template("rules/edit.html", mz=mz, rulesets=_rulesets, score=score, rules_info=rinfo,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
148
                           rule_ruleset=rruleset, custom_mz=custom_mz)
149
150
151
@rules.route("/save/<path:sid>", methods=["POST"])
152
def save(sid=''):  # FIXME this is the exact same method as the `new` one.
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
153
    if not sid:
154
        return redirect("/rules/")
155
156
    # create new rule
157
    try:
158
        msg = request.form["msg"]
159
        detect = str(request.form["detection"]).strip()
160
        if not detect.startswith("str:") and not detect.startswith("rx:"):
161
            detect = "str:%s" % detect
162
        mz = "|".join(request.form.getlist("mz"))
0 ignored issues
show
Coding Style Naming introduced by
The name mz does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
163
        try:
164
            if request.form["custom_mz"] == "on":
165
                if len(mz) > 1:
166
                    mz = "%s|%s" % (request.form["custom_mz_val"], mz)
0 ignored issues
show
Coding Style Naming introduced by
The name mz does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
167
                else:
168
                    mz = "%s" % (request.form["custom_mz_val"])
0 ignored issues
show
Coding Style Naming introduced by
The name mz does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
169
        except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
170
            pass
0 ignored issues
show
Unused Code introduced by
This except handler seems to be unused and could be removed.

Except handlers which only contain pass and do not have an else clause can usually simply be removed:

try:
    raises_exception()
except:  # Could be removed
    pass
Loading history...
171
        score_raw = request.form["score"].strip()
172
        score_val = request.form["score_%s" % score_raw].strip()
173
        score = "%s:%s" % (score_raw, score_val)
174
        # sid = nr["sid"]
175
        rmks = request.form["rmks"]
176
        ruleset = request.form["ruleset"]
177
        active = request.form["active"]
178
        negative = 'negative' in request.form and request.form['negative'] == 'checked'
179
    except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
180
        flash('ERROR - please select MZ/Score <a href="javascript:alert(history.back)">Go Back</a>', "error")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
181
        return redirect("/rules/edit/%s" % sid)
182
183
    nrule = NaxsiRules.query.filter(NaxsiRules.sid == sid).first()
184
    nrule.msg = msg
185
    nrule.detection = detect
186
    nrule.mz = mz
187
    nrule.score = score
188
    nrule.ruleset = ruleset
189
    nrule.rmks = rmks
190
    nrule.active = active
191
    nrule.negative = negative
192
    nrule.timestamp = int(time())
193
    db.session.add(nrule)
194
    try:
195
        db.session.commit()
196
    except SQLAlchemyError:
197
        flash("ERROR while trying to update %s : %s" % (sid, msg), "error")
198
    return redirect("/rules/edit/%s" % sid)
199
200
201
@rules.route("/view/<path:sid>", methods=["GET"])
202
def view(sid=''):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
203
    if not sid:
204
        return redirect("/rules/")
205
206
    rinfo = NaxsiRules.query.filter(NaxsiRules.sid == sid).first()
207
    if not rinfo:
208
        return redirect("/rules/")
209
210
    return render_template("rules/view.html", rule=rinfo, rtext=__get_textual_representation_rule(rinfo, full=0))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
211
212
213
@rules.route("/del/<path:sid>", methods=["GET"])
214
def del_sid(sid=''):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
215
    if not sid:
216
        return redirect("/rules/")
217
218
    nrule = NaxsiRules.query.filter(NaxsiRules.sid == sid).first()
219
    if not nrule:
220
        return redirect("/rules/")
221
222
    db.session.delete(nrule)
223
    try:
224
        db.session.commit()
225
        flash("OK: deleted %s : %s" % (sid, nrule.msg), "success")
226
    except SQLAlchemyError:
227
        flash("ERROR while trying to update %s : %s" % (sid, nrule.msg), "error")
228
229
    return redirect("/rules/")
230
231
232
@rules.route("/deact/<path:sid>", methods=["GET"])
233
def deact(sid=''):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
234
    if not sid:
235
        return redirect("/rules/")
236
237
    nrule = NaxsiRules.query.filter(NaxsiRules.sid == sid).first()
238
    if not nrule:
239
        return redirect("/rules/")
240
241
    if nrule.active == 0:
242
        nrule.active = 1
243
        fm = "reactivate"
0 ignored issues
show
Coding Style Naming introduced by
The name fm does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
244
    else:
245
        nrule.active = 0
246
        fm = "deactivate"
0 ignored issues
show
Coding Style Naming introduced by
The name fm does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
247
248
    db.session.add(nrule)
249
    try:
250
        db.session.commit()
251
        flash("OK: %s %sd : %s" % (fm, sid, nrule.msg), "success")
252
    except SQLAlchemyError:
253
        flash("ERROR while trying to %s %s : %s" % (fm, sid, nrule.msg), "error")
254
255
    rinfo = NaxsiRules.query.filter(NaxsiRules.sid == sid).first()
256
    if not rinfo:
257
        return redirect("/rules/")
258
259
    mz = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_mz").all()
0 ignored issues
show
Coding Style Naming introduced by
The name mz does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,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...
Bug introduced by
The Class ValueTemplates 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...
260
    score = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_score").all()
0 ignored issues
show
Bug introduced by
The Class ValueTemplates 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...
261
    _rulesets = NaxsiRuleSets.query.all()
262
    return render_template("rules/edit.html", mz=mz, rulesets=_rulesets, score=score, rules_info=rinfo)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
263
264
265
def __get_textual_representation_rule(rule, full=1):
0 ignored issues
show
Coding Style Naming introduced by
The name __get_textual_representation_rule does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,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...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
266
    rdate = strftime("%F - %H:%M", localtime(float(str(rule.timestamp))))
267
    rmks = "# ".join(rule.rmks.strip().split("\n"))
268
    detect = rule.detection.lower() if rule.detection.startswith("str:") else rule.detection
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (92/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
269
    negate = 'negative' if rule.negative == 1 else ''
270
271
    if full == 1:
272
        nout = """
273
#
274
# sid: %s | date: %s 
275
#
276
# %s
277
#
278
MainRule %s "%s" "msg:%s" "mz:%s" "s:%s" id:%s ;
279
      
280
      """ % (rule.sid, rdate, rmks, negate, detect, rule.msg, rule.mz, rule.score, rule.sid)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (92/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
281
    else:
282
        nout = """MainRule %s "%s" "msg:%s" "mz:%s" "s:%s" id:%s  ;""" % \
283
               (negate, rule.detection, rule.msg, rule.mz, rule.score, rule.sid)
284
285
    return nout
286