From e4badb6e68cde10fd60092f4f5e5f077d4dc5746 Mon Sep 17 00:00:00 2001 From: jakani24 Date: Tue, 12 Mar 2024 15:28:51 +0100 Subject: [PATCH] adding support for telegram --- .../api/php/notifications/sendmessage.php | 46 +++++++++++++++++++ .../cyberhex-code/install/create_db.php | 3 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/server/cyberhex-code/api/php/notifications/sendmessage.php diff --git a/src/server/cyberhex-code/api/php/notifications/sendmessage.php b/src/server/cyberhex-code/api/php/notifications/sendmessage.php new file mode 100644 index 0000000..bb8634f --- /dev/null +++ b/src/server/cyberhex-code/api/php/notifications/sendmessage.php @@ -0,0 +1,46 @@ + /dev/null &'); + +function send($message){ + //get apikey of telegram bot + $sql = "SELECT value FROM settings WHERE name = 'telegram_bot'"; + $stmt = $conn->prepare($sql); + // Execute the statement + $stmt->execute(); + // Get the result + $telegram_bot=""; + $result = $stmt->get_result(); + if ($result->num_rows > 0) { + // Fetch the first row as an associative array + $row = $result->fetch_assoc(); + // Extract the value of the 'value' column + $telegram_bot = $row['value']; + // Do something with the value, for example: + echo "Telegram Bot API Key: " . $telegram_bot; + } +} +?> + + + + /* + //if able to, send a telegram notification to user + $sql = "SELECT telegram_id FROM users"; + $stmt = $conn->prepare($sql); + // Execute the statement + $stmt->execute(); + // Get the result + $telegram_id=""; + $result = $stmt->get_result(); + + while($row = $result->fetch_assoc()) { + $telegram_id=$row["telegram_id"]; + //exec("curl \"https://api.telegram.org/$api/sendMessage?chat_id=$telegram_id&text=$text\""); + $url="https://api.telegram.org/$"; + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $fileContents = curl_exec($ch); + } + $stmt -> close(); + */ \ No newline at end of file diff --git a/src/server/cyberhex-code/install/create_db.php b/src/server/cyberhex-code/install/create_db.php index 45e5596..7876a9e 100644 --- a/src/server/cyberhex-code/install/create_db.php +++ b/src/server/cyberhex-code/install/create_db.php @@ -63,7 +63,8 @@ email VARCHAR(255) NOT NULL, perms VARCHAR(255), password VARCHAR(255), - 2fa VARCHAR(255) + 2fa VARCHAR(255), + telegram_id VARCHAR(255) )"; if ($conn->query($sql) === TRUE) {