-
Notifications
You must be signed in to change notification settings - Fork 443
/
AutoBan.h
110 lines (84 loc) · 2.2 KB
/
AutoBan.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef _AUTOBAN_H_
#define _AUTOBAN_H_
#include "TcpServer.h"
#include "HttpRequest.h"
#include "Parms.h"
#include "TuringTest.h"
#include "HashTableT.h"
//must be a power of 2!!!!!!
#define AUTOBAN_INITSIZE 262144
//#define AUTOBAN_INITSIZE 65536
//#define AUTOBAN_INITSIZE 32768
//#define AUTOBAN_INITSIZE 128
#define ONE_DAY 60*60*24
struct CodeVal {
char m_code[32];
int32_t m_ip;
int64_t m_count;
int32_t m_outstanding;
int32_t m_maxEver;
int32_t m_maxOutstanding;
int64_t m_bytesSent;
int64_t m_bytesRead;
};
class AutoBan {
public:
enum AutobanFlags {
CLEAR = 0x0,
ALLOW = 0x80,
DENY = 0x40,
FROMCONF = 0x20
};
struct DetectVal {
unsigned char m_flags;
unsigned char m_minuteCount;
unsigned char m_timesBanned;
int32_t m_dayCount;
int32_t m_minuteExpires;
int32_t m_dayExpires;
};
//init functions
AutoBan();
~AutoBan();
bool init();
void reset();
bool save();
bool restore();
bool hasCode(char *code, int32_t codeLen, int32_t ip);
bool hasPerm(int32_t ip,
char *code, int32_t codeLen,
char *uip, int32_t uipLen,
TcpSocket *s,
HttpRequest *r,
SafeBuf *testBuf,
bool justCheck ); // check, not incmreneting though
bool isBanned(uint32_t ip);
int32_t getSlot(int32_t ip);
bool addIp(int32_t ip, char allow);
bool addKey(int32_t ip, DetectVal* v);
bool growTable();
bool printTable( TcpSocket *s , HttpRequest *r );
void removeIp(int32_t ip);
void cleanHouse();
void setFromConf();
// . each client is now limited to a max outstanding requests
// . Proxy.cpp performs this limitation calculation
bool incRequestCount ( int32_t h , int32_t bytesRead );
void decRequestCount ( int32_t h , int32_t bytesSent );
protected:
int32_t *m_detectKeys;
DetectVal *m_detectVals;
int32_t m_tableSize;
int32_t m_numEntries;
bool setCodesFromConf();
// hash table for mapping client codes to various stats/counts,
// called "CodeVals"
HashTableT <int32_t,CodeVal> m_ht;
//int32_t *m_codeKeys;
//CodeVal *m_codeVals;
int32_t m_codeResetTime;
//int32_t m_codeTabSize;
//int32_t m_numCodes;
};
extern AutoBan g_autoBan;
#endif