Advertisement
alexhorner

VPN API

Jun 17th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. --DevelopedLogic's modem api VPN connection
  2. --Uses PixelToast's Encryption API
  3.  
  4. --RUN VPN AS A PROGRAM BEFORE USING API ON AN NEW
  5. --COMPUTER!
  6.  
  7. --Settings
  8. password = "changeme"
  9. modemSide = "left"
  10. modemChannel = 1276
  11. pixelAPI = "/pixelapi"
  12.  
  13. --Initial Checks
  14. if fs.exists(pixelAPI) == false then
  15.   shell.run("pastebin get WRTfH0yx "..pixelAPI)
  16. end
  17.  
  18. --Functions
  19. function open()
  20.   os.loadAPI(pixelAPI)
  21.   modem = peripheral.wrap(modemSide)
  22.   modem.open(modemChannel)
  23.   modemIsOpen = true
  24. end
  25.  
  26. function close()
  27.   if modemIsOpen == true and modem.isOpen(modemChannel) == true then
  28.     modem.close(modemChannel)
  29.   else
  30.     error(0, "VPN: Modem is not open!")
  31.   end
  32. end
  33.  
  34. function push(pushData)
  35.   modem.transmit(modemChannel, modemChannel, pixelapi.encrypt(pushData, password))
  36. end
  37.  
  38. function pull()
  39.   while true do
  40.     incoming = { os.pullEvent("modem_message") }
  41.     if incoming[3] == modemChannel then
  42.       return pixelapi.decrypt(incoming[5], password)
  43.     end
  44.   end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement