Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function httpCall(url,verify)
- http.request(url)
- while true do
- local x = {os.pullEvent()}
- local e = x[1]
- table.remove(x,1)
- if e=="http_success" then
- local get = x[2].readAll():match("[^%s]+")
- if verify(get) then
- return true,get
- end
- break
- elseif e=="http_failure" then
- break
- end
- end
- end
- function getInfo(x1,x2,y,label,colorsch,verify,over)
- label = label or ""
- local ubg = config.theme.bg
- local utx = config.theme.text
- if colorsch == "alt" then
- ubg = config.theme.altbg
- utx = config.theme.alttext
- end
- local stx = x1
- local enx = x2
- if verify then
- enx = enx-1
- end
- if label ~= "" then
- stx = x1+#label+1
- end
- term.setCursorPos(x1,y)
- term.setBackgroundColor(ubg)
- term.setTextColor(utx)
- term.write(label)
- local get = ""
- local function doIt()
- term.setCursorPos(stx,y)
- term.setBackgroundColor(config.theme.txtboxbg)
- term.setTextColor(config.theme.txtboxtxt)
- term.write(string.rep(" ",enx-stx+1))
- term.setCursorPos(stx,y)
- return limitRead(enx-stx+1,over)
- end
- if verify then
- --[[
- verify = {
- subdom = "/api/changePin"
- exq = {
- oldPin = "$INPUT$",
- newPin = "$INPUT$",
- address = "0000123412341234"
- }
- callback = function(inp)
- if inp=="SUCCESS_PIN_CHANGED" then
- return true
- end
- return false
- end
- }
- ]]
- local success = false
- local reinp
- term.setBackgroundColor(colors.orange)
- term.setCursorPos(x2,y)
- term.write(" ")
- while not success do
- reinp = doIt()
- if verify.preprocess then
- reinp = verify.preprocess(reinp)
- end
- local sbhost = config.host..verify.subdom.."?"
- for k,v in pairs(verify.exq) do
- if v=="$INPUT$" then
- v = tostring(reinp)
- end
- sbhost = sbhost..tostring(k).."="..v.."&"
- end
- sbhost = sbhost:sub(1,#sbhost-1)
- term.setBackgroundColor(ubg)
- term.setTextColor(utx)
- parallel.waitForAny(function() glib.spinner(x2,y) end, function()
- success = httpCall(sbhost,verify.callback)
- end)
- if not success then
- term.setCursorPos(x2,y)
- term.setBackgroundColor(colors.red)
- term.write(" ")
- end
- end
- term.setCursorPos(x2,y)
- term.setBackgroundColor(colors.green)
- term.write(" ")
- return reinp
- else
- return doIt()
- end
- end
- function getInfoPrerender(x1,x2,y,label,colorsch,verify)
- label = label or ""
- local ubg = config.theme.bg
- local utx = config.theme.text
- if colorsch == "alt" then
- ubg = config.theme.altbg
- utx = config.theme.alttext
- end
- local stx = x1
- local enx = x2
- if verify then
- enx = enx-1
- end
- if label ~= "" then
- stx = x1+#label+1
- end
- term.setCursorPos(x1,y)
- term.setBackgroundColor(ubg)
- term.setTextColor(utx)
- term.write(label)
- term.setCursorPos(stx,y)
- term.setBackgroundColor(config.theme.txtboxbg)
- term.setTextColor(config.theme.txtboxtxt)
- term.write(string.rep(" ",enx-stx+1))
- if verify then
- term.setBackgroundColor(colors.orange)
- term.setCursorPos(x2,y)
- term.write(" ")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement