Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local url = "www.example.com"
- if not fs.exists("/"..url) then fs.makeDir("/"..url) end
- rednet.open("right")
- function server_loop()
- while true do
- local id, msg = rednet.receive()
- print(msg)
- if msg:find("^LIST%s.-%sRTTP") then
- -- onList
- rednet.send(id, url);
- elseif msg:find("^GET") then
- local page, head = msg:match("GET%s([^%s]+)[^\n]*\n([^\n]*)")
- local headers = {}
- head:gsub('"([^"]*)":"([^"]*)"', function(k, v)
- headers[k] = v
- end)
- -- onBeforeSend
- if page then
- page = page:gsub("%.%.", "")
- print("/"..url..page)
- local f = io.open("/"..url..page, "r")
- if f then
- data = f:read("*a")
- f:close()
- print("200")
- rednet.send(id, '200 OK\n"type":"text/lua"\n'..data)
- else
- print("404")
- rednet.send(id, '404 Not Found\n"type":"text/lua"\nprint("404 Not Found")')
- end
- else
- print("400-2")
- rednet.send(id, '400 Bad Request\n"type":"text/lua"\bprint("400 Bad Request")')
- end
- else
- print("400-1")
- rednet.send(id, '400 Bad Request\n"type":"text/lua"\bprint("400 Bad Request")')
- end
- end
- end
- parallel.waitForAny(server_loop, function() shell.run("shell") end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement