Advertisement
Guest User

startup

a guest
Sep 28th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. function isFirstTime()
  2.    if not fs.exists("/.complete") then
  3.      return true
  4.    else
  5.     return false
  6.    end
  7. end
  8.  
  9. function completeSetup()
  10.    file = fs.open("/.complete", "w")
  11.    file.write("true")
  12.    file.close()
  13. end
  14.  
  15. local rdirs = {
  16.               "/router",
  17.               "/router/encryption"
  18. }
  19.  
  20. term.clear()
  21. term.setCursorPos(1,1)
  22. if isFirstTime() then
  23.   for _,dir in ipairs(rdirs) do
  24.      fs.makeDir(dir)
  25.   end
  26.   local olddir = shell.dir()
  27.   shell.setDir("/router/encryption")
  28.   shell.run("pastebin get 6UV4qfNF sha256")
  29.   shell.setDir(olddir)
  30.   os.loadAPI("/router/encryption/sha256")
  31.   term.clear()
  32.   term.setCursorPos(1,1)
  33.   print("Welcome to Wi-Fi Setup!")
  34.   print()
  35.   term.write("AP: ")
  36.   ap = read()
  37.   term.write("Pass: ")
  38.   pass = read("*")
  39.   print()
  40.   print("Processing...")
  41.   local salt = "stuff"
  42.   local hash = sha256.pbkdf2(pass, salt, 100):toHex()
  43.   file = fs.open(fs.combine("/router/", "pass"), "w")
  44.   file.write(hash)
  45.   file.close()
  46.   file = fs.open(fs.combine("/router/", "ap"), "w")
  47.   file.write(ap)
  48.   file.close()
  49.   print()
  50.   print("Would you like to have a sign-in screen? (Y/N)")
  51.   result = read()
  52.   if result == "Y" or result == "y" then
  53.     term.write("User: ")
  54.     user = read()
  55.     term.write("Pass: ")
  56.     pass = read()
  57.     file = fs.open(fs.combine("/router/", "signin"), "w")
  58.     file.write("function allowInternet()")
  59.     file.write('rednet.broadcast("allowinternet")')
  60.     file.write("term.clear()")
  61.     file.write("term.setCursorPos(1,1)")
  62.     file.write("end")
  63.     file.write('file = fs.open(fs.combine("/router/", "ap"), "w")')
  64.     file.write("local ap = file.readAll()")
  65.     file.write('file.close()')
  66.     completeSetup()
  67.     os.reboot()
  68.   elseif result == "N" or result == "n" then
  69.     completeSetup()
  70.     os.reboot()
  71.   end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement