Advertisement
xXm0dzXx

REX

Nov 5th, 2012
1,102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 40.92 KB | None | 0 0
  1. --[[74
  2. + Added full history/cookies
  3. ]]
  4. local vserin = "--[[74"
  5.  
  6. local x,y = term.getSize()
  7. local currentURL = "home"
  8. local hasModem = true
  9. local theme = "default"
  10. local rednetType = "Rednet"
  11. local tArgs = { ... }
  12. local sHistory = {}
  13.  
  14. fs.makeDir( ".rexComponents" )
  15. fs.makeDir( ".rexComponents/Cookies" )
  16. fs.makeDir( ".rexComponents/Extensions" )
  17.  
  18. local function syncHistory()
  19.     fs.delete( ".rexComponents/History" )
  20.     file = fs.open( ".rexComponents/History", "w" )
  21.     file.write( textutils.serialize( sHistory ) )
  22.     file.close()
  23. end
  24.  
  25. if fs.exists( ".rexComponents/History" ) then
  26.     file = fs.open( ".rexComponents/History", "r" )
  27.     sHistory = textutils.unserialize( file.readAll() )
  28.     file.close()
  29. else
  30.     syncHistory()
  31. end
  32.  
  33. browserAgent = "rex_renewed"
  34.  
  35. local autoUpdater = "http://pastebin.com/raw.php?i=FwhQMq8v"
  36. local WebsiteDatabase = "http://nexusindustries.x10.mx/Websites/folder/" --Folder with all the sites
  37. local ApiPath = "http://nexusindustries.x10.mx/Websites/mcmain.php" --Path API is stored
  38.  
  39. local userSites = { --Message me on the forums if you want a pre-installed site
  40.     ["search"] = [[ loadWebpage( "nexus/search" ) ]],
  41.     ["nexus"] = [[
  42.     local x,y = term.getSize()
  43.  
  44.     function navBar()
  45.         term.setCursorPos(1,y-1)
  46.         write( string.rep( "-", x ) )
  47.         term.setCursorPos(1,y)
  48.        
  49.         local pages = {}
  50.         function addPage( name, link )
  51.             pages[#pages+1] = {
  52.                 ["Name"] = name,
  53.                 ["Link"] = link,
  54.             }
  55.         end
  56.        
  57.         --Add your pages here
  58.        
  59.         addPage("Home","nexus")
  60.         addPage("Contact Us","nexus/contact")
  61.         addPage("IRC","nexus/games")
  62.         addPage("Search","nexus/search")
  63.        
  64.         --End
  65.        
  66.         local maxPage = #pages
  67.         for i=1,maxPage do
  68.             local page = pages[i]
  69.             newLink( " " ..page["Name"].. " ", page["Link"] )
  70.             if i ~= maxPage then
  71.                 write("|")
  72.             end
  73.         end
  74.     end
  75.  
  76.     cPrint("Site under construction",4)
  77.  
  78.     navBar()]],
  79.     ["nexus/contact"] = [[
  80.     local x,y = term.getSize()
  81.  
  82.     function navBar()
  83.         term.setCursorPos(1,y-1)
  84.         write( string.rep( "-", x ) )
  85.         term.setCursorPos(1,y)
  86.        
  87.         local pages = {}
  88.         function addPage( name, link )
  89.             pages[#pages+1] = {
  90.                 ["Name"] = name,
  91.                 ["Link"] = link,
  92.             }
  93.         end
  94.        
  95.         --Add your pages here
  96.        
  97.         addPage("Home","nexus")
  98.         addPage("Contact Us","nexus/contact")
  99.         addPage("IRC","nexus/games")
  100.         addPage("Search","nexus/search")
  101.        
  102.         --End
  103.        
  104.         local maxPage = #pages
  105.         for i=1,maxPage do
  106.             local page = pages[i]
  107.             newLink( " " ..page["Name"].. " ", page["Link"] )
  108.             if i ~= maxPage then
  109.                 write("|")
  110.             end
  111.         end
  112.     end
  113.  
  114.     cPrint("Contact Us",4)
  115.     cPrint("Contact us by messaging xXm0dzXx when I am online")
  116.     cPrint("(Message me with /msg xXm0dzXx <message>)")
  117.  
  118.     navBar()]],
  119.     ["nexus/games"] = [[
  120.     --This program is owned and copyrighted by the NeXuS Coperation (c)
  121.     --Program mainly coded by xXm0dzXx
  122.     --Legal Notice:
  123.     --                   DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  124.     --                                   Version 2, December 2004
  125.     --Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
  126.     --Everyone is permitted to copy and distribute verbatim or modified
  127.     --copies of this license document, and changing it is allowed as long
  128.     --as the name is changed.
  129.     --                   DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  130.     --  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  131.     --0. You just DO WHAT THE FUCK YOU WANT TO.
  132.  
  133.     local messages = {};
  134.     local serverHost = false;
  135.     local channelOP = 0;
  136.     local programName = shell.getRunningProgram()
  137.     local getVersionIRC = "N-IRC v2.0"
  138.     local x,y = term.getSize()
  139.     local serverOPs = {}
  140.     local banList = {}
  141.     local function cPrint(text)
  142.        local x,y = term.getSize()
  143.        x2,y2 = term.getCursorPos()
  144.        term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  145.        write(text.. "\n")
  146.     end
  147.  
  148.     function newIRCREAD( _sReplaceChar, _tHistory )
  149.         term.setCursorBlink( true )
  150.  
  151.         local sLine = ""
  152.         local nHistoryPos = nil
  153.         local nPos = 0
  154.         if _sReplaceChar then
  155.             _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
  156.         end
  157.        
  158.         local w, h = term.getSize()
  159.         local sx, sy = term.getCursorPos() 
  160.         local function redraw()
  161.             local nScroll = 0
  162.             if sx + nPos >= w then
  163.                 nScroll = (sx + nPos) - w
  164.             end
  165.                
  166.             term.setCursorPos( sx, sy )
  167.             term.write( string.rep(" ", w - sx + 1) )
  168.             term.setCursorPos( sx, sy )
  169.             if _sReplaceChar then
  170.                 term.write( string.rep(_sReplaceChar, string.len(sLine) - nScroll) )
  171.             else
  172.                 term.write( string.sub( sLine, nScroll + 1 ) )
  173.             end
  174.             term.setCursorPos( sx + nPos - nScroll, h )
  175.         end
  176.        
  177.         while true do
  178.             local sEvent, param, message = os.pullEvent()
  179.             if sEvent == "char" then
  180.                 sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  181.                 nPos = nPos + 1
  182.                 redraw()
  183.                
  184.             elseif sEvent == "key" then
  185.                 if param == keys.enter then
  186.                     -- Enter
  187.                     break
  188.                    
  189.                 elseif param == keys.left then
  190.                     -- Left
  191.                     if nPos > 0 then
  192.                         nPos = nPos - 1
  193.                         redraw()
  194.                     end
  195.                    
  196.                 elseif param == keys.right then
  197.                     -- Right               
  198.                     if nPos < string.len(sLine) then
  199.                         nPos = nPos + 1
  200.                         redraw()
  201.                     end
  202.                
  203.                 elseif param == keys.up or param == keys.down then
  204.                     -- Up or down
  205.                     if _tHistory then
  206.                         if param == keys.up then
  207.                             -- Up
  208.                             if nHistoryPos == nil then
  209.                                 if #_tHistory > 0 then
  210.                                     nHistoryPos = #_tHistory
  211.                                 end
  212.                             elseif nHistoryPos > 1 then
  213.                                 nHistoryPos = nHistoryPos - 1
  214.                             end
  215.                         else
  216.                             -- Down
  217.                             if nHistoryPos == #_tHistory then
  218.                                 nHistoryPos = nil
  219.                             elseif nHistoryPos ~= nil then
  220.                                 nHistoryPos = nHistoryPos + 1
  221.                             end                    
  222.                         end
  223.                        
  224.                         if nHistoryPos then
  225.                             sLine = _tHistory[nHistoryPos]
  226.                             nPos = string.len( sLine )
  227.                         else
  228.                             sLine = ""
  229.                             nPos = 0
  230.                         end
  231.                         redraw()
  232.                     end
  233.                 elseif param == keys.backspace then
  234.                     -- Backspace
  235.                     if nPos > 0 then
  236.                         sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
  237.                         nPos = nPos - 1                
  238.                         redraw()
  239.                     end
  240.                 end
  241.             elseif sEvent == "rednet_message" then
  242.                 local id = param
  243.                 local _messageWords1 = split(message, ":")
  244.                 local _messageWords2 = split(message, "<!:>")
  245.                 local _messageLength2 = string.len("IRC_MESSAGE<!:>" .._tChannel.. "<!:>");
  246.                 local _messageLength3 = string.len("IRC_COMMAND:" .._tChannel.. ":");
  247.                 if serverHost and message == ("IRC_OPS:" .._tChannel) then
  248.                     rednet.send(id, textutils.serialize(serverOPs))
  249.                 elseif serverHost and message == ("IRC_BAN:" .._tChannel) then
  250.                     rednet.send(id, textutils.serialize(banList))
  251.                 elseif message == ("IRC_OP:" .._tChannel.. ":" .._tUser) then
  252.                     addMSG("You are now OP!")
  253.                 elseif _messageWords1[1] == ("IRC_JOIN") and _messageWords1[2] == (_tChannel) then
  254.                     if isBanned( _messageWords1[3] ) ~= true then
  255.                         addMSG(_messageWords1[3].. " has joined the server!")
  256.                     end
  257.                 elseif _messageWords2[1] == ("IRC_MESSAGE") and _messageWords2[2] == (_tChannel) then
  258.                     if isBanned( _messageWords2[3] ) ~= true then
  259.                         if isOP(_messageWords2[3],serverOPs) then
  260.                             addMSG("[" .._messageWords2[3].. "] " .._messageWords2[4])
  261.                         else
  262.                             addMSG("<" .._messageWords2[3].. "> " .._messageWords2[4])
  263.                         end
  264.                     end
  265.                 elseif message == ("ServerPing" .._tChannel) and serverHost then
  266.                     rednet.send(id, ("Ping_Received_" .._tChannel.. "_IRC"))
  267.                 end
  268.                
  269.                 local x11,y11 = term.getSize()
  270.                 local x12,y12 = term.getCursorPos()
  271.                 term.clear()
  272.                 term.setCursorPos(1,1)
  273.                 print(_tUser.. " has joined the server!")
  274.                 for i=1,#messages do
  275.                     print(messages[i])
  276.                 end
  277.                
  278.                 print()
  279.                 term.setCursorPos(1,y11)
  280.                 write("> " ..sLine)
  281.             end
  282.         end
  283.        
  284.         term.setCursorBlink( false )
  285.        
  286.         return sLine
  287.     end
  288.  
  289.     function isOP( username )
  290.         if serverHost ~= true then
  291.             rednet.send(channelOP, "IRC_OPS:" .._tChannel)
  292.             repeat
  293.                 id, message2 = rednet.receive()
  294.             until id == channelOP
  295.             serverOPs = textutils.unserialize(message2)
  296.         end
  297.         for i=1,#serverOPs do
  298.             if serverOPs[i] == username then
  299.                 return true
  300.             end
  301.         end
  302.         return false
  303.     end
  304.  
  305.     function isBanned( username )
  306.         if serverHost ~= true then
  307.             rednet.send(channelOP, "IRC_BAN:" .._tChannel)
  308.             repeat
  309.                 id, message2 = rednet.receive()
  310.             until id == channelOP
  311.             banList = textutils.unserialize(message2)
  312.         end
  313.         for i=1,#banList do
  314.             if banList[i] == username then
  315.                 return true
  316.             end
  317.         end
  318.         return false
  319.     end
  320.  
  321.     function split( sLine, sCode )
  322.         local tWords = {}
  323.         for match in string.gmatch(sLine, "[^" ..sCode.. "\t]+") do
  324.             table.insert( tWords, match )
  325.         end
  326.         return tWords
  327.     end
  328.  
  329.     function startProgram()
  330.         term.clear()
  331.         term.setCursorPos(1,1)
  332.         textutils.slowPrint("Opening modems...")
  333.         rednet.open("top")
  334.         textutils.slowPrint("Pinging server: " .._tChannel)
  335.         local timer = os.startTimer(1)
  336.         while true do
  337.             rednet.broadcast("ServerPing" .._tChannel)
  338.             local event, id, message = os.pullEvent()
  339.             if event == "rednet_message" and message == "Ping_Received_" .._tChannel.. "_IRC" then
  340.                 channelOP = id;
  341.                 serverHost = false;
  342.                 textutils.slowPrint("Server found! Joining...")
  343.                 sleep(0.5)
  344.                 break
  345.             elseif event == "timer" and id == timer then
  346.                 textutils.slowPrint("Server not detected. Hosting...")
  347.                 serverHost = true;
  348.                 serverOPs[1] = _tUser
  349.                 sleep(0.5)
  350.                 break
  351.             end
  352.         end
  353.         term.clear()
  354.         term.setCursorPos(1,1)
  355.         sleep(0)
  356.         function addMSG( messagez )
  357.             messages[#messages + 1] = messagez
  358.         end
  359.        
  360.         rednet.broadcast("IRC_JOIN:" .._tChannel.. ":" .._tUser)
  361.        
  362.         function b()
  363.             while true do
  364.                 local x1,y1 = term.getCursorPos()
  365.                 local x,y = term.getSize()
  366.                 term.setCursorPos(1,1)
  367.                 print(_tUser.. " has joined the server!")
  368.                
  369.                 term.setCursorPos(1, y)
  370.                 write("> ")
  371.                 local messageaa = newIRCREAD()
  372.                 term.setCursorPos(1,y-1)
  373.                 term.clearLine()
  374.                 term.setCursorPos(1,y)
  375.                 term.clearLine()
  376.                 term.setCursorPos(x1,y1)
  377.                
  378.                 if string.sub(messageaa, 1, 1) == "/" then
  379.                     if string.sub(messageaa, 1, 3) == "/op" then
  380.                         if isOP(_tUser, serverOPs) then
  381.                             addMSG("(Console) Op'ing " ..string.sub(messageaa, 5, string.len(messageaa)))
  382.                             serverOPs[#serverOPs+1] = string.sub(messageaa, 5, string.len(messageaa))
  383.                             rednet.broadcast("IRC_OP:" .._tChannel.. ":" ..string.sub(messageaa, 5, string.len(messageaa)))
  384.                         else
  385.                             addMSG("No permission")
  386.                         end
  387.                     elseif string.sub(messageaa, 1, 5) == "/mute" then
  388.                         if isOP(_tUser, serverOPs) then
  389.                             addMSG(string.sub(messageaa, 7, string.len(messageaa)).. " has been muted.")
  390.                             banList[#banList+1] = string.sub(messageaa, 7, string.len(messageaa))
  391.                         else
  392.                             addMSG("No permission")
  393.                         end
  394.                     else
  395.                         addMSG("Unknown command.")
  396.                     end
  397.                 else
  398.                     if isBanned( _tUser ) then
  399.                         addMSG("You have been muted.")
  400.                     else
  401.                         if isOP(_tUser, serverOPs) then
  402.                             addMSG("[" .._tUser.. "] " ..messageaa)
  403.                         else
  404.                             addMSG("<" .._tUser.. "> " ..messageaa)
  405.                         end
  406.                         rednet.broadcast("IRC_MESSAGE<!:>" .._tChannel.. "<!:>" .._tUser.. "<!:>" ..messageaa)
  407.                     end
  408.                 end
  409.                
  410.                 local x11,y11 = term.getSize()
  411.                 local x12,y12 = term.getCursorPos()
  412.                 term.clear()
  413.                 term.setCursorPos(1,1)
  414.                 print(_tUser.. " has joined the server!")
  415.                 for i=1,#messages do
  416.                     print(messages[i])
  417.                 end
  418.                
  419.                 print()
  420.             end
  421.         end
  422.        
  423.         b()
  424.     end
  425.  
  426.     function mainMenu( showAdministrator )
  427.         term.clear()
  428.         term.setCursorPos(1,4)
  429.         cPrint("+--------------------+")
  430.         cPrint("|     " ..getVersionIRC.. "     |")
  431.         cPrint("|     ----------     |")
  432.         cPrint("| User:              |")
  433.         cPrint("| Channel: #         |")
  434.         if showAdministrator then
  435.             cPrint("|     ----------     |")
  436.             cPrint("| Admin:             |")
  437.             cPrint("| Enter administrator|")
  438.             cPrint("| code to manage IRC.|")
  439.         end
  440.         cPrint("+--------------------+")
  441.  
  442.         if showAdministrator then
  443.             term.setCursorPos(23,7)
  444.             write(_tUser)
  445.         else
  446.             repeat
  447.                 term.setCursorPos(23,7)
  448.                 _tUser = read()
  449.             until _tUser ~= ""
  450.         end
  451.  
  452.         repeat
  453.             term.setCursorPos(27,8)
  454.             _tChannel = read()
  455.         until _tChannel ~= ""
  456.        
  457.         if _tChannel == "ShowAdmin" then --OoOoOo! A easter egg :D Too bad you can't use it :/
  458.             mainMenu( true )
  459.         end
  460.        
  461.         if showAdministrator then
  462.             term.setCursorPos(24,10)
  463.             _tAdminCode = read()
  464.             -- Doesn't do anything yet...
  465.         end
  466.     end
  467.  
  468.     function autoUpdate()
  469.         term.clear()
  470.         term.setCursorPos(1,6)
  471.         cPrint("+--------------------+")
  472.         cPrint("|     Loading...     |")
  473.         cPrint("| ||||||             |") --Fake loading bar FTW
  474.         cPrint("+--------------------+")
  475.         while true do
  476.             local downloadedFile = http.request("http://pastebin.com/raw.php?i=6QfbvrBW")
  477.             local event, url, body = os.pullEvent()
  478.             if event == "http_success" then
  479.                 _tBody = body.readAll()
  480.                 break
  481.             elseif event == "http_failed" then
  482.                 break
  483.             end
  484.         end
  485.         term.clear()
  486.         term.setCursorPos(1,6)
  487.         cPrint("+--------------------+")
  488.         cPrint("|     Loading...     |")
  489.         cPrint("| ||||||||||||       |")
  490.         cPrint("+--------------------+")
  491.         file = fs.open(programName, "r")
  492.         _fBody = file.readAll()
  493.         file.close()
  494.         sleep(0.5)
  495.         term.clear()
  496.         term.setCursorPos(1,6)
  497.         cPrint("+--------------------+")
  498.         cPrint("|     Loading...     |")
  499.         cPrint("| |||||||||||||||||| |")
  500.         cPrint("+--------------------+")
  501.         sleep(0.5)
  502.         local selection = 1
  503.         if _fBody ~= _tBody then
  504.             while true do
  505.                 if selection == 1 then
  506.                     term.clear()
  507.                     term.setCursorPos(1,6)
  508.                     cPrint("+--------------------+")
  509.                     cPrint("| Install new update |")
  510.                     cPrint("| [Yes]    ?     No  |")
  511.                     cPrint("+--------------------+")
  512.                 else
  513.                     term.clear()
  514.                     term.setCursorPos(1,6)
  515.                     cPrint("+--------------------+")
  516.                     cPrint("| Install new update |")
  517.                     cPrint("|  Yes     ?    [No] |")
  518.                     cPrint("+--------------------+")
  519.                 end
  520.                 local event, key = os.pullEvent("key")
  521.                 if key == keys.left then
  522.                     selection = 1
  523.                 elseif key == keys.right then
  524.                     selection = 2
  525.                 elseif key == keys.enter then
  526.                     if selection == 1 then
  527.                         fs.delete(programName)
  528.                         file = fs.open(programName, "w")
  529.                         file.write(_tBody)
  530.                         file.close()
  531.                         shell.run(programName)
  532.                         error()
  533.                     else
  534.                         break
  535.                     end
  536.                 end
  537.             end
  538.         end
  539.     end
  540.  
  541.     autoUpdate()
  542.     mainMenu( false )
  543.     startProgram()]],
  544.     ["nexus/search"] = [[
  545.         local x,y = term.getSize()
  546.        
  547.         function navBar()
  548.             term.setCursorPos(1,y-1)
  549.             write( string.rep( "-", x ) )
  550.             term.setCursorPos(1,y)
  551.            
  552.             local pages = {}
  553.             function addPage( name, link )
  554.                 pages[#pages+1] = {
  555.                     ["Name"] = name,
  556.                     ["Link"] = link,
  557.                 }
  558.             end
  559.            
  560.             --Add your pages here
  561.            
  562.             addPage("Home","nexus")
  563.             addPage("Contact Us","nexus/contact")
  564.             addPage("IRC","nexus/games")
  565.             addPage("Search","nexus/search")
  566.            
  567.             --End
  568.            
  569.             if newLink then
  570.                 local maxPage = #pages
  571.                 for i=1,maxPage do
  572.                     local page = pages[i]
  573.                     newLink( " " ..page["Name"].. " ", page["Link"] )
  574.                     if i ~= maxPage then
  575.                         write("|")
  576.                     end
  577.                 end
  578.             else
  579.                 if term.isColor() then
  580.                     term.setTextColour( colors.red )
  581.                 end
  582.                 print("NavBar v1.1 not supported in this version of REX.")
  583.             end
  584.         end
  585.  
  586.         rednet.broadcast("rednet.api.ping.searchengine")
  587.  
  588.         cPrint("NeXuS FailSearch v2.0")
  589.  
  590.         local timez = os.startTimer(0.5)
  591.         repeat
  592.             local event, key, URL = os.pullEvent()
  593.             if event == "rednet_message" then
  594.                 cLink( URL )
  595.             end
  596.         until key == timez
  597.  
  598.         navBar()]],
  599.     ["extensions"] = [[local x,y = term.getSize()
  600.         local files = fs.list( ".rexComponents/Extensions" )
  601.         local scroll = 1
  602.         local selection = 1
  603.  
  604.         while true do
  605.             for i=3,y do
  606.                 term.setCursorPos(1,y)
  607.                 term.clearLine()
  608.             end
  609.            
  610.             term.setCursorPos(1,3)
  611.             if #files == 0 then
  612.                 print( "No extensions installed :C" )
  613.                 print( "Install some at rdnt://shop! (Coming soon" )
  614.             else
  615.                 for i=scroll,scroll+y-3 do
  616.                     if i == selection then
  617.                         print( "[X] " ..files[i].. " (DISABLED)" )
  618.                     else
  619.                         print( "[ ] " ..files[i].. " (DISABLED)" )
  620.                     end
  621.                 end
  622.             end
  623.  
  624.             term.setCursorPos(1,y-1)
  625.             print( string.rep( "-", x ) )
  626.             write( "[ Exit ] Enable" )
  627.            
  628.             local event, key = os.pullEvent( "key" )
  629.             if key == keys.up then
  630.                 if selection == scroll then
  631.                     if scroll ~= 1 then
  632.                         scroll = scroll -1
  633.                     end
  634.                 else
  635.                     if selection ~= 1 then
  636.                         selection = selection +1
  637.                     end
  638.                 end
  639.             elseif key == keys.down then
  640.                 if selection == scroll+y-3 then
  641.                     if scroll ~= #files then
  642.                         scroll = scroll +1
  643.                     end
  644.                 else
  645.                     if selection ~= #files then
  646.                         selection = selection +1
  647.                     end
  648.                 end
  649.             elseif key == keys.enter then
  650.                 error()
  651.             end
  652.         end]],
  653. }
  654.  
  655. function cWrite( txt, ypos )
  656.     if ypos then
  657.         term.setCursorPos(1,ypos)
  658.     end
  659.    
  660.     local function printC( text )
  661.         x2,y2 = term.getCursorPos()
  662.         term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  663.         write(text)
  664.     end
  665.    
  666.     if type(txt) == "string" then
  667.         printC( txt )
  668.     elseif type(txt) == "table" then
  669.         for i=1,#txt do
  670.             printC( txt[i] )
  671.         end
  672.     end
  673. end
  674.  
  675. function cPrint( txt, ypos ) --Version 2.0 of cPrint
  676.     cWrite( txt, ypos )
  677.     print()
  678. end
  679.  
  680. local function sneakPeek()
  681.     cPrint( {
  682.         " ________/ _[]x |",
  683.         "| Rednet        |",
  684.         "|    News Today |",
  685.         "|  11/29/2012   |",
  686.         " ~~~~~~~~~~~~~~~ ",
  687.     } )
  688.     print("Creator of REX Renewed claims to be making a new protocal, quote: ")
  689.     term.setTextColour( colors.gray )
  690.     cPrint( {
  691.         "\"Hey guys! I'm working on a new protocal",
  692.         "In this protocal, everything is in 1 file,",
  693.         "when you try to browse to it, it will exe-",
  694.         "cute it but use the subpages in the URL as",
  695.         "arguments in the program.                \"",
  696.     } )
  697.     term.setTextColour( colors.white )
  698.     term.setCursorPos( 1, y )
  699.     write("Posted on 11/29/2012")
  700. end
  701.  
  702. local function newsPage()
  703.     cPrint( {
  704.         " ________/ _[]x |",
  705.         "| Rednet        |",
  706.         "|    News Today |",
  707.         "|  11/29/2012   |",
  708.         " ~~~~~~~~~~~~~~~ ",
  709.     } )
  710.     print()
  711.     print("Welcome to the news site, this is where we add the current/upcoming events :D")
  712.     print("\nWhats new ( #62 ): ")
  713.     print("+ Added rdnt://search")
  714.     print("+ Added rdnt://news")
  715.     print("+ Added offline sites (Pre-installed)")
  716.     print("- Removed text at bottom of Homepage (no room :c)")
  717.     print("\nCreator of REX Renewed says a new protocal coming")
  718.     write("Go to ")
  719.     newLink( "rdnt://news/1-protocal", "news/1-protocal" )
  720.     print(" for more info about this article.")
  721. end
  722.  
  723. local function homePage()
  724.     cPrint("__________ _______________  ___")
  725.     cPrint("\\______   \\\\_   _____/\\   \\/  /")
  726.     cPrint(" |       _/ |    __)_  \\     / ")
  727.     cPrint(" |    |   \\ |        \\ /     \\ ")
  728.     cPrint(" |____|_  //_______  //___/\\  \\")
  729.     cPrint("        \\/         \\/       \\_/")
  730.     cPrint("~~=> Renewed <=~~")
  731.     print()
  732.     cPrint("Default sites: ")
  733.     cPrint("rdnt://home       Default Homepage")
  734.     cPrint("rdnt://settings   Settings        ")
  735.     cPrint("rdnt://newsite    Website Maker   ")
  736.     cPrint("rdnt://search     Default Search  ")
  737.     cPrint("rdnt://news       Rednet News     ")
  738.     cPrint("rdnt://nexus      NeXuS Website   ")
  739.     print()
  740.     cWrite("rdnt://exit")
  741. end
  742.  
  743. function rnetHost()
  744.     term.clear()
  745.     term.setCursorPos(1,1)
  746.     cPrint("Rednet Explorer Online Servers")
  747.     write("Domain (ex: YourDomain.com): rnet://")
  748.     domain = read()
  749.     write("Path to file: ")
  750.     path = read()
  751.     if fs.exists(path) then
  752.         file = fs.open(path, "r")
  753.         if file then
  754.             data = file.readAll()
  755.             file.close()
  756.             if not data then
  757.                 print("Failed to read " ..path)
  758.                 return
  759.             end
  760.             local response = http.post(
  761.             ApiPath,
  762.             "type=upload&"..
  763.             "user=guest&"..
  764.             "pass=guest&"..
  765.             "name=".. textutils.urlEncode(domain) .. "&"..
  766.             "data=" ..textutils.urlEncode(data)
  767.             )
  768.                        
  769.             if response then
  770.                 local sResponse = response.readAll()
  771.                 response.close()
  772.                 print("Done!")
  773.                 print("Log: ")
  774.                 sleep(0.5)
  775.                 if string.find(sResponse, "success") then
  776.                     print("Uploading " ..shell.resolve(path).. " complete!")
  777.                     print("Errors: 0")
  778.                     print("\nGo to " ..domain.. " to check the site!")
  779.                 else
  780.                     print("Failed : " ..sResponse)
  781.                     print()
  782.                     if sResponse == "Write_lock" then
  783.                         print("The write_lock error means you have been locked out from uploading because are a hacker, a troll, or a spammer that is trying to upload a file to mess up my database and you are gonna be hunted down and killed (not IRL) by my team :)\n\nFYI, your IP has been traced.")
  784.                     end
  785.                 end
  786.             else
  787.                 print("Failed to connect to database.")
  788.             end
  789.         else
  790.             print("Failed to open " ..path)
  791.         end
  792.     else
  793.         print(path.. " doesn't exist.")
  794.     end
  795. end
  796.  
  797. local function newButton( currentID, id, text, fez )
  798.     if not fez then
  799.         term.clearLine()
  800.     end
  801.     if currentID == id then
  802.         cPrint("[ " ..text.. " ]")
  803.     else
  804.         cPrint(text)
  805.     end
  806. end
  807.  
  808. local function settings()
  809.     local currentID = 1
  810.     local function settingMenu()
  811.         term.setCursorPos(1,5)
  812.         cPrint("Configuration")
  813.         print()
  814.         newButton( currentID, 1, "Download Settings (" ..rednetType.. ")" )
  815.         newButton( currentID, 2, "Homepage" )
  816.         newButton( currentID, 3, "Extensions (NYI)" )
  817.         newButton( currentID, 4, "Theme (" ..theme.. ")" )
  818.         newButton( currentID, 5, "Reset Browser Data" )
  819.         print()
  820.         newButton( currentID, 6, "Exit" )
  821.     end
  822.    
  823.     while true do
  824.         settingMenu()
  825.         local event, key = os.pullEvent("key")
  826.         if key == keys.up then
  827.             if currentID ~= 1 then
  828.                 currentID = currentID -1
  829.             end
  830.         elseif key == keys.down then
  831.             if currentID ~= 6 then
  832.                 currentID = currentID +1
  833.             end
  834.         elseif key == keys.enter then
  835.             if currentID == 1 then
  836.                 if rednetType == "Rednet" then
  837.                     rednetType = "HTTP"
  838.                 elseif rednetType == "HTTP" then
  839.                     rednetType = "rnet"
  840.                 elseif rednetType == "rnet" then
  841.                     rednetType = "Rednet"
  842.                 end
  843.                
  844.                 loadWebpage( "settings" )
  845.             elseif currentID == 2 then
  846.                 local newID = 1
  847.                 local currentTheme = ""
  848.                 local function settingMenu()
  849.                     term.clear()
  850.                     term.setCursorPos(1,1)
  851.                     cPrint("Homepage")
  852.                     file = fs.open( ".rexsettings", "r" )
  853.                     cPrint( "rdnt://" ..file.readLine() )
  854.                     currentTheme = file.readLine()
  855.                     file.close()
  856.                     print()
  857.                     newButton( newID, 1, "Change" )
  858.                     newButton( newID, 2, "Done" )
  859.                 end
  860.                
  861.                 while true do
  862.                     settingMenu()
  863.                     local event, key = os.pullEvent("key")
  864.                     if key == keys.up then
  865.                         newID = 1
  866.                     elseif key == keys.down then
  867.                         newID = 2
  868.                     elseif key == keys.enter then
  869.                         if newID == 1 then
  870.                             term.setCursorPos(1,2)
  871.                             term.clearLine()
  872.                             write("rdnt://")
  873.                             local address = read()
  874.                             file = fs.open( ".rexsettings", "w" )
  875.                             file.write( address.. "\n" )
  876.                             file.write( currentTheme )
  877.                             file.close()
  878.                         else
  879.                             loadWebpage("settings")
  880.                         end
  881.                     end
  882.                 end
  883.             elseif currentID == 3 then
  884.                 loadWebpage( "extensions" )
  885.             elseif currentID == 5 then
  886.                 fs.delete( ".rexComponents" )
  887.                
  888.                 fs.makeDir( ".rexComponents" )
  889.                 fs.makeDir( ".rexComponents/Cookies" )
  890.                 fs.makeDir( ".rexComponents/Extensions" )
  891.                
  892.                 sHistory = {}
  893.                 syncHistory()
  894.             elseif currentID == 4 then
  895.                 if theme == "default" then
  896.                     theme = "old"
  897.                 elseif theme == "old" then
  898.                     theme = "edit"
  899.                 elseif theme == "edit" then
  900.                     theme = "default"
  901.                 end
  902.                
  903.                 file = fs.open( ".rexsettings", "r" )
  904.                 local humpage = file.readLine()
  905.                 file.close()
  906.                 file = fs.open( ".rexsettings", "w" )
  907.                 file.write( humpage.. "\n" )
  908.                 file.write( theme )
  909.                 file.close()
  910.                 loadWebpage( "settings" )
  911.             elseif currentID == 6 then
  912.                 break
  913.             end
  914.         end
  915.     end
  916.    
  917.     loadWebpage( "home" )
  918. end
  919.  
  920. local function newButton2( currentID, id, text )
  921.     term.clearLine()
  922.     if currentID == id then
  923.         print("[>] " ..text)
  924.     else
  925.         print("[ ] " ..text)
  926.     end
  927. end
  928.  
  929. function newServer( newURL )
  930.     if newURL == nil then
  931.         print("Welcome to Rednet Servers!")
  932.         print("Before we begin, please enter the URL of the website you want: ")
  933.         write("\nrdnt://")
  934.         newURL = read()
  935.         rednet.broadcast( newURL )
  936.         local id,message = rednet.receive( 0.5 )
  937.         if message then
  938.             print( "A website with this URL is already owned by " ..id.. ", continue? (Y/N)" )
  939.             if string.lower( read() ) ~= "y" then
  940.                 return
  941.             end
  942.         end
  943.     end
  944.    
  945.     function drawFooter()
  946.         term.clear()
  947.         term.setCursorPos(1,1)
  948.         write("Hosting rdnt://" ..newURL)
  949.         local x,y = term.getSize()
  950.         for i=1,x do
  951.             term.setCursorPos(i,2)
  952.             write("-")
  953.         end
  954.     end
  955.    
  956.     function drawBrowser()
  957.         term.setCursorPos(1,3)
  958.         if fs.exists( "." ..newURL ) and fs.isDir( "." ..newURL ) then
  959.             if fs.exists( "." ..newURL.. "/index" ) then
  960.             else
  961.                 file = fs.open( "." ..newURL.. "/index", "w" )
  962.                 file.write( "print(\"This site has not yet been configured.\")" )
  963.                 file.close()
  964.             end
  965.         else
  966.             fs.makeDir( "." ..newURL )
  967.             file = fs.open( "." ..newURL.. "/index", "w" )
  968.             file.write( "print(\"This site has not yet been configured.\")" )
  969.             file.close()
  970.         end
  971.        
  972.         local filePath = fs.list( "." ..newURL )
  973.         for i=1,#filePath do
  974.             newButton2( currentID, i, filePath[i] )
  975.         end
  976.     end
  977.    
  978.     local status = "[Delete]New Edit"
  979.     currentID = 1
  980.     while true do
  981.         drawFooter()
  982.         drawBrowser()
  983.         term.setCursorPos(1,y)
  984.         term.clearLine()
  985.         write(status)
  986.         local event, key, message = os.pullEvent()
  987.         if event == "rednet_message" then
  988.             if message == newURL then
  989.                 file = fs.open( "." ..newURL.. "/index", "r" )
  990.                 rednet.send( key, file.readAll() )
  991.                 file.close()
  992.             elseif fs.exists( "." ..message ) then
  993.                 file = fs.open( "." ..message, "r" )
  994.                 if file then
  995.                     rednet.send( key, file.readAll() )
  996.                     file.close()
  997.                 end
  998.             elseif message == "rednet.api.ping.searchengine" then
  999.                 rednet.send( key, newURL )
  1000.             end
  1001.         elseif event == "key" then
  1002.             if key == keys.left then
  1003.                 if status == " Delete[New]Edit" then
  1004.                     status = "[Delete]New Edit"
  1005.                 elseif status == " Delete New[Edit]" then
  1006.                     status = " Delete[New]Edit"
  1007.                 end
  1008.             elseif key == keys.right then
  1009.                 if status == " Delete[New]Edit" then
  1010.                     status = " Delete New[Edit]"
  1011.                 elseif status == "[Delete]New Edit" then
  1012.                     status = " Delete[New]Edit"
  1013.                 end
  1014.             elseif key == keys.up then
  1015.                 if currentID ~= 1 then
  1016.                     currentID = currentID -1
  1017.                 end
  1018.             elseif key == keys.down then
  1019.                 if currentID ~= #fs.list( "." ..newURL ) then
  1020.                     currentID = currentID +1
  1021.                 end
  1022.             elseif key == keys.enter then
  1023.                 if status == "[Delete]New Edit" then
  1024.                     local filePath = fs.list( "." ..newURL )
  1025.                     fs.delete( "." ..newURL.. "/" ..filePath[ currentID ] )
  1026.                     currentID = 1
  1027.                 elseif status == " Delete[New]Edit" then
  1028.                     term.setCursorPos(1,y)
  1029.                     term.clearLine()
  1030.                     write("URL: rdnt://" ..newURL.. "/")
  1031.                     local fileName = read()
  1032.                     local number = 1
  1033.                     local origName = fileName
  1034.                    
  1035.                     while fs.exists( "." ..newURL.. "/" ..fileName ) do
  1036.                         fileName = origName.. " [" ..number.. "]"
  1037.                         number = number +1
  1038.                     end
  1039.                    
  1040.                     file = fs.open( "." ..newURL.. "/" ..fileName, "w" )
  1041.                     file.close()
  1042.                 else
  1043.                     local filePath = fs.list( "." ..newURL )
  1044.                     shouldIendThis = false
  1045.                    
  1046.                     function a()
  1047.                         while true do
  1048.                             local timer = os.startTimer( 0.5 )
  1049.                             local event, key, message = os.pullEvent()
  1050.                             if event == "rednet_message" then
  1051.                                 if message == newURL then
  1052.                                     file = fs.open( "." ..newURL.. "/index", "r" )
  1053.                                     rednet.send( key, file.readAll() )
  1054.                                     file.close()
  1055.                                 elseif fs.exists( "." ..message ) then
  1056.                                     file = fs.open( "." ..message, "r" )
  1057.                                     if file then
  1058.                                         rednet.send( key, file.readAll() )
  1059.                                         file.close()
  1060.                                     end
  1061.                                 elseif message == "rednet.api.ping.searchengine" then
  1062.                                     rednet.send( key, newURL )
  1063.                                 end
  1064.                             elseif shouldIendThis then
  1065.                                 break
  1066.                             end
  1067.                         end
  1068.                     end
  1069.                    
  1070.                     function b()
  1071.                         shell.run( "edit", "." ..newURL.. "/" ..filePath[ currentID ] )
  1072.                         shouldIendThis = true
  1073.                     end
  1074.                    
  1075.                     parallel.waitForAny( a, b )
  1076.                     drawFooter()
  1077.                 end
  1078.             end
  1079.         end
  1080.     end
  1081. end
  1082.  
  1083. function loadWebpage( url, id )
  1084.     if term.isColor() then
  1085.         term.setTextColour( colors.white )
  1086.         term.setBackgroundColour( colors.black )
  1087.     end
  1088.    
  1089.     if not url then
  1090.         url = currentURL
  1091.     end
  1092.     currentURL = url
  1093.     tLinks = {}
  1094.     function newLink( text, link )
  1095.         if link == nil then
  1096.             link = text
  1097.         end
  1098.         local xx, yy = term.getCursorPos()
  1099.         if term.isColor() then
  1100.             term.setTextColour( colors.lightBlue )
  1101.         end
  1102.         write( text )
  1103.         if term.isColor() then
  1104.             term.setTextColour( colors.white )
  1105.         end
  1106.         local xxx, yyy = term.getCursorPos()
  1107.         tLinks[ #tLinks+1 ] = {
  1108.             ["Text"] = text,
  1109.             ["To"] = link,
  1110.             ["X"] = xx,
  1111.             ["Y"] = yy,
  1112.             ["eX"] = xxx,
  1113.             ["eY"] = yyy,
  1114.         }
  1115.        
  1116.         return
  1117.     end
  1118.    
  1119.     function cLink( text, link, yPos )
  1120.         x2,y2 = term.getCursorPos()
  1121.         if yPos ~= nil then
  1122.             y2 = yPos
  1123.         end
  1124.         if link == nil then
  1125.             link = text
  1126.         elseif type(link) == "number" then
  1127.             yPos = link
  1128.             link = text
  1129.         end
  1130.         term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  1131.        
  1132.         newLink( text, link )
  1133.         print()
  1134.     end
  1135.    
  1136.     local function cookiePath()
  1137.         local endd = #url
  1138.        
  1139.         if string.find( url, "/" ) then
  1140.             endd = string.find( url, "/" ) -1
  1141.         end
  1142.        
  1143.         return ".rexComponents/Cookies/" ..string.sub( url, endd )
  1144.     end
  1145.    
  1146.     oldFSOpen = fs.open
  1147.     oldFSMove = fs.move
  1148.     oldFSDelete = fs.delete
  1149.    
  1150.     function nCookie( name, value )
  1151.         local coPath = cookiePath()
  1152.         fs.makeDir( coPath )
  1153.        
  1154.         if name and value then
  1155.             fs.delete( coPath.. "/" ..name )
  1156.        
  1157.             file = oldFSOpen( coPath.. "/" ..name, "w" )
  1158.             file.write( textutils.serialize( value ) )
  1159.             file.close()
  1160.            
  1161.             return true
  1162.         end
  1163.         return false
  1164.     end
  1165.    
  1166.     function cookies()
  1167.         local coPath = cookiePath()
  1168.         fs.makeDir( coPath )
  1169.         local lists = fs.list( coPath )
  1170.         local sCookies = {}
  1171.        
  1172.         for i=1,#lists do
  1173.             file = oldFSOpen( coPath.. "/" ..lists[i], "r" )
  1174.             sCookies[ lists[i] ] = textutils.unserialize( file.readAll() )
  1175.             file.close()
  1176.         end
  1177.        
  1178.         return sCookies
  1179.     end
  1180.    
  1181.     fs.open = function( path, _type )
  1182.         if string.find( path, ".rexComponents" ) then
  1183.             fs.delete( ".rexComponents/.failedToOpen" )
  1184.             file = oldFSOpen( ".rexComponents/.failedToOpen", "w" )
  1185.             file.write( "Blocked" )
  1186.             file.close()
  1187.            
  1188.             return oldFSOpen( ".rexComponents/.failedToOpen", _type )
  1189.         end
  1190.        
  1191.         return oldFSOpen( path, _type )
  1192.     end
  1193.    
  1194.     fs.move = function( path, tpath )
  1195.         if string.find( path, ".rexComponents" ) then
  1196.             return false
  1197.         end
  1198.    
  1199.         return oldFSMove( path, tpath )
  1200.     end
  1201.    
  1202.     fs.delete = function( path )
  1203.         if string.find( path, ".rexComponents" ) then
  1204.             return false
  1205.         end
  1206.    
  1207.         return oldFSDelete( path )
  1208.     end
  1209.    
  1210.     term.clear()
  1211.     term.setCursorPos(1,1)
  1212.    
  1213.     if theme == "default" then
  1214.         if rednetType == "HTTP" then
  1215.             print("http://" ..currentURL)
  1216.         elseif rednetType == "rnet" then
  1217.             print("rnet://" ..currentURL)
  1218.         else
  1219.             print("rdnt://" ..currentURL)
  1220.         end
  1221.        
  1222.         for i=1,x do
  1223.             term.setCursorPos(i,2)
  1224.             write("-")
  1225.         end
  1226.         term.setCursorPos(1,3)
  1227.     elseif theme == "old" then
  1228.         cPrint("Rednet Explorer")
  1229.         if rednetType == "HTTP" then
  1230.             cPrint("http://" ..currentURL )
  1231.         elseif rednetType == "rnet" then
  1232.             cPrint("rnet://" ..currentURL )
  1233.         else
  1234.             cPrint("rdnt://" ..currentURL)
  1235.         end
  1236.         term.setCursorPos(1,4)
  1237.     elseif theme == "edit" then
  1238.         term.setCursorPos(1,y)
  1239.         write("Press CTRL to access menu")
  1240.     end
  1241.    
  1242.     local function executeP( path )
  1243.         shell.run( path )
  1244.     end
  1245.        
  1246.     if url == "home" then
  1247.         homePage()
  1248.     elseif url == "newsite" then
  1249.         if rednetType == "rnet" then
  1250.             rnetHost()
  1251.         else
  1252.             newServer()
  1253.         end
  1254.     elseif url == "settings" then
  1255.         settings()
  1256.     elseif url == "exit" then
  1257.         error()
  1258.     elseif url == "news" then
  1259.         newsPage()
  1260.     elseif url == "news/1-protocal" then
  1261.         sneakPeek()
  1262.     elseif url == "search" then
  1263.         loadWebpage( "nexus/search" )
  1264.     elseif userSites[ url ] then
  1265.         fs.delete( ".downloadedWebsite" )
  1266.         webpage = fs.open( ".downloadedWebsite", "w" )
  1267.         webpage.write( userSites[ url ] )
  1268.         webpage.close()
  1269.         executeP( ".downloadedWebsite" )
  1270.     else
  1271.         if rednetType == "HTTP" then
  1272.             http.request( "http://" ..url )
  1273.             readTimedOut = os.startTimer(3)
  1274.             local text = ""
  1275.             while true do
  1276.                 local event, body, url = os.pullEvent()
  1277.                 if event == "http_success" then
  1278.                     text = url.readAll()
  1279.                     break
  1280.                 elseif event == "http_failed" then
  1281.                     text = "Failed to load"
  1282.                     break
  1283.                 elseif event == "timer" and body == readTimedOut then
  1284.                     text = "Read timed out"
  1285.                     break
  1286.                 end
  1287.             end
  1288.            
  1289.             print( text )
  1290.         elseif rednetType == "rnet" then
  1291.             local response = http.post(
  1292.             ApiPath,
  1293.             "user=guest&"..
  1294.             "pass=guest&"..
  1295.             "type=download&"..
  1296.             "data=blank&"..
  1297.             "name=".. textutils.urlEncode(url)
  1298.             )
  1299.                
  1300.             if response then
  1301.                 local body = response.readAll()
  1302.                 response.close()
  1303.                 if body == nil or body == "" or string.find(body, "auth_error") or string.find(body, "file_not_found") then
  1304.                     print("Unable to load webpage.")
  1305.                     print("\nThe website you have requested was unable to work. If you beleive this is a error please contact your rednet service providers. (RSP)")
  1306.                     print("\nThis may be the result of the list below: ")
  1307.                     print("1) The site you requested is down.")
  1308.                     print("2) The site you requested is corrupted.")
  1309.                     print("3) The site you requested forgot to put a modem")
  1310.                     print("4) You have no modem")
  1311.                     print("5) This message is faked, and you have a virus now.")
  1312.                 else
  1313.                     fs.delete(".downloadedWebsite")
  1314.                     webpage = fs.open(".downloadedWebsite", "w")
  1315.                     webpage.write(body)
  1316.                     webpage.close()
  1317.                     executeP(".downloadedWebsite")
  1318.                 end
  1319.             end
  1320.         else
  1321.            
  1322.             if id then
  1323.                 fs.delete(".downloadedWebsite")
  1324.                 file = fs.open(".downloadedWebsite", "w")
  1325.                 file.write( id )
  1326.                 file.close()
  1327.                 executeP(".downloadedWebsite")
  1328.             else
  1329.                 if hasModem then
  1330.                     if id then
  1331.                         rednet.send( id, url )
  1332.                     else
  1333.                         rednet.broadcast( url )
  1334.                     end
  1335.                    
  1336.                     local timer = os.startTimer(0)
  1337.                     local messages = {}
  1338.                     repeat
  1339.                         local event, key, message = os.pullEvent()
  1340.                         if event == "rednet_message" then
  1341.                             if id then
  1342.                                 if key == id then
  1343.                                     messages[#messages+1] = {
  1344.                                         ["id"] = key,
  1345.                                         ["code"] = message,
  1346.                                     }
  1347.                                 end
  1348.                             else
  1349.                                 messages[#messages+1] = {
  1350.                                     ["id"] = key,
  1351.                                     ["code"] = message,
  1352.                                 }
  1353.                             end
  1354.                         end
  1355.                     until event == "timer" and key == timer
  1356.                    
  1357.                     if #messages == 1 then
  1358.                         fs.delete(".downloadedWebsite")
  1359.                         file = fs.open(".downloadedWebsite", "w")
  1360.                         file.write( messages[1]["code"] )
  1361.                         file.close()
  1362.                         executeP(".downloadedWebsite")
  1363.                     elseif #messages == 0 then
  1364.                         print("Unable to load webpage.")
  1365.                         print("\nThe website you have requested was unable to work. If you beleive this is a error please contact your rednet service providers. (RSP)")
  1366.                         print("\nThis may be the result of the list below: ")
  1367.                         print("1) The site you requested is down.")
  1368.                         print("2) The site you requested is corrupted.")
  1369.                         print("3) The site you requested forgot to put a modem")
  1370.                         print("4) You have no modem")
  1371.                         print("5) This message is faked, and you have a virus now.")
  1372.                     else
  1373.                         local id = 0
  1374.                         local valvez = true
  1375.                         id = messages[1]["id"]
  1376.                         for i=2,#messages do
  1377.                             if messages[i]["id"] ~= id then
  1378.                                 valvez = false
  1379.                             end
  1380.                         end
  1381.                        
  1382.                         if valvez then
  1383.                             fs.delete(".downloadedWebsite")
  1384.                             file = fs.open(".downloadedWebsite", "w")
  1385.                             file.write( messages[1]["code"] )
  1386.                             file.close()
  1387.                             executeP(".downloadedWebsite")
  1388.                         else
  1389.                             local x1, y1 = term.getCursorPos()
  1390.                             local currentID = 1
  1391.                             while true do
  1392.                                 term.setCursorPos(1,y1)
  1393.                                 cPrint("+---Conflict Warning---+")
  1394.                                 cPrint("| 2 or more hosts have |")
  1395.                                 cPrint("| been found, please   |")
  1396.                                 cPrint("| select the correct ID|")
  1397.                                 cPrint("+----------------------+")
  1398.                                 for i=1,#messages do
  1399.                                     local xx, yy = term.getCursorPos()
  1400.                                     cPrint("|                      |")
  1401.                                     term.setCursorPos(xx, yy)
  1402.                                     newButton( currentID, i, "#" ..messages[i]["id"], true )
  1403.                                 end
  1404.                                
  1405.                                 cPrint("+----------------------+")
  1406.                                
  1407.                                 local event, key = os.pullEvent("key")
  1408.                                 if key == keys.up then
  1409.                                     if currentID ~= 1 then
  1410.                                         currentID = currentID -1
  1411.                                     end
  1412.                                 elseif key == keys.down then
  1413.                                     if currentID ~= #messages then
  1414.                                         currentID = currentID +1
  1415.                                     end
  1416.                                 elseif key == keys.enter then
  1417.                                     local code = messages[currentID]["code"]
  1418.                                     loadWebpage( url, code )
  1419.                                     break
  1420.                                 end
  1421.                             end
  1422.                         end
  1423.                     end
  1424.                 else
  1425.                     print("\nUnable to connect because no modem has been detected on your computer. Please attatch a modem and restart this program. ")
  1426.                 end
  1427.             end
  1428.         end
  1429.     end
  1430.    
  1431.     if term.isColor() then
  1432.         term.setTextColour( colors.white )
  1433.         term.setBackgroundColour( colors.black )
  1434.     end
  1435.    
  1436.     if theme == "default" then
  1437.         term.setCursorPos(x-#("Press CTRL to brows"), 1)
  1438.         write("Press CTRL to browse")
  1439.     elseif theme == "old" then
  1440.         term.setCursorPos(x-#("Press CTRL to explor"), y)
  1441.         write("Press CTRL to explore")
  1442.     end
  1443.    
  1444.     while true do
  1445.         local event, key, mX, mY = os.pullEvent()
  1446.         if event == "key" then
  1447.             if key == 29 or key == 157 then
  1448.                 break
  1449.             elseif key == 63 then
  1450.                 loadWebpage( url, id )
  1451.             end
  1452.         elseif event == "mouse_click" then
  1453.             if key == 1 then
  1454.                 for i=1,#tLinks do
  1455.                     local link = tLinks[i]
  1456.                     if mY == link["Y"] then
  1457.                         if mX >= link["X"] and mX <= link["eX"] then
  1458.                             loadWebpage( link["To"] )
  1459.                         end
  1460.                     end
  1461.                 end
  1462.             end
  1463.         end
  1464.     end
  1465.    
  1466.     if theme == "default" then
  1467.         term.setCursorPos(1,1)
  1468.         term.clearLine()
  1469.        
  1470.         if rednetType == "HTTP" then
  1471.             write("http://")
  1472.         elseif rednetType == "rnet" then
  1473.             write("rnet://")
  1474.         else
  1475.             write("rdnt://")
  1476.         end
  1477.     elseif theme == "old" or theme == "edit" then
  1478.         term.setCursorPos(1,2)
  1479.         term.clearLine()
  1480.        
  1481.         if rednetType == "HTTP" then
  1482.             write("http://")
  1483.         elseif rednetType == "rnet" then
  1484.             write("rnet://")
  1485.         else
  1486.             write("rdnt://")
  1487.         end
  1488.     end
  1489.    
  1490.     fs.open = oldFSOpen
  1491.     fs.move = oldFSMove
  1492.     fs.delete = oldFSDelete
  1493.    
  1494.     local sText = read( nil, sHistory )
  1495.     if sHistory[1] == "secret" and #sHistory == 1 then
  1496.         sHistory[1] = sText
  1497.     else
  1498.         table.insert( sHistory, sText )
  1499.         syncHistory()
  1500.     end
  1501.    
  1502.     loadWebpage( sText )
  1503. end
  1504.  
  1505. local function openModems()
  1506.     for i,v in pairs( rs.getSides() ) do
  1507.         if rednet.open( v ) then
  1508.             return true
  1509.         end
  1510.     end
  1511. end
  1512.  
  1513. openModems()
  1514.  
  1515. if fs.exists(".rexsettings") then
  1516.     file = fs.open(".rexsettings", "r")
  1517.     currentURL = file.readLine()
  1518.     theme = file.readLine()
  1519.     file.close()
  1520. else
  1521.     file = fs.open(".rexsettings", "w")
  1522.     file.write( "home\n" )
  1523.     file.write( "default" )
  1524.     file.close()
  1525. end
  1526.  
  1527. ---API/Compatibility---
  1528. centerPrint = cPrint
  1529. reDirect = loadWebpage
  1530. loadPage = loadWebpage
  1531. ---API/Compatibility---
  1532.  
  1533. --tArgs: rex server <name>
  1534. if tArgs[1] == "server" then
  1535.     if tArgs[2] then
  1536.         newServer( tArgs[2] )
  1537.     else
  1538.         print("Usage: rex server <name>")
  1539.         return
  1540.     end
  1541. end
  1542.  
  1543. fs.delete( ".temporarilyUpdatingFileChecker" )
  1544. file = fs.open( ".temporarilyUpdatingFileChecker", "w" )
  1545. file.write( http.get( autoUpdater ).readAll() )
  1546. file.close()
  1547.  
  1548. file = fs.open( ".temporarilyUpdatingFileChecker", "r" )
  1549. local newestVersion = file.readLine()
  1550. local desc = file.readLine()
  1551. file.close()
  1552.  
  1553. if newestVersion ~= vserin then
  1554.     term.clear()
  1555.     term.setCursorPos(1,1)
  1556.     print("rdnt://update")
  1557.     for i=1,x do
  1558.         term.setCursorPos(i,2)
  1559.         write("-")
  1560.     end
  1561.     print()
  1562.     cPrint("__________ _______________  ___")
  1563.     cPrint("\\______   \\\\_   _____/\\   \\/  /")
  1564.     cPrint(" |       _/ |    __)_  \\     / ")
  1565.     cPrint(" |    |   \\ |        \\ /     \\ ")
  1566.     cPrint(" |____|_  //_______  //___/\\  \\")
  1567.     cPrint("        \\/         \\/       \\_/")
  1568.     cPrint("(!!) New Update Available (!!)")
  1569.     print()
  1570.     cPrint("Changelog")
  1571.     cPrint("+-------+")
  1572.     cPrint( desc )
  1573.     cPrint("+-------+")
  1574.     print()
  1575.     cPrint("Update?")
  1576.     local x2,y2 = term.getCursorPos()
  1577.     local selection = 1
  1578.     while true do
  1579.         term.setCursorPos( x2, y2 )
  1580.         term.clearLine()
  1581.         if selection == 1 then
  1582.             cPrint("[ Yes ] No  ")
  1583.         else
  1584.             cPrint("  Yes [ No ]")
  1585.         end
  1586.         local event, key = os.pullEvent("key")
  1587.         if key == keys.left then
  1588.             selection = 1
  1589.         elseif key == keys.right then
  1590.             selection = 9001
  1591.         elseif key == keys.enter then
  1592.             break
  1593.         end
  1594.     end
  1595.    
  1596.     if selection == 1 then
  1597.         cPrint("Updating...")
  1598.         local sPath = shell.getRunningProgram()
  1599.         if fs.isReadOnly( sPath ) then
  1600.             cPrint("Failed...")
  1601.             sleep(1)
  1602.         else
  1603.             fs.delete( sPath )
  1604.             shell.run( "pastebin", "get", "FwhQMq8v", sPath )
  1605.             term.clear()
  1606.             term.setCursorPos(1,1)
  1607.             print("rdnt://exit")
  1608.             for i=1,x do
  1609.                 term.setCursorPos(i,2)
  1610.                 write("-")
  1611.             end
  1612.             cPrint("Updated! Browser restarted")
  1613.             error()
  1614.         end
  1615.     end
  1616. end
  1617.  
  1618. loadWebpage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement