From 5c0ea3a2a26ad13a912a758c19e1c35fa108aa74 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Fri, 1 Nov 2019 16:36:47 -0600 Subject: [PATCH] typo + lock screen --- builder/.package | 2 +- ccemux/.package | 2 +- common/.package | 2 +- core/.package | 2 +- farms/.package | 2 +- forestry/.package | 2 +- games/.package | 2 +- gps/.package | 2 +- mbs/.package | 2 +- milo/.package | 2 +- miloApps/.package | 2 +- miners/.package | 2 +- monitor/.package | 2 +- neural/.package | 2 +- pickup/.package | 2 +- recipeBook/.package | 2 +- secure/.package | 6 +++ secure/autorun/lock.lua | 106 +++++++++++++++++++++++++++++++++++++ secure/autorun/startup.lua | 4 ++ secure/system/secure.lua | 59 +++++++++++++++++++++ shellex/.package | 2 +- swshop/.package | 2 +- turtle/.package | 2 +- 23 files changed, 194 insertions(+), 19 deletions(-) create mode 100644 secure/.package create mode 100644 secure/autorun/lock.lua create mode 100644 secure/autorun/startup.lua create mode 100644 secure/system/secure.lua diff --git a/builder/.package b/builder/.package index bfcf3b7..55b672a 100644 --- a/builder/.package +++ b/builder/.package @@ -6,5 +6,5 @@ title = 'Schematic Builder', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/builder', description = [[Build structures from schematic files using a turtle or command computer. ]], - licence = 'MIT', + license = 'MIT', } diff --git a/ccemux/.package b/ccemux/.package index 3a2f698..96ed673 100644 --- a/ccemux/.package +++ b/ccemux/.package @@ -4,5 +4,5 @@ description = [[Peripheral management for CCEmuX Adds a tab in the System application for configuring peripherals.]], - licence = 'MIT', + license = 'MIT', } diff --git a/common/.package b/common/.package index 38a1d4c..939bc39 100644 --- a/common/.package +++ b/common/.package @@ -12,5 +12,5 @@ * Screen recorder * and more... ]], - licence = 'MIT', + license = 'MIT', } diff --git a/core/.package b/core/.package index 9c3b3d8..d426b8e 100644 --- a/core/.package +++ b/core/.package @@ -2,5 +2,5 @@ title = 'APIs used by various programs', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/core', description = [[Provides APIs used by Opus applications.]], - licence = 'MIT', + license = 'MIT', } diff --git a/farms/.package b/farms/.package index a8dee05..1605ef5 100644 --- a/farms/.package +++ b/farms/.package @@ -10,5 +10,5 @@ * Cow/Sheep Rancher * Farmer ]], - licence = 'MIT', + license = 'MIT', } diff --git a/forestry/.package b/forestry/.package index 0b8913e..12a9f63 100644 --- a/forestry/.package +++ b/forestry/.package @@ -2,5 +2,5 @@ title = 'Forestry mod applications', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/forestry', description = [[WIP]], - licence = 'MIT', + license = 'MIT', } diff --git a/games/.package b/games/.package index 610e83e..0854e77 100644 --- a/games/.package +++ b/games/.package @@ -2,5 +2,5 @@ title = 'Games', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/games', description = [[Games by various people]], - licence = 'MIT', + license = 'MIT', } diff --git a/gps/.package b/gps/.package index 9a31617..96e5242 100644 --- a/gps/.package +++ b/gps/.package @@ -9,5 +9,5 @@ Uses 4 wireless modems connected to a single turtle or computer connected with network cables. The turtle will also initially place all the modems in the correct locations. ]], - licence = 'MIT', + license = 'MIT', } diff --git a/mbs/.package b/mbs/.package index 0307605..95bbaaf 100644 --- a/mbs/.package +++ b/mbs/.package @@ -7,5 +7,5 @@ https://github.com/SquidDev-CC/mbs MBS is a series of utilities for improving the default CraftOS experience. ]], - licence = 'MIT', + license = 'MIT', } diff --git a/milo/.package b/milo/.package index 0c444cb..3118be9 100644 --- a/milo/.package +++ b/milo/.package @@ -10,5 +10,5 @@ Includes: importing, exporting, autocrafting, replenish, limits and much more. Includes over 200 standard Minecraft recipes.]], - licence = 'MIT', + license = 'MIT', } diff --git a/miloApps/.package b/miloApps/.package index 30e04c8..4d131df 100644 --- a/miloApps/.package +++ b/miloApps/.package @@ -5,5 +5,5 @@ title = 'Milo extra applications', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/miloApps', description = [[Programs for turtles in a Milo network]], - licence = 'MIT', + license = 'MIT', } diff --git a/miners/.package b/miners/.package index 3778bd4..3b04820 100644 --- a/miners/.package +++ b/miners/.package @@ -7,5 +7,5 @@ description = [[Provides two types of automated mining: * Scanning Miner: Uses a block scanner to very efficiently mine areas * Simple Miner: A single or multi-turtle miner]], - licence = 'MIT', + license = 'MIT', } diff --git a/monitor/.package b/monitor/.package index f993c05..a8b656e 100644 --- a/monitor/.package +++ b/monitor/.package @@ -2,5 +2,5 @@ title = 'Various monitor related programs', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/monitor', description = [[Mirror terminal to monitor, Monitor Window Manager (mwm), and more]], - licence = 'MIT', + license = 'MIT', } diff --git a/neural/.package b/neural/.package index 1a29a25..e110beb 100644 --- a/neural/.package +++ b/neural/.package @@ -2,7 +2,7 @@ title = 'Programs for the neural interface', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/neural', description = [[ Applications using various plethora modules ]], - licence = 'MIT', + license = 'MIT', required = { 'core', }, diff --git a/pickup/.package b/pickup/.package index 3e1b222..28c774f 100644 --- a/pickup/.package +++ b/pickup/.package @@ -6,5 +6,5 @@ title = 'Move resources around with turtles', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/pickup', description = [[ WiP ]], - licence = 'MIT', + license = 'MIT', } diff --git a/recipeBook/.package b/recipeBook/.package index 04b1063..8b0f49b 100644 --- a/recipeBook/.package +++ b/recipeBook/.package @@ -2,5 +2,5 @@ title = 'Recipe books for crafting programs', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/recipeBook', description = [[ WIP ]], - licence = 'Recipes for crafting', + license = 'MIT', } diff --git a/secure/.package b/secure/.package new file mode 100644 index 0000000..2eb4e27 --- /dev/null +++ b/secure/.package @@ -0,0 +1,6 @@ +{ + title = 'Security features for Opus OS', + repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/secure', + description = [[ Screen locking ]], + license = 'MIT', +} diff --git a/secure/autorun/lock.lua b/secure/autorun/lock.lua new file mode 100644 index 0000000..dabc7ff --- /dev/null +++ b/secure/autorun/lock.lua @@ -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) diff --git a/secure/autorun/startup.lua b/secure/autorun/startup.lua new file mode 100644 index 0000000..2f5d4ed --- /dev/null +++ b/secure/autorun/startup.lua @@ -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') diff --git a/secure/system/secure.lua b/secure/system/secure.lua new file mode 100644 index 0000000..6a38094 --- /dev/null +++ b/secure/system/secure.lua @@ -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 diff --git a/shellex/.package b/shellex/.package index 20a3c8c..0263ea8 100644 --- a/shellex/.package +++ b/shellex/.package @@ -8,5 +8,5 @@ Linux style shell commands: grep, cat, touch, df, etc. Linux style cp, ls]], - licence = 'MIT', + license = 'MIT', } diff --git a/swshop/.package b/swshop/.package index 31a9f58..efb46ed 100644 --- a/swshop/.package +++ b/swshop/.package @@ -2,5 +2,5 @@ title = 'Switchcraft basic shop', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/swshop', description = 'Modification of the k store by Lemmmy\nRun installPlugin.lua after install', - licence = 'MIT', + license = 'MIT', } diff --git a/turtle/.package b/turtle/.package index 82b146e..4207ce7 100644 --- a/turtle/.package +++ b/turtle/.package @@ -2,5 +2,5 @@ title = 'Turtle programs and apis', repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/turtle', description = [[Support programs and apis for turtles]], - licence = 'MIT', + license = 'MIT', }