Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables
- local x,y = term.getSize()
- local dnsid = 0
- -- Functions
- function clear()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- end
- function drawLine(color, x, y)
- term.setCursorPos(x, y)
- term.setBackgroundColor(color)
- term.clearLine()
- term.setCursorPos(x, y+1)
- end
- function writeToLog(text)
- local file = fs.open("log","a")
- file.writeLine(text)
- file.close()
- end
- local file = fs.open("log","w")
- file.write("")
- file.close()
- -- main gui function
- function drawGui()
- drawLine(256,1,1)
- term.setTextColor(32768)
- write(" <- -> ")
- term.setBackgroundColor(1)
- write(" http:// ")
- term.setBackgroundColor(256)
- write(" ")
- drawLine(256,1,3)
- drawLine(1,1,4)
- drawLine(1,1,5)
- drawLine(1,1,6)
- drawLine(1,1,7)
- drawLine(1,1,8)
- drawLine(1,1,9)
- drawLine(1,1,10)
- drawLine(1,1,11)
- drawLine(1,1,12)
- drawLine(1,1,13)
- drawLine(1,1,14)
- drawLine(1,1,15)
- drawLine(1,1,16)
- drawLine(1,1,17)
- drawLine(1,1,18)
- drawLine(1,1,y)
- writeToLog("Gui Drawn")
- end
- local s = rs.getSides()
- local modemside
- for each,side in pairs(s) do
- if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
- modemside = side
- break
- end
- end
- writeToLog("Found modem "..modemside)
- drawGui()
- -- URL
- while true do
- term.setCursorPos(18,2)
- term.setBackgroundColor(1)
- term.setTextColor(32768)
- url = read()
- writeToLog("Tried to access "..url)
- term.setCursorPos(1,4)
- term.setBackgroundColor(1)
- term.setTextColor(32768)
- -- Rednet
- writeToLog("Sending request "..url.." to "..dnsid.." on "..modemside)
- rednet.open(modemside)
- rednet.send(dnsid, url,os.getComputerID())
- id,message = rednet.receive(5)
- if message==nil then
- write("Error 404: Cannot connect to server")
- writeToLog("Couldn't connect")
- else
- local file = fs.open("temp","w")
- file.write(message)
- file.close()
- shell.run("temp")
- writeToLog("Connected")
- end
- rednet.close()
- while true do
- local event, param = os.pullEvent()
- writeToLog("Key")
- if event == "key" then
- if param == keys.leftCtrl then
- writeToLog("Exiting website")
- break
- end
- end
- end
- clear()
- drawGui()
- end
Add Comment
Please, Sign In to add comment