This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Online mode starts reading logs from the end of file and collect new …
…logs until the process is stopped. Offline mode starts reading logs from the start to the end of file and stops. The new online-resume mode resumes from where it was stopped. When a log is "submitted" (recorded to file, displayed to screen or send to syslog), a cursor file with the next position is updated. The cursor file is named <firewall_log_file>.cursor. Mode should be specified in configuration file (not ONLINE_MODE anymore) : MODE=OFFLINE MODE=ONLINE MODE=ONLINE-RESUME Or in command-line: --offline --online --online-resume
- Loading branch information
Gabriel MACHADO
committed
Oct 31, 2017
1 parent
adfca03
commit e843a0f
Showing
5 changed files
with
166 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "fw1-cursor.h" | ||
|
||
int read_fw1_cursorfile (const char *LogfileName) { | ||
FILE *fd; | ||
char line[POSITION_MAX_SIZE]; | ||
|
||
char *current_cursor = get_fw1_cursorname (LogfileName); | ||
fd = fopen (current_cursor,"r"); | ||
|
||
if (fd == NULL) | ||
{ | ||
fprintf (stderr, "Error while opening the file %s in read mode.\n", current_cursor); | ||
fprintf (stderr, "Maybe, it doesn't exist yet.\n"); | ||
free(current_cursor); | ||
return 0; | ||
} | ||
free(current_cursor); | ||
|
||
fgets (line, POSITION_MAX_SIZE, fd); | ||
fclose (fd); | ||
|
||
return atoi (line); | ||
} | ||
|
||
void write_fw1_cursorfile (const char *LogfileName, const char *message, const char separator) { | ||
FILE *fd; | ||
|
||
char *current_cursor = get_fw1_cursorname (LogfileName); | ||
char position[POSITION_MAX_SIZE]; | ||
int i, j = 0; | ||
|
||
fd = fopen (current_cursor,"r+"); | ||
|
||
if (fd == NULL) | ||
{ | ||
fprintf (stderr, "Error while opening the file %s in r+ mode.\n", current_cursor); | ||
fprintf (stderr, "Maybe, it doesn't exist yet. Trying to open it in w mode.\n"); | ||
|
||
fd = fopen (current_cursor,"w"); | ||
if (fd == NULL) | ||
{ | ||
fprintf (stderr, "Error while opening the file %s in w mode also.\n", current_cursor); | ||
free(current_cursor); | ||
exit (EXIT_FAILURE); | ||
} | ||
} | ||
free(current_cursor); | ||
|
||
// Extract cuurent position from message | ||
for (i=4; i<strlen (message); i++) | ||
{ | ||
if ((char)message[i] != separator) | ||
{ | ||
position[j] = message[i]; | ||
j++; | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
fprintf (fd, "%d", atoi (position)+1); | ||
fclose (fd); | ||
} | ||
|
||
char* get_fw1_cursorname(const char *LogfileName) { | ||
char *cursor_name = | ||
(char *) malloc (strlen (LogfileName) + 7); | ||
if (cursor_name == NULL) | ||
{ | ||
fprintf (stderr, "ERROR: Out of memory\n"); | ||
exit(EXIT_FAILURE); | ||
} | ||
strcpy (cursor_name, LogfileName); | ||
strcat (cursor_name, ".cursor"); | ||
|
||
return cursor_name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef FW1CURSOR_H | ||
#define FW1CURSOR_H | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#define POSITION_MAX_SIZE 20 | ||
|
||
int read_fw1_cursorfile(const char *LogfileName); // Return next log position from cursor file | ||
void write_fw1_cursorfile(const char *LogfileName, const char *message, const char separator); // Deduce next log position from current message | ||
char* get_fw1_cursorname(const char *LogfileName); // Give cursor name associated with log file | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters