BananeMan

Server

Sep 22nd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. --*****************************--
  2. --********BANQUE SERVEUR*******--
  3. --*****************************--
  4.  
  5. --Décalaration de variable
  6.  
  7. local checkstartup = false
  8. local checkfiles = false
  9. local checkshell2 = false
  10. local filesnumb = 0
  11. fileserror = 0
  12. local id = os.getComputerID()
  13. local st = ""
  14. local ver = "0.0.1"
  15. local string = ""
  16.  
  17. local usersf = "/files/users/"
  18. local adminsf = "/files/admins.txt"
  19. local atmsf = "/files/atms.txt"
  20. --local ronda = "/libs/rednet"
  21. local crypt = "/disk/crypto"
  22.  
  23. local privekey = ""
  24. local publickey = ""
  25. local allkey = ""
  26.  
  27. local coter = "left"
  28. --Fin de décalaration de variable
  29.  
  30. function startup()
  31. print("Démarage du serveur")
  32. print("Id de l'ordinateur:", id)
  33. print("Version: "..ver)
  34. print("Vérification des fichiers utilisateur")
  35. verif(usersf)
  36. verif(adminsf)
  37. verif(crypt)
  38. verif(atmsf)
  39. --verif(ronda)
  40. if fileserror == 0 then
  41. print(filesnumb, "fichiers on été vérifier")
  42. else
  43. print(fileserror, "fichiers on n'on pas été vérifier !")
  44. sleep(2)
  45. os.shutdown()
  46. end
  47.  
  48. print("\n\n\n")
  49. print("Load des apis")
  50. os.loadAPI(crypt)
  51. --os.loadAPI(ronda)
  52. print("Création des clées de cryptage")
  53. allkey = crypto.generate()
  54. publickey = allkey.public
  55. privkey = allkey.private
  56. print("Ouverture de rednet")
  57. rednet.open(coter)
  58. print("Fin du startup")
  59. parallel.waitForAll(redne, idre)
  60. end
  61.  
  62. function verif(var)
  63. if fs.exists(var) then
  64. print(var.." existant")
  65. filesnumb = filesnumb + 1
  66. else
  67. print(var.." n'existe pas !")
  68. fileserror = fileserror + 1
  69. sleep(10)
  70. os.shutdown()
  71. end
  72. end
  73.  
  74. function files(string)
  75. local response
  76.  
  77. return(response)
  78. end
  79.  
  80. function redne()
  81. print("Ecoute activée !")
  82. while true do
  83. local senderid, mess, proto = rednet.receive("superproto")
  84. print("[BANQUE]", "[SenderID]:",senderid)
  85. print(mess)
  86.  
  87. if pcall(messagedc = crypto.decrypt(mess, privekey)) then
  88. local table = textutils.unserialize(messagedc)
  89. if table.action == "login" then
  90. local user = table.User
  91. local pass = table.Pass
  92. if fs.exists("/files/users/"..user) then
  93. local file = fs.open("/files/users/"..user, "r")
  94.  
  95. local id = file.readLine()
  96. local pseudo = file.readLine()
  97. local mot = file.readLine()
  98. local argent = file.readLine()
  99. local historique = file.readLine()
  100. local entreprise = file.readLine()
  101. file.close()
  102. if user == pseudo and mot == pass then
  103. local table = {action = "login", user = pseudo, response = "yes"}
  104. tablesy = textutils.serialize(table)
  105. rednet.send(senderid, tablesy)
  106. else
  107. local table = {action = "login", user = pseudo, response = "no"}
  108. tablesn = textutils.serialize(table)
  109. rednet.send(senderid, tablesn)
  110. end
  111. else
  112. print("Utilisateur non existant")
  113. local table = {action = "login", user = user, response = "no"}
  114. tablesn = textutils.serialize(table)
  115. rednet.send(senderid, tablesn)
  116. end
  117. elseif table.action == "keyretrive" then
  118. rednet.send(senderid, publickey)
  119. print("Clée public envoyée a",senderid)
  120. else
  121. print("Pas implementer", table.action)
  122. end
  123. else
  124. local tablea = textutils.unserialize(mess)
  125. if tablea.action == "keyretrive" then
  126. rednet.send(senderid, publickey)
  127. print("Clée public envoyée a",senderid)
  128. else
  129. print("Pas implementer", tablea.action)
  130. end
  131. end
  132. end
  133. rednet.close()
  134. end
  135.  
  136. function shell2()
  137. shell.openTab("shell")
  138. end
  139.  
  140. function acces()
  141. end
  142.  
  143. function token(pseudo)
  144.  
  145. end
  146.  
  147. function idre()
  148. rednet.open(coter)
  149. rednet.host("2banque", "server")
  150. end
  151.  
  152. parallel.waitForAll(startup, shell2)
Add Comment
Please, Sign In to add comment