-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·106 lines (93 loc) · 2.62 KB
/
Copy pathmain.cpp
File metadata and controls
executable file
·106 lines (93 loc) · 2.62 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <iostream>
#include <fstream>
#include <time.h>
#include <zconf.h>
#include <libconfig.h++>
#include "nginxConfigReader.h"
#include "IpParser.h"
#include "IpHashTableGeneric.h"
#include "BanRecord.h"
#include "BinaryOps.h"
#include "Configuration.h"
#include "strFuncs.h"
#define cfgFilePath "/etc/nginx-instaban.conf"
using namespace libconfig;
using namespace std;
BanMgr* banMgr = nullptr;
int main() {
Config cfg;
try
{
cfg.readFile(cfgFilePath);
}
catch(const FileIOException &fioex)
{
std::cerr << "I/O error while reading file." << std::endl;
return(EXIT_FAILURE);
}
catch(const ParseException &pex)
{
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
return(EXIT_FAILURE);
}
try
{
Configuration::myLogPath = cfg.lookup("instabanLogPath");
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'instabanLogPath' setting in configuration file." << endl;
}
try
{
Configuration::chainAddCmd = cfg.lookup("commands.chainAddCmd");
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'commands.chainAddCmd' setting in configuration file." << endl;
}
try
{
Configuration::banCmd = cfg.lookup("commands.banCmd");
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'commands.banCmd' setting in configuration file." << endl;
}
try
{
Configuration::unbanCmd = cfg.lookup("commands.unbanCmd");
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'commands.unbanCmd' setting in configuration file." << endl;
}
try
{
Setting& logReaders = cfg.lookup("nginxLogReaders");
int count = logReaders.getLength();
for(int i = 0; i < count; ++i)
{
const Setting &logReader = logReaders[i];
const char* logPath;
int banTime;
int bitCount;
const char* chainName;
logReader.lookupValue("nginxLogPath", logPath);
logReader.lookupValue("banTime", banTime);
logReader.lookupValue("chainName", chainName);
logReader.lookupValue("valuableBitCount", bitCount);
new ConfigReader(logPath, banTime, chainName, bitCount);
}
}
catch(const SettingNotFoundException &nfex)
{
cerr << "Can't read 'nginxLogReaders' setting in configuration file." << endl;
}
cout << "Working!" << endl;
while(true)
sleep(INT_MAX);
return 0;
}