Advertisement
xXm0dzXx

Rednet Explorer 3.1 Beta

Aug 4th, 2012
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.20 KB | None | 0 0
  1. -----------------------------------
  2. --Welcome to Rednet Explorer 3.1!--
  3. -----------------------------------
  4. --Made by ComputerCraftFan11 (IGN: xXm0dzXx)
  5. --Please don't steal this without giving credits.
  6. --To change the database of the sites you are connecting to, edit this:
  7. local WebsiteDatabase = "http://nexusindustries.x10.mx/Websites/folder/" --Folder with all the sites
  8. local ApiPath = "http://nexusindustries.x10.mx/Websites/mcmain.php" --Path API is stored
  9. --All sites will be downloaded from there.
  10. --Default: "http://nexusindustries.x10.mx/Websites/folder/"
  11. --Change to "http://" to just browse the internet
  12. --API path is used for downloading and uploading files. Change it to the path of your API
  13.  
  14. local autoUpdater = true;
  15. local updaterPath = "http://pastebin.com/1EAc6tFd"; --COMING SOON
  16.  
  17. --If you are making a custom version of this browser, edit this variable for browser compatibility
  18. browserAgent = "rednetexplorer3.0"
  19.  
  20. local x,y = term.getSize()
  21. local language = 1 --1 = LUA
  22. local EditingValue = "";
  23.  
  24. function rednetV()
  25.     return "3.1"
  26. end
  27.  
  28. title = "Rednet Explorer " ..rednetV() --Add title = "name" to change the webpage's title!
  29. local website = "home";
  30. if fs.exists(".cache") then fs.delete(".cache") end
  31. if fs.exists(".websiteedited") then fs.delete(".websiteedited") end
  32. fs.makeDir(".cache")
  33.  
  34. function displayError()
  35.     print("Unable to connect.")
  36.     print("\n1) The requested site may be down or doesn't exist.")
  37.     print("2) You mistyped the website URL.")
  38.     print("3) A database admin may have deleted the requested site.")
  39.     print("4) A server admin may have blocked this website (Only if you are on multiplayer)")
  40.     print("5) The database might be down.")
  41.     print("6) The requested site may have faked this message and secretly gave you a virus.")
  42. end
  43.  
  44. local cPrint = function(text)
  45.     local x2,y2 = term.getCursorPos()
  46.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  47.    
  48.     print(text)
  49. end
  50.  
  51. function reDirect(url)
  52.     website = url
  53.     loadWebpage()
  54. end
  55.  
  56. function createSite()
  57.     term.clear()
  58.     term.setCursorPos(1,1)
  59.     cPrint("Rednet Explorer Online Servers")
  60.     write("Domain (ex: YourDomain.com): rdnt://")
  61.     domain = read()
  62.     write("Path to file: ")
  63.     path = read()
  64.     if fs.exists(path) then
  65.         file = fs.open(path, "r")
  66.         if file then
  67.             data = file.readAll()
  68.             file.close()
  69.             if not data then
  70.                 print("Failed to read " ..path)
  71.                 return
  72.             end
  73.             local response = http.post(
  74.             ApiPath,
  75.             "type=upload&"..
  76.             "user=guest&"..
  77.             "pass=guest&"..
  78.             "name=".. textutils.urlEncode(domain) .. "&"..
  79.             "data=" ..textutils.urlEncode(data)
  80.             )
  81.                        
  82.             if response then
  83.                 local sResponse = response.readAll()
  84.                 response.close()
  85.                 print("Done!")
  86.                 print("Log: ")
  87.                 sleep(0.5)
  88.                 if string.find(sResponse, "success") then
  89.                     print("Uploading " ..shell.resolve(path).. " complete!")
  90.                     print("Errors: 0")
  91.                     print("\nGo to " ..domain.. " to check the site!")
  92.                 else
  93.                     print("Failed : " ..sResponse)
  94.                     print()
  95.                     if sResponse == "Write_lock" then
  96.                         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.")
  97.                     end
  98.                 end
  99.             else
  100.                 print("Failed to connect to database.")
  101.             end
  102.         else
  103.             print("Failed to open " ..path)
  104.         end
  105.     else
  106.         print(path.. " doesn't exist.")
  107.     end
  108. end
  109.  
  110. local Address = function()
  111.     if WebsiteDatabase == "http://" then
  112.         text = "http://"
  113.     else
  114.         text = "rdnt://"
  115.     end
  116.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), 2)
  117.     term.clearLine()
  118.    
  119.     write(text)
  120.     website = read()
  121.     loadWebpage()
  122. end
  123.  
  124. function done()
  125.     term.setCursorPos(1, y)
  126.     name = "F5 = Refresh"
  127.     write("Press CTRL to travel the web! :D")
  128.     term.setCursorPos(x - name:len(), y)
  129.     write(name)
  130.    
  131.     while true do
  132.         sleep(0) -- stop crashing
  133.         e, k = os.pullEvent("key")
  134.         if k == 63 then
  135.             loadWebpage()
  136.             break
  137.         elseif k == 29 then
  138.             Address()
  139.             break
  140.         end
  141.     end
  142. end
  143.    
  144.  
  145. loadWebpage = function()
  146.     term.clear()
  147.     term.setCursorPos(1,1)
  148.     cPrint(title)
  149.     if WebsiteDatabase == "http://" then
  150.         cPrint("http://" ..website.. "\n")
  151.     else
  152.         cPrint("rdnt://" ..website.. "\n")
  153.     end
  154.    
  155.     if website == "home" then
  156.         print("Welcome to RedNet explorer (3.0)! This requires you to HTTP enabled.")
  157.         print("Host a website at:                ")
  158.         print("rdnt://newsite!            ")
  159.         print("Edit settings at:")
  160.         print("rdnt://settings")
  161.         print("   -ComputerCraftFan11    ")
  162.     elseif website == "newsite" then
  163.         createSite()
  164.     elseif website == "settings" then --COMING SOON
  165.         selection = 1
  166.         function lzy(aa, bb)
  167.             term.setCursorPos(1,bb + 1)
  168.             if aa == selection then
  169.                 cPrint("[ " ..bb.. " ]")
  170.             else
  171.                 cPrint(bb)
  172.             end
  173.         end
  174.        
  175.         while true do
  176.             term.clear()
  177.             term.setCursorPos(1,1)
  178.             cPrint("RedNet Explorer Settings")
  179.             local event, key = os.pullEvent("key")
  180.             if key == 208 then
  181.                 selection = selection +1
  182.                 if selection == 5 then selection = 4 end
  183.             elseif key == 200 then
  184.                 selection = selection -1
  185.                 if selection == -1 then selection = 1 end
  186.             elseif key == 28 then
  187.                 print("Coming Soon!")
  188.                 break
  189.             end
  190.            
  191.             lzy(1, "Edit Homepage")
  192.             lzy(2, "Edit Execution Settings")
  193.             lzy(3, "Edit Database Settings")
  194.             lzy(4, "Exit")
  195.            
  196.             --Options:
  197.             --Homepage: rdnt://home
  198.             --Execution Settings:
  199.             --  Lua (Default) (.lua)
  200.             --  Batch (BETA) (.bat)
  201.             --  HTML (BETA) (.html)
  202.             --  Text Document (.txt)
  203.             --Database Settings:
  204.             --  Edit Whitelist
  205.             --  Edit Blacklist
  206.             --  Edit Database folder:
  207.             --  Edit Database path:
  208.         end
  209.     else
  210.         title = "Rednet Explorer " ..rednetV()
  211.         rednet.broadcast(website)
  212.         print("Connecting...")
  213.         website1 = "Rednet_Explorer_RequestedSite"
  214.        
  215.         if WebsiteDatabase == "http://" then
  216.             while true do
  217.                 http.request(WebsiteDatabase..website)
  218.                 timer = os.startTimer(5)
  219.                 local event, body, url = os.pullEvent()
  220.                 if event == "http_success" then
  221.                     if language == 1 then
  222.                         if fs.exists(".cache/" ..website1) then fs.delete(".cache/" ..website1) end
  223.                         webpage = fs.open(".cache/" ..website1, "w")
  224.                         webpage.write(body.readAll())
  225.                         webpage.close()
  226.                         term.clear()
  227.                         term.setCursorPos(1,1)
  228.                         cPrint(title)
  229.                         if WebsiteDatabase == "http://" then
  230.                             cPrint("http://" ..website.. "\n")
  231.                         else
  232.                             cPrint("rdnt://" ..website.. "\n")
  233.                         end
  234.                         shell.run(".cache/" ..website1)
  235.                         break
  236.                     end
  237.                 elseif event == "http_failed" then
  238.                     displayError()
  239.                 elseif event == "timer" and body == timer then
  240.                     print("Failed to connect:")
  241.                     print("* Read timed out.")
  242.                 end
  243.             end
  244.         else
  245.             local response = http.post(
  246.             ApiPath,
  247.             "user=guest&"..
  248.             "pass=guest&"..
  249.             "type=download&"..
  250.             "data=blank&"..
  251.             "name=".. textutils.urlEncode(website)
  252.             )
  253.                
  254.             if response then
  255.                 local body = response.readAll()
  256.                 response.close()
  257.                 if body == nil or body == "" or string.find(body, "auth_error") or string.find(body, "file_not_found") then
  258.                     displayError()
  259.                 else
  260.                     if language == 1 then
  261.                         if fs.exists(".cache/" ..website1) then fs.delete(".cache/" ..website1) end
  262.                         webpage = fs.open(".cache/" ..website1, "w")
  263.                         webpage.write(body)
  264.                         webpage.close()
  265.                         term.clear()
  266.                         term.setCursorPos(1,1)
  267.                         cPrint(title)
  268.                         if WebsiteDatabase == "http://" then
  269.                             cPrint("http://" ..website.. "\n")
  270.                         else
  271.                             cPrint("rdnt://" ..website.. "\n")
  272.                         end
  273.                         if string.sub(body, 1, string.len("--%warn%")) == "--%warn%" then
  274.                             print("Warning, you are about to enter a malicous site.")
  275.                             print("Would you like to continue? (Y/N) ")
  276.                             while true do
  277.                                 input = read()
  278.                                 if input == "Y" then
  279.                                     shell.run(".cache/" ..website1)
  280.                                 elseif input == "N" then
  281.                                     print("Aborted.")
  282.                                     break
  283.                                 else
  284.                                     print("Unknown input... exiting.")
  285.                                     break
  286.                                 end
  287.                             end
  288.                         else
  289.                             shell.run(".cache/" ..website1)
  290.                         end
  291.                     end
  292.                 end
  293.             else
  294.                 displayError()
  295.             end
  296.         end
  297.     end
  298.    
  299.     done()
  300. end
  301.  
  302. loadWebpage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement