added location info into the log_parsing output. Now when the access logs are parsed, the geo_data is now included in the p_logs print function for each entry.

This commit is contained in:
rapturate
2026-06-08 14:25:11 -04:00
parent 1a129a5999
commit bdaf8451a0
6 changed files with 41 additions and 18 deletions

View File

@@ -5,7 +5,7 @@
#include <cstdlib>
#include <map>
#include <string>
#include <GeoLite2PP.hpp>
#include "../third_party/include/GeoLite2PP.hpp"
void load_env_file(const std::string& env_path) {
std::ifstream file(env_path);
@@ -30,7 +30,7 @@ void load_env_file(const std::string& env_path) {
}
}
std::string iplookup(const std::string& ip) {
loc_data iplookup(const std::string& ip) {
// 1. Load variables from the local .env file
load_env_file();
@@ -41,16 +41,19 @@ std::string iplookup(const std::string& ip) {
std::string db_path = (env_db_path != nullptr) ? env_db_path : "data/GeoLite2-City.mmdb";
std::string geo_string = "";
loc_data location;
try {
GeoLite2PP::DB db(db_path);
std::map<std::string, std::string> geo_data = db.get_all_fields(ip, "en");
geo_string = geo_data["country"] + "," + geo_data["subdivision"] + "," + geo_data["city"] + "," + geo_data["latitude"] + "," + geo_data["longitude"] + "\n";
location.country = geo_data["country"];
location.subdivision = geo_data["subdivision"];
location.city = geo_data["city"];
location.latitutde = geo_data["latitude"];
location.longitude = geo_data["longitude"];
}
catch (const std::exception& e) {
std::cerr << "Database failed to load: " << e.what() << std::endl;
}
return geo_string;
return location;
};