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