Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- -------- Mozilla Firefox
- -- -------- Created by 1lann
- -- -------- Edited by GravityScore
- function firefoxVersion()
- return "1.3.2 - Secure"
- end
- -- -------- Variables
- autoUpdate = false
- firefoxTitle = "Mozilla Firefox " .. firefoxVersion()
- firefoxServerTitle = "Firefox Server " .. firefoxVersion()
- local x, y = term.getSize()
- local bDatabase = {}
- local bvIDs = {}
- local bvAddresses = {}
- local bType = nil
- exitFirefox = false
- local firsttime = true
- local title = firefoxTitle
- local root = "/.FirefoxData"
- local blacklistLoc = root .. "/firefox_blacklist"
- local whitelistLoc = root .. "/firefox_whitelist"
- local killSite = false
- local secureHostFunc = function(f,p)
- local secureHost = coroutine.create(f)
- killSite = false
- coroutine.resume(secureHost,p)
- while not killSite do
- local ev,p1,p2,p3,p4,p5,p6 = os.pullEvent()
- if coroutine.status(secureHost) ~= "dead" then
- coroutine.resume(secureHost,ev,p1,p2,p3,p4,p5,p6)
- else
- break
- end
- end
- if killSite then
- print("Site execution aborted due security errors:"..killSite)
- end
- end
- function securityError(sec)
- print("SECURITY ERROR: "..sec)
- killSite = sec
- coroutine.yield()
- end
- local secureEnv = {}
- secureEnv.fs = {}
- --secureEnv.fs.open = function() securityError("fs.open") end
- --secureEnv.fs.d
- secureEnv.io = {}
- secureEnv.setfenv = function() securityError("setfenv") end
- secureEnv.getfenv = function() securityError("getfenv") end
- secureEnv.setmetatable = function() securityError("setmetatable") end
- secureEnv.getmetatable = function() securityError("getmetatable") end
- setmetatable(secureEnv,{__index=_G})
- setmetatable(secureEnv.fs,{__index=function(t,v) securityError(v) end})
- setmetatable(secureEnv.io,{__index=function(t,v) securityError(v) end})
- --Open Rednet
- rednet.open("top")
- rednet.open("left")
- rednet.open("right")
- rednet.open("back")
- rednet.open("front")
- rednet.open("bottom")
- -- -------- Functions
- local function prompt(list, dir)
- --Variables
- local curSel = 1
- local c1 = 200
- local c2 = 208
- if dir == "horizontal" then c1 = 203 c2 = 205 end
- --Draw words
- for i = 1, #list do
- if list[i][2] == 1 then list[i][2] = 2
- elseif list[i][2] + string.len(list[i][1]) >= 50 then
- list[i][2] = 49 - string.len(list[i][1])
- end
- term.setCursorPos(list[i][2], list[i][3])
- write(list[i][1])
- end
- --Functions
- local function drawArrows(word, x, y)
- --Draw arrows
- term.setCursorPos(x, y)
- write("[")
- term.setCursorPos(x + 1 + string.len(word), y)
- write("]")
- end
- local function removeArrows(word, x, y)
- --Remove current arrows
- term.setCursorPos(x, y)
- write(" ")
- term.setCursorPos(x + 1 + string.len(word), y)
- write(" ")
- end
- --Draw arrows
- drawArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
- --Start loop
- while true do
- --Get the key
- local event, key = os.pullEvent("key")
- --Remove arrows
- removeArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
- if key == c1 then
- --Subtract
- if curSel ~= 1 then
- curSel = curSel - 1
- end
- elseif key == c2 then
- --Add
- if curSel ~= #list then
- curSel = curSel + 1
- end
- elseif key == 28 then
- --Enter
- return list[curSel][1]
- end
- --Draw Arrows
- drawArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
- end
- end
- function getPastebin(pCode, pLocation)
- -- Get from pastebin
- local response = http.get("http://pastebin.com/raw.php?i=" .. textutils.urlEncode(pCode))
- if response then
- local sResponse = response.readAll()
- response.close()
- local file = fs.open(pLocation, "w")
- file.write(sResponse)
- file.close()
- end
- end
- function debug(debugmsg)
- -- Print a debug message
- term.setCursorPos(1,1)
- term.clearLine()
- write(debugmsg)
- sleep(0.1)
- end
- function isVerified(vWebsite, vID)
- -- Verify an ID
- for i = 1, #bvAddresses do
- if vWebsite == string.lower(bvAddresses[i]) then
- if tostring(vID) == bvIDs[i] then
- return "good"
- else
- return "bad"
- end
- end
- end
- return "unknown"
- end
- function getDatabase()
- -- Get database from pastebin
- getPastebin("KL3WwmER", root .. "/fireDatabase")
- getPastebin("GC4HK1We", root .. "/fireVerified")
- local f = io.open(root .. "/fireDatabase", "r")
- bDatabase = {}
- for readData in f:lines() do
- table.insert(bDatabase, readData)
- end
- f:close()
- f = io.open(root .. "/fireVerified", "r")
- bvIDs = {}
- bvAddresses = {}
- bType = "url"
- for readData in f:lines() do
- if bType == "url" then
- table.insert(bvAddresses, readData)
- bType = "id"
- else
- table.insert(bvIDs, readData)
- bType = "url"
- end
- end
- f:close()
- if not(fs.exists(blacklistLoc)) then
- f = io.open(blacklistLoc, "w") f:write("\n") f:close()
- else
- f = io.open(blacklistLoc, "r")
- for readData in f:lines() do
- table.insert(bDatabase, readData)
- end
- f:close()
- end
- if not fs.exists(whitelistLoc) then
- f = io.open(whitelistLoc, "w") f:write("\n") f:close()
- else
- bType = "url"
- f = io.open(whitelistLoc, "r")
- local x = 1
- local bnLines = 0
- for readData in f:lines() do
- bnLines = bnLines+1
- if bType == "url" then
- table.insert(bvAddresses, readData)
- bType = "id"
- else
- table.insert(bvIDs, readData)
- bType = "url"
- end
- end
- f:close()
- if #bvAddresses > #bvIDs then table.remove(bvAddresses, #bvAddresses)
- elseif #bvAddresses < #bvIDs then table.remove(bvIDs, #bvIDs) end
- end
- return (bDatabase)
- end
- function isBad(number)
- for i = 1, #bDatabase do
- if tostring(number) == bDatabase[i] then
- return true
- end
- end
- return false
- end
- function dbContains(object, dbase)
- for i = 1, #dbase do
- if tostring(object) == dbase[i] then
- return true, i
- end
- end
- return false
- end
- function checkMalicious()
- local suspected = {}
- local times = {}
- for i = 1, 5 do
- rednet.broadcast(tostring(math.random(1, 9001)))
- startClock = os.clock()
- while os.clock() - startClock < 0.05 do
- local a = rednet.receive(0.01)
- if a ~= nil then
- dbState, dbPos = dbContains(a, suspected)
- if isBad(a) then
- elseif not dbState then
- table.insert(suspected, tostring(a))
- table.insert(times, 1)
- break
- else
- local newTimes = times[dbPos] + 1
- times[dbPos] = newTimes
- end
- end
- end
- end
- for i =1, #suspected do
- if times[i] > 2 then
- f = io.open(blacklistLoc, "a")
- f:write(suspected[i] .. "\n")
- f:close()
- table.insert(bDatabase, suspected[i])
- end
- end
- end
- if not fs.exists(root) then
- fs.makeDir(root)
- fs.makeDir(root .. "/cache")
- elseif not fs.isDir(root) then
- fs.delete(root)
- fs.makeDir(root)
- fs.makeDir(root .. "/cache")
- end
- if fs.exists("/fireverify") then fs.move("/fireverify", whitelistLoc) end
- if fs.exists("/firelist") then fs.move("/firelist", blacklistLoc) end
- if fs.exists("/firefox_whitelist") then fs.move("/firefox_whitelist", whitelistLoc) end
- if fs.exists("/firefox_blacklist") then fs.move("/firefox_blacklist", blacklistLoc) end
- if fs.exists("/.fireServerPref") then fs.move("/.fireServerPref", root .. "/fireServerPref") end
- local website = "home"
- fs.delete("/.fireDatabase")
- fs.delete("/.fireVerify")
- function centerPrint(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 setTitle(tToSet)
- title = tToSet
- if title == nil then
- title = firefoxTitle
- end
- term.setCursorPos(1,1)
- term.clearLine()
- centerPrint(title)
- term.setCursorPos(1,2)
- term.clearLine()
- centerPrint("rdnt://" .. website .. "\n")
- end
- local function createSite(websitename)
- term.clear()
- term.setCursorPos(1, 2)
- print("Creating Site: " .. websitename)
- print("Please Wait...")
- f = io.open(root .. "/fireServerPref", "w")
- f:write(websitename)
- f:close()
- getPastebin("wEmK4D4U", root .. "/firefoxServerUpdater")
- shell.run(root .. "/firefoxServerUpdater")
- exitFirefox = true
- error()
- end
- function loadWebpage()
- if exitFirefox then error() end
- term.clear()
- term.setCursorPos(1,1)
- title = firefoxTitle
- centerPrint(title)
- website = string.lower(website)
- centerPrint("rdnt://" ..website.. "\n")
- if website == "home" then
- if firsttime then
- term.clear()
- term.setCursorPos(1, 4)
- print(" _____ _ ______ _____ ")
- print(" ~~~~~~~ / ___/ / / / _ / / ___/ ")
- print(" ------ / /__ / / / /_/ / / /_ ")
- print(" ~~~~~ / ___/ / / / _ _/ / __/ ")
- print(" ---- / / / / / / \\ \\ / /___ ")
- print(" ~~~ / / /_/ /_/ \\_\\/_____/ ")
- print(" -- / / _,-=._ /|_/| ")
- print(" ~ /_/ `-.} `=._,.-=-._., @ @._,")
- print(" `. _ _,-. ) _,.-' ")
- print(" G.m-\"^m`m' ")
- print(" ")
- print(" Mozilla Firefox is Now Loading... ")
- sleep(0.1)
- if autoUpdate then
- getPastebin("ppnsSi26", root .. "/firefoxClientUpdate")
- local f = io.open(root .. "/firefoxClientUpdate", "r")
- clientUpdate = f:read("*a")
- f:close()
- local ff = io.open("/firefox")
- currentClient = ff:read("*a")
- ff:close()
- if not(currentClient == clientUpdate) then
- fs.delete("/firefox")
- fs.move(root .. "/firefoxClientUpdate", "/firefox")
- shell.run("/firefox")
- error()
- end
- end
- firsttime = false
- end
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint(title)
- centerPrint("rdnt://" ..website.. "\n")
- centerPrint("Welcome to Mozilla Firefox " .. firefoxVersion())
- print(" ")
- if autoUpdate then
- print(" Auto Updating is On")
- else
- print(" Auto Updating is Off")
- end
- print(" ")
- print(" Useful Websites:")
- print(" - rdnt://exit To Exit")
- print(" - rdnt://help For Help on Black/Whitelisting")
- print(" - rdnt://update to Force Update Firefox")
- print(" - rdnt://newsite to Make a New Website")
- print(" - rdnt://credits to View Credits")
- elseif website == "exit" then
- term.clear()
- term.setCursorPos(1,1)
- print("Thank you for using Firefox!")
- sleep(0.3)
- exitFirefox = true
- return
- elseif website == "update" then
- centerPrint("Force Update Firefox?")
- print(" ")
- local o = prompt({{"Yes", 11, 8}, {"No", 36, 8}}, "horizontal")
- if o == "Yes" then
- term.setCursorPos(1,1)
- term.clear()
- centerPrint(title)
- centerPrint("rdnt://" ..website.. "\n")
- centerPrint("Updating...")
- getPastebin("ppnsSi26", "/firefox")
- term.clear()
- term.setCursorPos(1,1)
- centerPrint(title)
- centerPrint("rdnt://" ..website.. "\n")
- centerPrint("Firefox Has Been Updated")
- centerPrint("Press Any Key to Restart Firefox")
- os.pullEvent("key")
- shell.run("/firefox")
- error()
- else
- term.clear()
- term.setCursorPos(1,1)
- centerPrint(title)
- centerPrint("rdnt://" ..website.. "\n")
- centerPrint("Cancelled")
- end
- elseif website == "help" then
- term.setCursorPos(1, 4)
- print(" Help for Black and Whitelists:")
- print(" - Lists are stored in /.FirefoxData")
- print(" - To Add a Server to the Blacklist:")
- print(" - Enter the ID of the server you wish to block")
- print(" - Example:")
- print(" 135")
- print(" - To Add a Server to the Whitelist:")
- print(" - Enter the server's URL on the first line")
- print(" - Enter the server's ID on the next line")
- print(" - Example:")
- print(" mozilla")
- print(" 175")
- elseif website == "clear" then
- reDirect("home")
- elseif website == "credits" then
- term.setCursorPos(1, 4)
- print(" Firefox Credits:")
- print(" - Programmed by 1lann")
- print(" - Designed and Edited by GravityScore")
- print(" ")
- print(" - Based off Rednet Explorer v2.4.1,")
- print(" - Which is made by xXm0dzXx and CCFan11")
- elseif website == "newsite" then
- term.setCursorPos(1, 4)
- centerPrint("Use This Computer as a Website Server?")
- local k = prompt({{"Yes", 11, 6}, {"No", 36, 6}}, "horizontal")
- if k == "Yes" then
- term.clear()
- term.setCursorPos(1, 1)
- title = firefoxServerTitle
- centerPrint(title)
- print(" ")
- if fs.exists(root .. "/fireServerPref") then
- f = io.open(root .. "/fireServerPref", "r")
- websitename = f:read("*l")
- f:close()
- if fs.isDir("/" .. websitename) then
- centerPrint("A Previous Server Setup has Been Detected")
- centerPrint("For: " .. websitename)
- centerPrint("Use This Setup?")
- local opt = prompt({{"Yes", 11, 9}, {"No", 36, 9}}, "horizontal")
- if opt == "Yes" then
- createSite(websitename)
- end
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint(title)
- term.setCursorPos(2, 4)
- write("Website Name: ")
- websitename = read()
- f = io.open(root .. "/fireServerPref", "w")
- f:write(websitename)
- f:close()
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint(title .. "\n")
- if fs.exists("/" .. websitename) then
- if not(fs.isDir("/" .. websitename)) then
- fs.move("/" .. websitename, root .. "/firefoxtemphome")
- fs.makeDir("/" .. websitename)
- fs.move(root .. "/firefoxtemphome", "/" .. websitename .. "/home")
- print(" An Old Website Has Been Detected")
- print(" It Has Been Moved To: ")
- print(" /" .. websitename .. "/home")
- print(" ")
- end
- else
- fs.makeDir("/" .. websitename)
- end
- rednet.broadcast(string.lower(websitename))
- local i, me = rednet.receive(0.5)
- if i ~= nil then
- print(" WARNING: This Domain Name May Already Be In Use")
- print(" ")
- end
- print(" The Website Files can be Found In:")
- print(" /" .. websitename)
- print(" The Homepage is Located At:")
- print(" /" .. websitename .. "/home")
- print(" ")
- print(" Edit the Homepage of the Website?")
- local o = prompt({{"Yes", 11, 14}, {"No", 36, 14}}, "horizontal")
- if o == "Yes" then
- shell.run("/rom/programs/edit", "/" .. websitename .. "/" .. "home")
- elseif o == "No" then
- if not fs.exists("/" .. websitename .. "/" .. "home") then
- local f = io.open("/" .. websitename .. "/" .. "home", "w")
- f:write("print(\" \")\nprint(\"Welcome to " .. websitename .. "\")")
- end
- f:close()
- end
- term.clear()
- term.setCursorPos(1, 1)
- createSite(websitename)
- end
- else
- title = firefoxTitle
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint(title)
- centerPrint("rdnt://" ..website.. "\n")
- print(" Connecting to Website...")
- checkMalicious()
- rednet.broadcast(website)
- if string.find(website, "/") then
- fWebsite = string.gsub(website, "/", "$slazh$")
- else
- fWebsite = website
- end
- local website1 = root .. "/cache/" .. fWebsite
- local startClock = os.clock()
- while os.clock() - startClock < 0.05 do
- id, message = rednet.receive(0.01)
- vResult = isVerified(website, id)
- if vResult == "bad" then message = nil
- elseif vResult == "good" then break
- elseif vResult == "unknown" and isBad(id) == false then break
- else message = nil
- end
- end
- if message == nil then
- if fs.exists(website1) then
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint(title)
- centerPrint("rdnt://" ..website.. "\n")
- centerPrint("Unable to Connect to Website")
- centerPrint("Resort to Cached Version?")
- local o = prompt({{"Yes", 11, 8}, {"No", 36, 8}}, "horizontal")
- if o == "Yes" then
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint(title)
- centerPrint("rdnt://" ..website.. "\n")
- shell.run(website1)
- if exitFirefox then
- error()
- end
- elseif o == "No" then
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint(title)
- centerPrint("rdnt://" ..website.. "\n")
- centerPrint(" _____ _ ")
- centerPrint("| ___| | |")
- centerPrint("| |__ _ __ _ __ ___ _ __ | |")
- centerPrint("| __|| '__|| '__|/ _ \\ | '__|| |")
- centerPrint("| |___| | | | | (_) || | |_|")
- centerPrint("\\____/|_| |_| \\___/ |_| (_)")
- print(" ")
- centerPrint("Unable to Connect to Website")
- centerPrint("The Website May Be Down or Blocked")
- end
- else
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint(title)
- centerPrint("rdnt://" ..website.. "\n")
- centerPrint(" _____ _ ")
- centerPrint("| ___| | |")
- centerPrint("| |__ _ __ _ __ ___ _ __ | |")
- centerPrint("| __|| '__|| '__|/ _ \\ | '__|| |")
- centerPrint("| |___| | | | | (_) || | |_|")
- centerPrint("\\____/|_| |_| \\___/ |_| (_)")
- print(" ")
- centerPrint("Unable to Connect to Website")
- centerPrint("The Website May Be Down or Blocked")
- end
- else
- if fs.exists(website1) then fs.delete(website1) end
- local webpage = io.open(website1, "w")
- webpage:write(message)
- webpage:close()
- term.clear()
- term.setCursorPos(1, 1)
- centerPrint(title)
- centerPrint("rdnt://" ..website.. "\n")
- local runSecure = function(website1) local file = fs.open(website1,"r") local s = file.readAll() file.close() local f = loadstring(s) setfenv(f,secureEnv) f() end
- --setfenv(runSecure,secureEnv)
- secureHostFunc(runSecure,website1)
- --shell.run(website1)
- if exitFirefox then
- error()
- end
- end
- end
- if exitFirefox then error() end
- os.queueEvent("firefoxDoneLoading")
- term.setCursorPos(1, y)
- local name = "F5 to Refresh"
- write("Control to Surf the Web")
- term.setCursorPos(x - name:len(), y)
- write(name)
- while true do
- local e, k = os.pullEvent("key")
- if k == 63 then
- loadWebpage()
- break
- elseif k == 29 then
- term.setCursorPos(1,2)
- term.clearLine()
- write("rdnt://")
- website = read()
- loadWebpage()
- break
- end
- end
- end
- function autoDatabase()
- while true do
- local aDE = os.pullEvent()
- if aDE == "firefoxDoneLoading" then
- getDatabase()
- end
- end
- end
- parallel.waitForAny(autoDatabase, loadWebpage)
Advertisement
Add Comment
Please, Sign In to add comment