120 lines
2.6 KiB
C++
120 lines
2.6 KiB
C++
/**
|
|
* @file log_parsing.hpp
|
|
* @author Lewis Price (lewis.e.price@outlook.com)
|
|
* @brief A series of functions for parsing the access logs of an Apache2 webserver.
|
|
* @version 1.0.0
|
|
* @date 2026-06-09
|
|
*
|
|
* @copyright Copyright (c) 2026
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
#include <string>
|
|
#include <vector>
|
|
#include "../ip_to_geo/ip_to_geo.hpp"
|
|
|
|
struct Entry {
|
|
std::string ip;
|
|
loc_data location;
|
|
std::string timestamp;
|
|
std::string request;
|
|
std::string status;
|
|
std::string bytes;
|
|
std::string referer;
|
|
std::string os;
|
|
std::string browser;
|
|
};
|
|
|
|
class p_logs {
|
|
private:
|
|
Entry entry;
|
|
std::vector<Entry> logs;
|
|
std::string url;
|
|
public:
|
|
/**
|
|
* @brief Construct a new parsed logs object
|
|
* Detailed explanation: This function takes in the absolute path to a .log file and parses the lines into individual "Entry"s. These Entrys are then stored into a vector that can then be accessed via getter functions.
|
|
* @param string
|
|
*/
|
|
p_logs(std::string);
|
|
|
|
std::vector<Entry> get_all_logs();
|
|
|
|
/**
|
|
* @brief Getter function for a specific Entry's IP
|
|
*
|
|
* @param int
|
|
* @return std::string
|
|
*/
|
|
std::string entryx_ip(int);
|
|
|
|
/**
|
|
* @brief Getter function for a specific Entry's time stamp
|
|
*
|
|
* @param int
|
|
* @return std::string
|
|
*/
|
|
std::string entryx_timestamp(int);
|
|
|
|
/**
|
|
* @brief Getter function for a specific Entry's request
|
|
*
|
|
* @param int
|
|
* @return std::string
|
|
*/
|
|
std::string entryx_request(int);
|
|
|
|
/**
|
|
* @brief Getter function for a specific Entry's status
|
|
*
|
|
* @param int
|
|
* @return std::string
|
|
*/
|
|
std::string entryx_status(int);
|
|
|
|
/**
|
|
* @brief Getter function for a specific Entry's byte size
|
|
*
|
|
* @param int
|
|
* @return std::string
|
|
*/
|
|
std::string entryx_bytes(int);
|
|
|
|
/**
|
|
* @brief Getter function for a specific Entry's referer
|
|
*
|
|
* @param int
|
|
* @return std::string
|
|
*/
|
|
std::string entryx_referer(int);
|
|
|
|
/**
|
|
* @brief Getter function for a specific Entry's OS info
|
|
*
|
|
* @param int
|
|
* @return std::string
|
|
*/
|
|
std::string entryx_os(int);
|
|
|
|
/**
|
|
* @brief Getter function for a specific Entry's browser info
|
|
*
|
|
* @param int
|
|
* @return std::string
|
|
*/
|
|
std::string entryx_browser(int);
|
|
|
|
/**
|
|
* @brief Getter function for a specific Entry's location info.
|
|
*
|
|
* @return loc_data
|
|
*/
|
|
loc_data entryx_location(int);
|
|
|
|
/**
|
|
* @brief Prints all parsed log entries
|
|
*
|
|
*/
|
|
void print_logs();
|
|
}; |