diff --git a/daemon/core/services/utility.py b/daemon/core/services/utility.py index 3649df61..6f24f58d 100644 --- a/daemon/core/services/utility.py +++ b/daemon/core/services/utility.py @@ -1,6 +1,6 @@ # # CORE -# Copyright (c)2010-2012 the Boeing Company. +# Copyright (c)2010-2014 the Boeing Company. # See the LICENSE file included in this distribution. # # author: Jeff Ahrenholz @@ -394,6 +394,8 @@ class HttpService(UtilService): _startup = ("chown www-data /var/lock/apache2", "apache2ctl start",) _shutdown = ("apache2ctl stop",) _validate = ("pidof apache2",) + + APACHEVER22, APACHEVER24 = (22, 24) @classmethod def generateconfig(cls, node, filename, services): @@ -408,16 +410,55 @@ class HttpService(UtilService): else: return "" + @classmethod + def detectversionfromcmd(cls): + ''' Detect the apache2 version using the 'a2query' command. + ''' + try: + status, result = cmdresult(['a2query', '-v']) + except Exception: + status = -1 + if status == 0 and result[:3] == '2.4': + return cls.APACHEVER24 + return cls.APACHEVER22 + + @classmethod def generateapache2conf(cls, node, filename, services): - return """\ -# apache2.conf generated by utility.py:HttpService -LockFile ${APACHE_LOCK_DIR}/accept.lock + lockstr = { cls.APACHEVER22: + 'LockFile ${APACHE_LOCK_DIR}/accept.lock\n', + cls.APACHEVER24: + 'Mutex file:${APACHE_LOCK_DIR} default\n', } + mpmstr = { cls.APACHEVER22: '', cls.APACHEVER24: + 'LoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so\n', } + + permstr = { cls.APACHEVER22: + ' Order allow,deny\n Deny from all\n Satisfy all\n', + cls.APACHEVER24: + ' Require all denied\n', } + + authstr = { cls.APACHEVER22: + 'LoadModule authz_default_module /usr/lib/apache2/modules/mod_authz_default.so\n', + cls.APACHEVER24: + 'LoadModule authz_core_module /usr/lib/apache2/modules/mod_authz_core.so\n', } + + permstr2 = { cls.APACHEVER22: + '\t\tOrder allow,deny\n\t\tallow from all\n', + cls.APACHEVER24: + '\t\tRequire all granted\n', } + + version = cls.detectversionfromcmd() + cfg ="# apache2.conf generated by utility.py:HttpService\n" + cfg += lockstr[version] + cfg += """\ PidFile ${APACHE_PID_FILE} Timeout 300 KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 5 +""" + cfg += mpmstr[version] + cfg += """\ StartServers 5 @@ -453,9 +494,9 @@ Group ${APACHE_RUN_GROUP} AccessFileName .htaccess - Order allow,deny - Deny from all - Satisfy all +""" + cfg += permstr[version] + cfg += """\ DefaultType None @@ -469,7 +510,9 @@ LogLevel warn #Include mods-enabled/*.conf LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so LoadModule auth_basic_module /usr/lib/apache2/modules/mod_auth_basic.so -LoadModule authz_default_module /usr/lib/apache2/modules/mod_authz_default.so +""" + cfg += authstr[version] + cfg += """\ LoadModule authz_host_module /usr/lib/apache2/modules/mod_authz_host.so LoadModule authz_user_module /usr/lib/apache2/modules/mod_authz_user.so LoadModule autoindex_module /usr/lib/apache2/modules/mod_autoindex.so @@ -506,8 +549,9 @@ TraceEnable Off Options Indexes FollowSymLinks MultiViews AllowOverride None - Order allow,deny - allow from all +""" + cfg += permstr2[version] + cfg += """\ ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn @@ -515,6 +559,7 @@ TraceEnable Off """ + return cfg @classmethod def generateenvvars(cls, node, filename, services):