-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add discord and pushover as notification agents (#300)
fix: most error messages of the notifications endpoints would not reach the frontend
- Loading branch information
Showing
40 changed files
with
2,317 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
#Webroot path | ||
$webPath = "/var/www/html/"; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
require_once '../../includes/connect_endpoint.php'; | ||
session_start(); | ||
|
||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => translate('session_expired', $i18n) | ||
])); | ||
} | ||
|
||
if ($_SERVER["REQUEST_METHOD"] === "POST") { | ||
$postData = file_get_contents("php://input"); | ||
$data = json_decode($postData, true); | ||
|
||
if ( | ||
!isset($data["url"]) || $data["url"] == "" | ||
) { | ||
$response = [ | ||
"success" => false, | ||
"message" => translate('fill_mandatory_fields', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$enabled = $data["enabled"]; | ||
$webhook_url = $data["url"]; | ||
$bot_username = $data["bot_username"]; | ||
$bot_avatar_url = $data["bot_avatar"]; | ||
|
||
$query = "SELECT COUNT(*) FROM discord_notifications"; | ||
$result = $db->querySingle($query); | ||
|
||
if ($result === false) { | ||
$response = [ | ||
"success" => false, | ||
"message" => translate('error_saving_notifications', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
if ($result == 0) { | ||
$query = "INSERT INTO discord_notifications (enabled, webhook_url, bot_username, bot_avatar_url) | ||
VALUES (:enabled, :webhook_url, :bot_username, :bot_avatar_url)"; | ||
} else { | ||
$query = "UPDATE pushover_notifications | ||
SET enabled = :enabled, webhook_url = :webhook_url, bot_username = :bot_username, bot_avatar_url = :bot_avatar_url"; | ||
} | ||
|
||
$stmt = $db->prepare($query); | ||
$stmt->bindValue(':enabled', $enabled, SQLITE3_INTEGER); | ||
$stmt->bindValue(':webhook_url', $webhook_url, SQLITE3_TEXT); | ||
$stmt->bindValue(':bot_username', $bot_username, SQLITE3_TEXT); | ||
$stmt->bindValue(':bot_avatar_url', $bot_avatar_url, SQLITE3_TEXT); | ||
|
||
if ($stmt->execute()) { | ||
$response = [ | ||
"success" => true, | ||
"message" => translate('notifications_settings_saved', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$response = [ | ||
"success" => false, | ||
"message" => translate('error_saving_notifications', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} | ||
} | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.