Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Web-server by Zer0Galaxy
- on = require("opennet")
- fs = require("filesystem")
- ser = require("serialization").serialize
- webDir='/web/'
- maxPacketSize=8000
- local myIP,err=on.getIP()
- if not myIP then
- print(err)
- return
- end
- local sendIP, command
- commands={}
- function commands.ping()
- return "pong"
- end
- function commands.ver()
- return "Web-server ver 1.0"
- end
- function commands.get(path)
- path=path or 'index'
- file=io.open(webDir..path,'r')
- if not file then file=io.open(webDir..'404','r') end
- if file then
- text=file:read("*a") file:close()
- else
- text="Файл "..path.." не найден"
- end
- return text
- end
- function commands.list(path)
- local result={}
- path=webDir..(path or "")
- for name in fs.list(path) do
- result[#result+1]=name
- end
- return ser(result)
- end
- while true do
- local dat = {on.receive()}
- sendIP, command = dat[1], dat[2]
- if command then
- if commands[command] then
- on.send(sendIP, command, commands[command](table.unpack(dat,3)) )
- else
- on.send(sendIP, false, command, "Недопустимая команда" )
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement