-
Notifications
You must be signed in to change notification settings - Fork 3
/
firewall.h
86 lines (76 loc) · 2.09 KB
/
firewall.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once
#define LOG_FILE_PATH "./logs/firewall/"
#define FIREWALL_INI_FILE "firewall_rules.ini"
#define MAX_RULE_NUM (1000)
#define EXIT_CONFIG (-1)
////////////////////////////////
#define COMMAND (0)
//ADD
#define ADD_MAX_LENGTH (5)
#define ADD_MIN_LENGTH (4)
#define ADD_DIRECTION (1)
#define ADD_IP (2)
#define ADD_PORT (3)
#define ADD_ACTION (4)
//UPDATE
#define UPDATE_LENGTH (5)
#define UPDATE_NUMBER (1)
#define UPDATE_OPTION (2)
#define UPDATE_REDIRECTION (3)
#define UPDATE_NEW_VALUE (4)
//DELETE
#define DELETE_LENGTH (2)
#define DELETE_NUMBER (1)
////////////////////////////////
enum eIniFormat {
ACTION=0,
DIRECTION,
IP,
PORT
};
#include <filesystem>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <unordered_map>
#include <functional>
#include <regex>
#include <unordered_set>
#include <cstdlib>
#include <unistd.h>
#include <csignal>
#include <algorithm>
#include "error_codes.h"
#include "VariadicTable.h"
#include "config_firewall.h"
#include "ansi_color.h"
#include "email_sender.h"
#include "log_parser.h"
#include "config.h"
#include "util.h"
class CFirewall {
public:
int StartFirewall();
int RunFirewall();
int ConfigureFirewall();
int ViewLogs();
int RunIptables(const std::string& strDirection, const std::string& strIp, const std::string& strPort, const std::string& strAction);
static void ExecCommand(const std::string& strCmd);
private:
int AddRule(std::vector<std::string>& vecWords);
int UpdateRule(std::vector<std::string>& vecWords);
int DeleteRule(std::vector<std::string>& vecWords);
int RuleList();
void PrintConfigManual();
static void handleExit(int nSignum);
std::vector<std::string> ConfigureUserInput(std::string& strInput);
std::string GetSectionName(const auto& vecIniData, int nNumber);
bool isValidIP(const std::string& strIp);
bool isValidPort(const std::string& strPort);
bool isValidNumber(const std::string& strNumber);
int isValidInput(std::vector<std::string>& vecWords);
int PrintFirewallHelp();
void DefaultRuleSet();
};