echo.cgi.old 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/lua5.1
  2. -- Every CGI script that returns any valid JSON object will work in the test.
  3. -- In case you do not have not yet used CGI, you may want to use this script which is written in Lua.
  4. -- You may download an interpreter from http://luabinaries.sourceforge.net/download.html, extract it
  5. -- to some folder in your search path (the path of the webserver or /usr/bin on Linux), and add the
  6. -- following lines to your .conf file.
  7. -- cgi_interpreter c:\somewhere\lua5.1.exe
  8. -- enable_keep_alive yes
  9. resp = "{";
  10. method = os.getenv("REQUEST_METHOD")
  11. uri = os.getenv("REQUEST_URI");
  12. query = os.getenv("QUERY_STRING");
  13. datalen = os.getenv("CONTENT_LENGTH");
  14. if method then
  15. resp = resp .. '"method" : "' .. method .. '", ';
  16. end
  17. if uri then
  18. resp = resp .. '"uri" : "' .. uri .. '", ';
  19. end
  20. if query then
  21. resp = resp .. '"query" : "' .. query .. '", ';
  22. end
  23. if datalen then
  24. resp = resp .. '"datalen" : "' .. datalen .. '", ';
  25. end
  26. resp = resp .. '"time" : "' .. os.date() .. '" ';
  27. resp = resp .. "}";
  28. print "Status: 200 OK"
  29. print "Connection: close"
  30. --print "Connection: keep-alive"
  31. print "Content-Type: text/html; charset=utf-8"
  32. print "Cache-Control: no-cache"
  33. --print ("Content-Length: " .. resp:len())
  34. print ""
  35. print (resp)
  36. doLogging = false
  37. if (doLogging) then
  38. -- Store the POST data to a file
  39. if (method == "POST") then
  40. myFile = io.open("data" .. query:sub(4) .. ".txt", "wb");
  41. myFile:write(resp)
  42. myFile:write("\r\n\r\n")
  43. if datalen then
  44. datalen = tonumber(datalen)
  45. myFile:write("<<< " .. datalen .. " bytes of data >>>\r\n")
  46. data = io.stdin:read(datalen)
  47. myFile:write(data)
  48. myFile:write("\r\n<<< end >>>\r\n")
  49. else
  50. myFile:write("<<< no data >>>\r\n")
  51. end
  52. myFile:close()
  53. end
  54. end