Compare commits

..

26 Commits

Author SHA1 Message Date
9e633867da :3 2024-08-26 00:16:13 +03:00
79c5654247 :3 2024-08-26 00:13:01 +03:00
6b864b43be :3 2024-08-26 00:09:32 +03:00
5fa92ae0c4 :3 2024-08-26 00:08:40 +03:00
4ccc4b07da :3 2024-08-26 00:07:19 +03:00
b0c5b756b1 :3 2024-08-26 00:05:54 +03:00
a3ca65a458 :3 2024-08-26 00:04:22 +03:00
d07a35f360 :3 2024-08-26 00:03:08 +03:00
b88ca058fa :3 2024-08-25 23:58:57 +03:00
df5e544347 :3 2024-08-25 23:56:01 +03:00
7c78db3620 :3 2024-08-25 23:53:40 +03:00
7ed9f76f15 :3 2024-08-25 23:47:51 +03:00
2a8932a19f :3 2024-08-25 23:36:03 +03:00
28ceac8643 :3 2024-08-25 22:00:12 +03:00
68422b9343 Merge branch 'main' of https://git.mcorangehq.xyz/xomf/keypadOS 2024-08-24 12:59:41 -04:00
dcc0a3e687 :3 2024-08-24 12:59:30 -04:00
9b48f2adcb update rom 2024-08-20 22:19:45 -04:00
9d8398565b how did we get here? 2024-08-21 02:17:19 +00:00
7292f271fb nvm XD 2024-08-18 12:12:48 -04:00
0e6fa358a7 testing color 2024-08-18 12:12:00 -04:00
20495931d0 :3 2024-08-18 12:09:22 -04:00
1e170263fd purple :3 2024-08-18 11:59:14 -04:00
7ce154ed44 more error resistance 2024-08-18 11:50:07 -04:00
4c2197919a ;-; 2024-08-18 15:09:33 +03:00
5eb4a9edb7 :3 2024-08-18 15:03:36 +03:00
87fb39b9bd change default code, implement true hashes 2024-08-18 15:02:01 +03:00
6 changed files with 82 additions and 135 deletions

View File

@@ -3,62 +3,23 @@ local __DEFAULT_IMPORT = require
local require = function(path)
if __BUNDLER_FILES[path] then
return __BUNDLER_FILES[path]()
elseif __BUNDLER_FILES[path .. ".lua"] then
return __BUNDLER_FILES[path .. ".lua"]()
else
return __DEFAULT_IMPORT(path)
end
end
local KEYPADOS_UPDATE_HASH = "ThZGemtZHshNpaflGvUHcJoZ"rawset(__BUNDLER_FILES, "updater.lua", function ()
local __UPDATE_HASH = "5e1c10aba96c3f9ded6aecb030f2774577c005af"
rawset(__BUNDLER_FILES, "updater.lua", function ()
local utils = require("utils.lua")
local config = require("config.lua")
local LAST_USED = os.time()
local mod = {}
local function checkForUpdate()
local current_time = os.time()
local difference = math.abs(current_time - LAST_USED)
if difference > .5 then
print("INFO: Updating! (diff: " .. tostring(difference) .. ")")
local update_code_request = http.get(config.release_url .. "?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
if update_code_request then
local update_code_text = update_code_request.readAll()
if update_code_text then
if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then
if fs.exists("backup.lua") then
fs.delete("backup.lua")
end
fs.copy("startup.lua", "backup.lua")
if not string.find(update_code_text, KEYPADOS_UPDATE_HASH) then
local file = fs.open("startup.lua", "w")
file.write(update_code_text)
file.close()
os.reboot()
else
print("Nothing changed, not updating.")
LAST_USED = os.time()
return
end
else
print("Bad file download (core)")
end
else
print("Bad mem read (core)")
end
else
print("Bad download (core)")
end
end
end
function mod.UpdateChecker()
while true do
checkForUpdate()
sleep(1)
end
end
function mod.GetBasalt()
if fs.exists("basalt.lua") then
utils.MonPrint("Basalt found!")
else
utils.MonPrint("Downloading basalt...")
local basalt_code = http.get(config.release_url).readAll()
local basalt_code = http.get(config.basalt_url).readAll()
utils.MonPrint("Installing basalt...")
local file = fs.open("basalt.lua", "w")
if not file then
@@ -76,9 +37,10 @@ local KEYPADOS_UPDATE_HASH = "ThZGemtZHshNpaflGvUHcJoZ"rawset(__BUNDLER_FILES, "
end)
rawset(__BUNDLER_FILES, "config.lua", function ()
local config = {
correctPin = "42169",
correctPin = "42069",
release_url = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua",
basalt_url = "https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua",
ntfy_url = "https://ntfy.sh/keypadOS_alerts",
config_path = "keypadOS.config.lua"
}
local DEFAULT_CONFIG = "return {\n" ..
@@ -117,8 +79,8 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
drive:ejectDisk()
end
end
basalt.debug("test")
if ui.pin == config.correctPin then
blibs.notifier.notify("5", "Unlocked door :3 love u");
ui.enterButton:setBackground(colors.green)
ui.pinLabel:setText("Welcome")
redstone.setOutput("front", true)
@@ -185,11 +147,11 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
end
end
local status, err = pcall(function ()
parallel.waitForAll(basalt.autoUpdate, updater.UpdateChecker)
parallel.waitForAll(basalt.autoUpdate)
end)
if not status and err ~= "Terminated" then
print("Error detected: " .. err)
http.post("https://ntfy.sh/keypadOS_alerts", err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
log.error("Error detected: " .. err)
blibs.notifier.notify("5", err); --exposed ntfy url no spam me pls
sleep(5)
utils.MonReset(0.5)
fs.delete("basalt.lua")
@@ -221,15 +183,17 @@ end)
rawset(__BUNDLER_FILES, "main.lua", function ()
local utils = require("utils.lua")
local updater = require("updater.lua")
local main = {}
local mod = {}
KEYPADOS_VERSION = "4.0"
function main.Main()
function mod.main(blibs)
_G.log = blibs.log;
_G.blibs = blibs;
utils.MonReset(0.5)
updater.GetBasalt()
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
utils.MonReset(1)
require("ui.lua").InitUi()
end
return main
return mod;
end)
require("main.lua").Main()
return require("main.lua")

View File

@@ -1,5 +1,5 @@
local config = {
correctPin = "42169",
correctPin = "42069",
release_url = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua",
basalt_url = "https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua",
ntfy_url = "https://ntfy.sh/keypadOS_alerts",
@@ -13,7 +13,7 @@ local DEFAULT_CONFIG = "return {\n" ..
--- @class Config
--- @field group string
--- Read current configs, create if doesnt exist
--- Read current configs, create if doesnt exist :3
---@return Config
function config.ReadConfig()
if not fs.exists(config.config_path) then

View File

@@ -1,13 +1,37 @@
-- keycardOS "bootloader", has no access to basalt
-- intended for checking for updates, and automatically updating basalt if it is missing
local utils = require("utils.lua")
local updater = require("updater.lua")
local main = {}
local mod = {}
KEYPADOS_VERSION = "4.0"
function main.Main()
--- @class BootloaderLibs
--- @field log Logger
--- @field updater Updater
--- @field notifier Notifier
--- @field json JsonParser
--- @class Logger
--- @field error fun(...)
--- @field warn fun(...)
--- @field info fun(...)
--- @field debug fun(...)
--- @class Updater
--- @field addEntry fun(path: string, branch: string, url: string)
--- @class JsonParser
--- @field decode fun(s: string): table
--- @field encode fun(s: table): string
--- @class Notifier
--- @field notify fun(priority: "1"|"2"|"3"|"4"|"5", body: string)
---@param blibs BootloaderLibs
function mod.main(blibs)
_G.log = blibs.log;
_G.blibs = blibs;
utils.MonReset(0.5)
updater.GetBasalt()
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
@@ -16,5 +40,5 @@ function main.Main()
end
return main
return mod;

View File

@@ -2,6 +2,7 @@ local utils = require("utils.lua")
local basalt = require("basalt")
local config = require("config.lua")
local updater = require("updater.lua")
--- @type Monitor
local monitor = utils.Cast(peripheral.find("monitor"))
--- @type drive
@@ -36,8 +37,8 @@ local function unlockDoor(ui)
end
end
basalt.debug("test")
if ui.pin == config.correctPin then
blibs.notifier.notify("5", "Unlocked door :3 love u");
ui.enterButton:setBackground(colors.green)
ui.pinLabel:setText("Welcome")
redstone.setOutput("front", true)
@@ -117,12 +118,12 @@ function mod.InitUi()
end
local status, err = pcall(function ()
parallel.waitForAll(basalt.autoUpdate, updater.UpdateChecker)
parallel.waitForAll(basalt.autoUpdate)
end)
if not status and err ~= "Terminated" then
print("Error detected: " .. err)
http.post(config.ntfy_url, err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
log.error("Error detected: " .. err)
blibs.notifier.notify("5", err); --exposed ntfy url no spam me pls
sleep(5)
utils.MonReset(0.5)
fs.delete("basalt.lua")

View File

@@ -1,68 +1,15 @@
local utils = require("utils.lua")
local config = require("config.lua")
local LAST_USED = os.time()
local mod = {}
-- For lsp, shouldnt ever be check for true
if not __UPDATE_HASH then
__UPDATE_HASH = "WHATTHEFUCK";
end
local function checkForUpdate()
local current_time = os.time()
local difference = math.abs(current_time - LAST_USED)
-- print("INFO: Checking for update... difference: " .. tostring(difference))
--its been considerable time since the keypad was interacted with
--therefore it's time to force an update down the users throat (microsoft moment)
if difference > .5 then
print("INFO: Updating! (diff: " .. tostring(difference) .. ")")
local update_code_request = http.get(config.release_url .. "?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
if update_code_request then
local update_code_text = update_code_request.readAll()
if update_code_text then
if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then
-- Make backup
if fs.exists("backup.lua") then
fs.delete("backup.lua")
end
fs.copy("startup.lua", "backup.lua")
if not string.find(update_code_text, __UPDATE_HASH) then
local file = fs.open("startup.lua", "w")
file.write(update_code_text)
file.close()
os.reboot()
else
print("Nothing changed, not updating.")
LAST_USED = os.time()
return
end
else
print("Bad file download (core)")
end
else
print("Bad mem read (core)")
end
else
print("Bad download (core)")
end
end
end
function mod.UpdateChecker()
while true do
checkForUpdate()
sleep(1)
end
end
function mod.GetBasalt()
if fs.exists("basalt.lua") then
utils.MonPrint("Basalt found!")
else
utils.MonPrint("Downloading basalt...")
local basalt_code = http.get(config.release_url).readAll()
local basalt_code = http.get(config.basalt_url).readAll()
utils.MonPrint("Installing basalt...")
local file = fs.open("basalt.lua", "w")

45
x.py
View File

@@ -1,7 +1,5 @@
#!/usr/bin/python
import string
import random
UPDATE_ID= ''.join(random.choices(string.ascii_letters, k=24))
import hashlib
OUTPUT="keypadOS.lua";
FILES= [
"updater.lua",
@@ -36,29 +34,42 @@ def minimise(buf: str) -> str:
newbuf += line + "\n";
return newbuf;
def get_hash(buf: str) -> str:
hasher = hashlib.sha1();
hasher.update(bytes(buf, "utf-8"));
return hasher.hexdigest();
REQ_HEADER = """
local __BUNDLER_FILES = {}
local __DEFAULT_IMPORT = require
local require = function(path)
if __BUNDLER_FILES[path] then
return __BUNDLER_FILES[path]()
elseif __BUNDLER_FILES[path .. ".lua"] then
return __BUNDLER_FILES[path .. ".lua"]()
else
return __DEFAULT_IMPORT(path)
end
end
local __UPDATE_HASH = __BUNDLER_REPLACE_HASH__
"""
def main():
buf = ""
buf += "local __UPDATE_HASH = \"" + {UPDATE_ID} + "\"";
buf += "local __BUNDLER_FILES = {}\n";
buf += "local __DEFAULT_IMPORT = require\n";
buf += "local require = function(path)\n";
buf += " if __BUNDLER_FILES[path] then\n";
buf += " return __BUNDLER_FILES[path]()\n";
buf += " else\n";
buf += " return __DEFAULT_IMPORT(path)\n";
buf += " end\n";
buf += "end\n";
buf += REQ_HEADER;
for file in FILES:
print(f"=== FILE: {file}");
buf += read_file(file);
print(f"=== UPDATE HASH: {UPDATE_ID}")
buf += "require(\"main.lua\").Main()\n";
buf += "return require(\"main.lua\")";
if MINIMISE:
buf = minimise(buf);
update_hash = get_hash(buf);
buf = buf.replace("__BUNDLER_REPLACE_HASH__", f"\"{update_hash}\"");
print(f"=== UPDATE HASH: {update_hash}")
with open(OUTPUT, "w", encoding="utf-8") as f:
f.write(buf);
print("DONE");