Advertisement
the_lad

Server

Nov 13th, 2019 (edited)
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --functions
  2. function clear()
  3.   term.clear()
  4.   term.setCursorPos(1,1)
  5.   term.setTextColor(colors.red)
  6.   print("NEOTERRA FOUNDATION")
  7.   term.setTextColor(colors.white)
  8.   print("Hosting On: ".."[Redacted]")
  9. end
  10.  
  11.  
  12. function Init()
  13.   shell.run("fg")
  14.   print("Initializing...")
  15.   --open rednet
  16.   local config = fs.open(".rnconfig","r").readAll()
  17.   rednet.open(tostring(config))
  18.   if rednet.isOpen() == false then
  19.     print("Could Not Open Rednet, Check .rnconfig")
  20.   else
  21.     print("Rednet Opened On Channel "..os.computerID())
  22.   end
  23.   --end rn check
  24.   -- user database
  25.   print("Loading Username Database")
  26.   if fs.exists(".users") == false then
  27.     fs.open(".users","w").write('{"admin"}')
  28.     print("Creating User Database")
  29.   else
  30.     print("User Database Found")
  31.   end
  32.   --end user database check
  33.   -- password database check
  34.   print("Loading Password Database")
  35.   if fs.exists(".passwords") == false then
  36.     fs.open(".passwords","w").write('{"admin"}')
  37.     print("Creating Password Database")
  38.   else
  39.   print("Password Database Found")
  40.   end  
  41.   --end password check
  42. end
  43.  
  44. function load(name)
  45.   local file = fs.open(name, "r")
  46.   local data = file.readAll()
  47.   file.close()
  48.   return textutils.unserialise(data)
  49. end
  50.  
  51. function Host()
  52.   local log = fs.open(".log", "w")
  53.   while true do
  54.     local log = fs.open(".log", "a")
  55.     local client,message,protocol = rednet.receive()
  56.     --print(client.." : ".."[REDACTED]".." : "..protocol)
  57.     log.writeLine(client..' '..message..' '..protocol)
  58.     local cli = tonumber(client)
  59.     i = tonumber(UID)
  60.     --UID
  61.     if protocol == "UID" then
  62.       UID = message
  63.       print("UID set to :"..message.." : "..client)
  64.       rednet.send(cli, "confirm","response")
  65.     end
  66.     --USERNAME
  67.     if protocol == "username" then        
  68.         if message == UserData[i] then
  69.          print("Username: "..message.." : "..client)
  70.          rednet.send(cli,"confirm","response")
  71.         else
  72.           printError("Username Rejected")
  73.           rednet.send(cli, "denied","response")
  74.         end
  75.     end
  76.     --PASSWORD
  77.     if protocol == "password" then
  78.       if message == PassData[i] then
  79.         print("Password: ".."[REDACTED]".." : "..client)
  80.         rednet.send(cli, "confirm","response")
  81.       else
  82.         printError("Password Rejected")
  83.         rednet.send(cli, "denied","response")
  84.       end
  85.     end
  86.     --SSH
  87.     if protocol == "ssh" then
  88.       local result = shell.run(message)
  89.       rednet.send(client, result, "ssh")
  90.     end
  91.     log.close()
  92.   end
  93. end
  94.  
  95. --Start
  96. Init()
  97. print("Init Complete!")
  98. sleep(1)
  99. clear()
  100. UserData = load(".users")
  101. print("Loaded User Database!")
  102. sleep(1)
  103. PassData = load(".passwords")
  104. print("Loaded Password Database")
  105. sleep(1)
  106. clear()
  107. print("Hosting...")
  108. local UID = 1
  109. sleep(1)
  110. clear()
  111. Host()
  112.  
  113. --test
  114. --print("Test:")
  115. --print(UserData[2])
  116. --print(PassData[2])
  117. --sleep(1)
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement