Пример #1
0
    def str_to_ou(self, ou_string):
        """
        Generate a OU string with the path of the node. For example, for the node /root/first_child/grand_son,
        it's str_to_ou() is OU=grand_son,OU=first_child,OU=root,DC=myDomain,DC=local.
        The DC datas are read from the configuration file.

        Params:
            String ou_string contains the path of the node pointed.

        Returns:
            String which contains the result (i.e.: OU=grand_son,OU=first_child,OU=root,DC=myDomain,DC=local)
            or
            returns False if the string can't be generated
        """
        config = PluginConfigFactory.new(BasePluginConfig, "base")
        if config.has_section('authentication_externalldap'):
            # Get the parameters from the config file
            suffix = config.get('authentication_externalldap', 'suffix')

            ou_list = ou_string.split('/')
            ou_list.reverse()

            ous = []
            for ou in ou_list:
                ou = 'OU=' + ou
                ous.append(ou)

            ous.append(suffix)
            return ','.join(ous)

        else:
            return False
Пример #2
0
def get_openldap_config():
    """Return OpenLdap credentials used by mmc base plugin"""
    mmc_base_config = PluginConfigFactory.new(BasePluginConfig, "base")
    return {
        'base_dn': mmc_base_config.baseDN,
        'bind_dn': mmc_base_config.username,
        'bind_pw': mmc_base_config.password
    }
Пример #3
0
def get_conf_array(name):
    config = PluginConfigFactory.get(name)
    array = {}
    for section in config.sections():
        config.options(section)
        dic = {}
        for opt in config.options(section):
            dic[opt] = config.get(section, opt)
        array[section] = dic
    return array
Пример #4
0
def get_conf_array(name):
    config = PluginConfigFactory.get(name)
    array = {}
    for section in config.sections():
        config.options(section)
        dic = {}
        for opt in config.options(section):
            dic[opt] = config.get(section, opt)
        array[section] = dic
    return array
Пример #5
0
def get_openldap_config():
    """
    Return OpenLdap credentials used by mmc base plugin
    """
    from mmc.support.config import PluginConfigFactory
    from mmc.plugins.base.config import BasePluginConfig
    mmc_base_config = PluginConfigFactory.new(BasePluginConfig, "base")
    return {'base_dn': mmc_base_config.baseDN,
            'bind_dn': mmc_base_config.username,
            'bind_pw': mmc_base_config.password}
Пример #6
0
def set_conf_array(args):
    print(args)
    name, values = args['filename'], args['values']
    config = PluginConfigFactory.get(name)
    for option_name in values:
        section_name = values[option_name]['section_name']
        value = values[option_name]['value']
        if not config.has_section(section_name):
            config.add_section(section_name)
        config.set(section_name, option_name, value)
    # TODO check if the conf is OK, and return an error message if not
    return True
Пример #7
0
def set_conf_array(args):
    print(args)
    name, values = args['filename'], args['values']
    config = PluginConfigFactory.get(name)
    for option_name in values:
        section_name = values[option_name]['section_name']
        value = values[option_name]['value']
        if not config.has_section(section_name):
            config.add_section(section_name)
        config.set(section_name, option_name, value)
    # TODO check if the conf is OK, and return an error message if not
    return True
Пример #8
0
def loadInventoryConf(module_name):
    """
    before commiting the config for the inventory module
    we are switching to, we make sure the config is loaded
    (if not we load it), to be able to modify its value
    before starting the module
    Also enable and disable the correct module (but they
    are not yet started, just the config is modified)
    """
    inventory_config = PluginConfigFactory.new(InventoryConfig, "inventory")
    glpi_config = PluginConfigFactory.new(GlpiConfig, "glpi")
    print("Instance of inventory config in loadInventoryConf is %s" % inventory_config)

    # Enable and disable the right modules in their config
    # base_config = PluginConfigFactory.get("base")
    # base_config.set('computers', 'method', module_name)
    glpi_config.set("main", "disable", "0" if module_name == "glpi" else 1)
    inventory_config.init("inventory")
    inventory_config.cp.set("main", "disable", "0" if module_name == "inventory" else 1)

    print("Disable: ", inventory_config.disable)
Пример #9
0
def loadInventoryConf(module_name):
    """
    before commiting the config for the inventory module
    we are switching to, we make sure the config is loaded
    (if not we load it), to be able to modify its value
    before starting the module
    Also enable and disable the correct module (but they
    are not yet started, just the config is modified)
    """
    inventory_config = PluginConfigFactory.new(InventoryConfig, "inventory")
    glpi_config = PluginConfigFactory.new(GlpiConfig, "glpi")
    print('Instance of inventory config in loadInventoryConf is %s' %
          inventory_config)

    # Enable and disable the right modules in their config
    # base_config = PluginConfigFactory.get("base")
    # base_config.set('computers', 'method', module_name)
    glpi_config.set('main', 'disable', '0' if module_name == 'glpi' else 1)
    inventory_config.init('inventory')
    inventory_config.cp.set('main', 'disable',
                            '0' if module_name == 'inventory' else 1)

    print('Disable: ', inventory_config.disable)
Пример #10
0
    def __init__(self, config=None, init=True):
        Singleton.__init__(self)
        if not hasattr(self, "logaction"):
            if config == None:
                from mmc.plugins.base import BasePluginConfig
                from mmc.support.config import PluginConfigFactory

                try:
                    # Read the configuration
                    self.make(PluginConfigFactory.new(BasePluginConfig, "base"), init)
                except IOError:
                    # Fallback on default configuration
                    self.make(None, init)
            else:
                self.make(config, init)
Пример #11
0
 def __init__(self, config=None, init=True):
     Singleton.__init__(self)
     if not hasattr(self, 'logaction'):
         if config == None:
             from mmc.plugins.base import BasePluginConfig
             from mmc.support.config import PluginConfigFactory
             try:
                 # Read the configuration
                 self.make(
                     PluginConfigFactory.new(BasePluginConfig, 'base'),
                     init)
             except IOError:
                 # Fallback on default configuration
                 self.make(None, init)
         else:
             self.make(config, init)
Пример #12
0
def getLdapRootDN():
    """
    Returns the LDAP root DN.
    """
    config = PluginConfigFactory.new(BasePluginConfig, 'base')
    return {'LDAP root': config.baseDN}
Пример #13
0
def getLdapRootDN():
    """
    Returns the LDAP root DN.
    """
    config = PluginConfigFactory.new(BasePluginConfig, 'base')
    return {'LDAP root': config.baseDN}