Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local ID
- local PIN
- local settings
- local modem
- local drive
- local lan
- local accelerator
- local function setup()
- modem.closeAll()
- write("Transmitting modem channel (get this from the ATM server admin) [Default: " .. settings["channel"]["transmit"] .. "]: ")
- settings["channel"]["transmit"] = tonumber(read()) or settings["channel"]["transmit"]
- write("Receiving modem channel (this can be whatever you want) [Default: " .. settings["channel"]["receive"] .. "]: ")
- settings["channel"]["receive"] = tonumber(read()) or settings["channel"]["receive"]
- modem.open(settings["channel"]["transmit"])
- modem.open(settings["channel"]["receive"])
- write("Use cryptographic accelerator if attached [Default: " .. tostring(settings["crypto"]["enabled"]) .. "]: ")
- local function setCryptoTrue()
- print("Contacting server for public key (timeout: 5 seconds)...")
- modem.transmit(settings["channel"]["transmit"],settings["channel"]["receive"],{0,os.getComputerID()})
- local setupTimer = os.startTimer(5)
- local eventData
- repeat
- eventData = { os.pullEvent() }
- until ( eventData[1] == "modem_message" and eventData[3] == settings["channel"]["receive"] and eventData[5][1] == 0 and eventData[5][2] == os.getComputerID() ) or ( eventData[1] == "timer" and eventData[2] == setupTimer )
- if eventData[1] == "modem_message" then
- if eventData[5][3] == 0 then
- settings["crypto"]["key"] = eventData[5][4]
- settings["crypto"]["enabled"] = true
- print("Public key received and saved. Cryptographic accelerator support is now enabled.")
- elseif eventData[5][3] == 1 then
- print("The server has reported that it does not support encryption, and no public key was received. Cryptographic accelerator support will now be disabled.")
- settings["crypto"]["enabled"] = false
- else
- print("An unexpected response was received from the server (" .. textutils.serialize(eventData[5]) .. "), and no public key was received. Cryptographic accelerator support will now be disabled.")
- settings["crypto"]["enabled"] = false
- end
- else
- print("The request from the server timed out. No public key was received, and cryptographic accelerator support will now be disabled.")
- settings["crypto"]["enabled"] = false
- end
- end
- local function setCryptoFalse()
- settings["crypto"]["enabled"] = false
- end
- local cryptoFunctionLookup = {
- ["true"] = setCryptoTrue,
- ["false"] = setCryptoFalse
- }
- local selection = read()
- if cryptoFunctionLookup[selection] then
- cryptoFunctionLookup[selection]()
- else
- cryptoFunctionLookup[settings["crypto"]["enabled"]]()
- end
- local fileHandle = io.open(".accountRegistrar_settings","w")
- fileHandle:write(textutils.serialize(settings))
- fileHandle:close()
- print("Configuration complete. Press any key to continue.")
- os.pullEvent("key")
- sleep(0)
- end
- for k,v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "modem" then
- modem = peripheral.wrap(v)
- elseif peripheral.getType(v) == "drive" then
- drive = v
- elseif peripheral.getType(v) == "LAN NIC" then
- lan = peripheral.wrap(v)
- elseif peripheral.getType(v) == "cryptographic accelerator" then
- accelerator = peripheral.wrap(v)
- end
- end
- if not modem or not lan then
- print("Please attach a wireless and LAN modem, and restart the program.")
- return
- end
- if not fs.exists(".accountRegistrar_settings") then
- settings = {}
- settings["channel"] = {["transmit"]=1,["receive"]=2}
- settings["crypto"] = {["enabled"]=true}
- term.clear()
- term.setCursorPos(1,1)
- print("First time setup.")
- print("To modify these values later, use 'settings' as an argument for this program.")
- setup()
- else
- local fileHandle = io.open(".accountRegistrar_settings","r")
- settings = textutils.unserialize(fileHandle:read())
- fileHandle:close()
- if tArgs[1] == "settings" then
- term.clear()
- term.setCursorPos(1,1)
- setup()
- end
- modem.open(settings["channel"]["transmit"])
- modem.open(settings["channel"]["receive"])
- end
- if not drive or not disk.getLabel(drive) then
- term.clear()
- term.setCursorPos(1,1)
- print("No drive containing valid labeled card found.")
- write("Enter ID: ")
- repeat
- ID = read()
- until #ID > 0
- else
- ID = disk.getLabel(drive)
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Bank Deposit Terminal")
- if not ( settings["crypto"]["enabled"] and accelerator ) then
- print("NOTE: This terminal is not using a secure connection! Do not enter any personal information unless you accept and understand the risks.")
- end
- print("Hello " .. ID)
- write("Enter PIN: ")
- local PIN = read("*")
- if settings["crypto"]["enabled"] and accelerator then
- local key = accelerator.decodeKey("RSA",settings["crypto"]["key"])
- ID = key.encrypt("RSA",ID)
- PIN = key.encrypt("RSA",PIN)
- end
- print("Contacting collection turtle (timeout: 5 seconds)...")
- local turtleTimer = os.startTimer(5)
- local receivedResponse = false
- lan.send(textutils.serialize({0}))
- local eventData
- repeat
- local posx, posy
- eventData = { os.pullEvent() }
- if eventData[1] == "lan_message" and textutils.unserialize(eventData[5])[1] == 1 then
- print("Please throw ingots into hopper and press Return to continue")
- print("NOTE: If any ingots are thrown into the hopper when the transaction has completed, no funds will be added!")
- receivedResponse = true
- posx, posy = term.getCursorPos()
- elseif eventData[1] == "lan_message" and textutils.unseralize(eventData[5])[1] == 2 then
- term.setCursorPos(posx,posy)
- print("Current funds added: ")
- print("MC Dollars: " .. textutils.unseralize(eventData[5])[2]*100)
- print("Gold ingots: " .. textutils.unseralize(eventData[5])[2])
- end
- until ( eventData[1] == "timer" and eventData[2] == turtleTimer and not receivedResponse ) or ( eventData[1] == "key" and eventData[2] == 28 )
- if eventData[1] == "timer" then
- print("The collection turtle did not reply. The program will now terminate.")
- return
- end
- print("Contacting collection turtle for final value (timeout: 5 seconds)...")
- local finalValueTimer = os.startTimer(5)
- lan.send(textutils.serialize({3}))
- repeat
- eventData = os.pullEvent()
- until ( eventData[1] == "timer" and eventData[2] == finalValueTimer ) or ( eventData[1] == "lan_message" and textutils.unseralize(eventData[5])[1] == 4 )
- if eventData[1] == "timer" then
- print("The collection turtle did not reply. The program will now terminate.")
- return
- end
- print("Contacting server (timeout: 5 seconds)...")
- modem.transmit(settings["wireless"]["transmit"],settings["wireless"]["receive"],{2,os.getComputerID(),settings["crypto"]["enabled"],ID,PIN,textutils.unserialize(eventData[5])[2]})
- local depositTimer = os.startTimer(5)
- repeat
- eventData = { os.pullEvent() }
- until ( eventData[1] == "modem_message" and eventData[3] == settings["channel"]["receive"] and eventData[5][1] == 2 and eventData[5][2] == os.getComputerID()) or ( eventData[1] == "timer" and eventData[2] == depositTimer )
- if eventData[1] == "modem_message" then
- if eventData[5][3] == 0 then
- print("The deposit was completed successfully.")
- else
- print("An unexpected response was received from the server (" .. textutils.serialize(eventData[5]) .. "). The deposit was likely not successful.")
- end
- else
- print("The request from the server timed out. The deposit likely did not go through.")
- end
- modem.closeAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement