Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this script acts as a Search Engine
- local Opened Page = "home"
- local networkVersion = "1.0.0"
- local SecCode = "0000"
- local w, h = term.getSize()
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function CenterText(y,text)
- local x = math.floor((w - string.len(text)) /2)
- term.setCursorPos(x,y)
- term.clearLine()
- term.write(text)
- end
- function getFile(code)
- local file = http.get("http://pastebin.com/raw.php?i=" .. textutils.urlEncode(code))
- if file then
- local out = file.readAll()
- file.close()
- return(out)
- else
- return("failed")
- end
- end
- function GetNetworkVersion(fileContents)
- local _, numberChars = fileContents:lower():find('networkVersion = "')
- local fileVersion = ""
- local char = ""
- if numberChars then
- while char ~= '"' do
- numberChars = numberChars + 1
- char = fileContents:sub(numberChars,numberChars)
- fileVersion = fileVersion .. char
- end
- -- Making the version variable by putting every character from 'networkVersion = "' to '"'
- fileVersion = fileVersion:sub(1,#fileVersion-1)
- return fileVersion
- else
- return("failed")
- end
- end
- function getSecCode(fileContents)
- local _, numberChars = fileContents:lower():find('SecCode = "')
- local webCode = ""
- local char = ""
- if numberChars then
- while char ~= '"' do
- numberChars = numberChars + 1
- char = fileContents:sub(numberChars,numberChars)
- webCode = webCode .. char
- end
- -- Making the version variable by putting every character from 'webCode = "' to '"'
- webCode = webCode:sub(1,#webCode-1)
- return webCode
- else
- return("failed")
- end
- end
- function WebsiteSearch(webCode)
- local Results = getFile(WebCode)
- if Results == "failed" then
- return("failed to find Website")
- else
- if GetNetworkVersion(Results) == networkVersion then
- if getSecCode(Results) == SecCode then
- return("true")
- else
- return("invalid Security Code")
- end
- else
- if GetNetworkVersion(Results) > networkVersion then
- return("Site Runs Outdated Version")
- elseif GetNetworkVersion(Results) < networkVersion then
- return("Client is running too outdated Version to show this")
- elseif GetNetworkVersion(Results) == "failed" then
- return("invalid Site")
- end
- end
- end
- end
- function WebsiteLoader(URL)
- local webCode = URL:sub(string.len(URL)-7,string.len(URL))
- local CheckResults = WebsiteSearch(webCode)
- if CheckResults == "true" then
- LoadPage(webCode)
- else
- Clear()
- print("Web Search Engine")
- print(CheckResults)
- print("1 - return, 2 - exit")
- local event
- repeat
- event = {os.pullEvent("key")}
- until event[2] == keys.one or event[2] == keys.two
- if event[2] == keys.one then
- HomePage()
- elseif event[2] == keys.two then
- shell.run(settings.get("os_DesktopLoc"))
- end
- end
- end
- function LoadPage(webCode)
- Clear()
- shell.run("pastebin","get",webCode,"os/os_TempFiles/WebSearch/temp_webCache_"..webCode)
- Clear()
- shell.run("temp_webCache_"..webCode,"os/os_Programs/os_SearchEngine/ExitScript")
- end
- function HomePage()
- term.setBackgroundColor(colors.white)
- Clear()
- print("[X] Web Search Engine - version "..networkVersion)
- term.write("//")
- local input
- local event
- while true do
- event = {os.pullEvent()}
- if event[1] == "key" and event[2] == keys.enter then break() end
- if event[1] == "mouse_click" and event[3] < 3 and event[4] < 3 then break end
- input = read()
- end
- if event[1] == "mouse_click" then
- WebsiteLoader(input)
- else
- shell.run(settings.get("os_DesktopLoc"))
- end
- end
- HomePage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement