Advertisement
cadergator10

LegacyAutoInstaller

Aug 27th, 2021 (edited)
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 34.91 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local io = require("io")
  4. local ser = require("serialization")
  5. local fs = require("filesystem")
  6. local shell = require("shell")
  7. local event = require("event")
  8. local modem = component.modem
  9. local modemPort = 199
  10.  
  11. local tableToFileCode = "https://raw.githubusercontent.com/cadergator10/opencomputer-security-system/main/src/libraries/tableToFile.lua"
  12. local singleCode = {"https://raw.githubusercontent.com/cadergator10/opencomputer-security-system/main/src/doorcontrols/1.%23.%23/singleDoor.lua",nil}
  13. local multiCode = {"https://raw.githubusercontent.com/cadergator10/opencomputer-security-system/main/src/doorcontrols/1.%23.%23/multiDoor.lua",nil}
  14. local program = "ctrl.lua"
  15. local tableToFileName = "tableToFile.lua"
  16. local settingFileName = "doorSettings.txt"
  17.  
  18. local ExperimentalCode = false
  19.  
  20. local settingData2 = {}
  21. local randomNameArray = {"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m"}
  22.  
  23. local function save(table, location)
  24.   --saves a table to a file
  25.   local tableFile = assert(io.open(location, "w"))
  26.   tableFile:write(ser.serialize(table))
  27.   tableFile:close()
  28. end
  29. local function loadT(location)
  30.   --returns a table stored in a file.
  31.   local tableFile = assert(io.open(location))
  32.   return ser.unserialize(tableFile:read("*all"))
  33. end
  34.  
  35. local function runInstall(multi,num,accelerate,from2,port2,barcode)
  36.     local settingData = {}
  37.     if multi == false then --single
  38.        
  39.         if accelerate == true then
  40.             local e,from,port,text
  41.             from = from2
  42.             port = port2
  43.             modem.send(from,port,"clearTerm")
  44.                     modem.send(from,port,"print","downloading files...")
  45.                     os.execute("wget -f " .. singleCode[1] .. " " .. program)
  46.                     modem.send(from,port,"print","ONLY ENTER NUMBERS FOR ALL THE SETTINGS! NO WORDS")
  47.                     modem.send(from,port,"print","Door Type? 0= doorcontrol. 1=redstone. 2=bundled. 3=rolldoor")
  48.                     modem.send(from,port,"getInput")
  49.                     e, _, from, port, _, text = event.pull("modem_message")
  50.                     settingData["doorType"] = tonumber(text)  
  51.                     if(tonumber(text) == 1) then
  52.                         modem.send(from,port,"print","What side? 0=bottom, 1=top, 2=back, 3=front, 4=right, 5=right")
  53.                         modem.send(from,port,"getInput")
  54.                         e, _, from, port, _, text = event.pull("modem_message")
  55.                         settingData["redSide"] = tonumber(text)
  56.                         modem.send(from,port,"print","No need for redColor! The settings you inputted dont require it :)")
  57.                         settingData["redColor"] = 0
  58.                     elseif(tonumber(text) == 2) then
  59.                         modem.send(from,port,"print","What side? 0=bottom, 1=top, 2=back, 3=front, 4=right, 5=right")
  60.                         modem.send(from,port,"getInput")
  61.                         e, _, from, port, _, text = event.pull("modem_message")
  62.                         settingData["redSide"] = tonumber(text)
  63.                         modem.send(from,port,"print","What color. Use the Color API wiki provided in discord, and enter the NUMBER")
  64.                         modem.send(from,port,"getInput")
  65.                         e, _, from, port, _, text = event.pull("modem_message")
  66.                         settingData["redColor"] = tonumber(text)
  67.                     else
  68.                         modem.send(from,port,"print","No need for redSide or redColor! The settings you inputted dont require it :)")
  69.                         settingData["redSide"] = 0
  70.                         settingData["redColor"] = 0
  71.                     end
  72.                     modem.send(from,port,"print","Should the door be toggleable, or not? 0 for auto close and 1 for toggleable")
  73.                     modem.send(from,port,"getInput")
  74.                     e, _, from, port, _, text = event.pull("modem_message")
  75.                     settingData["toggle"] = tonumber(text)
  76.                     if(tonumber(text) == 0) then
  77.                         modem.send(from,port,"print","How long should the door stay open in seconds?")
  78.                         modem.send(from,port,"getInput")
  79.                         e, _, from, port, _, text = event.pull("modem_message")
  80.                         settingData["delay"] = tonumber(text)
  81.                     else
  82.                         modem.send(from,port,"print","No need to change delay! Previous setting doesnt require it :)")
  83.                         settingData["delay"] = 0
  84.                     end
  85.                     modem.send(from,port,"print","What should be read? 0 = level; 1 = armory level; 2 = MTF;")
  86.                     modem.send(from,port,"print","3 = GOI; 4 = Security; 5 = Department; 6 = Intercom; 7 = Staff")
  87.                     modem.send(from,port,"getInput")
  88.                     e, _, from, port, _, text = event.pull("modem_message")
  89.                     settingData["cardRead"] = tonumber(text)
  90.                     if(tonumber(text) <= 1 or tonumber(text) == 5) then
  91.                         modem.send(from,port,"print","Access Level of what should be read?")
  92.                         modem.send(from,port,"print","if level or armory level, enter the level that it should be.")
  93.                         modem.send(from,port,"print","if department: 1=SD, 2=ScD, 3=MD, 4=E&T, 5=O5")
  94.                         modem.send(from,port,"getInput")
  95.                         e, _, from, port, _, text = event.pull("modem_message")
  96.                         settingData["accessLevel"] = tonumber(text)
  97.                     else
  98.                         modem.send(from,port,"print","No need to set access level. This mode doesnt require it :)")
  99.                         settingData["accessLevel"] = 0
  100.                     end
  101.                     modem.send(from,port,"print","Is this door opened whenever all doors are asked to open? Not necessary if this is not Site 91")
  102.                     modem.send(from,port,"print","0 if no, 1 if yes. Default is yes")
  103.                     modem.send(from,port,"getInput")
  104.                     e, _, from, port, _, text = event.pull("modem_message")
  105.                     settingData["forceOpen"] = tonumber(text)
  106.                     modem.send(from,port,"print","Is this door immune to lock door? Not necessary if this is not Site 91")
  107.                     modem.send(from,port,"print","0 if no, 1 if yes. Default is no")
  108.                     modem.send(from,port,"getInput")
  109.                     e, _, from, port, _, text = event.pull("modem_message")
  110.                     settingData["bypassLock"] = tonumber(text)
  111.                     modem.send(from,port,"print","Installing table to file")
  112.                     os.execute("wget -f " .. tableToFileCode .. " " .. tableToFileName)
  113.                     term.clear()
  114.                     modem.send(from,port,"clearTerm")
  115.                     modem.send(from,port,"print","All done! go back to the main computer for final information")
  116.                     print("All done! You can remove internet card now. Run " .. program .. " now to start door!")
  117.                     modem.send(from,port,"terminate")
  118.                     print("terminated connection")
  119.             return settingData
  120.         elseif accelerate == false then
  121.            
  122.             term.clear()
  123.        os.execute("wget -f " .. singleCode[1] .. " " .. program)
  124.         print("ONLY ENTER NUMBERS FOR ALL THE SETTINGS! NO WORDS")
  125.         print("Door Type? 0= doorcontrol. 1=redstone. 2=bundled. 3=rolldoor")
  126.         text = term.read()
  127.         settingData["doorType"] = tonumber(text)  
  128.         if(tonumber(text) == 1) then
  129.             print("What side? 0=bottom, 1=top, 2=back, 3=front, 4=right, 5=right")
  130.             text = term.read()
  131.             settingData["redSide"] = tonumber(text)
  132.             print("No need for redColor! The settings you inputted dont require it :)")
  133.             settingData["redColor"] = 0
  134.         elseif(tonumber(text) == 2) then
  135.             print("What side? 0=bottom, 1=top, 2=back, 3=front, 4=right, 5=right")
  136.             text = term.read()
  137.             settingData["redSide"] = tonumber(text)
  138.             print("What color. Use the Color API wiki provided in discord, and enter the NUMBER")
  139.             text = term.read()
  140.             settingData["redColor"] = tonumber(text)
  141.         else
  142.             print("No need for redSide or redColor! The settings you inputted dont require it :)")
  143.             settingData["redSide"] = 0
  144.             settingData["redColor"] = 0
  145.         end
  146.         print("Should the door be toggleable, or not? 0 for auto close and 1 for toggleable")
  147.         text = term.read()
  148.         settingData["toggle"] = tonumber(text)
  149.         if(tonumber(text) == 0) then
  150.             print("How long should the door stay open in seconds?")
  151.             text = term.read()
  152.             settingData["delay"] = tonumber(text)
  153.         else
  154.             print("No need to change delay! Previous setting doesnt require it :)")
  155.             settingData["delay"] = 0
  156.         end
  157.         print("What should be read? 0 = level; 1 = armory level; 2 = MTF;")
  158.         print("3 = GOI; 4 = Security; 5 = Department; 6 = Intercom; 7 = Staff")
  159.         text = term.read()
  160.         settingData["cardRead"] = tonumber(text)
  161.         if(tonumber(text) <= 1 or tonumber(text) == 5) then
  162.             print("Access Level of what should be read?")
  163.             print("if level or armory level, enter the level that it should be.")
  164.             print("if department: 1=SD, 2=ScD, 3=MD, 4=E&T, 5=O5")
  165.             text = term.read()
  166.             settingData["accessLevel"] = tonumber(text)
  167.         else
  168.             print("No need to set access level. This mode doesnt require it :)")
  169.             settingData["accessLevel"] = 0
  170.         end
  171.         print("Is this door opened whenever all doors are asked to open? Not necessary if this is not Site 91")
  172.         print("0 if no, 1 if yes. Default is yes")
  173.         text = term.read()
  174.         settingData["forceOpen"] = tonumber(text)
  175.         print("Is this door immune to lock door? Not necessary if this is not Site 91")
  176.         print("0 if no, 1 if yes. Default is no")
  177.         text = term.read()
  178.         settingData["bypassLock"] = tonumber(text)
  179.         print("Installing table to file: ")
  180.         os.execute("wget -f " .. tableToFileCode .. " " .. tableToFileName)
  181.         term.clear()
  182.         print("All done! You can remove internet card now. Run " .. program .. " now to start door!")
  183.             return settingData
  184.         end
  185.        
  186.     elseif multi == true then --multi
  187.        
  188.         if accelerate == true then
  189.             local e,from,port,text
  190.             from = from2
  191.             port = port2
  192.                     modem.send(from,port,"print","Would you like accelerated magreader setup?")
  193.                     if barcode then
  194.                         modem.send(from,port,"print","(instead of typing uuid you scan the devices with the tablet)")
  195.                     else
  196.                         modem.send(from,port,"print","(instead of typing uuid you swipe any card in the magnetic reader)")
  197.                     end
  198.                     modem.send(from,port,"print","1 for yes, 2 for no")
  199.                     modem.send(from,port,"getInput")
  200.                     e, _, from, port, _, text = event.pull("modem_message")
  201.                     local swipeCard = tonumber(text)
  202.                     for i=1, num, 1 do
  203.                         term.clear()
  204.                         modem.send(from,port,"print","Door # " .. i .. " is being edited:")
  205.                         local keepLoop = true
  206.                         local j
  207.                         while keepLoop do
  208.                         j = randomNameArray[math.floor(math.random(1,26))]..randomNameArray[math.floor(math.random(1,26))]..randomNameArray[math.floor(math.random(1,26))]..randomNameArray[math.floor(math.random(1,26))]
  209.                             keepLoop = false
  210.                             for key,value in pairs(settingData) do
  211.                                 if key == j then
  212.                                     keepLoop = true
  213.                                 end
  214.                             end
  215.                         end
  216.                         if swipeCard == 1 then
  217.                             if barcode then
  218.                                 modem.send(from,port,"print","Magnetic card reader? Scan the magnetic card reader with your tablet")
  219.                                 modem.send(from,port,"write","uuid: ")
  220.                                 modem.send(from,port,"analyzer")
  221.                                 e, _, from, port, _, text = event.pull("modem_message")
  222.                                 modem.send(from,port,"write",text .. "\n")
  223.                                 settingData[j] = {}
  224.                                 settingData[j]["reader"] = text
  225.                             else
  226.                                 modem.send(from,port,"print","Magnetic card reader? Swipe a card in the reader of your choice.")
  227.                                 modem.send(from,port,"write","uuid: ")
  228.                                 _, text = event.pull("magData")
  229.                                 modem.send(from,port,"write",text .. "\n")
  230.                                 settingData[j] = {}
  231.                                 settingData[j]["reader"] = text
  232.                             end
  233.                         else
  234.                             modem.send(from,port,"print","Magnetic card reader address? TEXT")
  235.                             modem.send(from,port,"getInput")
  236.                             e, _, from, port, _, text = event.pull("modem_message")
  237.                             settingData[j] = {}
  238.                             settingData[j]["reader"] = text:sub(1,-2)
  239.                         end
  240.                         modem.send(from,port,"print","Door Type? 0= doorcontrol. 2=bundled. 3=rolldoor. NEVER USE 1! NUMBER ONLY")
  241.                         modem.send(from,port,"getInput")
  242.                         e, _, from, port, _, text = event.pull("modem_message")
  243.                         settingData[j]["doorType"] = tonumber(text)
  244.                         if(tonumber(text) == 2) then
  245.                             modem.send(from,port,"print","What color. Use the Color API wiki provided in discord, and enter the NUMBER")
  246.                             modem.send(from,port,"getInput")
  247.                             e, _, from, port, _, text = event.pull("modem_message")
  248.                             settingData[j]["redColor"] = tonumber(text)
  249.                             modem.send(from,port,"print","No need to input anything for door address. The setting doesnt require it :)")
  250.                             settingData[j]["doorAddress"] = ""
  251.                         else
  252.                             modem.send(from,port,"print","No need to input anything for redColor. The setting doesnt require it :)")
  253.                             settingData[j]["redColor"] = 0
  254.                             if barcode and swipeCard then
  255.                                 modem.send(from,port,"print","What is the address for the doorcontrol/rolldoor block? Scan with tablet.")
  256.                                 modem.send(from,port,"getInput")
  257.                                 e, _, from, port, _, text = event.pull("modem_message")
  258.                                 settingData[j]["doorAddress"] = text
  259.                             else
  260.                                 modem.send(from,port,"print","What is the address for the doorcontrol/rolldoor block? text is fine.")
  261.                                 modem.send(from,port,"getInput")
  262.                                 e, _, from, port, _, text = event.pull("modem_message")
  263.                                 settingData[j]["doorAddress"] = text:sub(1,-2)
  264.                             end
  265.                         end
  266.                         modem.send(from,port,"print","Should the door be toggleable, or not? 0 for auto close and 1 for toggleable")
  267.                         modem.send(from,port,"getInput")
  268.                         e, _, from, port, _, text = event.pull("modem_message")
  269.                         settingData[j]["toggle"] = tonumber(text)
  270.                         if(tonumber(text) == 0) then
  271.                             modem.send(from,port,"print","How long should the door stay open in seconds? NUMBER ONLY")
  272.                             modem.send(from,port,"getInput")
  273.                             e, _, from, port, _, text = event.pull("modem_message")
  274.                             settingData[j]["delay"] = tonumber(text)
  275.                         else
  276.                             modem.send(from,port,"print","No need to change delay! Previous setting doesnt require it :)")
  277.                             settingData[j]["delay"] = 0
  278.                         end      
  279.                         modem.send(from,port,"print","What should be read? 0 = level; 1 = armory level; 2 = MTF;")
  280.                         modem.send(from,port,"print","3 = GOI; 4 = Security; 5 = Department; 6 = Intercom; 7 = Staff")
  281.                         modem.send(from,port,"getInput")
  282.                         e, _, from, port, _, text = event.pull("modem_message")
  283.                         settingData[j]["cardRead"] = tonumber(text)
  284.                         if(tonumber(text) <= 1 or tonumber(text) == 5) then
  285.                             modem.send(from,port,"print","Access Level of what should be read? NUMBER ONLY")
  286.                             modem.send(from,port,"print","if level or armory level, enter the level that it should be.")
  287.                             modem.send(from,port,"print","if department: 1=SD, 2=ScD, 3=MD, 4=E&T, 5=O5")
  288.                             modem.send(from,port,"getInput")
  289.                             e, _, from, port, _, text = event.pull("modem_message")
  290.                             settingData[j]["accessLevel"] = tonumber(text)
  291.                         else
  292.                             modem.send(from,port,"print","No need to set access level. This mode doesnt require it :)")
  293.                             settingData[j]["accessLevel"] = 0
  294.                         end
  295.                         modem.send(from,port,"print","Is this door opened whenever all doors are asked to open? Not necessary if this is not Site 91")
  296.                         modem.send(from,port,"print","0 if no, 1 if yes. Default is yes")
  297.                         modem.send(from,port,"getInput")
  298.                         e, _, from, port, _, text = event.pull("modem_message")
  299.                         settingData[j]["forceOpen"] = tonumber(text)
  300.                         modem.send(from,port,"print","Is this door immune to lock door? Not necessary if this is not Site 91")
  301.                         modem.send(from,port,"print","0 if no, 1 if yes. Default is no")
  302.                         modem.send(from,port,"getInput")
  303.                         e, _, from, port, _, text = event.pull("modem_message")
  304.                         settingData[j]["bypassLock"] = tonumber(text)
  305.                     end
  306.                     modem.send(from,port,"print","Installing table to file: ")
  307.                     os.execute("wget -f " .. tableToFileCode .. " " .. tableToFileName)
  308.                     modem.send(from,port,"clearTerm")
  309.                     modem.send(from,port,"print","All done! go back to the main computer for final information")
  310.                     print("All done! You can remove internet card now. Run " .. program .. " now to start door!")
  311.                     modem.send(from,port,"terminate")
  312.                     print("terminated connection")
  313.             return settingData
  314.         elseif accelerate == false then
  315.            
  316.        for i=1, num, 1 do
  317.             term.clear()
  318.             print("Door # " .. i .. " is being edited:")
  319.  
  320.             print("Magnetic card reader address? TEXT")
  321.             text = term.read()
  322.             settingData[randomNameArray[i]] = {}
  323.             settingData[randomNameArray[i]]["reader"] = text:sub(1,-2)
  324.             print("Door Type? 0= doorcontrol. 2=bundled. 3=rolldoor. NEVER USE 1! NUMBER ONLY")
  325.             text = term.read()
  326.             settingData[randomNameArray[i]]["doorType"] = tonumber(text)
  327.             if(tonumber(text) == 2) then
  328.                 print("What color. Use the Color API wiki provided in discord, and enter the NUMBER")
  329.                 text = term.read()
  330.                 settingData[randomNameArray[i]]["redColor"] = tonumber(text)
  331.                 print("No need to input anything for door address. The setting doesnt require it :)")
  332.                 settingData[randomNameArray[i]]["doorAddress"] = ""
  333.             else
  334.                 print("No need to input anything for redColor. The setting doesnt require it :)")
  335.                 settingData[randomNameArray[i]]["redColor"] = 0
  336.                 print("What is the address for the doorcontrol/rolldoor block? text is fine.")
  337.                 text = term.read()
  338.                 settingData[randomNameArray[i]]["doorAddress"] = text:sub(1,-2)
  339.             end
  340.  
  341.             print("Should the door be toggleable, or not? 0 for auto close and 1 for toggleable")
  342.             text = term.read()
  343.             settingData[randomNameArray[i]]["toggle"] = tonumber(text)
  344.             if(tonumber(text) == 0) then
  345.                 print("How long should the door stay open in seconds? NUMBER ONLY")
  346.                 text = term.read()
  347.                 settingData[randomNameArray[i]]["delay"] = tonumber(text)
  348.             else
  349.                 print("No need to change delay! Previous setting doesnt require it :)")
  350.                 settingData[randomNameArray[i]]["delay"] = 0
  351.             end      
  352.             print("What should be read? 0 = level; 1 = armory level; 2 = MTF;")
  353.             print("3 = GOI; 4 = Security; 5 = Department; 6 = Intercom; 7 = Staff")
  354.             text = term.read()
  355.             settingData[randomNameArray[i]]["cardRead"] = tonumber(text)
  356.             if(tonumber(text) <= 1 or tonumber(text) == 5) then
  357.                 print("Access Level of what should be read? NUMBER ONLY")
  358.                 print("if level or armory level, enter the level that it should be.")
  359.                 print("if department: 1=SD, 2=ScD, 3=MD, 4=E&T, 5=O5")
  360.                 text = term.read()
  361.                 settingData[randomNameArray[i]]["accessLevel"] = tonumber(text)
  362.             else
  363.                 print("No need to set access level. This mode doesnt require it :)")
  364.                 settingData[randomNameArray[i]]["accessLevel"] = 0
  365.             end
  366.             print("Is this door opened whenever all doors are asked to open? Not necessary if this is not Site 91")
  367.             print("0 if no, 1 if yes. Default is yes")
  368.             text = term.read()
  369.             settingData[randomNameArray[i]]["forceOpen"] = tonumber(text)
  370.             print("Is this door immune to lock door? Not necessary if this is not Site 91")
  371.             print("0 if no, 1 if yes. Default is no")
  372.             text = term.read()
  373.             settingData[randomNameArray[i]]["bypassLock"] = tonumber(text)
  374.        end
  375.        print("Installing table to file: ")
  376.         os.execute("wget -f " .. tableToFileCode .. " " .. tableToFileName)
  377.         term.clear()
  378.         print("All done! You can remove internet card now. Run " .. program .. " now to start door!")
  379.             return settingData
  380.         end
  381.        
  382.     end
  383. end
  384.  
  385. modem.close()
  386. term.clear()
  387. print("Checking files...")
  388. local fill = io.open(program,"r")
  389. if fill~=nil then
  390.     term.clear()
  391.     print("Old files detected. Please select an option:")
  392.     print("1 = wipe all files (maybe)")
  393.     print("2 = add more doors (very experimental)")
  394.     print("3 = delete a door (very experimental)")
  395.     print("4 = change a door (not implemented yet)")
  396.     print("5 = update door")
  397.     local text = term.read()
  398.     if(tonumber(text) == 1) then
  399.         term.clear()
  400.         print("Deleting all files...")
  401.         local path = shell.getWorkingDirectory()
  402.         fs.remove(path .. "/" .. program)
  403.         fs.remove(path .. "/" .. tableToFileName)
  404.         fs.remove(path .. "/" .. settingFileName)
  405.         print("all done!")
  406.     elseif(tonumber(text) == 2) then
  407.         print("Is this door a multi or single door. 1 for single, 2 for multi, anything else for cancel.")
  408.         text = term.read()
  409.         if tonumber(text) == 1 then
  410.             print("you cannot add more doors as this is a single door. If you want to swap to a multidoor,")
  411.             print("wipe all files and reinstall as a multidoor.")
  412.             os.exit()
  413.         elseif tonumber(text) == 2 then
  414.             settingData2 = loadT(settingFileName)
  415.             print("how many doors would you like to add?")
  416.             text = term.read()
  417.             local num = tonumber(text)
  418.             local tempArray = runInstall(true,num,false)
  419.             for key, value in pairs(tempArray) do
  420.                 settingData2[key] = value
  421.             end
  422.             save(settingData2,settingFileName)
  423.             print("Added the doors. It is recommended you check if it worked, as this is experimental.")
  424.         else
  425.             print("not an answer")
  426.             os.exit()
  427.         end
  428.     elseif(tonumber(text) == 3) then
  429.         print("Is this door a multi or single door. 1 for single, 2 for multi, anything else for cancel.")
  430.         text = term.read()
  431.         if tonumber(text) == 1 then
  432.             print("You cannot remove a door as this is a single door. This only works on a multidoor.")
  433.             print("If this is meant to be a multidoor, wipe all files and reinstall as a multidoor.")
  434.             os.exit()
  435.         elseif tonumber(text) == 2 then
  436.             settingData2 = loadT(settingFileName)
  437.             print("What is the key for the door?")
  438.             text = term.read()
  439.             settingData2[text:sub(1,-2)] = nil
  440.             save(settingData2,settingFileName)
  441.             print("Removed the door. It is recommended you check if it worked, as this is experimental.")
  442.         else
  443.             print("not an answer")
  444.             os.exit()
  445.         end
  446.     elseif(tonumber(text) == 4) then
  447.             print("Is this door a multi or single door. 1 for single, 2 for multi, anything else for cancel.")
  448.             text = term.read()
  449.         if tonumber(text) == 1 then
  450.             print("Starting single door editing...")
  451.             local tempArray = runInstall(false,0,false)
  452.                 settingData2 = tempArray
  453.                 save(settingData2,settingFileName)
  454.                 print("Old config should be overwritten. It is recommended you check if it worked, as this is experimental.")
  455.         elseif tonumber(text) == 2 then
  456.             print("What is the key of the door you would like to edit?")
  457.             text = term.read()
  458.             local thisKey = text:sub(1,-2)
  459.             settingData2 = loadT(settingFileName)
  460.                 term.clear()
  461.                 print("Door with key " .. thisKey .. " is being edited:")
  462.  
  463.             print("Magnetic card reader address? TEXT")
  464.             text = term.read()
  465.             settingData2[thisKey] = {}
  466.             settingData2[thisKey]["reader"] = text:sub(1,-2)
  467.             print("Door Type? 0= doorcontrol. 2=bundled. 3=rolldoor. NEVER USE 1! NUMBER ONLY")
  468.             text = term.read()
  469.             settingData2[thisKey]["doorType"] = tonumber(text)
  470.             if(tonumber(text) == 2) then
  471.                 print("What color. Use the Color API wiki provided in discord, and enter the NUMBER")
  472.                 text = term.read()
  473.                 settingData2[thisKey]["redColor"] = tonumber(text)
  474.                 print("No need to input anything for door address. The setting doesnt require it :)")
  475.                 settingData2[thisKey]["doorAddress"] = ""
  476.             else
  477.                 print("No need to input anything for redColor. The setting doesnt require it :)")
  478.                 settingData2[thisKey]["redColor"] = 0
  479.                 print("What is the address for the doorcontrol/rolldoor block? text is fine.")
  480.                 text = term.read()
  481.                 settingData2[thisKey]["doorAddress"] = text:sub(1,-2)
  482.             end
  483.  
  484.             print("Should the door be toggleable, or not? 0 for auto close and 1 for toggleable")
  485.             text = term.read()
  486.             settingData2[thisKey]["toggle"] = tonumber(text)
  487.             if(tonumber(text) == 0) then
  488.                 print("How long should the door stay open in seconds? NUMBER ONLY")
  489.                 text = term.read()
  490.                 settingData2[thisKey]["delay"] = tonumber(text)
  491.             else
  492.                 print("No need to change delay! Previous setting doesnt require it :)")
  493.                 settingData2[thisKey]["delay"] = 0
  494.             end      
  495.             print("What should be read? 0 = level; 1 = armory level; 2 = MTF;")
  496.             print("3 = GOI; 4 = Security; 5 = Department; 6 = Intercom; 7 = Staff")
  497.             text = term.read()
  498.             settingData2[thisKey]["cardRead"] = tonumber(text)
  499.             if(tonumber(text) <= 1 or tonumber(text) == 5) then
  500.                 print("Access Level of what should be read? NUMBER ONLY")
  501.                 print("if level or armory level, enter the level that it should be.")
  502.                 print("if department: 1=SD, 2=ScD, 3=MD, 4=E&T, 5=O5")
  503.                 text = term.read()
  504.                 settingData2[thisKey]["accessLevel"] = tonumber(text)
  505.             else
  506.                 print("No need to set access level. This mode doesnt require it :)")
  507.                 settingData2[thisKey]["accessLevel"] = 0
  508.             end
  509.             print("Is this door opened whenever all doors are asked to open? Not necessary if this is not Site 91")
  510.             print("0 if no, 1 if yes. Default is yes")
  511.             text = term.read()
  512.             settingData2[thisKey]["forceOpen"] = tonumber(text)
  513.             print("Is this door immune to lock door? Not necessary if this is not Site 91")
  514.             print("0 if no, 1 if yes. Default is no")
  515.             text = term.read()
  516.             settingData2[thisKey]["bypassLock"] = tonumber(text)
  517.                
  518.             term.clear()
  519.             save(settingData2,settingFileName)
  520.             print("All done! The door should have been changed! It is recommended to check if it worked, as this is experimental.")
  521.                
  522.         else
  523.             print("not an answer")
  524.             os.exit()
  525.         end
  526.     elseif(tonumber(text) == 5) then
  527.         print("Are you sure you want to do this? New updates sometimes require manual changing of config.")
  528.         print("1 for continue, 2 for cancel")
  529.         text = term.read()
  530.         if tonumber(text) == 1 then
  531.         print("Is this door a multi or single door. 1 for single, 2 for multi, anything else for cancel.")
  532.         text = term.read()
  533.         if tonumber(text) == 1 then
  534.             print("downloading...")
  535.             os.execute("wget -f " .. singleCode[1] .. " " .. program)
  536.         elseif tonumber(text) == 2 then
  537.             print("downloading...")
  538.             os.execute("wget -f " .. multiCode[1] .. " " .. program)
  539.         else
  540.            
  541.         end
  542.         end
  543.     else
  544.        
  545.     end
  546. else
  547.     if true then
  548.     term.clear()
  549.     print("LEGACY AUTOINSTALLER! Use this ONLY if you need to do something to pc 1.7.1 and below.")
  550.     print("Autoupdating a pc in this autoinstaller will mean the new autoinstaller must be used after on it.")
  551.     print("...")
  552.     print("Would you like to use an external device for accelerated setup?")
  553.     print("This makes it easier to set up doors without having to move from the door to the pc constantly.")
  554.     print("It requires the program here to be set up on a tablet with a modem: https://github.com/cadergator10/opensecurity-scp-security-system/blob/main/src/extras/acceleratedDoorSetup.lua")
  555.     print("1 for yes, 2 for no")
  556.     text = term.read()
  557.         term.clear()
  558.         if tonumber(text) == 1 then
  559.             local code = math.floor(math.random(1000,9999))
  560.             modem.open(code)
  561.             print("Code is: " .. code)
  562.             print("Enter the code into the door setup tablet. In 60 seconds setup will cancel.")
  563.             local e, _, from, port, _, msg, barcode = event.pull(60, "modem_message")
  564.             if e then
  565.                 modem.send(from,port,"connected")
  566.                 term.clear()
  567.                 print("Connection successful! All prompts will be on the tablet now on.")
  568.                 os.sleep(1)
  569.                 modem.send(from,port,"print","What kind of door do you want? 1 for single door, 2 for multidoor")
  570.                 modem.send(from,port,"getInput")
  571.                 e, _, from, port, _, text = event.pull("modem_message")
  572.                 if tonumber(text) == 1 then
  573.                     local tempArray = runInstall(false,0,true,from,port,barcode)
  574.                     settingData2 = tempArray
  575.                     save(settingData2,settingFileName)
  576.                     --was single accelerated
  577.                     os.exit()
  578.                 elseif tonumber(text) == 2 then
  579.                     modem.send(from,port,"clearTerm")
  580.                     modem.send(from,port,"print","Downloading code...")
  581.                     os.execute("wget -f " .. multiCode .. " " .. program)
  582.                     modem.send(from,port,"print","Read the text carefully. Some of the inputs REQUIRE NUMBERS ONLY! Some require text.")
  583.                     modem.send(from,port,"print","The redSide is always 2, or back of the computer.")
  584.                     modem.send(from,port,"print","How many different doors are there?")
  585.                     modem.send(from,port,"getInput")
  586.                     e, _, from, port, _, text = event.pull("modem_message")
  587.                     local num = tonumber(text)
  588.                     local tempArray = runInstall(true,num,true,from,port,barcode)
  589.                     settingData2 = tempArray
  590.                     save(settingData2,settingFileName)
  591.                     --was multi accelerated
  592.                     os.exit()
  593.                 else
  594.                     term.clear()  
  595.                     modem.send(from,port,"print","not an answer")
  596.                     modem.send(from,port,"terminated connection")
  597.                     print("terminated")
  598.                     os.exit()
  599.                 end
  600.             else
  601.                 modem.close(code)
  602.                 print("Setup cancelled")
  603.                 os.exit()
  604.             end
  605.            else
  606.                 term.clear()
  607.     print("What kind of door do you want? 1 for single door, 2 for multidoor")
  608.     local text = term.read()
  609.     if(tonumber(text) == 1) then
  610.                 local tempArray = runInstall(false,0,false)
  611.                 settingData2 = tempArray
  612.                 save(settingData2,settingFileName)
  613.        --was single normal
  614.     elseif(tonumber(text) == 2) then
  615.                             term.clear()
  616.        os.execute("wget -f " .. multiCode[1] .. " " .. program)
  617.        print("Read the text carefully. Some of the inputs REQUIRE NUMBERS ONLY! Some require text.")
  618.        print("The redSide is always 2, or back of the computer.")
  619.        print("How many different doors are there?")
  620.        local num = tonumber(term.read())
  621.                 local tempArray = runInstall(true,num,false)
  622.                 settingData2 = tempArray
  623.                 save(settingData2,settingFileName)
  624.        --was multi normal
  625.     else
  626.        term.clear()  
  627.        print("Not an answer:" .. text)
  628.     end
  629.         end
  630.     end
  631. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement