Guest User

upload

a guest
Sep 26th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.36 KB | None | 0 0
  1. -- IPS - Improved Pastebin System --
  2. -- Created by XLzanfran. -----------
  3. -- Usage: Just follow with what it says!
  4. devKey = "814649b34fbb21e6452764a1cbfa9ace"
  5. userKey = ""
  6. if not http then
  7.   print("You need HTTP to use IPS!")
  8.   return
  9. end
  10. function post(uk, c, n)
  11.   if uk == "" then
  12.     resp = http.post("http://pastebin.com/api/api_post.php",
  13.       "api_dev_key=" .. devKey .. "&" ..
  14.       "api_option=paste&" ..
  15.       "api_paste_code=" .. c .. "&" ..
  16.       --"api_user_key=" .. uk .. "&" ..
  17.       "api_paste_name=" .. n .. "&" ..
  18.       "api_paste_format=lua"
  19.       --"api_paste_private=0"
  20.     )
  21.     if resp then
  22.       return resp.readAll()
  23.     else
  24.       return false
  25.     end
  26.   else
  27.     resp = http.post("http://pastebin.com/api/api_post.php",
  28.       "api_dev_key=" .. devKey .. "&" ..
  29.       "api_option=paste&" ..
  30.       "api_paste_code=" .. c .. "&" ..
  31.       "api_paste_name=" .. n .. "&" ..
  32.       "api_paste_format=lua&" ..
  33.       "api_user_key=" .. uk .. "&" ..
  34.       "api_paste_private=0"
  35.     )
  36.     if resp then
  37.       web = resp.readAll()
  38.       return web
  39.     else
  40.       return false
  41.     end
  42.   end
  43. end
  44. function loginProcess()
  45.   print("")
  46.   write("Enter your username: ")
  47.   local user = read()
  48.   print("")
  49.   print("")
  50.   write("Enter your password: ")
  51.   local pass = read("*")
  52.   print("Signing into Pastebin . . .")
  53.   local resp = http.post("http://pastebin.com/api/api_login.php",
  54.     "api_dev_key=" .. devKey .. "&" ..
  55.     "api_user_name=" .. user .. "&" ..
  56.     "api_user_password=" .. pass
  57.   )
  58.   if resp then
  59.     webr = resp.readAll()
  60.     if string.sub(webr, 1, 3) == "Bad" then
  61.       print("An error has occured. (" .. webr .. ")")
  62.       read()
  63.     else
  64.       print("Successfully logged in as " .. user)
  65.       userKey = webr
  66.       read()
  67.     end
  68.   end
  69. end
  70. function cmdSys()
  71.   term.clear()
  72.   term.setCursorPos(1, 1)
  73.   print("What would you like to do? (login/post/download/exit)")
  74.   term.write("> ")
  75.   local response = read()
  76.   if response == "login" then
  77.     loginProcess()
  78.     return cmdSys()
  79.   elseif response == "post" then
  80.     print("What program would you like to post?")
  81.     term.write("> ")
  82.     local f = read()
  83.     local file = fs.open(f, "r")
  84.     local data = file.readAll()
  85.     print("What would you like to name this as on Pastebin?")
  86.     term.write("> ")
  87.     local nameitas = read()
  88.     print("Posting " .. f .. " . . .")
  89.     local posting = post(userKey, data, nameitas)
  90.     if posting == false then
  91.       print("An error has occured.")
  92.       read()
  93.       cmdSys()
  94.     else
  95.       print("Uploaded. Go to " .. posting .. " to see your upload.")
  96.       read()
  97.       cmdSys()
  98.     end
  99.   elseif response == "download" then
  100.     print("Please enter the Pastebin ID:")
  101.     local id = read()
  102.     print("Please enter a filename to save it as:")
  103.     local f = read()
  104.     local fi = fs.open(f, "w")
  105.     print("Connecting to pastebin . . .")
  106.     local website = http.get("http://pastebin.com/raw.php?i=" .. textutils.urlEncode(id))
  107.     if website then
  108.       data = website.readAll()
  109.       fi.write(data)
  110.       fi.close()
  111.       print("Saved " .. id .. " as " .. f .. " successfully.")
  112.       read()
  113.       cmdSys()
  114.     else
  115.       print("An error has occured.")
  116.       read()
  117.       cmdSys()
  118.     end
  119.   elseif response == "exit" then
  120.    
  121.   else
  122.     print("Unknown command.")
  123.     read()
  124.     cmdSys()
  125.   end
  126. end
  127. cmdSys()
Add Comment
Please, Sign In to add comment