pandorrama

dns_installer

Sep 9th, 2020 (edited)
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. --TO INSTALL JUST EXECUTE: pastebin run aj3YdtWL
  2.  
  3. local serialization = require("serialization")
  4. local fs = require("filesystem")
  5. local dlURL = "https://pastebin.com/raw/"
  6.  
  7. local remote_files = {
  8.   server = {"fnt8qcZY", "6c2fngmc", "VajLjMDv"},
  9.   client = {"g44s8ySS", "VajLjMDv"}
  10. }
  11.  
  12. local files = {
  13.   server = {"bin/dns_server.lua", "bin/dns_server_starter.lua", "lib/tableToFile.lua"},
  14.   client = {"lib/dns_client.lua", "lib/tableToFile.lua"}
  15. }
  16.  
  17. local update = fs.exists("/dns")
  18. print("Choose what to install.")
  19. print("[1] Server")
  20. print("[2] Client")
  21. local input = io.read()
  22.  
  23. io.write("Are you sure? [Y/n]: ")
  24. if (io.read():lower() == "n") then --TEST: Is this allowed?
  25.   return
  26. end
  27. local port
  28. local settings = {}
  29. if (tostring(input) == "1") then
  30.   fs.makeDirectory("/dns/bin")
  31.   fs.makeDirectory("/dns/lib")
  32.   fs.makeDirectory("/dns/data")
  33.   remote_files = remote_files.server
  34.   files = files.server
  35.   settings.LOG_FILE = "/dns/DNS_LOG.log"
  36.   settings.HOST_FILE = "/dns/data/HOSTS.txt"
  37.  
  38.   io.write("Port for DNS communication (default:'53'): ")
  39.   port = io.read()
  40.   if port == "" then
  41.     port = nil
  42.   end
  43.   settings.port = tonumber(port) or 53
  44.   io.write("Enforce 'ipv4' addresses? [Y/n]: ")
  45.   if (io.read():lower() == "y") then
  46.     settings.formalAddr = true
  47.   else
  48.     settings.formalAddr = false
  49.   end
  50. elseif (tostring(input) == "2") then
  51.   remote_files = remote_files.client
  52.   files = files.client
  53.   fs.makeDirectory("/dns/lib")
  54.   fs.makeDirectory("/dns/data")
  55.  
  56.   io.write("Port for DNS communication (default:'53'): ")
  57.   port = io.read()
  58.   if port == "" then
  59.     port = nil
  60.   end
  61.   settings.port = tonumber(port) or 53
  62. else
  63.   print("'" .. input .. "' is not '1' or '2'")
  64. end
  65.  
  66. --fs.makeDirectory("/dns")
  67. if not update then
  68.   local settingsFile = io.open("/dns/data/DNS_SETTINGS.cfg", "w")
  69.   settingsFile:write(serialization.serialize(settings))
  70.   settingsFile:close()
  71. end
  72.  
  73. for i = 1, #files do
  74.   os.execute("wget -f " .. dlURL .. remote_files[i] .. " /dns/" .. files[i])
  75. end
  76. if (tostring(input) == "1") then
  77.   if not update then
  78.     local hostFile = io.open("/dns/data/HOSTS.txt", "a")
  79.     hostFile:write("{}")
  80.     hostFile:close()
  81.  
  82. --    local shellFile = io.open(os.getenv("HOME") .. "/.shrc", "a")
  83. --    shellFile:write("/dns/bin/dns_server_starter.lua\n")
  84. --    shellFile:close()
  85.   end
  86.  
  87.   io.write("Installation finished. Do you want to start the server: [Y/n]: ")
  88.   if (io.read():lower() == "n") then
  89.     return
  90.   else
  91.     os.execute("/dns/bin/dns_server_starter.lua")
  92.     os.execute("rc dns enable")
  93.     os.execute("rc dns start")
  94.   end
  95. else
  96. --  local shellFile = io.open(os.getenv("HOME") .. "/.shrc", "a")
  97. --  shellFile:write("ln /dns/lib /usr/lib\n")
  98. --  shellFile:close()
  99.   os.execute("cp -r /dns/lib/* /usr/lib/")
  100.   print("Installation finished.")
  101. end
Add Comment
Please, Sign In to add comment