Events, CurrentScan, pluginsState, ENABLE_PLUGINS work

This commit is contained in:
Jokob-sk
2023-08-12 12:17:53 +10:00
parent 5397edc14d
commit c2e4d39117
3 changed files with 37 additions and 21 deletions

View File

@@ -74,10 +74,12 @@ def print_log (pText):
# textchars = bytearray({7,8,9,10,12,13,27} | set(range(0x20, 0x100)) - {0x7f}) # textchars = bytearray({7,8,9,10,12,13,27} | set(range(0x20, 0x100)) - {0x7f})
# is_binary_string = lambda bytes: bool(bytes.translate(None, textchars)) # is_binary_string = lambda bytes: bool(bytes.translate(None, textchars))
def append_file_binary (pPath, input): def append_file_binary(file_path, input_data):
file = open (pPath, 'ab') with open(file_path, 'ab') as file:
file.write (input) if isinstance(input_data, str):
file.close() input_data = input_data.encode('utf-8') # Encode string as bytes
file.write(input_data)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------

View File

@@ -20,7 +20,10 @@ class plugins_state:
self.processScan = processScan self.processScan = processScan
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def run_plugin_scripts(db, runType, pluginsState = plugins_state()): def run_plugin_scripts(db, runType, pluginsState = None):
if pluginsState == None:
pluginsState = plugins_state()
# Header # Header
updateState(db,"Run: Plugins") updateState(db,"Run: Plugins")
@@ -604,13 +607,15 @@ def process_plugin_events(db, plugin, pluginsState):
sql.executemany(q, sqlParams) sql.executemany(q, sqlParams)
db.commitDB() db.commitDB()
# perform scan if mapped to CurrentScan table
if dbTable == 'CurrentScan':
pluginsState.processScan = True
db.commitDB() db.commitDB()
# perform scan if mapped to CurrentScan table
if dbTable == 'CurrentScan':
pluginsState.processScan = True
return pluginsState return pluginsState

View File

@@ -14,29 +14,38 @@ def check_config():
return True return True
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def send (msg: noti_struc): def send(msg: noti_struc):
html = msg.html html = msg.html
text = msg.text text = msg.text
#Define Apprise compatible payload (https://github.com/caronc/apprise-api#stateless-solution) # Define Apprise compatible payload (https://github.com/caronc/apprise-api#stateless-solution)
payload = html payload = html
if conf.APPRISE_PAYLOAD == 'text': if conf.APPRISE_PAYLOAD == 'text':
payload = text payload = text
_json_payload={ _json_payload = {
"urls": conf.APPRISE_URL, "urls": conf.APPRISE_URL,
"title": "Pi.Alert Notifications", "title": "Pi.Alert Notifications",
"format": conf.APPRISE_PAYLOAD, "format": conf.APPRISE_PAYLOAD,
"body": payload "body": payload
} }
try: try:
# try runnning a subprocess # Construct the curl command with input from the JSON payload
p = subprocess.Popen(["curl","-i","-X", "POST" ,"-H", "Content-Type:application/json" ,"-d", json.dumps(_json_payload), conf.APPRISE_HOST], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) curl_command = [
stdout, stderr = p.communicate() "curl", "-i", "-X", "POST", "-H", "Content-Type:application/json",
# write stdout and stderr into .log files for debugging if needed conf.APPRISE_HOST
logResult (stdout, stderr) # TO-DO should be changed to mylog ]
# Run the curl command with the JSON payload as input
completed_process = subprocess.run(
curl_command, input=json.dumps(_json_payload),
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
)
# Log the stdout and stderr
logResult(completed_process.stdout, completed_process.stderr) # TO-DO should be changed to mylog
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
# An error occured, handle it # An error occurred, handle it
mylog('none', [e.output]) mylog('none', [e.output])