示例#1
0
	def run(self):
		print("Welcome in the Blacklist center !\nWhat do you want to do ?")
		action = autresFonctions.ask("1 : Add something in the BlackList\n2 : Delete something in the BlackList\n3 : Update the Blacklist with an other peer\n4 : Change the BlackList default peer")
		try:
			action = int(action)
		except ValueError as e:
			print(str(c("red")+"Your input isn't correct (between 1 and 4)\nError : "+str(e)+""+str(c(""))))
		if action == 1:
			entree = autresFonctions.ask("What do you want to add in your BlackList ?")
			while 1:
				rank = autresFonctions.ask("What is the rank of this new entry ?")
				try:
					if int(rank) > 0 and int(rank) <= 5:
						break
				except ValueError as e:
					print(str(c("red")+"Your input isn't correct. (between 1 and 5)\nError : "+str(e)+""+str(c(""))))
			error = BDD.ajouterEntree("BlackList", entree, rank)
			if error == 0:
				print(str(c("yellow")+""+str(entree) + " has been added in the BlackList with the rank " + str(rank)+""+str(c(""))))
			else:
				print(str(c("red")+"An error occured. Look at the logs for more informations. ("+str(error)+")"+str(c(""))))
		elif action == 2:
			entree = autresFonctions.ask("What do you want to delete in your BlackList ?")
			error = BDD.supprEntree("BlackList", entree)
			if error == 0:
				print(str(c("yellow")+""+str(entree) + " has been deleted in the BlackList"+str(c(""))))
			else:
				print(str(c("red")+"An error occured. Look at the logs for more informations. ("+str(error)+")"+str(c(""))))
		elif action == 3:
			ipport = str(autresFonctions.ask("With which peer do you want to update? (Press ENTER to update with the default peer : "+str(config.readConfFile("BlackList"))+")"))
			if ipport == "":
				status = loader("Work in progress")
				status.start()
				blacklist.maj()
				status.stop()
				status.join()
			elif autresFonctions.verifIPPORT(IppeerPort): # Si ipport est un ip:port
				status = loader("Work in progress")
				status.start()
				blacklist.maj(ipport)
				status.stop()
				status.join()
			else:
				print(str(c("red")+"This is not a IP:PORT"+str(c(""))))
		elif action == 4:
			value = str(autresFonctions.ask("Which peer do you want to choose to be your default blacklist peer ? (The actual peer is "+str(config.readConfFile("Blacklist"))))
			if autresFonctions.verifIPPORT(value):
				config.modifConfigFile("Blacklist", value)
			else:
				print(str(c("red")+"Your input isn't a IP:PORT"+str(c(""))))
		else:
			print(str(c("red")+"Your input isn't correct."+str(c(""))))
示例#2
0
文件: dns.py 项目: anon1892/WTP
def addNoeudDNS(ipport, ipportNoeud):
    error = 0
    if autresFonctions.verifIPPORT(ipport):
        connexion_avec_serveur = autresFonctions.connectionClient(ipport)
        if str(connexion_avec_serveur) == "=cmd ERROR":
            error += 1
        else:
            logs.addLogs("Connection established with the DNS")
            # =cmd DNS AddDNSExt ipport ******
            request = "=cmd DNS AddDNSExt ipport " + ipportNoeud
            request = request.encode()
            connexion_avec_serveur.send(request)
            message = connexion_avec_serveur.recv(1024)
            connexion_avec_serveur.close()
            if message == "=cmd IPPORTDejaUtilise":
                error = 5
                print(
                    str(c("red")) +
                    "The peer DNS is already known by the receiver." +
                    str(c("")))
            elif message == "=cmd SUCCESS":
                print(
                    str(c("green")) +
                    "The DNS pair has been added to the receiver base." +
                    str(c("")))
            else:
                print(
                    str(c("red")) +
                    "An undetermined error occurred. Please try again later or change DNS peer."
                    + str(c("")))
                error = 1
    else:
        error += 1
    return error
