Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Port by Fronun.
- local GUI = require("GUI")
- local system = require("System")
- local component = require("Component")
- local event = require("Event")
- local server_password = "passw0rd"
- local version = "web-server mineWEB 1.1, powered by MineOS"
- local modem = component.modem
- local fs = require("Filesystem")
- local dirPage = "/web/"
- local computer = require("Computer")
- local workspace = GUI.workspace()
- workspace:addChild(GUI.panel(1, 1, workspace.width, workspace.height, 0x2D2D2D))
- local layout = workspace:addChild(GUI.layout(1, 1, workspace.width, workspace.height, 1, 8))
- local function addText(text)
- layout:addChild(GUI.text(layout.width, layout.height, 0xE1E1E1, text))
- end
- addText(version)
- addText("modem address: "..modem.address)
- modem.open(80)
- workspace:draw()
- while true do
- -- e3 удаленный айпи, e6 команда, e7 страница, e8, дата для PUT, e9 пароль
- local _, _, remoteIP, _, _, command, page, data, pass = event.pull()
- if command == "GET" then
- addText(remoteIP.. " request file: " ..page)
- local file = fs.read(dirPage..page)
- if not file then
- addText(remoteIP.. " redirect to 404")
- notpage = fs.read(dirPage.. "404.onml")
- modem.send(remoteIP, 80, notpage)
- end
- if file then
- local cont = fs.read(dirPage..page)
- modem.send(remoteIP, 80, cont)
- workspace:draw()
- end
- end
- if command == "PUT" then
- addText(remoteIP.. " trying to send a file to the server. File: "..page)
- if pass==server_password then
- file = fs.write(dirPage..page, data)
- modem.send(remoteIP, 80, "File_saved")
- end
- modem.send(remoteIP, 80, "invalid_password")
- workspace:draw()
- end
- if command == "VERSION" then
- addText(remoteIP.. " Request about version web-server")
- modem.send(remoteIP, 80, version)
- workspace:draw()
- end
- if command == "ping" then
- addText(remoteIP.. " ping")
- modem.send(remoteIP, 80, "pong")
- workspace:draw()
- end
- if command == "reboot" then
- addText(remoteIP.. " Trying reboot server")
- if pass==server_password then
- modem.send(remoteIP, 80, "server_rebooted")
- modem.close(80)
- computer.shutdown(true)
- end
- modem.send(remoteIP, 80, "invalid_password")
- end
- end
- workspace:start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement