Guest User

Untitled

a guest
May 12th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1.  
  2. local bExit = false
  3. local sDir = (shell and shell.dir()) or ""
  4. local tEnv = {}
  5.  
  6. local function fnRun( _sCommand, ... )
  7. -- Look in the current dir first
  8. local sPath = fs.combine( sDir, _sCommand )
  9. if fs.exists( sPath ) and not fs.isDir( sPath ) then
  10. return os.run( tEnv, sPath, ... )
  11. end
  12.  
  13. -- Then look at programs
  14. local sPath = fs.combine( "rom/programs", _sCommand )
  15. if fs.exists( sPath ) and not fs.isDir( sPath ) then
  16. return os.run( tEnv, sPath, ... )
  17. end
  18.  
  19. -- Then fail
  20. print( "No such program" )
  21. return false
  22. end
  23.  
  24. -- Install shell API -- startup
  25. tEnv["shell"] = {
  26. ["exit"] = function( )
  27. bExit = true
  28. end,
  29. ["dir"] = function( )
  30. return sDir
  31. end,
  32. ["setDir"] = function( _sDir )
  33. sDir = _sDir
  34. end,
  35. ["resolve"] = function( _sPath )
  36. local sStartChar = string.sub( _sPath, 1, 1 )
  37. if sStartChar == "/" or sStartChar == "\\" then
  38. return fs.combine( "", _sPath )
  39. else
  40. return fs.combine( sDir, _sPath )
  41. end
  42. end,
  43. ["run"] = function( _sCommand, ... )
  44. fnRun( _sCommand, ... )
  45. end,
  46. }
  47.  
  48. print( os.version() )
  49. print("______ _ _ _ _ ___ _ _ _ _ _____ _____ __ ")
  50. print("| ___ \ | || | | | | | / _ \ | | | | | | | || _ | | _ |/ | ")
  51. print("| |_/ / ___ __| || | | | ___ _ __ | | __ ___ / /_\ \| | _ __ | |__ __ _ | | | || |/' | | |/' |`| | ")
  52. print("| / / _ \ / _` || |/\| | / _ \ | '__|| |/ // __| | _ || || '_ \ | '_ \ / _` | | | | || /| | | /| | | | ")
  53. print("| |\ \| __/| (_| |\ /\ /| (_) || | | < \__ \ | | | || || |_) || | | || (_| | \ \_/ /\ |_/ /_\ |_/ /_| |_")
  54. print("\_| \_|\___| \__,_| \/ \/ \___/ |_| |_|\_\|___/ \_| |_/|_|| .__/ |_| |_| \__,_| \___/ \___/(_)\___/ \___/")
  55. print(" | | ")
  56. print(" |_| ")
  57. passwords = {
  58. ['Sarkynin'] = '12345',
  59. ['root'] = 'root'
  60.  
  61. }
  62.  
  63. term.clear()term.setCursorPos(1,1)
  64.  
  65. while true do
  66. print '\nUsername'
  67. user = read()
  68. if passwords[user] ~= nil then
  69. break
  70. end
  71. print '\nInvalid Username'
  72. sleep(1)
  73. end
  74. tries = 5
  75. while tries > 0
  76. do print '\nPassword'
  77. pass = read()
  78. if passwords[user] == pass then
  79. break
  80. end
  81. print '\nIncorrect Password'
  82. tries = tries - 1
  83. sleep(1)
  84. end
  85. if tries <= 0 then
  86. print '\nMaximum number of tries used.'
  87. sleep(2)
  88. print 'System will now shut down.'
  89. sleep(2)
  90. os.shutdown()
  91. end
  92. print('\nWelcome, ' .. user .. '.')
  93.  
  94. local tArgs = { ... }
  95. if #tArgs > 0 then
  96. fnRun( ... )
  97. end
  98.  
  99. while not bExit do
  100. io.write( sDir .. "> " )
  101.  
  102. local sLine = read( )
  103. local tWords = {}
  104. for match in string.gmatch(sLine, "[^ \t]+") do
  105. table.insert( tWords, match )
  106. end
  107.  
  108. local sCommand = tWords[1]
  109. if sCommand then
  110. fnRun( sCommand, unpack( tWords, 2 ) )
  111. end
  112. end
Add Comment
Please, Sign In to add comment