-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new notification methods (telegram, webhooks, gotify) (#295)
- Loading branch information
Showing
37 changed files
with
1,655 additions
and
231 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
* | ||
!.gitignore | ||
* | ||
!.gitignore |
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,5 +2,4 @@ | |
|
||
#Webroot path | ||
$webPath = "/var/www/html/"; | ||
|
||
?> |
Large diffs are not rendered by default.
Oops, something went wrong.
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,69 @@ | ||
<?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["gotify_url"]) || $data["gotify_url"] == "" || | ||
!isset($data["token"]) || $data["token"] == "" | ||
) { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => translate('fill_mandatory_fields', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$enabled = $data["enabled"]; | ||
$url = $data["gotify_url"]; | ||
$token = $data["token"]; | ||
|
||
$query = "SELECT COUNT(*) FROM gotify_notifications"; | ||
$result = $db->querySingle($query); | ||
|
||
if ($result === false) { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => translate('error_saving_notifications', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
if ($result == 0) { | ||
$query = "INSERT INTO gotify_notifications (enabled, url, token) | ||
VALUES (:enabled, :url, :token)"; | ||
} else { | ||
$query = "UPDATE gotify_notifications | ||
SET enabled = :enabled, url = :url, token = :token"; | ||
} | ||
|
||
$stmt = $db->prepare($query); | ||
$stmt->bindValue(':enabled', $enabled, SQLITE3_INTEGER); | ||
$stmt->bindValue(':url', $url, SQLITE3_TEXT); | ||
$stmt->bindValue(':token', $token, SQLITE3_TEXT); | ||
|
||
if ($stmt->execute()) { | ||
$response = [ | ||
"success" => true, | ||
"message" => translate('notifications_settings_saved', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?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["days"]) || $data['days'] == "") { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => translate('fill_mandatory_fields', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$days = $data["days"]; | ||
$query = "SELECT COUNT(*) FROM notification_settings"; | ||
$result = $db->querySingle($query); | ||
|
||
if ($result === false) { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => translate('error_saving_notifications', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
if ($result == 0) { | ||
$query = "INSERT INTO notification_settings (days) | ||
VALUES (:days)"; | ||
} else { | ||
$query = "UPDATE notification_settings SET days = :days"; | ||
} | ||
|
||
$stmt = $db->prepare($query); | ||
$stmt->bindValue(':days', $days, SQLITE3_INTEGER); | ||
|
||
if ($stmt->execute()) { | ||
$response = [ | ||
"success" => true, | ||
"message" => translate('notifications_settings_saved', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => translate('error_saving_notifications', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} | ||
} | ||
} | ||
} else { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => "Invalid request method" | ||
]; | ||
echo json_encode($response); | ||
exit(); | ||
} |
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,69 @@ | ||
<?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["bot_token"]) || $data["bot_token"] == "" || | ||
!isset($data["chat_id"]) || $data["chat_id"] == "" | ||
) { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => translate('fill_mandatory_fields', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$enabled = $data["enabled"]; | ||
$bot_token = $data["bot_token"]; | ||
$chat_id = $data["chat_id"]; | ||
|
||
$query = "SELECT COUNT(*) FROM telegram_notifications"; | ||
$result = $db->querySingle($query); | ||
|
||
if ($result === false) { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => translate('error_saving_notifications', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
if ($result == 0) { | ||
$query = "INSERT INTO telegram_notifications (enabled, bot_token, chat_id) | ||
VALUES (:enabled, :bot_token, :chat_id)"; | ||
} else { | ||
$query = "UPDATE telegram_notifications | ||
SET enabled = :enabled, bot_token = :bot_token, chat_id = :chat_id"; | ||
} | ||
|
||
$stmt = $db->prepare($query); | ||
$stmt->bindValue(':enabled', $enabled, SQLITE3_INTEGER); | ||
$stmt->bindValue(':bot_token', $bot_token, SQLITE3_TEXT); | ||
$stmt->bindValue(':chat_id', $chat_id, SQLITE3_TEXT); | ||
|
||
if ($stmt->execute()) { | ||
$response = [ | ||
"success" => true, | ||
"message" => translate('notifications_settings_saved', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?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["webhook_url"]) || $data["webhook_url"] == "" || | ||
!isset($data["payload"]) || $data["payload"] == "" | ||
) { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => translate('fill_mandatory_fields', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$enabled = $data["enabled"]; | ||
$url = $data["webhook_url"]; | ||
$headers = $data["headers"]; | ||
$payload = $data["payload"]; | ||
|
||
$query = "SELECT COUNT(*) FROM webhook_notifications"; | ||
$result = $db->querySingle($query); | ||
|
||
if ($result === false) { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => translate('error_saving_notifications', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
if ($result == 0) { | ||
$query = "INSERT INTO webhook_notifications (enabled, url, headers, payload) | ||
VALUES (:enabled, :url, :headers, :payload)"; | ||
} else { | ||
$query = "UPDATE webhook_notifications | ||
SET enabled = :enabled, url = :url, headers = :headers, payload = :payload"; | ||
} | ||
|
||
$stmt = $db->prepare($query); | ||
$stmt->bindValue(':enabled', $enabled, SQLITE3_INTEGER); | ||
$stmt->bindValue(':url', $url, SQLITE3_TEXT); | ||
$stmt->bindValue(':headers', $headers, SQLITE3_TEXT); | ||
$stmt->bindValue(':payload', $payload, SQLITE3_TEXT); | ||
|
||
if ($stmt->execute()) { | ||
$response = [ | ||
"success" => true, | ||
"message" => translate('notifications_settings_saved', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => translate('error_saving_notifications', $i18n) | ||
]; | ||
echo json_encode($response); | ||
} | ||
} | ||
} | ||
} | ||
?> |
Oops, something went wrong.