add regexFilter and docs

This commit is contained in:
Bastian Schroll 2019-10-26 13:41:17 +02:00
parent a92dd8d94c
commit 61e085d555
No known key found for this signature in database
GPG key ID: 0AE96912A20E9F5F
8 changed files with 144 additions and 5 deletions

View file

@ -38,8 +38,7 @@ class BoswatchModule(Module):
def doWork(self, bwPacket):
"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance
@return bwPacket or False"""
@param bwPacket: A BOSWatch packet instance"""
for mode in self.config.get("allowed", default=[]):
if bwPacket.get("mode") == mode:

View file

@ -0,0 +1,65 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
German BOS Information Script
by Bastian Schroll
@file: regexFilter.py
@date: 26.10.2019
@author: Bastian Schroll
@description: Regex filter module
"""
import logging
from module.module import Module
# ###################### #
# Custom plugin includes #
import re
# ###################### #
logging.debug("- %s loaded", __name__)
class BoswatchModule(Module):
"""!Description of the Module"""
def __init__(self, config):
"""!Do not change anything here!"""
super().__init__(__name__, config) # you can access the config class on 'self.config'
def onLoad(self):
"""!Called by import of the plugin"""
pass
def doWork(self, bwPacket):
"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance"""
for filter in self.config.get("filter"):
checkFailed = False
logging.debug("try filter '%s' with %d check(s)", filter.get("name"), len(filter.get("checks")))
for check in filter.get("checks"):
fieldData = bwPacket.get(check.get("field"))
if not fieldData or not re.search(check.get("regex"), fieldData):
logging.debug("[-] field '%s' with regex '%s'", check.get("field"), check.get("regex"))
checkFailed = True
break # if one check failed we break this filter
else:
logging.debug("[+] field '%s' with regex '%s'", check.get("field"), check.get("regex"))
if not checkFailed:
logging.debug("[PASSED] filter '%s'", filter.get("name"))
return None # None -> Router will go on with this packet
logging.debug("[FAILED] filter '%s'", filter.get("name"))
return False # False -> Router will stop further processing
def onUnload(self):
"""!Called by destruction of the plugin"""
pass

View file

@ -38,8 +38,7 @@ class BoswatchModule(Module):
def doWork(self, bwPacket):
"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance
@return bwPacket or False"""
@param bwPacket: A BOSWatch packet instance"""
if bwPacket.get("mode") == "fms":
pass
elif bwPacket.get("mode") == "zvei":