Advertisement
23kcarlson

Untitled

May 8th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. -----------------PASTEBINs--------------------------
  2. installer = "2etGLEDc"
  3.  
  4. player_module = "rWp0GXDW"
  5. redstone_module = "y73TxFcW"
  6. fluid_module = "x7K3zUAC"
  7. energy_module = "RxLuZWHp"
  8.  
  9. hash_api = "FLQ68J88"
  10. startup = "KnmEN37h"
  11. ---------------------------------------------
  12. term.clear()
  13. local token = ''
  14. local module_name = ''
  15. local username = ''
  16. local type = ''
  17. local updating = false
  18.  
  19. function draw_text_term(x, y, text, text_color, bg_color)
  20. term.setTextColor(text_color)
  21. term.setBackgroundColor(bg_color)
  22. term.setCursorPos(x,y)
  23. write(text)
  24. end
  25.  
  26. function draw_line_term(x, y, length, color)
  27. term.setBackgroundColor(color)
  28. term.setCursorPos(x,y)
  29. term.write(string.rep(" ", length))
  30. end
  31.  
  32. function bars()
  33. draw_line_term(1, 1, 51, colors.lime)
  34. draw_line_term(1, 19, 51, colors.lime)
  35. draw_text_term(12, 1, 'CraftNanny Module Installer', colors.gray, colors.lime)
  36. draw_text_term(17, 19, 'craftnanny.org', colors.gray, colors.lime)
  37. end
  38.  
  39. -- saves current token variable to local text file
  40. function save_config()
  41. sw = fs.open("config.txt", "w")
  42. sw.writeLine(token)
  43. sw.writeLine(module_name)
  44. sw.writeLine(username)
  45. sw.writeLine(type)
  46. sw.close()
  47. end
  48.  
  49. function load_config()
  50. sr = fs.open("config.txt", "r")
  51. token = sr.readLine()
  52. module_name = sr.readLine()
  53. username = sr.readLine()
  54. type = sr.readLine()
  55. sr.close()
  56. end
  57.  
  58. function launch_module()
  59. shell.run("CN_module")
  60. end
  61.  
  62. function install_module()
  63. if type == '1' then
  64. pastebin = player_module
  65. else if type == '2' then
  66. pastebin = energy_module
  67. else if type == '3' then
  68. pastebin = fluid_module
  69. else if type == '4' then
  70. pastebin = redstone_module
  71. end
  72. end
  73. end
  74. end
  75.  
  76. term.clear()
  77. bars()
  78. draw_text_term(1, 3, 'successfully logged in', colors.lime, colors.black)
  79. sleep(0.5)
  80. draw_text_term(1, 4, 'installing...', colors.white, colors.black)
  81. sleep(0.5)
  82.  
  83. draw_text_term(1, 5, 'removing old versions', colors.white, colors.black)
  84. if fs.exists("CN_module") then
  85. fs.delete("CN_module")
  86. end
  87. sleep(0.5)
  88.  
  89. draw_text_term(1, 6, 'fetch from pastebin', colors.white, colors.black)
  90. term.setCursorPos(1,7)
  91. term.setTextColor(colors.white)
  92. shell.run("pastebin get "..pastebin.." CN_module")
  93. sleep(0.5)
  94.  
  95. draw_text_term(1, 9, 'create startup file', colors.white, colors.black)
  96. term.setCursorPos(1,10)
  97. term.setTextColor(colors.white)
  98. if fs.exists("startup") then
  99. fs.delete("startup")
  100. end
  101. shell.run("pastebin get "..startup.." startup")
  102. sleep(1)
  103.  
  104. draw_text_term(1, 13, 'Setup Complete', colors.lime, colors.black)
  105.  
  106. draw_text_term(1, 14, 'press enter to continue', colors.lightGray, colors.black)
  107.  
  108. if updating then
  109.  
  110. else
  111. input = read()
  112. end
  113.  
  114. launch_module()
  115. end
  116.  
  117. function hash(password)
  118. shell.run("pastebin get "..hash_api.." sha1_api")
  119. os.loadAPI('sha1_api')
  120. response = http.post(
  121. "http://craftnanny.org/code/salt.php",
  122. "user="..user)
  123. salt = response.readAll()
  124. hash = sha1_api.sha1(salt..password)
  125. return hash
  126. end
  127.  
  128. function login()
  129. term.clear()
  130. bars()
  131. draw_text_term(1, 3, 'Register module to your CraftNanny account.', colors.lime, colors.black)
  132. draw_text_term(1, 4, 'Create an account at www.craftnanny.org', colors.lightGray, colors.black)
  133.  
  134. draw_text_term(1, 6, 'Username: ', colors.lime, colors.black)
  135. term.setTextColor(colors.white)
  136. user = read()
  137. draw_text_term(1, 7, 'Password: ', colors.lime, colors.black)
  138. term.setTextColor(colors.white)
  139. pass = read("*")
  140.  
  141. password = hash(pass)
  142.  
  143. response = http.post(
  144. "http://craftnanny.org/code/signin.php",
  145. "user="..user.."&pass="..password.."&id="..os.getComputerID().."&name="..module_name.."&module_type="..type)
  146. token = response.readAll()
  147.  
  148. if token == 'error' then
  149. draw_text_term(1, 8, 'login failed', colors.red, colors.black)
  150. sleep(2)
  151. login()
  152. else
  153. username = user
  154. save_config()
  155. install_module()
  156. end
  157. end
  158.  
  159. function name()
  160. term.clear()
  161. bars()
  162.  
  163. draw_text_term(1, 3, 'Give this module a unique name:', colors.lime, colors.black)
  164. term.setCursorPos(2,4)
  165. term.setTextColor(colors.white)
  166. module_name = read()
  167. os.setComputerLabel(string.gsub(module_name, "%s+", ""))
  168. login()
  169. end
  170.  
  171. function player_tracker()
  172.  
  173. -- code to check that openperipheral sensor is present. give relavent error
  174.  
  175. type = '1'
  176. name()
  177. end
  178.  
  179. function choose_module(input)
  180. if input == '1' then
  181. player_tracker()
  182. elseif input == '2' then
  183. type = '2'
  184. name()
  185. elseif input == '3' then
  186. type = '3'
  187. name()
  188. elseif input == '4' then
  189. type = '4'
  190. name()
  191. elseif input == '5' then
  192.  
  193. end
  194.  
  195. end
  196.  
  197. function install_select()
  198. term.clear()
  199. bars()
  200. draw_text_term(15, 3, 'Welcome to CraftNanny! - Edited', colors.lime, colors.black)
  201. draw_text_term(1, 5, 'What module would you like to install?', colors.white, colors.black)
  202.  
  203. draw_text_term(2, 7, '1. Player Tracking', colors.white, colors.black)
  204. draw_text_term(2, 8, '2. Energy Monitor', colors.white, colors.black)
  205. draw_text_term(2, 9, '3. Fluid Monitor', colors.white, colors.black)
  206. draw_text_term(2, 10, '4. Redstone Controls', colors.white, colors.black)
  207. draw_text_term(2, 11, '5. Rednet Controls', colors.white, colors.black)
  208. draw_text_term(1, 13, 'Enter number:', colors.white, colors.black)
  209. term.setCursorPos(1,14)
  210. term.setTextColor(colors.white)
  211. input = read()
  212.  
  213. choose_module(input)
  214. end
  215.  
  216. function start()
  217. term.clear()
  218. if fs.exists("config.txt") then
  219. load_config()
  220. updating = true
  221. install_module()
  222. else
  223. install_select()
  224. end
  225. end
  226.  
  227. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement