Esempio n. 1
0
    def connect_key(self,key_conf_path, net_o, do_execute=True):
        '''
        Connect to a network with non specified encryption. A network that reports encryption
        on but with no specified algorithms
        This function return the list of commands that would have been executed 
        (useful for testing) in the second position of a tuple.
        If do_execute is not True, it builds the list of commands without actually
        running them
        '''
        logger = logging.getLogger(Conf.LOGGER_NAME)
        success = True
        connect_commands = self.connect_common_pre()

        #get the key
        key = None
        try:
            with open(key_conf_path, 'rb') as f:
                key = pickle.load(f)
                if Conf.DEBUG_MODE:
                    logger.info("Found key for network")
        except IOError:
            key = None

        if not key is None:
            iwconfig_command = cp_builder.build_iwconfig_command(self.config, net_o, key)
            connect_commands.append((iwconfig_command, None))
            post = self.connect_common_post()
            connect_commands += post

            if do_execute:
                return_values = cp_builder.execute(connect_commands, True)
                commands_output = reduce(lambda x,y:x or y, return_values)
                if commands_output == 1:
                    success = False
        else:
            success = False
            logger.error("Error trying to read wireless key from {}".format(key_conf_path))
            
        return success, connect_commands
Esempio n. 2
0
    def connect_open(self, open_conf_path, net_o, do_execute=True):
        '''
        Connects to ann open network (encryption off) whose configuration is stored
        in open_conf_path.
        This function return the list of commands that would have been executed 
        (useful for testing) in the second position of a tuple.
        If do_execute is not True, it builds the list of commands without actually
        running them
        '''
        logger = logging.getLogger(Conf.LOGGER_NAME)
        success = True
        connect_commands = self.connect_common_pre()

        iwconfig_command = cp_builder.build_iwconfig_command(self.config, net_o, None)
        connect_commands.append((iwconfig_command, None))
        post = self.connect_common_post()
        connect_commands += post
        
        if do_execute:
            return_values = cp_builder.execute(connect_commands, True)
            commands_output = reduce(lambda x,y:x or y, return_values)
            if commands_output == 1:
                success = False
        return success, connect_commands