mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Events, CurrentScan, pluginsState, APPRISE work
This commit is contained in:
@@ -202,7 +202,7 @@ function cleanLog($logFile)
|
|||||||
|
|
||||||
$path = "";
|
$path = "";
|
||||||
|
|
||||||
$allowedFiles = ['pialert.log', 'pialert_front.log', 'IP_changes.log', 'stdout.log', 'stderr.log', "pialert_pholus_lastrun.log"];
|
$allowedFiles = ['pialert.log', 'pialert_front.log', 'IP_changes.log', 'stdout.log', 'stderr.log', "pialert_pholus_lastrun.log", 'pialert.php_errors.log'];
|
||||||
|
|
||||||
if(in_array($logFile, $allowedFiles))
|
if(in_array($logFile, $allowedFiles))
|
||||||
{
|
{
|
||||||
@@ -365,10 +365,39 @@ function encode_single_quotes ($val) {
|
|||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
function getDateFromPeriod () {
|
function getDateFromPeriod () {
|
||||||
$period = $_REQUEST['period'];
|
|
||||||
return '"'. date ('Y-m-d', strtotime ('+2 day -'. $period) ) .'"';
|
$periodDate = $_REQUEST['period'];
|
||||||
|
|
||||||
|
$periodDateSQL = "";
|
||||||
|
$days = "";
|
||||||
|
|
||||||
|
switch ($periodDate) {
|
||||||
|
case '7 days':
|
||||||
|
$days = "7";
|
||||||
|
break;
|
||||||
|
case '1 month':
|
||||||
|
$days = "30";
|
||||||
|
break;
|
||||||
|
case '1 year':
|
||||||
|
$days = "365";
|
||||||
|
break;
|
||||||
|
case '100 years':
|
||||||
|
$days = "3650"; //10 years
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$days = "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
$periodDateSQL = "-".$days." day";
|
||||||
|
|
||||||
|
return " date('now', '".$periodDateSQL."') ";
|
||||||
|
|
||||||
|
// $period = $_REQUEST['period'];
|
||||||
|
// return '"'. date ('Y-m-d', strtotime ('+2 day -'. $period) ) .'"';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
function quotes ($text) {
|
function quotes ($text) {
|
||||||
return str_replace ('"','""',$text);
|
return str_replace ('"','""',$text);
|
||||||
|
|||||||
@@ -492,7 +492,7 @@
|
|||||||
"WEBHOOK_REQUEST_METHOD_name" : "Request method",
|
"WEBHOOK_REQUEST_METHOD_name" : "Request method",
|
||||||
"WEBHOOK_REQUEST_METHOD_description" : "The HTTP request method to be used for the webhook call.",
|
"WEBHOOK_REQUEST_METHOD_description" : "The HTTP request method to be used for the webhook call.",
|
||||||
"WEBHOOK_SIZE_name" : "Max payload size",
|
"WEBHOOK_SIZE_name" : "Max payload size",
|
||||||
"WEBHOOK_SIZE_description" : "The maximum size of the webhook payload as number of characters in the passed string. If above limit, it will be truncated and a <code>(text was truncated)</code> message is appended.",
|
"WEBHOOK_SIZE_description" : "The maximum size of the webhook payload as number of characters in the passed string. If above limit, it will be truncated and a <code>(text was truncated)</code> message is appended.",
|
||||||
"Apprise_display_name" : "Apprise",
|
"Apprise_display_name" : "Apprise",
|
||||||
"Apprise_icon" : "<i class=\"fa fa-bullhorn\"></i>",
|
"Apprise_icon" : "<i class=\"fa fa-bullhorn\"></i>",
|
||||||
"REPORT_APPRISE_name" : "Enable Apprise",
|
"REPORT_APPRISE_name" : "Enable Apprise",
|
||||||
@@ -501,6 +501,8 @@
|
|||||||
"APPRISE_HOST_description" : "Apprise host URL starting with <code>http://</code> or <code>https://</code>. (don not forget to include <code>/notify</code> at the end)",
|
"APPRISE_HOST_description" : "Apprise host URL starting with <code>http://</code> or <code>https://</code>. (don not forget to include <code>/notify</code> at the end)",
|
||||||
"APPRISE_URL_name" : "Apprise notification URL",
|
"APPRISE_URL_name" : "Apprise notification URL",
|
||||||
"APPRISE_URL_description" : "Apprise notification target URL. For example for Telegram it would be <code>tgram://{bot_token}/{chat_id}</code>.",
|
"APPRISE_URL_description" : "Apprise notification target URL. For example for Telegram it would be <code>tgram://{bot_token}/{chat_id}</code>.",
|
||||||
|
"APPRISE_SIZE_name" : "Max payload size",
|
||||||
|
"APPRISE_SIZE_description" : "The maximum size of the apprise payload as number of characters in the passed string. If above limit, it will be truncated and a <code>(text was truncated)</code> message is appended.",
|
||||||
"NTFY_display_name" : "NTFY",
|
"NTFY_display_name" : "NTFY",
|
||||||
"NTFY_icon" : "<i class=\"fa fa-terminal\"></i>",
|
"NTFY_icon" : "<i class=\"fa fa-terminal\"></i>",
|
||||||
"REPORT_NTFY_name" : "Enable NTFY",
|
"REPORT_NTFY_name" : "Enable NTFY",
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ def read_config_file():
|
|||||||
|
|
||||||
print('[plugin_helper] reading config file')
|
print('[plugin_helper] reading config file')
|
||||||
# load the variables from pialert.conf
|
# load the variables from pialert.conf
|
||||||
code = compile(filename.read_text(), filename.name, "exec")
|
with open(filename, "r") as file:
|
||||||
|
code = compile(file.read(), filename, "exec")
|
||||||
|
|
||||||
confDict = {} # config dictionary
|
confDict = {} # config dictionary
|
||||||
exec(code, {"__builtins__": {}}, confDict)
|
exec(code, {"__builtins__": {}}, confDict)
|
||||||
return confDict
|
return confDict
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ def importConfigs (db):
|
|||||||
conf.APPRISE_HOST = ccd('APPRISE_HOST', '' , c_d, 'Apprise host URL', 'text', '', 'Apprise')
|
conf.APPRISE_HOST = ccd('APPRISE_HOST', '' , c_d, 'Apprise host URL', 'text', '', 'Apprise')
|
||||||
conf.APPRISE_URL = ccd('APPRISE_URL', '' , c_d, 'Apprise notification URL', 'text', '', 'Apprise')
|
conf.APPRISE_URL = ccd('APPRISE_URL', '' , c_d, 'Apprise notification URL', 'text', '', 'Apprise')
|
||||||
conf.APPRISE_PAYLOAD = ccd('APPRISE_PAYLOAD', 'html' , c_d, 'Payload type', 'text.select', "['html', 'text']", 'Apprise')
|
conf.APPRISE_PAYLOAD = ccd('APPRISE_PAYLOAD', 'html' , c_d, 'Payload type', 'text.select', "['html', 'text']", 'Apprise')
|
||||||
|
conf.APPRISE_SIZE = ccd('APPRISE_SIZE', 1024 , c_d, 'Payload size', 'integer', '', 'Apprise')
|
||||||
|
|
||||||
# NTFY
|
# NTFY
|
||||||
conf.REPORT_NTFY = ccd('REPORT_NTFY', False , c_d, 'Enable NTFY', 'boolean', '', 'NTFY', ['test'])
|
conf.REPORT_NTFY = ccd('REPORT_NTFY', False , c_d, 'Enable NTFY', 'boolean', '', 'NTFY', ['test'])
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class plugins_state:
|
|||||||
def run_plugin_scripts(db, runType, pluginsState = None):
|
def run_plugin_scripts(db, runType, pluginsState = None):
|
||||||
|
|
||||||
if pluginsState == None:
|
if pluginsState == None:
|
||||||
|
mylog('debug', ['[Plugins] pluginsState initialized '])
|
||||||
pluginsState = plugins_state()
|
pluginsState = plugins_state()
|
||||||
|
|
||||||
# Header
|
# Header
|
||||||
@@ -615,8 +616,6 @@ def process_plugin_events(db, plugin, pluginsState):
|
|||||||
|
|
||||||
db.commitDB()
|
db.commitDB()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return pluginsState
|
return pluginsState
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,34 +18,45 @@ 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)
|
payloadData = ''
|
||||||
payload = html
|
|
||||||
|
|
||||||
if conf.APPRISE_PAYLOAD == 'text':
|
# limit = 1024 * 1024 # 1MB limit (1024 bytes * 1024 bytes = 1MB)
|
||||||
payload = text
|
limit = conf.APPRISE_SIZE
|
||||||
|
|
||||||
|
# truncate size
|
||||||
|
if conf.APPRISE_PAYLOAD == 'html':
|
||||||
|
if len(msg.html) > limit:
|
||||||
|
payloadData = msg.html[:limit] + " <h1> (text was truncated)</h1>"
|
||||||
|
else:
|
||||||
|
payloadData = msg.html
|
||||||
|
if conf.APPRISE_PAYLOAD == 'text':
|
||||||
|
if len(msg.text) > limit:
|
||||||
|
payloadData = msg.text[:limit] + " (text was truncated)"
|
||||||
|
else:
|
||||||
|
payloadData = msg.text
|
||||||
|
|
||||||
|
# Define Apprise compatible payload (https://github.com/caronc/apprise-api#stateless-solution)
|
||||||
|
# payload = html
|
||||||
|
|
||||||
|
# if conf.APPRISE_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": payloadData
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Construct the curl command with input from the JSON payload
|
# try runnning a subprocess
|
||||||
curl_command = [
|
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", "-i", "-X", "POST", "-H", "Content-Type:application/json",
|
stdout, stderr = p.communicate()
|
||||||
conf.APPRISE_HOST
|
# write stdout and stderr into .log files for debugging if needed
|
||||||
]
|
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
|
# Log the stdout and stderr
|
||||||
logResult(completed_process.stdout, completed_process.stderr) # TO-DO should be changed to mylog
|
mylog('debug', [stdout, stderr]) # TO-DO should be changed to mylog
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
# An error occurred, handle it
|
# An error occurred, handle it
|
||||||
mylog('none', [e.output])
|
mylog('none', [e.output])
|
||||||
Reference in New Issue
Block a user