screen locking
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
[ 'neural' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/neural/.package',
|
[ 'neural' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/neural/.package',
|
||||||
-- [ 'pickup' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/pickup/.package',
|
-- [ 'pickup' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/pickup/.package',
|
||||||
[ 'recipeBook' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/recipeBook/.package',
|
[ 'recipeBook' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/recipeBook/.package',
|
||||||
|
[ 'secure' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/secure/.package',
|
||||||
[ 'shellex' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/shellex/.package',
|
[ 'shellex' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/shellex/.package',
|
||||||
[ 'swshop' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/swshop/.package',
|
[ 'swshop' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/swshop/.package',
|
||||||
[ 'turtle' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/turtle/.package',
|
[ 'turtle' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/turtle/.package',
|
||||||
|
|||||||
@@ -11,11 +11,7 @@ local config = Config.load('secure', {
|
|||||||
timeout = 60,
|
timeout = 60,
|
||||||
})
|
})
|
||||||
|
|
||||||
if not config.enabled then
|
local timer = config.enabled and os.startTimer(config.timeout)
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local timer = os.startTimer(config.timeout)
|
|
||||||
|
|
||||||
local sandboxEnv = Util.shallowCopy(_ENV)
|
local sandboxEnv = Util.shallowCopy(_ENV)
|
||||||
setmetatable(sandboxEnv, { __index = _G })
|
setmetatable(sandboxEnv, { __index = _G })
|
||||||
@@ -92,7 +88,7 @@ keyboard.addHotkey('control-l', function()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
kernel.hook({ 'mouse_click', 'mouse_up', 'mouse_drag', 'key_up' }, function(event, eventData)
|
kernel.hook({ 'mouse_click', 'mouse_up', 'mouse_drag', 'key_up', 'key' }, function()
|
||||||
if timer then
|
if timer then
|
||||||
os.cancelTimer(timer)
|
os.cancelTimer(timer)
|
||||||
timer = os.startTimer(config.timeout)
|
timer = os.startTimer(config.timeout)
|
||||||
@@ -104,3 +100,16 @@ kernel.hook('timer', function(_, eventData)
|
|||||||
showLockScreen()
|
showLockScreen()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
kernel.hook('config_update', function(_, eventData)
|
||||||
|
if eventData[1] == 'secure' then
|
||||||
|
Util.merge(config, eventData[2])
|
||||||
|
if timer then
|
||||||
|
os.cancelTimer(timer)
|
||||||
|
timer = nil
|
||||||
|
end
|
||||||
|
if config.enabled then
|
||||||
|
timer = os.startTimer(config.timeout)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|||||||
128
secure/saver.lua
Normal file
128
secure/saver.lua
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
--(c) 2013 Felix Maxwell
|
||||||
|
--License: CC BY-SA 3.0
|
||||||
|
--http://www.computercraft.info/forums2/index.php?/topic/12239-100-screensavers-game-of-life-and-matrix/
|
||||||
|
|
||||||
|
-- modified for use in Opus
|
||||||
|
|
||||||
|
local fps = 4 --Determines how long the program will wait between each tick
|
||||||
|
local char = "\127" --Live cells will look like this
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
local term = _G.term
|
||||||
|
|
||||||
|
local function randomColor()
|
||||||
|
return 2 ^ math.random(0, 14)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function printCharAt( monitor, x, y, ch )
|
||||||
|
monitor.setCursorPos( x, y )
|
||||||
|
monitor.write( ch )
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getNumNeighborhood( grid, x, y )
|
||||||
|
local neighbors = 0
|
||||||
|
if x > 1 then
|
||||||
|
if y > 1 then
|
||||||
|
if grid[x-1][y-1] == char then neighbors = neighbors + 1 end
|
||||||
|
end
|
||||||
|
if grid[x-1][y] == char then neighbors = neighbors + 1 end
|
||||||
|
if y < #grid[x] then
|
||||||
|
if grid[x-1][y+1] == char then neighbors = neighbors + 1 end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if y > 1 then
|
||||||
|
if grid[x][y-1] == char then neighbors = neighbors + 1 end
|
||||||
|
end
|
||||||
|
if y < #grid[x] then
|
||||||
|
if grid[x][y+1] == char then neighbors = neighbors + 1 end
|
||||||
|
end
|
||||||
|
|
||||||
|
if x < #grid then
|
||||||
|
if y > 1 then
|
||||||
|
if grid[x+1][y-1] == char then neighbors = neighbors + 1 end
|
||||||
|
end
|
||||||
|
if grid[x+1][y] == char then neighbors = neighbors + 1 end
|
||||||
|
if y < #grid then
|
||||||
|
if grid[x+1][y+1] == char then neighbors = neighbors + 1 end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return neighbors
|
||||||
|
end
|
||||||
|
local function lifeOrDeath( cur, neighbors )
|
||||||
|
if neighbors < 2 then
|
||||||
|
return " "
|
||||||
|
elseif neighbors > 3 then
|
||||||
|
return " "
|
||||||
|
elseif neighbors == 3 then
|
||||||
|
return char
|
||||||
|
else
|
||||||
|
return cur
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function tick( monitor, grid )
|
||||||
|
local retGrid = {}
|
||||||
|
for x=1,#grid do
|
||||||
|
retGrid[x] = {}
|
||||||
|
for y=1,#grid[x] do
|
||||||
|
local num = getNumNeighborhood( grid, x, y )
|
||||||
|
retGrid[x][y] = lifeOrDeath( grid[x][y], num )
|
||||||
|
if retGrid[x][y] ~= grid[x][y] then
|
||||||
|
printCharAt( monitor, x, y, retGrid[x][y] )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return retGrid
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setup( w, h )
|
||||||
|
local grid = {}
|
||||||
|
for i=1,w do
|
||||||
|
grid[i] = {}
|
||||||
|
for o=1,h do
|
||||||
|
if math.random(1, 5) == 1 then
|
||||||
|
grid[i][o] = char
|
||||||
|
else
|
||||||
|
grid[i][o] = " "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return grid
|
||||||
|
end
|
||||||
|
|
||||||
|
local function run()
|
||||||
|
local monitor = term.current()
|
||||||
|
if monitor.isColor() then
|
||||||
|
monitor.setTextColor(colors.lime)
|
||||||
|
monitor.setBackgroundColor(colors.black)
|
||||||
|
end
|
||||||
|
local w, h = monitor.getSize()
|
||||||
|
local grid
|
||||||
|
|
||||||
|
local delay = 1/fps
|
||||||
|
local timerId = os.startTimer(delay)
|
||||||
|
local reset = 0
|
||||||
|
while true do
|
||||||
|
local e, id = os.pullEvent()
|
||||||
|
if e == 'key' or e == 'char' or e == 'mouse_click' then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if e == 'timer' and id == timerId then
|
||||||
|
if reset == 0 then
|
||||||
|
reset = 300
|
||||||
|
monitor.setTextColor(randomColor())
|
||||||
|
grid = setup(w, h)
|
||||||
|
monitor.clear()
|
||||||
|
end
|
||||||
|
reset = reset - 1
|
||||||
|
grid = tick( monitor, grid )
|
||||||
|
timerId = os.startTimer(delay)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
run()
|
||||||
|
term.setCursorPos(1, 1)
|
||||||
|
term.clear()
|
||||||
@@ -30,10 +30,6 @@ local tab = UI.Tab {
|
|||||||
enter = 'update',
|
enter = 'update',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
label3 = UI.Text {
|
|
||||||
ex = -2, y = -2, width = 20,
|
|
||||||
textColor = colors.yellow,
|
|
||||||
},
|
|
||||||
button = UI.Button {
|
button = UI.Button {
|
||||||
x = 20, y = 6,
|
x = 20, y = 6,
|
||||||
text = 'Update',
|
text = 'Update',
|
||||||
@@ -50,8 +46,7 @@ function tab:eventHandler(event)
|
|||||||
Config.update('secure', config)
|
Config.update('secure', config)
|
||||||
|
|
||||||
self:emit({ type = 'success_message', message = 'Settings updated' })
|
self:emit({ type = 'success_message', message = 'Settings updated' })
|
||||||
self.label3.value = 'Restart is required'
|
os.queueEvent('config_update', 'secure', config)
|
||||||
self.label3:draw()
|
|
||||||
end
|
end
|
||||||
return UI.Tab.eventHandler(self, event)
|
return UI.Tab.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
|
|||||||
34
secure/unlock.lua
Normal file
34
secure/unlock.lua
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
-- add this file to the preload section of .startup.boot
|
||||||
|
-- example:
|
||||||
|
-- {
|
||||||
|
-- preload = { 'packages/secure/unlock.lua' },
|
||||||
|
-- ...
|
||||||
|
|
||||||
|
package.path = '/sys/modules/?.lua;' .. package.path
|
||||||
|
|
||||||
|
local Security = require('opus.security')
|
||||||
|
local SHA = require('opus.crypto.sha2')
|
||||||
|
local Terminal = require('opus.terminal')
|
||||||
|
|
||||||
|
local term = _G.term
|
||||||
|
|
||||||
|
term.setCursorPos(1, 1)
|
||||||
|
term.clear()
|
||||||
|
|
||||||
|
repeat
|
||||||
|
local s, m = pcall(function()
|
||||||
|
local password = Terminal.readPassword('Enter password: ')
|
||||||
|
|
||||||
|
if not password then
|
||||||
|
error('Invalid password')
|
||||||
|
end
|
||||||
|
|
||||||
|
if Security.verifyPassword(SHA.compute(password or '')) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
error('Invalid password')
|
||||||
|
end)
|
||||||
|
if not s and m then
|
||||||
|
_G.printError(m)
|
||||||
|
end
|
||||||
|
until s
|
||||||
Reference in New Issue
Block a user