Advertisement
Marlingaming

CC Tweaked Private Web Search Engine

Jan 12th, 2022 (edited)
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. --this script acts as a Search Engine
  2. local Opened Page = "home"
  3. local networkVersion = "1.0.0"
  4. local SecCode = "0000"
  5. local w, h = term.getSize()
  6.  
  7. local function Clear()
  8. term.clear()
  9. term.setCursorPos(1,1)
  10. end
  11.  
  12. local function CenterText(y,text)
  13. local x = math.floor((w - string.len(text)) /2)
  14. term.setCursorPos(x,y)
  15. term.clearLine()
  16. term.write(text)
  17. end
  18.  
  19. function getFile(code)
  20. local file = http.get("http://pastebin.com/raw.php?i=" .. textutils.urlEncode(code))
  21. if file then
  22. local out = file.readAll()
  23. file.close()
  24. return(out)
  25. else
  26. return("failed")
  27. end
  28. end
  29.  
  30.  
  31. function GetNetworkVersion(fileContents)
  32. local _, numberChars = fileContents:lower():find('networkVersion = "')
  33. local fileVersion = ""
  34. local char = ""
  35. if numberChars then
  36. while char ~= '"' do
  37.  
  38. numberChars = numberChars + 1
  39. char = fileContents:sub(numberChars,numberChars)
  40. fileVersion = fileVersion .. char
  41. end
  42. -- Making the version variable by putting every character from 'networkVersion = "' to '"'
  43.  
  44. fileVersion = fileVersion:sub(1,#fileVersion-1)
  45. return fileVersion
  46. else
  47.  
  48. return("failed")
  49. end
  50. end
  51.  
  52. function getSecCode(fileContents)
  53. local _, numberChars = fileContents:lower():find('SecCode = "')
  54. local webCode = ""
  55. local char = ""
  56. if numberChars then
  57. while char ~= '"' do
  58.  
  59. numberChars = numberChars + 1
  60. char = fileContents:sub(numberChars,numberChars)
  61. webCode = webCode .. char
  62. end
  63. -- Making the version variable by putting every character from 'webCode = "' to '"'
  64.  
  65. webCode = webCode:sub(1,#webCode-1)
  66. return webCode
  67. else
  68.  
  69. return("failed")
  70. end
  71. end
  72.  
  73. function WebsiteSearch(webCode)
  74. local Results = getFile(WebCode)
  75. if Results == "failed" then
  76. return("failed to find Website")
  77. else
  78. if GetNetworkVersion(Results) == networkVersion then
  79. if getSecCode(Results) == SecCode then
  80. return("true")
  81. else
  82. return("invalid Security Code")
  83. end
  84. else
  85. if GetNetworkVersion(Results) > networkVersion then
  86. return("Site Runs Outdated Version")
  87. elseif GetNetworkVersion(Results) < networkVersion then
  88. return("Client is running too outdated Version to show this")
  89. elseif GetNetworkVersion(Results) == "failed" then
  90. return("invalid Site")
  91. end
  92. end
  93. end
  94. end
  95.  
  96. function WebsiteLoader(URL)
  97. local webCode = URL:sub(string.len(URL)-7,string.len(URL))
  98. local CheckResults = WebsiteSearch(webCode)
  99. if CheckResults == "true" then
  100. LoadPage(webCode)
  101. else
  102. Clear()
  103. print("Web Search Engine")
  104. print(CheckResults)
  105. print("1 - return, 2 - exit")
  106. local event
  107. repeat
  108. event = {os.pullEvent("key")}
  109. until event[2] == keys.one or event[2] == keys.two
  110. if event[2] == keys.one then
  111. HomePage()
  112. elseif event[2] == keys.two then
  113. shell.run(settings.get("os_DesktopLoc"))
  114. end
  115. end
  116. end
  117.  
  118. function LoadPage(webCode)
  119. Clear()
  120. shell.run("pastebin","get",webCode,"os/os_TempFiles/WebSearch/temp_webCache_"..webCode)
  121. Clear()
  122. shell.run("temp_webCache_"..webCode,"os/os_Programs/os_SearchEngine/ExitScript")
  123. end
  124.  
  125. function HomePage()
  126. term.setBackgroundColor(colors.white)
  127. Clear()
  128. print("[X] Web Search Engine - version "..networkVersion)
  129. term.write("//")
  130. local input
  131. local event
  132. while true do
  133. event = {os.pullEvent()}
  134. if event[1] == "key" and event[2] == keys.enter then break() end
  135. if event[1] == "mouse_click" and event[3] < 3 and event[4] < 3 then break end
  136. input = read()
  137. end
  138. if event[1] == "mouse_click" then
  139. WebsiteLoader(input)
  140. else
  141. shell.run(settings.get("os_DesktopLoc"))
  142. end
  143. end
  144.  
  145. HomePage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement