Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ufw()
- haa = fs.open(".fw", "r")
- dataa = haa.readAll()
- data = textutils.unserialize(dataa)
- return data
- end
- function split (inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function in_table ( e, t )
- for _,v in pairs(t) do
- if (v==e) then return true end
- end
- return false
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("====================")
- print("\n>> Gauugle! Modem <<")
- print("\n====================")
- shell.run("id")
- if fs.exists(".settings") == false then
- print("\n\nE' ora di impostare il modem!");
- print("\nInserisci il lato del cavo LAN:")
- lancable = read()
- print("\nPerfetto! Ora inserisci il lato del modem wireless:")
- wireless = read()
- print("\n\nSto preparando le impostazioni di sistema...")
- h = fs.open(".settings", "w")
- h.writeLine("lan = '"..lancable.."'");
- h.writeLine("wm = '"..wireless.."'");
- h.flush()
- h.close()
- ha = fs.open(".fw", "w")
- door = {}
- table.insert(door, "80")
- ha.write(textutils.serialize(door))
- ha.flush()
- ha.close()
- print("\nFatto! :D\nRiavvio il modem!")
- shell.run("reboot")
- else
- shell.run(".settings")
- rednet.open(wm)
- modem = peripheral.wrap(lan)
- end
- fw = ufw()
- -- Ok, inizia lo scambio ovvio di informazioni ma prima apro le porte desiderate. Default: 80
- while true do
- ids, msg, protocol = rednet.receive()
- if protocol == "configurazione" then
- print("Ricevuto messaggio su conf()");
- res = split(msg, "_")
- if msg == "data" then
- print("Ricevuto conf()data")
- rednet.send(ids, textutils.serialize(fw))
- elseif res[1] == "remove" then
- table.remove(fw, res[2])
- ha = fs.open(".fw", "w")
- table.insert(door, "80")
- ha.write(textutils.serialize(fw))
- ha.flush()
- ha.close()
- rednet.send(ids, textutils.serialize(fw))
- shell.run("reboot")
- elseif res[1] == "add" then
- table.insert(fw, res[2])
- ha = fs.open(".fw", "w")
- table.insert(door, "80")
- ha.write(textutils.serialize(fw))
- ha.flush()
- ha.close()
- rednet.send(ids, textutils.serialize(fw))
- shell.run("reboot")
- end
- else
- print("Ricevuto "..msg)
- print("Inoltro richiesta a "..msg..":80")
- modem.sendChannel(80, msg)
- for _, v in pairs(fw) do
- modem.setListening(v, true)
- end
- local event, side, id, chn, mess = os.pullEvent("lan_message")
- for lo, v in pairs(fw) do
- if chn ~= v then
- print("\nRichiesta su porta chiusa ("..v..")")
- shell.run("reboot")
- end
- end
- print("Ricevuto risposta da: 144.91.97."..id)
- sleep(0.7)
- rednet.send(ids, mess)
- end
- sleep(0.1)
- end
Add Comment
Please, Sign In to add comment