示例#3
0
文件: dns.py 项目: anon1892/WTP
def supprNDD(ipport, ndd, password):
    error = 0
    if autresFonctions.verifIPPORT(ipport):
        connexion_avec_serveur = autresFonctions.connectionClient(ipport)
        if str(connexion_avec_serveur) == "=cmd ERROR":
            error += 1
        else:
            logs.addLogs("Connection established with the DNS")
            # =cmd DNS supprNDD ndd ****** pass ******
            request = "=cmd DNS supprNDD ndd " + str(ndd) + " pass " + str(
                password)
            request = request.encode()
            connexion_avec_serveur.send(request)
            message = connexion_avec_serveur.recv(1024)
            if message != "=cmd SUCCESS":
                error += 1
            connexion_avec_serveur.close()
    else:
        error += 1
    return error
示例#4
0
def VPN(demande, ipPortVPN, ipPortExt):
    error = 0
    if autresFonctions.verifIPPORT(ipPortExt) and reg.match(ipPortVPN):
        ip = ipPortVPN[:ipPortVPN.find(":")]
        port = ipPortVPN[ipPortVPN.find(":") + 1:]
        connNoeud = autresFonctions.connectionClient(ip, port)
        if str(connNoeud) == "=cmd ERROR":
            error += 1
        else:
            logs.addLogs(
                "INFO : Connection with VPN peer etablished on port {}".format(
                    port))
            # =cmd VPN noeud 127.0.0.1:5555 request =cmd DemandeFichier
            request = "=cmd VPN noeud " + ipPortExt + " request " + demande
            request = request.encode()
            connNoeud.send(request)
            print(connNoeud.recv(1024))
            connNoeud.close()
            # Maintenant que l'on a demandé au VPN d'executer la demande, il faut recuperer les donnnées
            # Pour cela, il faut analyser la request initiale
            if request[:19] == "=cmd DemandeFichier":
                # =cmd DemandeFichier nom sha256.ext
                error += CmdDemandeFichier(ip, port, request[24:])
            elif request[:17] == "=cmd DemandeNoeud":
                CmdDemandeNoeud(ip, port)
            elif request[:28] == "=cmd DemandeListeFichiersExt":
                CmdDemandeListeFichiers(ip, port, 1)
            elif request[:25] == "=cmd DemandeListeFichiers":
                CmdDemandeListeFichiers(ip, port)
            elif request[:23] == "=cmd DemandeListeNoeuds":
                CmdDemandeListeNoeuds(ip, port)
            elif request[:22] == "=cmd rechercher":
                # =cmd rechercher nom SHA256.ext
                search.rechercheFichierEntiere(sendCmd[20:])
            else:
                logs.addLogs("ERROR : Unknown request (VPN()) : " +
                             str(request))
                error += 1
    else:
        error += 1
    return error
示例#5
0
文件: parser.py 项目: anon1892/WTP
 def run(self):
     while self.allume:
         BDD.verifExistBDD()
         conn = sqlite3.connect('WTP.db')
         cursor = conn.cursor()
         try:
             cursor.execute("""SELECT IP FROM Noeuds WHERE 1""")
             rows = cursor.fetchall()
         except Exception as e:
             conn.rollback()
             logs.addLogs("ERREUR : Problem with database (parseAll()) : " +
                          str(e))
         for row in rows:
             if autresFonctions.verifIPPORT(row):  # Si row est un ip:port
                 host = row[:row.find(":")]
                 port = row[row.find(":") + 1:]
                 # Pour chaque noeud on demande la liste de :
                 # tous les files qu'il héberge (=cmd DemandeListeFichiers)
                 fctsClient.CmdDemandeListeFichiers(host, port)
                 # tous les files externes qu'il connait (=cmd DemandeListeFichiersExt)
                 fctsClient.CmdDemandeListeFichiers(host, port, 1)
                 # tous les noeuds qu'il connait (=cmd DemandeListeNoeuds)
                 fctsClient.CmdDemandeListeNoeuds(host, port)
         conn.close()
