typo + lock screen
This commit is contained in:
6
secure/.package
Normal file
6
secure/.package
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
title = 'Security features for Opus OS',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/secure',
|
||||
description = [[ Screen locking ]],
|
||||
license = 'MIT',
|
||||
}
|
||||
106
secure/autorun/lock.lua
Normal file
106
secure/autorun/lock.lua
Normal file
@@ -0,0 +1,106 @@
|
||||
local Config = require('opus.config')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local device = _G.device
|
||||
local kernel = _G.kernel
|
||||
local keyboard = device.keyboard
|
||||
local multishell = _ENV.multishell
|
||||
|
||||
local config = Config.load('secure', {
|
||||
enabled = false,
|
||||
timeout = 60,
|
||||
})
|
||||
|
||||
if not config.enabled then
|
||||
return
|
||||
end
|
||||
|
||||
local timer = os.startTimer(config.timeout)
|
||||
|
||||
local sandboxEnv = Util.shallowCopy(_ENV)
|
||||
setmetatable(sandboxEnv, { __index = _G })
|
||||
|
||||
local function buildLockScreen()
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local Event = require('opus.event')
|
||||
local Security = require('opus.security')
|
||||
local SHA = require('opus.crypto.sha2')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local counter = .1
|
||||
|
||||
local page = UI.Page {
|
||||
pass = UI.TextEntry {
|
||||
x = 10, ex = -10, y = "50%",
|
||||
limit = 32,
|
||||
mask = true,
|
||||
shadowText = 'password',
|
||||
accelerators = {
|
||||
enter = 'password',
|
||||
},
|
||||
},
|
||||
notification = UI.Notification(),
|
||||
}
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'password' then
|
||||
|
||||
if self.pass.value and
|
||||
#self.pass.value > 0 and
|
||||
Security.verifyPassword(SHA.compute(self.pass.value)) then
|
||||
|
||||
UI:exitPullEvents() -- valid
|
||||
else
|
||||
self.notification:error('Invalid password', math.max(counter, 2))
|
||||
self:sync()
|
||||
os.sleep(counter)
|
||||
counter = counter * 2
|
||||
|
||||
self.pass:reset()
|
||||
end
|
||||
else
|
||||
UI.Page.eventHandler(self, event)
|
||||
end
|
||||
end
|
||||
|
||||
Event.onTerminate(function() return false end)
|
||||
|
||||
UI:setPage(page)
|
||||
UI:pullEvents()
|
||||
|
||||
-- restart lock timer
|
||||
timer = os.startTimer(config.timeout)
|
||||
end
|
||||
|
||||
local function showLockScreen()
|
||||
timer = nil
|
||||
multishell.openTab({
|
||||
path = 'sys/apps/Lock.lua',
|
||||
fn = buildLockScreen,
|
||||
noTerminate = true,
|
||||
pinned = true,
|
||||
focused = true,
|
||||
title = 'Lock',
|
||||
env = sandboxEnv,
|
||||
})
|
||||
end
|
||||
|
||||
keyboard.addHotkey('control-l', function()
|
||||
if timer then
|
||||
os.cancelTimer(timer)
|
||||
showLockScreen()
|
||||
end
|
||||
end)
|
||||
|
||||
kernel.hook({ 'mouse_click', 'mouse_up', 'mouse_drag', 'key_up' }, function(event, eventData)
|
||||
if timer then
|
||||
os.cancelTimer(timer)
|
||||
timer = os.startTimer(config.timeout)
|
||||
end
|
||||
end)
|
||||
|
||||
kernel.hook('timer', function(_, eventData)
|
||||
if timer and eventData[1] == timer then
|
||||
showLockScreen()
|
||||
end
|
||||
end)
|
||||
4
secure/autorun/startup.lua
Normal file
4
secure/autorun/startup.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
local fs = _G.fs
|
||||
|
||||
-- add a System setup tab
|
||||
fs.mount('sys/apps/system/secure.lua', 'linkfs', 'packages/secure/system/secure.lua')
|
||||
59
secure/system/secure.lua
Normal file
59
secure/system/secure.lua
Normal file
@@ -0,0 +1,59 @@
|
||||
local Config = require('opus.config')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local config = Config.load('secure', {
|
||||
enabled = false,
|
||||
timeout = 60,
|
||||
})
|
||||
|
||||
local tab = UI.Tab {
|
||||
tabTitle = 'Secure',
|
||||
description = 'Secure options',
|
||||
label1 = UI.Text {
|
||||
x = 2, y = 3,
|
||||
value = 'Screen Locking',
|
||||
},
|
||||
checkbox = UI.Checkbox {
|
||||
x = 20, y = 3,
|
||||
value = config.enabled
|
||||
},
|
||||
label2 = UI.Text {
|
||||
x = 2, y = 4,
|
||||
value = 'Lock timeout',
|
||||
},
|
||||
timeout = UI.TextEntry {
|
||||
x = 20, y = 4, width = 6,
|
||||
limit = 4,
|
||||
transform = 'number',
|
||||
value = config.timeout,
|
||||
accelerators = {
|
||||
enter = 'update',
|
||||
},
|
||||
},
|
||||
label3 = UI.Text {
|
||||
ex = -2, y = -2, width = 20,
|
||||
textColor = colors.yellow,
|
||||
},
|
||||
button = UI.Button {
|
||||
x = 20, y = 6,
|
||||
text = 'Update',
|
||||
event = 'update',
|
||||
},
|
||||
}
|
||||
|
||||
function tab:eventHandler(event)
|
||||
if event.type =='checkbox_change' then
|
||||
config.enabled = not not event.checked
|
||||
|
||||
elseif event.type == 'update' then
|
||||
config.timeout = self.timeout.value
|
||||
Config.update('secure', config)
|
||||
|
||||
self:emit({ type = 'success_message', message = 'Settings updated' })
|
||||
self.label3.value = 'Restart is required'
|
||||
self.label3:draw()
|
||||
end
|
||||
return UI.Tab.eventHandler(self, event)
|
||||
end
|
||||
|
||||
return tab
|
||||
Reference in New Issue
Block a user