def loadRelevantPluginCredentials(): ''' Load the credentials configuration file. ''' configFile = hlm_args.args().daemonCredentials config = configparser.SafeConfigParser() try: config.read(configFile) except SystemExit: raise except BaseException as exc: raise FatalError(_('Can\'t load the credentials configuration file {0}: {1}').format(quote(configFile), exc)) configCredentials = {} try: supportedProviders = hlm_auth_plugins.getSupportedProviders() sections = config.sections() regex = re.compile('^provider = ([a-zA-Z0-9_.]+)$') for section in sections: # Check service provider match = regex.search(section) if match == None: raise Exception(_('section {0} is not allowed in this file.').format('[' + section + ']')) provider = match.group(1) if provider not in supportedProviders: raise Exception(_('service provider {0} is not (currently) supported by HLM.').format(quote(provider))) # Check options options = config.options(section) _checkAlienDirectives(['user', 'password'], options, section) user = _mandatoryDirective('user', options, section, config.get) password = _mandatoryDirective('password', options, section, config.get) configCredentials[provider] = (user, password) if configCredentials == {}: raise Exception(_('no configured credentials, exiting.')) # Check which plugins we may use, according to the provided credentials. availablePlugins = hlm_auth_plugins.getAuthPlugins() relevantPlugins = set() for plugin in availablePlugins: plugin.pluginCredentials = {} pluginProviders = plugin.getSupportedProviders() for provider in configCredentials: if provider in pluginProviders: plugin.pluginCredentials[provider] = configCredentials[provider] relevantPlugins.add(plugin) relevantPlugins = list(relevantPlugins) if relevantPlugins == []: raise Exception(_('configured credentials don\'t match any available authentication plugin, exiting.')) if __DEBUG__: logDebug('Credentials configuration has been loaded from {0}.'.format(configFile)) return relevantPlugins except SystemExit: raise except BaseException as exc: raise FatalError(_('Incorrect credentials configuration file {0}: {1}').format(quote(configFile), exc))
def main(args): providers = hlm_auth_plugins.getSupportedProviders() providerNames = list(providers) providerNames.sort() maxProviderNameLength = 0 for provider in providerNames: maxProviderNameLength = max(maxProviderNameLength, len(provider)) print(_('Available service providers:')) for provider in providerNames: padding = ' ' * (maxProviderNameLength - len(provider)) ssidsList = ', '.join(providers[provider]) print(' ' + _('{0} {1}(corresponding hotspots: {2})').format(provider, padding, ssidsList)) sys.exit(0)
def main(args): providers = hlm_auth_plugins.getSupportedProviders() providerNames = list(providers) providerNames.sort() maxProviderNameLength = 0 for provider in providerNames: maxProviderNameLength = max(maxProviderNameLength, len(provider)) print(_('Available service providers:')) for provider in providerNames: padding = ' ' * (maxProviderNameLength - len(provider)) ssidsList = ', '.join(providers[provider]) print(' ' + _('{0} {1}(corresponding hotspots: {2})').format( provider, padding, ssidsList)) sys.exit(0)