Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many changes #62

Open
wants to merge 9 commits into
base: develop-1.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sys/apps/Overview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ local config = {
}
Config.load('Overview', config)

local extSupport = Util.getVersion() >= 1.76
local extSupport = Util.supportsExtChars()

local applications = { }
local buttons = { }
Expand Down
16 changes: 12 additions & 4 deletions sys/apps/genotp.lua
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 7 additions & 3 deletions sys/apps/network/samba.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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)
22 changes: 16 additions & 6 deletions sys/apps/network/snmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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()
Expand All @@ -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)
12 changes: 6 additions & 6 deletions sys/apps/system/label.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sys/init/7.multishell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion sys/modules/opus/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion sys/modules/opus/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 11 additions & 8 deletions sys/modules/opus/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading