Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x,y = term.getSize()
- local version = "v 1.1"
- local website = "home";
- if fs.exists(".cache") then fs.delete(".cache") end
- fs.makeDir(".cache")
- local history = {"", "", "", "", "", "", "", "", "", ""}
- rednet.open("top")
- rednet.open("bottom")
- rednet.open("left")
- rednet.open("right")
- rednet.open("back")
- rednet.open("right")
- function getPastebin(pCode, pLocation)
- local sCode = pCode
- local sFile = pLocation
- local sPath = pLocation
- -- GET the contents from pastebin
- local response = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local file = fs.open( sPath, "w" )
- file.write( sResponse )
- file.close()
- else
- end
- end
- function isUpdate()
- local response = http.get("http://pastebin.com/raw.php?i=XFRj6NhD")
- if response then
- local sResponse = response.readAll()
- response.close()
- if sResponse == version then
- return false
- end
- return true
- end
- end
- function addHistory(val)
- table.remove(history)
- table.insert(history, 1, val)
- end
- function listHistory()
- for i = 1, 10 do
- print(tostring(i)..". "..history[i])
- end
- end
- function visitHistory(num)
- numI = tonumber(num)
- website = history[numI]
- loadWebpage()
- end
- function isDangerous(msg)
- a = string.find(msg, "startup")
- if a == nil then return false end
- return true
- end
- function savePageToFile(addr, file, check)
- rednet.broadcast(addr)
- id, message = rednet.receive(0.8)
- if message == nil then
- return
- end
- if isDangerous(message) == true and check == true then
- print("The webpage will meight modify your startup")
- print("continue anyways")
- print("Y = YES N = NO")
- while true do
- e, k = os.pullEvent("char")
- if k == "y" or k == "n" then
- break
- end
- end
- if k == "n" then return end
- end
- f = fs.open(file, "w")
- f.write(message)
- f.close()
- end
- local cPrint = function(text)
- local x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- print(text)
- end
- function reDirect(url)
- website = url
- loadWebpage()
- end
- function createSite(websitename, crawl, keys) --OPENNEXISGATES
- print("Warning this will overwrite your startup")
- print("continue anyways")
- print("Y = YES N = NO")
- while true do
- e, k = os.pullEvent("char")
- if k == "y" or k == "n" then
- break
- end
- end
- if k == "n" then return end
- fs.delete("startup")
- startup = fs.open("startup", "w")
- startup.writeLine("websitename = \"" ..websitename.. "\"")
- servercode = [[
- local enableSearching = "]]..tostring(crawl)..[["
- local keys = "]]..keys.. [["
- 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")
- rednet.open("left")
- rednet.open("right")
- rednet.open("back")
- rednet.open("front")
- rednet.open("bottom")
- term.clear()
- term.setCursorPos(1,1)
- print("Hosting " ..websitename.. "...")
- print("Press \"E\" to edit site")
- while true do
- test = io.open(websitename, "r")
- fileContents = test:read("*a")
- test:close()
- term.setCursorPos(1,1)
- print("Hosting " ..websitename.. "...")
- print("Press \"E\" to edit site")
- event, id, message = os.pullEvent()
- if event == "key" and id == 18 then
- sleep(0.2)
- shell.run("/rom/programs/edit", "/" .. websitename)
- elseif event == "rednet_message" then
- if message == websitename then
- record(" [" ..os.time().."] [" ..id.. "] Pinged Website.")
- for i = 1, 10 do
- rednet.send(id, fileContents)
- end
- record(" [" ..os.time().."] [" ..id.. "] Received Data")
- elseif message == "rednet.api.ping.searchengine" and enableSearching == true then
- rednet.send(id, websitename)
- record(" [" ..os.time().."] [" ..id.. "] Searched by " .. id)
- elseif message == "rednet.api.website.keys" and enableSearching == true then
- rednet.send(id, keys)
- record(" [" ..os.time().."] [" ..id.. "] Keywords req by " .. id)
- end
- end
- end
- ]]
- startup.writeLine(servercode)
- startup.close()
- os.reboot()
- end
- local Address = function()
- text = "rdnt://"
- term.setCursorPos(1,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()
- addHistory(website)
- local title = "Google Chrome "..version
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- if website == "home" then
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- print("Welcome to Google Chrome!")
- print("by xuma")
- print("visit rdnt://chrome:help to find out about Chrome")
- print("you can go to rdnt://chrome:exit to close Chrome")
- print("To host a website visit rdnt://chrome:new")
- elseif website == "chrome:exit" then
- term.clear()
- term.setCursorPos(1,1)
- print("Thanks for using Chrome!")
- error()
- elseif website == "chrome:help" then
- print("List of special pages:")
- print("home ,shows the main page")
- print("chrome:help ,shows this page")
- print("chrome:exit ,will exit chrome")
- print("chrome:new ,allows you to setup a new webpage")
- print("chrome:settings ,allows you to make settings")
- print("chrome:history ,shows your history")
- print("chrome:save ,allows you to save a webpage to a file")
- print("chrome:version ,information about the verion of Chorme you use")
- elseif website == "chrome:new" then
- print("Are you sure you would like to make this PC a server?")
- cPrint("Y = Yes N = No")
- while true do
- e, k = os.pullEvent("char")
- if k == "y" or k == "n" then
- break
- end
- end
- if k == "y" then
- term.clear()
- term.setCursorPos(1,1)
- title = "Chrome Sever " ..version
- cPrint(title)
- print("Welcome to Chrome for servers. Please enter the website name: ")
- websitename = read()
- rednet.broadcast(websitename)
- i, me = rednet.receive(0.1)
- if me == nil then
- else print("WARNING: Another server possibly using this domain")
- end
- print("Thank you! Do you want your website crawled by search engines?")
- cPrint("Y = YES N = NO")
- while true do
- e, k = os.pullEvent("char")
- if k == "y" or k == "n" then
- break
- end
- end
- crawl = false
- keywords = ""
- if k == "y" then
- print("Great. You can now enter keywords for your site seperated by a ,")
- keyswords = read()
- crawl = true
- end
- print("This website will be running off of the file:\n" ..websitename.. "\n")
- write("Are you sure? (Y = Continue, E = Edit)")
- while true do
- event, key = os.pullEvent("key")
- if key == 21 or key == 18 then
- break
- end
- end
- if key == 21 then
- if fs.exists(websitename) == false then
- print("Please create " ..websitename.. " first!")
- sleep(3)
- shell.run("/rom/programs/edit", "/" .. websitename)
- end
- term.clear()
- term.setCursorPos(1,1)
- createSite(websitename, crawl, keywords)
- elseif key == 18 then
- sleep(0.2)
- shell.run("/rom/programs/edit", "/" .. websitename)
- term.clear()
- term.setCursorPos(1,1)
- createSite(websitename, crawl, keywords)
- end
- end
- elseif website == "chrome:settings" then
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- print("No settings to make yet")
- elseif website == "chrome:history" then
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- print("Last ten pages you've visited: ")
- listHistory()
- print("Enter the number of the page to visit it now or press enter")
- num = read()
- if num ~= "" then
- visitHistory(num)
- end
- elseif website == "chrome:save" then
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- print("Enter the adress of the website: ")
- addr = read()
- savePageToFile(addr, "site_"..addr , false)
- if fs.exists("site_"..addr) == true then
- print("")
- print("The webpage has been saved to the file site_"..addr)
- print("")
- print("Do you want to open the file with the editor now?")
- cPrint("Y = YES N = NO")
- while true do
- e, k = os.pullEvent("char")
- if k == "y" or k == "n" then
- break
- end
- end
- if k == "y" then shell.run("/rom/programs/edit", "/site_" .. addr) end
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- print("Finished.")
- else
- print("Unable to load website")
- end
- elseif website == "chrome:version" then
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- print("You are currently using Gogle Chrome"..version)
- else
- title = "Google Chrome" ..version
- savePageToFile(website, ".cache/"..website, true)
- if fs.exists(".cache/" ..website) == true then
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- shell.run(".cache/" ..website)
- else
- term.clear()
- term.setCursorPos(1,1)
- cPrint(title)
- cPrint("rdnt://" ..website.. "\n")
- print("Website unreachable.")
- end
- end
- done()
- end
- if isUpdate() then
- cPrint("There is an update available")
- cPrint("Updating...")
- getPastebin("pcanbrn2", "/chrome")
- cPrint("update saved to chrome please restart chrome now.")
- error()
- end
- loadWebpage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement