-
Notifications
You must be signed in to change notification settings - Fork 89
/
3wifi.sql
323 lines (302 loc) · 11.6 KB
/
3wifi.sql
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
-- ------------------------------
-- Структура базы данных 3WiFi --
-- ------------------------------
-- Дамп структуры базы данных 3wifi
CREATE DATABASE IF NOT EXISTS `3wifi` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `3wifi`;
-- Дамп структуры таблицы 3wifi.base
CREATE TABLE `base` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`cmtid` INT(10) UNSIGNED NULL DEFAULT NULL,
`IP` INT(10) NULL DEFAULT NULL,
`Port` SMALLINT(5) UNSIGNED NULL DEFAULT NULL,
`Authorization` TINYTEXT NULL,
`name` TINYTEXT NOT NULL,
`RadioOff` BIT(1) NOT NULL DEFAULT b'0',
`Hidden` BIT(1) NOT NULL DEFAULT b'0',
`NoBSSID` TINYINT(3) UNSIGNED NOT NULL,
`BSSID` BIGINT(15) UNSIGNED NOT NULL,
`ESSID` VARCHAR(32) NOT NULL,
`Security` TINYINT(1) UNSIGNED NOT NULL,
`WiFiKey` VARCHAR(64) NOT NULL,
`WPSPIN` INT(8) UNSIGNED NOT NULL,
`LANIP` INT(10) NULL DEFAULT NULL,
`LANMask` INT(10) NULL DEFAULT NULL,
`WANIP` INT(10) NULL DEFAULT NULL,
`WANMask` INT(10) NULL DEFAULT NULL,
`WANGateway` INT(10) NULL DEFAULT NULL,
`DNS1` INT(10) NULL DEFAULT NULL,
`DNS2` INT(10) NULL DEFAULT NULL,
`DNS3` INT(10) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `BSSID` (`BSSID`),
INDEX `ESSID` (`ESSID`),
INDEX `Time` (`time`),
UNIQUE INDEX `WIFI` (`NoBSSID`, `BSSID`, `ESSID`, `WiFiKey`, `WPSPIN`)
) COLLATE='utf8_general_ci' ENGINE=InnoDB;
-- Дамп структуры таблицы 3wifi.geo
CREATE TABLE `geo` (
`BSSID` BIGINT(15) UNSIGNED NOT NULL,
`latitude` FLOAT(12,8) NULL DEFAULT NULL,
`longitude` FLOAT(12,8) NULL DEFAULT NULL,
`quadkey` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`BSSID`),
INDEX `quadkey` (`quadkey`),
INDEX `latitude` (`latitude`)
) COLLATE='utf8_general_ci' ENGINE=InnoDB;
-- Дамп структуры для таблицы 3wifi.invites
CREATE TABLE IF NOT EXISTS `invites` (
`invite` CHAR(12) NOT NULL,
`puid` INT(11) UNSIGNED NOT NULL,
`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`uid` INT(11) UNSIGNED NULL DEFAULT NULL,
`level` TINYINT(4) NOT NULL DEFAULT '1',
PRIMARY KEY (`invite`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Дамп структуры таблицы 3wifi.comments
CREATE TABLE `comments` (
`cmtid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`cmtval` VARCHAR(127) NOT NULL,
PRIMARY KEY (`cmtid`),
UNIQUE INDEX `comment` (`cmtval`)
) COLLATE='utf8_general_ci' ENGINE=InnoDB;
-- Дамп структуры таблицы 3wifi.tasks
CREATE TABLE `tasks` (
`tid` CHAR(32) NOT NULL,
`uid` INT(11) UNSIGNED NULL DEFAULT NULL,
`ipaddr` INT(11) NOT NULL,
`tstate` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
`created` TIMESTAMP NOT NULL DEFAULT current_timestamp(),
`modified` TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`ext` CHAR(4) NOT NULL,
`comment` TINYTEXT NOT NULL,
`checkexist` BIT(1) NOT NULL,
`nowait` BIT(1) NOT NULL,
`lines` INT(10) UNSIGNED NOT NULL DEFAULT 0,
`accepted` INT(10) UNSIGNED NOT NULL DEFAULT 0,
`onmap` INT(10) UNSIGNED NOT NULL DEFAULT 0,
`warns` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`tid`),
INDEX `task_state` (`tstate`),
INDEX `created_time` (`created`)
)
COLLATE='utf8_general_ci' ENGINE=InnoDB;
-- Дамп структуры таблицы 3wifi.ranges
CREATE TABLE `ranges` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`startIP` INT(10) UNSIGNED NOT NULL,
`endIP` INT(10) UNSIGNED NOT NULL,
`netname` TINYTEXT NOT NULL,
`descr` TINYTEXT NOT NULL,
`country` CHAR(2) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `RANGE` (`startIP`, `endIP`)
) COLLATE='utf8_general_ci' ENGINE=InnoDB;
-- Дамп структуры таблицы 3wifi.stats
CREATE TABLE `stats` (
`StatId` INT(15) UNSIGNED NOT NULL,
`Value` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`LastUpdate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`StatId`)
) COLLATE='utf8_general_ci' ENGINE=MEMORY;
-- Дамп структуры таблицы 3wifi.mem_base
CREATE TABLE `mem_base` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`cmtid` INT(10) UNSIGNED NULL DEFAULT NULL,
`IP` INT(10) NULL DEFAULT NULL,
`Port` SMALLINT(5) UNSIGNED NULL DEFAULT NULL,
`Authorization` VARCHAR(64) NULL DEFAULT NULL,
`name` VARCHAR(64) NOT NULL,
`RadioOff` BIT(1) NOT NULL DEFAULT b'0',
`Hidden` BIT(1) NOT NULL DEFAULT b'0',
`NoBSSID` TINYINT(3) UNSIGNED NOT NULL,
`BSSID` BIGINT(15) UNSIGNED NOT NULL,
`ESSID` VARCHAR(32) NOT NULL,
`Security` TINYINT(1) UNSIGNED NOT NULL,
`WiFiKey` VARCHAR(64) NOT NULL,
`WPSPIN` INT(8) UNSIGNED NOT NULL,
`LANIP` INT(10) NULL DEFAULT NULL,
`LANMask` INT(10) NULL DEFAULT NULL,
`WANIP` INT(10) NULL DEFAULT NULL,
`WANMask` INT(10) NULL DEFAULT NULL,
`WANGateway` INT(10) NULL DEFAULT NULL,
`DNS1` INT(10) NULL DEFAULT NULL,
`DNS2` INT(10) NULL DEFAULT NULL,
`DNS3` INT(10) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `BSSID` (`BSSID`),
INDEX `ESSID` (`ESSID`),
INDEX `Time` (`time`),
UNIQUE INDEX `WIFI` (`NoBSSID`, `BSSID`, `ESSID`, `WiFiKey`, `WPSPIN`)
) COLLATE='utf8_general_ci' ENGINE=MEMORY;
-- Дамп структуры таблицы 3wifi.mem_geo
CREATE TABLE `mem_geo` (
`BSSID` BIGINT(15) UNSIGNED NOT NULL,
`latitude` FLOAT(12,8) NULL DEFAULT NULL,
`longitude` FLOAT(12,8) NULL DEFAULT NULL,
`quadkey` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`BSSID`),
INDEX `quadkey` (`quadkey`),
INDEX `latitude` (`latitude`)
) COLLATE='utf8_general_ci' ENGINE=MEMORY;
-- Дамп структуры для таблицы 3wifi.users
CREATE TABLE `users` (
`uid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`regdate` TIMESTAMP NULL DEFAULT NULL,
`lastupdate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`puid` INT(11) NOT NULL DEFAULT '0',
`login` VARCHAR(30) NOT NULL,
`nick` VARCHAR(30) NOT NULL,
`pass_hash` CHAR(32) NOT NULL,
`autologin` CHAR(32) NOT NULL,
`salt` CHAR(32) NOT NULL,
`level` TINYINT(4) NOT NULL DEFAULT '0',
`ip_hash` CHAR(32) NOT NULL,
`invites` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
`rapikey` CHAR(32) NULL DEFAULT NULL,
`wapikey` CHAR(32) NULL DEFAULT NULL,
`querytime` TIMESTAMP NULL DEFAULT NULL,
`ban_reason` VARCHAR(16) NULL DEFAULT NULL,
PRIMARY KEY (`uid`),
UNIQUE INDEX `login` (`login`),
UNIQUE INDEX `nick` (`nick`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Дамп структуры для таблицы 3wifi.logauth
CREATE TABLE `logauth` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`IP` INT(15) NOT NULL,
`uid` INT(11) UNSIGNED NULL DEFAULT NULL,
`action` TINYINT(3) UNSIGNED NOT NULL,
`data` CHAR(64) NOT NULL DEFAULT '',
`status` BIT(1) NOT NULL DEFAULT b'0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Дамп структуры для таблицы 3wifi.logupload
CREATE TABLE `logupload` (
`id` INT(10) UNSIGNED NOT NULL,
`updated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`ipaddr` INT(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `FK1_logupload_base` (`id`),
INDEX `updated` (`updated`),
INDEX `ipaddr` (`ipaddr`),
CONSTRAINT `FK1_logupload_base` FOREIGN KEY (`id`) REFERENCES `base` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Дамп структуры для таблицы 3wifi.uploads
CREATE TABLE `uploads` (
`uid` INT(10) UNSIGNED NOT NULL,
`id` INT(10) UNSIGNED NOT NULL,
`creator` BIT(1) NOT NULL DEFAULT b'0',
UNIQUE INDEX `upload` (`uid`, `id`),
INDEX `FK_uploads_base` (`id`),
INDEX `uid` (`uid`),
CONSTRAINT `FK_uploads_users` FOREIGN KEY (`uid`) REFERENCES `users` (`uid`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `FK_uploads_base` FOREIGN KEY (`id`) REFERENCES `base` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Дамп структуры для таблицы 3wifi.favorites
CREATE TABLE `favorites` (
`uid` INT(10) UNSIGNED NOT NULL,
`id` INT(10) UNSIGNED NOT NULL,
UNIQUE INDEX `favorite` (`uid`, `id`),
INDEX `FK_favorites_base` (`id`),
INDEX `uid` (`uid`),
CONSTRAINT `FK_favorites_users` FOREIGN KEY (`uid`) REFERENCES `users` (`uid`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `FK_favorites_base` FOREIGN KEY (`id`) REFERENCES `base` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Дамп структуры для таблицы 3wifi.locations
CREATE TABLE `locations` (
`uid` INT(10) UNSIGNED NOT NULL,
`latitude` FLOAT(12,8) NOT NULL,
`longitude` FLOAT(12,8) NOT NULL,
`comment` VARCHAR(127) NOT NULL,
UNIQUE INDEX `uniq` (`uid`, `latitude`, `longitude`),
INDEX `uid` (`uid`),
INDEX `coords` (`latitude`, `longitude`),
CONSTRAINT `FK_locations_users` FOREIGN KEY (`uid`) REFERENCES `users` (`uid`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Дамп данных таблицы 3wifi.users
INSERT INTO `users` SET
`regdate`=CURRENT_TIMESTAMP,
`login`='admin',
`nick`='Administrator',
`salt`='2p8a!m%EFHr).djHO1uuIA^x82X$(988',
`pass_hash`=MD5(CONCAT('admin',`salt`)),
`autologin`='',
`level`=3,
`ip_hash`='',
`invites`=65535;
-- Дамп структуры для таблицы 3wifi.extinfo
CREATE TABLE `extinfo` (
`id` INT(11) NOT NULL,
`data` VARCHAR(255) NOT NULL,
`sn1` VARCHAR(50) NULL DEFAULT NULL,
`sn2` VARCHAR(50) NULL DEFAULT NULL,
`cable_mac` BIGINT(15) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `data_index` (`data`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Дамп данных процедуры 3wifi.show_graph_stat
CREATE PROCEDURE `show_graph_stat` (
IN `radius` INT
)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
BEGIN
IF radius = 0 THEN
SET @tme = (SELECT `time` FROM base WHERE `time` <= NOW() ORDER BY `time` DESC LIMIT 1);
ELSE
SET @tme = (SELECT `time` FROM base JOIN radius_ids USING(id) WHERE `time` <= NOW() ORDER BY radius_ids.id DESC LIMIT 1);
END IF;
SET @a = 0;
a_loop:
WHILE @a < 30 DO
IF FOUND_ROWS() = 0 THEN
LEAVE a_loop;
END IF;
IF @a = 0 THEN
IF radius = 0 THEN
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_graph AS (
SELECT DATE_FORMAT(time,'%Y.%m.%d') AS `date`, COUNT(id) AS `count` FROM base
WHERE `time` BETWEEN
CONCAT(SUBSTRING_INDEX(@tme, ' ', 1), ' 00:00:00') AND
CONCAT(SUBSTRING_INDEX(@tme, ' ', 1), ' 23:59:59')
);
ELSE
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_graph AS (
SELECT DATE_FORMAT(time,'%Y.%m.%d') AS `date`, COUNT(id) AS `count` FROM base
JOIN radius_ids USING(id)
WHERE `time` BETWEEN
CONCAT(SUBSTRING_INDEX(@tme, ' ', 1), ' 00:00:00') AND
CONCAT(SUBSTRING_INDEX(@tme, ' ', 1), ' 23:59:59')
);
END IF;
ELSE
IF radius = 0 THEN
INSERT INTO tmp_graph
SELECT DATE_FORMAT(time,'%Y.%m.%d') AS `date`, COUNT(id) AS `count` FROM base
WHERE `time` BETWEEN
CONCAT(SUBSTRING_INDEX(@tme, ' ', 1), ' 00:00:00') AND
CONCAT(SUBSTRING_INDEX(@tme, ' ', 1), ' 23:59:59');
ELSE
INSERT INTO tmp_graph
SELECT DATE_FORMAT(time,'%Y.%m.%d') AS `date`, COUNT(id) AS `count` FROM base
JOIN radius_ids USING(id)
WHERE `time` BETWEEN
CONCAT(SUBSTRING_INDEX(@tme, ' ', 1), ' 00:00:00') AND
CONCAT(SUBSTRING_INDEX(@tme, ' ', 1), ' 23:59:59');
END IF;
END IF;
SET @a = @a + 1;
IF radius = 0 THEN
SET @tme = (SELECT `time` FROM base WHERE `time` < CONCAT(SUBSTRING_INDEX(@tme, ' ', 1), ' 00:00:00') ORDER BY `time` DESC LIMIT 1);
ELSE
SET @tme = (SELECT `time` FROM base JOIN radius_ids USING(id) WHERE `time` < CONCAT(SUBSTRING_INDEX(@tme, ' ', 1), ' 00:00:00') ORDER BY radius_ids.id DESC LIMIT 1);
END IF;
END WHILE a_loop;
SELECT * FROM tmp_graph;
DROP TABLE IF EXISTS tmp_graph;
END