Advertisement
GravityScore

Firewolf 1.4.5

Nov 17th, 2012
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 57.79 KB | None | 0 0
  1. --  -------- Mozilla Firefox
  2. --  -------- Made by GravityScore and 1lann
  3.  
  4. --  -------- Original Idea from Rednet Explorer v2.4.1
  5. --  -------- Rednet Explorer made by xXm0dzXx/CCFan11
  6.  
  7.  
  8.  
  9. --  -------- Global Variables
  10.  
  11. local exitApp = false
  12. local finishExit = false
  13. local exitWebsite = false
  14.  
  15. -- Encase in function
  16. local function entiretyFirefox()
  17.  
  18.  
  19. --  -------- Constants
  20.  
  21. -- Version
  22. local firefoxVersion = "1.4.5"
  23. local browserAgentTemplate = "Mozilla Firefox " .. firefoxVersion
  24. browserAgent = ""
  25.  
  26. -- Server Identification
  27. local serverID = "old"
  28. local serverList = {m0dz = "Hacker's Paradise", immibis = "turtle.dig()", ctcraft = "CTCraft",
  29.                     geevancraft = "GeevanCraft", experimental = "Experimental",
  30.                     other = "Other", old = "None"}
  31.  
  32. -- Updating
  33. local autoupdate = "false"
  34. local incognito = "false"
  35. local debugging = false
  36. local override = false
  37.  
  38. -- Dropbox URLs
  39. local firefoxURL = "http://dl.dropbox.com/u/97263369/firefox/entities/" .. serverID .. ".lua"
  40. local databaseURL = "http://dl.dropbox.com/u/97263369/firefox/databases/" .. serverID .. "-database.txt"
  41. local serverURL = "http://dl.dropbox.com/u/97263369/firefox/firefox-server.lua"
  42.  
  43. -- Events
  44. local openURLBarEvent = "firefox_open_url_bar_event"
  45. local websiteLoadEvent = "firefox_website_loaded_event"
  46.  
  47. -- Webpage Variables
  48. local website = ""
  49. local homepage = ""
  50. local site = "home"
  51. local history = {}
  52. local searchBarHistory = {}
  53. local websiteLoadingRate = 0
  54. local loadingRateClock = os.clock()
  55. local timeout = 0.05
  56. local userTerminated = false
  57. local errorMessage = nil
  58. local lockCtrl = false
  59. local secureRedirection = nil
  60.  
  61. -- Prevent API Overrides
  62. local function copyTable(oldTable)
  63.     local oldTable = oldTable
  64.     local newTable = {}
  65.     for k,v in pairs(oldTable) do
  66.         newTable[k] = v
  67.     end
  68.     return newTable
  69. end
  70.  
  71. local fparallel = copyTable(parallel)
  72. local fstring = copyTable(string)
  73. local frednet = copyTable(rednet)
  74. local ftable = copyTable(table)
  75. local fhttp = copyTable(http)
  76. local ftextutils = copyTable(textutils)
  77. local fos = copyTable(os)
  78. local fterm = copyTable(term)
  79. local fshell = copyTable(shell)
  80. local ffs = copyTable(fs)
  81. local fio = copyTable(io)
  82. local ftostring = tostring
  83. local ftonumber = tonumber
  84. local fpcall = pcall
  85. local fperipheral = copyTable(peripheral)
  86. local fsleep = sleep
  87. local fprint = print
  88. local fwrite = write
  89. local fmath = copyTable(math)
  90. local ferror = error
  91. local fcoroutine = copyTable(coroutine)
  92. local backupYield = coroutine.yield
  93. local securePastebinDownload = nil
  94. local secureUrlDownload = nil
  95.  
  96. -- Databases
  97. local blacklistDatabase = {}
  98. local whitelistDatabase = {}
  99. local verifiedDatabase = {}
  100. local antivirusDefinitions = {}
  101. local downloadDatabase = {}
  102.  
  103. -- Data Locations
  104. local rootFolder = "/.Firefox_Data"
  105. local cacheFolder = rootFolder .. "/cache"
  106. local serverFolder = rootFolder .. "/servers"
  107. local serverSoftwareLocation = rootFolder .. "/server_software"
  108. local settingsLocation = rootFolder .. "/settings"
  109. local historyLocation = rootFolder .. "/history"
  110. local firefoxLocation = "/" .. fshell.getRunningProgram()
  111.  
  112. local userBlacklist = rootFolder .. "/user_blacklist"
  113. local userWhitelist = rootFolder .. "/user_whitelist"
  114. local globalDatabase = rootFolder .. "/database"
  115.  
  116. -- Firefox 1.3 Support
  117. local runningWebsite = ""
  118.  
  119. local function titleForPage(site)
  120.     -- Preset titles
  121.     local siteTitles = {{"firefox", "Mozilla Firefox"}, {"history", "Firefox History"},
  122.                         {"server", "Server Management"}, {"help", "Firefox Help"},
  123.                         {"settings", "Firefox Settings"}, {"getinfo", "Get Website Info"},
  124.                         {"credits", "Firefox Credits"}}
  125.  
  126.     -- Search
  127.     for i = 1, #siteTitles do
  128.         if fstring.lower(siteTitles[i][1]) == fstring.lower(site) then
  129.             return siteTitles[i][2]
  130.         end
  131.     end
  132.  
  133.     return nil
  134. end
  135.  
  136. local function clearPage(url)
  137.     -- URL
  138.     local w, h = fterm.getSize()
  139.     local title = titleForPage(url)
  140.     fterm.clear()
  141.     fterm.setCursorPos(2, 1)
  142.     fterm.clearLine()
  143.     fwrite("rdnt://" .. url)
  144.  
  145.     -- Title
  146.     if title ~= nil then
  147.         fterm.setCursorPos(w - fstring.len("  " .. title), 1)
  148.         fwrite("  " .. title)
  149.     end
  150.  
  151.     -- Line
  152.     fterm.setCursorPos(1, 2)
  153.     fterm.clearLine()
  154.     if fterm.setTextColor then
  155.         fterm.setCursorPos(1,2)
  156.     else
  157.         fterm.setCursorPos(1,1)
  158.     end
  159.     fwrite(fstring.rep("-", w))
  160.     fprint(" ")
  161. end
  162.  
  163. local function restoreFunctions()
  164.     redirect = secureRedirection
  165.     peripheral = copyTable(fperipheral)
  166.     browserAgent = browserAgentTemplate
  167.     pastebinDownload = securePastebinDownload
  168.     urlDownload = secureUrlDownload
  169.     string = copyTable(fstring)
  170.     shell = copyTable(fshell)
  171.     term = copyTable(fterm)
  172.  
  173.     function compatability()
  174.         term = copyTable(fterm)
  175.         shell = copyTable(fshell)
  176.     end
  177.  
  178.     function centerPrint(text)
  179.         local w, h = fterm.getSize()
  180.         local x, y = fterm.getCursorPos()
  181.         fterm.setCursorPos(fmath.ceil((w + 1)/2 - text:len()/2), y)
  182.         fprint(text)
  183.     end
  184.  
  185.     function centerWrite(text)
  186.         local w, h = fterm.getSize()
  187.         local x, y = fterm.getCursorPos()
  188.         fterm.setCursorPos(fmath.ceil((w + 1)/2 - text:len()/2), y)
  189.         fwrite(text)
  190.     end
  191.  
  192.     function leftPrint(text)
  193.         local x, y = fterm.getCursorPos()
  194.         fterm.setCursorPos(4, y)
  195.         fprint(text)
  196.     end
  197.  
  198.     function leftWrite(text)
  199.         local x, y = fterm.getCursorPos()
  200.         fterm.setCursorPos(4, y)
  201.         fwrite(text)
  202.     end
  203.  
  204.     function rightPrint(text)
  205.         local x, y = fterm.getCursorPos()
  206.         local w, h = fterm.getSize()
  207.         fterm.setCursorPos(w - text:len() - 1, y)
  208.         fprint(text)
  209.     end
  210.  
  211.     function rightWrite(text)
  212.         local x, y = fterm.getCursorPos()
  213.         local w, h = fterm.getSize()
  214.         fterm.setCursorPos(w - text:len() - 1, y)
  215.         fwrite(text)
  216.     end
  217.  
  218.     function cPrint(text)
  219.         centerPrint(text)
  220.     end
  221.  
  222.     function cWrite(text)
  223.         centerWrite(text)
  224.     end
  225.  
  226.     function lPrint(text)
  227.         leftWrite(text)
  228.     end
  229.  
  230.     function lWrite(text)
  231.         leftWrite(text)
  232.     end
  233.  
  234.     function rPrint(text)
  235.         rightWrite(text)
  236.     end
  237.  
  238.     function rWrite(text)
  239.         rightWrite(text)
  240.     end
  241.  
  242.     function reDirect(site)
  243.         redirect(site)
  244.     end
  245.  
  246.     function clearArea()
  247.         clearPage(runningWebsite)
  248.     end
  249.  
  250.     function lockControl()
  251.         lockCtrl = true
  252.     end
  253.  
  254.     function unlockControl()
  255.         lockCtrl = false
  256.     end
  257. end
  258.  
  259. --  -------- Prompt Software
  260.  
  261. function prompt(list, dir, startCurSel, notControl)
  262.     -- Functions
  263.     local function drawArrows(word, x, y)
  264.         fterm.setCursorPos(x, y)
  265.         fwrite("[")
  266.         fterm.setCursorPos(x + 1 + fstring.len(word), y)
  267.         fwrite("]")
  268.     end
  269.    
  270.     local function removeArrows(word, x, y)
  271.         fterm.setCursorPos(x, y)
  272.         fwrite(" ")
  273.         fterm.setCursorPos(x + 1 + fstring.len(word), y)
  274.         fwrite(" ")
  275.     end
  276.  
  277.     -- Variables
  278.     local curSel = 1
  279.     if startCurSel ~= nil then
  280.         curSel = startCurSel
  281.     end
  282.     local nc = false
  283.     if notControl == true then nc = true end
  284.     local c1 = 200
  285.     local c2 = 208
  286.     if dir == "horizontal" then c1 = 203 c2 = 205 end
  287.  
  288.     -- Draw
  289.     for i = 1, #list do
  290.         if list[i][2] == -1 then
  291.             local w, h = fterm.getSize()
  292.             list[i][2] = fmath.floor(w/2 - list[i][1]:len()/2)
  293.         end
  294.         fterm.setCursorPos(list[i][2], list[i][3])
  295.         fwrite(list[i][1])
  296.     end
  297.     drawArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
  298.  
  299.     -- Selection
  300.     while not(exitApp) do
  301.         local event, key = fos.pullEvent("key")
  302.         removeArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
  303.         if key == c1 then
  304.             if curSel ~= 1 then curSel = curSel - 1 end
  305.         elseif key == c2 then
  306.             if curSel ~= #list then curSel = curSel + 1 end
  307.         elseif key == 28 then
  308.             return list[curSel][1]
  309.         elseif key == 29 or key == 157 then
  310.             if not(nc) then
  311.                 fos.queueEvent(openURLBarEvent)
  312.                 return nil
  313.             end
  314.         end
  315.         drawArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
  316.     end
  317. end
  318.  
  319. function scrollingPrompt(list, disLen, xStart, yStart)
  320.     -- Functions
  321.     local function drawItems(items)
  322.         for i = 1, #items do
  323.             fterm.setCursorPos(xStart, i + yStart)
  324.             fterm.clearLine(i + 4)
  325.             fwrite("[ ]  " .. items[i])
  326.         end
  327.     end
  328.  
  329.     local function updateDisplayList(items, disLoc, disLen)
  330.         local ret = {}
  331.         for i = 1, disLen do
  332.             local item = items[i + disLoc - 1]
  333.             if item ~= nil then ftable.insert(ret, item) end
  334.         end
  335.         return ret
  336.     end
  337.  
  338.     -- Variables
  339.     local disLoc = 1
  340.     local disList = updateDisplayList(list, 1, disLen)
  341.     local curSel = 1
  342.     drawItems(disList)
  343.     fterm.setCursorPos(xStart + 1, yStart + 1)
  344.     fwrite("x")
  345.    
  346.     -- Selection
  347.     while not(exitApp) do
  348.         local event, key = fos.pullEvent("key")
  349.         fterm.setCursorPos(xStart + 1, yStart + curSel)
  350.         fwrite(" ")
  351.         if key == 200 then
  352.             if curSel ~= 1 then
  353.                 curSel = curSel - 1
  354.             else
  355.                 if disLoc ~= 1 then
  356.                     disLoc = disLoc - 1
  357.                     disList = updateDisplayList(list, disLoc, disLen)
  358.                     drawItems(disList)
  359.                 end
  360.             end
  361.         elseif key == 208 then
  362.             if curSel ~= #disList then
  363.                 curSel = curSel + 1
  364.             else
  365.                 if disLoc + curSel - 1 ~= #list then
  366.                     disLoc = disLoc + 1
  367.                     disList = updateDisplayList(list, disLoc, disLen)
  368.                     drawItems(disList)
  369.                 end
  370.             end
  371.         elseif key == 28 then
  372.             return list[curSel + disLoc - 1], false
  373.         elseif key == 29 or key == 157 then
  374.             fos.queueEvent(openURLBarEvent)
  375.             return "", true
  376.         end
  377.         fterm.setCursorPos(xStart + 1, yStart + curSel)
  378.         fwrite("x")
  379.     end
  380. end
  381.  
  382.  
  383. --  -------- Drawing Utilities
  384.  
  385. function centerPrint(text)
  386.     local w, h = fterm.getSize()
  387.     local x, y = fterm.getCursorPos()
  388.     fterm.setCursorPos(fmath.ceil((w + 1)/2 - text:len()/2), y)
  389.     fprint(text)
  390. end
  391.  
  392. function centerWrite(text)
  393.     local w, h = fterm.getSize()
  394.     local x, y = fterm.getCursorPos()
  395.     fterm.setCursorPos(fmath.ceil((w + 1)/2 - text:len()/2), y)
  396.     fwrite(text)
  397. end
  398.  
  399. function leftPrint(text)
  400.     local x, y = fterm.getCursorPos()
  401.     fterm.setCursorPos(4, y)
  402.     fprint(text)
  403. end
  404.  
  405. function leftWrite(text)
  406.     local x, y = fterm.getCursorPos()
  407.     fterm.setCursorPos(4, y)
  408.     fwrite(text)
  409. end
  410.  
  411. function rightPrint(text)
  412.     local x, y = fterm.getCursorPos()
  413.     local w, h = fterm.getSize()
  414.     fterm.setCursorPos(w - text:len() - 1, y)
  415.     fprint(text)
  416. end
  417.  
  418. function rightWrite(text)
  419.     local x, y = fterm.getCursorPos()
  420.     local w, h = fterm.getSize()
  421.     fterm.setCursorPos(w - text:len() - 1, y)
  422.     fwrite(text)
  423. end
  424.  
  425.  
  426. --  -------- Filesystem Management
  427.  
  428. local function getDropbox(url, file)
  429.     for i = 1, 3 do
  430.         local response = fhttp.get(url)
  431.         if response then
  432.             local fileData = response.readAll()
  433.             response.close()
  434.             local f = fio.open(file,"w")
  435.             f:write(fileData)
  436.             f:close()
  437.             return true
  438.         end
  439.     end
  440.     return false
  441. end
  442.  
  443. local function resetFilesystem()
  444.     -- Folders
  445.     if not(ffs.exists(rootFolder)) then
  446.         ffs.makeDir(rootFolder)
  447.     elseif not(ffs.isDir(rootFolder)) then
  448.         ffs.move(rootFolder, "/Old_Firefox_Data_File")
  449.         ffs.makeDir(rootFolder)
  450.     end
  451.     if not(ffs.exists(cacheFolder)) then ffs.makeDir(cacheFolder) end
  452.     if not(ffs.exists(serverFolder)) then ffs.makeDir(serverFolder) end
  453.  
  454.     -- Settings
  455.     if not(ffs.exists(settingsLocation)) then
  456.         local f = fio.open(settingsLocation, "w")
  457.         f:write(textutils.serialize({auto = "true", incog = "false", home = "firefox"}))
  458.         f:close()
  459.     end
  460.  
  461.     -- Server software
  462.     if not(ffs.exists(serverSoftwareLocation)) then
  463.         if not getDropbox(serverURL, serverSoftwareLocation) then
  464.             term.clear()
  465.             term.setCursorPos(1,1)
  466.             fprint("Error: Could not download server software")
  467.             ferror()
  468.         end
  469.     end
  470.  
  471.     -- History
  472.     if not(ffs.exists(historyLocation)) then
  473.         local f = fio.open(historyLocation, "w")
  474.         f:write(textutils.serialize({}))
  475.         f:close()
  476.     end
  477.  
  478.     -- Databases
  479.     ffs.delete(globalDatabase)
  480.     for _, v in ipairs({globalDatabase, userWhitelist, userBlacklist}) do
  481.         if not(ffs.exists(v)) then
  482.             local f = fio.open(v, "w")
  483.             f:write("")
  484.             f:close()
  485.         end
  486.     end
  487. end
  488.  
  489.  
  490. --  -------- Updating Utilities
  491.  
  492. local function updateClient()
  493.     local updateLocation = rootFolder .. "/firefox-update"
  494.  
  495.     -- Get files and contents
  496.     if getDropbox(firefoxURL, updateLocation) then
  497.         local f1 = fio.open(updateLocation, "r")
  498.         local f2 = fio.open(firefoxLocation, "r")
  499.         local update = f1:read("*a")
  500.         local current = f2:read("*a")
  501.         f1:close()
  502.         f2:close()
  503.  
  504.         -- Update
  505.         if current ~= update then
  506.             ffs.delete(firefoxLocation)
  507.             ffs.move(updateLocation, firefoxLocation)
  508.             fshell.run(firefoxLocation)
  509.             ferror()
  510.         else
  511.             ffs.delete(updateLocation)
  512.         end
  513.     end
  514. end
  515.  
  516. local function appendToHistory(item)
  517.     if incognito == "false" then
  518.         -- Clean up item
  519.         local a = item:gsub("^%s*(.-)%s*$", "%1"):lower()
  520.         if a == "home" then
  521.             a = homepage
  522.         end
  523.  
  524.         -- Append to overall history
  525.         if a ~= "exit" and a ~= "history" and a ~= "" and history[1] ~= a then
  526.             ftable.insert(history, 1, a)
  527.             local f = fio.open(historyLocation, "w")
  528.             f:write(textutils.serialize(history))
  529.             f:close()
  530.         end
  531.  
  532.         -- Append to search bar history
  533.         if searchBarHistory[#searchBarHistory] ~= a then
  534.             ftable.insert(searchBarHistory, a)
  535.         end
  536.     end
  537. end
  538.  
  539.  
  540. ------ Website Verification
  541.  
  542. local function reloadDatabases()
  543.     -- Get
  544.     getDropbox(databaseURL, globalDatabase)
  545.     local f = fio.open(globalDatabase, "r")
  546.  
  547.     -- Blacklist
  548.     blacklistDatabase = {}
  549.     local l = f:read("*l")
  550.     while l ~= "START-WHITELIST" do
  551.         l = f:read("*l")
  552.         if l ~= nil and l ~= "" and l ~= "\n" and l ~= "START-BLACKLIST" and
  553.            l ~= "START-WHITELIST" then
  554.             l = l:gsub("^%s*(.-)%s*$", "%1"):lower()
  555.             ftable.insert(blacklistDatabase, l)
  556.         end
  557.     end
  558.  
  559.     -- Whitelist
  560.     whitelistDatabase = {}
  561.     l = ""
  562.     while l ~= "START-VERIFIED" do
  563.         l = f:read("*l")
  564.         if l ~= nil and l ~= "" and l ~= "\n" and l ~= "START-VERIFIED" and
  565.            l ~= "START-WHITELIST" and l:find("| |") then
  566.             l = l:gsub("^%s*(.-)%s*$", "%1"):lower()
  567.             local a, b = l:find("| |")
  568.             local n = l:sub(1, a - 1)
  569.             local id = l:sub(b + 1, -1)
  570.             ftable.insert(whitelistDatabase, {n, id})
  571.         end
  572.     end
  573.  
  574.     -- Verified
  575.     verifiedDatabase = {}
  576.     l = ""
  577.     while l ~= "START-DOWNLOADS" do
  578.         l = f:read("*l")
  579.         if l ~= nil and l ~= "" and l ~= "\n" and l ~= "START-VERIFIED" and
  580.            l ~= "START-DOWNLOADS" and l:find("| |") then
  581.             l = l:gsub("^%s*(.-)%s*$", "%1"):lower()
  582.             local a, b = l:find("| |")
  583.             local n = l:sub(1, a - 1)
  584.             local id = l:sub(b + 1, -1)
  585.             ftable.insert(verifiedDatabase, {n, id})
  586.         end
  587.     end
  588.  
  589.     -- Downloads
  590.     downloadDatabase  = {}
  591.     l = ""
  592.     while l ~= "START-DEFINITIONS" do
  593.         l = f:read("*l")
  594.         if l ~= nil and l ~= "" and l ~= "\n" and l ~= "START-DOWNLOADS" and
  595.            l ~= "START-DEFINITIONS" then
  596.             l = l:gsub("^%s*(.-)%s*$", "%1")
  597.             ftable.insert(downloadDatabase, l)
  598.         end
  599.     end
  600.  
  601.     -- Definitions
  602.     antivirusDefinitions = {}
  603.     l = ""
  604.     while l ~= "END-DATABASE" do
  605.         l = f:read("*l")
  606.         if l ~= nil and l ~= "" and l ~= "\n" and l ~= "START-VERIFIED" and
  607.            l ~= "END-DATABASE" then
  608.             l = l:gsub("^%s*(.-)%s*$", "%1")
  609.             ftable.insert(antivirusDefinitions, l)
  610.         end
  611.     end
  612.  
  613.     f:close()
  614.  
  615.     -- User Blacklist
  616.     if not(ffs.exists(userBlacklist)) then
  617.         local bf = fio.open(userBlacklist, "w")
  618.         bf:write("\n")
  619.         bf:close()
  620.     else
  621.         local f = fio.open(userBlacklist, "r")
  622.         for line in f:lines() do
  623.             if line ~= nil and line ~= "" and line ~= "\n" then
  624.                 ftable.insert(blacklistDatabase, line:gsub("^%s*(.-)%s*$", "%1"):lower())
  625.             end
  626.         end
  627.         f:close()
  628.     end
  629.  
  630.     -- User Whitelist
  631.     if not(ffs.exists(userWhitelist)) then
  632.         local f = fio.open(userWhitelist, "w")
  633.         f:write("\n")
  634.         f:close()
  635.     else
  636.         local switch = "url"
  637.         local f = fio.open(userWhitelist, "r")
  638.  
  639.         for l in f:lines() do
  640.             if l ~= nil and l ~= "" and l ~= "\n" then
  641.                 l = l:gsub("^%s*(.-)%s*$", "%1"):lower()
  642.                 local a, b = l:find("| |")
  643.                 local n = l:sub(1, a - 1)
  644.                 local id = l:sub(b + 1, -1)
  645.                 ftable.insert(whitelistDatabase, {n, id})
  646.             end
  647.         end
  648.  
  649.         f:close()
  650.     end
  651. end
  652.  
  653. local function verifyAgainstWhitelist(site, id)
  654.     if site:find("/") then
  655.         local startPoint = site:find("/")
  656.         site = site:sub(1, startPoint-1)
  657.     end
  658.     for i = 1, #whitelistDatabase do
  659.         if whitelistDatabase[i][1] == site then
  660.             if whitelistDatabase[i][2] == ftostring(id) then
  661.                 return true
  662.             else
  663.                 return false
  664.             end
  665.         end
  666.     end
  667.     return "not verified"
  668. end
  669.  
  670. local function verifyAgainstVerified(site, id)
  671.     for i = 1, #verifiedDatabase do
  672.         if verifiedDatabase[i][1] == site and verifiedDatabase[i][2] == ftostring(id) then
  673.             return true
  674.         end
  675.     end
  676.  
  677.     return false
  678. end
  679.  
  680. local function verifyAgainstBlacklist(id)
  681.     for i = 1, #blacklistDatabase do
  682.         if blacklistDatabase[i] == ftostring(id) then
  683.             return true
  684.         end
  685.     end
  686.     return false
  687. end
  688.  
  689. local function verifyAgainstAntivirus(checkData)
  690.     local a = checkData
  691.     a = a:gsub(" ", ""):gsub("\n", ""):gsub("\t", "")
  692.     for i = 1, #antivirusDefinitions do
  693.         local b = antivirusDefinitions[i]
  694.         if b ~= "" and b ~= "\n" and b ~= nil then
  695.             if fstring.find(a, b, 1, true) then
  696.                 return true
  697.             end
  698.         end
  699.     end
  700.  
  701.     return false
  702. end
  703.  
  704. local function downloadVerified(checkData)
  705.     for i = 1, #downloadDatabase do
  706.         if downloadDatabase[i] == checkData then
  707.             return true
  708.         end
  709.     end
  710.  
  711.     return false
  712. end
  713.  
  714. local function blacklistRedirectionBots()
  715.     local suspected = {}
  716.     local alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
  717.                       "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "."}
  718.     local name = ""
  719.     for i = 1, fmath.random(1,3) do
  720.         name = ""
  721.         for d = 1, fmath.random(6, 17) do
  722.             name = name .. alphabet[fmath.random(1, 27)]
  723.         end
  724.         rednet.broadcast(name)
  725.         sleep(timeout)
  726.     end
  727.  
  728.     for i = 1, 4 do
  729.         name = ""
  730.         for d = 1, fmath.random(6, 17) do
  731.             name = name .. alphabet[fmath.random(1, 27)]
  732.         end
  733.  
  734.         local finishCheck = false
  735.         frednet.broadcast(name)
  736.         clock = fos.clock()
  737.         for i = 1, 5 do
  738.             while fos.clock() - clock < timeout do
  739.                 local id = frednet.receive(timeout)
  740.                 if id ~= nil and verifyAgainstBlacklist(id) == false then
  741.                     name = ""
  742.                     for d = 1, fmath.random(6, 17) do
  743.                         name = name .. alphabet[fmath.random(1, 27)]
  744.                     end
  745.  
  746.                     local inSuspected = false
  747.                     for b = 1, #suspected do
  748.                         if suspected[b][1] == id then
  749.                             suspected[b][2] = suspected[b][2] + 1
  750.                             inSuspected = true
  751.                         end
  752.                     end
  753.  
  754.                     if not(inSuspected) then
  755.                         ftable.insert(suspected, {id, 1})
  756.                         break
  757.                     end
  758.                 elseif id == nil then finishCheck = true
  759.                     break
  760.                 end
  761.             end
  762.             if finishCheck then break end
  763.         end
  764.         if finishCheck then break end
  765.     end
  766.  
  767.     for i = 1, #suspected do
  768.         if suspected[i][2] > 2 then
  769.             local f = fio.open(userBlacklist, "a")
  770.             f:write(ftostring(suspected[i][1]) .. "\n")
  771.             f:close()
  772.             ftable.insert(blacklistDatabase, ftostring(suspected[i][1]))
  773.         end
  774.     end
  775. end
  776.  
  777. local function updateDatabases()
  778.     while not(exitApp) do
  779.         fos.pullEvent(websiteLoadEvent)
  780.         reloadDatabases()
  781.     end
  782. end
  783.  
  784.  
  785. --  -------- Error Websites
  786.  
  787. local function webpageCrash()
  788.     -- URL
  789.     local url = runningWebsite
  790.     if errorMessage ~= nil then
  791.         url = "crash"
  792.     end
  793.  
  794.     -- Draw
  795.     local title = ""
  796.     local w, h = fterm.getSize()
  797.     if errorMessage ~= nil then
  798.         title = "Crash"
  799.     else
  800.         title = ""
  801.     end
  802.  
  803.     if errorMessage ~= nil then
  804.         fterm.clear()
  805.     end
  806.     fterm.setCursorPos(2, 1)
  807.     fwrite("rdnt://" .. url)
  808.  
  809.     -- Title
  810.     if title ~= nil then
  811.         fterm.setCursorPos(w - fstring.len("  " .. title), 1)
  812.         fwrite("  " .. title)
  813.     end
  814.  
  815.     -- Line
  816.     if fterm.setTextColor then
  817.         fterm.setCursorPos(1,2)
  818.     else
  819.         fterm.setCursorPos(1,1)
  820.     end
  821.     fwrite(fstring.rep("-", w))
  822.  
  823.     -- Content
  824.     if errorMessage == nil then
  825.         os.queueEvent("key", 29)
  826.     else
  827.         fprint("\n\n")
  828.         centerPrint("Error")
  829.         fprint(" ")
  830.         centerPrint("Firefox Has Crashed!")
  831.         centerPrint("Error Message:")
  832.         fprint(" ")
  833.         fprint(" " .. errorMessage)
  834.         fprint(" ")
  835.         centerPrint("Please Report This Error To")
  836.         centerPrint("1lann or GravityScore")
  837.         fprint(" ")
  838.         centerPrint("You May Now Browse Normally...")
  839.         errorMessage = nil
  840.     end
  841. end
  842.  
  843. local function webpageOverspeed(overspeed)
  844.     -- Reset
  845.     overspeed = false
  846.     loadingRateClock = fos.clock()
  847.     websiteLoadingRate = 0
  848.     runningWebsite = "toofast"
  849.  
  850.     -- URL
  851.     local w, h = fterm.getSize()
  852.     local title = "Overspeed"
  853.     fterm.clear()
  854.     fterm.setCursorPos(2, 1)
  855.     fwrite("rdnt://toofast")
  856.  
  857.     -- Title
  858.     if title ~= nil then
  859.         fterm.setCursorPos(w - fstring.len("  " .. title), 1)
  860.         fwrite("  " .. title)
  861.     end
  862.  
  863.     -- Line
  864.     for i = 1, 5 do
  865.         if fterm.setTextColor then
  866.             fterm.setCursorPos(1,2)
  867.         else
  868.             fterm.setCursorPos(1,1)
  869.         end
  870.         fwrite(fstring.rep("-", w))
  871.         fprint("\n\n")
  872.         centerPrint("Warning!")
  873.         fprint(" ")
  874.         centerPrint("Website Browsing Speed Limit Reached!")
  875.         fprint(" ")
  876.         centerPrint("To prevent Rednet spamming and being throttled")
  877.         centerPrint("Firefox has stopped loading the page.")
  878.         fprint(" ")
  879.         if 6 - i == 1 then
  880.             centerPrint(" Please Wait " .. ftostring(6 - i) .. " Second...")
  881.         else
  882.             centerPrint("Please Wait " .. ftostring(6 - i) .. " Seconds...")
  883.         end
  884.         fsleep(1)
  885.     end
  886.  
  887.     if fterm.setTextColor then
  888.         fterm.setCursorPos(1,2)
  889.     else
  890.         fterm.setCursorPos(1,1)
  891.     end
  892.     fwrite(fstring.rep("-", w))
  893.     fprint("\n\n")
  894.     centerPrint("Warning!")
  895.     fprint(" ")
  896.     centerPrint("Website Browsing Speed Limit Reached!")
  897.     fprint(" ")
  898.     centerPrint("To prevent Rednet spamming and being throttled")
  899.     centerPrint("Firefox has stopped loading the page.")
  900.     fprint(" ")
  901.     centerPrint("You May Now Browse Normally...")
  902. end
  903.  
  904. local function checkForModem()
  905.     while not(exitApp) do
  906.         -- Check For Modem
  907.         local present = false
  908.         for _, v in pairs(rs.getSides()) do
  909.             if fperipheral.getType(v) == "modem" then
  910.                 frednet.open(v)
  911.                 present = true
  912.                 break
  913.             end
  914.         end
  915.  
  916.         if not(present) then
  917.             runningWebsite = "nomodem"
  918.             clearPage("nomodem")
  919.             fprint(" ")
  920.             centerPrint("No Wireless Modem!")
  921.             fprint("\n\n")
  922.             centerPrint("No Wireless Modem Has Been Detected")
  923.             centerPrint("On This Computer!")
  924.             fprint(" ")
  925.             centerPrint("Waiting For A Modem To Be Attached...")
  926.             fprint("\n\n")
  927.             centerPrint("[Exit Firefox]")
  928.             while not(exitApp) do
  929.                 local event, id = fos.pullEvent()
  930.                 if event == "key" and id == 28 then
  931.                     return true
  932.                 elseif event == "peripheral" then
  933.                     break
  934.                 end
  935.             end
  936.         else
  937.             return
  938.         end
  939.     end
  940. end
  941.  
  942.  
  943. --  -------- Built-In Websites
  944.  
  945. local function webpageHome(site)
  946.     -- Title
  947.     local w, h = fterm.getSize()
  948.     fprint("\n")
  949.     centerPrint("        _,-='\"-.__               /\\_/\\   ")
  950.     centerPrint("         -.}        =._,.-==-._.,  @ @._,")
  951.     centerPrint("            -.__  __,-.   )       _,.-'  ")
  952.     centerPrint("                 \"     G..m-\"^m m'       ")
  953.     fprint(" ")
  954.     leftWrite("  Welcome to Mozilla Firefox " .. firefoxVersion)
  955.  
  956.     -- Useful websites
  957.     fterm.setCursorPos(1, 12)
  958.     lWrite("      rdnt://history")
  959.     rWrite("History      \n")
  960.     lWrite("      rdnt://server")
  961.     rWrite("Server Management      \n")
  962.     lWrite("      rdnt://help")
  963.     rWrite("Help Page      \n")
  964.     lWrite("      rdnt://settings")
  965.     rWrite("Settings      \n")
  966.     lWrite("      rdnt://credits")
  967.     rWrite("Credits      \n")
  968.     lWrite("      rdnt://exit")
  969.     rWrite("Exit      \n")
  970.     fprint(" ")
  971.     cWrite("Control To Navigate The Web")
  972. end
  973.  
  974. local function webpageHistory(site)
  975.     -- Title
  976.     centerPrint("Firefox History")
  977.  
  978.     if #history ~= 0 then
  979.         -- Organise
  980.         local his = {"Clear History"}
  981.         for i = 1, #history do
  982.             ftable.insert(his, "rdnt://" .. history[i])
  983.         end
  984.  
  985.         -- Prompt
  986.         local web, ex = scrollingPrompt(his, 14, 4, 4)
  987.         if not(ex) then
  988.             if web == "Clear History" then
  989.                 -- Reset history
  990.                 history = {}
  991.                 searchBarHistory = {}
  992.                 local f = fio.open(historyLocation, "w")
  993.                 f:write(textutils.serialize(history))
  994.                 f:close()
  995.  
  996.                 -- Draw
  997.                 clearPage(site)
  998.                 centerPrint("Firefox History")
  999.                 fprint("\n")
  1000.                 centerPrint("History Cleared")
  1001.                 fsleep(0.9)
  1002.                 redirect("history")
  1003.             else
  1004.                 -- Redirect
  1005.                 redirect(web:gsub("rdnt://", ""))
  1006.             end
  1007.         end
  1008.     else
  1009.         -- No Items
  1010.         fprint("\n\n")
  1011.         centerPrint("No Items In History")
  1012.     end
  1013. end
  1014.  
  1015. local function webpageServerManagement(site)
  1016.     centerPrint("Firefox Server Management")
  1017.  
  1018.     local l = ffs.list(serverFolder)
  1019.     local s = {"New Server"}
  1020.     for i = 1, #l do
  1021.         if ffs.isDir(serverFolder .. "/" .. l[i]) then
  1022.             ftable.insert(s, l[i])
  1023.         end
  1024.     end
  1025.  
  1026.     local server, ex = scrollingPrompt(s, 14, 4, 4)
  1027.     if not(ex) then
  1028.         if server == "New Server" then
  1029.             -- Get URL
  1030.             clearPage(site)
  1031.             centerPrint("Firefox Server Management")
  1032.             fprint("\n\n")
  1033.             leftWrite("Server URL:\n")
  1034.             leftWrite("    rdnt://")
  1035.             local url = read():lower():gsub(" ", "")
  1036.             fprint("\n")
  1037.  
  1038.             if url ~= "" then
  1039.                 if url:find("/") then
  1040.                     leftWrite("Server URL Invalid\n")
  1041.                     leftWrite("Contains Illegal '/'\n")
  1042.                     fsleep(0.9)
  1043.                 elseif url:find("| |") then
  1044.                     leftWrite("Server URL Invalid\n")
  1045.                     leftWrite("Contains Illegal '| |'\n")
  1046.                     fsleep(0.9)
  1047.                 else
  1048.                     leftWrite("Creating Server: " .. url)
  1049.                     fsleep(0.4)
  1050.  
  1051.                     local serverLoc = serverFolder .. "/" .. url
  1052.                     ffs.makeDir(serverLoc)
  1053.                     local homeF = fio.open(serverLoc .. "/home", "w")
  1054.                     homeF:write("print(\" \")\ncenterPrint(\"Welcome To " .. url .. "\")")
  1055.                     homeF:close()
  1056.                 end
  1057.             else
  1058.                 leftWrite("Server URL Empty!")
  1059.                 leftWrite("Could Not Create Server")
  1060.                 fsleep(0.4)
  1061.             end
  1062.             redirect("server")
  1063.         else
  1064.             local redir = false
  1065.             while not(exitApp) do
  1066.                 clearPage(site)
  1067.                 local serverPath = serverFolder .. "/" .. server
  1068.                 server = server:gsub("^%s*(.-)%s*$", "%1"):lower()
  1069.                 centerPrint("Firefox Server Management")
  1070.                 fprint(" ")
  1071.                 leftWrite("Server: " .. server)
  1072.  
  1073.                 local opt = prompt({{"Start Server", 5, 8}, {"Run On Startup", 5, 10},
  1074.                                     {"Edit Pages", 5, 12}, {"Delete Server", 5, 14},
  1075.                                     {"Back", 5, 16}}, "vertical")
  1076.                 if opt == "Start Server" then
  1077.                     fshell.run(serverSoftwareLocation, server, serverPath)
  1078.                     checkForModem()
  1079.                     redir = true
  1080.  
  1081.                     break
  1082.                 elseif opt == "Run On Startup" then
  1083.                     -- Move to startup
  1084.                     ffs.delete("/old-startup")
  1085.                     if ffs.exists("/startup") then ffs.move("/startup", "/old-startup") end
  1086.                     local f = fio.open("/startup", "w")
  1087.                     f:write("shell.run(\"" .. serverSoftwareLocation .. "\", \"" .. server ..
  1088.                             "\", \"" .. serverPath .. "\")")
  1089.                     f:close()
  1090.                     -- Display
  1091.                     clearPage("server")
  1092.                     cPrint("Firefox Server Management")
  1093.                     fprint("\n\n")
  1094.                     cPrint("Server Will Run On Startup")
  1095.                     fsleep(0.9)
  1096.                 elseif opt == "Edit Pages" then
  1097.                     -- Variables
  1098.                     local oldLocation = fshell.dir()
  1099.                     local comHis = {}
  1100.  
  1101.                     -- Title
  1102.                     fterm.clear()
  1103.                     fterm.setCursorPos(1,1)
  1104.                     fshell.setDir(serverFolder .. "/" .. server)
  1105.                     fprint("Server File Editing")
  1106.                     fprint("Type 'exit' To Return To Server Management")
  1107.                     fprint(" ")
  1108.                     fprint("Server files:")
  1109.                     fshell.run("/rom/programs/list")
  1110.                     fprint(" ")
  1111.  
  1112.                     -- Shell
  1113.                     while true do
  1114.                         fshell.setDir(serverFolder .. "/" .. server)
  1115.                         fwrite("> ")
  1116.  
  1117.                         local line = read(nil, comHis)
  1118.                         ftable.insert(comHis, line)
  1119.  
  1120.                         local words = {}
  1121.                         for match in fstring.gmatch(line, "[^ \t]+") do
  1122.                             ftable.insert(words, match)
  1123.                         end
  1124.  
  1125.                         local command = words[1]
  1126.                         if command == "exit" then
  1127.                             break
  1128.                         elseif command then
  1129.                             fshell.run(command, unpack(words, 2))
  1130.                         end
  1131.                     end
  1132.  
  1133.                     -- Reset
  1134.                     fshell.setDir(oldLocation)
  1135.                     fterm.clear()
  1136.                 elseif opt == "Delete Server" then
  1137.                     clearPage(site)
  1138.                     centerPrint("Firefox Server Management")
  1139.                     local w, h = fterm.getSize()
  1140.                     local opt = prompt({{"Delete Server",
  1141.                                          fmath.floor(w/4 - fstring.len("Delete Server")/2), 9},
  1142.                                         {"Cancel", fmath.ceil(w/4 - fstring.len("Cancel")/2 + w/2),
  1143.                                         9}}, "horizontal")
  1144.                     if opt == "Delete Server" then
  1145.                         clearPage(site)
  1146.                         centerPrint("Firefox Server Management")
  1147.                         fprint("\n\n")
  1148.                         centerPrint("Deleted Server")
  1149.                         fsleep(0.9)
  1150.                         ffs.delete(serverPath)
  1151.                     elseif opt == "Cancel" then
  1152.                         clearPage(site)
  1153.                         centerPrint("Firefox Server Management")
  1154.                         fprint("\n\n")
  1155.                         centerPrint("Cancelled Delete Operation")
  1156.                         fsleep(0.9)
  1157.                     end
  1158.  
  1159.                     redir = true
  1160.                     break
  1161.                 elseif opt == "Back" then
  1162.                     redir = true
  1163.                     break
  1164.                 elseif opt == nil then
  1165.                     return
  1166.                 end
  1167.             end
  1168.  
  1169.             if redir then redirect("server") end
  1170.         end
  1171.     end
  1172. end
  1173.  
  1174. local function webpageSettings(site)
  1175.     local selected = 1
  1176.     while not(exitApp) do
  1177.         -- Clear
  1178.         clearPage(site)
  1179.         centerPrint("Firefox Settings")
  1180.         fprint(" ")
  1181.         leftWrite("Designed For: " .. serverList[serverID])
  1182.  
  1183.         -- Load different options
  1184.         local t1 = "Auto-Update - Off"
  1185.         if autoupdate == "true" then t1 = "Auto-Update - On" end
  1186.         local t2 = "Record History - Off"
  1187.         if incognito == "true" then t2 = "Record History - On" end
  1188.         local x = homepage
  1189.         if x:len() > 22 then x = x:sub(1, 20) .. "..." end
  1190.         local t3 = "Homepage - rdnt://" .. x
  1191.  
  1192.         -- Prompt the user
  1193.         local opt = prompt({{t1, 5, 8}, {t2, 5, 10}, {t3, 5, 12}, {"Reset Firefox", -1, 17}},
  1194.                            "vertical", selected)
  1195.  
  1196.         -- Respond depending on option
  1197.         if opt == nil then
  1198.             break
  1199.         elseif opt == t1 then
  1200.             if autoupdate == "true" then
  1201.                 autoupdate = "false"
  1202.             else
  1203.                 autoupdate = "true"
  1204.             end
  1205.             selected = 1
  1206.         elseif opt == t2 then
  1207.             if incognito == "true" then
  1208.                 incognito = "false"
  1209.             else
  1210.                 incognito = "true"
  1211.             end
  1212.             selected = 2
  1213.         elseif opt == t3 then
  1214.             fterm.setCursorPos(8, 13)
  1215.             fwrite("rdnt://")
  1216.             homepage = read():gsub("^%s*(.-)%s*$", "%1"):lower()
  1217.             selected = 3
  1218.         elseif opt == "Reset Firefox" then
  1219.             -- Clear
  1220.             clearPage(site)
  1221.             fprint(" ")
  1222.             centerPrint("Firefox Settings")
  1223.  
  1224.             -- Prompt
  1225.             local w, h = fterm.getSize()
  1226.             local a = prompt({{"Reset", fmath.floor(w/4 - fstring.len("Reset")/2), 9},
  1227.                               {"Cancel", fmath.ceil(w/4 - fstring.len("Cancel")/2 + w/2), 9}},
  1228.                                "horizontal")
  1229.  
  1230.             if a == "Reset" then
  1231.                 -- Delete root folder
  1232.                 ffs.delete(rootFolder)
  1233.  
  1234.                 -- Draw
  1235.                 clearPage(site)
  1236.                 fprint(" ")
  1237.                 centerPrint("Firefox Settings")
  1238.                 fprint("\n\n")
  1239.                 centerPrint("Firefox Has Been Reset")
  1240.                 fprint("\n\n\n")
  1241.                 centerPrint("[Exit Firefox]")
  1242.                 while not(exitApp) do
  1243.                     local _, key = fos.pullEvent("key")
  1244.                     if key == 28 then
  1245.                         break
  1246.                     end
  1247.                 end
  1248.                 redirect("exit")
  1249.             elseif a == "Cancel" then
  1250.                 -- Draw
  1251.                 clearPage(site)
  1252.                 fprint(" ")
  1253.                 centerPrint("Firefox Settings")
  1254.                 fprint("\n\n")
  1255.                 centerPrint("Reset Cancelled")
  1256.                 fsleep(0.9)
  1257.             end
  1258.             selected = 1
  1259.         end
  1260.  
  1261.         -- Save settings
  1262.         local f = fio.open(settingsLocation, "w")
  1263.         f:write(textutils.serialize({auto = autoupdate, incog = incognito, home = homepage}))
  1264.         f:close()
  1265.     end
  1266. end
  1267.  
  1268. local function webpageHelp(site)
  1269.     -- Draw Dev page
  1270.     centerPrint("Firefox Help")
  1271.     fprint("\n")
  1272.     leftWrite("View a Help Topic:")
  1273.     local b = {{"Getting Started", 10, 8}, {"Making A Website", 10, 10}, {"API Documentation", 10, 12}}
  1274.     for _, v in pairs(b) do
  1275.         term.setCursorPos(v[2] - 3, v[3])
  1276.         write("-")
  1277.     end
  1278.     local topic = prompt(b, "vertical")
  1279.     if topic == nil then return end
  1280.  
  1281.     local pages = {}
  1282.     if topic == "Getting Started" then
  1283.         -- Pages
  1284.         pages[1] = function()
  1285.             centerPrint("Getting Started - 1")
  1286.             fprint(" ")
  1287.             centerPrint("Firefox is an application which allows you to")
  1288.             centerPrint("visit websites made by other people in Minecraft!")
  1289.             fprint(" ")
  1290.             centerPrint("You can also set up your own website for others")
  1291.             centerPrint("visit in-game.")
  1292.             fprint(" ")
  1293.             centerPrint("To access the URL bar, just press Control")
  1294.         end
  1295.  
  1296.         pages[2] = function()
  1297.             centerPrint("Getting Started - 2")
  1298.             fprint(" ")
  1299.             centerPrint("To search all the websites online, just type")
  1300.             centerPrint("nothing into the URL bar, and press enter")
  1301.             fprint(" ")
  1302.             centerPrint("To search for a specific keyword, type it into")
  1303.             centerPrint("the URL bar and press enter")
  1304.             fprint(" ")
  1305.             centerPrint("To visit a specific website, type its URL into")
  1306.             centerPrint("the URL bar, or select it from the list of search")
  1307.             centerPrint("results after searching.")
  1308.         end
  1309.  
  1310.         pages[3] = function()
  1311.             centerPrint("Getting Started - 3")
  1312.             fprint(" ")
  1313.             centerPrint("Firefox also offers a set of built in websites.")
  1314.             fprint(" ")
  1315.             centerPrint("These include:")
  1316.             leftPrint("   - rdnt://firefox")
  1317.             leftPrint("   - rdnt://history")
  1318.             leftPrint("   - rdnt://server")
  1319.             leftPrint("   - rdnt://help")
  1320.             leftPrint("   - rdnt://settings")
  1321.             leftPrint("   - rdnt://credits")
  1322.             leftPrint("   - rdnt://getinfo")
  1323.             leftPrint("   - rdnt://exit")
  1324.         end
  1325.  
  1326.         pages[4] = function()
  1327.             centerPrint("Getting Started - 4")
  1328.             fprint(" ")
  1329.             centerPrint("On the rdnt://settings page, you are able to")
  1330.             centerPrint("change whether Firefox automatically updates")
  1331.             centerPrint("itself, whether it records history, and the")
  1332.             centerPrint("default homepage.")
  1333.             fprint(" ")
  1334.             centerPrint("You can also completely reset Firefox to its")
  1335.             centerPrint("default settings. You will lose all your")
  1336.             centerPrint("servers, history items, and settings.")
  1337.         end
  1338.     elseif topic == "Making A Website" then
  1339.         -- Pages
  1340.         pages[1] = function()
  1341.             centerPrint("Making A Website - 1")
  1342.             fprint(" ")
  1343.             centerPrint("Websites are sites that players may create")
  1344.             centerPrint("and are accessable by other Firefox Browers.")
  1345.             fprint(" ")
  1346.             centerPrint("A server is software which allows you to host")
  1347.             centerPrint("a website, and make it viewable to other players.")
  1348.             fprint(" ")
  1349.             centerPrint("They can be created at rdnt://server.")
  1350.         end
  1351.  
  1352.         pages[2] = function()
  1353.             centerPrint("Making A Website - 2")
  1354.             fprint(" ")
  1355.             centerPrint("In rdnt://server, there is a list of servers")
  1356.             centerPrint("on this computer, as well as the option to")
  1357.             centerPrint("create a new one.")
  1358.             fprint(" ")
  1359.             centerPrint("Selecting a servers from the list displays")
  1360.             centerPrint("options for editing parts that server.")
  1361.             fprint(" ")
  1362.             centerPrint("You can edit the pages of a server in a")
  1363.             centerPrint("shell-style console when you select 'Edit Pages'")
  1364.         end
  1365.     elseif topic == "API Documentation" then
  1366.         pages[1] = function()
  1367.             centerPrint("API Documentation - 1")
  1368.             fprint(" ")
  1369.             centerPrint("Firefox API is a set of functions that")
  1370.             centerPrint("can be used by website developers.")
  1371.             fprint(" ")
  1372.             centerPrint("They are documented on the next few pages...")
  1373.         end
  1374.  
  1375.         pages[2] = function()
  1376.             centerPrint("API Documentation - 2")
  1377.             fprint(" ")
  1378.             leftPrint("centerPrint(text)  or   cPrint(text)")
  1379.             leftPrint("  - Prints text to the center of the page")
  1380.             leftPrint("  - Returns nothing")
  1381.             fprint(" ")
  1382.             leftPrint("leftPrint(text)    or   lPrint(text)")
  1383.             leftPrint("  - Prints text to the left of the page")
  1384.             leftPrint("  - Returns nothing")
  1385.             fprint(" ")
  1386.             leftPrint("rightPrint(text)   or   rPrint(text)")
  1387.             leftPrint("  - Prints text in the right of the page")
  1388.             leftPrint("  - Returns nothing")
  1389.         end
  1390.  
  1391.         pages[3] = function()
  1392.             centerPrint("API Documentation - 3")
  1393.             fprint(" ")
  1394.             leftPrint("centerWrite(text)  or   cWrite(text)")
  1395.             leftPrint("  - Writes text to the center of the page")
  1396.             leftPrint("  - Returns nothing")
  1397.             fprint(" ")
  1398.             leftPrint("leftWrite(text)    or   lWrite(text)")
  1399.             leftPrint("  - Writes text to the left of the page")
  1400.             leftPrint("  - Returns nothing")
  1401.             fprint(" ")
  1402.             leftPrint("rightWrite(text)   or   rWrite(text)")
  1403.             leftPrint("  - Writes text in the right of the page")
  1404.             leftPrint("  - Returns nothing")
  1405.         end
  1406.  
  1407.         pages[4] = function()
  1408.             centerPrint("API Documentation - 4")
  1409.             fprint(" ")
  1410.             leftPrint("prompt(options, direction)")
  1411.             leftPrint("  - Prompts the user to select an option")
  1412.             leftPrint("  - 'options' is an array, formatted like:")
  1413.             leftPrint("    { { [option name], [x], [y] }, ... }")
  1414.             leftPrint("  - Example:")
  1415.             leftPrint("    option = prompt({{\"Option 1\", 4, 5},")
  1416.             leftPrint("         {\"Option 2\", 5, 7}}, \"vertical\")")
  1417.             fprint(" ")
  1418.             leftPrint("pastebinDownload(pastebinCode)")
  1419.             leftPrint("  - Downloads code from pastebin into a user")
  1420.             leftPrint("    chosen path")
  1421.             leftPrint("  - Returns the name of the path of the user")
  1422.             leftPrint("    chose, or nil if the download failed")
  1423.         end
  1424.  
  1425.         pages[5] = function()
  1426.             centerPrint("API Documentation - 5")
  1427.             fprint(" ")
  1428.             leftPrint("urlDownload(url)")
  1429.             leftPrint("  - Downloads the contents of a url into a user")
  1430.             leftPrint("    chosen path")
  1431.             leftPrint("  - Returns the path of the file the user")
  1432.             leftPrint("    chose, or nil if the download failed")
  1433.         end
  1434.     end
  1435.  
  1436.     local curPage = 1
  1437.     local a = 1
  1438.     clearPage(site)
  1439.     pages[curPage]()
  1440.     while not(exitApp) do
  1441.         local w, h = fterm.getSize()
  1442.         local l = {{"Previous", 3, 18}, {"Back", -1, 18}, {"Next", w - 7, 18}}
  1443.         if curPage == 1 then
  1444.             l = {{"Back", -1, 18}, {"Next", w - 7, 18}}
  1445.         elseif curPage == #pages then
  1446.             l = {{"Previous", 3, 18}, {"Back", -1, 18}}
  1447.         end
  1448.         local opt = prompt(l, "horizontal", a)
  1449.         if opt ~= nil then clearPage(site) end
  1450.  
  1451.         if opt == "Previous" then
  1452.             curPage = curPage - 1
  1453.             if curPage ~= 1 then a = 1
  1454.             else a = 1 end
  1455.         elseif opt == "Back" then
  1456.             break
  1457.         elseif opt == "Next" then
  1458.             curPage = curPage + 1
  1459.             if curPage ~= #pages then a = 3
  1460.             else a = 2 end
  1461.         elseif opt == nil then
  1462.             return
  1463.         end
  1464.  
  1465.         pages[curPage]()
  1466.     end
  1467.  
  1468.     redirect("help")
  1469. end
  1470.  
  1471. local function webpageCredits(site)
  1472.     -- Draw Credits
  1473.     fprint(" ")
  1474.     centerPrint("Firefox Credits")
  1475.     fprint("\n")
  1476.     centerPrint("Coded By:")
  1477.     centerPrint("1lann and GravityScore")
  1478.     fprint("\n")
  1479.     centerPrint("Originally Based Off:")
  1480.     centerPrint("Rednet Explorer 2.4.1")
  1481.     fprint(" ")
  1482.     centerPrint("Rednet Explorer Made By:")
  1483.     centerPrint("xXm0dzXx/CCFan11")
  1484. end
  1485.  
  1486. local function webpageGetInfo(site)
  1487.     -- Title
  1488.     clearPage(site)
  1489.     fprint(" ")
  1490.     centerPrint("Website Information")
  1491.     fprint("\n\n")
  1492.     leftPrint("Enter URL: ")
  1493.     leftWrite("    rdnt://")
  1494.     local url = read():gsub("^%s*(.-)%s*$", "%1"):lower()
  1495.  
  1496.     -- Get website
  1497.     local id, content, valid = nil
  1498.     local av, bl, wl, vf = nil, nil, nil, nil
  1499.     local clock = fos.clock()
  1500.     frednet.broadcast(url)
  1501.     while fos.clock() - clock < timeout do
  1502.         -- Get
  1503.         id, content = frednet.receive(timeout)
  1504.  
  1505.         if id ~= nil then
  1506.             -- Validity check
  1507.             av = verifyAgainstAntivirus(content)
  1508.             bl = verifyAgainstBlacklist(id)
  1509.             wl = verifyAgainstWhitelist(url, id)
  1510.             vf = verifyAgainstVerified(url, id)
  1511.             valid = ""
  1512.             if bl or not(wl) then
  1513.                 valid = "blacklist"
  1514.             elseif av and not(vf) then
  1515.                 valid = "antivirus"
  1516.                 break
  1517.             else
  1518.                 valid = "true"
  1519.                 break
  1520.             end
  1521.         end
  1522.     end
  1523.  
  1524.     if valid ~= nil and id ~= nil and content ~= nil then
  1525.         -- Print information
  1526.         clearPage(site)
  1527.         fprint(" ")
  1528.         centerPrint("Website Information")
  1529.         fprint("\n")
  1530.         leftWrite("Site: " .. url .. "\n")
  1531.         fprint(" ")
  1532.         leftWrite("ID: " .. id .. "\n")
  1533.         if bl then
  1534.             leftWrite("Site Is Filtered/Ignored\n")
  1535.         end if type(wl) ~= "string" and wl then
  1536.             leftWrite("Site Is Whitelisted\n")
  1537.         end
  1538.         fprint(" ")
  1539.         if av then
  1540.             leftWrite("Site Triggered Antivirus\n")
  1541.         end if vf then
  1542.             leftWrite("Site Is Verified\n")
  1543.         end
  1544.     else
  1545.         -- Not Found
  1546.         clearPage(site)
  1547.         fprint(" ")
  1548.         centerPrint("Website Information")
  1549.         fprint("\n")
  1550.         centerPrint("Page Not Found")
  1551.         fsleep(0.9)
  1552.         redirect("getinfo")
  1553.     end
  1554. end
  1555.  
  1556. local function loadWebpage(site)
  1557.     -- Functions
  1558.     local function runSite(cacheLoc)
  1559.         clearPage(site)
  1560.  
  1561.         function term.getSize()
  1562.             return 51, 17
  1563.         end
  1564.  
  1565.         function term.setCursorPos(x, y)
  1566.             return fterm.setCursorPos(x, y + 2)
  1567.         end
  1568.  
  1569.         function term.clear()
  1570.             return clearArea()
  1571.         end
  1572.  
  1573.         function term.getCursorPos()
  1574.             local x, y = fterm.getCursorPos()
  1575.             return x, y - 2
  1576.         end
  1577.  
  1578.         local function ctrlControl()
  1579.             while not(exitApp) do
  1580.                 local event, key = os.pullEvent("key")
  1581.                 if key == 29 and not(lockCtrl) then
  1582.                     exitWebsite = true
  1583.                 end
  1584.             end
  1585.         end
  1586.  
  1587.         local _, websiteError = fpcall(fparallel.waitForAll(ctrlControl, function()
  1588.             fshell.run(cacheLoc)
  1589.         end))
  1590.         if websiteError then fprint(websiteError) end
  1591.  
  1592.         exitWebsite = false
  1593.         term = copyTable(fterm)
  1594.         shell = copyTable(fshell)
  1595.         string = copyTable(fstring)
  1596.         lockCtrl = false
  1597.     end
  1598.  
  1599.     -- Draw
  1600.     term = copyTable(fterm)
  1601.     shell = copyTable(fshell)
  1602.     clearPage(site)
  1603.     fprint("\n")
  1604.     centerPrint("Connecting...")
  1605.  
  1606.     -- Reset
  1607.     websiteLoadingRate = websiteLoadingRate + 1
  1608.     restoreFunctions()
  1609.  
  1610.     -- Redirection Bots
  1611.     blacklistRedirectionBots()
  1612.  
  1613.     -- Get website
  1614.     local id, content, valid = nil
  1615.     local clock = fos.clock()
  1616.     frednet.broadcast(site)
  1617.     while fos.clock() - clock < timeout do
  1618.         -- Get
  1619.         id, content = frednet.receive(timeout)
  1620.         if id ~= nil then
  1621.             -- Validity check
  1622.             local av = verifyAgainstAntivirus(content)
  1623.             local bl = verifyAgainstBlacklist(id)
  1624.             local wl = verifyAgainstWhitelist(site, id)
  1625.             local vf = verifyAgainstVerified(site, id)
  1626.             valid = nil
  1627.             if bl or not(wl) or site == "" or site == "." or site == ".." then
  1628.                 -- Ignore
  1629.             elseif av and not(vf) then
  1630.                 valid = "antivirus"
  1631.                 break
  1632.             else
  1633.                 valid = "true"
  1634.                 break
  1635.             end
  1636.         end
  1637.     end
  1638.  
  1639.     local cacheLoc = cacheFolder .. "/" .. site:gsub("/", "$slazh$")
  1640.     if valid then
  1641.         -- Run page
  1642.         if valid == "antivirus" then
  1643.             clearPage(site)
  1644.             fprint("\n")
  1645.             centerPrint("    ___     __             __   __")
  1646.             centerPrint("   /   |   / /___   _____ / /_ / /")
  1647.             centerPrint("  / /| |  / // _ \\ / ___// __// / ")
  1648.             centerPrint(" / ___ | / //  __// /   / /_ /_/  ")
  1649.             centerPrint("/_/  |_|/_/ \\___//_/    \\__/(_)   ")
  1650.             fprint("\n")
  1651.             centerPrint("Warning!")
  1652.             fprint(" ")
  1653.             centerPrint("This Website Has Been Detected")
  1654.             centerPrint("As Malicious!")
  1655.  
  1656.             local w, h = fterm.getSize()
  1657.             local opt = prompt({{"Cancel", fmath.floor(w/4 - fstring.len("Cancel")/2), 17},
  1658.                                 {"Load Page", fmath.ceil(w/4 - fstring.len("Load Page")/2 + w/2),
  1659.                                  17}}, "horizontal")
  1660.             if opt == "Cancel" then
  1661.                 ffs.delete(cacheLoc)
  1662.                 clearPage(site)
  1663.                 fprint("\n")
  1664.                 centerPrint("    ______                          __")
  1665.                 centerPrint("   / ____/_____ _____ ____   _____ / /")
  1666.                 centerPrint("  / __/  / ___// ___// __ \\ / ___// / ")
  1667.                 centerPrint(" / /___ / /   / /   / /_/ // /   /_/  ")
  1668.                 centerPrint("/_____//_/   /_/    \\____//_/   (_)   ")
  1669.                 fprint("\n")
  1670.                 centerPrint("Could Not Connect To Website!")
  1671.                 fprint(" ")
  1672.                 centerPrint("Antivirus Cancelled Loading")
  1673.             elseif opt == "Load Page" then
  1674.                 valid = "true"
  1675.             end
  1676.         end
  1677.  
  1678.         if valid == "true" and site ~= "" then
  1679.             local f = io.open(cacheLoc, "w")
  1680.             f:write(content)
  1681.             f:close()
  1682.             runSite(cacheLoc)
  1683.         end
  1684.     else
  1685.         if ffs.exists(cacheLoc) and site ~= "" and site ~= ".." and site ~= "." then
  1686.             clearPage(site)
  1687.             fprint("\n")
  1688.             centerPrint("   ______                        ")
  1689.             centerPrint("  / ____/____ _ _____ __  __ ___ ")
  1690.             centerPrint(" / /    / __ '// ___// /_/ // _ \\")
  1691.             centerPrint("/ /___ / /_/ // /__ / __  //  __/")
  1692.             centerPrint("\\____/ \\__,_/ \\___//_/ /_/ \\___/ ")
  1693.             fprint("\n")
  1694.             centerPrint("Could Not Connect To Website!")
  1695.             fprint(" ")
  1696.             centerPrint("A Cache Version Was Found")
  1697.             local w, h = fterm.getSize()
  1698.             local opt = prompt({{"Load Cache", fmath.floor(w/4 - fstring.len("Load Cache")/2), 17},
  1699.                 {"Delete Cache", 20, 17},
  1700.                 {"Cancel", fmath.ceil(w/4 - fstring.len("Cancel")/2 + w/2), 17}},
  1701.                 "horizontal")
  1702.  
  1703.             if opt == "Load Cache" then
  1704.                 runSite(cacheLoc)
  1705.             elseif opt == "Delete Cache" then
  1706.                 ffs.delete(cacheLoc)
  1707.                 clearPage(site)
  1708.                 fprint("\n")
  1709.                 centerPrint("   ______                        ")
  1710.                 centerPrint("  / ____/____ _ _____ __  __ ___ ")
  1711.                 centerPrint(" / /    / __ '// ___// /_/ // _ \\")
  1712.                 centerPrint("/ /___ / /_/ // /__ / __  //  __/")
  1713.                 centerPrint("\\____/ \\__,_/ \\___//_/ /_/ \\___/ ")
  1714.                 fprint("\n")
  1715.                 centerPrint("Deleted Cached Page!")
  1716.                 fsleep(1.8)
  1717.  
  1718.                 clearPage(site)
  1719.                 fprint("\n")
  1720.                 centerPrint("    ______                          __")
  1721.                 centerPrint("   / ____/_____ _____ ____   _____ / /")
  1722.                 centerPrint("  / __/  / ___// ___// __ \\ / ___// / ")
  1723.                 centerPrint(" / /___ / /   / /   / /_/ // /   /_/  ")
  1724.                 centerPrint("/_____//_/   /_/    \\____//_/   (_)   ")
  1725.                 fprint("\n")
  1726.                 centerPrint("Could Not Connect To Website!")
  1727.                 fprint(" ")
  1728.                 centerPrint("The Address Could Not Be Found")
  1729.             elseif opt == "Cancel" then
  1730.                 clearPage(site)
  1731.                 fprint("\n")
  1732.                 centerPrint("    ______                          __")
  1733.                 centerPrint("   / ____/_____ _____ ____   _____ / /")
  1734.                 centerPrint("  / __/  / ___// ___// __ \\ / ___// / ")
  1735.                 centerPrint(" / /___ / /   / /   / /_/ // /   /_/  ")
  1736.                 centerPrint("/_____//_/   /_/    \\____//_/   (_)   ")
  1737.                 fprint("\n")
  1738.                 centerPrint("Could Not Connect To Website!")
  1739.                 fprint(" ")
  1740.                 centerPrint("Cached Version Was Not Loaded")
  1741.             end
  1742.         else
  1743.             -- Get search results
  1744.             local input = site:gsub("^%s*(.-)%s*$", "%1"):lower()
  1745.             local results = {}
  1746.             local resultIDs = {}
  1747.             frednet.broadcast("rednet.api.ping.searchengine")
  1748.             local startClock = fos.clock()
  1749.             while fos.clock() - startClock < 1 do
  1750.                 local id, i = nil, nil
  1751.                 local id, i = frednet.receive(timeout)
  1752.                 if id then
  1753.                     if not(i:find(" ")) and i:len() < 40 and not(verifyAgainstBlacklist(id)) then
  1754.                         if not(resultIDs[ftostring(id)]) then
  1755.                             resultIDs[ftostring(id)] = 1
  1756.                         else
  1757.                             resultIDs[ftostring(id)] = resultIDs[ftostring(id)]+1
  1758.                         end
  1759.                         local x = false
  1760.                         for y = 1, #results do
  1761.                             if results[y]:lower() == i:lower() then
  1762.                                 x = true
  1763.                             end
  1764.                         end
  1765.                         if not(x) then
  1766.                             if resultIDs[ftostring(id)] <= 5 then
  1767.                                 if input == "" then
  1768.                                     ftable.insert(results, i)
  1769.                                 elseif fstring.find(i, input) and i ~= input then
  1770.                                     ftable.insert(results, i)
  1771.                                 end
  1772.                             else
  1773.                                 ftable.insert(blacklistDatabase, ftostring(id))
  1774.                             end
  1775.                         end
  1776.                     end
  1777.                 else
  1778.                     break
  1779.                 end
  1780.             end
  1781.  
  1782.             -- Display
  1783.             if #results ~= 0 then
  1784.                 clearPage(site)
  1785.                 centerPrint("Search Results")
  1786.                 local res = {}
  1787.                 for i = 1, #results do
  1788.                     ftable.insert(res, "rdnt://" .. results[i]:gsub("^%s*(.-)%s*$", "%1"):lower())
  1789.                 end
  1790.  
  1791.                 ftable.sort(res)
  1792.                 local s, ex = scrollingPrompt(res, 14, 4, 4)
  1793.                 if not(ex) then
  1794.                     redirect(s:gsub("rdnt://", ""))
  1795.                 end
  1796.             elseif site == "" then
  1797.                 clearPage(site)
  1798.                 centerPrint("Search Results")
  1799.                 fprint("\n\n")
  1800.                 centerPrint("No Websites Online")
  1801.             else
  1802.                 clearPage(site)
  1803.                 fprint("\n")
  1804.                 centerPrint("    ______                          __")
  1805.                 centerPrint("   / ____/_____ _____ ____   _____ / /")
  1806.                 centerPrint("  / __/  / ___// ___// __ \\ / ___// / ")
  1807.                 centerPrint(" / /___ / /   / /   / /_/ // /   /_/  ")
  1808.                 centerPrint("/_____//_/   /_/    \\____//_/   (_)   ")
  1809.                 fprint("\n")
  1810.                 centerPrint("Could Not Connect To Website!")
  1811.                 fprint(" ")
  1812.                 centerPrint("The Address Could Not Be Found")
  1813.                 centerPrint("Or The Website Was Blocked")
  1814.             end
  1815.         end
  1816.     end
  1817.     string = copyTable(fstring)
  1818.  
  1819.     -- Render bar
  1820.     local w, h = fterm.getSize()
  1821.     local title = titleForPage(runningWebsite)
  1822.     fterm.setCursorPos(2, 1)
  1823.     fterm.clearLine()
  1824.     fwrite("rdnt://" .. runningWebsite)
  1825.     if title ~= nil then
  1826.         fterm.setCursorPos(w - fstring.len("  " .. title), 1)
  1827.         fwrite("  " .. title)
  1828.     end
  1829.  
  1830.     -- Line
  1831.     fterm.setCursorPos(1, 2)
  1832.     fterm.clearLine()
  1833.     if fterm.setTextColor then
  1834.         fterm.setCursorPos(1,2)
  1835.     else
  1836.         fterm.setCursorPos(1,1)
  1837.     end
  1838.     fwrite(fstring.rep("-", w))
  1839.     fprint(" ")
  1840. end
  1841.  
  1842. --  -------- Download API
  1843.  
  1844. local function download(url)
  1845.     clearPage(runningWebsite)
  1846.     fprint("\n")
  1847.     centerPrint("Processing Download Request...")
  1848.  
  1849.     local fileData = nil
  1850.     local exitDownload = false
  1851.     local response = fhttp.get(url)
  1852.     if response then
  1853.         fileData = response.readAll()
  1854.         response.close()
  1855.     else
  1856.         clearPage(runningWebsite)
  1857.         fprint("\n\n")
  1858.         centerPrint("Download Request Failed!")
  1859.         fprint(" ")
  1860.         centerPrint("Please Report This To The Website Owner!")
  1861.         prompt({{"Continue To Website", -1, 11}}, "vertical")
  1862.         clearPage(runningWebsite)
  1863.         exitDownload = true
  1864.  
  1865.         return nil
  1866.     end
  1867.  
  1868.     if not(exitDownload) then
  1869.         clearPage(runningWebsite)
  1870.         fprint(" ")
  1871.         centerPrint("The Website:")
  1872.         centerPrint(runningWebsite)
  1873.         fprint(" ")
  1874.         centerPrint("Is Attempting To Download A File To")
  1875.         centerPrint("Your Computer.")
  1876.         fprint(" ")
  1877.  
  1878.         local w, h = fterm.getSize()
  1879.         local a = {{"Download", fmath.floor(w/4 - fstring.len("Download")/2), 15},
  1880.                    {"Cancel", fmath.ceil(w/4 - fstring.len("Cancel")/2 + w/2), 15}}
  1881.  
  1882.         if downloadVerified(code) then
  1883.             centerPrint("This Download Has Been Deemed Safe By Mozilla")
  1884.         else
  1885.             centerPrint("Warning - This Download Has Not Been Deemed Safe!")
  1886.             centerPrint("Download With Caution!")
  1887.             a = {{"Cancel", fmath.floor(w/4 - fstring.len("Cancel")/2), 15},
  1888.                  {"Download", fmath.ceil(w/4 - fstring.len("Download")/2 + w/2), 15}}
  1889.         end
  1890.  
  1891.         local opt = prompt(a, "horizontal")
  1892.         if opt == "Download" then
  1893.             local randomCheck = ftostring(fmath.random(1000,9999))
  1894.             fterm.setCursorPos(2, 13)
  1895.             centerPrint("This is for security purposes: " .. randomCheck)
  1896.             fterm.setCursorPos(2, 15)
  1897.             fterm.clearLine()
  1898.             fwrite("Enter the numbers above: ")
  1899.             local numberCheck = read()
  1900.             if numberCheck == randomCheck then
  1901.                 fterm.setCursorPos(2, 13)
  1902.                 term.clearLine()
  1903.                 fterm.setCursorPos(2, 15)
  1904.                 fterm.clearLine()
  1905.                 fwrite("Save As: /")
  1906.                 local b = "/" .. read()
  1907.  
  1908.                 local dlf = fio.open(b, "w")
  1909.                 dlf:write(fileData)
  1910.                 dlf:close()
  1911.  
  1912.                 clearPage(runningWebsite)
  1913.                 fprint("\n")
  1914.                 centerPrint("Download Successful!")
  1915.                 prompt({{"Continue To Website", -1, 11}}, "vertical")
  1916.                 clearPage(runningWebsite)
  1917.  
  1918.                 return b
  1919.             else
  1920.                 clearPage(runningWebsite)
  1921.                 fprint("\n")
  1922.                 centerPrint("Number entered is incorrect!")
  1923.                 centerPrint("Download Cancelled!")
  1924.                 prompt({{"Continue To Website", -1, 11}}, "vertical")
  1925.                 clearPage(runningWebsite)
  1926.                 return nil
  1927.             end
  1928.         elseif opt == "Cancel" then
  1929.             clearPage(runningWebsite)
  1930.             fprint("\n")
  1931.             centerPrint("Download Cancelled!")
  1932.             prompt({{"Continue To Website", -1, 11}}, "vertical")
  1933.             clearPage(runningWebsite)
  1934.  
  1935.             return nil
  1936.         end
  1937.     end
  1938. end
  1939.  
  1940. function pastebinDownload(code)
  1941.     download("http://pastebin.com/raw.php?i=" .. textutils.urlEncode(code))
  1942. end
  1943.  
  1944. function urlDownload(url)
  1945.     download(url)
  1946. end
  1947.  
  1948. securePastebinDownload = pastebinDownload
  1949. secureUrlDownload = urlDownload
  1950.  
  1951.  
  1952. --  -------- Website Management
  1953.  
  1954. local function enterURL()
  1955.     -- Clear
  1956.     fterm.setCursorPos(2, 1)
  1957.     fterm.clearLine()
  1958.     fwrite("rdnt://")
  1959.  
  1960.     -- Read
  1961.     local ret = read(nil, searchBarHistory):gsub("^%s*(.-)%s*$", "%1"):lower()
  1962.     appendToHistory(ret)
  1963.     if ret:len() > 32 then
  1964.         ret = fstring.sub(ret, 1, 39) .. "..."
  1965.     end
  1966.  
  1967.     return ret
  1968. end
  1969.  
  1970. local function renderWebpage(site)
  1971.     term = copyTable(fterm)
  1972.     shell = copyTable(fshell)
  1973.  
  1974.     -- Check for modem
  1975.     if checkForModem() then
  1976.         fterm.clear()
  1977.         fterm.setCursorPos(1, 1)
  1978.         centerPrint("Thank You for Using Mozilla Firefox " .. firefoxVersion)
  1979.         centerPrint("Made by 1lann and GravityScore")
  1980.         term = copyTable(fterm)
  1981.         shell = copyTable(fshell)
  1982.  
  1983.         -- Close rednet
  1984.         for _, v in pairs(rs.getSides()) do
  1985.             frednet.close(v)
  1986.         end
  1987.         exitApp = true
  1988.         return "exit"
  1989.     end
  1990.  
  1991.     -- Variables
  1992.     local overspeed = false
  1993.     runningWebsite = site
  1994.     restoreFunctions()
  1995.     fos.queueEvent(websiteLoadEvent)
  1996.     if fos.clock() - loadingRateClock > 5 then
  1997.         websiteLoadingRate = 0
  1998.         loadingRateClock = fos.clock()
  1999.     elseif websiteLoadingRate >= 4 then
  2000.         overspeed = true
  2001.     end
  2002.  
  2003.     -- Render site
  2004.     if overspeed then webpageOverspeed(overspeed)
  2005.     elseif site == "firefox" then webpageHome(site)
  2006.     elseif site == "history" then webpageHistory(site)
  2007.     elseif site == "server" then webpageServerManagement(site)
  2008.     elseif site == "help" then webpageHelp(site)
  2009.     elseif site == "settings" then webpageSettings(site)
  2010.     elseif site == "credits" then webpageCredits(site)
  2011.     elseif site == "getinfo" then webpageGetInfo(site)
  2012.     elseif site == "exit" then
  2013.         -- Exit client
  2014.         fterm.clear()
  2015.         fterm.setCursorPos(1, 1)
  2016.         centerPrint("Thank You for Using Mozilla Firefox " .. firefoxVersion)
  2017.         centerPrint("Made by 1lann and GravityScore")
  2018.         term = copyTable(fterm)
  2019.         shell = copyTable(fshell)
  2020.  
  2021.         -- Close rednet
  2022.         for _, v in pairs(rs.getSides()) do
  2023.             rednet.close(v)
  2024.         end
  2025.        
  2026.         exitApp = true
  2027.         return "exit"
  2028.     else
  2029.         -- Load the site
  2030.         loadWebpage(site)
  2031.     end
  2032. end
  2033.  
  2034. function redirect(site)
  2035.     term = copyTable(fterm)
  2036.     shell = copyTable(fshell)
  2037.     -- Convert site
  2038.     local url = site:gsub("^%s*(.-)%s*$", "%1"):lower()
  2039.     if url == "home" then
  2040.         url = homepage
  2041.     end
  2042.  
  2043.     -- Load site
  2044.     appendToHistory(url)
  2045.     clearPage(url)
  2046.     local opt = renderWebpage(url)
  2047.     if opt == "exit" then
  2048.         exitApp = true
  2049.         ferror()
  2050.     end
  2051.  
  2052.     if fshell.getRunningProgram():find(".Firefox_Data/cache") then
  2053.         ferror()
  2054.     end
  2055. end
  2056.  
  2057. secureRedirection = redirect
  2058.  
  2059. local function manageWebpages()
  2060.     while not(exitApp) do
  2061.         -- Render Page
  2062.         local opt = ""
  2063.         if not(userTerminated) then
  2064.             clearPage(website)
  2065.             opt = renderWebpage(website)
  2066.         else
  2067.             webpageCrash()
  2068.         end
  2069.  
  2070.         -- Exit
  2071.         userTerminated = false
  2072.         if opt == "exit" then
  2073.             exitApp = true
  2074.             ferror()
  2075.         end
  2076.  
  2077.         -- Wait for URL bar open
  2078.         fos.pullEvent(openURLBarEvent)
  2079.         website = enterURL()
  2080.         if website == "home" then
  2081.             website = homepage
  2082.         end
  2083.     end
  2084. end
  2085.  
  2086. local function waitForURLEnter()
  2087.     while not(exitApp) do
  2088.         _, key = fos.pullEvent("key")
  2089.         if key == 29 or key == 157 then
  2090.             string = copyTable(fstring)
  2091.             fos.queueEvent(openURLBarEvent)
  2092.         end
  2093.     end
  2094. end
  2095.  
  2096.  
  2097. --  -------- Firefox 1.3 Support
  2098.  
  2099. function cPrint(text)
  2100.     centerPrint(text)
  2101. end
  2102.  
  2103. function cWrite(text)
  2104.     centerWrite(text)
  2105. end
  2106.  
  2107. function lPrint(text)
  2108.     leftWrite(text)
  2109. end
  2110.  
  2111. function lWrite(text)
  2112.     leftWrite(text)
  2113. end
  2114.  
  2115. function rPrint(text)
  2116.     rightWrite(text)
  2117. end
  2118.  
  2119. function rWrite(text)
  2120.     rightWrite(text)
  2121. end
  2122.  
  2123. function reDirect(site)
  2124.     redirect(site)
  2125. end
  2126.  
  2127. function clearArea()
  2128.     clearPage(runningWebsite)
  2129. end
  2130.  
  2131. function lockControl()
  2132.     lockCtrl = true
  2133. end
  2134.  
  2135. function unlockControl()
  2136.     lockCtrl = false
  2137. end
  2138.  
  2139. function compatability()
  2140.     term = copyTable(fterm)
  2141.     shell = copyTable(fshell)
  2142. end
  2143.  
  2144. --  -------- Main
  2145.  
  2146. local function startup()
  2147.     -- Logo
  2148.     fterm.clear()
  2149.     fterm.setCursorPos(1, 4)
  2150.     centerPrint("           _   _                    __ __   ")
  2151.     centerPrint("--------- / | / |   ____ ____   __ / // /___")
  2152.     centerPrint("-------- /  |/  |  /   //_  /  / // // //  |")
  2153.     centerPrint("------- / /| /| | / / /  / /_ / // // // - |")
  2154.     centerPrint("------ /_/ |/ |_|/___/  /___//_//_//_//_/|_|")
  2155.     centerPrint("----- _____ __ ____   ____ ___  ______  __  ")
  2156.     centerPrint("---- / ___// // __ \\ / __// __//   /\\ \\/ /  ")
  2157.     centerPrint("--- / /__ / // _  / / __// __// / /  >  <   ")
  2158.     centerPrint("-- / ___//_//_/ \\_\\/___//_/  /___/  /_/\\_\\  ")
  2159.     centerPrint("- / /                                       ")
  2160.     centerPrint(" /_/    Doing Good is Part of Our Code      ")
  2161.     fprint("\n")
  2162.  
  2163.     -- Filesystem
  2164.     fterm.clearLine()
  2165.     centerWrite("Downloading Required Files...")
  2166.     resetFilesystem()
  2167.  
  2168.     -- Databases
  2169.     fterm.clearLine()
  2170.     centerWrite("Downloading Databases...")
  2171.     reloadDatabases()
  2172.  
  2173.     -- Load settings
  2174.     fterm.clearLine()
  2175.     centerWrite("Loading Settings...")
  2176.     local f1 = fio.open(settingsLocation, "r")
  2177.     local set = ftextutils.unserialize(f1:read("*l"))
  2178.     homepage = set.home
  2179.     website = homepage
  2180.     if not(override) then
  2181.         autoupdate = set.auto
  2182.         incognito = set.incog
  2183.     end
  2184.     restoreFunctions()
  2185.     f1:close()
  2186.  
  2187.     local f2 = fio.open(historyLocation, "r")
  2188.     history = ftextutils.unserialize(f2:read("*l"))
  2189.     f2:close()
  2190.    
  2191.     -- Update
  2192.     fterm.clearLine()
  2193.     centerWrite("Checking for Updates...")
  2194.     if autoupdate == "true" then
  2195. --      updateClient()
  2196.     end
  2197.  
  2198.     -- Modem
  2199.     checkForModem()
  2200.  
  2201.     -- Start websites
  2202.     if debugging then
  2203.         fparallel.waitForAny(manageWebpages, waitForURLEnter, updateDatabases)
  2204.     else
  2205.         rawset(coroutine, "yield", function(a)
  2206.             if exitWebsite or exitApp then
  2207.                 if not finishExit then
  2208.                     ferror()
  2209.                 else
  2210.                     exitApp = false
  2211.                     exitWebsite = false
  2212.                     return backupYield(a)
  2213.                 end
  2214.             else
  2215.                 return backupYield(a)
  2216.             end
  2217.         end)
  2218.        
  2219.         while not(exitApp) do
  2220.             fterm.setCursorBlink(false)
  2221.             fparallel.waitForAll(
  2222.                 function()
  2223.                     _, errorMessage = fpcall(manageWebpages)
  2224.                     ferror()
  2225.                 end, waitForURLEnter, updateDatabases)
  2226.  
  2227.             if exitApp then
  2228.                 ferror()
  2229.             end
  2230.             exitWebsite = false
  2231.             userTerminated = true
  2232.         end
  2233.     end
  2234. end
  2235.  
  2236. -- Start Firefox
  2237. startup()
  2238.  
  2239. -- End Encasing Function
  2240. end
  2241.  
  2242.  
  2243. --  -------- Complete Crash Protection
  2244.  
  2245. -- Copy APIs
  2246. local function fcopyTable(oldTable)
  2247.     local newTable = {}
  2248.     for k,v in pairs(oldTable) do
  2249.         print(k)
  2250.         newTable[k] = v
  2251.     end
  2252.     return newTable
  2253. end
  2254.  
  2255. local sterm = fcopyTable(term)
  2256. local sos = os
  2257. local sprint = print
  2258. local serror = error
  2259. local smath = fcopyTable(math)
  2260.  
  2261. -- Functions
  2262. local function scenterPrint(text)
  2263.     local w, h = sterm.getSize()
  2264.     local x, y = sterm.getCursorPos()
  2265.     sterm.setCursorPos(smath.ceil((w + 1)/2 - text:len()/2), y)
  2266.     sprint(text)
  2267. end
  2268.  
  2269. if http then
  2270.     -- Run Firefox
  2271.     local err = nil
  2272.     local _, err = pcall(entiretyFirefox)
  2273.  
  2274.     -- Catch Crash
  2275.     finishExit = true
  2276.     exitApp = false
  2277.     if err then
  2278.         sterm.clear()
  2279.         sterm.setCursorPos(1, 2)
  2280.         scenterPrint("Critical Error!")
  2281.         sprint("\n")
  2282.         scenterPrint("Firefox Has Encountered A Critical")
  2283.         scenterPrint("Internal Error!")
  2284.         sprint("\n")
  2285.         scenterPrint("Error:")
  2286.         sprint("  " .. err)
  2287.         sprint(" ")
  2288.         scenterPrint("Please Report This Error To 1lann")
  2289.         scenterPrint("or GravityScore")
  2290.         sprint("\n")
  2291.         scenterPrint("[Exit Firefox]")
  2292.         while true do
  2293.             local _, key = sos.pullEvent("key")
  2294.             if key == 28 then
  2295.                 sterm.clear()
  2296.                 sterm.setCursorPos(1, 1)
  2297.                 break
  2298.             end
  2299.         end
  2300.     end
  2301. else
  2302.     sterm.clear()
  2303.     sterm.setCursorPos(1, 2)
  2304.     scenterPrint("HTTP API Not Enabled!")
  2305.     sprint("\n")
  2306.     scenterPrint("Warning:")
  2307.     scenterPrint("The HTTP API Is Not Enabled!")
  2308.     sprint(" ")
  2309.     scenterPrint("Firefox Requires The HTTP API To Be Enabled!")
  2310.     sprint("\n\n")
  2311.     scenterPrint("[Exit Firefox]")
  2312.     while true do
  2313.         local _, key = sos.pullEvent("key")
  2314.         if key == 28 then
  2315.             sterm.clear()
  2316.             sterm.setCursorPos(1, 1)
  2317.             break
  2318.         end
  2319.     end
  2320. end
  2321.  
  2322. -- Exit
  2323. serror()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement