Ejemplo n.º 1
0
    def generate_supplicant_file(self, net_o, passw=None):
        """
        This function reuses or try to generate new configuration file for wpa_supplicant
        Returns a tuple containing a boolean for success and the path for the supplicant file
        """
        logger = logging.getLogger(Conf.LOGGER_NAME)
        valid_conf_created = False
        passphrase = ''
        supplicant_conf_path = ''

        if passw is None or not type(passw) == str:
            passphrase = util.ask_for_password(net_o)
        else:
            passphrase = passw
            
        if not passphrase is None:
            supplicant_conf_path = self.get_network_conf_file(net_o)
            wpapass_command = cp_builder.build_wpapass_command(self.config, net_o, passphrase)
            wpa_commands = [(wpapass_command, supplicant_conf_path)]
            wpa_return_values = cp_builder.execute(wpa_commands, True)
            if wpa_return_values[0] == 0:
                valid_conf_created = True
            else:
                print('Error creating configuration file for network {0}'.format(net_o.essid))
            
        return valid_conf_created,supplicant_conf_path
Ejemplo n.º 2
0
 def generate_key_file(self, net_o, passw=None):
     """
     This function reuses or try to generate new configuration file for connect to a network
     that is encrypted but it has not specified the algorithm.
     This file is used only for the password.
     Returns a tuple containing a boolean for success and the path for the supplicant file
     """
     if passw is None or not type(passw) == str:
         passphrase = util.ask_for_password(net_o)
     else:
         passphrase = passw
         
     valid_conf_created = False
     key_conf_path = ''
     
     if not passphrase is None:
         key_conf_path = self.get_network_conf_file(net_o)
         with open(key_conf_path, 'wb') as f:
             pickle.dump(passphrase, f)
             valid_conf_created = True
         
     return valid_conf_created, key_conf_path