Advertisement
GravityScore

Firefox 1.3.6

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