Advertisement
Guest User

bluesafe

a guest
May 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 40.17 KB | None | 0 0
  1. --[[
  2.                     GNU GENERAL PUBLIC LICENSE
  3.                        Version 3, 29 June 2007
  4.  
  5.  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
  6.  Everyone is permitted to copy and distribute verbatim copies
  7.  of this license document, but changing it is not allowed.
  8.  
  9.  Full license: https://github.com/Ale32bit/BlueSafe/blob/master/LICENSE
  10. ]]--
  11.  
  12. local args = {...}
  13.  
  14. if not term.isColor() then
  15.     print("Classic computers not supported (yet)")
  16.     return
  17. end
  18.  
  19. -- SHA256
  20. local MOD = 2^32
  21. local MODM = MOD-1
  22.  
  23. local function memoize(f)
  24.         local mt = {}
  25.         local t = setmetatable({}, mt)
  26.         function mt:__index(k)
  27.                 local v = f(k)
  28.                 t[k] = v
  29.                 return v
  30.         end
  31.         return t
  32. end
  33.  
  34. local function make_bitop_uncached(t, m)
  35.         local function bitop(a, b)
  36.                 local res,p = 0,1
  37.                 while a ~= 0 and b ~= 0 do
  38.                         local am, bm = a % m, b % m
  39.                         res = res + t[am][bm] * p
  40.                         a = (a - am) / m
  41.                         b = (b - bm) / m
  42.                         p = p*m
  43.                 end
  44.                 res = res + (a + b) * p
  45.                 return res
  46.         end
  47.         return bitop
  48. end
  49.  
  50. local function make_bitop(t)
  51.         local op1 = make_bitop_uncached(t,2^1)
  52.         local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)
  53.         return make_bitop_uncached(op2, 2 ^ (t.n or 1))
  54. end
  55.  
  56. local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})
  57.  
  58. local function bxor(a, b, c, ...)
  59.         local z = nil
  60.         if b then
  61.                 a = a % MOD
  62.                 b = b % MOD
  63.                 z = bxor1(a, b)
  64.                 if c then z = bxor(z, c, ...) end
  65.                 return z
  66.         elseif a then return a % MOD
  67.         else return 0 end
  68. end
  69.  
  70. local function band(a, b, c, ...)
  71.         local z
  72.         if b then
  73.                 a = a % MOD
  74.                 b = b % MOD
  75.                 z = ((a + b) - bxor1(a,b)) / 2
  76.                 if c then z = bit32_band(z, c, ...) end
  77.                 return z
  78.         elseif a then return a % MOD
  79.         else return MODM end
  80. end
  81.  
  82. local function bnot(x) return (-1 - x) % MOD end
  83.  
  84. local function rshift1(a, disp)
  85.         if disp < 0 then return lshift(a,-disp) end
  86.         return math.floor(a % 2 ^ 32 / 2 ^ disp)
  87. end
  88.  
  89. local function rshift(x, disp)
  90.         if disp > 31 or disp < -31 then return 0 end
  91.         return rshift1(x % MOD, disp)
  92. end
  93.  
  94. local function lshift(a, disp)
  95.         if disp < 0 then return rshift(a,-disp) end
  96.         return (a * 2 ^ disp) % 2 ^ 32
  97. end
  98.  
  99. local function rrotate(x, disp)
  100.     x = x % MOD
  101.     disp = disp % 32
  102.     local low = band(x, 2 ^ disp - 1)
  103.     return rshift(x, disp) + lshift(low, 32 - disp)
  104. end
  105.  
  106. local k = {
  107.         0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  108.         0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  109.         0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  110.         0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  111.         0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  112.         0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  113.         0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  114.         0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  115.         0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  116.         0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  117.         0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  118.         0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  119.         0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  120.         0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  121.         0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  122.         0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
  123. }
  124.  
  125. local function str2hexa(s)
  126.         return (string.gsub(s, ".", function(c) return string.format("%02x", string.byte(c)) end))
  127. end
  128.  
  129. local function num2s(l, n)
  130.         local s = ""
  131.         for i = 1, n do
  132.                 local rem = l % 256
  133.                 s = string.char(rem) .. s
  134.                 l = (l - rem) / 256
  135.         end
  136.         return s
  137. end
  138.  
  139. local function s232num(s, i)
  140.         local n = 0
  141.         for i = i, i + 3 do n = n*256 + string.byte(s, i) end
  142.         return n
  143. end
  144.  
  145. local function preproc(msg, len)
  146.         local extra = 64 - ((len + 9) % 64)
  147.         len = num2s(8 * len, 8)
  148.         msg = msg .. "\128" .. string.rep("\0", extra) .. len
  149.         assert(#msg % 64 == 0)
  150.         return msg
  151. end
  152.  
  153. local function initH256(H)
  154.         H[1] = 0x6a09e667
  155.         H[2] = 0xbb67ae85
  156.         H[3] = 0x3c6ef372
  157.         H[4] = 0xa54ff53a
  158.         H[5] = 0x510e527f
  159.         H[6] = 0x9b05688c
  160.         H[7] = 0x1f83d9ab
  161.         H[8] = 0x5be0cd19
  162.         return H
  163. end
  164.  
  165. local function digestblock(msg, i, H)
  166.         local w = {}
  167.         for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end
  168.         for j = 17, 64 do
  169.                 local v = w[j - 15]
  170.                 local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))
  171.                 v = w[j - 2]
  172.                 w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))
  173.         end
  174.  
  175.         local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]
  176.         for i = 1, 64 do
  177.                 local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
  178.                 local maj = bxor(band(a, b), band(a, c), band(b, c))
  179.                 local t2 = s0 + maj
  180.                 local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
  181.                 local ch = bxor (band(e, f), band(bnot(e), g))
  182.                 local t1 = h + s1 + ch + k[i] + w[i]
  183.                 h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2
  184.         end
  185.  
  186.         H[1] = band(H[1] + a)
  187.         H[2] = band(H[2] + b)
  188.         H[3] = band(H[3] + c)
  189.         H[4] = band(H[4] + d)
  190.         H[5] = band(H[5] + e)
  191.         H[6] = band(H[6] + f)
  192.         H[7] = band(H[7] + g)
  193.         H[8] = band(H[8] + h)
  194. end
  195.  
  196. local function hash(msg)
  197.         msg = preproc(msg, string.len(msg))
  198.         local H = initH256({})
  199.         for i = 1, #msg, 64 do digestblock(msg, i, H) end
  200.         return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
  201.                 num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
  202. end
  203.  
  204. -- DB
  205.  
  206. --[[
  207.  
  208.     Database API Created by Ale32bit
  209.    
  210.     db v2.2
  211.    
  212.     MIT License
  213.  
  214.     Copyright (c) 2017 Ale32bit
  215.  
  216.     Permission is hereby granted, free of charge, to any person obtaining a copy
  217.     of this software and associated documentation files (the "Software"), to deal
  218.     in the Software without restriction, including without limitation the rights
  219.     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  220.     copies of the Software, and to permit persons to whom the Software is
  221.     furnished to do so, subject to the following conditions:
  222.  
  223.     The above copyright notice and this permission notice shall be included in all
  224.     copies or substantial portions of the Software.
  225.  
  226.     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  227.     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  228.     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  229.     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  230.     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  231.     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  232.     SOFTWARE.
  233.  
  234. ]]--
  235.  
  236. local conf = {}
  237.  
  238. local database = "/.bluesafeconf" -- Config file
  239.  
  240. local db = {}
  241.  
  242. if fs.isDir(database) then
  243.     error("database must be a file")
  244. end
  245.  
  246. if not fs.exists(database) then
  247.     local data = {
  248.         database = {
  249.             version = 2.2,
  250.         }
  251.     }
  252.     local f = fs.open(database,"w")
  253.     f.write(textutils.serialise(data))
  254.     f.close()
  255. end
  256.  
  257. -- init
  258.  
  259. local f = fs.open(database,"r")
  260. db = textutils.unserialise(f.readAll())
  261. f.close()
  262. if not db then
  263.     db = {
  264.         database = {
  265.             version = 2.2,
  266.         }
  267.     }
  268. end
  269.  
  270. function conf.checkDatabase()
  271.   local f = fs.open(database,"r")
  272.   local data = textutils.unserialise(f.readAll())
  273.   f.close()
  274.   if data then
  275.     return true
  276.   end
  277.   return false
  278. end
  279.  
  280. function conf.get(group,config)
  281.     if not db[group] then
  282.         return nil
  283.     end
  284.     if not config then
  285.         return db[group]
  286.     end
  287.     return db[group][config]
  288. end
  289.  
  290. function conf.set(group,config,value)
  291.     local old = db
  292.     if not db[group] then
  293.         db[group] = {}
  294.     end
  295.     db[group][config] = value
  296.     if not db then
  297.         db = old
  298.         return false
  299.     end
  300.     local f = fs.open(database,"w")
  301.     f.write(textutils.serialise(db))
  302.     f.close()
  303.     return true
  304. end
  305.  
  306. function conf.list(group)
  307.     return db[group]
  308. end
  309.  
  310. function conf.index()
  311.     return db
  312. end
  313.  
  314. function conf.update() --update from file
  315.     if not checkDatabase() then
  316.         return false, "database corrupted"
  317.     end
  318.     local f = fs.open(database,"r")
  319.     db = textutils.unserialise(f.readAll())
  320.     f.close()
  321.     return true
  322. end
  323.  
  324. function conf.fixFile() --update file from memory
  325.     local f = fs.open(database, "w")
  326.     f.write(textutils.serialize(db))
  327.     f.close()
  328. end
  329.  
  330. function conf.delete(group)
  331.     db[group] = nil
  332.     local f = fs.open(database,"w")
  333.     f.write(textutils.serialise(db))
  334.     f.close()
  335. end
  336.  
  337. -- END APIs
  338.  
  339. local function read( _sReplaceChar, _tHistory, _fnComplete, _MouseEvent, _presetInput, _onlyNumbers )
  340.     term.setCursorBlink( true )
  341.     local sLine = _presetInput
  342.        
  343.         if type(sLine) ~= "string" then
  344.             sLine = ""
  345.         end
  346.         local nPos = #sLine
  347.     local nHistoryPos
  348.         local _MouseX
  349.         local _MouseY
  350.         local param
  351.         local sEvent
  352.         local usedMouse = false
  353.     if _sReplaceChar then
  354.         _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
  355.     end
  356.  
  357.     local tCompletions
  358.     local nCompletion
  359.     local function recomplete()
  360.         if _fnComplete and nPos == string.len(sLine) then
  361.             tCompletions = _fnComplete( sLine )
  362.             if tCompletions and #tCompletions > 0 then
  363.                 nCompletion = 1
  364.             else
  365.                 nCompletion = nil
  366.             end
  367.         else
  368.             tCompletions = nil
  369.             nCompletion = nil
  370.         end
  371.     end
  372.  
  373.     local function uncomplete()
  374.         tCompletions = nil
  375.         nCompletion = nil
  376.     end
  377.  
  378.     local w = term.getSize()
  379.     local sx = term.getCursorPos()
  380.  
  381.     local function redraw( _bClear )
  382.         local nScroll = 0
  383.         if sx + nPos >= w then
  384.             nScroll = (sx + nPos) - w
  385.         end
  386.  
  387.         local cx,cy = term.getCursorPos()
  388.         term.setCursorPos( sx, cy )
  389.         local sReplace = (_bClear and " ") or _sReplaceChar
  390.         if sReplace then
  391.             term.write( string.rep( sReplace, math.max( string.len(sLine) - nScroll, 0 ) ) )
  392.         else
  393.             term.write( string.sub( sLine, nScroll + 1 ) )
  394.         end
  395.  
  396.         if nCompletion then
  397.             local sCompletion = tCompletions[ nCompletion ]
  398.             local oldText, oldBg
  399.             if not _bClear then
  400.                 oldText = term.getTextColor()
  401.                 oldBg = term.getBackgroundColor()
  402.                 term.setTextColor( colors.gray )
  403.             end
  404.             if sReplace then
  405.                 term.write( string.rep( sReplace, string.len( sCompletion ) ) )
  406.             else
  407.                 term.write( sCompletion )
  408.             end
  409.             if not _bClear then
  410.                 term.setTextColor( oldText )
  411.                 term.setBackgroundColor( oldBg )
  412.             end
  413.         end
  414.  
  415.         term.setCursorPos( sx + nPos - nScroll, cy )
  416.     end
  417.    
  418.     local function clear()
  419.         redraw( true )
  420.     end
  421.  
  422.     recomplete()
  423.     redraw()
  424.  
  425.     local function acceptCompletion()
  426.         if nCompletion then
  427.             -- Clear
  428.             clear()
  429.  
  430.             -- Find the common prefix of all the other suggestions which start with the same letter as the current one
  431.             local sCompletion = tCompletions[ nCompletion ]
  432.             sLine = sLine .. sCompletion
  433.             nPos = string.len( sLine )
  434.  
  435.             -- Redraw
  436.             recomplete()
  437.             redraw()
  438.         end
  439.     end
  440.     while true do
  441.         sEvent, param,_MouseX,_MouseY = os.pullEvent()
  442.         if sEvent == "char" then
  443.             -- Typed key
  444.             clear()
  445.             if _onlyNumbers then
  446.                 if tonumber(param) then
  447.                     sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  448.                     nPos = nPos + 1
  449.                 end
  450.             else
  451.                 sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  452.                 nPos = nPos + 1
  453.             end
  454.             recomplete()
  455.             redraw()
  456.  
  457.         elseif sEvent == "paste" then
  458.             -- Pasted text
  459.             clear()
  460.             sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  461.             nPos = nPos + string.len( param )
  462.             recomplete()
  463.             redraw()
  464.  
  465.         elseif sEvent == "key" then
  466.             if param == keys.enter then
  467.                 -- Enter
  468.                 if nCompletion then
  469.                     clear()
  470.                     uncomplete()
  471.                     redraw()
  472.                 end
  473.                 break
  474.                
  475.             elseif param == keys.left then
  476.                 -- Left
  477.                 if nPos > 0 then
  478.                     clear()
  479.                     nPos = nPos - 1
  480.                     recomplete()
  481.                     redraw()
  482.                 end
  483.                
  484.             elseif param == keys.right then
  485.                 -- Right                
  486.                 if nPos < string.len(sLine) then
  487.                     -- Move right
  488.                     clear()
  489.                     nPos = nPos + 1
  490.                     recomplete()
  491.                     redraw()
  492.                 else
  493.                     -- Accept autocomplete
  494.                     acceptCompletion()
  495.                 end
  496.  
  497.             elseif param == keys.up or param == keys.down then
  498.                 -- Up or down
  499.                 if nCompletion then
  500.                     -- Cycle completions
  501.                     clear()
  502.                     if param == keys.up then
  503.                         nCompletion = nCompletion - 1
  504.                         if nCompletion < 1 then
  505.                             nCompletion = #tCompletions
  506.                         end
  507.                     elseif param == keys.down then
  508.                         nCompletion = nCompletion + 1
  509.                         if nCompletion > #tCompletions then
  510.                             nCompletion = 1
  511.                         end
  512.                     end
  513.                     redraw()
  514.  
  515.                 elseif _tHistory then
  516.                     -- Cycle history
  517.                     clear()
  518.                     if param == keys.up then
  519.                         -- Up
  520.                         if nHistoryPos == nil then
  521.                             if #_tHistory > 0 then
  522.                                 nHistoryPos = #_tHistory
  523.                             end
  524.                         elseif nHistoryPos > 1 then
  525.                             nHistoryPos = nHistoryPos - 1
  526.                         end
  527.                     else
  528.                         -- Down
  529.                         if nHistoryPos == #_tHistory then
  530.                             nHistoryPos = nil
  531.                         elseif nHistoryPos ~= nil then
  532.                             nHistoryPos = nHistoryPos + 1
  533.                         end                        
  534.                     end
  535.                     if nHistoryPos then
  536.                         sLine = _tHistory[nHistoryPos]
  537.                         nPos = string.len( sLine )
  538.                     else
  539.                         sLine = ""
  540.                         nPos = 0
  541.                     end
  542.                     uncomplete()
  543.                     redraw()
  544.  
  545.                 end
  546.  
  547.             elseif param == keys.backspace then
  548.                 -- Backspace
  549.                 if nPos > 0 then
  550.                     clear()
  551.                     sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
  552.                     nPos = nPos - 1
  553.                     recomplete()
  554.                     redraw()
  555.                 end
  556.  
  557.             elseif param == keys.home then
  558.                 -- Home
  559.                 if nPos > 0 then
  560.                     clear()
  561.                     nPos = 0
  562.                     recomplete()
  563.                     redraw()
  564.                 end
  565.  
  566.             elseif param == keys.delete then
  567.                 -- Delete
  568.                 if nPos < string.len(sLine) then
  569.                     clear()
  570.                     sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )                
  571.                     recomplete()
  572.                     redraw()
  573.                 end
  574.  
  575.             elseif param == keys["end"] then
  576.                 -- End
  577.                 if nPos < string.len(sLine ) then
  578.                     clear()
  579.                     nPos = string.len(sLine)
  580.                     recomplete()
  581.                     redraw()
  582.                 end
  583.  
  584.             elseif param == keys.tab then
  585.                 -- Tab (accept autocomplete)
  586.                 acceptCompletion()
  587.  
  588.             end
  589.  
  590.         elseif sEvent == "term_resize" then
  591.             -- Terminal resized
  592.             w = term.getSize()
  593.             redraw()
  594.                
  595.                 elseif sEvent == "mouse_click" and _MouseEvent then
  596.                     if nCompletion then
  597.             clear()
  598.             uncomplete()
  599.             redraw()
  600.           end
  601.                     usedMouse = true
  602.                     break
  603.         end
  604.     end
  605.  
  606.     local cx, cy = term.getCursorPos()
  607.     term.setCursorBlink( false )
  608.     term.setCursorPos( w + 1, cy )
  609.     print()
  610.         if sEvent == "mouse_click" then
  611.             return sLine, param, _MouseX, _MouseY
  612.         end
  613.     return sLine
  614. end
  615.  
  616. local w,h = term.getSize()
  617.  
  618. local function right(str)
  619.     local x,y = term.getCursorPos()
  620.     term.setCursorPos(w-str:len(),y)
  621.     write(str)
  622. end
  623.  
  624. local theme = {}
  625. if term.isColor() then
  626.     theme.bg = colors.white
  627.     theme.text = colors.black
  628.     theme.hdbg = colors.blue
  629.     theme.hdtext = colors.white
  630.     theme.wrong = colors.red
  631.     theme.correct = colors.lime
  632.     theme.input = colors.gray
  633.     theme.activeinput = colors.lightGray
  634.     theme.inputtext = colors.lightGray
  635.     theme.activeinputtext = colors.white
  636.     theme.yes = colors.lime
  637.     theme.no = colors.red
  638.     theme.btntext = colors.white
  639.     theme.red = colors.red
  640. else
  641.     theme.bg = colors.white
  642.     theme.text = colors.black
  643.     theme.hdbg = colors.gray
  644.     theme.hdtext = colors.white
  645.     theme.wrong = colors.black
  646.     theme.correct = colors.black
  647.     theme.input = colors.gray
  648.     theme.activeinput = colors.lightGray
  649.     theme.inputtext = colors.white
  650.     theme.activeinputtext = colors.black
  651.     theme.yes = colors.lightGray
  652.     theme.no = colors.gray
  653.     theme.btntext = colors.white
  654.     theme.red = colors.lightGray
  655. end
  656.  
  657. local oldPull = os.pullEvent
  658. os.pullEvent = os.pullEventRaw
  659.  
  660. local username = ""
  661. local password = ""
  662. local repeatpw = ""
  663. local mouse,mx,my
  664.  
  665. if not conf.get("accounts") then
  666.     local exit = false
  667.     local lockMode
  668.     conf.set("conf","salt",hash(tostring(os.time()+os.day())))
  669.     local info = window.create(term.current(),27,4,24,14,true)
  670.     if not _G.pocket then
  671.         local function printInfo(...)
  672.             local old = term.current()
  673.             term.redirect(info)
  674.             term.setBackgroundColor(theme.bg)
  675.             term.setTextColor(theme.text)
  676.             term.clear()
  677.             term.setCursorPos(1,1)
  678.             print(...)
  679.             term.redirect(old)
  680.         end
  681.         term.setBackgroundColor(theme.bg)
  682.         term.clear()
  683.         paintutils.drawLine(1,1,w,1,theme.hdbg)
  684.         term.setTextColor(theme.hdtext)
  685.         term.setBackgroundColor(theme.hdbg)
  686.         term.setCursorPos(2,1)
  687.         term.write("Setup")
  688.         right("BlueSafe")
  689.         term.setCursorPos(2,4)
  690.         term.setBackgroundColor(theme.bg)
  691.         term.setTextColor(theme.text)
  692.         print("Choose lock mode")
  693.         term.setTextColor(theme.inputtext)
  694.         paintutils.drawFilledBox(2,6,11,9,theme.input)
  695.         paintutils.drawFilledBox(14,6,23,9,theme.input)
  696.         term.setCursorPos(3,7)
  697.         write("Computer")
  698.         term.setCursorPos(5,8)
  699.         write("Lock")
  700.        
  701.         term.setCursorPos(15,7)
  702.         write("Redstone")
  703.         term.setCursorPos(17,8)
  704.         write("Lock")
  705.        
  706.         term.setBackgroundColor(theme.bg)
  707.         term.setCursorPos(2,h-1)
  708.         term.setBackgroundColor(theme.red)
  709.         term.setTextColor(theme.hdtext)
  710.         write(" Exit ")
  711.        
  712.         printInfo("Welcome to BlueSafe!\n\nSelect \"Computer Lock\" to safe your computer.\n\nSelect \"Redstone Lock\" to send redstone signal.\n\nCreated by Ale32bit\n\nCopyright (c) Ale32bit\nGNU License")
  713.        
  714.         while true do
  715.             local ev = {os.pullEvent()}
  716.             if ev[1] == "mouse_click" then
  717.                 local x,y = ev[3],ev[4]
  718.                
  719.                 if y >=6 and y <= 9 then
  720.                     if x >=2 and x <=11 then
  721.                         paintutils.drawFilledBox(2,6,11,9,theme.activeinput)
  722.                         term.setTextColor(theme.activeinputtext)
  723.                         term.setCursorPos(3,7)
  724.                         write("Computer")
  725.                         term.setCursorPos(5,8)
  726.                         write("Lock")
  727.                         paintutils.drawFilledBox(14,6,23,9,theme.input)
  728.                         term.setTextColor(theme.inputtext)
  729.                         term.setCursorPos(15,7)
  730.                         write("Redstone")
  731.                         term.setCursorPos(17,8)
  732.                         write("Lock")
  733.                        
  734.                         printInfo("Protect your computer by logging in using your credentials.")
  735.                        
  736.                         term.setBackgroundColor(theme.bg)
  737.                         term.setTextColor(theme.text)
  738.                         term.setCursorPos(w-12,h-1)
  739.                         print("Continue >")
  740.                         lockMode = "shell"
  741.                     elseif x >= 14 and x <= 23 then
  742.                         paintutils.drawFilledBox(2,6,11,9,theme.input)
  743.                         term.setTextColor(theme.inputtext)
  744.                         term.setCursorPos(3,7)
  745.                         write("Computer")
  746.                         term.setCursorPos(5,8)
  747.                         write("Lock")
  748.                         paintutils.drawFilledBox(14,6,23,9,theme.activeinput)
  749.                         term.setTextColor(theme.activeinputtext)
  750.                         term.setCursorPos(15,7)
  751.                         write("Redstone")
  752.                         term.setCursorPos(17,8)
  753.                         write("Lock")
  754.                        
  755.                         printInfo("Send redstone signal for n seconds using your credentials.")
  756.                        
  757.                         term.setBackgroundColor(theme.bg)
  758.                         term.setTextColor(theme.text)
  759.                         term.setCursorPos(w-12,h-1)
  760.                         print("Continue >")
  761.                         lockMode = "redstone"
  762.                     end
  763.                 elseif y == h-1 and x>=w-12 and x<=w-3 and lockMode then
  764.                     break
  765.                 elseif y == h-1 and x>= 2 and x<=7 then
  766.                     term.setBackgroundColor(colors.black)
  767.                     term.setTextColor(colors.white)
  768.                     term.clear()
  769.                     term.setCursorPos(1,1)
  770.                     print("BlueSafe setup canceled.")
  771.                     return
  772.                 end
  773.             end
  774.         end
  775.         if lockMode == "redstone" then
  776.             local sleepseconds = 2
  777.             local side
  778.             term.setBackgroundColor(theme.bg)
  779.             term.clear()
  780.             paintutils.drawLine(1,1,w,1,theme.hdbg)
  781.             term.setTextColor(theme.hdtext)
  782.             term.setBackgroundColor(theme.hdbg)
  783.             term.setCursorPos(2,1)
  784.             term.write("Setup")
  785.             right("BlueSafe")
  786.             term.setCursorPos(2,4)
  787.             term.setBackgroundColor(theme.bg)
  788.             term.setTextColor(theme.text)
  789.             print("Select redstone sides")
  790.             term.setCursorPos(31,4)
  791.             print("Sleep time")
  792.             term.setCursorPos(37,7)
  793.             print("seconds")
  794.            
  795.             paintutils.drawFilledBox(31,7,35,7,theme.input)
  796.            
  797.             paintutils.drawFilledBox(10,7,16,9,theme.input) --top
  798.             paintutils.drawFilledBox(2,11,8,13,theme.input) --left
  799.             paintutils.drawFilledBox(10,11,16,13,theme.input) --front
  800.             paintutils.drawFilledBox(10,15,16,17,theme.input) --bottom
  801.             paintutils.drawFilledBox(18,11,24,13,theme.input) --right
  802.             paintutils.drawFilledBox(18,7,24,9,theme.input) -- back
  803.             term.setTextColor(theme.inputtext)
  804.            
  805.             term.setCursorPos(12,8)
  806.             term.write("Top")
  807.            
  808.             term.setCursorPos(3,12)
  809.             term.write("Left")
  810.            
  811.             term.setCursorPos(11,12)
  812.             term.write("Front")
  813.            
  814.             term.setCursorPos(11,16)
  815.             term.write("Bottm")
  816.            
  817.             term.setCursorPos(19,12)
  818.             term.write("Right")
  819.            
  820.             term.setCursorPos(19,8)
  821.             term.write("Back")
  822.            
  823.             term.setCursorPos(31,7)
  824.             term.write(sleepseconds)
  825.            
  826.             local sides = {
  827.                 front = false,
  828.                 back = false,
  829.                 top = false,
  830.                 bottom = false,
  831.                 right = false,
  832.                 left = false,
  833.             }
  834.            
  835.             local sideset = false
  836.            
  837.             while true do
  838.                 local ev = {os.pullEvent()}
  839.                 if ev[1] == "mouse_click" then
  840.                     local x,y = ev[3],ev[4]
  841.                    
  842.                    
  843.                     if (x>=10 and x<=16) and (y>=7 and y<=9) then --top
  844.                         if sides["top"] then
  845.                             sides["top"] = false
  846.                             paintutils.drawFilledBox(10,7,16,9,theme.input)
  847.                             term.setTextColor(theme.inputtext)
  848.                             term.setCursorPos(12,8)
  849.                             term.write("Top")
  850.                         else
  851.                             sides["top"] = true
  852.                             paintutils.drawFilledBox(10,7,16,9,theme.activeinput)
  853.                             term.setTextColor(theme.activeinputtext)
  854.                             term.setCursorPos(12,8)
  855.                             term.write("Top")
  856.                         end
  857.                        
  858.                        
  859.                     elseif (x>=2 and x<=8) and (y>=11 and y<=13) then --left
  860.                         if sides["left"] then
  861.                             sides["left"] = false
  862.                             paintutils.drawFilledBox(2,11,8,13,theme.input)
  863.                             term.setTextColor(theme.inputtext)
  864.                             term.setCursorPos(3,12)
  865.                             term.write("Left")
  866.                         else
  867.                             sides["left"] = true
  868.                             paintutils.drawFilledBox(2,11,8,13,theme.activeinput)
  869.                             term.setTextColor(theme.activeinputtext)
  870.                             term.setCursorPos(3,12)
  871.                             term.write("Left")
  872.                         end
  873.                        
  874.                        
  875.                     elseif (x>=10 and x<=16) and (y>=11 and y<=13) then --front
  876.                         if sides["front"] then
  877.                             sides["front"] = false
  878.                             paintutils.drawFilledBox(10,11,16,13,theme.input)
  879.                             term.setTextColor(theme.inputtext)
  880.                             term.setCursorPos(11,12)
  881.                             term.write("Front")
  882.                         else
  883.                             sides["front"] = true
  884.                             paintutils.drawFilledBox(10,11,16,13,theme.activeinput)
  885.                             term.setTextColor(theme.activeinputtext)
  886.                             term.setCursorPos(11,12)
  887.                             term.write("Front")
  888.                         end
  889.                        
  890.                        
  891.                     elseif (x>=10 and x<=16) and (y>=15 and y<=17) then --bottom
  892.                         if sides["bottom"] then
  893.                             sides["bottom"] = false
  894.                             paintutils.drawFilledBox(10,15,16,17,theme.input)
  895.                             term.setTextColor(theme.inputtext)
  896.                             term.setCursorPos(11,16)
  897.                             term.write("Bottm")
  898.                         else
  899.                             sides["bottom"] = true
  900.                             paintutils.drawFilledBox(10,15,16,17,theme.activeinput)
  901.                             term.setTextColor(theme.activeinputtext)
  902.                             term.setCursorPos(11,16)
  903.                             term.write("Bottm")
  904.                         end
  905.                        
  906.                        
  907.                     elseif (x>=18 and x<=24) and (y>=11 and y<=13) then --right
  908.                         if sides["right"] then
  909.                             sides["right"] = false
  910.                             paintutils.drawFilledBox(18,11,24,13,theme.input)
  911.                             term.setTextColor(theme.inputtext)
  912.                             term.setCursorPos(19,12)
  913.                             term.write("Right")
  914.                         else
  915.                             sides["right"] = true
  916.                             paintutils.drawFilledBox(18,11,24,13,theme.activeinput)
  917.                             term.setTextColor(theme.activeinputtext)
  918.                             term.setCursorPos(19,12)
  919.                             term.write("Right")
  920.                         end
  921.                        
  922.                        
  923.                     elseif (x>=18 and x<=24) and (y>=7 and y<=9) then --back
  924.                         if sides["back"] then
  925.                             sides["back"] = false
  926.                             paintutils.drawFilledBox(18,7,24,9,theme.input)
  927.                             term.setTextColor(theme.inputtext)
  928.                             term.setCursorPos(19,8)
  929.                             term.write("Back")
  930.                         else
  931.                             sides["back"] = true
  932.                             paintutils.drawFilledBox(18,7,24,9,theme.activeinput)
  933.                             term.setTextColor(theme.activeinputtext)
  934.                             term.setCursorPos(19,8)
  935.                             term.write("Back")
  936.                         end
  937.                    
  938.                    
  939.                     elseif y == 7 and (x>=31 and x<=35) then
  940.                         local curr = term.current()
  941.                         local inp = window.create(term.current(), 31,7,5,1,true)
  942.                         term.redirect(inp)
  943.                         term.setBackgroundColor(theme.activeinput)
  944.                         term.setTextColor(theme.activeinputtext)
  945.                         term.clear()
  946.                         term.setCursorPos(1,1)
  947.                         sleepseconds, mouse, mx,my = read(nil,nil,nil,true,tostring(sleepseconds),true)
  948.                         sleepseconds = tostring(sleepseconds)
  949.                         term.setBackgroundColor(theme.input)
  950.                         term.setTextColor(theme.inputtext)
  951.                         term.clear()
  952.                         term.setCursorPos(1,1)
  953.                         term.write(sleepseconds)
  954.                         term.redirect(curr)
  955.                         sleepseconds = tonumber(sleepseconds)
  956.                        
  957.                         if mouse then
  958.                             os.queueEvent("mouse_click",1,mx,my)
  959.                         end
  960.                     elseif y == h-1 and x>=w-12 and x<=w-3 and sideset then
  961.                         for k,v in pairs(sides) do
  962.                             conf.set("rssides",k,v)
  963.                         end
  964.                         conf.set("conf","lockmode","redstone")
  965.                         conf.set("conf","sleep",tonumber(sleepseconds) or 2)
  966.                         break
  967.                     end
  968.                 end
  969.                 local ss
  970.                 for k,v in pairs(sides) do
  971.                     if v then
  972.                         ss = true
  973.                     end
  974.                 end
  975.                 if ss then
  976.                     sideset = true
  977.                 else
  978.                     sideset = false
  979.                 end
  980.                 ss = false
  981.                
  982.                 if sideset then
  983.                     term.setBackgroundColor(theme.bg)
  984.                     term.setTextColor(theme.text)
  985.                     term.setCursorPos(w-12,h-1)
  986.                     print("Continue >")
  987.                 else
  988.                     term.setCursorPos(1,h-1)
  989.                     term.setBackgroundColor(theme.bg)
  990.                     term.clearLine()
  991.                 end
  992.             end
  993.         else                       
  994.             conf.set("conf","lockmode","shell")
  995.         end
  996.     else
  997.         term.setBackgroundColor(theme.bg)
  998.         term.clear()
  999.         paintutils.drawLine(1,1,w,1,theme.hdbg)
  1000.         term.setTextColor(theme.hdtext)
  1001.         term.setBackgroundColor(theme.hdbg)
  1002.         term.setCursorPos(2,1)
  1003.         term.write("Setup")
  1004.         right("BlueSafe")
  1005.        
  1006.         term.setCursorPos(2,4)
  1007.         term.setBackgroundColor(theme.bg)
  1008.         term.setTextColor(theme.text)
  1009.         print("Welcome to BlueSafe!")
  1010.         term.setCursorPos(2,6)
  1011.         print("Because of pocket computer, \"Computer Lock\" is automatically selected.")
  1012.         term.setCursorPos(2,8)
  1013.         print("Created by Ale32bit")
  1014.         term.setCursorPos(2,10)
  1015.         print("Copyright (c) Ale32bit")
  1016.         term.setCursorPos(2,11)
  1017.         print("GNU License")
  1018.        
  1019.         term.setBackgroundColor(theme.bg)
  1020.         term.setCursorPos(2,h-1)
  1021.         term.setBackgroundColor(theme.red)
  1022.         term.setTextColor(theme.hdtext)
  1023.         write(" Exit ")
  1024.        
  1025.         term.setBackgroundColor(theme.bg)
  1026.         term.setTextColor(theme.text)
  1027.         term.setCursorPos(w-12,h-1)
  1028.         print("Continue >")
  1029.        
  1030.         while true do
  1031.             local e = {os.pullEvent()}
  1032.             if e[1] == "mouse_click" then
  1033.                 local x,y = e[3],e[4]
  1034.                
  1035.                 if y == h-1 and (x>=2 and x<=7) then
  1036.                     return
  1037.                 elseif y == h-1 and (x>=w-12 and x<=w-3) then
  1038.                     break
  1039.                 end
  1040.             end
  1041.         end
  1042.         conf.set("conf","lockmode","shell")
  1043.     end
  1044.     while not exit do
  1045.         term.setBackgroundColor(theme.bg)
  1046.         term.clear()
  1047.         paintutils.drawLine(1,1,w,1,theme.hdbg)
  1048.         term.setTextColor(theme.hdtext)
  1049.         term.setBackgroundColor(theme.hdbg)
  1050.         term.setCursorPos(2,1)
  1051.         term.write("Setup")
  1052.         right("BlueSafe")
  1053.  
  1054.         term.setCursorPos(2,4)
  1055.         term.setBackgroundColor(theme.bg)
  1056.         term.setTextColor(theme.text)
  1057.         print((function() if not term.isColor() then return "[1] " end return "" end)().."Username")
  1058.         term.setCursorPos(2,8)
  1059.         print((function() if not term.isColor() then return "[2] " end return "" end)().."Password")
  1060.         term.setCursorPos(2,12)
  1061.         print((function() if not term.isColor() then return "[3] " end return "" end)().."Repeat Password")
  1062.         if term.isColor() then
  1063.             term.setCursorPos(w-10,h-1)
  1064.             print("Create >")
  1065.         else
  1066.             term.setCursorPos(w-13,h-1)
  1067.             print("[4] Create >")
  1068.         end
  1069.  
  1070.         paintutils.drawLine(2,5,w-5,5,theme.input)
  1071.         paintutils.drawLine(2,9,w-5,9,theme.input)
  1072.         paintutils.drawLine(2,13,w-5,13,theme.input)
  1073.        
  1074.         local lExit = false
  1075.  
  1076.         os.queueEvent("mouse_click",1,2,5) --first input
  1077.  
  1078.         while not lExit do
  1079.             local ev={os.pullEvent()}
  1080.             if ev[1] == "mouse_click" then
  1081.                 local x,y = ev[3], ev[4]
  1082.                 if y == 5 and (x>=2 and x<=w-5) then
  1083.                     local curr = term.current()
  1084.                     local inp = window.create(term.current(), 2,5,w-6,1,true)
  1085.                     term.redirect(inp)
  1086.                     term.setBackgroundColor(theme.activeinput)
  1087.                     term.setTextColor(theme.activeinputtext)
  1088.                     term.clear()
  1089.                     term.setCursorPos(1,1)
  1090.                     username, mouse, mx,my = read(nil,nil,nil,true,username)
  1091.                     term.setBackgroundColor(theme.input)
  1092.                     term.setTextColor(theme.inputtext)
  1093.                     term.clear()
  1094.                     term.setCursorPos(1,1)
  1095.                     term.write(username)
  1096.                     term.redirect(curr)
  1097.                     if mouse then
  1098.                         os.queueEvent("mouse_click",1,mx,my)
  1099.                     else
  1100.                         os.queueEvent("mouse_click",1,2,9)
  1101.                     end
  1102.                 elseif y == 9 and (x>=2 and x<=w-5) then
  1103.                     local curr = term.current()
  1104.                     local inp = window.create(term.current(), 2,9,w-6,1,true)
  1105.                     term.redirect(inp)
  1106.                     term.setBackgroundColor(theme.activeinput)
  1107.                     term.setTextColor(theme.activeinputtext)
  1108.                     term.clear()
  1109.                     term.setCursorPos(1,1)
  1110.                     password, mouse, mx,my = read("*",nil,nil,true,password)
  1111.                     term.setBackgroundColor(theme.input)
  1112.                     term.setTextColor(theme.inputtext)
  1113.                     term.clear()
  1114.                     term.setCursorPos(1,1)
  1115.                     term.write(string.rep("*",password:len()))
  1116.                     term.redirect(curr)
  1117.                     if mouse then
  1118.                         os.queueEvent("mouse_click",1,mx,my)
  1119.                     else
  1120.                         os.queueEvent("mouse_click",1,2,13)
  1121.                     end
  1122.                 elseif y == 13 and (x>=2 and x<=w-5) then
  1123.                     local curr = term.current()
  1124.                     local inp = window.create(term.current(), 2,13,w-6,1,true)
  1125.                     term.redirect(inp)
  1126.                     term.setBackgroundColor(theme.activeinput)
  1127.                     term.setTextColor(theme.activeinputtext)
  1128.                     term.clear()
  1129.                     term.setCursorPos(1,1)
  1130.                     repeatpw, mouse, mx,my = read("*",nil,nil,true,repeatpw)
  1131.                     term.setBackgroundColor(theme.input)
  1132.                     term.setTextColor(theme.inputtext)
  1133.                     term.clear()
  1134.                     term.setCursorPos(1,1)
  1135.                     term.write(string.rep("*",repeatpw:len()))
  1136.                     term.redirect(curr)
  1137.                     if mouse then
  1138.                         os.queueEvent("mouse_click",1,mx,my)
  1139.                     else
  1140.                         os.queueEvent("mouse_click",1,w-10,h-1)
  1141.                     end
  1142.                 elseif y == h-1 and (x>=w-10 and x<=w-3) then
  1143.                     if repeatpw == password then
  1144.                         conf.set("accounts",username,hash(conf.get("conf","salt")..hash(password)..hash(username)))
  1145.                         local accounts = {}
  1146.                         for k,v in pairs(conf.list("accounts")) do
  1147.                             table.insert(accounts,k)
  1148.                         end
  1149.                         term.setBackgroundColor(theme.bg)
  1150.                         term.clear()
  1151.                         paintutils.drawLine(1,1,w,1,theme.hdbg)
  1152.                         term.setTextColor(theme.hdtext)
  1153.                         term.setBackgroundColor(theme.hdbg)
  1154.                         term.setCursorPos(2,1)
  1155.                         term.write("Setup")
  1156.                         right("BlueSafe")
  1157.  
  1158.                         term.setCursorPos(2,4)
  1159.                         term.setBackgroundColor(theme.bg)
  1160.                         term.setTextColor(theme.text)
  1161.                         print("Create another account?")
  1162.                         paintutils.drawLine(2,6,6,6,theme.yes)
  1163.                         paintutils.drawLine(9,6,12,6,theme.no)
  1164.                         term.setCursorPos(3,6)
  1165.                         term.setTextColor(theme.btntext)
  1166.                         term.setBackgroundColor(theme.yes)
  1167.                         write("Yes")
  1168.                         term.setCursorPos(10,6)
  1169.                         term.setTextColor(theme.btntext)
  1170.                         term.setBackgroundColor(theme.no)
  1171.                         write("No")
  1172.                         term.setBackgroundColor(theme.bg)
  1173.                         term.setTextColor(theme.text)
  1174.                         local curr = term.current()
  1175.                         local nw = window.create(curr,2,9,w-2,h-9,true)
  1176.                         nw.setBackgroundColor(theme.bg)
  1177.                         nw.setTextColor(theme.text)
  1178.                         nw.clear()
  1179.                         nw.setCursorPos(1,1)
  1180.                         term.redirect(nw)
  1181.                         write("Accounts: "..table.concat(accounts,", "))
  1182.                         term.redirect(curr)
  1183.                         while true do
  1184.                             local e = {os.pullEvent()}
  1185.                             if e[1] == "mouse_click" then
  1186.                                 local x,y = e[3],e[4]
  1187.                                 if y == 6 then
  1188.                                     if x >= 2 and x <= 6 then
  1189.                                         lExit = true
  1190.                                         username = ""
  1191.                                         password = ""
  1192.                                         repeatpw = ""
  1193.                                         break
  1194.                                     elseif x >= 9 and x <= 12 then
  1195.                                         exit = true
  1196.                                         lExit = true
  1197.                                         break
  1198.                                     end
  1199.                                 end
  1200.                             end
  1201.                         end
  1202.                     else
  1203.                         term.setCursorPos(2,16)
  1204.                         term.setTextColor(theme.wrong)
  1205.                         term.setBackgroundColor(theme.bg)
  1206.                         print("Passwords do not match!")
  1207.                     end
  1208.                 end
  1209.             elseif ev[1] == "char" then
  1210.                 local c = ev[2]
  1211.                 if c == "1" then
  1212.                     os.queueEvent("mouse_click",1,2,5)
  1213.                 elseif c == "2" then
  1214.                     os.queueEvent("mouse_click",1,2,9)
  1215.                 elseif c == "3" then
  1216.                     os.queueEvent("mouse_click",1,2,13)
  1217.                 elseif c == "4" then
  1218.                     os.queueEvent("mouse_click",1,w-10,h-1)
  1219.                 end
  1220.             end
  1221.         end
  1222.     end
  1223.     if settings then
  1224.         settings.set("shell.allow_disk_startup",false)
  1225.         settings.save(".settings")
  1226.     end
  1227.     os.pullEvent = oldPull
  1228.     term.setBackgroundColor(colors.black)
  1229.     term.setTextColor(colors.white)
  1230.     term.clear()
  1231.     term.setCursorPos(1,1)
  1232.     print("Account(s) created!")
  1233.     if settings then
  1234.         print("Setting \"shell.allow_disk_startup\" has been disabled!")
  1235.     end
  1236.     if os.getComputerLabel() then
  1237.         printError("It is recommended to clear label!")
  1238.     end
  1239.     if conf.get("conf","lockmode") == "shell" then
  1240.         return
  1241.     end
  1242. end
  1243.  
  1244. if not conf.get("conf","salt") then
  1245.     conf.set("conf","salt",hash(tostring(os.time()+os.day())))
  1246. end
  1247.  
  1248. local username = ""
  1249. local password = ""
  1250.  
  1251. term.setBackgroundColor(theme.bg)
  1252. term.clear()
  1253. paintutils.drawLine(1,1,w,1,theme.hdbg)
  1254. term.setTextColor(theme.hdtext)
  1255. term.setBackgroundColor(theme.hdbg)
  1256. term.setCursorPos(2,1)
  1257. term.write("Login")
  1258. right("BlueSafe")
  1259.  
  1260. term.setCursorPos(2,4)
  1261. term.setBackgroundColor(theme.bg)
  1262. term.setTextColor(theme.text)
  1263. print((function() if not term.isColor() then return "[1] " end return "" end)().."Username")
  1264. term.setCursorPos(2,8)
  1265. print((function() if not term.isColor() then return "[2] " end return "" end)().."Password")
  1266. if term.isColor() then
  1267.     term.setCursorPos(w-10,h-1)
  1268.     print("Unlock >")
  1269. else
  1270.     term.setCursorPos(w-13,h-1)
  1271.     print("[3] Unlock >")
  1272. end
  1273.  
  1274. paintutils.drawLine(2,5,w-5,5,theme.input)
  1275. paintutils.drawLine(2,9,w-5,9,theme.input)
  1276.  
  1277. os.queueEvent("mouse_click",1,2,5) --first input
  1278.  
  1279. while true do
  1280.     local ev={os.pullEvent()}
  1281.     if ev[1] == "mouse_click" then
  1282.         local x,y = ev[3], ev[4]
  1283.         if y == 5 and (x>=2 and x<=w-5) then
  1284.             local curr = term.current()
  1285.             local inp = window.create(term.current(), 2,5,w-6,1,true)
  1286.             term.redirect(inp)
  1287.             term.setBackgroundColor(theme.activeinput)
  1288.             term.setTextColor(theme.activeinputtext)
  1289.             term.clear()
  1290.             term.setCursorPos(1,1)
  1291.             username, mouse, mx,my = read(nil,nil,nil,true,username)
  1292.             term.setBackgroundColor(theme.input)
  1293.             term.setTextColor(theme.inputtext)
  1294.             term.clear()
  1295.             term.setCursorPos(1,1)
  1296.             term.write(username)
  1297.             term.redirect(curr)
  1298.             if mouse then
  1299.                 os.queueEvent("mouse_click",1,mx,my)
  1300.             else
  1301.                 os.queueEvent("mouse_click",1,2,9)
  1302.             end
  1303.         elseif y == 9 and (x>=2 and x<=w-5) then
  1304.             local curr = term.current()
  1305.             local inp = window.create(term.current(), 2,9,w-6,1,true)
  1306.             term.redirect(inp)
  1307.             term.setBackgroundColor(theme.activeinput)
  1308.             term.setTextColor(theme.activeinputtext)
  1309.             term.clear()
  1310.             term.setCursorPos(1,1)
  1311.             password, mouse, mx,my = read("*",nil,nil,true,password)
  1312.             term.setBackgroundColor(theme.input)
  1313.             term.setTextColor(theme.inputtext)
  1314.             term.clear()
  1315.             term.setCursorPos(1,1)
  1316.             term.write(string.rep("*",password:len()))
  1317.             term.redirect(curr)
  1318.             if mouse then
  1319.                 os.queueEvent("mouse_click",1,mx,my)
  1320.             else
  1321.                 os.queueEvent("mouse_click",1,w-10,h-1)
  1322.             end
  1323.         elseif y == h-1 and (x>=w-10 and x<=w-3) then
  1324.             if conf.get("accounts",username) then
  1325.                 if hash(conf.get("conf","salt")..hash(password)..hash(username)) == conf.get("accounts",username) then
  1326.                     if conf.get("conf","lockmode") == "shell" then
  1327.                         os.pullEvent = oldPull
  1328.                         term.setBackgroundColor(colors.black)
  1329.                         term.setTextColor(colors.white)
  1330.                         term.clear()
  1331.                         term.setCursorPos(1,1)
  1332.                         print("Welcome back, "..username)
  1333.                         if os.getComputerLabel() then
  1334.                             printError("Warning: Label is set!")
  1335.                         end
  1336.                         if settings and settings.get("shell.allow_disk_startup") then
  1337.                             printError("Warning: Setting \"shell.allow_disk_startup\" is enabled!")
  1338.                         end
  1339.                         return
  1340.                     elseif conf.get("conf","lockmode") == "redstone" then
  1341.                         term.setCursorPos(2,12)
  1342.                         term.setBackgroundColor(theme.bg)
  1343.                         term.clearLine()
  1344.                         term.setTextColor(theme.correct)
  1345.                         print("Correct!")
  1346.                         for k,v in pairs(conf.list("rssides")) do
  1347.                             rs.setOutput(k,v)
  1348.                         end
  1349.                         sleep(conf.get("conf","sleep") or 2)
  1350.                         for k,v in pairs(conf.list("rssides")) do
  1351.                             rs.setOutput(k,false)
  1352.                         end
  1353.                         username = ""
  1354.                         password = ""
  1355.                         term.setCursorPos(2,12)
  1356.                         term.clearLine()
  1357.                         paintutils.drawLine(2,5,w-5,5,theme.input)
  1358.                         paintutils.drawLine(2,9,w-5,9,theme.input)
  1359.                         os.queueEvent("mouse_click",1,2,5)
  1360.                     end
  1361.                 else
  1362.                     term.setCursorPos(2,12)
  1363.                     term.setTextColor(theme.wrong)
  1364.                     term.setBackgroundColor(theme.bg)
  1365.                     print("Wrong username or password!")
  1366.                 end
  1367.             else
  1368.                 term.setCursorPos(2,12)
  1369.                 term.setTextColor(theme.wrong)
  1370.                 term.setBackgroundColor(theme.bg)
  1371.                 print("Wrong username or password!")
  1372.             end
  1373.         end
  1374.     elseif ev[1] == "char" then
  1375.         local c = ev[2]
  1376.         if c == "1" then
  1377.             os.queueEvent("mouse_click",1,2,5)
  1378.         elseif c == "2" then
  1379.             os.queueEvent("mouse_click",1,2,9)
  1380.         elseif c == "3" then
  1381.             os.queueEvent("mouse_click",1,w-10,h-1)
  1382.         end
  1383.     end
  1384. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement