Theudas

login

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