diff --git a/configs/everything-noinit.cfg b/configs/everything-noinit.cfg index 97ccab4..535d1d5 100644 --- a/configs/everything-noinit.cfg +++ b/configs/everything-noinit.cfg @@ -5,6 +5,7 @@ library/fs-min.lua library/fs-std.lua library/fs-util.lua util/fs-automount.lua +util/fs-automount-ext.lua drivers/tty.lua drivers/kbd.lua util/autogpu.lua @@ -15,10 +16,13 @@ library/base64.lua library/chauth.lua library/fs-ext.lua library/readline.lua +library/buffer.lua +library/io.lua net/nshd.lua net/nshc.lua net/nshd-auth.lua net/nshc-auth.lua +net/pxesrv.lua applications/shutil.lua applications/skex2.lua applications/luash.lua diff --git a/configs/headless-server.cfg b/configs/headless-server.cfg new file mode 100644 index 0000000..f7cdcca --- /dev/null +++ b/configs/headless-server.cfg @@ -0,0 +1,20 @@ +base/header.lua +library/print.lua +library/net.lua +library/readline.lua +net/nshd.lua +library/crc32.lua +library/chauth.lua +net/nshd.lua +net/nshd-auth.lua +applications/luash-login.lua +applications/shutil.lua +library/fs-min.lua +library/fs-std.lua +library/fs-ext.lua +library/buffer.lua +library/io.lua +util/fs-automount-min.lua +util/fs-automount-ext.lua +util/autonsh.lua +base/footer.lua diff --git a/modules/applications/luash-login.lua b/modules/applications/luash-login.lua new file mode 100644 index 0000000..ae4025a --- /dev/null +++ b/modules/applications/luash-login.lua @@ -0,0 +1,18 @@ +function luash(si) +s("lua shell",function() + local np = "" + while np ~= pass do + write("Password: ") + np=readln("*") + end + if _OSVERSION and _BD then + write(_OSVERSION.." on "..nID.." (built at ".._BD..")\t") + end + print(tostring(computer.freeMemory()/1024).."K free.",_G.motd) + print(_VERSION) + while true do + write("> ") + print(pcall(load(readln()))) + end +end,si) +end diff --git a/modules/library/fs-min.lua b/modules/library/fs-min.lua index 7415c52..7b22c5f 100644 --- a/modules/library/fs-min.lua +++ b/modules/library/fs-min.lua @@ -1,6 +1,6 @@ fT = {} function fres(p) - local F = (p:match("(%a-):") or p:match("/?(%a-)/")) - local P = (p:match("%a-:(.+)") or p:match("/?%a-/(.+)")) + local F = (p:match("(.-):") or p:match("/?(.-)/")) + local P = (p:match(".-:(.+)") or p:match("/?.-/(.+)")) if fT[F] ~= nil then return fT[F],P else return false end end diff --git a/modules/net/pxesrv.lua b/modules/net/pxesrv.lua new file mode 100644 index 0000000..dc4e600 --- /dev/null +++ b/modules/net/pxesrv.lua @@ -0,0 +1,59 @@ +function pxesrv(i,P,LF) -- port, image, log file + _G.pxcl = {} + local P,i,LF = P or 9671,i or "boot:/pxeimage.lua",LF or "boot:/pxetab.csv" + for k,v in ipairs(tM) do v.open(P) end + print("[netboot] loading data") + f=io.open(i) + if f then d=f:read("*a") f:close() + else error("image not found") + end + print("[netboot] server starting, port "..TS(P)..", image file "..i) + print("[netboot] loading existing data") + local f=io.open(LF) + C.yield() + if f then + local c = f:read("*a") + f:close() + for m,C,h,p in c:gmatch("(.-),(.-),(.-),(.-)\n") do + print(m.." = {"..C..", "..h..", "..p.."}") + pxcl[m]={C,h,p} + end + end + s("pxesrv",function() print(pcall(function() + while true do + if ev[1] == "modem_message" and ev[4] == P then + print("[netboot] request from "..ev[3]:sub(1,8)..":"..TS(ev[6]):sub(1,8)) + if type(pxcl[ev[3]]) ~= "table" then + pxcl[ev[3]]={ev[6],ev[6]:sub(1,8),"pass"} + else + pxcl[ev[3]]={ev[6],pxcl[ev[3]][2] or ev[6]:sub(1,8),pxcl[ev[3]][3] or "pass"} + end + fd=d:gsub("HOSTNAME",pxcl[ev[3]][2]) + fd=fd:gsub("PASSWORD",pxcl[ev[3]][3]) + local la,fr = ev[2],ev[3] + print(fd:len()) + for i = 1, fd:len(), 2048 do + component.invoke(la,"send",fr,P,fd:sub(i,i+2047)) + C.yield() + end + component.invoke(la,"send",fr,P,".") + end + C.yield() + end + end)) end) + s("pxesrv logger",function() print(pcall(function() + while true do + for i = 1, 100 do + C.yield() + end + f=fopen(LF,"w") + if f then + for k,v in pairs(pxcl) do + fwrite(f,k..","..v[1]..","..v[2]..","..v[3].."\n") + end + fclose(f) + C.yield() + end + end + end)) end) +end diff --git a/modules/util/autoexec.lua b/modules/util/autoexec.lua new file mode 100644 index 0000000..fb27cf6 --- /dev/null +++ b/modules/util/autoexec.lua @@ -0,0 +1,7 @@ +do + local f=io.open("/boot/autoexec.lua") + if f then + pcall(load(f:read("*a"))) + f:close() + end +end diff --git a/modules/util/autonsh.lua b/modules/util/autonsh.lua new file mode 100644 index 0000000..3665884 --- /dev/null +++ b/modules/util/autonsh.lua @@ -0,0 +1,3 @@ +_G.pass = "PASSWORD" +nshd("nsh") +nshds("nshs",pass) diff --git a/modules/util/fs-automount-ext.lua b/modules/util/fs-automount-ext.lua new file mode 100644 index 0000000..2879ae6 --- /dev/null +++ b/modules/util/fs-automount-ext.lua @@ -0,0 +1,9 @@ +do + local C=0 + for c in component.list("filesystem") do + if c ~= fT.boot.address and c ~= fT.tmp.address then + fT["fs"..string.format("%02d",C)] = component.proxy(c) + C=C+1 + end + end +end diff --git a/util/pixice.lua b/util/pixice.lua new file mode 100644 index 0000000..599c6d3 --- /dev/null +++ b/util/pixice.lua @@ -0,0 +1,58 @@ +--base/loadlin.lua +if pcall(require,"computer") then + print("OpenOS detected.") + print(os.getenv("_")) + local computer = require "computer" + local process = require "process" + os.execute("cp "..os.getenv("_").." /tmp/init.lua") + computer.setBootAddress(computer.tmpAddress()) + computer.shutdown(true) +end +-- actual code starts here +s="" +computer.getBootAddress = computer.tmpAddress +do + local addr=nil + local OCPS,OCSD,OCI=computer.pullSignal,computer.shutdown,component.invoke + function computer.pullSignal(...) + local tA={...} + local eV={OCPS(...)} + if eV[1] == "modem_message" and eV[3] == addr and eV[4] == 9671 then + if eV[6] == "reboot" then + OCSD(true) + end + return + end + return table.unpack(eV) + end + function computer.shutdown() + OCSD(true) + end + function component.invoke(...) + tA={...} + if tA[2] == "stop" then return end + return OCI(...) + end + local m=component.proxy(component.list("modem")()) + m.open(9671) + if addr then + m.send(addr,9671,computer.address()) + while true do + local ev={computer.pullSignal()} + if ev[1] == "modem_message" and ev[3] == addr and ev[4] == 9671 then + if ev[6] == "." then break end + s=s..ev[6] + end + end + else + m.broadcast(9671,computer.address()) + while true do + local ev={computer.pullSignal()} + if ev[1] == "modem_message" and ev[4] == 9671 then + if ev[6] == "." then break end + s=s..ev[6] + end + end + end +end +load(s)()