This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
RainbowCow's profile picture

Revoking Access.

Started by RainbowCow, 29 December 2014 - 01:16 PM
RainbowCow #1
Posted 29 December 2014 - 02:16 PM
Hello, I wondered if I can revoke access to edit files, open files, delete files and such.

This is a program I made (below this) I want to revoke people's access to delete stuff, edit stuff and open some things.. can someone help me on that?

term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.cyan)
print("Welcome to this computer!")
sleep(1)
print(" ")
print("Would you like to sign in?")
sleep(1)
print("YES/NO, Remember its cap sensetive!")
write("YES/NO: ")
answear = read()
if answear == "YES" then
print("Please input password.")
sleep(2)
write("Password: ")
password = read("*")
if password == "1793" then
sleep(1)
print("Access Granted.")
sleep(1)
print("Thank you for using Eyax Security.")
sleep(1)
print("Enjoy!")
sleep(1)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.green)
else
print("Wrong password. Shutting down.")
sleep(2)
os.shutdown()
end
else if answear == "NO" then
print("Answear = No")
sleep(1)
print("Shutting down, thank you for using Eyax Security.")
sleep(2)
os.shutdown()
else
print("Please use caps! Would you like to reboot or shutdown?")
write("reboot/shutdown: ")
answear1 = read()
if answear1 == "reboot" then
print("Rebooting … Please wait.")
sleep(2)
os.reboot()
else if answear1 == "shutdown" then
print("Thank you for using Eyax Security! Goodbye!")
sleep(3)
os.shutdown()
end
end
end
end


This code was done in OneOS.
Dustmuz #2
Posted 29 December 2014 - 04:19 PM
cleaned up the code with indentations and you had 2 to many end's at the end

on the security part i wont be of much help



term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.cyan)
print("Welcome to this computer!")
sleep(1)
print(" ")
print("Would you like to sign in?")
sleep(1)
print("YES/NO, Remember its cap sensetive!")
write("YES/NO: ")
answear = read()

if answear == "YES" then
  print("Please input password.")
  sleep(2)
  write("Password: ")
  password = read("*")
  if password == "1793" then
   sleep(1)
   print("Access Granted.")
   sleep(1)
   print("Thank you for using Eyax Security.")
   sleep(1)
   print("Enjoy!")
   sleep(1)
   term.clear()
   term.setCursorPos(1,1)
   term.setTextColor(colors.green)
  else
   print("Wrong password. Shutting down.")
   sleep(2)
   os.shutdown()
  end
elseif answear == "NO" then
  print("Answear = No")
  sleep(1)
  print("Shutting down, thank you for using Eyax Security.")
  sleep(2)
  os.shutdown()
else
  print("Please use caps! Would you like to reboot or shutdown?")
  write("reboot/shutdown: ")
  answear1 = read()
  if answear1 == "reboot" then
   print("Rebooting ... Please wait.")
   sleep(2)
   os.reboot()
  elseif answear1 == "shutdown" then
   print("Thank you for using Eyax Security! Goodbye!")
   sleep(3)
   os.shutdown()
  end
end
Edited on 29 December 2014 - 03:21 PM
MKlegoman357 #3
Posted 29 December 2014 - 05:01 PM
You would have to 'sandbox' the FS API for that. Basically, you would rewrite every sensitive FS API function with your own function that would restrict anything you want. It may be quite a challenge for a new programmer though. Judging from the code, your post count and the actual question I assume you are not a very experienced user yet.

By saying 'opening' you mean doing 'edit my_secret_program' in shell, right? Well, that may be more complicated to do than you may think. Well, one of the ways would be to 'hide' or do not allow a user to use the 'edit' program and overwrite the FS API to restrict the rest (deleting, moving files). Although that approach has flaws, big ones. You could also only allow the user to work in a specific directory only, that would also need a sandboxed FS API.

Sandboxing is not that hard, but you may accidentally leave flaws in the overwritten API. I now wonder if anyone has made a program to do this kind of sandboxing…
RainbowCow #4
Posted 31 December 2014 - 09:58 PM
Thanks guys,this really helped :)/>


- I am quite new, trying to learn lua step by step, started in minecraft and gmod. :D/>
RainbowCow #5
Posted 01 January 2015 - 02:21 PM
Hello, is there any way I can like, remove access from floppy disks so they can't overwrite the security password startup? Please write it in my code if it is possible :D/> Code:

os.pullEvent = os.pullEventRaw -- Terminate disabled.
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.cyan)
print("Welcome to this computer!")
sleep(1)
print(" ")
print("Would you like to sign in?")
sleep(1)
print("YES/NO, Remember its cap sensetive!")
write("YES/NO: ")
answear = read()
if answear == "YES" then
  print("Please input password.")
  sleep(2)
  write("Password: ")
  password = read("*")
  if password == "1793" then
	sleep(1)
	print("Access Granted.")
	sleep(1)
	print("Thank you for using Eyax Security.")
	sleep(1)
	print("Enjoy!")
	sleep(1)
	term.clear()
	term.setCursorPos(1,1)
	term.setTextColor(colors.green)
  else
	print("Wrong password. Shutting down.")
	sleep(2)
	os.shutdown()
  end
else if answear == "NO" then
  print("Answear = No")
  sleep(1)
  print("Shutting down, thank you for using Eyax Security.")
  sleep(2)
  os.shutdown()
else
  print("Please use caps! Would you like to reboot or shutdown?")
  write("reboot/shutdown: ")
  answear1 = read()
  if answear1 == "reboot" then
	print("Rebooting ... Please wait.")
	sleep(2)
	os.reboot()
  else if answear1 == "shutdown" then
	print("Thank you for using Eyax Security! Goodbye!")
	sleep(3)
	os.shutdown()
  end
  end
  end
  end 
Edited on 01 January 2015 - 10:40 PM
TheOddByte #6
Posted 01 January 2015 - 04:04 PM
Put the code in code tags for readability

os.pullEvent = os.pullEventRaw -- Terminate disabled.
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.cyan)
print("Welcome to this computer!")
sleep(1)
print(" ")
print("Would you like to sign in?")
sleep(1)
print("YES/NO, Remember its cap sensetive!")
write("YES/NO: ")
answear = read()
if answear == "YES" then
print("Please input password.")
sleep(2)
write("Password: ")
password = read("*")
if password == "1793" then
sleep(1)
print("Access Granted.")
sleep(1)
print("Thank you for using Eyax Security.")
sleep(1)
print("Enjoy!")
sleep(1)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.green)
else
print("Wrong password. Shutting down.")
sleep(2)
os.shutdown()
end
else if answear == "NO" then
print("Answear = No")
sleep(1)
print("Shutting down, thank you for using Eyax Security.")
sleep(2)
os.shutdown()
else
print("Please use caps! Would you like to reboot or shutdown?")
write("reboot/shutdown: ")
answear1 = read()
if answear1 == "reboot" then
print("Rebooting ... Please wait.")
sleep(2)
os.reboot()
else if answear1 == "shutdown" then
print("Thank you for using Eyax Security! Goodbye!")
sleep(3)
os.shutdown()
end
end
end
end
And have you tried putting this in a 'while true do' loop? Also, you should indent your code.

--# Indent by 4 or 2 spaces in statements
if <condition> then
	print( "foo" )
elseif <condition>  then
	print( "bar" )
else
	print( "Hello World!" )
end

--# Same for loops
while true do
	print( "foo" )
	if <condition> then
		print( "bar" )
	end
	sleep( 1 )
end

for i = 1, 10 do
	print( "foo" )
	if i == 10 then
		print( "bar" )
	end
end
And you've misspelled 'answer'.

Edit: I've seen you've changed the color of the code, that doesn't really help for readability, you can put the code between
[Xcode] code here [X/code] ( without the X )

Does this work for you?

os.pullEvent = os.pullEventRaw -- Terminate disabled.
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.cyan)
print("Welcome to this computer!")
sleep(1)
print("\nWould you like to sign in?") --# Removed a print call and added in \n here to indicate a new line
sleep(1)
write("YES/NO: ")
local answer = string.upper( read() ) --# Upper the input, so if the user inputs yEs or something it becomes YES
if answer == "YES" then
print("Please input password.")
sleep(2)
write("Password: ")
local password = read("*")
if password == "1793" then
sleep(1)
print("Access Granted.")
sleep(1)
print("Thank you for using Eyax Security.")
sleep(1)
print("Enjoy!")
sleep(1)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.green)
else
print("Wrong password. Shutting down.")
sleep(2)
os.shutdown()
end
elseif answear == "NO" then
print("Answer = No")
sleep(1)
print("Shutting down, thank you for using Eyax Security.")
sleep(2)
os.shutdown()
else
repeat --# Repeat this part until it gets a valid answer
   print("Invalid answer")
write("Reboot/Shutdown: ")
local answer1 = string.upper( read() )
if answer1 == "REBOOT" then
print("Rebooting ... Please wait.")
sleep(2)
os.reboot()
elseif answer1 == "SHUTDOWN" then
print("Thank you for using Eyax Security! Goodbye!")
sleep(3)
os.shutdown()
end
until answer1 == "REBOOT" or answer1 == "SHUTDOWN" --# Make sure the answer was REBOOT or SHUTDOWN
end
( Why does the forum destroy my indentation when I copy/paste from N++? :(/> )
Edited on 01 January 2015 - 04:48 PM