Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- SaviOS logging pastebin system.
- ]]--
- w, h = term.getSize()
- clear = term.clear
- function term.clear()
- for i=1, h-1 do
- term.setCursorPos(1, i)
- term.clearLine()
- end
- end
- function saveUserData(user, api_dev_key)
- file = fs.open("disk/.cloudData", "a")
- file.write(user.." "..api_dev_key)
- file.close()
- end
- function loadUserData(user)
- file = fs.open("disk/.cloudData", "r")
- sLine = file.readLine()
- tLines = {}
- while sLine do
- table.insert(tLines, sLine)
- sLine = file.readLine()
- end
- file.close()
- for k,v in pairs(tLines) do
- if string.find(v, user) ~= nil then
- tWords = {}
- for m in string.gmatch(v, "[^ \t]+") do
- table.insert(tWords, m)
- return tWords[2]
- end
- end
- end
- end
- function setStatus(text)
- term.setCursorPos(1, h)
- term.clearLine()
- term.write(text)
- end
- function download(code, filename)
- setStatus("Downloading from: pastebin.com/raw/"..code)
- data = http.get("http://www.pastebin.com/raw"..textutils.urlEncode(code)).readAll()
- if data == nil then
- data = "Error: Downloading wasn't succesfull!"
- end
- if fs.exists(filename) then
- setStatus("Error: File exists!")
- return false
- else
- file = fs.open(filename, "w")
- file.write(data)
- file.close()
- if data == "Error: Downloading wasn't succesfull!" then
- setStatus(data)
- return false
- else
- setStatus("Successfully saved to "..filename)
- return true
- end
- end
- end
- function login(user, password, dev_key)
- api_user_key = http.post(
- "http://www.pastebin.com/api/api_login.php",
- "api_dev_key="..dev_key.."&"..
- "api_user_name="..textutils.urlEncode(user).."&"..
- "api_user_password="..textutils.urlEncode(password)
- ).readAll()
- return api_user_key
- end
- function upload(title, textData, expiration)
- response = http.post(
- "http://www.pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_user_key="..api_user_key.."&"..
- "api_paste_name="..textutils.urlEncode(title).."&"..
- "api_paste_format=lua&"..
- "api_paste_expire_date="..expiration.."&"..
- "api_paste_code="..textutils.urlEncode(textData).."&"..
- "api_dev_key="..dev_key
- ).readAll()
- ran = string.gmatch(response, "[^/]+$")
- out = ran()
- return out
- end
- function delete(paste_key)
- setStatus("Removing paste: "..paste_key.."!")
- progress = http.post(
- "http://www.pastebin.com/api/api_post.php",
- "api_option=delete&"..
- "api_dev_key="..dev_key.."&"..
- "api_user_key="..api_user_key.."&"..
- "api_paste_key="..paste_key
- ).readAll()
- return progress
- end
- function list(dev_key, user_key )
- files = http.get(
- "https://pastebin.com/api/api_post.php",
- "api_option=list&"..
- "api_user_key="..user_key..
- "api_dev_key="..dev_key).readAll()
- file = fs.open(".tmp", "w")
- file.write(files)
- file.close()
- end
- function reloadMenu(n)
- menu = {}
- for i=1, #fullMenu do
- table.insert(menu, fullMenu[n[i]])
- end
- end
- fullMenu = {"Login", "Register", "Logout", "Upload", "Download", "Edit"}
- menu = {"Login", "Register"}
- menuFunc = {
- ["Edit"] = function()
- term.clear()
- setStatus("Filename you want to edit")
- term.setCursorPos(2, 2)
- term.write("Filename: ")
- fName = read()
- shell.run("edit", fName)
- end,
- ["Download"] = function()
- term.clear()
- setStatus("Filename, where'll be your code saved")
- term.setCursorPos(2, 2)
- term.write("Filename: ")
- fName = read()
- setStatus("A title of code, you want to download")
- term.setCursorPos(2, 4)
- term.write("Title: ")
- title = read()
- code = loadUserData(title)
- success = download(code, fName)
- end,
- ["Register"] = function()
- term.clear()
- setStatus("Your pastebin username")
- term.setCursorPos(2, 2)
- term.write("User: ")
- user = read()
- setStatus("You can find it on: www.pastebin.com/api")
- term.setCursorPos(2, 4)
- term.write("Type your 'api_dev_key': ")
- api_dev_key = read()
- setStatus("Password for your pastebin account")
- term.setCursorPos(2, 6)
- term.write("Password: ")
- pass = read("*")
- check = login(user, pass, api_dev_key)
- if check:sub(1, 7) ~= "Bad API" then
- setStatus("Data verified, your api_dev_key was saved")
- else
- setStatus("Check your data, something is wrong")
- end
- end,
- ["Upload"] = function()
- term.clear()
- setStatus("")
- term.setCursorPos(2, 2)
- term.write("Paste Title: ")
- title = read()
- term.setCursorPos(2, 4)
- term.write("File to Upload: ")
- filename = read()
- term.write("Expiration: ")
- expiration = read()
- file = fs.open(filename, "r")
- data = file.readAll()
- file.close()
- setStatus("Uploading..")
- code = upload(title, data, expiration)
- file = fs.open("disk/codes", "r")
- sLine = file.readLine()
- tLines = {}
- while sLine do
- table.insert(tLines, sLine)
- sLine = file.readLine()
- end
- file.close()
- file = fs.open("disk/codes", "w")
- file.writeLine(title.." "..code)
- for k,v in pairs(tLines) do
- file.writeLine(v)
- end
- file.close()
- setStatus("Uploaded as: "..code.." Code was wrote to 'code file'!")
- end,
- ["Logout"] = function()
- n = {1}
- api_user_key = nil
- reloadMenu(n)
- end,
- ["Login"] = function()
- term.clear()
- setStatus("")
- term.setCursorPos(2, 2)
- term.write("User: ")
- user = read()
- term.setCursorPos(2, 4)
- term.write("Password: ")
- pass = read("*")
- api_dev_key = loadUserData(user)
- if not api_dev_key then
- setStatus("This username is not registered, please register")
- else
- api_user_key = login(user, pass, api_dev_key)
- if api_user_key:sub(1, 7) == "Bad API" then
- setStatus("Error: "..api_user_key:sub(17, #api_user_key))
- term.clear()
- n = {1}
- reloadMenu(n)
- else
- setStatus("Welcome "..user.."!")
- term.clear()
- n = {3,4,5,6}
- reloadMenu(n)
- end
- end
- end,
- }
- term.clear = clear
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement