mirror of
https://github.com/kepler155c/opus
synced 2025-04-07 08:06:54 +00:00
Merge 9b502553e064635a27fff50c099151c68e29d824 into 4104750539695affeb6518947b53ef0c5ba372fb
This commit is contained in:
commit
5974bf5456
@ -51,7 +51,7 @@ local config = {
|
||||
}
|
||||
Config.load('Overview', config)
|
||||
|
||||
local extSupport = Util.getVersion() >= 1.76
|
||||
local extSupport = Util.supportsExtChars()
|
||||
|
||||
local applications = { }
|
||||
local buttons = { }
|
||||
|
@ -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)
|
||||
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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user