Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x,y = term.getSize()
- local currentURL = "home"
- local hasModem = true
- local theme = "default"
- local rednetType = "Rednet"
- browserAgent = "rex_renewed"
- local WebsiteDatabase = "http://nexusindustries.x10.mx/Websites/folder/" --Folder with all the sites
- local ApiPath = "http://nexusindustries.x10.mx/Websites/mcmain.php" --Path API is stored
- local function cPrint(text)
- x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- write(text.. "\n")
- end
- local function homePage()
- cPrint("__________ _______________ ___")
- cPrint("\\______ \\\\_ _____/\\ \\/ /")
- cPrint(" | _/ | __)_ \\ / ")
- cPrint(" | | \\ | \\ / \\ ")
- cPrint(" |____|_ //_______ //___/\\ \\")
- cPrint(" \\/ \\/ \\_/")
- cPrint("~~=> Renewed <=~~")
- print()
- cPrint("Default sites: ")
- cPrint("rdnt://home Default Homepage")
- cPrint("rdnt://settings Settings ")
- cPrint("rdnt://newsite Website Maker ")
- print()
- cPrint("rdnt://exit")
- cPrint("Check out")
- cPrint("play.geevancraft.com")
- end
- function rnetHost()
- term.clear()
- term.setCursorPos(1,1)
- cPrint("Rednet Explorer Online Servers")
- write("Domain (ex: YourDomain.com): rnet://")
- domain = read()
- write("Path to file: ")
- path = read()
- if fs.exists(path) then
- file = fs.open(path, "r")
- if file then
- data = file.readAll()
- file.close()
- if not data then
- print("Failed to read " ..path)
- return
- end
- local response = http.post(
- ApiPath,
- "type=upload&"..
- "user=guest&"..
- "pass=guest&"..
- "name=".. textutils.urlEncode(domain) .. "&"..
- "data=" ..textutils.urlEncode(data)
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- print("Done!")
- print("Log: ")
- sleep(0.5)
- if string.find(sResponse, "success") then
- print("Uploading " ..shell.resolve(path).. " complete!")
- print("Errors: 0")
- print("\nGo to " ..domain.. " to check the site!")
- else
- print("Failed : " ..sResponse)
- print()
- if sResponse == "Write_lock" then
- 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.")
- end
- end
- else
- print("Failed to connect to database.")
- end
- else
- print("Failed to open " ..path)
- end
- else
- print(path.. " doesn't exist.")
- end
- end
- local function newButton( currentID, id, text, fez )
- if not fez then
- term.clearLine()
- end
- if currentID == id then
- cPrint("[ " ..text.. " ]")
- else
- cPrint(text)
- end
- end
- local function settings()
- local currentID = 1
- local function settingMenu()
- term.setCursorPos(1,5)
- cPrint("Configuration")
- print()
- newButton( currentID, 1, "Download Settings (" ..rednetType.. ")" )
- newButton( currentID, 2, "Homepage" )
- newButton( currentID, 3, "Extensions (NYI)" )
- newButton( currentID, 4, "Theme (" ..theme.. ")" )
- print()
- newButton( currentID, 5, "Exit" )
- end
- while true do
- settingMenu()
- local event, key = os.pullEvent("key")
- if key == keys.up then
- if currentID ~= 1 then
- currentID = currentID -1
- end
- elseif key == keys.down then
- if currentID ~= 5 then
- currentID = currentID +1
- end
- elseif key == keys.enter then
- if currentID == 1 then
- if rednetType == "Rednet" then
- rednetType = "HTTP"
- elseif rednetType == "HTTP" then
- rednetType = "rnet"
- elseif rednetType == "rnet" then
- rednetType = "Rednet"
- end
- loadWebpage( "settings" )
- elseif currentID == 2 then
- local newID = 1
- local currentTheme = ""
- local function settingMenu()
- term.clear()
- term.setCursorPos(1,1)
- cPrint("Homepage")
- file = fs.open( ".rexsettings", "r" )
- cPrint( "rdnt://" ..file.readLine() )
- currentTheme = file.readLine()
- file.close()
- print()
- newButton( newID, 1, "Change" )
- newButton( newID, 2, "Done" )
- end
- while true do
- settingMenu()
- local event, key = os.pullEvent("key")
- if key == keys.up then
- newID = 1
- elseif key == keys.down then
- newID = 2
- elseif key == keys.enter then
- if newID == 1 then
- term.setCursorPos(1,2)
- term.clearLine()
- write("rdnt://")
- local address = read()
- file = fs.open( ".rexsettings", "w" )
- file.write( address.. "\n" )
- file.write( currentTheme )
- file.close()
- else
- loadWebpage("settings")
- end
- end
- end
- elseif currentID == 3 then
- elseif currentID == 4 then
- if theme == "default" then
- theme = "old"
- elseif theme == "old" then
- theme = "edit"
- elseif theme == "edit" then
- theme = "default"
- end
- file = fs.open( ".rexsettings", "r" )
- local humpage = file.readLine()
- file.close()
- file = fs.open( ".rexsettings", "w" )
- file.write( humpage.. "\n" )
- file.write( theme )
- file.close()
- loadWebpage( "settings" )
- elseif currentID == 5 then
- break
- end
- end
- end
- loadWebpage( "home" )
- end
- local function newButton2( currentID, id, text )
- term.clearLine()
- if currentID == id then
- print("[>] " ..text)
- else
- print("[ ] " ..text)
- end
- end
- function newServer()
- print("Welcome to Rednet Servers!")
- print("Before we begin, please enter the URL of the website you want: ")
- write("\nrdnt://")
- newURL = read()
- rednet.broadcast( newURL )
- local id,message = rednet.receive( 0.5 )
- if message then
- print( "A website with this URL is already owned by " ..id.. ", continue? (Y/N)" )
- if string.lower( read() ) ~= "y" then
- return
- end
- end
- function drawFooter()
- term.clear()
- term.setCursorPos(1,1)
- write("Hosting rdnt://" ..newURL)
- local x,y = term.getSize()
- for i=1,x do
- term.setCursorPos(i,2)
- write("-")
- end
- end
- function drawBrowser()
- term.setCursorPos(1,3)
- if fs.exists( "." ..newURL ) and fs.isDir( "." ..newURL ) then
- if fs.exists( "." ..newURL.. "/index" ) then
- else
- file = fs.open( "." ..newURL.. "/index", "w" )
- file.write( "print(\"This site has not yet been configured.\")" )
- file.close()
- end
- else
- fs.makeDir( "." ..newURL )
- file = fs.open( "." ..newURL.. "/index", "w" )
- file.write( "print(\"This site has not yet been configured.\")" )
- file.close()
- end
- local filePath = fs.list( "." ..newURL )
- for i=1,#filePath do
- newButton2( currentID, i, filePath[i] )
- end
- end
- local status = "[Delete]New Edit"
- currentID = 1
- while true do
- drawFooter()
- drawBrowser()
- term.setCursorPos(1,y)
- term.clearLine()
- write(status)
- local event, key, message = os.pullEvent()
- if event == "rednet_message" then
- if message == newURL then
- file = fs.open( "." ..newURL.. "/index", "r" )
- rednet.send( key, file.readAll() )
- file.close()
- elseif fs.exists( "." ..message ) then
- file = fs.open( "." ..message, "r" )
- if file then
- rednet.send( key, file.readAll() )
- file.close()
- end
- end
- elseif event == "key" then
- if key == keys.left then
- if status == " Delete[New]Edit" then
- status = "[Delete]New Edit"
- elseif status == " Delete New[Edit]" then
- status = " Delete[New]Edit"
- end
- elseif key == keys.right then
- if status == " Delete[New]Edit" then
- status = " Delete New[Edit]"
- elseif status == "[Delete]New Edit" then
- status = " Delete[New]Edit"
- end
- elseif key == keys.up then
- if currentID ~= 1 then
- currentID = currentID -1
- end
- elseif key == keys.down then
- if currentID ~= #fs.list( "." ..newURL ) then
- currentID = currentID +1
- end
- elseif key == keys.enter then
- if status == "[Delete]New Edit" then
- local filePath = fs.list( "." ..newURL )
- fs.delete( "." ..newURL.. "/" ..filePath[ currentID ] )
- currentID = 1
- elseif status == " Delete[New]Edit" then
- term.setCursorPos(1,y)
- term.clearLine()
- write("URL: rdnt://" ..newURL.. "/")
- local fileName = read()
- local number = 1
- local origName = fileName
- while fs.exists( "." ..newURL.. "/" ..fileName ) do
- fileName = origName.. " [" ..number.. "]"
- number = number +1
- end
- file = fs.open( "." ..newURL.. "/" ..fileName, "w" )
- file.close()
- else
- local filePath = fs.list( "." ..newURL )
- shouldIendThis = false
- function a()
- while true do
- local timer = os.startTimer( 0.5 )
- local event, key, message = os.pullEvent()
- if event == "rednet_message" then
- if message == newURL then
- file = fs.open( "." ..newURL.. "/index", "r" )
- rednet.send( key, file.readAll() )
- file.close()
- elseif fs.exists( "." ..message ) then
- file = fs.open( "." ..message, "r" )
- if file then
- rednet.send( key, file.readAll() )
- file.close()
- end
- end
- elseif shouldIendThis then
- break
- end
- end
- end
- function b()
- shell.run( "edit", "." ..newURL.. "/" ..filePath[ currentID ] )
- shouldIendThis = true
- end
- parallel.waitForAny( a, b )
- drawFooter()
- end
- end
- end
- end
- end
- function loadWebpage( url, id )
- if not url then
- url = currentURL
- end
- currentURL = url
- term.clear()
- term.setCursorPos(1,1)
- if theme == "default" then
- if rednetType == "HTTP" then
- print("http://" ..currentURL)
- elseif rednetType == "rnet" then
- print("rnet://" ..currentURL)
- else
- print("rdnt://" ..currentURL)
- end
- for i=1,x do
- term.setCursorPos(i,2)
- write("-")
- end
- term.setCursorPos(1,3)
- elseif theme == "old" then
- cPrint("Rednet Explorer")
- if rednetType == "HTTP" then
- cPrint("http://" ..currentURL )
- elseif rednetType == "rnet" then
- cPrint("rnet://" ..currentURL )
- else
- cPrint("rdnt://" ..currentURL)
- end
- term.setCursorPos(1,4)
- elseif theme == "edit" then
- term.setCursorPos(1,y)
- write("Press CTRL to access menu")
- end
- if url == "home" then
- homePage()
- elseif url == "newsite" then
- if rednetType == "rnet" then
- rnetHost()
- else
- newServer()
- end
- elseif url == "settings" then
- settings()
- elseif url == "exit" then
- error()
- else
- if rednetType == "HTTP" then
- http.request( "http://" ..url )
- readTimedOut = os.startTimer(3)
- local text = ""
- while true do
- local event, body, url = os.pullEvent()
- if event == "http_success" then
- text = url.readAll()
- break
- elseif event == "http_failed" then
- text = "Failed to load"
- break
- elseif event == "timer" and body == readTimedOut then
- text = "Read timed out"
- break
- end
- end
- print( text )
- elseif rednetType == "rnet" then
- local response = http.post(
- ApiPath,
- "user=guest&"..
- "pass=guest&"..
- "type=download&"..
- "data=blank&"..
- "name=".. textutils.urlEncode(url)
- )
- if response then
- local body = response.readAll()
- response.close()
- if body == nil or body == "" or string.find(body, "auth_error") or string.find(body, "file_not_found") then
- print("Unable to load webpage.")
- print("\nThe website you have requested was unable to work. If you beleive this is a error please contact your rednet service providers. (RSP)")
- print("\nThis may be the result of the list below: ")
- print("1) The site you requested is down.")
- print("2) The site you requested is corrupted.")
- print("3) The site you requested forgot to put a modem")
- print("4) You have no modem")
- print("5) This message is faked, and you have a virus now.")
- else
- fs.delete(".downloadedWebsite")
- webpage = fs.open(".downloadedWebsite", "w")
- webpage.write(body)
- webpage.close()
- shell.run(".downloadedWebsite")
- end
- end
- else
- if id then
- fs.delete(".downloadedWebsite")
- file = fs.open(".downloadedWebsite", "w")
- file.write( id )
- file.close()
- shell.run(".downloadedWebsite")
- else
- if hasModem then
- if id then
- rednet.send( id, url )
- else
- rednet.broadcast( url )
- end
- local timer = os.startTimer(0)
- local messages = {}
- repeat
- local event, key, message = os.pullEvent()
- if event == "rednet_message" then
- if id then
- if key == id then
- messages[#messages+1] = {
- ["id"] = key,
- ["code"] = message,
- }
- end
- else
- messages[#messages+1] = {
- ["id"] = key,
- ["code"] = message,
- }
- end
- end
- until event == "timer" and key == timer
- if #messages == 1 then
- fs.delete(".downloadedWebsite")
- file = fs.open(".downloadedWebsite", "w")
- file.write( messages[1]["code"] )
- file.close()
- shell.run(".downloadedWebsite")
- elseif #messages == 0 then
- print("Unable to load webpage.")
- print("\nThe website you have requested was unable to work. If you beleive this is a error please contact your rednet service providers. (RSP)")
- print("\nThis may be the result of the list below: ")
- print("1) The site you requested is down.")
- print("2) The site you requested is corrupted.")
- print("3) The site you requested forgot to put a modem")
- print("4) You have no modem")
- print("5) This message is faked, and you have a virus now.")
- else
- local id = 0
- local valvez = true
- id = messages[1]["id"]
- for i=2,#messages do
- if messages[i]["id"] ~= id then
- valvez = false
- end
- end
- if valvez then
- fs.delete(".downloadedWebsite")
- file = fs.open(".downloadedWebsite", "w")
- file.write( messages[1]["code"] )
- file.close()
- shell.run(".downloadedWebsite")
- else
- local x1, y1 = term.getCursorPos()
- local currentID = 1
- while true do
- term.setCursorPos(1,y1)
- cPrint("+---Conflict Warning---+")
- cPrint("| 2 or more hosts have |")
- cPrint("| been found, please |")
- cPrint("| select the correct ID|")
- cPrint("+----------------------+")
- for i=1,#messages do
- local xx, yy = term.getCursorPos()
- cPrint("| |")
- term.setCursorPos(xx, yy)
- newButton( currentID, i, "#" ..messages[i]["id"], true )
- end
- cPrint("+----------------------+")
- local event, key = os.pullEvent("key")
- if key == keys.up then
- if currentID ~= 1 then
- currentID = currentID -1
- end
- elseif key == keys.down then
- if currentID ~= #messages then
- currentID = currentID +1
- end
- elseif key == keys.enter then
- local code = messages[currentID]["code"]
- loadWebpage( url, code )
- break
- end
- end
- end
- end
- else
- print("\nUnable to connect because no modem has been detected on your computer. Please attatch a modem and restart this program. ")
- end
- end
- end
- end
- if theme == "default" then
- term.setCursorPos(x-#("Press CTRL to brows"), 1)
- write("Press CTRL to browse")
- elseif theme == "old" then
- term.setCursorPos(x-#("Press CTRL to explor"), y)
- write("Press CTRL to explore")
- end
- repeat
- local _, key = os.pullEvent("key")
- until key == 29 or key == 157
- if theme == "default" then
- term.setCursorPos(1,1)
- term.clearLine()
- if rednetType == "HTTP" then
- write("http://")
- elseif rednetType == "rnet" then
- write("rnet://")
- else
- write("rdnt://")
- end
- elseif theme == "old" or theme == "edit" then
- term.setCursorPos(1,2)
- term.clearLine()
- if rednetType == "HTTP" then
- write("http://")
- elseif rednetType == "rnet" then
- write("rnet://")
- else
- write("rdnt://")
- end
- end
- loadWebpage( read() )
- end
- local function openModems()
- for i,v in pairs( rs.getSides() ) do
- if rednet.open( v ) then
- return true
- end
- end
- end
- openModems()
- if fs.exists(".rexsettings") then
- file = fs.open(".rexsettings", "r")
- currentURL = file.readLine()
- theme = file.readLine()
- file.close()
- else
- file = fs.open(".rexsettings", "w")
- file.write( "home\n" )
- file.write( "default" )
- file.close()
- end
- loadWebpage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement