Advertisement
jared314

**CraftNanny Module Installer**

Aug 4th, 2015
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.58 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.     response = http.post(
  147.                 "http://craftnanny.org/code/signin.php",
  148.                 "user="..user.."&pass="..password.."&id="..os.getComputerID().."&name="..module_name.."&module_type="..type)
  149.     token = response.readAll()
  150.  
  151.     if token == 'error' then
  152.         draw_text_term(1, 8, 'login failed', colors.red, colors.black)
  153.         sleep(2)
  154.         login()
  155.     else
  156.         username = user
  157.         save_config()
  158.         install_module()
  159.     end
  160. end
  161.  
  162. function name()
  163.     term.clear()
  164.     bars()
  165.    
  166.     draw_text_term(1, 3, 'Give this module a unique name:', colors.lime, colors.black)
  167.     term.setCursorPos(2,4)
  168.     term.setTextColor(colors.white)
  169.     module_name = read()
  170.     os.setComputerLabel(string.gsub(module_name, "%s+", ""))
  171.     login()
  172. end
  173.  
  174. function player_tracker()
  175.    
  176.     -- code to check that openperipheral sensor is present. give relavent error
  177.    
  178.     type = '1'
  179.     name()
  180. end
  181.  
  182. function choose_module(input)
  183.     if input == '1' then
  184.         player_tracker()
  185.     elseif input == '2' then
  186.         type = '2'
  187.         name()
  188.     elseif input == '3' then
  189.         type = '3'
  190.         name()
  191.     elseif input == '4' then
  192.         type = '4'
  193.         name()
  194.     elseif input == '5' then
  195.    
  196.     end
  197.    
  198. end
  199.  
  200. function install_select()
  201.     term.clear()
  202.     bars()
  203.     draw_text_term(15, 3, 'Welcome to CraftNanny!', colors.lime, colors.black)
  204.     draw_text_term(1, 5, 'What module would you like to install?', colors.white, colors.black)
  205.    
  206.     draw_text_term(2, 7, '1. Player Tracking', colors.white, colors.black)
  207.     draw_text_term(2, 8, '2. Energy Monitor', colors.white, colors.black)
  208.     draw_text_term(2, 9, '3. Fluid Monitor', colors.white, colors.black)
  209.     draw_text_term(2, 10, '4. Redstone Controls', colors.white, colors.black)
  210.     draw_text_term(2, 11, '5. Rednet Controls', colors.white, colors.black)
  211.     draw_text_term(1, 13, 'Enter number:', colors.white, colors.black)
  212.     term.setCursorPos(1,14)
  213.     term.setTextColor(colors.white)
  214.     input = read()
  215.    
  216.     choose_module(input)
  217. end
  218.  
  219. function start()
  220.   term.clear()
  221.   if fs.exists("config.txt") then
  222.     load_config()
  223.     updating = true
  224.     install_module()
  225.   else
  226.     install_select()
  227.   end
  228. end
  229.  
  230. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement