Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function modRead()
- local text = ""
- while true do
- e = {os.pullEvent()}
- if e[1] == "key" then
- if e[2] == keys.enter then
- return text
- elseif e[2] == keys.backspace then
- text = text:sub(1,#text-1)
- end
- elseif e[1] == "char" then
- text = text..e[2]
- end
- end
- term.setCursorBlink(false)
- end
- local server = "http://luca.spdns.eu/dep-get/cc/"
- local function getPage(page)
- local uri = server..page
- local stream = http.get(uri)
- local content = stream.readAll()
- local res = stream.getResponseCode()
- stream.close()
- return content,res
- end
- local function contains(table,key)
- for i,v in pairs(table) do
- if v == key then
- return true
- end
- end
- return false
- end
- local function installAPI(api)
- print("Installing API "..api)
- local depsRaw = getPage("depget.php?file="..api)
- table.insert(_G.depapis,api)
- for dep in (depsRaw.."\n"):gmatch("([^\n]*)\n") do
- if dep ~= "" and not contains(_G.depapi,dep) then
- installAPI(dep)
- end
- end
- local content = getPage("get.php?file="..api)
- local f = fs.open("/usr/apis/"..api,"w")
- f.write(content)
- f.close()
- os.loadAPI("/usr/apis/"..api)
- end
- local function install(program)
- print("Installing "..program)
- local depsRaw = getPage("depget.php?file="..program)
- if not contains(_G.depinstalled,program) then
- for dep in (depsRaw.."\n"):gmatch("([^\n]*)\n") do
- if dep ~= "" and not contains(_G.depapis,dep) then
- installAPI(dep)
- end
- end
- local content = getPage("get.php?file="..program)
- local f = fs.open("/usr/bin/"..program,"w")
- f.write(content)
- f.close()
- else
- print(program.." is already installed!")
- end
- end
- local tArgs = {...}
- if #tArgs == 0 or tArgs[1] == "help" then
- print("Dep-Get help:")
- print(" dep-get list <filter>")
- print(" dep-get startup")
- print(" dep-get download <file>")
- print(" dep-get install <program>")
- print(" dep-get upload <user> <file>")
- print(" This dep has Super Cow Powers")
- elseif tArgs[1] == "moo" then
- print(" (__)")
- print(" (oo)")
- print(" /------\\/")
- print(" / | ||")
- print("* /\\ /\\")
- print(" ~~ ~~")
- print("...\"Have you mooed today?\"...")
- elseif tArgs[1] == "list" then
- local filter = false
- local filterText = ""
- if tArgs[2] then
- filter = true
- filterText = tArgs[2]
- end
- local content = getPage("list.php")
- term.clear()
- local files = {}
- for f in (content.."\n"):gmatch("([^\n]*)\n") do
- if filter then
- if f:lower():match(filterText:lower()) then
- table.insert(files,f)
- end
- else
- table.insert(files,f)
- end
- end
- local y = 1
- local _,my = term.getSize()
- for i,v in pairs(files) do
- term.setCursorPos(1,y)
- write(v)
- y = y + 1
- if y == my then
- term.setCursorPos(1,y)
- write("--Press a key to continue(Q to quit)--")
- local e,k = os.pullEvent("key")
- if k == keys.q then
- sleep(.05)
- break
- else
- term.clear()
- y = 1
- end
- end
- end
- print()
- sleep(.05)
- elseif tArgs[1] == "startup" then
- shell.setPath(shell.path()..":/usr/bin")
- _G.depapis = fs.list("/usr/apis")
- _G.depinstalled = fs.list("/usr/bin")
- for i,v in pairs(_G.depapis) do
- os.loadAPI("/usr/apis/"..v)
- end
- elseif tArgs[1] == "download" then
- local file = tArgs[2]
- local content = getPage("get.php?file="..file)
- local f = fs.open(file,"w")
- f.write(content)
- f.close()
- print("File downloaded raw!")
- elseif tArgs[1] == "install" then
- local file = tArgs[2]
- install(file)
- elseif tArgs[1] == "upload" then
- local user = tArgs[2]
- local file = tArgs[3]
- write("Password for "..user.."(hidden): ")
- local pass = modRead()
- print()
- local data = "?user="..user.."&"
- data = data.."password="..pass.."&"
- data = data.."file="..textutils.urlEncode(file).."&"
- write("Reading in "..file.."...")
- local f = fs.open(file,"r")
- local cont = f.readAll()
- print("done")
- write("Uploading...")
- data = data.."filecontent="..textutils.urlEncode(cont)
- local stream = http.get(server.."upload.php"..data)
- local res = stream.readAll()
- stream.close()
- print(res)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement