pprogress
This commit is contained in:
		
							parent
							
								
									a7a34db884
								
							
						
					
					
						commit
						76b8da4685
					
				
							
								
								
									
										33
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								src/main.c
									
									
									
									
									
								
							@ -15,19 +15,22 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 | 
				
			|||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <dirent.h>
 | 
					#include <dirent.h> // library für Interaktion mit Ordnerstrukturen
 | 
				
			||||||
#include <sys/stat.h>
 | 
					#include <sys/stat.h> // library für is_directory: Unterscheidung zwischen Dateien und Ordnern
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MAX_LINE 2048
 | 
					#define MAX_LINE_LENGTH_BUF 2048
 | 
				
			||||||
#define INITIAL_ENTRIES 1000
 | 
					#define INITIAL_ENTRIES 1000 // globale Variable zur initialen Speicherallokation in allocate_initial_memory(). Wird falls nötig um GROWTH_FACTOR erweitert
 | 
				
			||||||
#define GROWTH_FACTOR 2
 | 
					#define GROWTH_FACTOR 2 // wird in expand_memory_if_needed() genutzt, um den Speicher zu vergrößern
 | 
				
			||||||
#define MAX_FILTERS 100
 | 
					#define MAX_FILTERS 100
 | 
				
			||||||
 | 
					#define MAX_URL_PATH_LENGTH 512
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// definiert Variablen für den Filtermodus. FILTER_INCLUDE=0, FILTER_EXCLUDE=1. Verbessert die Lesbarkeit des Codes.
 | 
				
			||||||
typedef enum {
 | 
					typedef enum {
 | 
				
			||||||
    FILTER_INCLUDE,
 | 
					    FILTER_INCLUDE,
 | 
				
			||||||
    FILTER_EXCLUDE
 | 
					    FILTER_EXCLUDE
 | 
				
			||||||
} filter_mode_t;
 | 
					} filter_mode_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// struct für die Darstellung von Timestamps. Die granulare Trennung in verschiedene int-Werte macht die spätere Verarbeitung modular anpassbar/erweiterbar und erleichtert die Verarbeitung.
 | 
				
			||||||
struct simple_time {
 | 
					struct simple_time {
 | 
				
			||||||
    int day;
 | 
					    int day;
 | 
				
			||||||
    int month;
 | 
					    int month;
 | 
				
			||||||
@ -37,31 +40,36 @@ struct simple_time {
 | 
				
			|||||||
    int second;
 | 
					    int second;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Struktur für die Darstellung eines Standard-NGINX-Logeintrags.
 | 
				
			||||||
struct log_entry {
 | 
					struct log_entry {
 | 
				
			||||||
    char ip_address[50];
 | 
					    char ip_address[50]; // ausreichende Längenbegrenzung für IP-Adressen. Könnte theoretisch auch ipv6 (ungetestet)
 | 
				
			||||||
    char request_method[10];
 | 
					    char request_method[10]; // GET, POST, PUT, DELETE, PROPFIND ...
 | 
				
			||||||
    char url_path[200];
 | 
					    char url_path[MAX_URL_PATH_LENGTH]; // Pfade können lang werden, insbesodere bei base64-Strings wie oft in modernen Applikationen oder Malware verwendet
 | 
				
			||||||
    int status_code;
 | 
					    int status_code;
 | 
				
			||||||
    int bytes_sent;
 | 
					    int bytes_sent;
 | 
				
			||||||
    struct simple_time time;
 | 
					    struct simple_time time;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Struktur für einen Status-Filtereintrag mit Inhalt & Modus
 | 
				
			||||||
struct status_filter {
 | 
					struct status_filter {
 | 
				
			||||||
    int code;
 | 
					    int code;
 | 
				
			||||||
    filter_mode_t mode;
 | 
					    filter_mode_t mode;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// für IP-Adressen
 | 
				
			||||||
struct ip_filter {
 | 
					struct ip_filter {
 | 
				
			||||||
    char ip_address[50];
 | 
					    char ip_address[50];
 | 
				
			||||||
    filter_mode_t mode;
 | 
					    filter_mode_t mode;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// für Zeit, Start- und Endzeit
 | 
				
			||||||
struct time_filter {
 | 
					struct time_filter {
 | 
				
			||||||
    struct simple_time start_time;
 | 
					    struct simple_time start_time;
 | 
				
			||||||
    struct simple_time end_time;
 | 
					    struct simple_time end_time;
 | 
				
			||||||
    filter_mode_t mode;
 | 
					    filter_mode_t mode;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Struktur zum erhalten aller Filtereinträge, kann im Dialogbetrieb bearbeitet werden. Mit Zähler.
 | 
				
			||||||
struct filter_system {
 | 
					struct filter_system {
 | 
				
			||||||
    struct status_filter status_filters[MAX_FILTERS];
 | 
					    struct status_filter status_filters[MAX_FILTERS];
 | 
				
			||||||
    int status_count;
 | 
					    int status_count;
 | 
				
			||||||
@ -72,18 +80,21 @@ struct filter_system {
 | 
				
			|||||||
    struct time_filter time_filters[MAX_FILTERS];
 | 
					    struct time_filter time_filters[MAX_FILTERS];
 | 
				
			||||||
    int time_count;
 | 
					    int time_count;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    int combination_mode;
 | 
					    int combination_mode; // 0=AND-Filter oder 1=OR-Filter
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Initialisierung eines Arrays für die Logeinträge und weiterer Startvariablen
 | 
				
			||||||
struct log_entry *all_entries = NULL;
 | 
					struct log_entry *all_entries = NULL;
 | 
				
			||||||
int max_entries = 0;
 | 
					int max_entries = 0;
 | 
				
			||||||
int total_entries = 0;
 | 
					int total_entries = 0;
 | 
				
			||||||
struct filter_system filters = {0};
 | 
					struct filter_system filters = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Helper für die Erkennung von Leerzeichen
 | 
				
			||||||
int is_space(char c) {
 | 
					int is_space(char c) {
 | 
				
			||||||
    return (c == ' ' || c == '\t');
 | 
					    return (c == ' ' || c == '\t');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Helper zum Überspringen von Leerzeichen, gibt den Pointer für das nächste nicht-Leerzeichen zurück. Nötig für strtok-Parser.
 | 
				
			||||||
char* skip_spaces(char* str) {
 | 
					char* skip_spaces(char* str) {
 | 
				
			||||||
    while (is_space(*str)) {
 | 
					    while (is_space(*str)) {
 | 
				
			||||||
        str++;
 | 
					        str++;
 | 
				
			||||||
@ -91,6 +102,7 @@ char* skip_spaces(char* str) {
 | 
				
			|||||||
    return str;
 | 
					    return str;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO
 | 
				
			||||||
void copy_until_space(char* destination, char* source, int max_length) {
 | 
					void copy_until_space(char* destination, char* source, int max_length) {
 | 
				
			||||||
    int i = 0;
 | 
					    int i = 0;
 | 
				
			||||||
    while (source[i] != ' ' && source[i] != '\0' && i < max_length - 1) {
 | 
					    while (source[i] != ' ' && source[i] != '\0' && i < max_length - 1) {
 | 
				
			||||||
@ -100,6 +112,7 @@ void copy_until_space(char* destination, char* source, int max_length) {
 | 
				
			|||||||
    destination[i] = '\0';
 | 
					    destination[i] = '\0';
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// NGINX speichert Timestamps mit Monatskürzel. Umwandlung in Zahlen für maschinelle Verarbeitung.
 | 
				
			||||||
int month_name_to_number(char* month_name) {
 | 
					int month_name_to_number(char* month_name) {
 | 
				
			||||||
    if (strncmp(month_name, "Jan", 3) == 0) return 1;
 | 
					    if (strncmp(month_name, "Jan", 3) == 0) return 1;
 | 
				
			||||||
    if (strncmp(month_name, "Feb", 3) == 0) return 2;
 | 
					    if (strncmp(month_name, "Feb", 3) == 0) return 2;
 | 
				
			||||||
@ -343,7 +356,7 @@ void load_regular_file(char* filename) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    printf("Lade Datei: %s\n", filename);
 | 
					    printf("Lade Datei: %s\n", filename);
 | 
				
			||||||
    char line[MAX_LINE];
 | 
					    char line[MAX_LINE_LENGTH_BUF];
 | 
				
			||||||
    int loaded_from_this_file = 0;
 | 
					    int loaded_from_this_file = 0;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    while (fgets(line, sizeof(line), file) != NULL) {
 | 
					    while (fgets(line, sizeof(line), file) != NULL) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user