Alyssa

Browser_Beta

Feb 17th, 2015
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.20 KB | None | 0 0
  1. version = 0.02
  2. if not fs.isDir("/apis") then
  3.         fs.delete("/apis/")
  4.         fs.makeDir("/apis/")
  5.         shell.run("pastebin get 9E5UHiqv /apis/AES")
  6.         shell.run("pastebin get QYvNKrXE /apis/Base64")
  7. end
  8. if not fs.exists("/apis/AES") then
  9.         shell.run("pastebin get 9E5UHiqv /apis/AES")
  10. end
  11. if not fs.exists("/apis/Base64") then
  12.         shell.run("pastebin get QYvNKrXE /apis/Base64")
  13. end
  14. os.loadAPI("/apis/AES")
  15. os.loadAPI("/apis/Base64")
  16. modem = nil
  17. browserID = "storm"
  18. for k, v in pairs(peripheral.getNames()) do
  19.         if peripheral.getType(v) == "modem" then
  20.                 modem = peripheral.wrap(v)
  21.         end
  22. end
  23. if not modem then
  24.         error("This program requires a modem!")
  25. else
  26.         modem.open(24680)
  27. end
  28. function decode(msg)
  29.     de_msg = AES.decrypt(tostring(client_id)..tostring(distance)..tostring(server_sent),Base64.decode(msg))
  30.     server_sent = server_sent +1
  31.     return de_msg
  32. end
  33. function eSend(tmsg,domain,msg)
  34.     the_key = tostring(client_id) .. tostring(distance) .. tostring(sent)
  35.     messageToSend = Base64.encode(AES.encrypt(the_key,tmsg.." "..msg))
  36.     sent = sent+1
  37.     modem.transmit(24680,client_id,"E"..domain.."|"..messageToSend)
  38. end
  39. function send(tmsg,msg)
  40.     sent = sent+1
  41.     modem.transmit(24680,client_id,tmsg.." "..msg)
  42. end
  43. function connect(address)
  44.     server_sent = 0
  45.     sent = 0
  46.     client_id = math.random(1000,31337)
  47.     send("PING",address)
  48.     timer_id = os.startTimer(2)
  49.     exit_loop = false
  50.     while not exit_loop do
  51.         evnt = {os.pullEvent()}
  52.         if evnt[1] == "timer" and evnt[2] == timer_id then
  53.             return false -- time out
  54.         elseif evnt[1] == "modem_message" and evnt[4] == client_id then
  55.             msg = evnt[5]
  56.             msg_words = {}
  57.             for w in msg:gmatch("%S+") do
  58.                 table.insert(msg_words,w)
  59.             end
  60.             if msg_words[1] and msg_words[1] == "Pong" then
  61.                 if msg_words[2] and msg_words[2] == "Pong!" then
  62.                     distance = evnt[6]
  63.                     exit_loop = true
  64.                 end
  65.             end
  66.         end
  67.     end
  68.     eSend("EPING",address,"ENCRYPTED PING")
  69.     exit_loop = false
  70.     timer_id = os.startTimer(2)
  71.     while not exit_loop do
  72.         evnt = {os.pullEvent()}
  73.         if evnt[1] == "timer" and evnt[2] == timer_id then
  74.             return false
  75.         elseif evnt[1] == "modem_message" then
  76.             if evnt[4] == client_id then
  77.                 if evnt[5]:sub(1,1) == "E" then
  78.                     msg = decode(evnt[5]:sub(2,#evnt[5]))
  79.                     msg_words = {}
  80.                     for w in msg:gmatch("%S+") do
  81.                         table.insert(msg_words,w)
  82.                     end
  83.                     if msg_words[2] and msg_words[2] == "EPONG" then
  84.                         if msg_words[3] and msg_words[4] and msg_words[4] == "ENCRYPTED" and msg_words[4] == "PONG" then
  85.                             return true
  86.                         end
  87.                     else
  88.                         return false
  89.                     end
  90.                 else
  91.                 end
  92.             end
  93.         end
  94.     end
  95. end
  96. function getPage(dmn,page)
  97.     connect(dmn)
  98.     eSend("PAGE",dmn,page)
  99.     exit_loop = false
  100.     timer_id = os.startTimer(2)
  101.     while not exit_loop do
  102.         evnt = {os.pullEvent()}
  103.         if evnt[1] == "timer" and evnt[2] == timer_id then
  104.             return false
  105.         elseif evnt[1] == "modem_message" then
  106.             if evnt[4] == client_id then
  107.                 if evnt[5]:sub(1,1) == "E" then
  108.                     msg = decode(evnt[5]:sub(2,#evnt[5]))
  109.                     if msg:sub(1,9) == "200 PDATA" then
  110.                         page_data = msg:sub(11,#msg)
  111.                         exit_loop = true
  112.                         return page_data, tonumber(msg:sub(1,3))
  113.                     elseif msg:sub(1,9) == "404 PDATA" then
  114.                         page_data = msg:sub(11,#msg)
  115.                         exit_llop = true
  116.                         return page_data, tonumber(msg:sub(1,3))
  117.                     end
  118.                 end
  119.             end
  120.         end
  121.     end
  122. end
  123. function loadPage(pageData)
  124.     if pageData then
  125.         local page = loadstring(pageData)
  126.         page = setfenv(page,getfenv())
  127.         page()
  128.     end
  129. end
  130. term.setBackgroundColor(colors.white)
  131. term.setTextColor(colors.black)
  132. term.clear()
  133. local cur = term.current()
  134. scrx,scry = term.getSize()
  135. --local wPage = window.create(cur, 1, 3, scrx, scry-2,true)
  136. --local wBar= window.create(cur,7,1,scrx-6, 1, true)
  137. history = { "new" }
  138. local oPullRaw = os.pullEventRaw
  139. local oPull = os.pullEvent
  140. os.pullEvent = function(filter)
  141.         local pEData = {oPullRaw(filter)}
  142.         if pEData[1] ~= "mouse_click" then
  143.                 return unpack(pEData)
  144.         else
  145.                 local e,b,cx,cy =unpack(pEData)
  146.                 cy = cy-2
  147.                 return e,b,cx,cy
  148.         end
  149. end
  150. loadPage(getPage("tron.com","index"))
  151. os.pullEvent = oPull
Advertisement
Add Comment
Please, Sign In to add comment