mirevall

modem_server

Jun 5th, 2017 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. -- 1.1.4
  2. version = "1.1.4"
  3.  
  4. print("V. "..version)
  5.  
  6. if peripheral.getType("back") ~= "modem" then
  7. term.setTextColour(colours.red)
  8. print("A mondem or wireless modem on the back side is required by this program.")
  9. os.sleep(3)
  10. os.reboot()
  11. end
  12.  
  13. if not fs.exists("/CB/%NAS%/admin/.ignore") then
  14. term.setTextColour(colours.white)
  15. write("choose the admin password : ")
  16. term.setTextColour(colours.yellow)
  17. pass = read("*")
  18. if pass == nil then
  19. term.setTextColour(colours.red)
  20. print("you need to type something")
  21. os.sleep(2)
  22. os.reboot()
  23. end
  24. term.setTextColour(colours.white)
  25. write("confirm your password : ")
  26. term.setTextColour(colours.yellow)
  27. cpass = read("*")
  28. if pass == cpass then
  29. naccount = fs.open("/CB/%NAS%/admin/.ignore", "w")
  30. naccount.writeLine(pass)
  31. naccount.close()
  32. end
  33. end
  34.  
  35. term.setTextColour(colours.white)
  36. while true do
  37.  
  38. local Mots = {}
  39.  
  40. function letn (content)
  41. logfile = fs.open("/CB/%NAS%/admin/log", "a")
  42. logfile.writeLine(content)
  43. logfile.close()
  44. print(content)
  45. end
  46.  
  47. local modem = peripheral.wrap("back")
  48. shell.run("mkdir /CB/%NAS%/shared")
  49. ing = fs.open("/CB/%NAS%/shared/.ignore", "w")
  50. ing.close()
  51. modem.open(1)
  52. local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  53.  
  54. for i in string.gmatch(message, "%S+") do
  55. table.insert(Mots, i)
  56. end
  57.  
  58. if Mots[4] == "@p" then
  59. Mots[4] = replyChannel-1
  60. end
  61.  
  62. if Mots[1] == "version" then
  63. if Mots[2] ~= version then
  64. maj = fs.open("/CB/Prog/MAJ", "w")
  65. maj.writeLine('fs.delete("/CB/NAS")')
  66. maj.writeLine('shell.run("pastebin get 5WgxqxCv /CB/NAS")')
  67. maj.writeLine('os.reboot()')
  68. maj.close()
  69. shell.run("/CB/Prog/MAJ")
  70. end
  71. end
  72.  
  73. if Mots[1] == "delete" then
  74. if fs.exists("/CB/%NAS%/"..Mots[3].."/"..Mots[2]) and Mots[2] ~= ".ignore" then
  75. fs.delete("/CB/%NAS%/"..Mots[3].."/"..Mots[2])
  76. letn("File /CB/%NAS%/"..Mots[3].."/"..Mots[2].."was deleted from #"..replyChannel-1)
  77. end
  78. end
  79.  
  80. if Mots[1] == "account" then
  81. if fs.exists("/CB/%NAS%/"..Mots[2].."/") then
  82. modem.transmit(replyChannel, 1, "already exists")
  83. else
  84. modem.transmit(replyChannel, 1, "not exists")
  85. end
  86. letn("account status of "..Mots[2].." has been send to #"..replyChannel-1)
  87. end
  88.  
  89. if Mots[1] == "login" then
  90. login = fs.open("/CB/%NAS%/"..Mots[2].."/.ignore", "r")
  91. pass = login.readLine()
  92. login.close()
  93. if pass == Mots[3] then
  94. modem.transmit(replyChannel, 1, "logged")
  95. letn(Mots[2].." logged in from #"..replyChannel-1)
  96. else
  97. modem.transmit(replyChannel, 1, "wrong")
  98. letn(Mots[2].." tried to log in from #"..replyChannel-1)
  99. end
  100. end
  101.  
  102. if Mots[1] == "mkaccount" then
  103. shell.run("mkdir /CB/%NAS%/"..Mots[2])
  104. ing = fs.open("/CB/%NAS%/"..Mots[2].."/.ignore", "w")
  105. ing.write(Mots[3])
  106. ing.close()
  107. letn("Account "..Mots[2].." has been created from #"..replyChannel-1)
  108. end
  109.  
  110. if Mots[1] == "lfiles" then
  111. local Files = fs.list("/CB/%NAS%/"..Mots[2])
  112. send = Files[1]
  113. for i=2,#Files do
  114. send = send.." "..Files[i]
  115. end
  116. letn("listfile from "..Mots[2].." send to #"..replyChannel-1)
  117. modem.transmit(replyChannel, 1, send)
  118. end
  119.  
  120. if Mots[1] == "sfile" then
  121. if fs.exists("/CB/%NAS%/"..Mots[4].."/"..Mots[3]) then
  122. letn("write file failed "..Mots[4].."/"..Mots[3].." from #"..replyChannel-1)
  123. modem.transmit(replyChannel, 1, "failed : file already exists")
  124. else
  125. vfile = fs.open("/CB/%NAS%/"..Mots[4].."/"..Mots[3], "w")
  126. local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  127. vfile.write(message)
  128. vfile.close()
  129. letn("write file "..Mots[4].."/"..Mots[3].." from #"..replyChannel-1)
  130. modem.transmit(replyChannel, 1, "succes")
  131. end
  132. end
  133.  
  134. if Mots[1] == "rfile" then
  135. if not fs.exists("/CB/%NAS%/"..Mots[4].."/"..Mots[2]) then
  136. letn("send file failed "..Mots[4].."/"..Mots[2].." for #"..replyChannel-1)
  137. modem.transmit(replyChannel, 1, "failed : file not exists on server")
  138. else
  139. pfile = fs.open("/CB/%NAS%/"..Mots[4].."/"..Mots[2], "r")
  140. sendfile = pfile.readAll()
  141. pfile.close()
  142. letn("send file "..Mots[4].."/"..Mots[2].." for #"..replyChannel-1)
  143. modem.transmit(replyChannel, 1, sendfile)
  144. end
  145. end
  146.  
  147.  
  148.  
  149. end
Add Comment
Please, Sign In to add comment