summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves-Gwenael Bourhis <yves-gwenael.bourhis@cloudwatt.com>2015-03-31 18:20:20 +0200
committerYves-Gwenael Bourhis <yves-gwenael.bourhis@cloudwatt.com>2015-04-03 09:51:05 +0200
commit42bc31b38687ff8c41319d0e9384e628adbb0a21 (patch)
treeefb9456ea461072bf89aff0ecd87370b55e0914b
parentc8f4f5360f8830b34a6da1c5f112854407e237f9 (diff)
downloadhorizon-42bc31b38687ff8c41319d0e9384e628adbb0a21.tar.gz
Detect apache version
We try to detect apache's version. Some distributions do not allow launching apache commands (even for detection) if not root, so we gracefully fall back on 2.4 version configuration file We alse add an --apache-version option to force the version in case detection would be wrong. Closes Bug: #1438773 Change-Id: I7d28c319601cf3919068be4ac52dd10f58a82557
-rw-r--r--openstack_dashboard/management/commands/apache_vhost.conf.template8
-rw-r--r--openstack_dashboard/management/commands/make_web_conf.py43
2 files changed, 49 insertions, 2 deletions
diff --git a/openstack_dashboard/management/commands/apache_vhost.conf.template b/openstack_dashboard/management/commands/apache_vhost.conf.template
index 5db931852..06fe27fd6 100644
--- a/openstack_dashboard/management/commands/apache_vhost.conf.template
+++ b/openstack_dashboard/management/commands/apache_vhost.conf.template
@@ -24,12 +24,16 @@
WSGIPassAuthorization On
WSGIScriptAlias / {{ WSGI_FILE }}
-
+{% if APACHE2_VERSION >= 2.4 %}
+ <Location "/">
+ Require all granted
+ </Location>
+{% else %}
<Location "/">
Order Allow,Deny
Allow from all
</Location>
-
+{% endif %}
Alias /static {{ STATIC_PATH }}
<Location "/static">
SetHandler None
diff --git a/openstack_dashboard/management/commands/make_web_conf.py b/openstack_dashboard/management/commands/make_web_conf.py
index 38d1de887..9cbfe61d4 100644
--- a/openstack_dashboard/management/commands/make_web_conf.py
+++ b/openstack_dashboard/management/commands/make_web_conf.py
@@ -15,7 +15,9 @@ from __future__ import print_function
from optparse import make_option # noqa
import os
+import re
import socket
+import subprocess
import sys
import warnings
@@ -33,6 +35,14 @@ CURDIR = os.path.realpath(os.path.dirname(__file__))
PROJECT_PATH = os.path.realpath(os.path.join(CURDIR, '../..'))
STATIC_PATH = os.path.realpath(os.path.join(PROJECT_PATH, '../static'))
+# Known apache regular expression to retrieve it's version
+APACHE_VERSION_REG = r'Apache/(?P<version>[\d.]*)'
+# Known apache commands to retrieve it's version
+APACHE2_VERSION_CMDS = (
+ (('/usr/sbin/apache2ctl', '-V'), APACHE_VERSION_REG),
+ (('/usr/sbin/apache2', '-v'), APACHE_VERSION_REG),
+)
+
# Known apache log directory locations
APACHE_LOG_DIRS = (
'/var/log/httpd', # RHEL / Red Hat / CentOS / Fedora Linux
@@ -94,6 +104,29 @@ if virtualenv:
if os.path.exists(activate_this):
context['ACTIVATE_THIS'] = activate_this
+# Try to detect apache's version
+# We fallback on 2.4.
+context['APACHE2_VERSION'] = 2.4
+APACHE2_VERSION = None
+for cmd in APACHE2_VERSION_CMDS:
+ if os.path.exists(cmd[0][0]):
+ try:
+ reg = re.compile(cmd[1])
+ res = reg.search(
+ subprocess.check_output(cmd[0], stderr=subprocess.STDOUT))
+ if res:
+ APACHE2_VERSION = res.group('version')
+ break
+ except subprocess.CalledProcessError:
+ pass
+if APACHE2_VERSION:
+ ver_nums = APACHE2_VERSION.split('.')
+ if len(ver_nums) >= 2:
+ try:
+ context['APACHE2_VERSION'] = float('.'.join(ver_nums[:2]))
+ except ValueError:
+ pass
+
def find_apache_log_dir():
for log_dir in APACHE_LOG_DIRS:
@@ -190,6 +223,14 @@ location you desire, e.g.::
"the path to the SSLCertificateKeyFile "
"(default : %s)") % context['SSLKEY'],
metavar="SSLKEY"),
+ make_option("--apache-version",
+ dest="apache_version",
+ type="float",
+ help=("Use with the --apache option to define the apache "
+ "major (as a floating point number) version "
+ "(default : %s)."
+ % context['APACHE2_VERSION']),
+ metavar="APACHE_VERSION"),
make_option("-w", "--wsgi",
default=False, action="store_true", dest="wsgi",
help="generate the horizon.wsgi file"),
@@ -213,6 +254,8 @@ location you desire, e.g.::
context['SSLCERT'] = options['sslcert']
if options.get('sslkey'):
context['SSLKEY'] = options['sslkey']
+ if options.get('apache_version'):
+ context['APACHE2_VERSION'] = options['apache_version']
if options.get('namedhost'):
context['NAMEDHOST'] = context['VHOSTNAME']