-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.lua
More file actions
51 lines (44 loc) · 1.25 KB
/
server.lua
File metadata and controls
51 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function SaveX(sErr)
if (sErr) then
print (sErr)
s.err = sErr
end
file.remove("s.txt")
file.open("s.txt","w+")
for k, v in pairs(s) do
file.writeline(k .. "=" .. v)
end
file.close()
collectgarbage()
end
print(collectgarbage("count").." kB used")
LoadX()
wifi.setmode(wifi.SOFTAP)
wifi.ap.config({ssid="node_"..node.chipid(), pwd=""})
srv=net.createServer(net.TCP)
print(wifi.sta.getip())
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=([^&]*)&*") do
s[k],n = string.gsub(v,"%%2F","/")
print(k .. " = " .. s[k])
end
SaveX()
if ((s.err == "") and s.host and s.domain and s.path) then
node.restart()
end
end
file.open("y.htm","r")
local sH = file.read()
for k, v in pairs(s) do
sH,n = string.gsub(sH,"_"..k,v)
end
print(sH)
file.close()
client:send(sH)
client:close()
collectgarbage()
end)
end)