Пример #1
0
    def prepare():
        """
            Check if we can restart HAProxy when we are done.

            :raises .errors.NoInstallationError when no haproxy executable can
                be found
            :raises .errors.NoInstallationError when the default service
                manager executable can't be found
            :raises .errors.NotSupportedError when the installed haproxy
                version is incompatible with this plugin
        """
        service_mgr = constants.os_constant("service_manager")
        if not util.exe_exists(service_mgr):
            raise errors.NoInstallationError(
                "Can't find the default service manager for your system:"
                "{0}, please install it first or configure different OS"
                " constants".format(service_mgr))

        # Check that a supported version of HAProxy is installed.
        version_cmd = constants.os_constant("version_cmd")
        output = subprocess.check_output(version_cmd).decode('utf8')
        matches = re.match(
            r'HA-Proxy version'
            r' (?P<version>[0-9]{1,4}\.[0-9]{1,4}\.[0-9a-z]{1,10}).*', output)
        if matches is None:
            raise errors.NoInstallationError(
                "It looks like HAProxy is not installed or the version might"
                " be incompatible.")
        else:
            version = matches.group('version')
            if StrictVersion(version) < StrictVersion(HAPROXY_MIN_VERSION):
                raise errors.NotSupportedError(
                    "Version {} of HAProxy is not supported by this plugin,"
                    " you need to install {} or higher to be"
                    " incompatible.".format(version, HAPROXY_MIN_VERSION))
Пример #2
0
 def _find_config_root(self):
     """Find the Apache Configuration Root file."""
     location = ["apache2.conf", "httpd.conf", "conf/httpd.conf"]
     for name in location:
         if os.path.isfile(os.path.join(self.root, name)):
             return os.path.join(self.root, name)
     raise errors.NoInstallationError("Could not find configuration root")
Пример #3
0
    def prepare(self):
        """Prepare the authenticator/installer.

        :raises .errors.NoInstallationError: If Nginx ctl cannot be found
        :raises .errors.MisconfigurationError: If Nginx is misconfigured
        """
        # Verify Nginx is installed
        if not util.exe_exists(self.conf('ctl')):
            raise errors.NoInstallationError(
                "Could not find a usable 'nginx' binary. Ensure nginx exists, "
                "the binary is executable, and your PATH is set correctly.")

        # Make sure configuration is valid
        self.config_test()

        self.parser = parser.NginxParser(self.conf('server-root'))

        install_ssl_options_conf(self.mod_ssl_conf, self.updated_mod_ssl_conf_digest)

        self.install_ssl_dhparams()

        # Set Version
        if self.version is None:
            self.version = self.get_version()

        # Prevent two Nginx plugins from modifying a config at once
        try:
            util.lock_dir_until_exit(self.conf('server-root'))
        except (OSError, errors.LockError):
            logger.debug('Encountered error:', exc_info=True)
            raise errors.PluginError('Unable to lock {0}'.format(self.conf('server-root')))
Пример #4
0
 def prepare(self):
     logger.debug("******* Inside prepare*************")
     logger.debug("value for self" + self.conf('ctl'))
     if not util.exe_exists(self.conf('ctl')):
         raise errors.NoInstallationError(
             "Could not find a usable 'tomcat' binary. Ensure tomcat exists, "
             "the binary is executable, and your PATH is set correctly.")
     self.parser = tomcat_parser.TomcatParser(self.conf("server-root"))
Пример #5
0
    def _find_config_root(self):
        """Find the Nginx Configuration Root file."""
        location = ['nginx.conf']

        for name in location:
            if os.path.isfile(os.path.join(self.root, name)):
                return os.path.join(self.root, name)

        raise errors.NoInstallationError("Could not find configuration root")
Пример #6
0
def init_augeas() -> Augeas:
    """ Initialize the actual Augeas instance """

    if not Augeas:  # pragma: no cover
        raise errors.NoInstallationError("Problem in Augeas installation")

    return Augeas(
        # specify a directory to load our preferred lens from
        loadpath=constants.AUGEAS_LENS_DIR,
        # Do not save backup (we do it ourselves), do not load
        # anything by default
        flags=(Augeas.NONE | Augeas.NO_MODL_AUTOLOAD | Augeas.ENABLE_SPAN))
Пример #7
0
 def check_version(self):
     """Check Plesk installed and version is supported"""
     if self.secret_key:
         return
     version = os.path.join(self.PSA_PATH, "version")
     if not os.path.exists(version):
         raise errors.NoInstallationError('Plesk is not installed')
     with open(version, 'r') as f:
         version_data = f.read()
         major, _ = version_data.split('.', 1)
         if int(major) < 12:
             raise errors.NotSupportedError(
                 'Plesk version is not supported: %s' % version_data)
Пример #8
0
    def init_augeas(self):
        """ Initialize the actual Augeas instance """

        try:
            import augeas
        except ImportError:  # pragma: no cover
            raise errors.NoInstallationError("Problem in Augeas installation")

        self.aug = augeas.Augeas(
            # specify a directory to load our preferred lens from
            loadpath=constants.AUGEAS_LENS_DIR,
            # Do not save backup (we do it ourselves), do not load
            # anything by default
            flags=(augeas.Augeas.NONE | augeas.Augeas.NO_MODL_AUTOLOAD
                   | augeas.Augeas.ENABLE_SPAN))
Пример #9
0
def verify_exe_exists(exe, message=None):
    """Ensures an executable with the given name is available.

    If an executable isn't found for the given path or name, extra
    directories are added to the user's PATH to help find system
    utilities that may not be available in the default cron PATH.

    :param str exe: executable path or name
    :param str message: Error message to print.

    :raises .NoInstallationError: when the executable isn't found

    """
    if message is None:
        message = "Cannot find executable '{0}'.".format(exe)
    if not (certbot_util.exe_exists(exe) or plugins_util.path_surgery(exe)):
        raise errors.NoInstallationError(message)
Пример #10
0
    def prepare(self):  # type: ignore
        """Prepare the plugin.

        Finish up any additional initialization.

        :raises .PluginError:
            when full initialization cannot be completed.
        :raises .MisconfigurationError:
            when full initialization cannot be completed. Plugin will
            be displayed on a list of available plugins.
        :raises .NoInstallationError:
            when the necessary programs/files cannot be located. Plugin
            will NOT be displayed on a list of available plugins.
        :raises .NotSupportedError:
            when the installation is recognized, but the version is not
            currently supported.

        """
        cfgfile = self.get_tigase_config_file()
        if not os.path.isfile(cfgfile):
            raise errors.NoInstallationError("Invalid Tigase installation.")