[UP] HHH_a, cgi can work perfect now, use escape and unescape lib
[archserver.git] / mail / postfix / cgi / mysql.lua
blob60af1dbd17059d4c112697f50247070b511c6801
1 #!/usr/bin/lua
2 dofile "lib.inc";
3 -- variables declare
4 env, con = nil, nil;
6 function cb_head()
7 print([[<script type="text/javascript">
8 function init()
12 </script>]])
13 end
15 function db_open()
16 require "luasql.mysql";
17 env = assert (luasql.mysql())
18 con = assert (env:connect(CONF_DB.DBN, CONF_DB.USR, CONF_DB.PWD, CONF_DB.SRV), "mysql connect bad")
19 end
21 function rows(connection, sql_statement)
22 local cursor = assert(connection:execute(sql_statement))
23 return function()
24 return cursor:fetch()
25 end
26 end
28 function cb_body()
29 db_open();
30 for email, pwd in rows(con, "select email,clear from postfix_users") do
31 print(string.format ("%s:%s<br>", email, pwd))
32 end
33 end
35 -- within framework
36 as_head(cb_head, "mysql as_header");
37 as_body(cb_body, "init();");