adding telegram bot

This commit is contained in:
jakani24
2024-03-12 13:58:45 +01:00
parent b219fbab8e
commit 99a7cb7068
10 changed files with 134 additions and 75 deletions

View File

@@ -94,8 +94,7 @@
"RelativeToolTip": "security.cpp",
"ViewState": "AQIAABsAAAAAAAAAAAAAADoAAAA2AAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-03-12T10:18:22.033Z",
"EditorCaption": ""
"WhenOpened": "2024-03-12T10:18:22.033Z"
},
{
"$type": "Document",
@@ -107,8 +106,7 @@
"RelativeToolTip": "permissions.cpp",
"ViewState": "AQIAAAQAAAAAAAAAAAAIwDsAAAAAAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-03-12T10:18:17.369Z",
"EditorCaption": ""
"WhenOpened": "2024-03-12T10:18:17.369Z"
},
{
"$type": "Document",
@@ -120,8 +118,7 @@
"RelativeToolTip": "app_ctrl.cpp",
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAwAAAAPAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-03-12T10:10:59.685Z",
"EditorCaption": ""
"WhenOpened": "2024-03-12T10:10:59.685Z"
},
{
"$type": "Document",
@@ -133,8 +130,7 @@
"RelativeToolTip": "check_process.cpp",
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAYAAAARAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-03-10T14:40:03.094Z",
"EditorCaption": ""
"WhenOpened": "2024-03-10T14:40:03.094Z"
},
{
"$type": "Document",
@@ -146,8 +142,7 @@
"RelativeToolTip": "md5hash.cpp",
"ViewState": "AQIAACQAAAAAAAAAAAAAADUAAAA1AAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-03-09T19:22:09.647Z",
"EditorCaption": ""
"WhenOpened": "2024-03-09T19:22:09.647Z"
},
{
"$type": "Document",
@@ -159,8 +154,7 @@
"RelativeToolTip": "check_dir.cpp",
"ViewState": "AQIAAEkAAAAAAAAAAAAIwHYAAACFAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-02-25T13:36:05.414Z",
"EditorCaption": ""
"WhenOpened": "2024-02-25T13:36:05.414Z"
},
{
"$type": "Document",
@@ -172,8 +166,7 @@
"RelativeToolTip": "log.h",
"ViewState": "AQIAAFMAAAAAAAAAAAAkwFsAAAAjAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
"WhenOpened": "2024-02-25T09:02:55.874Z",
"EditorCaption": ""
"WhenOpened": "2024-02-25T09:02:55.874Z"
},
{
"$type": "Document",
@@ -185,8 +178,7 @@
"RelativeToolTip": "log.cpp",
"ViewState": "AQIAAAAAAAAAAAAAAAAAAB8AAAAFAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-02-25T09:08:59.07Z",
"EditorCaption": ""
"WhenOpened": "2024-02-25T09:08:59.07Z"
},
{
"$type": "Document",
@@ -198,8 +190,7 @@
"RelativeToolTip": "local_com.cpp",
"ViewState": "AQIAAAAAAAAAAAAAAAAAADYAAAAYAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-01-28T20:40:06.217Z",
"EditorCaption": ""
"WhenOpened": "2024-01-28T20:40:06.217Z"
},
{
"$type": "Document",
@@ -211,8 +202,7 @@
"RelativeToolTip": "settings.cpp",
"ViewState": "AQIAAMwAAAAAAAAAAAAIwAMBAAAAAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-01-28T20:40:06.264Z",
"EditorCaption": ""
"WhenOpened": "2024-01-28T20:40:06.264Z"
},
{
"$type": "Document",
@@ -224,8 +214,7 @@
"RelativeToolTip": "thread_ctrl.cpp",
"ViewState": "AQIAABUAAAAAAAAAAAAAADMAAAAFAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-01-28T20:40:06.264Z",
"EditorCaption": ""
"WhenOpened": "2024-01-28T20:40:06.264Z"
},
{
"$type": "Document",
@@ -237,8 +226,7 @@
"RelativeToolTip": "scan.cpp",
"ViewState": "AQIAAAAAAAAAAAAAAAAAAKEAAAAAAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-01-28T20:40:06.248Z",
"EditorCaption": ""
"WhenOpened": "2024-01-28T20:40:06.248Z"
},
{
"$type": "Document",
@@ -250,8 +238,7 @@
"RelativeToolTip": "client_backend.cpp",
"ViewState": "AQIAADMAAAAAAAAAAAAAAFsAAAAhAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-01-28T20:40:06.279Z",
"EditorCaption": ""
"WhenOpened": "2024-01-28T20:40:06.279Z"
},
{
"$type": "Document",
@@ -263,8 +250,7 @@
"RelativeToolTip": "update.cpp",
"ViewState": "AQIAACwAAAAAAAAAAAAkwFIAAAAWAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-01-28T20:40:06.248Z",
"EditorCaption": ""
"WhenOpened": "2024-01-28T20:40:06.248Z"
},
{
"$type": "Document",
@@ -276,8 +262,7 @@
"RelativeToolTip": "local_schedule.cpp",
"ViewState": "AQIAAGYAAAAAAAAAAAAAAJoAAAAaAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-01-28T20:40:06.279Z",
"EditorCaption": ""
"WhenOpened": "2024-01-28T20:40:06.279Z"
},
{
"$type": "Document",
@@ -289,8 +274,7 @@
"RelativeToolTip": "queue _ctrl.cpp",
"ViewState": "AQIAAAAAAAAAAAAAAAAAACsAAAABAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-01-28T20:40:06.295Z",
"EditorCaption": ""
"WhenOpened": "2024-01-28T20:40:06.295Z"
},
{
"$type": "Document",
@@ -302,8 +286,7 @@
"RelativeToolTip": "connect.cpp",
"ViewState": "AQIAABQAAAAAAAAAAAAkwEAAAAAVAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-01-28T20:40:06.315Z",
"EditorCaption": ""
"WhenOpened": "2024-01-28T20:40:06.315Z"
},
{
"$type": "Document",
@@ -313,7 +296,7 @@
"RelativeDocumentMoniker": "virus_ctrl.cpp",
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\virus_ctrl.cpp",
"RelativeToolTip": "virus_ctrl.cpp",
"ViewState": "AQIAADAAAAAAAAAAAAAAAEkAAAA+AAAA",
"ViewState": "AQIAADAAAAAAAAAAAAAAAFIAAABzAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2024-02-18T12:49:41.861Z",
"EditorCaption": ""

View File

@@ -71,26 +71,6 @@ int virus_ctrl_process( const char* id) {
log(LOGLEVEL::ERR, "[virus_ctrl_process()]:Error while removing infected file: ", path," ",hash);
else
log(LOGLEVEL::VIRUS, "[virus_ctrl_process()]:Removed Virus: ", path, " ", hash, "");
//call the server and say him that we have found a virus.
url[0] = '\0';
if (get_setting("server:server_url", url) == 0 or strcmp(url, "nan") == 0) {
strcat_s(url, 1000, "/api/php/virus/notify_virus.php?");
strcat_s(url, 1000, "file=");
strcat_s(url, 1000, url_encode(path));
strcat_s(url, 1000, "&hash=");
strcat_s(url, 1000, hash);
strcat_s(url, 1000, "&action=");
strcat_s(url, 1000, "remove");
strcat_s(url, 1000, "&machine_id=");
strcat_s(url, 1000, get_machineid(SECRETS));
strcat_s(url, 1000, "&apikey=");
strcat_s(url, 1000, get_apikey(SECRETS));
if (connect_to_srv(url, server_response, 100, get_setting("communication:unsafe_tls")) != 0 or strcmp("wrt_ok", server_response) != 0)
log(LOGLEVEL::ERR, "[virus_ctrl_process()]:Error while notifying server about virus: ", path, " ", hash);
}
else {
log(LOGLEVEL::ERR, "[virus_ctrl_process()]:Error while notifying server about virus: ", path, " ", hash);
}
break;
case 2://quarantine
@@ -101,26 +81,6 @@ int virus_ctrl_process( const char* id) {
log(LOGLEVEL::ERR, "[virus_ctrl_process()]:Error while quarantining infected file: ", path," ",hash);
else
log(LOGLEVEL::VIRUS, "[virus_ctrl_process()]:Quarantined Virus: ", path, " ", hash, " to ", quarantine_path);
//call the server and say him that we have found a virus.
url[0] = '\0';
if (get_setting("server:server_url", url) == 0 or strcmp(url, "nan") == 0) {
strcat_s(url, 1000, "/api/php/virus/notify_virus.php?");
strcat_s(url, 1000, "file=");
strcat_s(url, 1000, url_encode(path));
strcat_s(url, 1000, "&hash=");
strcat_s(url, 1000, hash);
strcat_s(url, 1000, "&action=");
strcat_s(url, 1000, "quarantine");
strcat_s(url, 1000, "&machine_id=");
strcat_s(url, 1000, get_machineid(SECRETS));
strcat_s(url, 1000, "&apikey=");
strcat_s(url, 1000, get_apikey(SECRETS));
if (connect_to_srv(url, server_response, 100, get_setting("communication:unsafe_tls")) != 0 or strcmp("wrt_ok", server_response) != 0)
log(LOGLEVEL::ERR, "[virus_ctrl_process()]:Error while notifying server about virus: ", path, " ", hash);
}
else {
log(LOGLEVEL::ERR, "[virus_ctrl_process()]:Error while notifying server about virus: ", path, " ", hash);
}
break;
case 3://ignore

View File

@@ -0,0 +1,116 @@
<?php
session_start();
// Check if the user is logged in
if (!isset($_SESSION['username']) or !isset($_SESSION["login"])) {
// Redirect to the login page or handle unauthorized access
header("Location: /login.php");
exit();
}
$username = $_SESSION['username'];
$perms = $_SESSION["perms"];
$email = $_SESSION["email"];
if($perms[5]!=="1"){
header("location:/system/insecure_zone/php/no_access.php");
$block=1;
exit();
}else{
$block=0;
}
$setting_virus_ctrl_virus_found_action = "not configured yet";
$setting_virus_ctrl_virus_process_found_kill = 0;
$setting_communication_unsafe_tls = "not configured yet";
$setting_server_server_url="not configured yet";
$setting_rtp_folder_scan_status=0;
$setting_rtp_process_scan_status=0;
include "../../../config.php";
$conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD,$DB_DATABASE);
if ($conn->connect_error) {
$success=0;
die("Connection failed: " . $conn->connect_error);
}
//we store all the functions like update,safe,load etc in this file, because else "client_settings.php" will get way to big
include "client_settings_functions.php";
if(isset($_GET["update"])){
safe_settings();
}
if(isset($_GET["delete"])){
delete_item($_GET["db"],$_GET["delete"]);
}
if(isset($_GET["add"])){
add_item($_GET["add"],$_GET["value"],$_GET["field"]);
}
load_settings();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<title>Change Password</title>
</head>
<body>
<script>
function update_textfield(id,name){
var element = document.getElementById(id);
var value = element.value;
fetch('server_settings.php?update='+name+'&value='+value);
}
<?php
include "../../../config.php";
$conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD,$DB_DATABASE);
if ($conn->connect_error) {
$success=0;
die("Connection failed: " . $conn->connect_error);
}
if(isset($_GET["update"])){
$value=htmlspecialchars($_GET["value"]);
$name=htmlspecialchars($_GET["update"]);
if($_GET["update"]=="telegram_bot"){
$stmt = $conn->prepare("INSERT INTO settings (name,value) VALUES (?,?) ON DUPLICATE KEY UPDATE value = ?;");
$stmt->bind_param("sss",$name,$value,$value);
$stmt->execute();
$stmt->close();
}
}
//load settings
$sql = "SELECT * FROM settings WHERE name = 'telegram_bot'";
$stmt = $conn->prepare($sql);
// Execute the statement
$stmt->execute();
// Get the result
$telegram_bot="";
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if($result->num_rows > 0){
$telegram_bot=$row["value"];
}
$stmt -> close();
?>
//exec("curl \"https://api.telegram.org/$api/sendMessage?chat_id=$telegram_id&text=$text\"");
</script>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4>Server settings</h4>
</div>
<div class="card-body">
<h7>Telegram Bot API-key</h7>
<input type="text" id="telegram_bot" class="form-control" name="telegram_bot" value="<?php echo($telegram_bot); ?>" oninput="update_textfield('telegram_bot','telegram_bot');">
</div>
</div>
</div>
</div>
</div>
</body>
</html>