Advertisement
guitarplayer616

Pastebin.com - CC Edition Backup

Jun 25th, 2015
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.16 KB | None | 0 0
  1. local button = {}
  2. local menus = {"signIn","home"}
  3. local menu = "signIn"
  4. local native = term.current()
  5. local corY,corY2 = 1,1
  6. local usercode,username,password,pastebinWin,signInWin,submitWin
  7. local eventsToggle = true
  8. fs.open("log","w")
  9.  
  10. local w,h = term.getSize()
  11. local c,r,l = 'c','r','l'
  12. local deftxt, defback = colors.white,colors.lightGray
  13.  
  14. --Console(temporary)
  15. function logCorTab(e)
  16.     for i = 1,4 do
  17.         term.setBackgroundColor(defback)
  18.         term.setCursorPos(w-15,i)
  19.         term.write(string.rep(" ",16))
  20.     end
  21.     if eventsToggle then
  22.         corY = 1
  23.         for i = 1,#e do
  24.             draw(e[i],r,corY)
  25.             corY = corY + 1
  26.         end
  27.     end
  28. end
  29.  
  30. function logCor(words)
  31.     if eventsToggle then
  32.         draw(words,r,corY)
  33.         corY2 = corY2+1
  34.     end
  35. end
  36.  
  37. function log(words)
  38.     words = tostring(words)
  39.     local h = fs.open("log","a")
  40.     h.writeLine(words)
  41.     h.close()
  42. end
  43.  
  44. --WindowClasses (todo = betterscrollin, movable/draggable/resizable/scrollbarable windows)
  45.  
  46. function writeLn(self,words,txtcol,backcol,x,y)
  47.     local w,h = self.getSize()
  48.     txtcol = txtcol or deftxt
  49.     backcol = backcol or defback
  50.     if x and y then
  51.         self.setCursorPos(x,y)
  52.     end
  53.     self.setBackgroundColor(backcol)
  54.     self.setTextColor(txtcol)
  55.     self.write(words)
  56.     local x,y = self.getCursorPos()
  57.     self.setCursorPos(x-#words,y+1)
  58. end
  59.  
  60. function clearWin(self,backcol)
  61.     self.setBackgroundColor(backcol)
  62.     self.clear()
  63. end
  64.  
  65. function toggle(self,bVis)
  66.     if bVis then
  67.         self.setVisible(true)
  68.     else
  69.     end
  70. end
  71.        
  72.  
  73. --uWordsAPI/WebtoolsAPI
  74.  
  75. function getColors()
  76.   for i,v in pairs(colors) do
  77.     if tonumber(v) then
  78.       loadstring(i.."="..v)()
  79.     end
  80.   end
  81.   grey = gray
  82.   lightGrey = lightGray
  83. end
  84.  
  85. function basics(e)
  86.     if e[1] == "key" then
  87.         if e[2] == keys.q then
  88.             error()
  89.         elseif e[2] == keys.leftAlt then
  90.             shell.run("pastebin run NybMLEHL")
  91.         elseif e[2] == keys.tab then
  92.             if eventsToggle == true then
  93.                 eventsToggle = false
  94.             else
  95.                 eventsToggle = true
  96.             end
  97.             logCorTab(e)
  98.         elseif e[2] == keys.delete then
  99.             menu = "home"
  100.             updateMenus()
  101.         end
  102.     end
  103. end
  104.  
  105. function hitbox(e,x,y,x2,y2,num,func,...)
  106.         --takes events (e) and compares to box(x,y,x2,y2) to see if box had been clicked, if so run function
  107.         if e[1] == "mouse_click" and e[2] == num and e[3] >= x and e[3] <= x2 and e[4] <= y and e[4] >=y2 then
  108.                 local returns = {func(...)}
  109.         if returns then return returns end
  110.         end
  111. end
  112.  
  113. function clearScreen(backcol)
  114.     term.setBackgroundColor(backcol)
  115.     term.clear()
  116.     term.setCursorPos(1,1)
  117. end
  118.  
  119. function draw(words,x,y,txtcol,backcol)
  120.     --put at top of file/program: local c,r,l = 'c','r','l'; local deftxt,defback
  121.     local w,h = term.getSize()
  122.     local offset = 0
  123.         local writeLn
  124.     words = tostring(words)
  125.         words = words or " "
  126.         if not (x and y) then
  127.                 x,y = term.getCursorPos()
  128.                 writeLn = true
  129.     elseif not x then
  130.         x,_ = term.getCursorPos()
  131.                 writeLn = true
  132.         elseif not y then
  133.         _,y = term.getCursorPos()
  134.         writeLn = true
  135.     end
  136.         txtcol = txtcol or deftxt
  137.         backcol = backcol or defback
  138.         if not tonumber(x) then
  139.                 x = x:gsub(" ", "")
  140.                 if x:sub(1, 1) == "l" then
  141.                         if x:find("+") then
  142.                                 offset = tonumber(x:sub(x:find("+") + 1))
  143.                                 term.setCursorPos(1 + offset, y)
  144.                         else
  145.                                 term.setCursorPos(1, y)
  146.                         end
  147.                 elseif x:sub(1, 1) == "c" then
  148.                         if x:find("+") then
  149.                                 offset = tonumber(x:sub(x:find("+") + 1))
  150.                                 term.setCursorPos(w/2 - #words/2 + 1 + offset, y)
  151.                         elseif x:find("-") then
  152.                                 offset = tonumber(x:sub(x:find("-") + 1))
  153.                                 term.setCursorPos(w/2 - #words/2 + 1 - offset, y)
  154.                         else
  155.                                 term.setCursorPos(w/2 - #words/2 + 1, y)
  156.                         end
  157.                 elseif x:sub(1, 1) == "r" then
  158.                         if x:find("-") then
  159.                                 offset = tonumber(x:sub(x:find("-") + 1))
  160.                                 term.setCursorPos(w - #words+ 1 - offset, y)
  161.                         else
  162.                                 term.setCursorPos(w - #words+ 1, y)
  163.                         end
  164.                 end
  165.         else
  166.                 term.setCursorPos(x, y)
  167.         end
  168.         term.setTextColor(txtcol)
  169.         term.setBackgroundColor(backcol)
  170.         if writeLn then
  171.                 write(words..'\n')
  172.         else
  173.                 write(words)
  174.         end
  175. end
  176.  
  177. --ButtonMethods
  178.  
  179. function button.signIn(x,y,txtcol,backcol,bool)
  180.     local userdetails
  181.     term.setCursorPos(x,y)
  182.     term.setTextColor(txtcol)
  183.     term.setBackgroundColor(backcol)
  184.     term.write("___________          ")
  185.     term.setCursorPos(x,y)
  186.     if not bool then
  187.         userdetails = read()
  188.     else
  189.         userdetails = read("*")
  190.     end
  191.     if userdetails then return userdetails end
  192. end
  193.  
  194. function button.authenticate(user,pass)
  195.     if user and pass then  
  196.         log("received authent")
  197.         log("Authenticated: "..user)
  198.         log("Authenticated: "..pass)
  199.         draw(string.rep(" ",70),1,h-1)
  200.         draw(string.rep(" ",70),1,h)
  201.         draw("Connecting to Pastebin...",1,h,yellow)
  202.         local userkey = http.post(
  203.             "http://pastebin.com/api/api_login.php",
  204.             "api_option=login&"..
  205.             "api_dev_key=996a06d80a378f151e589ac86c83e865&"..
  206.             "api_user_name="..textutils.urlEncode(username).."&"..
  207.             "api_user_password="..textutils.urlEncode(password)
  208.         )
  209.    
  210.         local postdata = userkey.readAll()
  211.         term.setTextColor(colors.red)
  212.         log(postdata)
  213.         userkey.close()
  214.         if postdata:sub(1,3) == 'Bad' then
  215.             usercode = nil
  216.             log("Authentication Request Failed")
  217.             draw(string.rep(" ",70),1,h-1)
  218.             draw(string.rep(" ",70),1,h)
  219.             draw("The Username or Password is incorrect,\nPlease try again...",1,h-1,red)
  220.             username,password = nil,nil
  221.         else
  222.             log("Authentication Successful")
  223.             usercode = postdata
  224.             menu = "home"
  225.             updateMenus()
  226.         end
  227.     else
  228.         draw(string.rep(" ",70),1,h)
  229.         draw(string.rep(" ",70),1,h-1)
  230.         draw("Please fill all required fields with your Username and Password...",1,h-1,red)
  231.     end
  232. end
  233.  
  234. --==0-0==--
  235.  
  236. getColors()
  237. username,password = nil,nil
  238.  
  239. pastebinWin = window.create(native,1,2,16,5,false)
  240. signInWin = window.create(native,w-9,2,w,4,false)
  241. --submitWin =
  242.  
  243. clearWin(pastebinWin,lightBlue)
  244. writeLn(pastebinWin," -New Paste",gray,lightBlue)
  245. writeLn(pastebinWin," -Upload file",gray,lightBlue)
  246. writeLn(pastebinWin," -Download file",gray,lightBlue)
  247. writeLn(pastebinWin," -Run Pastrami",gray,lightBlue)
  248.  
  249.  
  250.  
  251. function updateMenus()
  252.     if menu == "signIn" then
  253.         clearScreen(lightGray)
  254.         local signInBackCol,guestBackCol = white,lightBlue
  255.         draw("--------------",c,5,lightBlue)
  256.         draw("PastebinCC",c,6,white,defback)
  257.         draw("--------------",c,7,lightBlue)
  258.         draw("Username: ___________",c,9,grey)
  259.         draw("Password: ___________",c,11,grey)
  260.         draw(" Sign In ",'r-13',13,black,signInBackCol)
  261.         draw(" Sign in as Guest ",1,1,white,guestBackCol)
  262.     elseif menu == "home" then
  263.         clearScreen(lightGray)
  264.         paintutils.drawLine(1,1,w,1,lightBlue)
  265.         paintutils.drawLine(1,2,w,2,blue)
  266.         draw("Pastebin.com",l,1,white,lightBlue)   
  267.         paintutils.drawBox(2,4,w-1,h-1,white)
  268.         draw("[new paste]",3,4,gray,white)
  269.         --draw("[+] create new paste [^] trending pastes",2,3,white,blue)
  270.         --draw("sign in|my pastebin|my profile|logout",r,2,white,lightBlue)
  271.         draw(" sign in ",r,1,white,lightBlue)
  272.         draw(" Submit ",'r-2',h,gray,lightBlue)
  273.         pastebinWin.redraw()
  274.     end
  275. end
  276.  
  277. updateMenus()
  278.  
  279. while menu == "signIn" do
  280.     local e = {os.pullEvent()}
  281.     logCorTab(e)
  282.     local user = hitbox(e,w/2,9,w/2+10,9,1,button.signIn,w/2+1,9,black,defback)
  283.     if user then username = user[1]; log("Username: "..username); end
  284.     pass = hitbox(e,w/2,11,w/2+10,11,1,button.signIn,w/2+1,11,black,defback,'secret')
  285.     if pass then password = pass[1]; log("Password: "..password); end
  286.     hitbox(e,29,13,38,13,1,button.authenticate,username,password)
  287.     basics(e)
  288. end
  289.  
  290. while menu == "home" do
  291.     local e = {os.pullEvent()}
  292.     logCorTab(e)
  293.     basics(e)
  294. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement