mirror of
https://github.com/certbot/certbot.git
synced 2026-07-27 00:00:44 +02:00
Merge remote-tracking branch 'origin/master' into multi-topic-help
This commit is contained in:
@@ -244,7 +244,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
||||
|
||||
if not path["cert_path"] or not path["cert_key"]:
|
||||
# Throw some can't find all of the directives error"
|
||||
logger.warn(
|
||||
logger.warning(
|
||||
"Cannot find a cert or key directive in %s. "
|
||||
"VirtualHost was not modified", vhost.path)
|
||||
# Presumably break here so that the virtualhost is not modified
|
||||
@@ -522,7 +522,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
||||
try:
|
||||
args = self.aug.match(path + "/arg")
|
||||
except RuntimeError:
|
||||
logger.warn("Encountered a problem while parsing file: %s, skipping", path)
|
||||
logger.warning("Encountered a problem while parsing file: %s, skipping", path)
|
||||
return None
|
||||
for arg in args:
|
||||
addrs.add(obj.Addr.fromstring(self.parser.get_arg(arg)))
|
||||
@@ -538,6 +538,9 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
||||
is_ssl = True
|
||||
|
||||
filename = get_file_path(self.aug.get("/augeas/files%s/path" % get_file_path(path)))
|
||||
if filename is None:
|
||||
return None
|
||||
|
||||
if self.conf("handle-sites"):
|
||||
is_enabled = self.is_site_enabled(filename)
|
||||
else:
|
||||
@@ -1089,7 +1092,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
||||
try:
|
||||
func(self.choose_vhost(domain), options)
|
||||
except errors.PluginError:
|
||||
logger.warn("Failed %s for %s", enhancement, domain)
|
||||
logger.warning("Failed %s for %s", enhancement, domain)
|
||||
raise
|
||||
|
||||
def _enable_ocsp_stapling(self, ssl_vhost, unused_options):
|
||||
@@ -1276,9 +1279,9 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
||||
# but redirect loops are possible in very obscure cases; see #1620
|
||||
# for reasoning.
|
||||
if self._is_rewrite_exists(general_vh):
|
||||
logger.warn("Added an HTTP->HTTPS rewrite in addition to "
|
||||
"other RewriteRules; you may wish to check for "
|
||||
"overall consistency.")
|
||||
logger.warning("Added an HTTP->HTTPS rewrite in addition to "
|
||||
"other RewriteRules; you may wish to check for "
|
||||
"overall consistency.")
|
||||
|
||||
# Add directives to server
|
||||
# Note: These are not immediately searchable in sites-enabled
|
||||
@@ -1801,25 +1804,25 @@ def get_file_path(vhost_path):
|
||||
:rtype: str
|
||||
|
||||
"""
|
||||
# Strip off /files
|
||||
avail_fp = vhost_path[6:]
|
||||
# This can be optimized...
|
||||
while True:
|
||||
# Cast all to lowercase to be case insensitive
|
||||
find_if = avail_fp.lower().find("/ifmodule")
|
||||
if find_if != -1:
|
||||
avail_fp = avail_fp[:find_if]
|
||||
continue
|
||||
find_vh = avail_fp.lower().find("/virtualhost")
|
||||
if find_vh != -1:
|
||||
avail_fp = avail_fp[:find_vh]
|
||||
continue
|
||||
find_macro = avail_fp.lower().find("/macro")
|
||||
if find_macro != -1:
|
||||
avail_fp = avail_fp[:find_macro]
|
||||
continue
|
||||
break
|
||||
return avail_fp
|
||||
# Strip off /files/
|
||||
try:
|
||||
if vhost_path.startswith("/files/"):
|
||||
avail_fp = vhost_path[7:].split("/")
|
||||
else:
|
||||
return None
|
||||
except AttributeError:
|
||||
# If we recieved a None path
|
||||
return None
|
||||
|
||||
last_good = ""
|
||||
# Loop through the path parts and validate after every addition
|
||||
for p in avail_fp:
|
||||
cur_path = last_good+"/"+p
|
||||
if os.path.exists(cur_path):
|
||||
last_good = cur_path
|
||||
else:
|
||||
break
|
||||
return last_good
|
||||
|
||||
|
||||
def install_ssl_options_conf(options_ssl):
|
||||
|
||||
@@ -2,7 +2,23 @@
|
||||
import pkg_resources
|
||||
from certbot import util
|
||||
|
||||
|
||||
CLI_DEFAULTS_DEFAULT = dict(
|
||||
server_root="/etc/apache2",
|
||||
vhost_root="/etc/apache2/sites-available",
|
||||
vhost_files="*",
|
||||
version_cmd=['apache2ctl', '-v'],
|
||||
define_cmd=['apache2ctl', '-t', '-D', 'DUMP_RUN_CFG'],
|
||||
restart_cmd=['apache2ctl', 'graceful'],
|
||||
conftest_cmd=['apache2ctl', 'configtest'],
|
||||
enmod=None,
|
||||
dismod=None,
|
||||
le_vhost_ext="-le-ssl.conf",
|
||||
handle_mods=False,
|
||||
handle_sites=False,
|
||||
challenge_location="/etc/apache2",
|
||||
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
|
||||
"certbot_apache", "options-ssl-apache.conf")
|
||||
)
|
||||
CLI_DEFAULTS_DEBIAN = dict(
|
||||
server_root="/etc/apache2",
|
||||
vhost_root="/etc/apache2/sites-available",
|
||||
@@ -71,7 +87,25 @@ CLI_DEFAULTS_DARWIN = dict(
|
||||
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
|
||||
"certbot_apache", "options-ssl-apache.conf")
|
||||
)
|
||||
CLI_DEFAULTS_SUSE = dict(
|
||||
server_root="/etc/apache2",
|
||||
vhost_root="/etc/apache2/vhosts.d",
|
||||
vhost_files="*.conf",
|
||||
version_cmd=['apache2ctl', '-v'],
|
||||
define_cmd=['apache2ctl', '-t', '-D', 'DUMP_RUN_CFG'],
|
||||
restart_cmd=['apache2ctl', 'graceful'],
|
||||
conftest_cmd=['apache2ctl', 'configtest'],
|
||||
enmod="a2enmod",
|
||||
dismod="a2dismod",
|
||||
le_vhost_ext="-le-ssl.conf",
|
||||
handle_mods=False,
|
||||
handle_sites=False,
|
||||
challenge_location="/etc/apache2/vhosts.d",
|
||||
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
|
||||
"certbot_apache", "options-ssl-apache.conf")
|
||||
)
|
||||
CLI_DEFAULTS = {
|
||||
"default": CLI_DEFAULTS_DEFAULT,
|
||||
"debian": CLI_DEFAULTS_DEBIAN,
|
||||
"ubuntu": CLI_DEFAULTS_DEBIAN,
|
||||
"centos": CLI_DEFAULTS_CENTOS,
|
||||
@@ -83,6 +117,8 @@ CLI_DEFAULTS = {
|
||||
"gentoo": CLI_DEFAULTS_GENTOO,
|
||||
"gentoo base system": CLI_DEFAULTS_GENTOO,
|
||||
"darwin": CLI_DEFAULTS_DARWIN,
|
||||
"opensuse": CLI_DEFAULTS_SUSE,
|
||||
"suse": CLI_DEFAULTS_SUSE,
|
||||
}
|
||||
"""CLI defaults."""
|
||||
|
||||
@@ -115,13 +151,36 @@ HEADER_ARGS = {"Strict-Transport-Security": HSTS_ARGS,
|
||||
|
||||
|
||||
def os_constant(key):
|
||||
"""Get a constant value for operating system
|
||||
"""
|
||||
Get a constant value for operating system
|
||||
|
||||
:param key: name of cli constant
|
||||
:return: value of constant for active os
|
||||
"""
|
||||
|
||||
os_info = util.get_os_info()
|
||||
try:
|
||||
constants = CLI_DEFAULTS[os_info[0].lower()]
|
||||
except KeyError:
|
||||
constants = CLI_DEFAULTS["debian"]
|
||||
constants = os_like_constants()
|
||||
if not constants:
|
||||
constants = CLI_DEFAULTS["default"]
|
||||
return constants[key]
|
||||
|
||||
|
||||
def os_like_constants():
|
||||
"""
|
||||
Try to get constants for distribution with
|
||||
similar layout and configuration, indicated by
|
||||
/etc/os-release variable "LIKE"
|
||||
|
||||
:returns: Constants dictionary
|
||||
:rtype: `dict`
|
||||
"""
|
||||
|
||||
os_like = util.get_systemd_os_like()
|
||||
if os_like:
|
||||
for os_name in os_like:
|
||||
if os_name in CLI_DEFAULTS.keys():
|
||||
return CLI_DEFAULTS[os_name]
|
||||
return {}
|
||||
|
||||
@@ -91,7 +91,7 @@ def _vhost_menu(domain, vhosts):
|
||||
"non-interactive mode. Currently Certbot needs each vhost to be "
|
||||
"in its own conf file, and may need vhosts to be explicitly "
|
||||
"labelled with ServerName or ServerAlias directories.")
|
||||
logger.warn(msg)
|
||||
logger.warning(msg)
|
||||
raise errors.MissingCommandlineFlag(msg)
|
||||
|
||||
return code, tag
|
||||
|
||||
@@ -146,7 +146,7 @@ class ApacheParser(object):
|
||||
constants.os_constant("define_cmd"))
|
||||
# Small errors that do not impede
|
||||
if proc.returncode != 0:
|
||||
logger.warn("Error in checking parameter list: %s", stderr)
|
||||
logger.warning("Error in checking parameter list: %s", stderr)
|
||||
raise errors.MisconfigurationError(
|
||||
"Apache is unable to check whether or not the module is "
|
||||
"loaded because Apache is misconfigured.")
|
||||
|
||||
@@ -56,7 +56,7 @@ class MultipleVhostsTest(util.ApacheTest):
|
||||
mock_surgery.return_value = False
|
||||
with mock.patch.dict('os.environ', silly_path):
|
||||
self.assertRaises(errors.NoInstallationError, self.config.prepare)
|
||||
self.assertEquals(mock_surgery.call_count, 1)
|
||||
self.assertEqual(mock_surgery.call_count, 1)
|
||||
|
||||
@mock.patch("certbot_apache.augeas_configurator.AugeasConfigurator.init_augeas")
|
||||
def test_prepare_no_augeas(self, mock_init_augeas):
|
||||
@@ -125,6 +125,12 @@ class MultipleVhostsTest(util.ApacheTest):
|
||||
self.assertTrue("google.com" in names)
|
||||
self.assertTrue("certbot.demo" in names)
|
||||
|
||||
def test_get_bad_path(self):
|
||||
from certbot_apache.configurator import get_file_path
|
||||
self.assertEqual(get_file_path(None), None)
|
||||
self.assertEqual(get_file_path("nonexistent"), None)
|
||||
self.assertEqual(self.config._create_vhost("nonexistent"), None) # pylint: disable=protected-access
|
||||
|
||||
def test_bad_servername_alias(self):
|
||||
ssl_vh1 = obj.VirtualHost(
|
||||
"fp1", "ap1", set([obj.Addr(("*", "443"))]),
|
||||
@@ -1242,8 +1248,8 @@ class MultipleVhostsTest(util.ApacheTest):
|
||||
mock_match = mock.Mock(return_value=["something"])
|
||||
self.config.aug.match = mock_match
|
||||
# pylint: disable=protected-access
|
||||
self.assertEquals(self.config._check_aug_version(),
|
||||
["something"])
|
||||
self.assertEqual(self.config._check_aug_version(),
|
||||
["something"])
|
||||
self.config.aug.match.side_effect = RuntimeError
|
||||
self.assertFalse(self.config._check_aug_version())
|
||||
|
||||
|
||||
@@ -25,3 +25,20 @@ class ConstantsTest(unittest.TestCase):
|
||||
os_info.return_value = ('Nonexistent Linux', '', '')
|
||||
self.assertEqual(constants.os_constant("vhost_root"),
|
||||
"/etc/apache2/sites-available")
|
||||
|
||||
@mock.patch("certbot.util.get_os_info")
|
||||
def test_get_default_constants(self, os_info):
|
||||
os_info.return_value = ('Nonexistent Linux', '', '')
|
||||
with mock.patch("certbot.util.get_systemd_os_like") as os_like:
|
||||
# Get defaults
|
||||
os_like.return_value = False
|
||||
c_hm = constants.os_constant("handle_mods")
|
||||
c_sr = constants.os_constant("server_root")
|
||||
self.assertFalse(c_hm)
|
||||
self.assertEqual(c_sr, "/etc/apache2")
|
||||
# Use darwin as like test target
|
||||
os_like.return_value = ["something", "nonexistent", "darwin"]
|
||||
d_vr = constants.os_constant("vhost_root")
|
||||
d_em = constants.os_constant("enmod")
|
||||
self.assertFalse(d_em)
|
||||
self.assertEqual(d_vr, "/etc/apache2/other")
|
||||
|
||||
@@ -129,7 +129,7 @@ class ApacheTlsSni01(common.TLSSNI01):
|
||||
# because it's a new vhost that's not configured yet (GH #677),
|
||||
# or perhaps because there were multiple <VirtualHost> sections
|
||||
# in the config file (GH #1042). See also GH #2600.
|
||||
logger.warn("Falling back to default vhost %s...", default_addr)
|
||||
logger.warning("Falling back to default vhost %s...", default_addr)
|
||||
addrs.add(default_addr)
|
||||
return addrs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user