Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x,y = term.getSize()
- rednet.open("top")
- local EditingValue = "";
- function rednetV()
- return "2.3"
- end
- title = "Rednet Explorer " ..rednetV() --Add title = "name" to change the webpage's title!
- local website = "home";
- if fs.exists(".cache") then fs.delete(".cache") end
- if fs.exists(".websiteedited") then fs.delete(".websiteedited") end
- fs.makeDir(".cache")
- local cPrint = function(text)
- local x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- print(text)
- end
- function createSite(websitename)
- fs.delete("startup")
- startup = fs.open("startup", "w")
- startup.writeLine("websitename = \"" ..websitename.. "\"")
- servercode = [[
- function record(text)
- print(text)
- log = fs.open("rednet.log", "w")
- log.writeLine(text)
- log.close()
- end
- local x,y = term.getSize()
- local cPrint = function(text)
- local x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- print(text)
- end
- rednet.open("top")
- term.clear()
- cPrint("Hosting " ..websitename.. "...\n")
- cPrint("Go to " ..websitename.. "/editor to edit it! (PASS: " ..os.getComputerID().. ")\n")
- test = fs.open(websitename, "r")
- fileContents = test:readAll()
- test.close()
- while true do
- sleep(0)
- id, message = rednet.receive()
- if message == websitename then
- record(" [" ..os.time().."] [" ..id.. "] Pinged Website.")
- rednet.send(id, fileContents)
- record(" [" ..os.time().."] [" ..id.. "] Received Data")
- elseif message == websitename.. "/editor" then
- rednet.send(id, "EditorMode")
- rednet.send(id, tostring(os.getComputerID()))
- rednet.send(id, fileContents)
- elseif message == websitename.. "/editor EDITED COMPLED!" then
- id, message = rednet.receive(0.001)
- fs.delete(websitename)
- webpage = fs.open(websitename, "w")
- webpage.write(message)
- webpage.close()
- test = fs.open(websitename, "r")
- fileContents = test:readAll()
- test.close()
- record(" [" ..os.time().."] [" ..id.. "] Updated Website!")
- end
- end
- ]]
- startup.writeLine(servercode)
- startup.close()
- os.reboot()
- end
- local Address = function()
- text = "rdnt://"
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), 2)
- term.clearLine()
- write("rdnt://")
- website = read()
- loadWebpage()
- end
- function done()
- term.setCursorPos(1, y)
- name = "F5 = Refresh"
- write("Press CTRL to travel the web! :D")
- term.setCursorPos(x - name:len(), y)
- write(name)
- while true do
- sleep(0) -- stop crashing
- e, k = os.pullEvent("key")
- if k == 63 then
- loadWebpage()
- break
- elseif k == 29 then
- Address()
- break
- end
- end
- end
- loadWebpage = function()
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- if website == "home" then
- print("Welcome to RedNet explorer (2.0)! This requires you to have a wireless modem on your computer.")
- print("Host a website at: ")
- print("rdnt://newsite! ")
- print(" -ComputerCraftFan11 ")
- elseif website == "newsite" then
- print("Internet Cafe Web Safety\n")
- print("Blocked for: \nEditing Startup.")
- else
- title = "Rednet Explorer " ..rednetV()
- rednet.send(133, "Blo" ..website)
- id, message = rednet.receive()
- if message == "safe" then
- rednet.broadcast(website)
- print("Connecting...")
- id, message = rednet.receive(0.1)
- if message == nil then
- print("Unable to load webpage.")
- elseif message == "EditorMode" then
- id, password = rednet.receive(0.1)
- id, EditingValue = rednet.receive(0.1)
- write("Password: ")
- input = read("*")
- if tostring(password) == input then
- fs.delete(".cache/" ..website)
- editor = fs.open(".websiteedited", "w")
- if editor then
- editor.writeLine(EditingValue)
- end
- editor.close()
- shell.run("edit", ".websiteedited")
- edited = fs.open(".websiteedited", "r")
- editwebpage = edited.readAll()
- edited.close()
- rednet.broadcast(website.. " EDITED COMPLED!")
- rednet.broadcast(editwebpage)
- website = "home"
- loadWebpage()
- else
- website = "home"
- loadWebpage()
- end
- else
- if fs.exists(".cache/" ..website) then fs.delete(".cache/" ..website) end
- webpage = fs.open(".cache/" ..website, "w")
- webpage.write(message)
- webpage.close()
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- shell.run(".cache/" ..website)
- end
- else
- print("Internet Cafe Web Safety\n")
- print("Blocked for: \n"..message..".")
- end
- end
- done()
- end
- loadWebpage()
Advertisement
Add Comment
Please, Sign In to add comment