9 Commits

Author SHA1 Message Date
Kan18
9b502553e0 Update json.lua 2023-12-17 10:14:40 -05:00
Kan18
c247097e20 oops 2022-12-28 20:25:52 +04:00
Kan18
2597724dab Fix Util.getVersion 2022-12-28 20:05:16 +04:00
Kan18
5f153721ea oops 2022-12-28 19:26:48 +04:00
Kan18
0a42551ab7 actually set it to 30 2022-12-28 19:22:38 +04:00
Kan18
76b310d873 oops 2022-12-28 19:22:20 +04:00
Kan18
f26f443b9d Increase discovery message interval, distribute messages
Previously on large server(s), there was an issue where because
chunkloaded computers all started up at once, so they all had the same
discovery message sending timer. This prevents that by starting each off
with a random offset. Also increases the interval for sending messages
from 15 s to 30 s, so that messages (which are the same, a lot of the
time) get sent less often.
2022-12-28 18:43:49 +04:00
Kan18
8fbcc7b8bc Sanitize label in samba.lua
Prevent labels from having .., /, *, control characters, or quotes (this
generally messes things up) and limit them to a reasonable length. We
might possibly also want to do this in snmp.lua, I'm not sure if that
will break things though
2022-12-28 18:26:27 +04:00
Kan18
f7ba900930 genotp.lua changes
Make genotp more clearly state that the password can be used once but
allows permanent access (sorry for not making this clear earlier.) Use a
slightly longer password, and allow uppercase characters except for some
that could be ambiguous
2022-12-28 13:22:57 +04:00
9 changed files with 57 additions and 31 deletions

View File

@@ -51,7 +51,7 @@ local config = {
} }
Config.load('Overview', config) Config.load('Overview', config)
local extSupport = Util.getVersion() >= 1.76 local extSupport = Util.supportsExtChars()
local applications = { } local applications = { }
local buttons = { } local buttons = { }

View File

@@ -1,14 +1,22 @@
local SHA = require("opus.crypto.sha2") 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 acceptableCharactersLen = #acceptableCharacters
local password = "" local password = ""
for _i = 1, 8 do for i = 1, 10 do
password = password .. acceptableCharacters[math.random(acceptableCharactersLen)] password = password .. acceptableCharacters[math.random(acceptableCharactersLen)]
end end
os.queueEvent("set_otp", SHA.compute(password)) os.queueEvent("set_otp", SHA.compute(password))
print("Your one-time password is: " .. password) 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)

View File

@@ -59,6 +59,10 @@ local function sambaConnection(socket)
print('samba: Connection closed') print('samba: Connection closed')
end end
local function sanitizeLabel(computer)
return (computer.id.."_"..computer.label:gsub("[%c%.\"'/%*]", "")):sub(1, 40)
end
Event.addRoutine(function() Event.addRoutine(function()
print('samba: listening on port 139') print('samba: listening on port 139')
@@ -79,10 +83,10 @@ Event.addRoutine(function()
end) end)
Event.on('network_attach', function(_, computer) 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) end)
Event.on('network_detach', function(_, computer) Event.on('network_detach', function(_, computer)
print('samba: detaching ' .. computer.label) print('samba: detaching ' .. sanitizeLabel(computer))
fs.unmount(fs.combine('network', computer.label)) fs.unmount(fs.combine('network', sanitizeLabel(computer)))
end) end)

View File

@@ -152,7 +152,7 @@ local function getSlots()
end end
local function sendInfo() local function sendInfo()
if os.clock() - infoTimer >= 1 then -- don't flood if os.clock() - infoTimer >= 5 then -- don't flood
infoTimer = os.clock() infoTimer = os.clock()
info.label = os.getComputerLabel() info.label = os.getComputerLabel()
info.uptime = math.floor(os.clock()) info.uptime = math.floor(os.clock())
@@ -194,16 +194,25 @@ local function sendInfo()
end end
end end
-- every 10 seconds, send out this computer's info local function cleanNetwork()
Event.onInterval(10, function()
sendInfo()
for _,c in pairs(_G.network) do for _,c in pairs(_G.network) do
local elapsed = os.clock()-c.timestamp local elapsed = os.clock()-c.timestamp
if c.active and elapsed > 15 then if c.active and elapsed > 50 then
c.active = false c.active = false
os.queueEvent('network_detach', c) os.queueEvent('network_detach', c)
end end
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) end)
Event.on('turtle_response', function() Event.on('turtle_response', function()
@@ -213,4 +222,5 @@ Event.on('turtle_response', function()
end end
end) end)
Event.onTimeout(1, sendInfo) -- send info early so that computers show soon after booting
Event.onTimeout(math.random() * 2 + 1, sendInfo)

View File

@@ -26,12 +26,12 @@ return UI.Tab {
x = 2, y = 5, ex = -2, ey = -2, x = 2, y = 5, ex = -2, ey = -2,
values = { values = {
{ name = '', value = '' }, { name = '', value = '' },
{ name = 'CC version', value = Util.getVersion() }, { name = 'CC version', value = ("%d.%d"):format(Util.getVersion()) },
{ name = 'Lua version', value = _VERSION }, { name = 'Lua version', value = _VERSION },
{ name = 'MC version', value = Util.getMinecraftVersion() }, { name = 'MC version', value = Util.getMinecraftVersion() },
{ name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) }, { name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) },
{ name = 'Computer ID', value = tostring(os.getComputerID()) }, { name = 'Computer ID', value = tostring(os.getComputerID()) },
{ name = 'Day', value = tostring(os.day()) }, { name = 'Day', value = tostring(os.day()) },
}, },
disableHeader = true, disableHeader = true,
inactive = true, inactive = true,

View File

@@ -14,7 +14,7 @@ local parentTerm = _G.device.terminal
local w,h = parentTerm.getSize() local w,h = parentTerm.getSize()
local overviewId local overviewId
local tabsDirty = false local tabsDirty = false
local closeInd = Util.getVersion() >= 1.76 and '\215' or '*' local closeInd = Util.supportsExtChars() and '\215' or '*'
local multishell = { } local multishell = { }
_ENV.multishell = multishell _ENV.multishell = multishell

View File

@@ -39,7 +39,8 @@ if register_global_module_table then
_G[global_module_name] = json _G[global_module_name] = json
end 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() pcall (function()
-- Enable access to blocked metatables. -- Enable access to blocked metatables.

View File

@@ -44,7 +44,7 @@ function UI:init()
tertiary = colors.gray, tertiary = colors.gray,
} }
} }
self.extChars = Util.getVersion() >= 1.76 self.extChars = Util.supportsExtChars()
local function keyFunction(event, code, held) local function keyFunction(event, code, held)
local ie = Input:translate(event, code, held) local ie = Input:translate(event, code, held)

View File

@@ -170,16 +170,19 @@ function Util.print(pattern, ...)
end end
function Util.getVersion() 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 function Util.compareVersion(major, minor)
version = tonumber(_G._CC_VERSION:match('[%d]+%.?[%d][%d]')) local currentMajor, currentMinor = Util.getVersion()
end return currentMajor > major or currentMajor == major and currentMinor >= minor
if not version and _G._HOST then end
version = tonumber(_G._HOST:match('[%d]+%.?[%d][%d]'))
end
return version or 1.7 function Util.supportsExtChars()
return Util.compareVersion(1, 76)
end end
function Util.getMinecraftVersion() function Util.getMinecraftVersion()