Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --OpenNet Server
- --Internet for OpenComputers
- local component = require("component")
- local event = require("event")
- local keyboard = require("keyboard")
- local fs = require("filesystem")
- --Config (DNS registration, webpages)
- local dns_addr = "2578c0ec-94b2-4d52-8a31-65379978d0ad"
- local dns_name = "t-mobile.cz"
- local main_page = "index.onml"
- -- Objects (various values needed)
- local modem = component.modem
- local gpu = component.gpu
- function def()
- fldr = main_page
- file = io.open(main_page, "r")
- cont = file:read("*a")
- file:close()
- end
- function init()
- modem.open(55)
- modem.send(dns_addr, 55, "INIT " .. dns_name)
- modem.close(55)
- print("Reg on "..dns_addr)
- end
- function respondToRequest(req)
- if not modem.isOpen(80) then
- modem.open(80)
- end
- print("User with network card address " .. req.remoteAddr .. " requested -"..fldr.."/")
- modem.send(req.remoteAddr, 80, cont)
- end
- init()
- running = true
- while running do
- modem.open(80)
- local _, _, from, _, _, request = event.pull("modem_message")
- if string.match(request, "/") then
- url, fldr = string.match(request, "(.*)%/(.*)")
- fldr = fldr..".onml"
- if fs.exists(fldr) then
- file = io.open(fldr, "r")
- cont = file:read("*a")
- file:close()
- else
- cont = "Not found"
- end
- respondToRequest({remoteAddr = from, request = request})
- else
- def()
- respondToRequest({remoteAddr = from, request = request})
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement