コード例 #1
0
ファイル: server.py プロジェクト: brunoqs/try-p2p
 def conn_handler(self, conn, addr):
     data = do_decrypt(conn.recv(1024))
     data = data.split()
     addr = list(addr)
     del addr[1]
     if data[0] == "REGISTER":
         self.register_data(addr, data)
         resp = "True"
         conn.send(do_encrypt(resp))
     elif data[0] == "SEARCH":
         peer = self.search_data(data[1])
         conn.send(do_encrypt(pickle.dumps(peer)))
     conn.close()
コード例 #2
0
    def on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None):

        if prompt:
            msg = prompt
        else:
            msg = 'input for %s: ' % varname

        def prompt(prompt, private):
            if private:
                return getpass.getpass(prompt)
            return raw_input(prompt)


        if confirm:
            while True:
                result = prompt(msg, private)
                second = prompt("confirm " + msg, private)
                if result == second: 
                    break
                print "***** VALUES ENTERED DO NOT MATCH ****"
        else:
            result = prompt(msg, private)

        if encrypt:
            result = utils.do_encrypt(result,encrypt,salt_size,salt)

        call_callback_module('playbook_on_vars_prompt', varname, private=private, prompt=prompt, encrypt=encrypt, confirm=confirm, salt_size=salt_size, salt=None)

        return result
コード例 #3
0
ファイル: callbacks.py プロジェクト: broferek/ansible
    def on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None):

        if prompt:
            msg = "%s: " % prompt
        else:
            msg = 'input for %s: ' % varname

        def prompt(prompt, private):
            if private:
                return getpass.getpass(prompt)
            return raw_input(prompt)


        if confirm:
            while True:
                result = prompt(msg, private)
                second = prompt("confirm " + msg, private)
                if result == second: 
                    break
                print "***** VALUES ENTERED DO NOT MATCH ****"
        else:
            result = prompt(msg, private)

        if encrypt:
            result = utils.do_encrypt(result,encrypt,salt_size,salt)

        call_callback_module('playbook_on_vars_prompt', varname, private=private, prompt=prompt, encrypt=encrypt, confirm=confirm, salt_size=salt_size, salt=None)

        return result
コード例 #4
0
 def listen(self):
     while True:
         conn, addr = self.sock.accept()
         file = do_decrypt(conn.recv(1024))
         data = file_data(file)  # le o arquivo para envia seus dados
         conn.send(do_encrypt(data))
     conn.close()
コード例 #5
0
ファイル: callbacks.py プロジェクト: onecliquezone/ansible
    def on_vars_prompt(self,
                       varname,
                       private=True,
                       prompt=None,
                       encrypt=None,
                       confirm=False,
                       salt_size=None,
                       salt=None,
                       default=None):

        if prompt and default is not None:
            msg = "%s [%s]: " % (prompt, default)
        elif prompt:
            msg = "%s: " % prompt
        else:
            msg = 'input for %s: ' % varname

        def do_prompt(prompt, private):
            if sys.stdout.encoding:
                msg = prompt.encode(sys.stdout.encoding)
            else:
                # when piping the output, or at other times when stdout
                # may not be the standard file descriptor, the stdout
                # encoding may not be set, so default to something sane
                msg = prompt.encode(locale.getpreferredencoding())
            if private:
                return getpass.getpass(msg)
            return raw_input(msg)

        if confirm:
            while True:
                result = do_prompt(msg, private)
                second = do_prompt("confirm " + msg, private)
                if result == second:
                    break
                display("***** VALUES ENTERED DO NOT MATCH ****")
        else:
            result = do_prompt(msg, private)

        # if result is false and default is not None
        if not result and default is not None:
            result = default

        if encrypt:
            result = utils.do_encrypt(result, encrypt, salt_size, salt)

        # handle utf-8 chars
        result = to_unicode(result, errors='strict')
        call_callback_module('playbook_on_vars_prompt',
                             varname,
                             private=private,
                             prompt=prompt,
                             encrypt=encrypt,
                             confirm=confirm,
                             salt_size=salt_size,
                             salt=None,
                             default=default)

        return result
コード例 #6
0
    def on_vars_prompt(self,
                       varname,
                       private=True,
                       prompt=None,
                       encrypt=None,
                       confirm=False,
                       salt_size=None,
                       salt=None,
                       default=None):

        if prompt and default is not None:
            msg = "%s [%s]: " % (prompt, default)
        elif prompt:
            msg = "%s: " % prompt
        else:
            msg = 'input for %s: ' % varname

        def prompt(prompt, private):
            msg = prompt.encode(sys.stdout.encoding)
            if private:
                return getpass.getpass(msg)
            return raw_input(msg)

        if confirm:
            while True:
                result = prompt(msg, private)
                second = prompt("confirm " + msg, private)
                if result == second:
                    break
                display("***** VALUES ENTERED DO NOT MATCH ****")
        else:
            result = prompt(msg, private)

        # if result is false and default is not None
        if not result and default:
            result = default

        if encrypt:
            result = utils.do_encrypt(result, encrypt, salt_size, salt)

        call_callback_module('playbook_on_vars_prompt',
                             varname,
                             private=private,
                             prompt=prompt,
                             encrypt=encrypt,
                             confirm=confirm,
                             salt_size=salt_size,
                             salt=None,
                             default=default)

        return result
コード例 #7
0
    def download_file(self, file, addr, port):
        sock = socket()
        try:
            sock.connect((addr, port))
        except ConnectionRefusedError:
            print("Peer desligado!")
            return False
        sock.send(do_encrypt(file))
        resp = do_decrypt(sock.recv(1024))
        sock.close()
        write_file(file, resp)  # cria um arquivo com os dados baixados
        print("Download {} terminado".format(file))

        return True
コード例 #8
0
ファイル: callbacks.py プロジェクト: jgreene/ansible
    def on_vars_prompt(
        self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None
    ):

        if prompt and default is not None:
            msg = "%s [%s]: " % (prompt, default)
        elif prompt:
            msg = "%s: " % prompt
        else:
            msg = "input for %s: " % varname

        def prompt(prompt, private):
            msg = prompt.encode(sys.stdout.encoding)
            if private:
                return getpass.getpass(msg)
            return raw_input(msg)

        if confirm:
            while True:
                result = prompt(msg, private)
                second = prompt("confirm " + msg, private)
                if result == second:
                    break
                display("***** VALUES ENTERED DO NOT MATCH ****")
        else:
            result = prompt(msg, private)

        # if result is false and default is not None
        if not result and default:
            result = default

        if encrypt:
            result = utils.do_encrypt(result, encrypt, salt_size, salt)

        call_callback_module(
            "playbook_on_vars_prompt",
            varname,
            private=private,
            prompt=prompt,
            encrypt=encrypt,
            confirm=confirm,
            salt_size=salt_size,
            salt=None,
            default=default,
        )

        return result
コード例 #9
0
ファイル: callbacks.py プロジェクト: rainslytherin/ansible
    def on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):

        if prompt and default is not None:
            msg = "%s [%s]: " % (prompt, default)
        elif prompt:
            msg = "%s: " % prompt
        else:
            msg = 'input for %s: ' % varname

        def do_prompt(prompt, private):
            if sys.stdout.encoding:
                msg = prompt.encode(sys.stdout.encoding)
            else:
                # when piping the output, or at other times when stdout
                # may not be the standard file descriptor, the stdout
                # encoding may not be set, so default to something sane
                msg = prompt.encode(locale.getpreferredencoding())
            if private:
                return getpass.getpass(msg)
            return raw_input(msg)


        if confirm:
            while True:
                result = do_prompt(msg, private)
                second = do_prompt("confirm " + msg, private)
                if result == second:
                    break
                display("***** VALUES ENTERED DO NOT MATCH ****")
        else:
            result = do_prompt(msg, private)

        # if result is false and default is not None
        if not result and default is not None:
            result = default


        if encrypt:
            result = utils.do_encrypt(result, encrypt, salt_size, salt)

        # handle utf-8 chars
        result = to_unicode(result, errors='strict')
        call_callback_module( 'playbook_on_vars_prompt', varname, private=private, prompt=prompt,
                               encrypt=encrypt, confirm=confirm, salt_size=salt_size, salt=None, default=default
                            )

        return result
コード例 #10
0
    def search_file(self):
        file = input("Digite o arquivo que deseja procurar\n")
        sock = socket()
        try:
            sock.connect((self.s_ip, self.s_port))
        except ConnectionRefusedError:
            sys.exit("Server de controle desligado")
        hash_file = md5(file.encode('utf-8')).hexdigest()
        sock.send(do_encrypt("SEARCH {}".format(hash_file)))
        resp = pickle.loads(do_decrypt(sock.recv(1024)))

        if resp != None:
            sock.close()
            return resp

        sock.close()
        return False
コード例 #11
0
    def register_peer(self):
        file = input("Digite o arquivo que deseja registrar\n")
        if (not file_exists(file)):
            print("Arquivo nao existe, tente de novo.")
            return False

        sock = socket()
        try:
            sock.connect((self.s_ip, self.s_port))
        except ConnectionRefusedError:
            sys.exit("Server de controle desligado")
        hash_file = md5(
            file.encode('utf-8')).hexdigest()  # hash nome do arquivo
        encrypt = do_encrypt("REGISTER {} {} {}".format(
            hash_file, file, self.c_port))
        sock.send(encrypt)
        resp = do_decrypt(sock.recv(1024))

        if resp == "True":
            print("Arquivo registrado com sucesso")

        sock.close()
        return True