コード例 #1
0
def main(args):
    if not hlm_notifierbackend.isAvailable():
        sys.exit(1)
    # First connection yields an error if the daemon is not available.
    clientSocket = hlm_clientsocket.ClientSocket()

    while True:
        if __INFO__: logInfo('HLM notifier daemon is up and running.')
        try:
            clientSocket.write('notify')
            #
            # Regexes for parsing the notifications:
            # If a notification starts with [...] then the "..." is supposed
            # to be an icon that we will pass to notify-send.
            # Icons are taken from the hotspot_login_manager/icons directory.
            #
            regex = re.compile('^\\[([^]/]+)\\] ')
            #
            while True:
                message = clientSocket.readMessage()
                if message == '':
                    break
                # Keep-alive message, ignore it
                if message == '.':
                    continue
                # Default icon
                icon = None
                match = regex.search(message)
                if match != None:
                    # We found [icon], check it and adjust the message
                    iconName = match.group(1)
                    iconPath = hlm_application.getPath(
                    ) + '/icons/' + iconName + '.png'
                    if os.path.isfile(iconPath):
                        icon = iconPath
                        message = message[len(iconName) + 3:]
                # Send the notification to the end-user
                hlm_notifierbackend.notify(message, icon)

        finally:
            clientSocket.close()

        # Reconnect silently if the daemon went down
        if __DEBUG__: logDebug('Daemon went down, trying to reconnect...')
        while True:
            try:
                time.sleep(1)
                clientSocket = hlm_clientsocket.ClientSocket()
                if __DEBUG__: logDebug('Daemon went up again.')
                break
            except SystemExit:
                raise
            except KeyboardInterrupt:
                raise
            except BaseException:
                pass
コード例 #2
0
def main(args):
    if not hlm_notifierbackend.isAvailable():
        sys.exit(1)
    # First connection yields an error if the daemon is not available.
    clientSocket = hlm_clientsocket.ClientSocket()

    while True:
        if __INFO__: logInfo('HLM notifier daemon is up and running.')
        try:
            clientSocket.write('notify')
            #
            # Regexes for parsing the notifications:
            # If a notification starts with [...] then the "..." is supposed
            # to be an icon that we will pass to notify-send.
            # Icons are taken from the hotspot_login_manager/icons directory.
            #
            regex = re.compile('^\\[([^]/]+)\\] ')
            #
            while True:
                message = clientSocket.readMessage()
                if message == '':
                    break
                # Keep-alive message, ignore it
                if message == '.':
                    continue
                # Default icon
                icon = None
                match = regex.search(message)
                if match != None:
                    # We found [icon], check it and adjust the message
                    iconName = match.group(1)
                    iconPath = hlm_application.getPath() + '/icons/' + iconName + '.png'
                    if os.path.isfile(iconPath):
                        icon = iconPath
                        message = message[len(iconName)+3:]
                # Send the notification to the end-user
                hlm_notifierbackend.notify(message, icon)

        finally:
            clientSocket.close()

        # Reconnect silently if the daemon went down
        if __DEBUG__: logDebug('Daemon went down, trying to reconnect...')
        while True:
            try:
                time.sleep(1)
                clientSocket = hlm_clientsocket.ClientSocket()
                if __DEBUG__: logDebug('Daemon went up again.')
                break
            except SystemExit:
                raise
            except KeyboardInterrupt:
                raise
            except BaseException:
                pass
コード例 #3
0
def getAuthPlugins():
    ''' Load all the authentication plugins.
    '''
    if getAuthPlugins.__cachePlugins == None:
        pluginsPath = hlm_application.getPath() + '/libs/auth'
        regex = re.compile('^hlma_([a-zA-Z0-9_]+).py$')
        plugins = []
        allProviders = {}
        for item in os.listdir(pluginsPath):
            if os.path.isfile(pluginsPath + '/' + item):
                match = regex.search(item)
                if match != None:
                    try:
                        pluginModule = hlm_plugin.load(item[:-3], pluginsPath,
                                                       'auth')
                        pluginModule.pluginName = match.group(1)
                        # Compute the supported providers, supported SSIDs etc
                        pluginProviders = pluginModule.getSupportedProviders()
                        pluginSSIDs = set()
                        for provider in pluginProviders:
                            pluginSSIDs = pluginSSIDs.union(
                                pluginProviders[provider])
                        pluginModule.supportedSSIDs = list(pluginSSIDs)
                        # Merge the supported plugin providers/SSIDs in the global cache
                        for provider in pluginProviders:
                            if pluginProviders[provider] != []:
                                if provider not in allProviders:
                                    allProviders[provider] = set()
                                allProviders[provider] = allProviders[
                                    provider].union(pluginProviders[provider])
                        # Add the plugin
                        plugins.append(pluginModule)
                    except SystemExit:
                        raise
                    except BaseException as exc:
                        if __WARNING__:
                            logWarning(
                                _('Invalid authentication plugin {0}: {1}').
                                format(quote(item), exc))
        # Normalize the providers list
        if allProviders == {}:
            raise FatalError(
                _('No authentication plugin available / no supported service provider, exiting.'
                  ))
        for provider in allProviders:
            allProviders[provider] = list(allProviders[provider])
            allProviders[provider].sort()
        # Cache the results
        getAuthPlugins.__cachePlugins = plugins
        getAuthPlugins.__cacheProviders = allProviders

    return getAuthPlugins.__cachePlugins
