#---------------------------------------------------------------------------------# # Pi.Alert # # Open Source Network Guard / WIFI & LAN intrusion detector # # # # reporting.py - Pialert Back module. Template to email reporting in HTML format # #---------------------------------------------------------------------------------# # Puche 2021 pi.alert.application@gmail.com GNU GPLv3 # # jokob-sk 2022 jokob.sk@gmail.com GNU GPLv3 # # leiweibau 2022 https://github.com/leiweibau GNU GPLv3 # # cvc90 2023 https://github.com/cvc90 GNU GPLv3 # #---------------------------------------------------------------------------------# import datetime import json import socket import subprocess import requests from json2table import convert # pialert modules import conf import const from const import pialertPath, logPath, apiPath from helper import noti_obj, generate_mac_links, removeDuplicateNewLines, timeNowTZ, hide_email, updateState, get_file_content, write_file from logger import logResult, mylog, print_log from publishers.ntfy import (check_config as ntfy_check_config, send as send_ntfy ) from publishers.webhook import (check_config as webhook_check_config, send as send_webhook) from publishers.pushsafer import (check_config as pushsafer_check_config, send as send_pushsafer) from publishers.mqtt import (check_config as mqtt_check_config, mqtt_start ) #=============================================================================== # REPORTING #=============================================================================== # create a json of the notifications to provide further integration options (e.g. used in webhook, mqtt notifications) json_final = [] #------------------------------------------------------------------------------- def construct_notifications(db, sqlQuery, tableTitle, skipText = False, suppliedJsonStruct = None): if suppliedJsonStruct is None and sqlQuery == "": return noti_obj("", "", "") table_attributes = {"style" : "border-collapse: collapse; font-size: 12px; color:#70707", "width" : "100%", "cellspacing" : 0, "cellpadding" : "3px", "bordercolor" : "#C0C0C0", "border":"1"} headerProps = "width='120px' style='color:white; font-size: 16px;' bgcolor='#64a0d6' " thProps = "width='120px' style='color:#F0F0F0' bgcolor='#64a0d6' " build_direction = "TOP_TO_BOTTOM" text_line = '{}\t{}\n' if suppliedJsonStruct is None: json_obj = db.get_table_as_json(sqlQuery) else: json_obj = suppliedJsonStruct jsn = json_obj.json html = "" text = "" if len(jsn["data"]) > 0: text = tableTitle + "\n---------\n" # Convert a JSON into an HTML table html = convert(jsn, build_direction=build_direction, table_attributes=table_attributes) # Cleanup the generated HTML table notification html = format_table(html, "data", headerProps, tableTitle).replace('