Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- latency = 0
- function ufw()
- haa = fs.open(".fw", "r")
- dataa = haa.readAll()
- data = textutils.unserialize(dataa)
- return data
- end
- function removeEl(tbl, val)
- for i, v in ipairs(tbl) do
- if v == val then
- return table.remove(tbl, i)
- end
- end
- 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, msga, protocol = rednet.receive()
- msg = msga
- lol = split(msga, "()")
- if lol[1] == "firewall" then
- print("Ricevuto conf()data")
- rednet.send(ids, textutils.serialize(fw))
- shell.run("reboot")
- elseif lol[1] == "remove" then
- print("Rimozione porta "..lol[2].." in corso...")
- removeEl(fw, lol[2])
- ha = fs.open(".fw", "w")
- ha.write(textutils.serialize(fw))
- ha.flush()
- ha.close()
- shell.run("reboot")
- elseif lol[1] == "add" then
- print("add")
- table.insert(fw, lol[2])
- ha = fs.open(".fw", "w")
- ha.write(textutils.serialize(fw))
- ha.flush()
- ha.close()
- shell.run("reboot")
- elseif lol[1] == "search" then
- print("Ricevuto "..lol[2])
- print("Inoltro richiesta a "..lol[2]..":81")
- modem.sendChannel(81, lol[2])
- for _, v in pairs(fw) do
- modem.setListening(tonumber(v), true)
- end
- local event, side, id, chn, mess = os.pullEvent("lan_message")
- print("Ricevuto risposta da: 144.91.97."..id)
- sleep(latency)
- rednet.send(ids, mess, "httpwebtransfer")
- elseif lol[1] == "game" then
- print("Ricevuto "..lol[2]..":51")
- print("Inoltro richiesta a "..lol[2]..":51")
- modem.sendChannel(51, lol[2])
- for _, v in pairs(fw) do
- modem.setListening(tonumber(v), true)
- end
- local event, side, id, chn, mess = os.pullEvent("lan_message")
- print("Ricevuto risposta da: 144.91.97."..id)
- rednet.send(ids, mess, "httpwebtransfer")
- elseif lol[1] == "chat" then
- print("Ricevuto "..lol[2]..":70")
- print("Inoltro richiesta a "..lol[2]..":70")
- modem.sendChannel(70, lol[2])
- for _, v in pairs(fw) do
- modem.setListening(tonumber(v), true)
- end
- local event, side, id, chn, mess = os.pullEvent("lan_message")
- print("Ricevuto risposta da: 144.91.97."..id)
- rednet.send(ids, mess, "httpwebtransfer")
- else
- exit()
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement