forked from yiwenshao/Practical-Cryptdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial-basic.lua
More file actions
172 lines (146 loc) · 4.51 KB
/
tutorial-basic.lua
File metadata and controls
172 lines (146 loc) · 4.51 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
COLOR_END = '\027[00m'
function redtext(x)
return '\027[1;31m' .. x .. COLOR_END
end
function greentext(x)
return '\027[1;92m'.. x .. COLOR_END
end
function orangetext(x)
return '\027[01;33m'.. x .. COLOR_END
end
g=1
queryType = {}
queryType[proxy.COM_SLEEP] = "COM_SLEEP"
queryType[proxy.COM_QUIT] = "COM_QUIT"
queryType[proxy.COM_INIT_DB] = "COM_INIT_DB"
queryType[proxy.COM_QUERY] = "COM_QUERY"
queryType[proxy.COM_FIELD_LIST]= "COM_FIELD_LIST"
queryType[proxy.COM_CREATE_DB]= "COM_CREATE_DB"
queryType[proxy.COM_DROP_DB]= "COM_DROP_DB"
queryType[proxy.COM_REFRESH]= "COM_REFRESH"
queryType[proxy.COM_SHUTDOWN] = "COM_SHUTDOWN"
queryType[proxy.COM_STATISTICS] = "COM_STATISTICS"
queryType[proxy.COM_PROCESS_INFO] = "COM_PROCESS_INFO"
queryType[proxy.COM_CONNECT] = "COM_CONNECT"
queryType[proxy.COM_PROCESS_KILL] = "COM_PROCESS_KILL"
queryType[proxy.COM_DEBUG] = "COM_DEBUG"
queryType[proxy.COM_PING] = "COM_PING"
queryType[proxy.COM_TIME] = "COM_TIME"
queryType[proxy.COM_DELAYED_INSERT] = "COM_DELAYED_INSERT"
queryType[proxy.COM_CHANGE_USER] = "COM_CHANGE_USER"
queryType[proxy.COM_BINLOG_DUMP] = "COM_BINLOG_DUMP"
queryType[proxy.COM_TABLE_DUMP] = "COM_TABLE_DUMP"
queryType[proxy.COM_CONNECT_OUT] = "COM_CONNECT_OUT"
queryType[proxy.COM_REGISTER_SLAVE] = "COM_REGISTER_SLAVE"
queryType[proxy.COM_STMT_PREPARE] = "COM_STMT_PREPARE"
queryType[proxy.COM_STMT_EXECUTE] = "COM_STMT_EXECUTE"
queryType[proxy.COM_STMT_SEND_LONG_DATA] = "COM_STMT_SEND_LONG_DATA"
queryType[proxy.COM_STMT_CLOSE] = "COM_STMT_CLOSE"
queryType[proxy.COM_STMT_RESET] = "COM_STMT_RESET"
queryType[proxy.COM_SET_OPTION] = "COM_SET_OPTION"
queryType[proxy.COM_STMT_FETCH] = "COM_STMT_FETCH"
queryType[proxy.COM_DAEMON] = "COM_DAEMON"
function printCS()
server = nil
client = nil
sp = nil
if proxy.connection.client ~= nil then
client = proxy.connection.client.src.name
end
if proxy.connection.server ~= nil then
server = proxy.connection.server.dst.address
sp = proxy.connection.server.dst.port
end
if client~= nil then
print(redtext("clientName:"..client))
else
print(redtext("clientName=nil"))
end
if server ~= nil then
print(redtext(server))
else
print(redtext("server=nil"))
end
if sp ~= nil then
print(redtext(sp))
else
print(redtext("sp = nil"))
end
end
function connect_server()
print(orangetext("connect_server"))
printCS()
if g == 1 then
g = 0
else g = 1
end
print("g "..g)
print("ndx "..proxy.connection.backend_ndx.."get: "..#proxy.global.backends)
end
function read_handshake()
print(orangetext("read_handshake"))
printCS()
end
function read_auth()
print(orangetext("read_auth"))
printCS()
end
function read_auth_result()
print(orangetext("read_auth_result"))
printCS()
end
function read_query( packet )
print(orangetext("read_query"))
print(redtext("query type: "..queryType[string.byte(packet)]))
printCS()
if string.byte(packet) == proxy.COM_QUERY then
print("we got a normal query: " .. string.sub(packet, 2))
proxy.queries:append(1, packet, {resultset_is_needed = true})
return proxy.PROXY_SEND_QUERY
else
print("we got a abnormal query: " .. string.sub(packet, 2))
end
end
function print_fields(infields)
local resfields = infields
local interim_fields = {}
--store fileds in interim_fields
if (#resfields) then
io.write("|")
end
for i = 1, #resfields do
rfi = resfields[i]
interim_fields[i] ={ type = resfields[i].type,name = resfields[i].name }
io.write(string.format("%-20s|",rfi.name))
end
end
function print_rows(inrows)
local resrows = inrows
local interim_rows = {}
for row in resrows do
table.insert(interim_rows, row)
io.write("|")
-- for key,value in pairs(row) do
-- io.write(string.format("%-20s|", value))
-- end
for k,v in pairs(row) do
if v ~= nil then
io.write(string.format("%-20s|", v))
io.write("size = "..string.len(v))
else
io.write(string.format("%-20s|", "nil"))
end
end
print()
end
end
function read_query_result(inj)
print(orangetext("read_query_result"))
printCS()
print("ROWS: "..type(inj.resultset.rows))
if inj.resultset.rows ~= nil then
print_fields(inj.resultset.fields)
print("finish fields")
print_rows(inj.resultset.rows)
end
end