-
Notifications
You must be signed in to change notification settings - Fork 0
/
MySQL CREATE DATABASE CybelinServer.sql
126 lines (119 loc) · 3.13 KB
/
MySQL CREATE DATABASE CybelinServer.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
CREATE DATABASE CybelinServer;
USE CybelinServer;
-- Tabla BlacklistedIps
CREATE TABLE BlacklistedIps (
Id INT AUTO_INCREMENT PRIMARY KEY,
IpAddress TEXT NULL,
DateAdded DATETIME(6) NOT NULL,
Reason TEXT NULL,
IsActive BOOLEAN NOT NULL
);
-- Tabla Configurations
CREATE TABLE Configurations (
Id INT AUTO_INCREMENT PRIMARY KEY,
`Key` TEXT NULL,
`Value` TEXT NULL,
LastUpdated DATETIME(6) NOT NULL
);
-- Tabla RequestLogs
CREATE TABLE RequestLogs (
RequestLogId BIGINT AUTO_INCREMENT PRIMARY KEY,
RequestId CHAR(36) NOT NULL, -- Para UUID
HttpMethod TEXT NULL,
RequestPath TEXT NULL,
QueryString TEXT NULL,
RequestHeaders TEXT NULL,
ClientIp TEXT NULL,
UserAgent TEXT NULL,
RequestTime DATETIME(6) NOT NULL,
HttpVersion TEXT NULL,
RequestBody TEXT NULL
);
-- Tabla ResponseLogs
CREATE TABLE ResponseLogs (
ResponseLogId BIGINT AUTO_INCREMENT PRIMARY KEY,
RequestId CHAR(36) NOT NULL, -- Para UUID
StatusCode INT NOT NULL,
ResponseHeaders TEXT NULL,
ResponseTime DATETIME(6) NOT NULL,
DurationMs BIGINT NOT NULL,
ServerIp TEXT NULL,
ResponseSizeInBytes BIGINT NOT NULL DEFAULT 0
);
-- Procedimiento GetLogsAfterDate
DELIMITER $$
CREATE PROCEDURE GetLogsAfterDate(IN RequestTimeFilter DATETIME(6))
BEGIN
SELECT
rl.RequestLogId,
rl.RequestId,
rl.HttpMethod,
rl.RequestPath,
rl.QueryString,
rl.RequestHeaders,
rl.ClientIp,
rl.UserAgent,
rl.RequestTime,
rl.HttpVersion,
rl.RequestBody,
resl.ResponseLogId,
resl.StatusCode,
resl.ResponseHeaders,
resl.ResponseTime,
resl.DurationMs,
resl.ServerIp,
resl.ResponseSizeInBytes
FROM
RequestLogs rl
LEFT JOIN
ResponseLogs resl
ON
rl.RequestId = resl.RequestId
WHERE
rl.RequestTime >= RequestTimeFilter
ORDER BY
rl.RequestLogId;
END$$
DELIMITER ;
-- Procedimiento GetLogsFilteredByTimeAndClientIp
DELIMITER $$
CREATE PROCEDURE GetLogsFilteredByTimeAndClientIp(
IN RequestTimeFilter DATETIME(6),
IN ClientIp TEXT
)
BEGIN
SELECT
r.RequestLogId,
r.RequestId,
r.HttpMethod,
r.RequestPath,
r.QueryString,
r.RequestHeaders,
r.ClientIp,
r.UserAgent,
r.RequestTime,
r.HttpVersion,
r.RequestBody,
res.ResponseLogId,
res.StatusCode,
res.ResponseHeaders,
res.ResponseTime,
res.DurationMs,
res.ServerIp,
res.ResponseSizeInBytes
FROM
RequestLogs r
LEFT JOIN
ResponseLogs res
ON
r.RequestId = res.RequestId
WHERE
r.RequestTime >= RequestTimeFilter
AND r.ClientIp = ClientIp
ORDER BY
r.RequestLogId;
END$$
DELIMITER ;
-- Insertar un registro en Configurations
INSERT INTO Configurations (`Key`, `Value`, LastUpdated)
VALUES ('MaliciousIpCheckIntervalInSeconds', '60', '2024-10-12 04:15:57');