certbot/certbot-apache/certbot_apache/constants.py

125 lines
4 KiB
Python
Raw Normal View History

"""Apache plugin constants."""
import pkg_resources
from certbot import le_util
2015-12-03 07:14:02 -05:00
CLI_DEFAULTS_DEBIAN = dict(
2015-05-08 17:32:13 -04:00
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'],
2015-05-08 17:32:13 -04:00
enmod="a2enmod",
2015-07-30 02:40:07 -04:00
dismod="a2dismod",
le_vhost_ext="-le-ssl.conf",
handle_mods=True,
handle_sites=True,
challenge_location="/etc/apache2",
2016-01-26 13:39:54 -05:00
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf")
2015-05-08 17:32:13 -04:00
)
2015-12-03 07:14:02 -05:00
CLI_DEFAULTS_CENTOS = dict(
server_root="/etc/httpd",
vhost_root="/etc/httpd/conf.d",
vhost_files="*.conf",
version_cmd=['apachectl', '-v'],
define_cmd=['apachectl', '-t', '-D', 'DUMP_RUN_CFG'],
restart_cmd=['apachectl', 'graceful'],
conftest_cmd=['apachectl', 'configtest'],
2015-12-03 07:14:02 -05:00
enmod=None,
dismod=None,
le_vhost_ext="-le-ssl.conf",
handle_mods=False,
handle_sites=False,
challenge_location="/etc/httpd/conf.d",
2016-01-26 13:39:54 -05:00
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "centos-options-ssl-apache.conf")
2015-12-03 07:14:02 -05:00
)
CLI_DEFAULTS_GENTOO = dict(
server_root="/etc/apache2",
vhost_root="/etc/apache2/vhosts.d",
vhost_files="*.conf",
version_cmd=['/usr/sbin/apache2', '-v'],
2016-03-23 12:12:07 -04:00
define_cmd=['apache2ctl', 'virtualhosts'],
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/vhosts.d",
2016-01-26 13:39:54 -05:00
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf")
)
CLI_DEFAULTS_DARWIN = dict(
server_root="/etc/apache2",
vhost_root="/etc/apache2/other",
vhost_files="*.conf",
version_cmd=['/usr/sbin/httpd', '-v'],
define_cmd=['/usr/sbin/httpd', '-t', '-D', 'DUMP_RUN_CFG'],
restart_cmd=['apachectl', 'graceful'],
conftest_cmd=['apachectl', 'configtest'],
enmod=None,
dismod=None,
le_vhost_ext="-le-ssl.conf",
handle_mods=False,
handle_sites=False,
challenge_location="/etc/apache2/other",
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf")
)
2015-12-03 07:14:02 -05:00
CLI_DEFAULTS = {
"debian": CLI_DEFAULTS_DEBIAN,
"ubuntu": CLI_DEFAULTS_DEBIAN,
"centos": CLI_DEFAULTS_CENTOS,
2015-12-07 07:22:56 -05:00
"centos linux": CLI_DEFAULTS_CENTOS,
"fedora": CLI_DEFAULTS_CENTOS,
2015-12-21 15:52:32 -05:00
"red hat enterprise linux server": CLI_DEFAULTS_CENTOS,
"gentoo base system": CLI_DEFAULTS_GENTOO,
"darwin": CLI_DEFAULTS_DARWIN,
2015-12-03 07:14:02 -05:00
}
2015-05-08 17:32:13 -04:00
"""CLI defaults."""
MOD_SSL_CONF_DEST = "options-ssl-apache.conf"
"""Name of the mod_ssl config file as saved in `IConfig.config_dir`."""
2015-11-04 15:12:39 -05:00
AUGEAS_LENS_DIR = pkg_resources.resource_filename(
"certbot_apache", "augeas_lens")
2015-11-04 15:12:39 -05:00
"""Path to the Augeas lens directory"""
REWRITE_HTTPS_ARGS = [
2015-07-21 20:16:46 -04:00
"^", "https://%{SERVER_NAME}%{REQUEST_URI}", "[L,QSA,R=permanent]"]
2016-01-14 06:25:15 -05:00
"""Apache version<2.3.9 rewrite rule arguments used for redirections to
https vhost"""
2015-11-06 17:31:30 -05:00
REWRITE_HTTPS_ARGS_WITH_END = [
"^", "https://%{SERVER_NAME}%{REQUEST_URI}", "[END,QSA,R=permanent]"]
2015-12-01 19:16:13 -05:00
"""Apache version >= 2.3.9 rewrite rule arguments used for redirections to
https vhost"""
2015-11-07 23:37:57 -05:00
HSTS_ARGS = ["always", "set", "Strict-Transport-Security",
2016-01-14 06:25:15 -05:00
"\"max-age=31536000\""]
2015-11-06 17:31:30 -05:00
"""Apache header arguments for HSTS"""
2015-11-07 23:37:57 -05:00
UIR_ARGS = ["always", "set", "Content-Security-Policy",
2016-01-14 06:25:15 -05:00
"upgrade-insecure-requests"]
2015-11-07 23:37:57 -05:00
2015-11-08 10:21:36 -05:00
HEADER_ARGS = {"Strict-Transport-Security": HSTS_ARGS,
2016-01-14 06:25:15 -05:00
"Upgrade-Insecure-Requests": UIR_ARGS}
2015-11-07 23:37:57 -05:00
2015-12-07 06:37:58 -05:00
2015-12-03 07:14:02 -05:00
def os_constant(key):
2015-12-07 05:01:35 -05:00
"""Get a constant value for operating system
:param key: name of cli constant
:return: value of constant for active os
"""
2015-12-03 07:14:02 -05:00
os_info = le_util.get_os_info()
try:
constants = CLI_DEFAULTS[os_info[0].lower()]
except KeyError:
constants = CLI_DEFAULTS["debian"]
return constants[key]