wfSchema.php
7.11 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php
require_once('wfDB.php');
class wfSchema {
private $tables = array(
"wfBadLeechers" => "(
eMin int UNSIGNED NOT NULL,
IP int UNSIGNED NOT NULL,
hits int UNSIGNED NOT NULL,
PRIMARY KEY k1(eMin, IP)
) default charset=latin1",
"wfVulnScanners" => "(
IP int UNSIGNED PRIMARY KEY,
ctime int UNSIGNED NOT NULL,
hits int UNSIGNED NOT NULL
)",
"wfBlocks" => "(
IP int UNSIGNED PRIMARY KEY,
blockedTime int UNSIGNED NOT NULL,
reason varchar(255) NOT NULL,
lastAttempt int UNSIGNED default 0,
blockedHits int UNSIGNED default 0,
wfsn tinyint UNSIGNED default 0,
permanent tinyint UNSIGNED default 0,
KEY k1(wfsn)
) default charset=utf8",
"wfConfig" => "(
`name` varchar(100) NOT NULL,
`val` longblob,
`autoload` enum('no','yes') NOT NULL DEFAULT 'yes',
PRIMARY KEY (`name`)
) default charset=utf8",
"wfCrawlers" => "(
IP INT UNSIGNED NOT NULL,
patternSig binary(16) NOT NULL,
status char(8) NOT NULL,
lastUpdate int UNSIGNED NOT NULL,
PTR varchar(255) default '',
PRIMARY KEY k1(IP, patternSig)
) default charset=latin1",
"wfFileChanges" => "(
filenameHash char(64) NOT NULL PRIMARY KEY,
file varchar(1000) NOT NULL,
md5 char(32) NOT NULL
) default charset=utf8",
"wfHits" => "(
id int UNSIGNED auto_increment PRIMARY KEY,
ctime DOUBLE(17,6) UNSIGNED NOT NULL,
IP int UNSIGNED NOT NULL,
jsRun tinyint default 0,
statusCode int NOT NULL default 200,
isGoogle tinyint NOT NULL,
userID int UNSIGNED NOT NULL,
newVisit tinyint UNSIGNED NOT NULL,
URL text,
referer text,
UA text,
KEY k1(ctime),
KEY k2(IP, ctime)
) default charset=latin1",
"wfIssues" => "(
id int UNSIGNED NOT NULL auto_increment PRIMARY KEY,
time int UNSIGNED NOT NULL,
status varchar(10) NOT NULL,
type varchar(20) NOT NULL,
severity tinyint UNSIGNED NOT NULL,
ignoreP char(32) NOT NULL,
ignoreC char(32) NOT NULL,
shortMsg varchar(255) NOT NULL,
longMsg text,
data text
) default charset=utf8",
"wfLeechers" => "(
eMin int UNSIGNED NOT NULL,
IP int UNSIGNED NOT NULL,
hits int UNSIGNED NOT NULL,
PRIMARY KEY k1(eMin, IP)
) default charset=latin1",
"wfLockedOut" => "(
IP int UNSIGNED PRIMARY KEY,
blockedTime int UNSIGNED NOT NULL,
reason varchar(255) NOT NULL,
lastAttempt int UNSIGNED default 0,
blockedHits int UNSIGNED default 0
) default charset=utf8",
"wfLocs" => "(
IP int UNSIGNED NOT NULL PRIMARY KEY,
ctime int UNSIGNED NOT NULL,
failed tinyint UNSIGNED NOT NULL,
city varchar(255) default '',
region varchar(255) default '',
countryName varchar(255) default '',
countryCode char(2) default '',
lat float(10,7) default 0,
lon float(10,7) default 0
) default charset=utf8",
"wfLogins" => "(
id int UNSIGNED auto_increment PRIMARY KEY,
ctime DOUBLE(17,6) UNSIGNED NOT NULL,
fail tinyint UNSIGNED NOT NULL,
action varchar(40) NOT NULL,
username varchar(255) NOT NULL,
userID int UNSIGNED NOT NULL,
IP int UNSIGNED NOT NULL,
UA text,
KEY k1(IP, fail)
) default charset=utf8",
"wfReverseCache" => "(
IP int UNSIGNED PRIMARY KEY,
host varchar(255) NOT NULL,
lastUpdate int UNSIGNED NOT NULL
) default charset=latin1",
"wfScanners" => "(
eMin int UNSIGNED NOT NULL,
IP int UNSIGNED NOT NULL,
hits smallint UNSIGNED NOT NULL,
PRIMARY KEY k1(eMin, IP)
) default charset=latin1",
"wfThrottleLog" => "(
IP int UNSIGNED NOT NULL PRIMARY KEY,
startTime int UNSIGNED NOT NULL,
endTime int UNSIGNED NOT NULL,
timesThrottled int UNSIGNED NOT NULL,
lastReason varchar(255) NOT NULL,
KEY k2(endTime)
) default charset=utf8",
"wfStatus" => "(
id bigint UNSIGNED NOT NULL auto_increment PRIMARY KEY,
ctime DOUBLE(17,6) UNSIGNED NOT NULL,
level tinyint UNSIGNED NOT NULL,
type char(5) NOT NULL,
msg varchar(1000) NOT NULL,
KEY k1(ctime),
KEY k2(type)
) default charset=utf8",
'wfNet404s' => "(
sig binary(16) NOT NULL PRIMARY KEY,
ctime int UNSIGNED NOT NULL,
URI varchar(1000) NOT NULL,
KEY k1(ctime)
) default charset=utf8",
'wfHoover' => "(
id int UNSIGNED auto_increment PRIMARY KEY,
owner text,
host text,
path text,
hostKey binary(4),
KEY k2(hostKey)
) default charset=utf8",
'wfFileMods' => "(
filenameMD5 binary(16) NOT NULL PRIMARY KEY,
filename varchar(1000) NOT NULL,
knownFile tinyint UNSIGNED NOT NULL,
oldMD5 binary(16) NOT NULL,
newMD5 binary(16) NOT NULL
) default charset=utf8",
'wfBlocksAdv' => "(
id int UNSIGNED NOT NULL auto_increment PRIMARY KEY,
blockType char(2) NOT NULL,
blockString varchar(255) NOT NULL,
ctime int UNSIGNED NOT NULL,
reason varchar(255) NOT NULL,
totalBlocked int UNSIGNED default 0,
lastBlocked int UNSIGNED default 0
) default charset=utf8",
'wfBlockedIPLog' => "(
IP int UNSIGNED NOT NULL,
countryCode VARCHAR(2) NOT NULL,
blockCount int UNSIGNED NOT NULL DEFAULT 0,
unixday int UNSIGNED NOT NULL,
PRIMARY KEY(IP, unixday)
) default charset=utf8",
'wfSNIPCache' => "(
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`IP` varchar(45) NOT NULL DEFAULT '',
`expiration` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`body` varchar(255) NOT NULL DEFAULT '',
`count` int(10) unsigned NOT NULL DEFAULT '0',
`type` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `expiration` (`expiration`),
KEY `IP` (`IP`),
KEY `type` (`type`)
) DEFAULT CHARSET=utf8",
'wfKnownFileList' => "(
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`path` text NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8",
'wfNotifications' => "(
`id` varchar(32) NOT NULL DEFAULT '',
`new` tinyint(3) unsigned NOT NULL DEFAULT '1',
`category` varchar(255) NOT NULL,
`priority` int(11) NOT NULL DEFAULT '1000',
`ctime` int(10) unsigned NOT NULL,
`html` text NOT NULL,
`links` text NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;"
/*
'wfPerfLog' => "(
id int UNSIGNED NOT NULL auto_increment PRIMARY KEY,
IP int UNSIGNED NOT NULL,
userID int UNSIGNED NOT NULL,
UA varchar(1000) NOT NULL,
URL varchar(1000) NOT NULL,
ctime int UNSIGNED NOT NULL,
fetchStart int UNSIGNED NOT NULL,
domainLookupStart int UNSIGNED NOT NULL,
domainLookupEnd int UNSIGNED NOT NULL,
connectStart int UNSIGNED NOT NULL,
connectEnd int UNSIGNED NOT NULL,
requestStart int UNSIGNED NOT NULL,
responseStart int UNSIGNED NOT NULL,
responseEnd int UNSIGNED NOT NULL,
domReady int UNSIGNED NOT NULL,
loaded int UNSIGNED NOT NULL,
KEY k1(ctime)
) default charset=utf8"
*/
);
private $db = false;
private $prefix = 'wp_';
public function __construct($dbhost = false, $dbuser = false, $dbpassword = false, $dbname = false){
/*
if($dbhost){ //for testing
$this->db = new wfDB(false, $dbhost, $dbuser, $dbpassword, $dbname);
$this->prefix = 'wp_';
} else {
*/
global $wpdb;
$this->db = new wfDB();
$this->prefix = $wpdb->base_prefix;
}
public function dropAll(){
foreach($this->tables as $table => $def){
$this->db->queryWrite("drop table if exists " . $this->prefix . $table);
}
}
public function createAll(){
foreach($this->tables as $table => $def){
$this->db->queryWrite("create table IF NOT EXISTS " . $this->prefix . $table . " " . $def);
}
}
public function create($table){
$this->db->queryWrite("create table IF NOT EXISTS " . $this->prefix . $table . " " . $this->tables[$table]);
}
public function drop($table){
$this->db->queryWrite("drop table if exists " . $this->prefix . $table);
}
}
?>