示例#6
0
文件: dns.py 项目: anon1892/WTP
def modifNDD(ipport, ndd, adress, password):
    error = 0
    if autresFonctions.verifIPPORT(ipport):
        connexion_avec_serveur = autresFonctions.connectionClient(ipport)
        if str(connexion_avec_serveur) == "=cmd ERROR":
            error += 1
        else:
            logs.addLogs("Connection established with the DNS")
            # =cmd DNS modifNDD ndd ****** adress ****** pass ******
            request = "=cmd DNS modifNDD ndd " + str(ndd) + " adress " + str(
                adress) + " pass " + str(password)
            request = request.encode()
            connexion_avec_serveur.send(request)
            message = connexion_avec_serveur.recv(1024)
            connexion_avec_serveur.close()
            error = 0
            if message == "=cmd IPPORTDejaUtilise":
                error = 5
                print(
                    str(c("red")) +
                    "Le noeud DNS est déjà connu par le receveur." +
                    str(c("")))
            elif message == "=cmd SUCCESS":
                print(
                    str(c("green")) +
                    "Le noeud DNS a bien été ajouté à la base du receveur." +
                    str(c("")))
            else:
                print(
                    str(c("red")) +
                    "An undetermined error occurred. Please try again later or change DNS peer."
                    + str(c("")))
                error += 1
    else:
        error += 1
    return error
示例#7
0
文件: dns.py 项目: anon1892/WTP
def addNDD(ipport, sha, ndd, password):
    error = 0
    if autresFonctions.verifIPPORT(ipport):  # Si ipport est un ip:port
        connexion_avec_serveur = autresFonctions.connectionClient(ipport)
        if str(connexion_avec_serveur) == "=cmd ERROR":
            error += 1
        else:
            logs.addLogs("Connection established with the DNS")
            # =cmd DNS AddDNS sha ******* ndd ******* pass *******
            request = "=cmd DNS AddDNS sha " + str(sha) + " ndd " + str(
                ndd) + " pass " + str(password)
            request = request.encode()
            connexion_avec_serveur.send(request)
            message = connexion_avec_serveur.recv(1024)
            connexion_avec_serveur.close()
            if message == "=cmd NDDDejaUtilise":
                error = 5
                print(
                    str(c("red")) + "The domain name is already used." +
                    str(c("")) +
                    " If it belongs to you, you can modify it provided you know the password."
                )
            elif message == "=cmd SUCCESS":
                print(
                    str(c("green")) +
                    "The domain name and address SHA256 have been associated."
                    + str(c("")))
            else:
                print(
                    str(c("red")) +
                    "An undetermined error occurred. Please try again later or change DNS peer."
                    + str(c("")))
                error = 1
    else:
        error += 1
    return error
示例#8
0
def cmdLauncher(userCmd):
    error = 0
    if userCmd == "help":
        # Afficher toutes les options
        documentation.mini()
    elif userCmd == "update":
        # Vérifier les MAJ
        status = loader("Work in progress")
        status.start()
        #maj.verifMAJ()
        #maj.verifSources()
        status.stop()
        status.join()
        print(c("green") + "Done." + c(""))
    elif userCmd == "stats":
        # Affiche les statistiques
        print("Number of peers in the database : " +
              str(stats.compterStats("NbNoeuds")))
        print("Number of special peers in the database : " +
              str(stats.compterStats("NbSN")))
        print("Number of external files in the database : " +
              str(stats.compterStats("NbFichiersExt")))
        print("Number of files on this hard drive : " +
              str(stats.compterStats("NbFichiers")))
        print("Size of all files : " +
              str(stats.compterStats("PoidsFichiers")))
        print("Number of peers lists sent : " +
              str(stats.compterStats("NbEnvsLstNoeuds")))
        print("Number of file lists sent : " +
              str(stats.compterStats("NbEnvsLstFichiers")))
        print("Number of external file lists sent : " +
              str(stats.compterStats("NbEnvsLstFichiersExt")))
        print("Number of files sent : " +
              str(stats.compterStats("NbEnvsFichiers")))
        print("Number of presence requests received : " +
              str(stats.compterStats("NbPresence")))
        print("Number of files received : " +
              str(stats.compterStats("NbReceptFichiers")))
    elif userCmd == "config":
        # Modifier le fichier de configuration
        config.modifConfig()
    elif userCmd == "dns":
        # Entrer dans le programme de configuration du DNS
        thrdDNS = DNSConfig()
        thrdDNS.start()
        thrdDNS.join()
    elif userCmd == "exit":
        # On arrète WTP
        print(
            "Pro tip : You can also stop WTP at any time by pressing Ctrl + C."
        )
        return -1
    elif userCmd == "doc":
        # On affiche la documentation
        documentation.maxi()
    elif userCmd == "checkFiles":
        # On vérifie immédiatement dans ADDFILES, HOSTEDFILES et .TEMP
        status = loader("Work in progress")
        status.start()
        fctsMntc.checkIntruders()
        fctsMntc.creerFichier()
        fctsMntc.supprTemp()
        status.stop()
        status.join()
        print(c("green") + "Done." + c(""))
    elif userCmd == "delAll":
        print(
            "Are you sure you want to delete everything ?\nAll configuration, database, hosted files will be lost."
        )
        print("You will not be able to go back.")
        if str(input("If you are sure, enter DeleteAll\n>> ")) == "DeleteAll":
            print(
                "We are sorry to see you go.\nWe hope to see you very soon !\nIf you have comments to send to you, please contact us via our website :\nhttps://myrasp.fr/WTP"
            )
            status = loader("Work in progress")
            status.start()
            shutil.rmtree(str(os.getcwd()) + "/HOSTEDFILES")
            shutil.rmtree(str(os.getcwd()) + "/ADDFILES")
            os.remove(str(os.getcwd()) + "/.extinctionWTP")
            os.remove(str(os.getcwd()) + "/.TempMaintenance24H")
            os.remove(str(os.getcwd()) + "/.TempMaintenance5M")
            logs.rapportErreur()
            os.remove(str(os.getcwd()) + "/logs.txt")
            os.remove(str(os.getcwd()) + "/wtp.conf")
            status.stop()
            status.join()
            return -1
        print(
            "You scared us!\nFortunately, you have not passed the dark side of the force!"
        )
    elif userCmd == "majDNS":
        print(
            "You want to update the DNS database.\nIf you are crazy, you can enter crazy to update with a random peer."
        )
        ipport = str(
            input("With which DNS do you want to update ? (IP:Port)\n>> "))
        # Vérifier le noeud
        if autresFonctions.verifIPPORT(ipport):
            # C'est un IPPort
            co = autresFonctions.connectionClient(ipport)
            if co != "=cmd ERROR":
                sendCmd = "=cmd status"
                co.send(sendCmd.encode())
                rcvCmd = co.recv(1024).decode()
                co.close()
                if rcvCmd == "=cmd DNS":
                    e = dns.majDNS(ipport)
                    if int(e) > 0:
                        print(c("red") + "An error occured." + c(""))
                    else:
                        print(c("green") + "Done." + c(""))
                else:
                    print(c("red") + "This peer isn't DNS." + c(""))
            print(c("red") + "Unable to connect to this peer." + c(""))
        elif ipport == "crazy":
            print(
                "DISCLAMER : Some peers can be controlled by malicious people who can perform phishing attacks"
            )
            rep = str(input("Are you sure ? (y/N)\n>>"))
            if rep == "y" or rep == "Y":
                e = dns.majDNS()
                if int(e) > 0:
                    print(c("red") + "An error occured." + c(""))
                else:
                    print(c("green") + "Done." + c(""))
            else:
                print(
                    "You scared us!\nFortunately, you have not passed the dark side of the force!"
                )
        else:
            print(c("red") + "It's not an ip:port" + c(""))
    elif userCmd == "client":
        # Possibilité de faire des demandes en console
        error = 0
        sendCmd = ""
        print(
            "You can now write requests and send them to the peers you want.")
        print("Exit this wizard and enter doc for more information.")
        while sendCmd != "exit":
            sendCmd = str(
                input(
                    "What is your request ? (exit for quit this wizard)\n>> "))
            if sendCmd == "doc":
                documentation.maxi()
            elif sendCmd != "exit":
                host = str(
                    input(
                        "What is the IP of the peer that you want to contact ? > "
                    ))
                try:
                    port = int(
                        input(
                            "What is the Port of the peer that you want to contact ? > "
                        ))
                except ValueError:
                    print(
                        c("red") + "It isn't a port (between 1024 and 65535)" +
                        c(""))
                else:
                    if sendCmd == "=cmd DemandeNoeud":
                        error += fctsClient.CmdDemandeNoeud(host, port)
                    elif sendCmd[:19] == "=cmd DemandeFichier":
                        # =cmd DemandeFichier nom sha256.ext
                        error += fctsClient.CmdDemandeFichier(
                            host, port, sendCmd[24:])
                    elif sendCmd == "=cmd DemandeListeNoeuds":
                        error += fctsClient.CmdDemandeListeNoeuds(host, port)
                    elif sendCmd == "=cmd DemandeListeFichiers":
                        error += fctsClient.CmdDemandeListeFichiers(host, port)
                    elif sendCmd[:19] == "=cmd rechercher nom":
                        # =cmd rechercher nom SHA256.ext
                        sortie = search.rechercheFichierEntiere(sendCmd[20:])
                        ipport = sortie[:sortie.find(";")]
                        sha = sortie[sortie.find(";") + 1:]
                        if autresFonctions.verifIPPORT(ipport):
                            # C'est un IPPort
                            # On envoi vers la fonction qui télécharge le file
                            ip = ipport[:ipport.find(":")]
                            port = int(ipport[ipport.find(":") + 1:])
                            error += fctsClient.CmdDemandeFichier(
                                ip, int(port), sha)
                        else:
                            # C'est une erreur
                            print(sortie)
                            error += 1
                    else:
                        error = 0
                        connexion_avec_serveur = autresFonctions.connectionClient(
                            host, port)
                        if str(connexion_avec_serveur) == "=cmd ERROR":
                            error += 1
                        else:
                            connexion_avec_serveur.send(sendCmd.encode())
                            rcvCmd = connexion_avec_serveur.recv(1024).decode()
                            connexion_avec_serveur.close()
                            print(rcvCmd)
                    if int(error) == 0:
                        print(c("green") + "Done." + c(""))
                    else:
                        print(
                            c("red") + "An error occured. (" + str(error) +
                            ")" + c(""))
            else:
                break
    elif userCmd == "add":
        # L'utilisateur veut ajouter quelque chose
        categorie = str(input("What do you want to add ?\n>>> "))
        if categorie == "peer":
            ipport = str(input("What is the IP:Port of the peer ?\n>>> "))
            error = BDD.ajouterEntree("Noeud", ipport)
            if error == 0:
                print(c("green") + "Done." + c(""))
            else:
                print(c("red") + "An error occured (" + str(error) + ").")
        else:
            print(c("red") + "Your input is unknown." + c(""))
            print(
                c("cian") + "You can enter help for more information." + c(""))
    elif userCmd == "blacklist":
        blckLst = clientBlacklist.configBlckLst()
        blckLst.start()
        blckLst.join()
    else:
        print(c("red") + "Unknown request." + c(""))
    return 0