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

ComputerCraft System Controller (SysCon)

Started by Stirfry Noodles, 04 August 2012 - 07:04 AM
Stirfry Noodles #1
Posted 04 August 2012 - 09:04 AM
Hey peoples,

I'm making a bunch of new programs which are linked together so that all changes can be tracked and also controlled from a single point. Obviously if that's the aim, the computers must be secure right? Of course :D/> Read below if you want to know more.

Explanation of program interaction:
The front end client works by the user entering in their login details, it then packages that info up nice and neat and sends it to the designated server. Once that's done, the server check the username and password and sends back a response of "ADMIN" or "USER", if the password or username is wrong then it simply doesn't send anything back and ignores it. Depending on the result of the authentication, you either gain access to the Admin Menu, the User Menu or you get chucked back into the log in page. Since no passwords are stored on the front end, it means a) you don't have to place usernames and passwords everywhere and B)/> no risk of them getting the information from the front end. The future aim is to next code in a feature that means that the server controls everything, however it's the user terminals that 'ask' for things to happen, and if it isn't authenticated, then it is ignored.

Just be advised that the programs that I will be writing will most likely be for the FTB client because there are more mods which can work with the computers, e.g. bundled cables.

I have started posting components below :D/>

If anyone wants some help with their own programs or has any good ideas for me to add then please comment :P/>

Thanks!

Stirfry Noodles



[ 11th of June 2013 ]

Just a little update, there is code a few posts below, however all of them has been majorly upgraded. I had one of those moments where you realize there is a much better and simpler way of doing something… Scary.

Will post the updated version soon, many differences, and so far, it works. More updates are to come though, trying to implement a more secure authentication system for Front End controls.

[ 12th of June 2013 ]

More updates posted…

ALL PROGRAMS ARE WRITTEN BY MYSELF.
IF YOU USE IT, PLEASE SAY SO :)/>

THERE ARE INCOMPLETE SECTIONS, I'M NOT DONE … YET. :P/>


The Roaming Login Server
Spoiler
--[[ Door Roaming Login Server ]]--
--[[ Login Details ]]--
tUsernames = {	-- Add users to the list, make sure there is the corresponding password and user status in the correct index
"StirfryNoodles",
"99Doomsday",
"CyrusShock",
"ANYONE :D/>/>/>/>/>/>/>/>"
}
tPasswords = {
"12345",
"54321",
"13524",
"AND ANY PASSWORD"

}
tUserStatus = {
"ADMIN",
"ADMIN",
"USER",
"SET STATUS HERE :D/>/>/>/>/>/>/>/>"
}
tAcceptedSenders = { 1, 3, 4, 5 }
--[[ Local Variables ]]--
bRunning = true	 -- Main loop controller ( boolean value )
localComputerID = os.getComputerID()
activityLogServerID = 0   -- Change the ID shown here to the one of the Activity Log Server
sWirelessModemSide = "right" -- Change to the side that has the wireless modem... Obviously
statusReport = "User logged into Door Server: "..localComputerID
--[[ Local Functions ]]--
function clearScreen()
term.clear()
term.setCursorPos( 1,1 )
end
function IsAcceptableTerminal(nTerminalID)
for i = 1, #tAcceptedSenders do
  if tAcceptedSenders[i] == nTerminalID then
   return true
  end
end
return false
end
function ValidateUser(sUser, sPass)
retVal = "";
for i = 1, #tUsernames do
  if tUsernames[i] == sUser then
   if tPasswords[i] == sPass then
	retVal = tUserStatus[i]
	break
   end
  end
end
return retVal
end
function sendReport()
tTable = { sUserType, tCredentials[1], "User has logged on" }
sTable = textutils.serialize( tTable )
rednet.send( activityLogServerID, sTable )
end
--[[ Program Start ]]--
-- No os.pullEvent() = os.pullEventRaw() because this is a server, you may need to shut it down manually.
while bRunning do   -- Main program loop, it doesn't end. At all. Use Ctrl-T to terminate it. :)/>/>/>/>/>/>/>/>
clearScreen()
rednet.open( sWirelessModemSide )
print( "Login Server Online at Terminal: "..localComputerID )
print( "Accepting transmissions from: " )
for nIndex = 1, #tAcceptedSenders do
  write( tAcceptedSenders[nIndex]..", " )
end

initialSenderID, sentCredentials = rednet.receive()
term.setCursorPos( 1,5 )
while true do
  if IsAcceptableTerminal(initialSenderID) then
   tCredentials = textutils.unserialize(sentCredentials)
   print ( "Username = " .. tCredentials[1] .. " with Passowrd = " .. tCredentials[2] )
   sUserType = ValidateUser(tCredentials[1], tCredentials[2])
   print ("UserType = " .. sUserType)
   rednet.send(initialSenderID, sUserType)
   if sUserType == "ADMIN" or sUserType == "USER" then
	sendReport()
   end
   initialSenderID, sentCredentials = rednet.receive()
  end
end
end

Front End Client
Spoiler
--[[ Door Control Program ]]--
-- BUILD IN PROGRESS

--[[ Local Variables ]]--
bRunning = true	 -- DO NOT CHANGE THESE BOOLEAN VALUES. AT ALL. BIG MISTAKE.
bCheckForLockDown = true
bWaitingForUser = false
bInUserLoginScreen = false
bInPassLoginScreen = false
bInUserMenu = false
bInAdminMenu = false
bSystemFailSafe = true
local nTermWidth, nTermHeight = term.getSize()
sWirelessModemSide = "right" -- Change to the side of the wireless modem.
sBundledCableSide = "left"  -- Change to the side of the bundled cable.
local lockDownRedstoneCheck = redstone.testBundledInput( sBundledCableSide, 16384 ) -- BTW that colour is red.
loginServerID = 2   -- Change server IDs to match their respective jobs.
activityLogServerID = 0
sLocalDoorCode = "D1"  -- Change to the name of the appropriate door.
--[[ Local Functions ]]--
function clearScreen()
term.clear()
term.setCursorPos(1,1)
end
function printCentered( nStartHeight, sString )
term.setCursorPos( nTermWidth/2 - string.len( sString )/2 + 1, nStartHeight )
term.write( sString )
end
function printErrorMessage( sErrorCode )
term.clear()
term.setCursorPos( 1,1 )
print( "An unexpected error has occurred, please contact\nthe Network Administrator and quote the error code,\nso they can help solve your problem.\n\nSorry for any inconvenience.\n\nError Code: "..sErrorCode.."\nSysCon v1.1" )
sleep( 5 )
os.shutdown()
end
function SendStatusReport( sStatusToBeSent )
tTable = { sUserType, enteredUsername, sStatusToBeSent }
sTable = textutils.serialize( tTable )
rednet.send( activityLogServerID, sTable )
end
--[[ Program Start ]]--
clearScreen()
print( "Loading program, please wait..." )
sleep( 1 )
print( "Load complete." )
sleep( 0.5 )
clearScreen()
rednet.open( sWirelessModemSide )
print( "Rednet port opened on side: "..sWirelessModemSide )
sleep( 0.5 )
while bRunning do
while bCheckForLockDown do
  clearScreen()
  print( "Checking systems..." )
  sleep( 0.5 )
  while lockDownRedstoneCheck do	 -- This will actually need to do something in the future... Where in case of lock-down, only admins can access terminals.
   clearScreen()
   print( "Currently unstable..." )
   -- SECTION INCOMPLETE
  end
  print( "Check complete. Starting core functions." )
  sleep( 1 )
  bCheckForLockDown = false
  -- bWaitingForUser = true
  bInUserLoginScreen = true
end

while bWaitingForUser do   -- This section of code is curently unused as I can't seem to clear the buffer of the os.pullEvent( "key" )
  clearScreen()
  printCentered( 9, "Press 'L' To Login" )
  printCentered( 12, "** WARNING: Roaming Logon Enabled **" )
  local sEvent, lKey = os.pullEvent( "key" )
  if lKey == keys.l then
   bInUserLoginScreen = true
   bWaitingForUser = false
  end

end

while bInUserLoginScreen do
  clearScreen()
  printCentered( 3, "Enter Username then Press Enter" )
  printCentered( 5, "Enter 'Q' into Username to Quit" )
  printCentered( 8, "############################" )
  printCentered( 9, "# Username:				#" )
  printCentered( 10, "############################" )
  printCentered( 11, "# Password:				#" )
  printCentered( 12, "############################" )
  printCentered( 14, "** WARNING: Roaming Logon Enabled **" )
  term.setCursorPos( nTermWidth/2 - string.len( "# Username:				#" )/2 + 12, 9 )
  enteredUsername = read()
  if enteredUsername == "q" then
   bInUserLoginScreen = false
   bRunning = false
   os.shutdown()
  elseif enteredUsername == "Q" then
   bInUserLoginScreen = false
   bRunning = false
   os.shutdown()
  elseif enteredUsername == "756312746815634" then
   clearScreen()
   print( "Machine debug overide key detected, please wait..." )
   print( "Stopping processess..." )
   sleep( 1 )
   print( "Done." )
   sleep( 1.5 )
   print( "WARNING: SYSTEM IS NOW VULNERABLE.\n		 PLEASE REBOOT WHEN FINISHED." )
   print( "WARNING: ACTIVITY LOG HAS BEEN NOTIFIED." )
   sleep( 1 )
   tTable = { "SYSTEM", "TERMINAL", "MACHINE HAS ENTERED DEBUG MODE." }
   sTable = textutils.serialize( tTable )
   rednet.send( activityLogServerID, sTable )
   bInUserLoginScreen = false
   bRunning = false
   bSystemFailSafe = false
  else
   bInPassLoginScreen = true
   bInUserLoginScreen = false
  end
end

while bInPassLoginScreen do
  term.setCursorPos( nTermWidth/2 - string.len( "# Password:				#" )/2 + 12, 11 )
  enteredPassword = read( "*" )
  tCredentials = { enteredUsername, enteredPassword }
  sCredentials = textutils.serialize(tCredentials)
  rednet.send( loginServerID, sCredentials )
  senderId, sUserType = rednet.receive()
  if senderId == loginServerID then
   print(sUserType)
   if sUserType == "ADMIN" then
	clearScreen()
	bInAdminMenu = true
	bInPassLoginScreen = false
	print( "Authentication successful. Please wait." )
  
   elseif sUserType == "USER" then
	clearScreen()
	bInUserMenu = true
	bInPassLoginScreen = false
	print( "Authentication successful. Please wait." )
   else
	printCentered( 16, "Authentication failed. Please try again." )
	bInPassLoginScreen = false
	bInUserLoginScreen = true
	sleep( 1.5 )
   end
  end
end

while bInUserMenu do
  clearScreen()
  print( "Successfully got to User Menu." )
  printCentered( 3, "Press the number to select option." )
  term.setCursorPos( 17, 6 )
  print( "[1] Open Doors" )
  term.setCursorPos( 17, 7 )
  print( "[2] Log Out" )
  term.setCursorPos( 17, 8 )
  print( "[3] Shutdown" )
  local sEvent, nKey = os.pullEvent( "key" )
  if nKey == 2 then
   clearScreen()
   print( "Option 1 has been selected." )
   print( "Doors will open for 3 seconds, please wait..." )
   print( "WARNING: Notifying Activity Log..." )
   SendStatusReport( "User has opened door: " .. sLocalDoorCode )
   sleep( 0.5 )
   -- SECTION INCOMPLETE
   -- Make doors open and stuff like that for 3 seconds
   sleep( 3 )
   print( "Auto-logout, logging out, please wait..." )
   SendStatusReport( "User has logged out." )
   sleep( 1.5 )
   bInUserMenu = false
   bCheckForLockDown = true
  elseif nKey == 3 then
   clearScreen()
   print( "Logging out, please wait..." )
   sleep( 1.5 )
   bInUserMenu = false
   bCheckForLockDown = true
   SendStatusReport( "User has logged out." )
  elseif nKey == 4 then
   clearScreen()
   print( "Shutting down, please wait..." )
   SendStatusReport( "User has logged out." )
   sleep( 1.5 )
   bInUserMenu = false
   bRunning = false
   os.shutdown()
  end
end

while bInAdminMenu do
  clearScreen()
  print( "Successfully got to Admin Menu." )
  -- SECTION INCOMPLETE...
  sleep( 2 )
end
end
while bSystemFailSafe do
printErrorMessage( "#001-A" )
end
print( "The program has terminated." )

Activity Log
Spoiler
--[[ Activity Log ]]--
--[[
Notes:
- Program is designed to run on a monitor for easy use and viewing.
-
]]--
--[[ Local Variables ]]--
bRunning = true
sWirelessModemSide = "right"  -- Change modem side as required, default is "right" for testing purposes.
nWriteLineHeight = 2
tAcceptedSenders = { 1, 2, 3, 4 } -- Change to match accepted senders

--[[ Local Functions ]]--
function printStatus()
local t = os.time()
t = textutils.formatTime( t, true )
print( "[ " .. t .. " ] >> " .. tStatusReport[1] .. "-" .. tStatusReport[2] .. "; Terminal: " .. initialSenderID )
print( "		  >> " .. tStatusReport[3] )
end
function clearScreen()
term.clear()
term.setCursorPos(1,1)
end
function IsAcceptableTerminal(nTerminalID)
for i = 1, #tAcceptedSenders do
  if tAcceptedSenders[i] == nTerminalID then
   return true
  end
end
return false
end

--[[ Program Start ]]--
clearScreen()
print("")
while bRunning do
x, y = term.getCursorPos()
term.setCursorPos( 1, 1 )
print( "Activity Log Server Online, Hold Ctl-T to Quit" )
term.setCursorPos(x, y)

rednet.open( sWirelessModemSide )
initialSenderID, sentStatusReport = rednet.receive()
if IsAcceptableTerminal( initialSenderID ) then
  tStatusReport = textutils.unserialize( sentStatusReport )
  printStatus()
  nWriteLineHeight = nWriteLineHeight + 2
end
end




SFND.
ciba43 #2
Posted 04 August 2012 - 09:22 AM
Cool. I already coded something similar, but it wont be out. I am still coding it. It will be justForFun.
Stirfry Noodles #3
Posted 04 August 2012 - 09:36 AM
Yea same :P/>/> but i had a few issues which I've now fixed! ;)/>/>
Stirfry Noodles #4
Posted 07 June 2013 - 07:53 AM
Just removing posts, sorta…

Read the first post for info :D/>
Cruor #5
Posted 07 June 2013 - 07:56 AM
Moved to general until code to show.
Stirfry Noodles #6
Posted 07 June 2013 - 09:20 PM
Again, removing posts… :/
Stirfry Noodles #7
Posted 08 June 2013 - 12:24 AM
You guessed it, removing posts… :(/>
Stirfry Noodles #8
Posted 08 June 2013 - 12:26 AM
Moved to general until code to show.

Well, there's code now :D/>
Cruor #9
Posted 08 June 2013 - 09:02 AM
Please use the fancy little 'edit' button, it does wonders.
Stirfry Noodles #10
Posted 11 June 2013 - 05:58 AM
Please use the fancy little 'edit' button, it does wonders.

I was thinking of deleting this post and starting again… Know how?

p.s. no need to use sarcasm :)/> I'm semi new seeing as I haven't used this site much as you can see :)/>
Stirfry Noodles #11
Posted 11 June 2013 - 06:26 AM
Moved to general until code to show.

Btw, maybe you want to move it back to programs?
superaxander #12
Posted 11 June 2013 - 06:28 AM
Report your topic to get it moved
Stirfry Noodles #13
Posted 11 June 2013 - 06:56 AM
Report your topic to get it moved

Sorry I'm reallyyyyy new at this, how do I do that?? :/
superaxander #14
Posted 11 June 2013 - 07:43 AM
Under your first post click report. Then you can type in a message to the moderators like: "Please move my thread to the programs section"
Tiin57 #15
Posted 11 June 2013 - 09:36 AM
A while true inside an effective while true? Point being…?
lesauvage #16
Posted 11 June 2013 - 10:35 AM
Why am a getting this ?
Stirfry Noodles #17
Posted 11 June 2013 - 10:03 PM
A while true inside an effective while true? Point being…?

If you are referring to the bRunning while loop then that is to ensure the system stays secure, ie. it can't be terminated, unless you used the debug key, which i suggest you change once you implement it. The other loops were a way of containing the sections of code and keeping it neat, overall the loops are not probably not all that necessary sometimes, however it makes it easy to understand what's happening. ie. only one while loop is active at a time and each sets off the next meaning you have a eternal loop between them all.

Why am a getting this ?


Sorry, another mistake on my part, but if you have a look at the code, the only reason that line runs is because the main Boolean value has been set to false in the admin section as well as when the program terminates.. I'll fix that now… Sorry about that :P/> The point of that error code is so that if somehow the program does escape the bRunning = true while loop the terminal can stay secure and will shut itself down.

I'll repost the program, a newer version btw :P/> I'm recently been updating heavily and simplifying things.
Dave-ee Jones #18
Posted 15 June 2013 - 07:09 AM
Hmm…the login system isn't the best. I made my own login system that allows you to login, register, remove, change your username/password on any account. It is really secure (except against me :P/> I made it, I know it's weaknesses). If you want I can PM you a version?