From b7951b909b5acf89c1b9c15f0bc262512d434cae Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 19 Jul 2018 09:50:03 +0200 Subject: [PATCH] apache: replace IncludeOptional with Include IncludeOptional is apache 2.4 only, use Include for apache 2.2 --- Makefile | 2 ++ Makefile.omd | 10 ++++++ debian/postinst.in | 6 ++-- debian/postrm.in | 6 ++++ debian/rules | 1 + omd.spec.in | 10 +++++- packages/apache-omd/.gitignore | 1 + packages/apache-omd/APACHE_TCP_PORT.hook | 2 +- packages/apache-omd/Makefile | 5 --- packages/apache-omd/WEB_ALIAS.hook | 36 +++++++++---------- packages/apache-omd/WEB_REDIRECT.hook | 6 ++-- .../skel/etc/apache/system.d/.gitignore | 0 packages/omd/omd | 2 +- 13 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 packages/apache-omd/skel/etc/apache/system.d/.gitignore diff --git a/Makefile b/Makefile index dd5c518ef..8ad3ed744 100644 --- a/Makefile +++ b/Makefile @@ -122,6 +122,7 @@ pack: done sed -i -e 's|###APACHE_MODULE_DIR###|$(MODULE_DIR)|g' $(DESTDIR)$(OMD_ROOT)/lib/omd/hooks/* + sed -i -e 's|###APACHE_INCLUDEOPT###|$(APACHE_INCLUDEOPT)|g' $(DESTDIR)$(OMD_ROOT)/lib/omd/hooks/* # Repair packages that install with silly modes (such as Nagios) chmod -R o+Xr $(DESTDIR)$(OMD_ROOT) @@ -262,6 +263,7 @@ rpm: -e 's/^Release:.*/Release: $(OMD_SERIAL)/' \ -e 's#@APACHE_CONFDIR@#$(APACHE_CONF_DIR)#g' \ -e 's#@APACHE_NAME@#$(APACHE_NAME)#g' \ + -e 's#@APACHE_INCLUDEOPT@#$(APACHE_INCLUDEOPT)#g' \ omd.spec.in > omd.spec rm -f $(SOURCE_TGZ) test -d .git && $(MAKE) $(SOURCE_TGZ) || $(MAKE) $(SOURCE_TGZ)-snap diff --git a/Makefile.omd b/Makefile.omd index ef1c25a79..bf90f334a 100644 --- a/Makefile.omd +++ b/Makefile.omd @@ -37,3 +37,13 @@ endif ifdef SKIP_PACKAGES PACKAGES:=$(shell for p in $(PACKAGES); do skip=0; for s in $(SKIP_PACKAGES); do if [ "$$s" = "$$p" ]; then skip=1; fi; done; if [ $$skip -eq 0 ]; then echo $$p; fi; done) endif + +APACHE_VERSION = $(shell $(APACHE_BIN) -v | awk '/version/ {print $$3}' | awk -F/ '{print $$2}') +APACHE_VERSION_MAIN = $(word 1, $(subst ., ,$(APACHE_VERSION))) +APACHE_VERSION_SUB = $(word 2, $(subst ., ,$(APACHE_VERSION))) +APACHE_24_OR_NEWER = $(shell [ $(APACHE_VERSION_MAIN) -ge 2 -a $(APACHE_VERSION_SUB) -ge 4 ] && echo 1 || echo 0) +ifeq ($(APACHE_24_OR_NEWER),1) +APACHE_INCLUDEOPT = IncludeOptional +else +APACHE_INCLUDEOPT = Include +endif diff --git a/debian/postinst.in b/debian/postinst.in index e2f4c49c4..bf37c85b8 100755 --- a/debian/postinst.in +++ b/debian/postinst.in @@ -76,7 +76,7 @@ case "$1" in fi if ! test -e $APACHE_OMD_CONF; then - echo "IncludeOptional /omd/apache/*.conf" > $APACHE_OMD_CONF + echo "###APACHE_INCLUDEOPT### /omd/apache/*.conf" > $APACHE_OMD_CONF # -- enable conf include, when available ! test -x /usr/sbin/a2enconf || a2enconf zzz_omd @@ -94,10 +94,10 @@ case "$1" in a2ensite default-ssl fi - ls -1 /etc/apache2/sites-available/default-ssl 2>/dev/null | \ + ls -1 /etc/apache2/sites-available/default-ssl.conf 2>/dev/null | \ while read file; do if ! grep /omd/apache/ $file >/dev/null 2>&1; then - sed -i -e 's||\n IncludeOptional /omd/apache/*.include\n|g' $file + sed -i -e 's||\n ###APACHE_INCLUDEOPT### /omd/apache/*.include\n|g' $file fi done # -- default for init diff --git a/debian/postrm.in b/debian/postrm.in index dc9d39a8b..0d348f1bc 100644 --- a/debian/postrm.in +++ b/debian/postrm.in @@ -45,6 +45,12 @@ case "$1" in fi ! test -x /usr/sbin/a2disconf || a2disconf zzz_omd rm -f $APACHE_OMD_CONF + ls -1 /etc/apache2/sites-available/default-ssl.conf 2>/dev/null | \ + while read file; do + if ! grep /omd/apache/ $file >/dev/null 2>&1; then + sed -i -e '/Include.* \/omd\/apache/d' $file + fi + done rm -f /omd # Try to remove empty directories if test -d /opt/omd/versions; then diff --git a/debian/rules b/debian/rules index 9be08e3b6..a0034a8b5 100755 --- a/debian/rules +++ b/debian/rules @@ -86,6 +86,7 @@ install: build sed -e 's/###OMD_VERSION###/$(OMD_VERSION)/g' \ -e 's/###OMD_SERIAL###/$(OMD_SERIAL)/g' \ + -e 's/###APACHE_INCLUDEOPT###/$(APACHE_INCLUDEOPT)/g' \ $(_PWD)/debian/postinst.in > $(_PWD)/debian/postinst sed -e 's/###OMD_VERSION###/$(OMD_VERSION)/g' \ $(_PWD)/debian/preinst.in > $(_PWD)/debian/preinst diff --git a/omd.spec.in b/omd.spec.in index f172f52f8..026ea23af 100644 --- a/omd.spec.in +++ b/omd.spec.in @@ -143,7 +143,7 @@ fi ls -1 /etc/apache2/vhosts.d/vhost-ssl-omd.conf /etc/httpd/conf.d/ssl.conf | \ while read file; do if ! grep /omd/apache/ $file >/dev/null 2>&1; then - sed -i -e 's||\n IncludeOptional /omd/apache/*.include\n|g' $file + sed -i -e 's||\n @APACHE_INCLUDEOPT@ /omd/apache/*.include\n|g' $file fi done @@ -219,6 +219,14 @@ else rm -f @APACHE_CONFDIR@/zzz_omd.conf rm -f /etc/apache2/vhosts.d/vhost-ssl-omd.conf rm -f /omd + ls -1 /etc/apache2/vhosts.d/vhost-ssl-omd.conf /etc/httpd/conf.d/ssl.conf | \ + while read file; do + if ! grep /omd/apache/ $file >/dev/null 2>&1; then + sed -i -e '/Include.* \/omd\/apache/d' $file + fi + done + + # Try to remove empty directories rmdir /opt/omd/sites 2>/dev/null || true rmdir /opt/omd 2>/dev/null || true diff --git a/packages/apache-omd/.gitignore b/packages/apache-omd/.gitignore index b2df90b68..68f364099 100644 --- a/packages/apache-omd/.gitignore +++ b/packages/apache-omd/.gitignore @@ -1 +1,2 @@ mod_fcgid-?.?.? +mod_rpaf-?.? diff --git a/packages/apache-omd/APACHE_TCP_PORT.hook b/packages/apache-omd/APACHE_TCP_PORT.hook index ef95c9cb0..eddf25495 100755 --- a/packages/apache-omd/APACHE_TCP_PORT.hook +++ b/packages/apache-omd/APACHE_TCP_PORT.hook @@ -85,7 +85,7 @@ EOF -IncludeOptional $OMD_ROOT/etc/apache/*.include +###APACHE_INCLUDEOPT### $OMD_ROOT/etc/apache/system.d/*.conf EOF if [ "$PORT" != "$2" ] ; then echo "Apache port $2 is in use. I've choosen $PORT instead." >&2 diff --git a/packages/apache-omd/Makefile b/packages/apache-omd/Makefile index f156a8e1e..b3a954828 100644 --- a/packages/apache-omd/Makefile +++ b/packages/apache-omd/Makefile @@ -6,11 +6,6 @@ DIR = $(NAME)-$(VERSION) FCGI_FILE="mod_fcgid-2.3.9" MOD_RPAF_VERSION="0.8" -APACHE_VERSION = $(shell $(APACHE_BIN) -v | awk '/version/ {print $$3}' | awk -F/ '{print $$2}') -APACHE_VERSION_MAIN = $(word 1, $(subst ., ,$(APACHE_VERSION))) -APACHE_VERSION_SUB = $(word 2, $(subst ., ,$(APACHE_VERSION))) -APACHE_24_OR_NEWER = $(shell [ $(APACHE_VERSION_MAIN) -ge 2 -a $(APACHE_VERSION_SUB) -ge 4 ] && echo 1 || echo 0) - APACHE_MODULES=modrpaf APACHE_MODULES_INSTALL=modrpaf_install APACHE_FCGID_PATH=$(MODULE_DIR)/$(APACHE_FCGID_MODULE) diff --git a/packages/apache-omd/WEB_ALIAS.hook b/packages/apache-omd/WEB_ALIAS.hook index 99e2098e4..1dbbcb9af 100755 --- a/packages/apache-omd/WEB_ALIAS.hook +++ b/packages/apache-omd/WEB_ALIAS.hook @@ -13,45 +13,43 @@ case "$1" in echo "" ;; choices) - echo "([a-zA-Z0-9-]+)" + echo "([a-zA-Z0-9-_]+)" ;; set) ALIAS=$2 - cat < $OMD_ROOT/etc/apache/alias.include + . $OMD_ROOT/etc/omd/site.conf >/dev/null 2>&1 + PROTO="http" + if [ $CONFIG_APACHE_MODE = "ssl" ]; then + PROTO="https" + fi + sed -i $OMD_ROOT/etc/grafana/grafana.ini -e 's/^root_url.*/root_url = %(protocol)s:\/\/%(domain)s\/'$OMD_SITE'\/grafana\//g' + rm -f $OMD_ROOT/etc/apache/thruk/thruk_local.d/omd_web_alias.conf + mkdir -p $OMD_ROOT/etc/apache/system.d + cat < $OMD_ROOT/etc/apache/system.d/alias.conf # This file is managed by 'omd config set WEB_ALIAS'. # Better do not edit manually EOF if [ ! -z $ALIAS ]; then - cat <> $OMD_ROOT/etc/apache/alias.include -#RewriteEngine on -#RewriteCond %{REQUEST_METHOD} GET -#RewriteRule ^/$OMD_SITE(.*) /$ALIAS\$1 [R=permanent,L,NE] -#RewriteRule ^/$ALIAS(.*) /$OMD_SITE\$1 [PT,L,NE] -#Alias /$OMD_SITE "$OMD_ROOT/var/www" -# -# Options +SymLinksIfOwnerMatch -# AllowOverride All -# Order deny,allow -# Allow from all -# - - + cat <> $OMD_ROOT/etc/apache/system.d/alias.conf RewriteEngine on RewriteCond %{REQUEST_METHOD} GET RewriteRule ^/$OMD_SITE(.*) /$ALIAS\$1 [R=permanent,L,NE] - # Setting "retry=0" to prevent 60 second caching of problem states e.g. when # the site apache is down and someone tries to access the page. # "disablereuse=On" prevents the apache from keeping the connection which leads to # wrong devlivered pages sometimes - ProxyPass https://127.0.0.1:5000/$OMD_SITE retry=0 disablereuse=On - ProxyPassReverse https://127.0.0.1:5000/$OMD_SITE + ProxyPass $PROTO://$CONFIG_APACHE_TCP_ADDR:$CONFIG_APACHE_TCP_PORT/$OMD_SITE retry=0 disablereuse=On + ProxyPassReverse $PROTO://$CONFIG_APACHE_TCP_ADDR:$CONFIG_APACHE_TCP_PORT/$OMD_SITE EOF + cat < $OMD_ROOT/etc/apache/thruk/thruk_local.d/omd_web_alias.conf +cookie_path = /$ALIAS +EOF + sed -i $OMD_ROOT/etc/grafana/grafana.ini -e 's/^root_url.*/root_url = %(protocol)s:\/\/%(domain)s\/'$ALIAS'\/grafana\//g' fi ;; depends) diff --git a/packages/apache-omd/WEB_REDIRECT.hook b/packages/apache-omd/WEB_REDIRECT.hook index 6ad6af1cf..d3ab618f3 100755 --- a/packages/apache-omd/WEB_REDIRECT.hook +++ b/packages/apache-omd/WEB_REDIRECT.hook @@ -22,8 +22,8 @@ case "$1" in echo "on: redirect / to /$TARGET" ;; set) - # just create an empty file - cat < $OMD_ROOT/etc/apache/redirect.include + mkdir -p $OMD_ROOT/etc/apache/system.d + cat < $OMD_ROOT/etc/apache/system.d/redirect.conf # This file is managed by 'omd config set WEB_REDIRECT'. # Better do not edit manually EOF @@ -35,7 +35,7 @@ EOF echo "redirect is currently enabled for site: $CURRENT" >&2 echo "off" else - cat <>$OMD_ROOT/etc/apache/redirect.include + cat <>$OMD_ROOT/etc/apache/system.d/redirect.conf # redirect / to our site RewriteEngine On RewriteRule ^/$ /$OMD_SITE/ [R,L] diff --git a/packages/apache-omd/skel/etc/apache/system.d/.gitignore b/packages/apache-omd/skel/etc/apache/system.d/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/packages/omd/omd b/packages/omd/omd index fa5d21f28..f8ae31644 100755 --- a/packages/omd/omd +++ b/packages/omd/omd @@ -2337,7 +2337,7 @@ def create_apache_hook(sitename): file("/omd/apache/%s.conf" % sitename, "w")\ .write("Include %s/etc/apache/mode.conf\n" % site_dir(sitename)) file("/omd/apache/%s.include" % sitename, "w")\ - .write("IncludeOptional %s/etc/apache/*.include\n" % site_dir(sitename)) + .write("Include %s/etc/apache/system.d/*.conf\n" % site_dir(sitename)) def delete_apache_hook(sitename): hook_path = "/omd/apache/%s.conf" % sitename