コード例 #4
0
def getAuthPlugins():
    ''' Load all the authentication plugins.
    '''
    if getAuthPlugins.__cachePlugins == None:
        pluginsPath = hlm_application.getPath() + '/libs/auth'
        regex = re.compile('^hlma_([a-zA-Z0-9_]+).py$')
        plugins = []
        allProviders = {}
        for item in os.listdir(pluginsPath):
            if os.path.isfile(pluginsPath + '/' + item):
                match = regex.search(item)
                if match != None:
                    try:
                        pluginModule = hlm_plugin.load(item[:-3], pluginsPath, 'auth')
                        pluginModule.pluginName = match.group(1)
                        # Compute the supported providers, supported SSIDs etc
                        pluginProviders = pluginModule.getSupportedProviders()
                        pluginSSIDs = set()
                        for provider in pluginProviders:
                            pluginSSIDs = pluginSSIDs.union(pluginProviders[provider])
                        pluginModule.supportedSSIDs = list(pluginSSIDs)
                        # Merge the supported plugin providers/SSIDs in the global cache
                        for provider in pluginProviders:
                            if pluginProviders[provider] != []:
                                if provider not in allProviders:
                                    allProviders[provider] = set()
                                allProviders[provider] = allProviders[provider].union(pluginProviders[provider])
                        # Add the plugin
                        plugins.append(pluginModule)
                    except SystemExit:
                        raise
                    except BaseException as exc:
                        if __WARNING__: logWarning(_('Invalid authentication plugin {0}: {1}').format(quote(item), exc))
        # Normalize the providers list
        if allProviders == {}:
            raise FatalError(_('No authentication plugin available / no supported service provider, exiting.'))
        for provider in allProviders:
            allProviders[provider] = list(allProviders[provider])
            allProviders[provider].sort()
        # Cache the results
        getAuthPlugins.__cachePlugins = plugins
        getAuthPlugins.__cacheProviders = allProviders

    return getAuthPlugins.__cachePlugins
コード例 #5
0
#
# Detect the current platform, and exit if it is not supported.
#
_platform = None

if (os.name == 'posix') and (platform.system() == 'Linux'):
    _platform = 'linux'

else:
    logError(_('Sorry, your platform ({0}/{1} {2}) is not supported.').format(os.name, platform.system(), platform.release()))
    sys.exit(255)

#
# Plugins path for the current platform.
#
_platformPluginsPath = hlm_application.getPath() + '/libs/platforms/' + _platform


#-----------------------------------------------------------------------------
def install(wrapperVars, moduleName):
    ''' Import moduleName and install into the wrapper module every public
        variable/function/class it defines.
        Modules imported by moduleName are not installed into the wrapper.

        Public items are the ones NOT starting with an underscore.

        Usage:
            from hotspot_login_manager.libs.core import hlm_platform
            hlm_platform.install(vars(), 'module')
    '''
    moduleObject = hlm_plugin.load('hlmp_' + moduleName, _platformPluginsPath, 'platform')
コード例 #6
0
'''


#-----------------------------------------------------------------------------
import gettext
import sys
#
from hotspot_login_manager.libs.core import hlm_application


#-----------------------------------------------------------------------------
#
# Translation services.
# Bind the gettext functions to the locales directory and domain.
#
gettext.bindtextdomain('hotspot-login-manager', hlm_application.getPath() + '/lang')
gettext.textdomain('hotspot-login-manager')


globals()['__builtins__']['_'] = gettext.gettext
globals()['__builtins__']['_N'] = gettext.ngettext


#-----------------------------------------------------------------------------
#
# Basic logging services.
# Those functions will be overriden in daemon mode by daemon/hlm_log.activate()
#


availableLogLevels = ['info', 'warning', 'error', 'debug']
コード例 #7
0
        must import hlm_globals as early as possible (it should be the first HLM import).
'''

#-----------------------------------------------------------------------------
import gettext
import sys
#
from hotspot_login_manager.libs.core import hlm_application

#-----------------------------------------------------------------------------
#
# Translation services.
# Bind the gettext functions to the locales directory and domain.
#
gettext.bindtextdomain('hotspot-login-manager',
                       hlm_application.getPath() + '/lang')
gettext.textdomain('hotspot-login-manager')

globals()['__builtins__']['_'] = gettext.gettext
globals()['__builtins__']['_N'] = gettext.ngettext

#-----------------------------------------------------------------------------
#
# Basic logging services.
# Those functions will be overriden in daemon mode by daemon/hlm_log.activate()
#

availableLogLevels = ['info', 'warning', 'error', 'debug']
defaultLogLevel = 'info'

コード例 #8
0
#
_platform = None

if (os.name == 'posix') and (platform.system() == 'Linux'):
    _platform = 'linux'

else:
    logError(
        _('Sorry, your platform ({0}/{1} {2}) is not supported.').format(
            os.name, platform.system(), platform.release()))
    sys.exit(255)

#
# Plugins path for the current platform.
#
_platformPluginsPath = hlm_application.getPath(
) + '/libs/platforms/' + _platform


#-----------------------------------------------------------------------------
def install(wrapperVars, moduleName):
    ''' Import moduleName and install into the wrapper module every public
        variable/function/class it defines.
        Modules imported by moduleName are not installed into the wrapper.

        Public items are the ones NOT starting with an underscore.

        Usage:
            from hotspot_login_manager.libs.core import hlm_platform
            hlm_platform.install(vars(), 'module')
    '''
    moduleObject = hlm_plugin.load('hlmp_' + moduleName, _platformPluginsPath,