mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 01:26:11 -08:00
Discord compatible webhooks + bugfix of redirect after logon
This commit is contained in:
@@ -1447,7 +1447,7 @@ def email_reporting ():
|
|||||||
print (' Skip Apprise...')
|
print (' Skip Apprise...')
|
||||||
if REPORT_WEBHOOK :
|
if REPORT_WEBHOOK :
|
||||||
print (' Sending report by webhook...')
|
print (' Sending report by webhook...')
|
||||||
send_webhook (json_final)
|
send_webhook (json_final, mail_text)
|
||||||
else :
|
else :
|
||||||
print (' Skip webhook...')
|
print (' Skip webhook...')
|
||||||
if REPORT_NTFY :
|
if REPORT_NTFY :
|
||||||
@@ -1600,7 +1600,20 @@ def SafeParseGlobalBool(boolVariable):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def send_webhook (_json):
|
def send_webhook (_json, _html):
|
||||||
|
|
||||||
|
# payload type
|
||||||
|
try:
|
||||||
|
webhookPayload = WEBHOOK_PAYLOAD
|
||||||
|
except NameError: # variable not defined, use a default
|
||||||
|
webhookPayload = 'json'
|
||||||
|
|
||||||
|
# use data type based on specified payload type
|
||||||
|
if webhookPayload == 'json':
|
||||||
|
payloadData = _json
|
||||||
|
if webhookPayload == 'html':
|
||||||
|
payloadData = _html
|
||||||
|
|
||||||
#Define slack-compatible payload
|
#Define slack-compatible payload
|
||||||
_json_payload={
|
_json_payload={
|
||||||
"username": "Pi.Alert",
|
"username": "Pi.Alert",
|
||||||
@@ -1608,17 +1621,20 @@ def send_webhook (_json):
|
|||||||
"attachments": [{
|
"attachments": [{
|
||||||
"title": "Pi.Alert Notifications",
|
"title": "Pi.Alert Notifications",
|
||||||
"title_link": REPORT_DASHBOARD_URL,
|
"title_link": REPORT_DASHBOARD_URL,
|
||||||
"text": _json
|
"text": payloadData
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Using the Slack-Compatible Webhook endpoint for Discord so that the same payload can be used for both
|
# Using the Slack-Compatible Webhook endpoint for Discord so that the same payload can be used for both
|
||||||
if(WEBHOOK_URL.startswith('https://discord.com/api/webhooks/') and not WEBHOOK_URL.endswith("/slack")):
|
if(WEBHOOK_URL.startswith('https://discord.com/api/webhooks/') and not WEBHOOK_URL.endswith("/slack")):
|
||||||
_WEBHOOK_URL = f"{WEBHOOK_URL}/slack"
|
_WEBHOOK_URL = f"{WEBHOOK_URL}/slack"
|
||||||
|
curlParams = ["curl","-i","-H", "Content-Type:application/json" ,"-d", json.dumps(_json_payload), _WEBHOOK_URL]
|
||||||
else:
|
else:
|
||||||
_WEBHOOK_URL = WEBHOOK_URL
|
_WEBHOOK_URL = WEBHOOK_URL
|
||||||
|
curlParams = ["curl","-i","-X", "GET" ,"-H", "Content-Type:application/json" ,"-d", json.dumps(_json_payload), _WEBHOOK_URL]
|
||||||
|
|
||||||
p = subprocess.Popen(["curl","-i","-X", "GET" ,"-H", "Content-Type:application/json" ,"-d", json.dumps(_json_payload), _WEBHOOK_URL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
# execute CURL call
|
||||||
|
p = subprocess.Popen(curlParams, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ REPORT_DASHBOARD_URL = 'http://pi.alert/'
|
|||||||
# ----------------------
|
# ----------------------
|
||||||
REPORT_WEBHOOK = False
|
REPORT_WEBHOOK = False
|
||||||
WEBHOOK_URL = 'http://n8n.local:5555/webhook-test/aaaaaaaa-aaaa-aaaa-aaaaa-aaaaaaaaaaaa'
|
WEBHOOK_URL = 'http://n8n.local:5555/webhook-test/aaaaaaaa-aaaa-aaaa-aaaaa-aaaaaaaaaaaa'
|
||||||
|
# webhook payload data format for the "body > attachements > text" attribute in https://github.com/jokob-sk/Pi.Alert/blob/main/docs/webhook_json_sample.json
|
||||||
|
# supported values: 'json' or 'html'
|
||||||
|
# e.g.: for discord use 'html'
|
||||||
|
WEBHOOK_PAYLOAD = 'json'
|
||||||
|
|
||||||
# Apprise settings
|
# Apprise settings
|
||||||
#-----------------------
|
#-----------------------
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ session_start();
|
|||||||
|
|
||||||
if ($_SESSION["login"] != 1)
|
if ($_SESSION["login"] != 1)
|
||||||
{
|
{
|
||||||
header('Location: /pialert/index.php');
|
header('Location: index.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,13 +77,6 @@ if (($_SESSION["login"] == 1) || ($Pia_Password == $_COOKIE["PiAler_SaveLogin"])
|
|||||||
if (isset($_POST['PWRemember'])) {setcookie("PiAler_SaveLogin", hash('sha256',$_POST["loginpassword"]), time()+604800);}
|
if (isset($_POST['PWRemember'])) {setcookie("PiAler_SaveLogin", hash('sha256',$_POST["loginpassword"]), time()+604800);}
|
||||||
}
|
}
|
||||||
|
|
||||||
// active Session or valid cookie (cookie not extends)
|
|
||||||
if (($_SESSION["login"] == 1) || ($Pia_Password == $_COOKIE["PiAler_SaveLogin"]))
|
|
||||||
{
|
|
||||||
header('Location: /pialert/devices.php');
|
|
||||||
$_SESSION["login"] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no active session, cookie not checked
|
// no active session, cookie not checked
|
||||||
if ($_SESSION["login"] != 1)
|
if ($_SESSION["login"] != 1)
|
||||||
{
|
{
|
||||||
@@ -181,7 +174,7 @@ if ($ENABLED_DARKMODE === True) {
|
|||||||
|
|
||||||
<div id="myDIV" class="box-body" style="margin-top: 50px; <?php echo $login_display_mode;?>">
|
<div id="myDIV" class="box-body" style="margin-top: 50px; <?php echo $login_display_mode;?>">
|
||||||
<div class="alert alert-<?php echo $login_mode;?> alert-dismissible">
|
<div class="alert alert-<?php echo $login_mode;?> alert-dismissible">
|
||||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true"><3E></button>
|
<button type="button" class="close" data-dismiss="alert" aria-hidden="true"><3E></button>
|
||||||
<h4><i class="icon fa <?php echo $login_icon;?>"></i><?php echo $login_headline;?></h4>
|
<h4><i class="icon fa <?php echo $login_icon;?>"></i><?php echo $login_headline;?></h4>
|
||||||
<p><?php echo $login_info;?></p>
|
<p><?php echo $login_info;?></p>
|
||||||
<p><?php echo $pia_lang['Login_Psw_run'];?><br><span style="border: solid 1px yellow; padding: 2px;">./reset_password.sh <?php echo $pia_lang['Login_Psw_new'];?></span><br><?php echo $pia_lang['Login_Psw_folder'];?></p>
|
<p><?php echo $pia_lang['Login_Psw_run'];?><br><span style="border: solid 1px yellow; padding: 2px;">./reset_password.sh <?php echo $pia_lang['Login_Psw_new'];?></span><br><?php echo $pia_lang['Login_Psw_folder'];?></p>
|
||||||
|
|||||||
Reference in New Issue
Block a user