Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables
- local env = getfenv()
- local width,height = term.getSize()
- local username
- local password
- local token
- local SKIPLOGIN = true
- local selected = false
- local scroll = 0
- local refresh = false
- local baseOptions = {"Upload","New"}
- local fileOptions = {"Upload","New"," -----","Download","Delete","Rename","Edit","Run"}
- --Functions
- local drawBanner = function()
- paintutils.drawLine(1,1,width,1,colors.green)
- term.setCursorPos(math.ceil((width-10)/2),1)
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.white)
- term.write("DacStorage")
- end
- local info = function(txt,t)
- paintutils.drawLine(1,height,width,height,colors.lightGray)
- term.setTextColor(colors.gray)
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(2,height)
- term.write(txt)
- if not t then
- while true do
- local e = os.pullEvent()
- if e == "mouse_click" or e == "char" then
- break
- end
- end
- end
- end
- local prompt = function(txt)
- info(txt..": ",true)
- return read()
- end
- local runprogram = function(selection)
- local p = http.post("https://dacpages.tk/dpserver.php","f=filedownload&filename="..selection.."&username="..username.."&token="..token)
- local msg = p.readAll()
- if msg == "File Does Not Exist!" then
- info(msg)
- return
- end
- loadstring(msg)()
- end
- local rclick = function(x,y,tbl,selection)
- if y == 1 then
- return
- end
- local bw,bh,value
- bh = #tbl
- bw = 0
- for i = 1,#tbl do
- if #tbl[i]+2 > bw then
- bw = #tbl[i]+2
- end
- end
- if x+bw > width then
- x = width-bw+1
- end
- if y+bh > height then
- y = height-bh+1
- end
- paintutils.drawFilledBox(x+1,y+1,x+bw,y+bh,colors.black)
- paintutils.drawFilledBox(x,y,x+bw-1,y+bh-1,colors.green)
- term.setTextColor(colors.white)
- for i = 1,#tbl do
- term.setCursorPos(x+1,y+i-1)
- term.write(tbl[i])
- end
- local e,a,b,c = os.pullEvent("mouse_click")
- if b > x+bw-1 or b < x or c > y+bh-1 or c < y then
- return
- else
- value = tbl[c-y+1]
- end
- if value == "Download" then
- local p = http.post("https://dacpages.tk/dpserver.php","f=filedownload&filename="..selection.."&username="..username.."&token="..token)
- local msg = p.readAll()
- if msg == "File Does Not Exist!" then
- info(msg)
- else
- local f = fs.open(selection,"w")
- f.write(p.readAll())
- f.close()
- end
- p.close()
- elseif value == "Upload" then
- local file = prompt("Enter file location")
- if not fs.exists(file) then
- info("File Does Not Exist!")
- return
- end
- local f = fs.open(file,"r")
- local data = textutils.urlEncode(f.readAll())
- f.close()
- local p = http.post("https://dacpages.tk/dpserver.php","f=rawupload&filename="..fs.getName(file).."&username="..username.."&token="..token.."&filedata="..data)
- local msg = p.readAll()
- if msg == "success" then
- refresh = true
- else
- info(msg)
- end
- p.close()
- elseif value == "Delete" then
- if string.lower(string.sub(prompt("Are you sure? (y/n)"),1,1)) ~= "y" then
- return
- end
- local p = http.post("https://dacpages.tk/dpserver.php","f=filedelete&filename="..selection.."&username="..username.."&token="..token)
- local msg = p.readAll()
- if msg == "success" then
- refresh = true
- else
- info(msg)
- end
- p.close()
- elseif value == "Rename" then
- local newfilename = prompt("Enter New Filename")
- local p = http.post("https://dacpages.tk/dpserver.php","f=filerename&filename="..selection.."&username="..username.."&token="..token.."&newfilename="..newfilename)
- local msg = p.readAll()
- if msg == "success" then
- refresh = true
- else
- info(msg)
- end
- p.close()
- elseif value == "Edit" then
- local p = http.post("https://dacpages.tk/dpserver.php","f=filedownload&filename="..selection.."&username="..username.."&token="..token)
- local msg = p.readAll()
- if msg == "File Does Not Exist!" then
- info(msg)
- p.close()
- return
- end
- local f = fs.open(".temp","w")
- f.write(msg)
- f.close()
- p.close()
- shell.run("edit",".temp")
- f = fs.open(".temp","r")
- local data = textutils.urlEncode(f.readAll())
- f.close()
- local p = http.post("https://dacpages.tk/dpserver.php","f=filedelete&filename="..selection.."&username="..username.."&token="..token)
- local msg = p.readAll()
- if msg ~= "success" then
- info(msg)
- p.close()
- return
- end
- p.close()
- local p = http.post("https://dacpages.tk/dpserver.php","f=rawupload&filename="..selection.."&username="..username.."&token="..token.."&filedata="..data)
- local msg = p.readAll()
- if msg == "success" then
- refresh = true
- else
- info(msg)
- refresh = true
- end
- p.close()
- elseif value == "New" then
- local filename = prompt("Enter filename")
- local p = http.post("https://dacpages.tk/dpserver.php","f=rawupload&filename="..filename.."&username="..username.."&token="..token.."&filedata=")
- local msg = p.readAll()
- if msg == "success" then
- refresh = true
- else
- info(msg)
- end
- p.close()
- elseif value == "Run" then
- runprogram(selection)
- end
- end
- --Code
- while not SKIPLOGIN do
- term.setBackgroundColor(colors.white)
- term.clear()
- drawBanner()
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(3,4)
- term.write("Enter Username for DacPages Account:")
- term.setCursorPos(5,6)
- term.setTextColor(colors.gray)
- username = textutils.urlEncode(read())
- term.setCursorPos(3,8)
- term.setTextColor(colors.black)
- term.write("Enter DacPages Account Password:")
- term.setCursorPos(5,10)
- term.setTextColor(colors.gray)
- password = textutils.urlEncode(read("*"))
- local page = http.post("https://dacpages.tk/dpserver.php","f=signin&password="..password.."&username="..username)
- local out = page.readAll()
- if string.sub(out,1,7) == "token: " then
- token = string.sub(out,8,#out)
- break
- else
- term.setCursorPos(3,height)
- term.setTextColor(colors.red)
- term.write(out)
- sleep(3)
- end
- end
- if SKIPLOGIN then
- username = "TheDacinator"
- token = "b3ca861b12142c2c"
- end
- while true do
- term.setBackgroundColor(colors.white)
- term.clear()
- drawBanner()
- local page = http.post("https://dacpages.tk/dpserver.php","f=listfiles&username="..username.."&token="..token)
- local list = {}
- for i in string.gmatch(page.readAll(),"[^,]+") do
- if not (i == "." or i == "..") then
- list[#list+1] = i
- end
- end
- while true do
- for i = 2,height do
- term.setCursorPos(2,i)
- if list[i-1+scroll] then
- if i-1+scroll == selected then
- term.setBackgroundColor(colors.lightBlue)
- paintutils.drawLine(1,i,width,i,colors.lightBlue)
- term.setTextColor(colors.white)
- else
- paintutils.drawLine(1,i,width,i,colors.white)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- end
- term.setCursorPos(2,i)
- term.write(list[i-1+scroll])
- else
- paintutils.drawLine(1,i,width,i,colors.white)
- end
- end
- while true do
- local e,a,b,c = os.pullEvent()
- if e == "mouse_click" then
- if list[c-1] and a == 1 then
- selected = c-1+scroll
- break
- elseif a == 2 then
- if list[c-1] then
- rclick(b,c,fileOptions,list[c-1+scroll])
- else
- rclick(b,c,baseOptions)
- end
- break
- end
- elseif e == "mouse_scroll" then
- scroll = scroll + a
- if scroll > #list-(height-1) then
- scroll = #list-(height-1)
- end
- if scroll < 0 then
- scroll = 0
- end
- break
- elseif e == "key" then
- if a == 200 and selected and selected > 1 then
- selected = selected - 1
- if selected <= scroll then
- scroll = selected - 1
- end
- break
- elseif a == 208 and ((not selected) or selected < #list) then
- if not selected then
- selected = 0
- end
- selected = selected + 1
- if selected > height-1+scroll then
- scroll = selected-height+1
- end
- break
- elseif a == 28 and selected and list[selected] then
- runprogram(list[selected])
- end
- end
- end
- if refresh then
- refresh = false
- break
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement