Advertisement
GravityScore

Firefox 1.3.5

Nov 17th, 2012
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.35 KB | None | 0 0
  1. --  -------- Mozilla Firefox
  2. --  -------- Designed and Programmed by 1lann and GravityScore
  3.  
  4. --  -------- Originally Based off RednetExplorer v2.4.1
  5. --  -------- RednetExplorer Originally Made by xXm0dzXx/CCFan11
  6.  
  7.  
  8. --  -------- Features to Come
  9.  
  10. -- 1. Unified Title and URL Bar             1.4
  11. -- 2. Server Managing                       1.4
  12. -- 3. Bookmarks                             1.3.5
  13. -- 4. View History                          1.3.5
  14. -- 5. Upgraded Help                         1.4
  15. -- 6. Preferences                           1.4
  16. --   1. Auto-Updating on/off
  17. --   2. Change Homepage
  18. --   3. Ability to download pre-releases (off unstable)
  19. --   4. Reset Firefox
  20. -- 7. Sites: Description of Each            1.3.4
  21.  
  22.  
  23.  
  24. --  -------- Variables
  25.  
  26. -- Version
  27. local firefoxVersion = "1.3.5"
  28.  
  29. -- Title
  30. local firefoxTitle = "Mozilla Firefox " .. firefoxVersion
  31. local firefoxServerTitle = "Firefox Server " .. firefoxVersion
  32. local title = firefoxTitle
  33.  
  34. -- Pastebin IDs
  35. local firefoxPastebinID = "firefox-stable.lua"
  36. local fireDatabasePastebinID = "firefox-firewall.txt"
  37. local fireVerifiedPastebinID = "firefox-verified.txt"
  38. local firefoxServerPastebinID = "firefox-server.lua"
  39. local fireDefinitionsPastebinID = "firefox-defs.txt"
  40.  
  41. -- Data Locations
  42. local root = "/.FirefoxData"
  43. local blacklistLoc = root .. "/firefox_blacklist"
  44. local whitelistLoc = root .. "/firefox_whitelist"
  45. local definitionsLoc = root .. "/firefox_definitions"
  46. local firefoxLoc = "/" .. shell.getRunningProgram()
  47. local website = "home"
  48.  
  49. -- Other
  50. exitFirefox = false
  51. local firstOpen = true
  52. local quickHistory = {}
  53. local websiteRunning = false
  54.  
  55. local autoUpdate = false
  56. local debugging = false
  57.  
  58. -- Open Rednet
  59. rednet.open("top")
  60. rednet.open("left")
  61. rednet.open("right")
  62. rednet.open("back")
  63. rednet.open("front")
  64. rednet.open("bottom")
  65.  
  66. --  -------- Prompt Function
  67.  
  68. -- Prompt the user for an input
  69. local function prompt(list, dir)
  70.     --Variables
  71.     local curSel = 1
  72.     local c1 = 200
  73.     local c2 = 208
  74.     if dir == "horizontal" then c1 = 203 c2 = 205 end
  75.    
  76.     --Draw words
  77.     for i = 1, #list do
  78.         if list[i][2] == 1 then list[i][2] = 2
  79.         elseif list[i][2] + string.len(list[i][1]) >= 50 then
  80.             list[i][2] = 49 - string.len(list[i][1])
  81.         end
  82.        
  83.         term.setCursorPos(list[i][2], list[i][3])
  84.         write(list[i][1])
  85.     end
  86.    
  87.     --Functions
  88.     local function drawArrows(word, x, y)
  89.         --Draw arrows
  90.         term.setCursorPos(x, y)
  91.         write("[")
  92.         term.setCursorPos(x + 1 + string.len(word), y)
  93.         write("]")
  94.     end
  95.    
  96.     local function removeArrows(word, x, y)
  97.         --Remove current arrows
  98.         term.setCursorPos(x, y)
  99.         write(" ")
  100.         term.setCursorPos(x + 1 + string.len(word), y)
  101.         write(" ")
  102.     end
  103.    
  104.     --Draw arrows
  105.     drawArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
  106.    
  107.     --Start loop
  108.     while true do
  109.         --Get the key
  110.         local event, key = os.pullEvent("key")
  111.        
  112.         --Remove arrows
  113.         removeArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
  114.        
  115.         if key == c1 then
  116.             --Subtract
  117.             if curSel ~= 1 then
  118.                 curSel = curSel - 1
  119.             end
  120.         elseif key == c2 then
  121.             --Add
  122.             if curSel ~= #list then
  123.                 curSel = curSel + 1
  124.             end
  125.         elseif key == 28 then
  126.             --Enter
  127.             return list[curSel][1]
  128.         end
  129.        
  130.         --Draw Arrows
  131.         drawArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
  132.     end
  133. end
  134.  
  135. --  -------- Drawing
  136.  
  137. -- Print text in the center of the screen
  138. function cPrint(text)
  139.     local w, h = term.getSize()
  140.     local x, y = term.getCursorPos()
  141.     term.setCursorPos(math.ceil((w / 2) - (text:len() / 2)), y)
  142.     print(text)
  143. end
  144.  
  145. -- Clear page apart from title and website name
  146. function clearArea()
  147.     term.clear()
  148.     term.setCursorPos(1, 1)
  149.     cPrint(title)
  150.     cPrint("rdnt://" .. website .. "\n")
  151. end
  152.  
  153. --  -------- Utilities
  154.  
  155. -- Get code from pastebin
  156. function getPastebin(code, location)
  157.     local response = http.get("http://dl.dropbox.com/u/97263369/" .. code)
  158.  
  159.     if response then
  160.         local text = response.readAll()
  161.         response.close()
  162.        
  163.         local file = fs.open(location, "w")
  164.         file.write(text)
  165.         file.close()
  166.     end
  167. end
  168.  
  169. -- Quickly debug a message
  170. local function debug(msg)
  171.     term.setCursorPos(1,1)
  172.     term.clearLine()
  173.     write(tostring(msg))
  174.     sleep(3)
  175. end
  176.  
  177. --  -------- Database Functions
  178.  
  179. -- Variables
  180. local bDatabase = {}
  181. local bvIDs = {}
  182. local bvAddresses = {}
  183. local bType = nil
  184.  
  185. -- Download and update the database of servers (white and blacklists)
  186. local function getDatabase()
  187.     -- Get database from pastebin
  188.     getPastebin(fireDatabasePastebinID, root .. "/fireDatabase")
  189.     getPastebin(fireVerifiedPastebinID, root .. "/fireVerified")
  190.     getPastebin(fireDefinitionsPastebinID, root .. "/fireDefinitions")
  191.  
  192.     local f = io.open(root .. "/fireDatabase", "r")
  193.     bDatabase = {}
  194.     for readData in f:lines() do
  195.         table.insert(bDatabase, readData)
  196.     end
  197.     f:close()
  198.     local f = io.open(root .. "/fireDefinitions")
  199.     webDefinitions = {}
  200.     for readData in f:lines() do
  201.         table.insert(webDefinitions, readData)
  202.     end
  203.     f:close()
  204.     f = io.open(root .. "/fireVerified", "r")
  205.     bvIDs = {}
  206.     bvAddresses = {}
  207.     bType = "url"
  208.     for readData in f:lines() do
  209.         if bType == "url" then
  210.             table.insert(bvAddresses, readData)
  211.             bType = "id"
  212.         else
  213.             table.insert(bvIDs, readData)
  214.             bType = "url"
  215.         end
  216.     end
  217.     f:close()
  218.  
  219.     if not(fs.exists(blacklistLoc)) then
  220.         f = io.open(blacklistLoc, "w") f:write("\n") f:close()
  221.     else
  222.         f = io.open(blacklistLoc, "r")
  223.         for readData in f:lines() do
  224.             table.insert(bDatabase, readData)
  225.         end
  226.         f:close()
  227.     end
  228.  
  229.     if not(fs.exists(definitionsLoc)) then
  230.         f = io.open(definitionsLoc, "w") f:write("\n") f:close()
  231.     else
  232.         f = io.open(definitionsLoc, "r")
  233.         for readData in f:lines() do
  234.             table.insert(webDefinitions, readData)
  235.         end
  236.         f:close()
  237.     end
  238.  
  239.  
  240.     if not fs.exists(whitelistLoc) then
  241.         f = io.open(whitelistLoc, "w") f:write("\n") f:close()
  242.     else
  243.         bType = "url"
  244.         f = io.open(whitelistLoc, "r")
  245.         local x = 1
  246.         local bnLines = 0
  247.         for readData in f:lines() do
  248.             bnLines = bnLines+1
  249.             if bType == "url" then
  250.                 table.insert(bvAddresses, readData)
  251.                 bType = "id"
  252.             else
  253.                 table.insert(bvIDs, readData)
  254.                 bType = "url"
  255.             end
  256.         end
  257.         f:close()
  258.         if #bvAddresses > #bvIDs then table.remove(bvAddresses, #bvAddresses)
  259.         elseif #bvAddresses < #bvIDs then table.remove(bvIDs, #bvIDs) end
  260.     end
  261.  
  262.     return bDatabase
  263. end
  264.  
  265. -- Check if the database contains an object
  266. local function dbContains(object, dbase)
  267.     for i = 1, #dbase do
  268.         if tostring(object) == dbase[i] then
  269.             return true, i
  270.         end
  271.     end
  272.  
  273.     return false
  274. end
  275.  
  276. -- Constantly Update the Database Upon Webpage Load
  277. local function autoDatabase()
  278.     while true do
  279.         local aDE = os.pullEvent()
  280.         if aDE == "firefoxDoneLoading" then
  281.             getDatabase()
  282.         end
  283.     end
  284. end
  285.  
  286. --  -------- Verifing Websites
  287.  
  288. -- Verify the website against the whitelist
  289. local function isVerified(vWebsite, vID)
  290.     -- Verify an ID
  291.     if string.find(vWebsite, "/") then
  292.         local vFind = string.find(vWebsite, "/")
  293.         vWebsite = string.sub(vWebsite, 1, vFind - 1)
  294.     end
  295.  
  296.     for i = 1, #bvAddresses do
  297.         if vWebsite == string.lower(bvAddresses[i]) then
  298.             if tostring(vID) == bvIDs[i] then
  299.                 return "good"
  300.             else
  301.                 return "bad"
  302.             end
  303.         end
  304.     end
  305.  
  306.     return "unknown"
  307. end
  308.  
  309. -- Check a database entry against the database
  310. local function isBad(number)
  311.     for i = 1, #bDatabase do
  312.         if tostring(number) == bDatabase[i] then
  313.             return true
  314.         end
  315.     end
  316.  
  317.     return false
  318. end
  319.  
  320. local function checkWebsite(dataCheck)
  321.     for i = 1, #webDefinitions do
  322.         if string.find(dataCheck, webDefinitions[i], 1, true) and webDefinitions[i] ~= nil and webDefinitions[i] ~= "" and webDefinitions[i] ~= "\n" then
  323.             return true
  324.         end
  325.     end
  326. return false
  327. end
  328.  
  329.  
  330. -- Check if a website it malicious
  331. local function checkMalicious()
  332.     local suspected = {}
  333.     local times = {}
  334.     for i = 1, 5 do
  335.         rednet.broadcast(tostring(math.random(1, 9001)))
  336.         startClock = os.clock()
  337.         while os.clock() - startClock < 0.1 do
  338.             local a = rednet.receive(0.05)
  339.             if a ~= nil then
  340.                 dbState, dbPos = dbContains(a, suspected)
  341.                 if isBad(a) then
  342.                 elseif not dbState then
  343.                     table.insert(suspected, tostring(a))
  344.                     table.insert(times, 1)
  345.                     break
  346.                 else
  347.                     local newTimes = times[dbPos] + 1
  348.                     times[dbPos] = newTimes
  349.                 end
  350.             end
  351.         end
  352.     end
  353.  
  354.     for i =1, #suspected do
  355.         if times[i] > 2 then
  356.             f = io.open(blacklistLoc, "a")
  357.             f:write("\n" .. suspected[i])
  358.             f:close()
  359.             table.insert(bDatabase, suspected[i])
  360.         end
  361.     end
  362. end
  363.  
  364. --  -------- File System
  365.  
  366. -- Update the file system from previous versions
  367. local function resetFileSystem()
  368.     if not fs.exists(root) then
  369.         fs.makeDir(root)
  370.         fs.makeDir(root .. "/cache")
  371.     elseif not fs.isDir(root) then
  372.         fs.delete(root)
  373.         fs.makeDir(root)
  374.         fs.makeDir(root .. "/cache")
  375.     end
  376.  
  377.     if fs.exists("/fireverify") then fs.move("/fireverify", whitelistLoc) end
  378.     if fs.exists("/firelist") then fs.move("/firelist", blacklistLoc) end
  379.     if fs.exists("/firefox_whitelist") then fs.move("/firefox_whitelist", whitelistLoc) end
  380.     if fs.exists("/firefox_blacklist") then fs.move("/firefox_blacklist", blacklistLoc) end
  381.     if fs.exists("/.fireServerPref") then fs.move("/.fireServerPref", root .. "/fireServerPref") end
  382.  
  383.     fs.delete("/.fireDatabase")
  384.     fs.delete("/.fireVerify")
  385. end
  386.  
  387. -- Update Firefox client
  388. local function autoUpdater()
  389.     if autoUpdate then
  390.         getPastebin(firefoxPastebinID, root .. "/firefoxClientUpdate")
  391.         local f = io.open(root .. "/firefoxClientUpdate", "r")
  392.         local clientUpdate = f:read("*a")
  393.         f:close()
  394.  
  395.         local ff = io.open(firefoxLoc)
  396.         local currentClient = ff:read("*a")
  397.         ff:close()
  398.  
  399.         if currentClient ~= clientUpdate then
  400.             fs.delete(firefoxLoc)
  401.             fs.move(root .. "/firefoxClientUpdate", firefoxLoc)
  402.             shell.run(firefoxLoc)
  403.             error()
  404.         end
  405.     end
  406. end
  407.  
  408. --  -------- Webpage Loading
  409.  
  410. -- Browser controls
  411.  
  412. local function browserControl()
  413.     websiteRunning = false
  414.     term.setCursorBlink(false)
  415.     if exitFirefox then error() end
  416.     setTitle()
  417.     os.queueEvent("firefoxDoneLoading")
  418.  
  419.     local w, h = term.getSize()
  420.     term.setCursorPos(1, h)
  421.     write(" Control to Surf the Web")
  422.     term.setCursorPos(w - string.len("F5 to Refresh"), h)
  423.     write("F5 to Refresh")
  424.    
  425.     while true do
  426.         local e, k = os.pullEvent("key")
  427.         if k == 63 then
  428.             loadWebpage()
  429.             break
  430.         elseif k == 29 then
  431.             term.setCursorPos(1,2)
  432.             term.clearLine()
  433.             write(" rdnt://")
  434.             website = read(nil, quickHistory)
  435.             loadWebpage()
  436.             break
  437.         end
  438.     end
  439. end
  440.  
  441. -- Set the webpage title
  442. function setTitle(newTitle)
  443.     title = newTitle
  444.     if title == nil then
  445.         title = firefoxTitle
  446.     elseif title:len() == 0 then
  447.         title = firefoxTitle
  448.     end
  449.  
  450.     term.setCursorPos(1, 1)
  451.     term.clearLine()
  452.     cPrint(title)
  453.     term.setCursorPos(1, 2)
  454.     term.clearLine()
  455.     cPrint("rdnt://" .. website .. "\n")
  456. end
  457.  
  458. -- Create webiste
  459. local function createSite(websitename)
  460.     term.clear()
  461.     term.setCursorPos(1, 2)
  462.     print("Creating Site: " .. websitename)
  463.     print("Please Wait...")
  464.  
  465.     f = io.open(root .. "/fireServerPref", "w")
  466.     f:write(websitename)
  467.     f:close()
  468.     getPastebin(firefoxServerPastebinID, root .. "/firefoxServerUpdater")
  469.     shell.run(root .. "/firefoxServerUpdater")
  470.     exitFirefox = true
  471.     error()
  472. end
  473.  
  474. -- Redirect the user to a different page
  475. function redirect(url)
  476.     website = url
  477.     loadWebpage()
  478. end
  479.  
  480. -- Load the website
  481. function loadWebpage()
  482.     if exitFirefox then error() end
  483. if websiteRunning then
  484.     browserControl()
  485.     else
  486.     websiteRunning = true
  487.         title = firefoxTitle
  488.         website = website:lower()
  489.  
  490.         clearArea()
  491.         table.insert(quickHistory, website)
  492.         if website == "home" then
  493.             if firstOpen then
  494.                 term.clear()
  495.                 term.setCursorPos(1, 4)
  496.                 cPrint("         _____  _   ______   _____ ")
  497.                 cPrint("~~~~~~~ / ___/ / / / _   /  / ___/ ")
  498.                 cPrint("------ / /__  / / / /_/ /  / /_    ")
  499.                 cPrint("~~~~~ / ___/ / / / _  _/  / __/    ")
  500.                 cPrint("---- / /    / / / / \\ \\  / /___    ")
  501.                 cPrint("~~~ / /    /_/ /_/   \\_\\/_____/    ")
  502.                 cPrint("-- / /  _,-=._              /|_/|  ")
  503.                 cPrint("~ /_/  `-.}   `=._,.-=-._.,  @ @._,")
  504.                 cPrint("          `. _ _,-.   )      _,.-' ")
  505.                 cPrint("                   G.m-\"^m`m'       ")
  506.                 print(" ")
  507.                 cPrint(" Mozilla Firefox is Now Loading... ")
  508. --              if not(autoUpdate) then sleep(0.75) end
  509. --              autoUpdater()
  510.                 firstOpen = false
  511.             end
  512.  
  513.             clearArea()
  514.             cPrint("Welcome To " .. firefoxTitle)
  515.             print(" ")
  516.  
  517.             if autoUpdate then
  518.                 print(" Automatic Updating is On")
  519.             else
  520.                 print(" Automatic Updating is Off")
  521.             end
  522.  
  523.             local w, h = term.getSize()
  524.             print(" ")
  525.             term.setCursorPos(2, 8)
  526.             write("rdnt://sites")
  527.             term.setCursorPos(w - 1 - string.len("See Sites"), 8)
  528.             write("See Sites")
  529.             term.setCursorPos(2, 9)
  530.             write("rdnt://whatsnew")
  531.             term.setCursorPos(w - 1 - string.len("See Whats New in " .. firefoxVersion), 9)
  532.             write("See Whats New in " .. firefoxVersion)
  533.             term.setCursorPos(2, 10)
  534.             write("rdnt://credits")
  535.             term.setCursorPos(w - 1 - string.len("View Credits"), 10)
  536.             write("View Credits")
  537.             term.setCursorPos(2, 11)
  538.             write("rdnt://exit")
  539.             term.setCursorPos(w - 1 - string.len("Exit Firefox"), 11)
  540.             write("Exit Firefox")
  541.         elseif website == "" or website == " " then
  542.             clearArea()
  543.             print(" ")
  544.             cPrint("OMFG Y U NO ENTER SOMETING?!?!")
  545.         elseif website == "exit" then
  546.             term.clear()
  547.             term.setCursorPos(1,1)
  548.             print("Thank You for Using Firefox!")
  549.             sleep(0.3)
  550.  
  551.             exitFirefox = true
  552.             return
  553.         elseif website == "update" then
  554.             cPrint("Force Update Firefox")
  555.             print(" ")
  556.             local o = prompt({{"Yes", 11, 8}, {"No", 36, 8}},  "horizontal")
  557.             if o == "Yes" then
  558.                 clearArea()
  559.                 cPrint("Updating...")
  560.                 getPastebin(firefoxPastebinID, firefoxLoc)
  561.  
  562.                 clearArea()
  563.                 cPrint("Firefox Has Been Updated")
  564.                 cPrint("Press Any Key to Restart")
  565.                 os.pullEvent("key")
  566.                 shell.run(firefoxLoc)
  567.                 error()
  568.             else
  569.                 clearArea()
  570.                 cPrint("Cancelled Update")
  571.             end
  572.         elseif website == "whatsnew" then
  573.             cPrint("New Fetures in Firefox " .. firefoxVersion)
  574.             print(" ")
  575.             print(" Changed the UI Slightly")
  576.             print(" Improved In-Built Server Software")
  577.             print(" Moved from Pastebin to Dropbox")
  578.             print(" Added Virus Detection and Protection")
  579.             print(" Fixed Several Bugs that Cause Crashing")
  580.             print(" Added Secret Easter Egg :D")
  581.         elseif website == "sites" then
  582.             --[[cPrint("Sites")
  583.             print(" ")
  584.             print(" Enter \"firefox\" to See Firefox Sites")
  585.             term.setCursorPos(2, 7)
  586.             write("Enter Search: ")
  587.             local search = read()
  588.  
  589.             if search:lower() == "firefox" then]]--
  590.                 --clearArea()
  591.                 cPrint("Standard Firefox Sites")
  592.                 print(" ")
  593.                 print(" rdnt://home")
  594.                 print(" rdnt://update")
  595.                 print(" rdnt://whatsnew")
  596.                 print(" rdnt://sites")
  597.                 print(" rdnt://getid")
  598.                 print(" rdnt://newsite")
  599.                 print(" rdnt://credits")
  600.                 print(" rdnt://exit")
  601.                 print(" ")
  602.             --[[else
  603.                 rednet.broadcast("rednet.api.ping.searchengine")
  604.                 local s = {}
  605.                 local x = 1
  606.                 while true do
  607.                     local i, m = rednet.receive(0.1)
  608.                     if i then table.insert(s, (i .. " : " .. m))
  609.                     else break end
  610.                 end
  611.  
  612.                 clearArea()
  613.                 cPrint("User Sites")
  614.                 print(" ")
  615.                 for i = 1, s do
  616.                     print(" " + s[i])
  617.                 end
  618.             end]]--
  619.         elseif website == "getid" then
  620.             cPrint("Get Server Computer ID")
  621.             term.setCursorPos(2, 7)
  622.             write("Enter Server URL: ")
  623.             local url = read()
  624.  
  625.             rednet.broadcast(url)
  626.             local i, m = rednet.receive(0.1)
  627.  
  628.             clearArea()
  629.             cPrint("Get Server Computer ID")
  630.             print(" ")
  631.             term.setCursorPos(1, 7)
  632.             if string.len(m) ~= 0 and i ~= nil then
  633.                 print(" Server Computer ID: " .. i)
  634.             else
  635.                 print(" Could Not Get Computer ID")
  636.             end
  637.         elseif website == "credits" then
  638.             local w, h = term.getSize()
  639.  
  640.             term.setCursorPos(1, 4)
  641.             cPrint("Firefox Credits")
  642.             print(" ")
  643.             term.setCursorPos(2, 7)
  644.             write("Designed and Coded by:")
  645.             term.setCursorPos(w - 1 - string.len("1lann and GravityScore"), 7)
  646.             write("1lann and GravityScore")
  647.             term.setCursorPos(2, 9)
  648.             write("Based off:")
  649.             term.setCursorPos(w - 1 - string.len("Rednet Explorer v2.4.1"), 9)
  650.             write("Rednet Explorer v2.4.1")
  651.             term.setCursorPos(2, 10)
  652.             write("Rednet Explorer Made by:")
  653.             term.setCursorPos(w - 1 - string.len("xXm0dzXx/CCFan11"), 10)
  654.             write("xXm0dzXx/CCFan11")
  655.         elseif website == "newsite" then
  656.             term.setCursorPos(1, 4)
  657.             cPrint("Use This Computer as a Webserver")
  658.             local opt = prompt({{"Yes", 11, 6}, {"No", 36, 6}}, "horizontal")
  659.            
  660.             if opt == "Yes" then
  661.                 clearArea()
  662.                 if fs.exists(root .. "/fireServerPref") then
  663.                     f = io.open(root .. "/fireServerPref", "r")
  664.                     websitename = f:read("*l")
  665.                     f:close()
  666.  
  667.                     if fs.isDir("/" .. websitename) then
  668.                         cPrint("A Previous Server Setup has Been Detected")
  669.                         cPrint("For Site: " .. websitename)
  670.                         cPrint("Use This Setup")
  671.                         local opt = prompt({{"Yes", 11, 9}, {"No", 36, 9}}, "horizontal")
  672.  
  673.                         if opt == "Yes" then
  674.                             createSite(websitename)
  675.                         end
  676.                     end
  677.                 end
  678.  
  679.                 term.clear()
  680.                 term.setCursorPos(1, 1)
  681.                 cPrint(title)
  682.                 term.setCursorPos(2, 4)
  683.                 write("Website Name: ")
  684.                 websitename = read()
  685.                 f = io.open(root .. "/fireServerPref", "w")
  686.                 f:write(websitename)
  687.                 f:close()
  688.  
  689.                 term.clear()
  690.                 term.setCursorPos(1, 1)
  691.                 cPrint(title .. "\n")
  692.                    
  693.                 if fs.exists("/" .. websitename) and not(fs.isDir("/" .. websitename)) then
  694.                     fs.move("/" .. websitename, root .. "/firefoxtemphome")
  695.                     fs.makeDir("/" .. websitename)
  696.                     fs.move(root .. "/firefoxtemphome", "/" .. websitename .. "/home")
  697.                     print(" An Old Website Has Been Detected")
  698.                     print(" It Has Been Moved To: ")
  699.                     print(" /" .. websitename .. "/home")
  700.                     print(" ")
  701.                 else
  702.                     fs.makeDir("/" .. websitename)
  703.                 end
  704.  
  705.                 rednet.broadcast(string.lower(websitename))
  706.                 local i, me = rednet.receive(0.5)
  707.                 if i ~= nil then
  708.                     print(" WARNING: This Domain Name May Already Be In Use")
  709.                     print(" ")
  710.                 end
  711.  
  712.                 print(" The Website Files can be Found In:")
  713.                 print(" /" .. websitename)
  714.                 print(" The Homepage is Located At:")
  715.                 print(" /" .. websitename .. "/home")
  716.                 print(" ")
  717.  
  718.                 print(" Edit the Homepage of the Website?")
  719.                 local o = prompt({{"Yes", 11, 14}, {"No", 36, 14}}, "horizontal")
  720.                 if o == "Yes" then
  721.                     shell.run("/rom/programs/edit", "/" .. websitename .. "/" .. "home")
  722.                 elseif o == "No" then
  723.                     if not fs.exists("/" .. websitename .. "/" .. "home") then
  724.                         local f = io.open("/" .. websitename .. "/" .. "home", "w")
  725.                         f:write("print(\" \")\nprint(\"Welcome to " .. websitename .. "\")")
  726.                     end
  727.  
  728.                     f:close()
  729.                 end
  730.                
  731.                 term.clear()
  732.                 term.setCursorPos(1, 1)
  733.                 createSite(websitename)
  734.             end
  735.         else
  736.             title = firefoxTitle
  737.             clearArea()
  738.             print(" Connecting to Website...")
  739.  
  740.             checkMalicious()
  741.             rednet.broadcast(website)
  742.             local fWebsite = ""
  743.             if string.find(website, "/") then
  744.                 fWebsite = string.gsub(website, "/", "$slazh$")
  745.             else
  746.                 fWebsite = website
  747.             end
  748.  
  749.             local website1 = root .. "/cache/" .. fWebsite
  750.             local startClock = os.clock()
  751.             local id, message = nil
  752.             while os.clock() - startClock < 0.2 do
  753.                 id, message = rednet.receive(0.1)
  754.                 local vResult = isVerified(website, id)
  755.                 if vResult == "bad" then message = nil
  756.                 elseif vResult == "good" then break
  757.                 elseif vResult == "unknown" and isBad(id) == false then break
  758.                 else message = nil
  759.                 end
  760.             end
  761.  
  762.             local function drawError()
  763.                 clearArea()
  764.                 cPrint(" _____                         _ ")
  765.                 cPrint("|  ___|                       | |")
  766.                 cPrint("| |__  _ __  _ __  ___   _ __ | |")
  767.                 cPrint("|  __|| '__|| '__|/ _ \\ | '__|| |")
  768.                 cPrint("| |___| |   | |  | (_) || |   |_|")
  769.                 cPrint("\\____/|_|   |_|   \\___/ |_|   (_)")
  770.                 print(" ")
  771.                 cPrint("Unable to Connect to Website")
  772.                 cPrint("The Website May Be Down or Blocked")
  773.             end
  774.  
  775.             if message == nil then
  776.                 if fs.exists(website1) then
  777.                     clearArea()
  778.                     cPrint("Unable to Connect to Website")
  779.                     cPrint("Resort to Cached Version?")
  780.                     local o = prompt({{"Yes", 7, 8}, {"No", 16, 8}, {"Delete Cached Version", 24, 8}}, "horizontal")
  781.                     if o == "Yes" then
  782.                         clearArea()
  783.                         websiteRunning = true
  784.                         shell.run(website1)
  785.                     elseif o == "No" then
  786.                         drawError()
  787.                     else
  788.                         fs.delete(website1)
  789.                         clearArea()
  790.                         cPrint("Deleted cached version!")
  791.                     end
  792.                 else
  793.                     drawError()
  794.                 end
  795.             else
  796.                 if checkWebsite(message) then
  797.                     clearArea()
  798.                     cPrint("  ___   _      ___________ _____ _ ")
  799.                     cPrint(" / _ \\ | |    |  ___| ___ \\_   _| |")
  800.                     cPrint("/ /_\\ \\| |    | |__ | |_/ / | | | |")
  801.                     cPrint("|  _  || |    |  __||    /  | | | |")
  802.                     cPrint("| | | || |____| |___| |\\ \\  | | |_|")
  803.                     cPrint("\\_| |_/\\_____/\\____/\\_| \\_| \\_/ (_)")
  804.                     print(" ")
  805.                     cPrint("The Website you are Trying to Access has Been")
  806.                     cPrint("Detected to be Malicious. It is Highly")
  807.                     cPrint("Recommended to Blacklist this Server")
  808.                    
  809.                     local aO = prompt({{"Blacklist this Server", 15, 15}, {"Go to Homepage", 18, 16}, {"Continue Loading", 17, 17}}, "vertical")
  810.                     if aO == "Blacklist this Server" then
  811.                         local f = io.open(blacklistLoc, "a")
  812.                         f:write("\n" .. tostring(id))
  813.                         f:close()
  814.                         table.insert(bDatabase, tostring(id))
  815.                         clearArea()
  816.                         cPrint("Added to the blacklist!")
  817.                         cPrint("The blacklist can be accessed from")
  818.                         cPrint("/.FirefoxData/firefox_blacklist")
  819.                     elseif aO == "Go to Homepage" then
  820.                         websiteRunning = false
  821.                         redirect("home")
  822.                     elseif aO == "Continue Loading" then
  823.                         if fs.exists(website1) then fs.delete(website1) end
  824.                         local webpage = io.open(website1, "w")
  825.                         webpage:write(message)
  826.                         webpage:close()
  827.                         clearArea()
  828.                         websiteRunning = true
  829.                         shell.run(website1)
  830.                     end
  831.                 else
  832.                     if fs.exists(website1) then fs.delete(website1) end
  833.                     local webpage = io.open(website1, "w")
  834.                     webpage:write(message)
  835.                     webpage:close()
  836.                     clearArea()
  837.                     websiteRunning = true
  838.                     shell.run(website1)
  839.                 end
  840.             end
  841.         end
  842.         browserControl()
  843.     end
  844. end
  845.  
  846. --  -------- Main
  847.  
  848. resetFileSystem()
  849. if debugging then
  850.     parallel.waitForAny(autoDatabase, loadWebpage)
  851. else
  852.     while not exitFirefox do
  853.         pcall(function() parallel.waitForAny(autoDatabase, loadWebpage) end)
  854.     end
  855. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement