1818
1919 $%ENDLICENSE%$ --]]
2020
21- --[[
22- -- redefine next, used for iterate userdata
23- rawnext = next
24- function next(t,k)
25- local m = getmetatable(t)
26- local n = m and m.__next or rawnext
27- return n(t,k)
28- end
29- ]]
30-
3121function set_error (errmsg )
3222 proxy .response = {
3323 type = proxy .MYSQLD_PACKET_ERR ,
@@ -50,23 +40,12 @@ function read_query(packet)
5040 fields = {
5141 { name = " backend_ndx" ,
5242 type = proxy .MYSQL_TYPE_LONG },
53- --[[ { name = "username",
54- type = proxy.MYSQL_TYPE_STRING },
55- ]]
5643 { name = " address" ,
5744 type = proxy .MYSQL_TYPE_STRING },
5845 { name = " state" ,
5946 type = proxy .MYSQL_TYPE_STRING },
6047 { name = " type" ,
6148 type = proxy .MYSQL_TYPE_STRING },
62- -- { name = "uuid",
63- -- type = proxy.MYSQL_TYPE_STRING },
64- -- { name = "connected_clients",
65- -- type = proxy.MYSQL_TYPE_LONG },
66- --[[
67- { name = "cur_idle_connections",
68- type = proxy.MYSQL_TYPE_LONG },
69- ]]
7049 }
7150
7251 for i = 1 , # proxy .global .backends do
@@ -83,30 +62,12 @@ function read_query(packet)
8362 }
8463 local b = proxy .global .backends [i ]
8564
86- rows [# rows + 1 ] = {
87- i ,
88- b .dst .name , -- configured backend address
89- states [b .state + 1 ], -- the C-id is pushed down starting at 0
90- types [b .type + 1 ], -- the C-id is pushed down starting at 0
91- -- b.uuid, -- the MySQL Server's UUID if it is managed
92- -- b.connected_clients -- currently connected clients
93- }
94-
95- --[[
96- for j, username in next, b.pool.users, 0 do
97-
98- rows[#rows + 1] = {
99- i,
100- username,
101- b.dst.name, -- configured backend address
102- states[b.state + 1], -- the C-id is pushed down starting at 0
103- types[b.type + 1], -- the C-id is pushed down starting at 0
104- b.uuid, -- the MySQL Server's UUID if it is managed
105- b.connected_clients, -- currently connected clients
106- b.pool.users[username].cur_idle_connections
107- }
108- end
109- ]]
65+ rows [# rows + 1 ] = {
66+ i ,
67+ b .dst .name , -- configured backend address
68+ states [b .state + 1 ], -- the C-id is pushed down starting at 0
69+ types [b .type + 1 ], -- the C-id is pushed down starting at 0
70+ }
11071 end
11172 elseif string.find (query :lower (), " ^set%s+%a+%s+%d+$" ) then
11273 local state ,id = string.match (query :lower (), " ^set%s+(%a+)%s+(%d+)$" )
@@ -133,10 +94,6 @@ function read_query(packet)
13394 type = proxy .MYSQL_TYPE_STRING },
13495 { name = " type" ,
13596 type = proxy .MYSQL_TYPE_STRING },
136- -- { name = "uuid",
137- -- type = proxy.MYSQL_TYPE_STRING },
138- -- { name = "connected_clients",
139- -- type = proxy.MYSQL_TYPE_LONG },
14097 }
14198
14299 local states = {
@@ -157,8 +114,6 @@ function read_query(packet)
157114 b .dst .name , -- configured backend address
158115 states [b .state + 1 ], -- the C-id is pushed down starting at 0
159116 types [b .type + 1 ], -- the C-id is pushed down starting at 0
160- -- b.uuid, -- the MySQL Server's UUID if it is managed
161- -- b.connected_clients -- currently connected clients
162117 }
163118 elseif string.find (query :lower (), " ^add%s+master%s+%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?:%d%d?%d?%d?%d?$" ) then
164119 local newserver = string.match (query :lower (), " ^add%s+master%s+(.+)$" )
@@ -204,6 +159,22 @@ function read_query(packet)
204159 local client = string.match (query :lower (), " ^remove%s+client%s+(.+)$" )
205160 proxy .global .backends .removeclient = client
206161
162+ fields = {
163+ { name = " status" ,
164+ type = proxy .MYSQL_TYPE_STRING },
165+ }
166+ elseif string.find (query :lower (), " ^add%s+pwd%s+(.+):(.+)$" ) then
167+ local pwd = string.match (query :lower (), " ^add%s+pwd%s+(.+)$" )
168+ proxy .global .backends .addpwd = pwd
169+
170+ fields = {
171+ { name = " status" ,
172+ type = proxy .MYSQL_TYPE_STRING },
173+ }
174+ elseif string.find (query :lower (), " ^remove%s+pwd%s+(.+)$" ) then
175+ local pwd = string.match (query :lower (), " ^remove%s+pwd%s+(.+)$" )
176+ proxy .global .backends .removepwd = pwd
177+
207178 fields = {
208179 { name = " status" ,
209180 type = proxy .MYSQL_TYPE_STRING },
@@ -222,14 +193,22 @@ function read_query(packet)
222193 type = proxy .MYSQL_TYPE_STRING },
223194 }
224195 rows [# rows + 1 ] = { " SELECT * FROM help" , " shows this help" }
196+
225197 rows [# rows + 1 ] = { " SELECT * FROM backends" , " lists the backends and their state" }
226198 rows [# rows + 1 ] = { " SET OFFLINE $backend_id" , " offline backend server, $backend_id is backend_ndx's id" }
227199 rows [# rows + 1 ] = { " SET ONLINE $backend_id" , " online backend server, ..." }
228200 rows [# rows + 1 ] = { " ADD MASTER $backend" , " example: \" add master 127.0.0.1:3306\" , ..." }
229201 rows [# rows + 1 ] = { " ADD SLAVE $backend" , " example: \" add slave 127.0.0.1:3306\" , ..." }
230202 rows [# rows + 1 ] = { " REMOVE BACKEND $backend_id" , " example: \" remove backend 1\" , ..." }
203+
204+ rows [# rows + 1 ] = { " SELECT * FROM clients" , " lists the clients" }
231205 rows [# rows + 1 ] = { " ADD CLIENT $client" , " example: \" add client 192.168.1.2\" , ..." }
232206 rows [# rows + 1 ] = { " REMOVE CLIENT $client" , " example: \" remove client 192.168.1.2\" , ..." }
207+
208+ rows [# rows + 1 ] = { " SELECT * FROM pwds" , " lists the pwds" }
209+ rows [# rows + 1 ] = { " ADD PWD $pwd" , " example: \" add pwd user:password\" , ..." }
210+ rows [# rows + 1 ] = { " REMOVE PWD $pwd" , " example: \" remove pwd user\" , ..." }
211+
233212 rows [# rows + 1 ] = { " SAVE CONFIG" , " save the backends to config file" }
234213 else
235214 set_error (" use 'SELECT * FROM help' to see the supported commands" )
0 commit comments