Advertisement
koki2000

Mining turtle 2.0

Oct 26th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.01 KB | None | 0 0
  1. -- v 2.30
  2. --[[
  3. 2015.10.28
  4. add user delete permission change
  5. add string hash
  6. add security program broken
  7. ]]--
  8.  
  9. local pullEvent = os.pullEvent
  10. os.pullEvent = os.pullEventRaw
  11.  
  12. local unlock = {}
  13. local index = 1
  14. local matrix1 = ""
  15. local matrix2 = ""
  16.  
  17. local ujverzio
  18. local regiverzio
  19. local width, height = term.getSize()
  20. local selectedMenu = 1
  21. local selectedItem = 1
  22. local username = ""
  23. local adminjog = ""
  24. local doors = ""
  25. local windows = ""
  26. local delete = ""
  27.  
  28. local running = true
  29.  
  30. function clear()
  31. term.clear()
  32. term.setCursorPos(1,1)
  33. end
  34.  
  35. function updateStartup()
  36. clear()
  37.   shell.run("pastebin","get","ANLXqv40","update")
  38.   local file = fs.open("update", "r")
  39.   lx = file.readLine()
  40.   s1 = lx:find("v")
  41.   ujverzio = tonumber(lx:sub(s1+2))
  42.   file.close()
  43.   clear()
  44.   print("Uj verzio: ", ujverzio)
  45.   sleep(1)
  46.  
  47.   local file = fs.open("startup", "r")
  48.   lx = file.readLine()
  49.   s1 = lx:find("v")
  50.   regiverzio = tonumber(lx:sub(s1+2))
  51.   file.close()
  52.   print("regi verzio: ", regiverzio)
  53.   sleep(1)
  54.        
  55.     if regiverzio < ujverzio or regiverzio > ujverzio then
  56.       fs.delete("startup")
  57.       fs.copy("update", "startup")
  58.       fs.delete("update")
  59.       shell.run("startup")
  60.     else
  61.       fs.delete("update")
  62.       clear()
  63.       print("nincs elerheto frissites")
  64.       sleep(1)
  65.       return false
  66.     end
  67. end
  68.  
  69. updateStartup()
  70.  
  71. function StringHash(text)
  72.   local counter = 1
  73.   local len = string.len(text)
  74.   for i = 1, len, 3 do
  75.     counter = math.fmod(counter*8161, 4294967279) +
  76.           (string.byte(text,i)*16776193) +
  77.           ((string.byte(text,i+1) or (len-i+256))*8372226) +
  78.           ((string.byte(text,i+2) or (len-i+256))*3932164)
  79.   end
  80.   return math.fmod(counter, 4294967291)
  81. end
  82.  
  83.  
  84. function login()
  85. print("The program created by Csaba")
  86. print("login")
  87. username = read()
  88.   if username == "" then
  89.     print("can not be empty")
  90.     sleep(.4)
  91.   elseif not fs.exists("database/"..username) then
  92.     print("username does not exist")
  93.     sleep(.4)
  94.   elseif fs.exists("database/"..username) then
  95.     file = fs.open("database/"..username, "r")
  96.     loads()
  97.     file.close()
  98.     print("jelszo")
  99.     passhash = read("*")
  100.     pass = tostring(StringHash(passhash))
  101.     if pass == "" then
  102.     print("can not be empty")
  103.     sleep(.4)
  104.     elseif pass == goodpass then
  105.       if adminjog == "true" then
  106.         selectedMenu = 2
  107.       elseif adminjog == "false" then
  108.         selectedMenu = 3
  109.       end
  110.       print("access granted")
  111.       sleep(1)
  112.       if goodpass == "1504751979" then
  113.         clear()
  114.         print("change rootpass")
  115.         changepassword()
  116.       end
  117.     else
  118.       print("access denied")
  119.       sleep(.4)
  120.     end
  121.   end
  122. end
  123.  
  124. function changepassword()
  125. file = fs.open("database/"..username, "r")
  126. actualpass = file.readLine()
  127. file.close()
  128. clear()
  129. print("actual password:")
  130. requestpass = read()
  131. if actualpass == tostring(StringHash(requestpass)) then
  132. print("password access")
  133. sleep(2) clear()
  134. print("new password")
  135. pass1hash = read("*")
  136. pass1 = tostring(StringHash(pass1hash))
  137. print("confirm password")
  138. pass2hash = read("*")
  139. pass2 = tostring(StringHash(pass2hash))
  140.   if pass1 == "" or pass2 == "" then
  141.     print("jelszo ures")
  142.     sleep(.4)
  143.     return changepassword()
  144.   elseif actualpass == pass2 then
  145.     print("root password can't same than root") sleep(2)
  146.     return changepassword()
  147.   elseif pass1 == pass2 then
  148.     file = fs.open("database/"..username, "r")
  149.     file.readLine()
  150.     file.readLine()
  151.     doors = file.readLine()
  152.     windows = file.readLine()
  153.     file.readLine()
  154.     delete = file.readLine()
  155.     file.close()
  156.     file = fs.open("database/"..username, "w")
  157.     file.writeLine(pass1)
  158.     file.writeLine(adminjog)
  159.     file.writeLine(doors)
  160.     file.writeLine(windows)
  161.     file.writeLine(signing)
  162.     file.writeLine(delete)
  163.     file.close()
  164.   end
  165. else
  166. print("incorrect password")
  167. sleep(1)
  168. return changepassword()
  169. end
  170. end
  171.  
  172. function createuser()
  173. if delete == "true" then
  174. print("username")
  175. newuser = read()
  176. print("password")
  177. newpasshash = read("*")
  178. newpass = tostring(StringHash(newpasshash))
  179. print("admin access (i/n)")
  180. adminjog2 = read()
  181.   if newuser == "" or newpass == "" or adminjog2 == "" then
  182.     print("newuser or password or admin access empty")
  183.     sleep(.4)
  184.   else
  185. file = fs.open("database/"..newuser, "w")
  186. file.writeLine(newpass)
  187.   if adminjog2 == "i" or adminjog2 == "I" then
  188.     file.writeLine("true")
  189.     file.writeLine("true")
  190.     file.writeLine("true")
  191.     file.writeLine("false")
  192.     file.writeLine("true")
  193.   elseif adminjog2 == "n" or adminjog2 == "N" then
  194.     file.writeLine("false")
  195.     file.writeLine("false")
  196.     file.writeLine("false")
  197.     file.writeLine("false")
  198.     file.writeLine("false")
  199.   else
  200.     print("wrong character")
  201.     sleep(1)
  202.   end
  203. file.close()
  204.   end
  205. else
  206. print("You don't have enough permission")
  207. sleep(1)
  208. end
  209. end
  210.  
  211. function alluser()
  212. clear()
  213. print("-----> Osszes felhasznalo <-----")
  214. local filelist = fs.list("database/")
  215.   for _, file in ipairs(filelist) do
  216.   list = fs.open("database/"..file, "r")
  217.   list.readLine()
  218.   list.readLine()
  219.   list.readLine()
  220.   list.readLine()
  221.   signing = list.readLine()
  222.   list.close()
  223.     if signing == "true" then
  224.       print(file, ": ", "alairva")
  225.     else
  226.       print(file, ": ", "nincs alairva")
  227.     end
  228.   sleep(.4)
  229.   end
  230. print("press button continue")
  231. read("")
  232. end
  233.  
  234. function permissions()
  235. perms = {"adminjog2", "doors", "windows", "signing", "delete"}
  236. clear()
  237. print("permissions:\n 1: root perm \n 2: doors\n 3: windows \n 4: signing\n 5: delete")
  238. print("user")
  239. user = read()
  240.   if not fs.exists("database/"..user) then
  241.     print("user not fould")
  242.     sleep(.4)
  243.   elseif fs.exists("database/"..user) then
  244.     print("permissions")
  245.     perm = tonumber(read())
  246.       if perm == nil then
  247.         print("can not be empty")
  248.         sleep(.4)
  249.         return permissions()
  250.       end
  251.     for i = 1, perm do
  252.       jog = perms[i]
  253.       print("jog: ", jog)
  254.     end
  255.     file = fs.open("database/"..user, "r")
  256.     actpass = file.readLine()
  257.     adminjog2 = file.readLine()
  258.     doors = file.readLine()
  259.     windows = file.readLine()
  260.     signing = file.readLine()
  261.     delete = file.readLine()
  262.     file.close()
  263.     print("mire")
  264.       which = read()
  265.       permissionok(user, jog, doors, windows, delete, which)
  266.   end
  267. end
  268.  
  269. function permissionok()
  270. print("doorsx: ", doors)
  271. print("windowsx: ", windows)
  272. print("whichx: ", which)
  273. print("jogx: ", jog)
  274. print("whichx: ", which)
  275. if jog == "adminjog2" then
  276. adminjog2 = which
  277. end
  278. if jog == "doors" then
  279. doors = which
  280. end
  281. if jog == "windows" then
  282. windows = which
  283. end
  284. if jog == "signing" then
  285. signing = which
  286. end
  287. if jog == "delete" then
  288. delete = which
  289. end
  290. file = fs.open("database/"..user, "w")
  291. file.writeLine(actpass)
  292. file.writeLine(adminjog2)
  293. file.writeLine(doors)
  294. file.writeLine(windows)
  295. file.writeLine(signing)
  296. file.writeLine(delete)
  297. file.close()
  298. sleep(1)
  299. end
  300.  
  301. function deleteuser()
  302. if delete == "true" then
  303. print("username")
  304. deleteuser = read()
  305.   if deleteuser == "" then
  306.     print("ures") sleep(1)
  307.   elseif not fs.exists("database/"..deleteuser) then
  308.     print("user not found")
  309.     sleep(.4)
  310.   elseif fs.exists("database/"..deleteuser) then
  311.     if deleteuser == "root" then
  312.     print("You don't have enough permission")
  313.     elseif username == username then
  314.     print("You can not delete yourself")
  315.     sleep(1)
  316.     end
  317.     print("user found")
  318.     print("confirm delete i/n")
  319.     delete2 = read()
  320.     if delete2 == "i" or delete2 == "I" then
  321.     fs.delete("database/"..deleteuser)
  322.     elseif delete2 == "n" or delete2 == "N" then
  323.     print("delete canceled")
  324.     end
  325.   end
  326. else
  327. print("You don't have enough permission")
  328. sleep(1)
  329. end
  330. end
  331.  
  332. function shutdown()
  333.  os.shutdown()
  334. end
  335.  
  336. function logout()
  337. selectedItem = 1
  338. selectedMenu = 1
  339. end
  340.  
  341. function loads()
  342. file = fs.open("database/"..username, "r")
  343. goodpass = file.readLine()
  344. adminjog = file.readLine()
  345. doors = file.readLine()
  346. windows = file.readLine()
  347. file.readLine()
  348. delete = file.readLine()
  349. file.close()
  350. end
  351.  
  352. function doorsopen()
  353. clear()
  354.   if doors == "true" then
  355.     print("ajtok nyitva")
  356.     rs.setOutput("right", true)
  357.     sleep(6)
  358.     rs.setOutput("right", false)
  359.   end
  360.   if doors == "false" then
  361.     print("You don't have enough permission")
  362.     sleep(1)
  363.   end
  364. end
  365.  
  366. function windowsopen()
  367. clear()
  368.   if windows == "true" then
  369.     print("ablakok nyitva")
  370.     sleep(1)
  371.   end
  372.   if windows == "false" then
  373.     print("You don't have enough permission")
  374.     sleep(1)
  375.   end
  376. end
  377.  
  378. function programstops()
  379.   for i = 1, #unlock do
  380.   tabla = unlock[i]
  381.   matrix2 = matrix1..tabla
  382.   matrix1 = matrix2
  383.   end
  384.     if matrix2 == "19870221" then
  385.       print("sikeres") sleep(.4)
  386.       running = false
  387.     else
  388.       print("sikertelen") sleep(.4)
  389.     end
  390.   for i = 1, #unlock do
  391.   table.remove(unlock)
  392.   end
  393.   index = 1
  394.   matrix1 = ""
  395.   matrix2 = ""
  396. end
  397.  
  398. local mainMenu1 = {
  399. [1] = { text = "Login", handler = login },
  400. [2] = { text = "Shutdown", handler = shutdown }
  401. }
  402.  
  403. local mainMenu2 = {
  404. [1] = { text = "new password", handler = changepassword },
  405. [2] = { text = "create user", handler = createuser },
  406. [3] = { text = "all user", handler = alluser },
  407. [4] = { text = "user perm", handler = permissions },
  408. [5] = { text = "delete user", handler = deleteuser },
  409. [6] = { text = "logout", handler = logout },
  410. [7] = { text = "doors open", handler = doorsopen },
  411. [8] = { text = "windows open", handler = windowsopen },
  412. [9] = { text = "program stops", handler = programstops }
  413. }
  414.  
  415. local mainMenu3 = {
  416. [1] = { text = "new password", handler = changepassword },
  417. [2] = { text = "doors open", handler = doorsopen },
  418. [3] = { text = "windows open", handler = windowsopen },
  419. [4] = { text = "logout", handler = logout }
  420. }
  421.  
  422. function printMenu( menu )
  423.   if #menu < 18 then
  424.     for i=1,#menu do
  425.       if i < height then
  426.         if i == selectedItem then
  427.           term.setCursorPos(17, (i))
  428.           print(">> "..menu[i].text .. " <<")
  429.         else
  430.           term.setCursorPos(17, (i))
  431.           print("   "..menu[i].text)
  432.         end
  433.       end
  434.     end
  435.   elseif # menu >= 18 then
  436.     for i=1, #menu do
  437.       if i < height then
  438.         if i == selectedItem then
  439.           term.setCursorPos(4, (i))
  440.           print(">> "..menu[i].text .. " <<")          
  441.         else
  442.           term.setCursorPos(1, (i))
  443.           print("   "..menu[i].text)
  444.         end
  445.       elseif i > height - 1 then
  446.         if i == selectedItem then
  447.           term.setCursorPos(32, (i-17))
  448.           print(">> "..menu[i].text .. " <<")          
  449.         else
  450.           term.setCursorPos(32, (i-17))
  451.           print("   "..menu[i].text)
  452.         end
  453.       end
  454.     end
  455.   end
  456. end
  457.  
  458. function keypressprint()
  459. term.setCursorPos(49,17)
  460. print("*") sleep(.1) index = index + 1
  461. end
  462.  
  463. function onKeyPressed( key, menu )
  464.  if key == 28 then
  465.   onItemSelected(menu)
  466.  elseif key == 200 then
  467.   if selectedItem > 1 then
  468.    selectedItem = selectedItem - 1
  469.   end
  470.  elseif key == 208 then
  471.   if selectedItem < #menu then
  472.    selectedItem = selectedItem + 1
  473.   end
  474.  elseif key == 203 then
  475.   if selectedItem > 17 then
  476.    selectedItem = selectedItem - 17
  477.   end
  478.  elseif key == 205 then
  479.   vissza = selectedItem
  480.   if selectedItem < #menu then
  481.    selectedItem = selectedItem + 17
  482.     if selectedItem > #menu then
  483.       selectedItem = vissza
  484.     end
  485.   end
  486.  elseif key == 82 then
  487.   table.insert(unlock, index, 0)
  488.   keypressprint()
  489.  elseif key == 79 then
  490.   table.insert(unlock, index, 1)
  491.   keypressprint()
  492.  elseif key == 80 then
  493.   table.insert(unlock, index, 2)
  494.   keypressprint()
  495.  elseif key == 81 then
  496.   table.insert(unlock, index, 3)
  497.   keypressprint()
  498.  elseif key == 75 then
  499.   table.insert(unlock, index, 4)
  500.   keypressprint()
  501.  elseif key == 76 then
  502.   table.insert(unlock, index, 5)
  503.   keypressprint()
  504.  elseif key == 77 then
  505.   table.insert(unlock, index, 6)
  506.   keypressprint()
  507.  elseif key == 71 then
  508.   table.insert(unlock, index, 7)
  509.   keypressprint()
  510.  elseif key == 72 then
  511.   table.insert(unlock, index, 8)
  512.   keypressprint()
  513.  elseif key == 73 then
  514.   table.insert(unlock, index, 9)
  515.   keypressprint()
  516.  end
  517. end
  518.  
  519. function onItemSelected( menu )
  520.  menu[selectedItem].handler()
  521. end
  522.  
  523. function main()
  524. if not fs.exists("database") then
  525. print("hi")
  526.   fs.makeDir("database")
  527.   local file = fs.open("database/root", "w")
  528.   root = tostring(StringHash("root"))
  529.   file.writeLine(root)
  530.   file.writeLine("true")
  531.   file.writeLine("true")
  532.   file.writeLine("true")
  533.   file.writeLine("false")
  534.   file.close()
  535.   end
  536. while running do
  537.  if selectedMenu == 1 then
  538.   term.clear()
  539.   term.setCursorPos(1,1)
  540.   printMenu(mainMenu1)
  541.   event, key = os.pullEvent("key")
  542.   onKeyPressed(key,mainMenu1)
  543.   elseif selectedMenu == 2 then
  544.   term.clear()
  545.   term.setCursorPos(1,1)
  546.   printMenu(mainMenu2)
  547.   event, key = os.pullEvent("key")
  548.   onKeyPressed(key,mainMenu2)
  549.   elseif selectedMenu == 3 then
  550.   term.clear()
  551.   term.setCursorPos(1,1)
  552.   printMenu(mainMenu3)
  553.   event, key = os.pullEvent("key")
  554.   onKeyPressed(key,mainMenu3)
  555.   end
  556.  end
  557. end
  558.  
  559. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement