xXm0dzXx

Untitled

May 18th, 2012
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local x,y = term.getSize()
  2. rednet.open("top")
  3. local EditingValue = "";
  4.  
  5. function rednetV()
  6. return "2.3"
  7. end
  8.  
  9. title = "Rednet Explorer " ..rednetV() --Add title = "name" to change the webpage's title!
  10. local website = "home";
  11. if fs.exists(".cache") then fs.delete(".cache") end
  12. if fs.exists(".websiteedited") then fs.delete(".websiteedited") end
  13. fs.makeDir(".cache")
  14.  
  15. local cPrint = function(text)
  16. local x2,y2 = term.getCursorPos()
  17. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  18.  
  19. print(text)
  20. end
  21.  
  22. function createSite(websitename)
  23. fs.delete("startup")
  24. startup = fs.open("startup", "w")
  25. startup.writeLine("websitename = \"" ..websitename.. "\"")
  26. servercode = [[
  27.  
  28.  
  29. function record(text)
  30. print(text)
  31. log = fs.open("rednet.log", "w")
  32. log.writeLine(text)
  33. log.close()
  34. end
  35.  
  36. local x,y = term.getSize()
  37. local cPrint = function(text)
  38. local x2,y2 = term.getCursorPos()
  39. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  40.  
  41. print(text)
  42. end
  43.  
  44. rednet.open("top")
  45. term.clear()
  46. cPrint("Hosting " ..websitename.. "...\n")
  47. cPrint("Go to " ..websitename.. "/editor to edit it! (PASS: " ..os.getComputerID().. ")\n")
  48. test = fs.open(websitename, "r")
  49. fileContents = test:readAll()
  50. test.close()
  51. while true do
  52. sleep(0)
  53. id, message = rednet.receive()
  54. if message == websitename then
  55. record(" [" ..os.time().."] [" ..id.. "] Pinged Website.")
  56. rednet.send(id, fileContents)
  57. record(" [" ..os.time().."] [" ..id.. "] Received Data")
  58. elseif message == websitename.. "/editor" then
  59. rednet.send(id, "EditorMode")
  60. rednet.send(id, tostring(os.getComputerID()))
  61. rednet.send(id, fileContents)
  62. elseif message == websitename.. "/editor EDITED COMPLED!" then
  63. id, message = rednet.receive(0.001)
  64. fs.delete(websitename)
  65. webpage = fs.open(websitename, "w")
  66. webpage.write(message)
  67. webpage.close()
  68.  
  69.  
  70. test = fs.open(websitename, "r")
  71. fileContents = test:readAll()
  72. test.close()
  73. record(" [" ..os.time().."] [" ..id.. "] Updated Website!")
  74. end
  75. end
  76. ]]
  77.  
  78. startup.writeLine(servercode)
  79. startup.close()
  80. os.reboot()
  81. end
  82.  
  83. local Address = function()
  84. text = "rdnt://"
  85. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), 2)
  86. term.clearLine()
  87.  
  88. write("rdnt://")
  89. website = read()
  90. loadWebpage()
  91. end
  92.  
  93. function done()
  94. term.setCursorPos(1, y)
  95. name = "F5 = Refresh"
  96. write("Press CTRL to travel the web! :D")
  97. term.setCursorPos(x - name:len(), y)
  98. write(name)
  99.  
  100. while true do
  101. sleep(0) -- stop crashing
  102. e, k = os.pullEvent("key")
  103. if k == 63 then
  104. loadWebpage()
  105. break
  106. elseif k == 29 then
  107. Address()
  108. break
  109. end
  110. end
  111. end
  112.  
  113.  
  114. loadWebpage = function()
  115. term.clear()
  116. term.setCursorPos(1,1)
  117. cPrint(title)
  118. cPrint("rdnt://" ..website.. "\n")
  119. if website == "home" then
  120. print("Welcome to RedNet explorer (2.0)! This requires you to have a wireless modem on your computer.")
  121. print("Host a website at: ")
  122. print("rdnt://newsite! ")
  123. print(" -ComputerCraftFan11 ")
  124. elseif website == "newsite" then
  125. print("Internet Cafe Site Protector\n")
  126. print("Website Blocked. Reason: Editing Startup")
  127. else
  128. title = "Rednet Explorer " ..rednetV()
  129. rednet.broadcast(website)
  130. print("Connecting...")
  131. id, message = rednet.receive(0.1)
  132. if message == nil then
  133. print("Unable to load webpage.")
  134. elseif message == "EditorMode" then
  135. id, password = rednet.receive(0.1)
  136. id, EditingValue = rednet.receive(0.1)
  137. write("Password: ")
  138. input = read("*")
  139. if tostring(password) == input then
  140. fs.delete(".cache/" ..website)
  141. editor = fs.open(".websiteedited", "w")
  142. if editor then
  143. editor.writeLine(EditingValue)
  144. end
  145. editor.close()
  146.  
  147. shell.run("edit", ".websiteedited")
  148.  
  149. edited = fs.open(".websiteedited", "r")
  150. editwebpage = edited.readAll()
  151. edited.close()
  152.  
  153. rednet.broadcast(website.. " EDITED COMPLED!")
  154. rednet.broadcast(editwebpage)
  155. website = "home"
  156. loadWebpage()
  157.  
  158. else
  159.  
  160. website = "home"
  161. loadWebpage()
  162.  
  163. end
  164. else
  165. if fs.exists(".cache/" ..website) then fs.delete(".cache/" ..website) end
  166. webpage = fs.open(".cache/" ..website, "w")
  167. webpage.write(message)
  168. webpage.close()
  169. term.clear()
  170. term.setCursorPos(1,1)
  171. cPrint(title)
  172. cPrint("rdnt://" ..website.. "\n")
  173. shell.run(".cache/" ..website)
  174. end
  175. end
  176.  
  177. done()
  178. end
  179.  
  180. loadWebpage()
Advertisement
Add Comment
Please, Sign In to add comment