Advertisement
jared314

Untitled

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