Ejemplo n.º 1
0
    def disconnect(self):
        '''
        disconnect from all possible forms of connection and shut down wireless networking
        '''
        logger = logging.getLogger(Conf.LOGGER_NAME)

        supplicant_command = cp_builder.build_supplicant_kill_command(self.config)
        ifconfig_command = cp_builder.build_ifconfig_command(self.config,
                                                             Conf.IFCONFIG_ACTION_DOWN)
        rfkill_command = cp_builder.build_rfkill_command(self.config,
                                                         Conf.RFKILL_VAL_BLOCK,
                                                         Conf.RFKILL_VAL_WIFI)
        disconnect_commands = [(supplicant_command, None), (ifconfig_command, None),
                               (rfkill_command, None)]
        
        disconnect_return_values = cp_builder.execute(disconnect_commands, False)
Ejemplo n.º 2
0
    def start(self):
        """This function scans for wifi networks and outputs to a temporary file"""
        from conf import Conf
        import logging
        logger = logging.getLogger(Conf.LOGGER_NAME)

        import subprocess

        self.error = 0

        import os, parser, cp_builder
        self.tmp_scan = cp_builder.build_tmp_scan_path(self.config)
        

        if Conf.DISABLE_SCAN:
            if Conf.DEBUG_MODE:
                logger.info('Scan disabled, we try to read networks from {}'.format(self.tmp_scan))
 
            if not os.path.exists(self.tmp_scan):
                self.error = 1
                logger.error('Modo debug pero el archivo de redes escaneadas {} no existe'.
                             format(self.tmp_scan))
        else:

            try:
                os.remove(self.config.conf_files[Conf.PATH_TMP_SCAN_FILE])
                if Conf.DEBUG_MODE:
                    logger.info("Previous scan deleted")
            except OSError:
                pass

            rfkill_command = cp_builder.build_rfkill_command(self.config,
                                                             Conf.RFKILL_VAL_UNBLOCK,
                                                             Conf.RFKILL_VAL_WIFI)
            ifconfig_command = cp_builder.build_ifconfig_command(self.config,
                                                                 Conf.IFCONFIG_ACTION_UP)
            scan_command = cp_builder.build_scan_command(self.config)
            
            scan_commands = [(rfkill_command, None), (ifconfig_command, None),
                             (scan_command, self.tmp_scan)]

            scan_return_values = cp_builder.execute(scan_commands, True)

            if Conf.DEBUG_MODE:
                logger.info('Commands returned: ' + scan_return_values.__repr__())
Ejemplo n.º 3
0
    def connect_common_pre(self):
        '''
        Execute commands common to all connection strategies. These commands
        come before the specific one are executed.
        Returns True in all commands were succesful
        '''
        success = True
        common_commands = list()

        rfkill_command = cp_builder.build_rfkill_command(self.config,
                                                        Conf.RFKILL_VAL_UNBLOCK,
                                                        Conf.RFKILL_VAL_WIFI)
        ifconfig_command = cp_builder.build_ifconfig_command(self.config,
                                                             Conf.IFCONFIG_ACTION_UP)

        common_commands.append((rfkill_command, None))
        common_commands.append((ifconfig_command, None))

        return common_commands