Untitled
unknown
plain_text
2 years ago
4.3 kB
5
Indexable
#include "httplib.hpp"
#include "json.hpp"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <thread>
#include <filesystem>
using namespace std;
httplib::SSLServer server("cert.pem", "key.pem");
string server_data;
const char* gov = R"(
<style>
h1 {
text-align: center;
}
</style>
<body>
<h1>
<b><big>Unauthorized Access</big></b>
</h1>
</body>
)";
class Connection {
public:
string ip = "";
int attempts = 0;
};
vector<Connection> connection_data;
// JSON dosyasındaki server_ip ve server_port değerlerini kontrol et
bool checkConfig() {
nlohmann::json config;
ifstream config_file("config.json");
if (config_file.is_open()) {
config_file >> config;
if (config.contains("server_ip") && config.contains("server_port")) {
server_data = "server|" + config["server_ip"].get<string>() + "\nport|" +
to_string(config["server_port"].get<int>()) +
"\ntype|1\nmeta|cmeta\nRTENDMARKERBS1001";
return true;
} else {
cout << "Hata: 'config.json' dosyasında 'server_ip' ve 'server_port' bulunamadı." << endl;
}
} else {
cout << "Hata: 'config.json' dosyası okunamıyor." << endl;
}
return false;
}
// JSON dosyasına bağlantı verilerini kaydet
void saveConnectionData() {
nlohmann::json j;
for (const auto& connection : connection_data) {
nlohmann::json entry;
entry["ip"] = connection.ip;
entry["attempts"] = connection.attempts;
j.push_back(entry);
}
ofstream w("connection.json");
w << setw(2) << j;
}
// JSON dosyasından bağlantı verilerini yükle
void loadConnectionData() {
nlohmann::json j;
ifstream r("connection.json");
if (r.is_open()) {
r >> j;
for (const auto& entry : j) {
Connection connection;
connection.ip = entry["ip"];
connection.attempts = entry["attempts"];
connection_data.push_back(connection);
}
}
}
void append_reset(string ip) {
while (true) {
for (auto& connection : connection_data) {
if (connection.ip == ip) {
if (connection.attempts > 3) {
this_thread::sleep_for(4s);
connection.attempts -= 3;
} else {
if (connection.attempts <= 0) continue; // Geç
this_thread::sleep_for(1800ms);
connection.attempts -= 1;
}
saveConnectionData();
}
}
this_thread::sleep_for(5ms);
}
}
bool handle_request(const httplib::Request req) {
bool new_connection = true;
for (auto& connection : connection_data) {
if (connection.ip == req.remote_addr) {
new_connection = false;
connection.attempts++;
if (connection.attempts > 3) {
backtasks.emplace_back(append_reset, req.remote_addr);
return false;
}
saveConnectionData();
break;
}
}
if (new_connection) {
Connection new_data;
new_data.ip = req.remote_addr;
new_data.attempts = 1;
connection_data.push_back(new_data);
saveConnectionData();
}
return true;
}
int main() {
if (!checkConfig()) {
cout << "Hata: Config dosyası kontrolü başarısız. Program sonlandırılıyor." << endl;
return 1;
}
cout << "Growtopia HTTPS developed by Ametsa77" << endl;
loadConnectionData();
server.Post(("/growtopia/server_data.php"), [&](const auto& req, auto& res) {
future<bool> Request = async(handle_request, req);
Request.wait();
if (!Request.get()) {
cout << req.remote_addr << " has blocked due to attack suspicion" << endl;
return;
}
cout << req.remote_addr << " has connected to server" << endl;
res.set_content(server_data, "text/plain");
});
server.Get(("/growtopia/server_data.php"), [&](const auto& req, auto& res) {
res.set_content(gov, "text/html");
});
server.listen("0.0.0.0", 443);
return 0;
}
Editor is loading...
Leave a Comment