7abb1ef781190ddcc49ee2429bbd4f70552b499b
[project/luci.git] / libs / sgi-cgi / luasrc / sgi / cgi.lua
1 --[[
2 LuCI - SGI-Module for CGI
3
4 Description:
5 Server Gateway Interface for CGI
6
7 FileId:
8 $Id$
9
10 License:
11 Copyright 2008 Steven Barth <steven@midlink.org>
12
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at 
16
17         http://www.apache.org/licenses/LICENSE-2.0 
18
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
24
25 ]]--
26 module("luci.sgi.cgi", package.seeall)
27 require("luci.http")
28 require("luci.sys")
29 require("luci.dispatcher")
30
31 function run()
32         local r = luci.http.Request(luci.sys.getenv(), io.stdin, io.stderr)
33         
34         local x = coroutine.create(luci.dispatcher.httpdispatch)
35         
36         while coroutine.status(x) ~= "dead" do
37                 local res, id, data1, data2 = coroutine.resume(x, r)
38
39                 if not res then
40                         print("Status: 500 Internal Server Error")
41                         print("Content-Type: text/plain\n")
42                         print(id)
43                         break;
44                 end
45                 
46                 if id == 1 then
47                         io.write("Status: " .. tostring(data1) .. " " .. data2 .. "\n")
48                 elseif id == 2 then
49                         io.write(data1 .. ": " .. data2 .. "\n")
50                 elseif id == 3 then
51                         io.write("\n")
52                 elseif id == 4 then
53                         io.write(data1)
54                 end
55                 
56         end
57 end