math.randomseed(os.time()) local function tempname() local name = "/tmp/das-" name = name..math.random(1000,9999) return(name) end local on_digiline_receive = function (pos, node, channel, msg) local meta = minetest.get_meta(pos) local setchan = meta:get_string("channel") local dev = meta:get_string("device") local intemp = tempname() local outtemp = tempname() local ret = {} local sendlen = 0 if channel ~= setchan then return end if type(msg) ~= "table" then return end local cdb = "" for i=1,string.len(msg.cdb),1 do local byte = string.sub(msg.cdb,i,i) cdb = string.format("%s %02X",cdb,string.byte(byte)) end local cmd = "sudo sg_raw -vvvR "..dev..cdb if msg.request then cmd = cmd.." -r "..msg.request.." -o "..intemp end if msg.data then sendlen = string.len(msg.data) local outfile = io.open(outtemp,"w") outfile:write(msg.data) outfile:close() cmd = cmd.." -s "..sendlen.." -i "..outtemp end print(cmd) ret.sk = os.execute(cmd) if msg.request then local infile = io.open(intemp,"r") if infile then local indata = infile:read("*all") infile:close() os.execute("sudo rm "..intemp) ret.data = indata end end if msg.data then os.execute("sudo rm "..outtemp) end digiline:receptor_send(pos, digiline.rules.default, channel, ret) end minetest.register_node("das:scsi_gateway", { tiles = { "das_logo.png" }, digiline = { receptor = {}, effector = {action = on_digiline_receive} }, groups = {cracky=2}, description = "DAS<->SCSI Gateway", on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("formspec","size[8,4;]field[1,1;6,2;channel;Channel;${channel}]field[1,2;6,2;device;Device;${device}]button_exit[2.25,3;3,1;submit;Save]") meta:set_string("device","/dev/sda") meta:set_string("channel","scsi") end, on_receive_fields = function(pos, formname, fields, sender) local name = sender:get_player_name() if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then minetest.record_protection_violation(pos,name) return end local meta = minetest.get_meta(pos) if fields.channel then meta:set_string("channel",fields.channel) end if fields.device then meta:set_string("device",fields.device) end end, sounds = default.node_sound_stone_defaults() })