diff --git a/sys/apps/Overview.lua b/sys/apps/Overview.lua index 722127ec..b5edf39b 100644 --- a/sys/apps/Overview.lua +++ b/sys/apps/Overview.lua @@ -51,7 +51,7 @@ local config = { } Config.load('Overview', config) -local extSupport = Util.getVersion() >= 1.76 +local extSupport = Util.supportsExtChars() local applications = { } local buttons = { } diff --git a/sys/apps/genotp.lua b/sys/apps/genotp.lua index cdaf6eb3..9c1abb73 100644 --- a/sys/apps/genotp.lua +++ b/sys/apps/genotp.lua @@ -1,14 +1,22 @@ local SHA = require("opus.crypto.sha2") -local acceptableCharacters = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} +local acceptableCharacters = {} +for c = 0, 127 do + local char = string.char(c) + -- exclude potentially ambiguous characters + if char:match("[1-9a-zA-Z]") and char:match("[^OIl]") then + table.insert(acceptableCharacters, char) + end +end local acceptableCharactersLen = #acceptableCharacters - local password = "" -for _i = 1, 8 do +for i = 1, 10 do password = password .. acceptableCharacters[math.random(acceptableCharactersLen)] end os.queueEvent("set_otp", SHA.compute(password)) -print("Your one-time password is: " .. password) \ No newline at end of file +print("This allows one other device to permanently gain access to this device.") +print("Use the trust settings in System to revert this.") +print("Your one-time password is: " .. password) diff --git a/sys/apps/network/samba.lua b/sys/apps/network/samba.lua index 50cbfd0a..5e8d59c6 100644 --- a/sys/apps/network/samba.lua +++ b/sys/apps/network/samba.lua @@ -59,6 +59,10 @@ local function sambaConnection(socket) print('samba: Connection closed') end +local function sanitizeLabel(computer) + return (computer.id.."_"..computer.label:gsub("[%c%.\"'/%*]", "")):sub(1, 40) +end + Event.addRoutine(function() print('samba: listening on port 139') @@ -79,10 +83,10 @@ Event.addRoutine(function() end) Event.on('network_attach', function(_, computer) - fs.mount(fs.combine('network', computer.label), 'netfs', computer.id) + fs.mount(fs.combine('network', sanitizeLabel(computer)), 'netfs', computer.id) end) Event.on('network_detach', function(_, computer) - print('samba: detaching ' .. computer.label) - fs.unmount(fs.combine('network', computer.label)) + print('samba: detaching ' .. sanitizeLabel(computer)) + fs.unmount(fs.combine('network', sanitizeLabel(computer))) end) diff --git a/sys/apps/network/snmp.lua b/sys/apps/network/snmp.lua index 2c48ee15..39724411 100644 --- a/sys/apps/network/snmp.lua +++ b/sys/apps/network/snmp.lua @@ -152,7 +152,7 @@ local function getSlots() end local function sendInfo() - if os.clock() - infoTimer >= 1 then -- don't flood + if os.clock() - infoTimer >= 5 then -- don't flood infoTimer = os.clock() info.label = os.getComputerLabel() info.uptime = math.floor(os.clock()) @@ -194,16 +194,25 @@ local function sendInfo() end end --- every 10 seconds, send out this computer's info -Event.onInterval(10, function() - sendInfo() +local function cleanNetwork() for _,c in pairs(_G.network) do local elapsed = os.clock()-c.timestamp - if c.active and elapsed > 15 then + if c.active and elapsed > 50 then c.active = false os.queueEvent('network_detach', c) end end +end + +-- every 30 seconds, send out this computer's info +-- send with offset so that messages are evenly distributed and do not all come at once +Event.onTimeout(math.random() * 30, function() + sendInfo() + cleanNetwork() + Event.onInterval(30, function() + sendInfo() + cleanNetwork() + end) end) Event.on('turtle_response', function() @@ -213,4 +222,5 @@ Event.on('turtle_response', function() end end) -Event.onTimeout(1, sendInfo) +-- send info early so that computers show soon after booting +Event.onTimeout(math.random() * 2 + 1, sendInfo) diff --git a/sys/apps/system/label.lua b/sys/apps/system/label.lua index ba381092..61d36983 100644 --- a/sys/apps/system/label.lua +++ b/sys/apps/system/label.lua @@ -26,12 +26,12 @@ return UI.Tab { x = 2, y = 5, ex = -2, ey = -2, values = { { name = '', value = '' }, - { name = 'CC version', value = Util.getVersion() }, - { name = 'Lua version', value = _VERSION }, - { name = 'MC version', value = Util.getMinecraftVersion() }, - { name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) }, - { name = 'Computer ID', value = tostring(os.getComputerID()) }, - { name = 'Day', value = tostring(os.day()) }, + { name = 'CC version', value = ("%d.%d"):format(Util.getVersion()) }, + { name = 'Lua version', value = _VERSION }, + { name = 'MC version', value = Util.getMinecraftVersion() }, + { name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) }, + { name = 'Computer ID', value = tostring(os.getComputerID()) }, + { name = 'Day', value = tostring(os.day()) }, }, disableHeader = true, inactive = true, diff --git a/sys/init/7.multishell.lua b/sys/init/7.multishell.lua index 728a3802..b799584c 100644 --- a/sys/init/7.multishell.lua +++ b/sys/init/7.multishell.lua @@ -14,7 +14,7 @@ local parentTerm = _G.device.terminal local w,h = parentTerm.getSize() local overviewId local tabsDirty = false -local closeInd = Util.getVersion() >= 1.76 and '\215' or '*' +local closeInd = Util.supportsExtChars() and '\215' or '*' local multishell = { } _ENV.multishell = multishell diff --git a/sys/modules/opus/json.lua b/sys/modules/opus/json.lua index 04b1cd11..41d0e368 100644 --- a/sys/modules/opus/json.lua +++ b/sys/modules/opus/json.lua @@ -39,7 +39,8 @@ if register_global_module_table then _G[global_module_name] = json end -local _ENV = nil -- blocking globals in Lua 5.2 +-- this was incompatible because we use fs later +--local _ENV = nil -- blocking globals in Lua 5.2 pcall (function() -- Enable access to blocked metatables. diff --git a/sys/modules/opus/ui.lua b/sys/modules/opus/ui.lua index 8451e1d6..c5b412e8 100644 --- a/sys/modules/opus/ui.lua +++ b/sys/modules/opus/ui.lua @@ -44,7 +44,7 @@ function UI:init() tertiary = colors.gray, } } - self.extChars = Util.getVersion() >= 1.76 + self.extChars = Util.supportsExtChars() local function keyFunction(event, code, held) local ie = Input:translate(event, code, held) diff --git a/sys/modules/opus/util.lua b/sys/modules/opus/util.lua index 484231ba..9c455c6c 100644 --- a/sys/modules/opus/util.lua +++ b/sys/modules/opus/util.lua @@ -170,16 +170,19 @@ function Util.print(pattern, ...) end function Util.getVersion() - local version + local versionString = _G._HOST or _G._CC_VERSION + local versionMajor, versionMinor = versionString:match("(%d+)%.(%d+)") + -- ex.: 1.89 would return 1, 89 + return tonumber(versionMajor), tonumber(versionMinor) +end - if _G._CC_VERSION then - version = tonumber(_G._CC_VERSION:match('[%d]+%.?[%d][%d]')) - end - if not version and _G._HOST then - version = tonumber(_G._HOST:match('[%d]+%.?[%d][%d]')) - end +function Util.compareVersion(major, minor) + local currentMajor, currentMinor = Util.getVersion() + return currentMajor > major or currentMajor == major and currentMinor >= minor +end - return version or 1.7 +function Util.supportsExtChars() + return Util.compareVersion(1, 76) end function Util.getMinecraftVersion()