SHOW:
|
|
- or go back to the newest paste.
1 | latency = 0 | |
2 | ||
3 | function ufw() | |
4 | haa = fs.open(".fw", "r") | |
5 | dataa = haa.readAll() | |
6 | data = textutils.unserialize(dataa) | |
7 | return data | |
8 | end | |
9 | ||
10 | function removeEl(tbl, val) | |
11 | for i, v in ipairs(tbl) do | |
12 | if v == val then | |
13 | return table.remove(tbl, i) | |
14 | end | |
15 | end | |
16 | end | |
17 | ||
18 | function split (inputstr, sep) | |
19 | if sep == nil then | |
20 | sep = "%s" | |
21 | end | |
22 | local t={} | |
23 | for str in string.gmatch(inputstr, "([^"..sep.."]+)") do | |
24 | table.insert(t, str) | |
25 | end | |
26 | return t | |
27 | end | |
28 | ||
29 | function in_table ( e, t ) | |
30 | for _,v in pairs(t) do | |
31 | if (v==e) then return true end | |
32 | end | |
33 | return false | |
34 | end | |
35 | ||
36 | term.clear() | |
37 | term.setCursorPos(1, 1) | |
38 | print("====================") | |
39 | print("\n>> Gauugle! Modem <<") | |
40 | print("\n====================") | |
41 | shell.run("id") | |
42 | ||
43 | if fs.exists(".settings") == false then | |
44 | print("\n\nE' ora di impostare il modem!"); | |
45 | print("\nInserisci il lato del cavo LAN:") | |
46 | lancable = read() | |
47 | print("\nPerfetto! Ora inserisci il lato del modem wireless:") | |
48 | wireless = read() | |
49 | print("\n\nSto preparando le impostazioni di sistema...") | |
50 | h = fs.open(".settings", "w") | |
51 | h.writeLine("lan = '"..lancable.."'"); | |
52 | h.writeLine("wm = '"..wireless.."'"); | |
53 | h.flush() | |
54 | h.close() | |
55 | ha = fs.open(".fw", "w") | |
56 | door = {} | |
57 | table.insert(door, "80") | |
58 | ha.write(textutils.serialize(door)) | |
59 | ha.flush() | |
60 | ha.close() | |
61 | print("\nFatto! :D\nRiavvio il modem!") | |
62 | shell.run("reboot") | |
63 | - | ids, msg, protocol = rednet.receive() |
63 | + | |
64 | shell.run(".settings") | |
65 | - | print("Protoc: "..protocol) |
65 | + | |
66 | - | if protocol == "39.255573" then |
66 | + | |
67 | - | print("Ricevuto messaggio su conf()"); |
67 | + | |
68 | - | res = split(msg, "_") |
68 | + | |
69 | - | if msg == "data" then |
69 | + | |
70 | -- Ok, inizia lo scambio ovvio di informazioni ma prima apro le porte desiderate. Default: 80 | |
71 | while true do | |
72 | - | elseif res[1] == "remove" then |
72 | + | |
73 | - | table.remove(fw, res[2]) |
73 | + | ids, msga, protocol = rednet.receive() |
74 | ||
75 | msg = msga | |
76 | lol = split(msga, "()") | |
77 | if lol[1] == "firewall" then | |
78 | print("Ricevuto conf()data") | |
79 | rednet.send(ids, textutils.serialize(fw)) | |
80 | shell.run("reboot") | |
81 | - | elseif res[1] == "add" then |
81 | + | elseif lol[1] == "remove" then |
82 | - | table.insert(fw, res[2]) |
82 | + | print("Rimozione porta "..lol[2].." in corso...") |
83 | removeEl(fw, lol[2]) | |
84 | ha = fs.open(".fw", "w") | |
85 | ha.write(textutils.serialize(fw)) | |
86 | ha.flush() | |
87 | ha.close() | |
88 | shell.run("reboot") | |
89 | elseif lol[1] == "add" then | |
90 | print("add") | |
91 | table.insert(fw, lol[2]) | |
92 | ha = fs.open(".fw", "w") | |
93 | - | print("Ricevuto "..msg) |
93 | + | |
94 | - | print("Inoltro richiesta a "..msg..":80") |
94 | + | |
95 | ha.close() | |
96 | - | modem.sendChannel(80, msg) |
96 | + | |
97 | elseif lol[1] == "search" then | |
98 | - | for _, v in pairs(fw) do |
98 | + | |
99 | - | modem.setListening(v, true) |
99 | + | print("Ricevuto "..lol[2]) |
100 | print("Inoltro richiesta a "..lol[2]..":81") | |
101 | ||
102 | - | local event, side, id, chn, mess = os.pullEvent("lan_message") |
102 | + | modem.sendChannel(81, lol[2]) |
103 | ||
104 | - | for lo, v in pairs(fw) do |
104 | + | for _, v in pairs(fw) do |
105 | - | if chn ~= v then |
105 | + | modem.setListening(tonumber(v), true) |
106 | - | print("\nRichiesta su porta chiusa ("..v..")") |
106 | + | end |
107 | - | shell.run("reboot") |
107 | + | |
108 | - | end |
108 | + | local event, side, id, chn, mess = os.pullEvent("lan_message") |
109 | ||
110 | print("Ricevuto risposta da: 144.91.97."..id) | |
111 | - | print("Ricevuto risposta da: 144.91.97."..id) |
111 | + | |
112 | sleep(latency) | |
113 | - | sleep(0.7) |
113 | + | |
114 | rednet.send(ids, mess, "httpwebtransfer") | |
115 | - | rednet.send(ids, mess) |
115 | + | elseif lol[1] == "game" then |
116 | print("Ricevuto "..lol[2]..":51") | |
117 | print("Inoltro richiesta a "..lol[2]..":51") | |
118 | ||
119 | modem.sendChannel(51, lol[2]) | |
120 | ||
121 | for _, v in pairs(fw) do | |
122 | modem.setListening(tonumber(v), true) | |
123 | end | |
124 | ||
125 | local event, side, id, chn, mess = os.pullEvent("lan_message") | |
126 | ||
127 | print("Ricevuto risposta da: 144.91.97."..id) | |
128 | rednet.send(ids, mess, "httpwebtransfer") | |
129 | elseif lol[1] == "chat" then | |
130 | print("Ricevuto "..lol[2]..":70") | |
131 | print("Inoltro richiesta a "..lol[2]..":70") | |
132 | ||
133 | modem.sendChannel(70, lol[2]) | |
134 | ||
135 | for _, v in pairs(fw) do | |
136 | modem.setListening(tonumber(v), true) | |
137 | end | |
138 | ||
139 | local event, side, id, chn, mess = os.pullEvent("lan_message") | |
140 | ||
141 | print("Ricevuto risposta da: 144.91.97."..id) | |
142 | rednet.send(ids, mess, "httpwebtransfer") | |
143 | else | |
144 | exit() | |
145 | end | |
146 | sleep(0.1) | |
147 | end |