Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- oldpull = os.pullEvent
- os.pullEvent = os.pullEventRaw
- local w,h = term.getSize()
- local rw = w/2
- local rh = h/2
- local inlock = true
- local name = ""
- local role = ""
- local pass = ""
- scp = term.setCursorPos
- sbc = term.setBackgroundColor
- stc = term.setTextColor
- function readCredentials()
- local f = fs.open(".usercomputerinfo","r")
- local name = f.readLine()
- local role = f.readLine()
- local pass = f.readLine()
- return name, role, pass
- end
- function scaleup(sx,sy,ex,ey,color,speed)
- local xd = ex - sx
- local yd = ey - sy
- local winaddx = 0
- local winaddy = 0
- for i = 1, xd+yd do
- paintutils.drawFilledBox(sx,sy,sx+winaddx,sy+winaddy,color)
- if(sx+winaddx < ex)then winaddx=winaddx+1 end
- if(sy+winaddy < ey)then winaddy=winaddy+1 end
- sleep(speed)
- end
- end
- function scaledown(sx,sy,ex,ey,color,speed)
- local xd = ex - sx
- local yd = ey - sy
- local winaddx = 0
- local winaddy = 0
- for i = 1, xd+yd do
- paintutils.drawFilledBox(ex,ey,ex+winaddx,ey+winaddy,color)
- if(sy-winaddy < ey)then winaddy=winaddy-1 end
- if(sx-winaddx < ex)then winaddx=winaddx-1 end
- sleep(speed)
- end
- end
- function drawLogin()
- paintutils.drawFilledBox(1,1,2,h,colors.blue)
- for i = 1, w/2 do
- term.current().setVisible(false)
- paintutils.drawFilledBox(1,1,3+i,h,colors.gray)
- paintutils.drawFilledBox(1,1,2+i,h,colors.lightGray)
- paintutils.drawFilledBox(1,1,2+i,3,colors.blue)
- if(i % 5 < 1)then sleep(0.01) end
- term.current().setVisible(true)
- end
- scp(rw+3,rh+1)
- sbc(colors.gray)
- stc(colors.black)
- write("<")
- sbc(colors.lightBlue)
- stc(colors.white)
- local locking = "Verify credentials."
- scp(((w/4)-#locking/2)+2,2)
- write(locking)
- end
- function pwrite(x,y,txt)
- scp(x,y)
- write(txt)
- end
- function cwrite(txt,h)
- scp(rw - #txt/2,h)
- write(txt)
- end
- function undrawLogin()
- term.current().setVisible(false)
- paintutils.drawFilledBox(1,1,rw+3,h,colors.white)
- term.current().setVisible(true)
- for x = 1, rw+1 do
- term.current().setVisible(false)
- paintutils.drawFilledBox(1,1,(rw+3)-x,h,colors.gray)
- paintutils.drawFilledBox(1,1,(rw+1)-x,h,colors.lightGray)
- paintutils.drawFilledBox(1,1,(rw+1)-x,3,colors.blue)
- paintutils.drawFilledBox((rw+3)-x,1,(rw+4)-x,h,colors.white)
- term.current().setVisible(true)
- if(x % 5 < 1)then sleep(0.01) end
- end
- end
- function window_write(ww,wh,txt)
- local x, y = term.getCursorPos()
- scp(((rw+1) - ww/2)+x,((rh+2) - wh/2)+y)
- write(txt)
- end
- function window(dowait,title,text,ww,wh,bgcolor,topcolor,sdwcolor,ccol)
- if(dowait == nil)then dowait = true end
- paintutils.drawFilledBox(
- (rw+1) - ww/2,
- (rh+2) - wh/2,
- (rw+1) + ww/2,
- (rh+2) + wh/2,
- sdwcolor
- )
- paintutils.drawFilledBox(
- rw - ww/2,
- (rh+1) - wh/2,
- rw + ww/2,
- (rh+1) + wh/2,
- bgcolor
- )
- paintutils.drawLine(
- rw - ww/2,
- (rh+1) - wh/2,
- rw + ww/2,
- (rh+1) - wh/2,
- topcolor
- )
- sbc(topcolor)
- stc(2^ ( 15 - (math.log(sdwcolor) / math.log(2) ) ))
- scp((rw-ww/2),(rh+1) - wh/2)
- write(title)
- sbc(bgcolor)
- stc(sdwcolor)
- local strlin = ( ( rh + 2 ) - wh/2) +1
- scp((rw-ww/2), strlin)
- local xx = 0
- local online = 1
- local ind = 0
- for i = 1, #text do
- xx = xx + 1
- if(text:sub(ind,ind+1) == "/n")then
- online = online + 1
- xx = 1
- ind = ind + 1
- else
- scp((rw-ww/2)+xx,strlin+online)
- write(text:sub(ind,ind))
- end
- ind = ind + 1
- end
- if(dowait)then
- os.pullEvent("key")
- paintutils.drawFilledBox(
- (rw) - ww/2,
- (rh) - wh/2,
- (rw+1) + ww/2,
- (rh+2) + wh/2,
- ccol
- )
- end
- end
- function askyn()
- local inyn = true
- local isy = false
- while(inyn)do
- local e, k = os.pullEvent("key")
- if(k == keys.y)then
- isy = true
- inyn = false
- break
- elseif(k == keys.n)then
- inyn = false
- break
- end
- end
- return isy
- end
- function defwindow()
- return colors.white,colors.blue,colors.black,colors.lightGray --term.getBackgroundColor()
- end
- function darkwindow()
- return colors.lightGray,colors.blue,colors.black,colors.white --term.getBackgroundColor()
- end
- function setupPass()
- paintutils.drawFilledBox(1,1,w,h,colors.lightGray)
- window(false,"Setup Password","Enter new password below.",38,8,defwindow())
- scp(1,4)
- sbc(colors.gray)
- window_write(38,8,string.rep(" ",35))
- scp(rw - 17, 11)
- stc(colors.white)
- local pass = read('*')
- scp(-1,7)
- window_write(38,8,string.rep(" ",39))
- scp(16,7)
- stc(colors.white)
- window_write(38,8,"Y/n?")
- if(not askyn())then return setupPass() end
- sbc(colors.lightGray)
- window(1,"Setup Password","Press any key to continue.",38,8,defwindow())
- if(not fs.exists("sha256"))then
- window(1,"Setup Password","Required file missing: sha256. /n Press any key to download sha256.",38,8,defwindow())
- local sha = http.get("http://pastebin.com/raw.php?i=U1fGPi4B")
- if sha then
- local f = fs.open("sha256","w")
- f.write(sha.readAll())
- f.close()
- window(1,"Setup Password","Downloaded file: sha256. /n Successfully.",38,8,defwindow())
- os.loadAPI("sha256")
- local f = fs.open(".usercomputerinfo",'w')
- f.writeLine(name)
- f.writeLine(role)
- f.writeLine(sha256.sha256(pass))
- f.close()
- window(1,"Setup Password","Setup completed! /n Press any key to reboot.",38,8,defwindow())
- os.reboot()
- else
- window(false,"Setup Password","/n/n Sha256 download failed.",38,8,defwindow())
- stc(colors.red)
- scp(1,1)
- window_write(38,8,"FATAL ERROR")
- os.pullEvent("key")
- window(1,"Fatal Error","Sha256 download failed /n press any key to exit.",38,8,defwindow())
- sbc(colors.black)
- stc(colors.white)
- term.clear()
- return false
- end
- end
- end
- function drawCredentials()
- local n, r, p = readCredentials()
- paintutils.drawFilledBox(1,1,rw+3,h,colors.white)
- stc(colors.lightGray)
- cwrite("This Computer Is Secured With StoneLock",1)
- cwrite("This computer belongs to ", 3)
- pwrite(rw-10,6,"Name: " .. n)
- pwrite(rw-10,7,"Role: " .. r)
- end
- function refresh(inpass)
- paintutils.drawFilledBox(1,1,w,h,colors.white)
- if not sha256 then
- os.loadAPI("sha256")
- end
- local n, r, p = readCredentials()
- drawCredentials()
- if(inpass)then
- paintutils.drawFilledBox(1,1,2,h,colors.lightGray)
- paintutils.drawFilledBox(1,1,3+w/2,h,colors.gray)
- paintutils.drawFilledBox(1,1,2+w/2,h,colors.lightGray)
- paintutils.drawFilledBox(1,1,2+w/2,3,colors.blue)
- scp(rw+3,rh+1)
- sbc(colors.gray)
- stc(colors.black)
- write("<")
- sbc(colors.blue)
- stc(colors.white)
- local locking = "Verify credentials."
- scp(((w/4)-#locking/2)+2,2)
- write(locking)
- sbc(colors.lightGray)
- stc(colors.white)
- scp(2,5)
- write("Enter the password for: ")
- scp(2,7)
- write("[" .. r .. "] " .. n)
- scp(2,9)
- sbc(colors.gray)
- stc(colors.white)
- write(string.rep(" ", rw-2))
- scp(2,9)
- local pss = read('*')
- if(sha256.sha256(pss) == p)then
- undrawLogin()
- drawCredentials()
- window(false,"Password","/n/n Welcome back, " .. n.. "/n Press any key.",28,8,darkwindow())
- stc(colors.lime)
- scp(2,1)
- window_write(28,8,"Password Verified.")
- os.pullEvent("key")
- os.pullEvent = oldpull
- inlock = false
- sbc(colors.black)
- stc(colors.white)
- scp(1,1)
- term.clear()
- return true
- else
- undrawLogin()
- drawCredentials()
- window(false,"Password","/n/n Press any key.",28,8,darkwindow())
- stc(colors.red)
- scp(2,1)
- window_write(28,8,"Password Invalid.")
- os.pullEvent("key")
- return false
- end
- else
- paintutils.drawFilledBox(1,1,1,h,colors.gray)
- scp(1,rh+1)
- sbc(colors.gray)
- stc(colors.black)
- write(">")
- end
- end
- function drawScreen()
- paintutils.drawFilledBox(1,1,w,h,colors.white)
- if(not fs.exists(".usercomputerinfo"))then
- paintutils.drawFilledBox(1,1,w,h,colors.lightGray)
- window(1,"Setup Description"," Welcome to StoneLock. /n/n A lock designed for all /n StoneFruit staff members.",28,8,defwindow())
- window(1,"Setup Description","Role description required. /n/n Press any key to setup.",28,8,defwindow())
- window(false,"Setup Description","Please enter your role at StoneFruit.",38,8,defwindow())
- scp(1,4)
- sbc(colors.gray)
- window_write(38,8,string.rep(" ",35))
- os.pullEvent("key")
- scp(rw - 17, 11)
- stc(colors.white)
- role = read()
- sbc(colors.lightGray)
- window(1,"Setup Description","Press any key to continue.",38,8,defwindow())
- window(false,"Setup Description","What is your name?.",28,8,defwindow())
- scp(1,4)
- sbc(colors.gray)
- window_write(28,8,string.rep(" ",26))
- os.pullEvent("key")
- scp(rw - 12, 11)
- stc(colors.white)
- name = read()
- window(false,"Setup Description","Is this correct? /n/n Name: " .. name .. "/n Role: " .. role,38,10,defwindow())
- sbc(colors.gray)
- scp(-1,9)
- window_write(38,10,string.rep(" ",39))
- scp(16,9)
- stc(colors.white)
- window_write(38,10,"Y/n?")
- if(not askyn())then return drawScreen() end
- sbc(colors.lightGray)
- window(1,"Setup Password","Press any key to continue.",38,10,defwindow())
- return setupPass()
- else
- return refresh(false)
- end
- end
- function update()
- drawScreen()
- while inlock do
- -- Handle menu opening and function calling here
- local e, b, x, y = os.pullEvent()
- if(e == "mouse_click")then
- if(x == 1)then
- drawLogin()
- if(not refresh(true))then
- refresh(false)
- end
- end
- elseif(e == "key")then
- if(b == keys.right)then
- drawLogin()
- if(not refresh(true))then
- refresh(false)
- end
- end
- end
- end
- end
- update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement