Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Server
- -- Functions
- function continue()
- print("scanning 2")
- from,rp2=rednet.receive(5)
- sleep(1)
- print("scanning 3")
- from,rp3=rednet.receive(5)
- sleep(1)
- print("scanning 4")
- from,rp4=rednet.receive(5)
- if rp1=="login" then login()
- elseif rp1=="register" then userreg()
- elseif rp1=="shutdown" then ashutdown()
- elseif rp1=="userdel" then userdel()
- elseif rp1=="usercpass" then usercpass()
- elseif rp1=="reboot" then reboot()
- elseif rp1=="test" then test()
- elseif rp1=="print" then print()
- elseif rp1=="reset" then reset()
- end
- end
- function print()
- print(rp3, ":", rp2) -- line 25
- end
- function test()
- print("recieved test")
- rednet.broadcast("test")
- end
- function reset()
- print("resetting")
- fs.delete("users/admin")
- fs.makeDir("users/admin")
- fs.makeDir("users/admin/" .. rp2)
- fs.makeDir("users/admin/priv")
- fs.makeDir("users/admin/priv/superuser")
- print("admin password set with privalege superuser remotely")
- end
- function reboot()
- print("rebooting")
- os.reboot()
- end
- function usercpass()
- if fs.exists("users/" .. rp2) and fs.exists("users/" .. rp2 .. "/" .. rp3) then
- fs.delete("users/" .. rp2 .. "/" .. rp3)
- fs.makeDir("users/" .. rp2 .. "/" .. rp4)
- print("successfully change password for user ", rp2)
- rednet.broadcast("success")
- else
- rednet.broadcast("exists")
- end
- end
- function userdel()
- if fs.exists("users/".. rp2) then
- fs.delete("users/".. rp2)
- print("deleted user")
- rednet.broadcast("success")
- else
- rednet.broadcast("exists")
- end
- end
- function loginpriv()
- print(rp2, " found. sending admin login codes")
- sleep(2)
- rednet.broadcast(rp1)
- sleep(2)
- rednet.broadcast(rp2)
- sleep(2)
- rednet.broadcast(rp4)
- sleep(2)
- rednet.broadcast("superuser")
- print(rp2, ":", rp4, ":", "superuser:has logged in")
- end
- function loginnorm()
- if fs.exists("users/" .. rp2 .. "/" .. rp3) then
- print(rp2, " found. sending norm login codes")
- sleep(2)
- rednet.broadcast(rp1)
- sleep(2)
- rednet.broadcast(rp2)
- sleep(2)
- rednet.broadcast(rp4)
- sleep(2)
- rednet.broadcast("norm")
- print(rp2, ":", rp4, ":", "norm:has logged in")
- end
- end
- function loginbad()
- sleep(2)
- rednet.broadcast("bad")
- sleep(2)
- rednet.broadcast("bad")
- sleep(2)
- rednet.broadcast("bad")
- sleep(2)
- rednet.broadcast("bad")
- print(rp2, ": Bad Login")
- end
- function login()
- if fs.exists("users/" .. rp2 .. "/" .. rp3) then
- if fs.exists("users/" .. rp2 .. "/priv/superuser") then
- loginpriv()
- elseif fs.exists("users/" .. rp2 .. "/" .. rp3) then
- loginnorm()
- else
- loginbad()
- end
- end
- end
- function ashutdown()
- if fs.exists("users/" .. rp2 .. "/priv/superuser") then
- print("shutting down")
- sleep(2)
- os.shutdown()
- else
- print("attempt to shutdown failed due to wrong pass")
- end
- end
- function restart()
- end
- function userreg()
- if fs.exists("users/".. rp2) then
- print("user already exists")
- rednet.broadcast("exists")
- else
- print("registering user: ", rp2)
- fs.makeDir("users/" .. rp2)
- fs.makeDir("users/" .. rp2 .. "/" .. rp3)
- fs.makeDir("users/" .. rp2 .. "/priv/")
- fs.makeDir("users/" .. rp2 .. "/priv/" .. rp4)
- sleep(2)
- rednet.broadcast("done")
- print("Registered")
- end
- end
- --Loop Program
- print("Starting CraftOs Server Program By Alex_")
- print("which side is the modem?")
- modem=read()
- print("Admin password for session")
- apass=read()
- fs.delete("users/admin")
- fs.makeDir("users/admin")
- fs.makeDir("users/admin/" .. apass)
- fs.makeDir("users/admin/priv")
- fs.makeDir("users/admin/priv/superuser")
- print("password set with privalege superuser")
- sleep(1)
- rednet.open(modem)
- term.clear()
- term.setCursorPos(1,1)
- print("Server Started")
- print("Click CTRL For Console")
- print("===============================================")
- while true do
- print("scanning 1")
- from,rp1=rednet.receive(9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)
- if rp1=="login" then continue()
- elseif rp1=="register" then continue()
- elseif rp1=="shutdown" then continue()
- elseif rp1=="userdel" then continue()
- elseif rp1=="usercpass" then continue()
- elseif rp1=="reboot" then continue()
- elseif rp1=="test" then continue()
- elseif rp1=="print" then continue()
- elseif rp1=="reset" then continue()
- end
- end
- --Client
- term.clear()
- term.setCursorPos(1,1)
- print("Welcome to CraftOs server client program")
- print("By Alex_")
- print("Starting Up")
- fs.delete("OS/session/user")
- sleep(1)
- print("Success")
- sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- print("Login to Network")
- print("===============================================")
- print("Username")
- local sp2=read()
- print("password")
- local sp3=read()
- print("Computer ID number (only last's a session)")
- local sp4=read()
- term.clear()
- term.setCursorPos(1,1)
- print("Opening RedNet")
- rednet.open("right")
- print("Communicating With Server")
- rednet.broadcast("login")
- sleep(2)
- rednet.broadcast(sp2)
- sleep(2)
- rednet.broadcast(sp3)
- sleep(2)
- rednet.broadcast(sp4)
- while true do
- from,rp1=rednet.receive(60)
- sleep(1)
- from,rp2=rednet.receive(60)
- sleep(1)
- from,rp4=rednet.receive(60)
- sleep(1)
- from,priv=rednet.receive(60)
- sleep(1)
- if rp1=="login" and rp2==sp2 and rp4==sp4 then
- print("Writing Session Files")
- fs.makeDir("OS/session/user/" .. rp2)
- fs.makeDir("OS/session/user/" .. rp2 .. "/priv/")
- fs.makeDir("OS/session/user/" .. rp2 .. "/priv2/")
- fs.makeDir("OS/session/user/" .. rp2 .. "/priv/" .. priv)
- fs.makeDir("OS/session/user/" .. rp2 .. "/priv2/" .. priv)
- print("logging in")
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- print("logged in as ", rp2, ":", priv)
- print("===============================================")
- break
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Bad Login/Server Offline")
- print("Shutting Down")
- sleep(3)
- os.shutdown()
- end
- end
- --server console for client
- --Note (Do user priv command)
- --functions
- function main()
- term.clear()
- term.setCursorPos(1,1)
- print("Server Console")
- print("===============================================")
- main2()
- end
- function main2()
- print("#SUPERUSER:", user, ":")
- command=read()
- if command=="user" then
- print("Usage: user command")
- main2()
- elseif command=="help" then help()
- elseif command=="user register" then userreg()
- elseif command=="user help" then userhelp()
- elseif command=="user del" then userdel()
- elseif command=="user cpass" then usercpass()
- elseif command=="server" then
- print("Usage: server command")
- elseif command=="server shutdown" then servershutdown()
- elseif command=="server print" then serverprint()
- elseif command=="server reboot" then serverreboot()
- elseif command=="server reset" then serverreset()
- elseif command=="server test" then servertest()
- elseif command=="server help" then serverhelp()
- elseif command=="exit" then exit()
- else
- print("command unknown")
- main2()
- end
- end
- function serverprint()
- print("please type what you wish to send")
- print=read()
- print("printing on server")
- rednet.broadcast("print")
- sleep(2)
- rednet.broadcast(print)
- sleep(2)
- rednet.broadcast(user)
- sleep(2)
- rednet.broadcast("null")
- sleep(2)
- main2()
- end
- function serverreboot()
- print("rebooting server")
- rednet.broadcast("reboot")
- sleep(2)
- rednet.broadcast("null")
- sleep(2)
- rednet.broadcast("null")
- sleep(2)
- rednet.broadcast("null")
- main2()
- end
- function serverreset()
- print("are you sure you want to reset the server? 'Y' or 'N'")
- print("Warning: This will remove all users")
- option=read()
- if option=="n" or option=="N" then
- main2()
- elseif option=="y" or option=="Y" then
- print("Admin password for session")
- adminpass=read()
- print("reseting")
- rednet.broadcast("reset")
- sleep(2)
- rednet.broadcast(adminpass)
- sleep(2)
- rednet.broadcast("null")
- sleep(2)
- rednet.broadcast("null")
- sleep(2)
- end
- function servertest()
- print("testing server")
- rednet.broadcast("test")
- sleep(2)
- rednet.broadcast("null")
- sleep(2)
- rednet.broadcast("null")
- sleep(2)
- rednet.broadcast("null")
- sleep(2)
- from,test = rednet.receive(10)
- if test=="test" then
- print("test ok")
- main2()
- end
- function usercpass()
- print("Change password:")
- print("Username")
- cuser=read()
- print("old password")
- cpassword=read()
- print("new password")
- ccpassword=read()
- print("Changing Password")
- rednet.broadcast("usercpass")
- sleep(1)
- rednet.broadcast(cuser)
- sleep(1)
- rednet.broadcast(cpassword)
- sleep(1)
- rednet.broadcast(ccpassword)
- print("sent")
- print("checking")
- from,confirm = rednet.receive(10)
- if confirm=="success" then
- print("Successfully Changed Password")
- sleep(5)
- main()
- elseif confirm=="exists" then
- print("Does not exist/ Wrong password")
- main2()
- else print("error please check domain server")
- main2()
- end
- end
- function userpriv()
- print("Delete User:")
- print("Username")
- deluser=read()
- print("Deleting")
- rednet.broadcast("userdel")
- sleep(1)
- rednet.broadcast(deluser)
- sleep(1)
- rednet.broadcast("null")
- sleep(1)
- rednet.broadcast("null")
- print("sent")
- print("checking")
- from,confirm = rednet.receive(10)
- if confirm=="success" then
- print("Successfully Deleted")
- sleep(5)
- main()
- elseif confirm=="exists" then
- print("Does not exist")
- main2()
- else print("error please check domain server")
- main2()
- end
- end
- function userdel()
- print("Delete User:")
- print("Username")
- deluser=read()
- print("Deleting")
- rednet.broadcast("userdel")
- sleep(1)
- rednet.broadcast(deluser)
- sleep(1)
- rednet.broadcast("null")
- sleep(1)
- rednet.broadcast("null")
- print("sent")
- print("checking")
- from,confirm = rednet.receive(10)
- if confirm=="success" then
- print("Successfully Deleted")
- sleep(5)
- main()
- elseif confirm=="exists" then
- print("Does not exist")
- main2()
- else print("error please check domain server")
- main2()
- end
- end
- function help()
- print("")
- print("List of commands")
- print("server")
- print("user")
- print("exit")
- print("")
- main2()
- end
- function userhelp()
- print("")
- print("List of commands for user")
- print("register - To register a new user")
- print("del - To delete a user")
- print("cpass - Change the password of a user")
- print("priv - Change the privilege of user")
- print("help - a list of commands for user")
- print("")
- main2()
- end
- function serverhelp()
- print("")
- print("List of command for server")
- print("print - send a message to appear on the server")
- print("test - test the connection with the server")
- print("shutdown - Shutdown the server")
- print("reboot - reboot the server")
- print("hard reset - resets the server to default setting and removing all users")
- print("help - a list of commands for server")
- end
- function exit()
- term.clear()
- term.setCursorPos(1,1)
- print("Exiting Console")
- sleep(2)
- end
- function user()
- print("Usage: user command")
- main()
- end
- function userreg()
- print("Register a new user")
- print("Username")
- reguser=read()
- print("Password")
- regpassword=read()
- print("Type 'superuser' or 'norm'")
- print("*superuser - This is an admin")
- print("*norm - This is a normal User")
- print("note do not use capitals")
- regtype=read()
- print("registering")
- rednet.broadcast("register")
- sleep(1)
- rednet.broadcast(reguser)
- sleep(1)
- rednet.broadcast(regpassword)
- sleep(1)
- rednet.broadcast(regtype)
- print("sent")
- print("checking")
- from,confirm = rednet.receive(10)
- if confirm=="done" then
- print("Successfully registered")
- print("Username: ", reguser)
- print("Password: ", regpassword)
- sleep(5)
- main()
- elseif confirm=="exists" then
- print("Already Registered!!")
- main2()
- else print("error please check domain server")
- main2()
- end
- end
- function servershutdown()
- rednet.broadcast("shutdown")
- sleep(1)
- rednet.broadcast(user)
- sleep(1)
- rednet.broadcast("null")
- sleep(1)
- rednet.broadcast("null")
- end
- --program
- term.clear()
- term.setCursorPos(1,1)
- print("Server Console")
- print("===============================================")
- print("confirm username")
- user=read()
- print("checking")
- sleep(1)
- print("accessing superuser")
- sleep(1)
- if fs.exists("OS/session/user/" .. user .. "/priv/superuser") then
- if fs.exists("OS/session/user/" .. user .. "/priv2/superuser") then
- main()
- else
- term.clear()
- print("access denied")
- end
- end
Add Comment
Please, Sign In to add comment