Compare commits

..

3 Commits
dev ... my_msg

Author SHA1 Message Date
Aleksanov, Yuriy 070d2d19c3 msg2 2025-03-06 12:05:17 +03:00
Aleksanov, Yuriy 54da7e13b9 msg1 2025-03-06 05:03:47 +03:00
Aleksanov, Yuriy 6576afc671 msg 2025-03-06 05:00:49 +03:00
7 changed files with 81 additions and 1175 deletions

4
.gitignore vendored
View File

@ -1,4 +0,0 @@
.vscode
src/test.cpp
test
DosAtk

21
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,21 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}

View File

@ -1,37 +1,10 @@
# Как жить?
Регаемся на данном сайте, форкаем либу, пушим в свой форк и создаём merge request.
Либо просим у Серафима контрибьютора и сразу делаем ветку где надо (так даже лучше, не придётся мучаться с мержем из форка)
```
git clone https://gitea.serafimdev.com/serafim/dos # Клонируем репозиторий (замените на свой форк!)
git clone https://gitea.serafimdev.com/serafim/dos # Клонируем репозиторий
git checkout -b my_dns # Создаём ветку для реализации модуля my_dns
git add * # Добавляем написанный код в комит
git commit -m 'Написал код' # Комитим в локальную ветку
git push origin my_dns # Пушим свою ветку в репозиторий
# Теперь в интерфейсе https://gitea.serafimdev.com/serafim/dos создаём пул реквест и пишем мне в тг
```
# Компиляция
Для компиляции: `./build.py` (после компиляции запускает файл), либо ручками: `g++ src/DosAtk.cpp -o DosAtk -lcurl -lssl -lcrypto`
Если ошибка отсутствия заголовочных файлов, то нужно установить:
```
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libssl-dev
sudo apt-get install python3
sudo apt-get install nlohmann-json3-dev
```
# Запуск
Пример запуска:
```
sudo ./DosAtk -a flood -i 127.0.0.1 -p 800 # запуск заранее скомпилированной программы
sudo ./build.py -a flood -i 127.0.0.1 -p 800 # скомипилирует и запустит программу
```
Запускается только на Линухе!

View File

@ -1,21 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import subprocess
log_path = "/var/log/DosAtk"
if not os.path.exists(log_path):
if os.getuid() == 0: # Если уже root
os.system("mkdir -p /var/log && touch /var/log/DosAtk")
os.system("chmod 666 /var/log/DosAtk")
else:
os.system("sudo mkdir -p /var/log && sudo touch /var/log/DosAtk 2>/dev/null || true")
os.system("sudo chmod 666 /var/log/DosAtk 2>/dev/null || true")
# Компиляция
if subprocess.call(["g++", "src/DosAtk.cpp", "-o", "DosAtk", "-lcurl", "-lssl", "-lcrypto"]) != 0:
sys.exit(1)
# Запуск с аргументами
if len(sys.argv[1:]) > 0:
os.execvp("./DosAtk", ["./DosAtk"] + sys.argv[1:])

View File

@ -1,4 +0,0 @@
#!/bin/sh
set -e # if compilation fail next command will not be executed, so older version of programm will not be launched
g++ src/DosAtk.cpp -o DosAtk -lcurl -lssl -lcrypto
./DosAtk "$@"

58
my_msg.cpp Normal file
View File

@ -0,0 +1,58 @@
#include <iostream>
#include <string>
#include <curl/curl.h>
#include <cctype>
using namespace std;
string telegram_id;
string bot_token;
int my_msg(const string& msg) {
cout << msg << endl;
CURL* curl = curl_easy_init();
if (!curl) return 6;
string escaped_msg = escape_json(msg);
string chat_id_field;
if (is_numeric(telegram_id)) {
chat_id_field = "\"chat_id\": " + telegram_id;
} else {
chat_id_field = "\"chat_id\": \"" + telegram_id + "\"";
}
string json_data = "{" + chat_id_field + ", \"text\": \"" + escaped_msg + "\"}";
struct curl_slist* headers = nullptr;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, ("https://api.telegram.org/bot" + bot_token + "/sendMessage").c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_data.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl/7.68.0");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, [](void*, size_t size, size_t nmemb, void*) -> size_t {
return size * nmemb;
});
CURLcode res = curl_easy_perform(curl);
long http_code = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
if (res != CURLE_OK) return 5;
switch (http_code) {
case 200: return 0; // Успех
case 401: return 1; // Неверный токен
case 400: return 2; // Неверный chat_id
case 404: return 3; // Неверный URL (бот не найден)
default:
return 4; // Ошибка сервера (500)
}
}

File diff suppressed because it is too large Load Diff