FoxWorn3365

Gauugle x ClodedFiber - Modem

Sep 29th, 2021 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. function ufw()
  2. haa = fs.open(".fw", "r")
  3. dataa = haa.readAll()
  4. data = textutils.unserialize(dataa)
  5. return data
  6. end
  7.  
  8. function split (inputstr, sep)
  9. if sep == nil then
  10. sep = "%s"
  11. end
  12. local t={}
  13. for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  14. table.insert(t, str)
  15. end
  16. return t
  17. end
  18.  
  19. function in_table ( e, t )
  20. for _,v in pairs(t) do
  21. if (v==e) then return true end
  22. end
  23. return false
  24. end
  25.  
  26. term.clear()
  27. term.setCursorPos(1, 1)
  28. print("====================")
  29. print("\n>> Gauugle! Modem <<")
  30. print("\n====================")
  31. shell.run("id")
  32.  
  33. if fs.exists(".settings") == false then
  34. print("\n\nE' ora di impostare il modem!");
  35. print("\nInserisci il lato del cavo LAN:")
  36. lancable = read()
  37. print("\nPerfetto! Ora inserisci il lato del modem wireless:")
  38. wireless = read()
  39. print("\n\nSto preparando le impostazioni di sistema...")
  40. h = fs.open(".settings", "w")
  41. h.writeLine("lan = '"..lancable.."'");
  42. h.writeLine("wm = '"..wireless.."'");
  43. h.flush()
  44. h.close()
  45. ha = fs.open(".fw", "w")
  46. door = {}
  47. table.insert(door, "80")
  48. ha.write(textutils.serialize(door))
  49. ha.flush()
  50. ha.close()
  51. print("\nFatto! :D\nRiavvio il modem!")
  52. shell.run("reboot")
  53. else
  54. shell.run(".settings")
  55. rednet.open(wm)
  56. modem = peripheral.wrap(lan)
  57. end
  58.  
  59. fw = ufw()
  60. -- Ok, inizia lo scambio ovvio di informazioni ma prima apro le porte desiderate. Default: 80
  61. while true do
  62.  
  63. ids, msg, protocol = rednet.receive()
  64.  
  65. if protocol == "configurazione" then
  66. print("Ricevuto messaggio su conf()");
  67. res = split(msg, "_")
  68. if msg == "data" then
  69. print("Ricevuto conf()data")
  70. rednet.send(ids, textutils.serialize(fw))
  71. elseif res[1] == "remove" then
  72. table.remove(fw, res[2])
  73. ha = fs.open(".fw", "w")
  74. table.insert(door, "80")
  75. ha.write(textutils.serialize(fw))
  76. ha.flush()
  77. ha.close()
  78. rednet.send(ids, textutils.serialize(fw))
  79. shell.run("reboot")
  80. elseif res[1] == "add" then
  81. table.insert(fw, res[2])
  82. ha = fs.open(".fw", "w")
  83. table.insert(door, "80")
  84. ha.write(textutils.serialize(fw))
  85. ha.flush()
  86. ha.close()
  87. rednet.send(ids, textutils.serialize(fw))
  88. shell.run("reboot")
  89. end
  90. else
  91.  
  92. print("Ricevuto "..msg)
  93. print("Inoltro richiesta a "..msg..":80")
  94.  
  95. modem.sendChannel(80, msg)
  96.  
  97. for _, v in pairs(fw) do
  98. modem.setListening(v, true)
  99. end
  100.  
  101. local event, side, id, chn, mess = os.pullEvent("lan_message")
  102.  
  103. for lo, v in pairs(fw) do
  104. if chn ~= v then
  105. print("\nRichiesta su porta chiusa ("..v..")")
  106. shell.run("reboot")
  107. end
  108. end
  109.  
  110. print("Ricevuto risposta da: 144.91.97."..id)
  111.  
  112. sleep(0.7)
  113.  
  114. rednet.send(ids, mess)
  115. end
  116. sleep(0.1)
  117. end
Add Comment
Please, Sign In to add comment