-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
myproxy.lua
50 lines (45 loc) · 1.85 KB
/
myproxy.lua
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
local fh = io.open("/var/log/mysql/proxy.query.log", "a+")
fh:setvbuf('line',4096)
local the_query = '';
local seqno = 0;
function read_query(packet)
if string.byte(packet) == proxy.COM_QUERY then
-- query = string.sub(packet, 2)
seqno = seqno + 1
the_query = (string.gsub(string.gsub(string.sub(packet, 2), "%s%s*", ' '), "^%s*(.-)%s*$", "%1"))
fh:write(string.format("%s %09d %09d : %s (%s) -- %s\n",
os.date('%Y-%m-%d %H:%M:%S'),
proxy.connection.server.thread_id,
seqno,
proxy.connection.client.username,
proxy.connection.client.default_db,
the_query))
fh:flush()
proxy.queries:append(1, packet, {resultset_is_needed = true} )
return proxy.PROXY_SEND_QUERY
end
end
function read_query_result (inj)
local res = assert(inj.resultset)
-- if res.query_status == proxy.MYSQLD_PACKET_ERR then
if (res.query_status == proxy.MYSQLD_PACKET_ERR) then
local query = string.sub(inj.query, 2)
local err_code = res.raw:byte(2) + (res.raw:byte(3) * 256)
local err_sqlstate = res.raw:sub(5, 9)
local err_msg = res.raw:sub(10)
print("Query Received -\027[01;31m\027[K", query, "\027[m\027[K")
print("Query Error code -", err_code)
print("Query Error Sqlstate -", err_sqlstate)
print("Query Error message -", err_msg)
elseif (res.warning_count > 0) then
local query = string.sub(inj.query, 2)
local err_code = res.raw:byte(2) + (res.raw:byte(3) * 256)
local err_sqlstate = res.raw:sub(5, 9)
local err_msg = res.raw:sub(10)
print("Query Received -\027[33m\027[K", query, "\027[m\027[K")
print("Query warnings -", res.warning_count)
end
end
function read_auth(moo)
-- print("\027[01;30m\027[KLogin\027[m\027[K")
end