commit 9472a46bea71710848ecae6809478218b9915dc5 Author: Christoph Date: Tue Feb 21 02:20:36 2017 +0100 Initial import diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a149b6f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/BAK/* diff --git a/add_custom_log_to_vhost.sh b/add_custom_log_to_vhost.sh new file mode 100755 index 0000000..c139380 --- /dev/null +++ b/add_custom_log_to_vhost.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +vhost_config_dir=/usr/local/apache2/conf/vhosts + +_temp_dir=`mktemp -d` + +cp -a $vhost_config_dir ${vhost_config_dir}-`date +%Y%m%d-%H%M` + +files=`find $vhost_config_dir -maxdepth 1 -mindepth 1 -type f -print` + +_tmp_file=`mktemp` +echo false > $_tmp_file + +find "$vhost_config_dir" -maxdepth 1 -mindepth 1 -type f -print | while read _file ; do + echo "$_file" + [[ "`basename $_file`" = "0000-logformat.conf" ]] && continue; + [[ "`basename $_file`" = "000-default.conf" ]] && continue; + new_file="$_temp_dir/`basename $_file`" + while IFS='' read -r line || [[ -n $line ]]; do + if [[ "$line" =~ " $_tmp_file + fi + if [[ "$line" =~ "$log_entry" ]]; then + echo "false" > $_tmp_file + fi + if [[ "$line" =~ "> $new_file + ## - with tabstop + #echo -e " $log_entry" >> $new_file + ## - with blank signs + echo -e " $log_entry" >> $new_file + echo "" >> $new_file + fi + echo false > $_tmp_file + fi + echo "$line" >> $new_file + done < $_file +done + + +find $_temp_dir -maxdepth 1 -mindepth 1 -type f -print -exec cp -f {} $vhost_config_dir/ \; > /dev/null 2>&1 + +rm -f $_tmp_file +rm -rf $_temp_dir + +exit diff --git a/add_https_to_vhosts.sh b/add_https_to_vhosts.sh new file mode 100755 index 0000000..bafae04 --- /dev/null +++ b/add_https_to_vhosts.sh @@ -0,0 +1,355 @@ +#!/usr/bin/env bash + +_date=`date +%Y-%m-%d-%H%M` + +vhost_dir=/usr/local/apache2/conf/vhosts +target_dir=$vhost_dir +#target_dir=/root/tmp +ipv4=83.223.86.82 +ipv6="2a01:30:0:13:26f:6dff:feb9:9d11" +_cert_default=/usr/local/apache2/conf/server-bundle.crt +_key_default=/usr/local/apache2/conf/server.key + +file_suffixes="conf mod_php php-fpm mod_fcgid mod_php redirect" + +## --- Some functions +## --- + +## - Check if a given array (parameter 2) contains a given string (parameter 1) +## - +containsElement () { + local e + for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done + return 1 +} + +echononl(){ + echo X\\c > /tmp/shprompt$$ + if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then + echo -e -n "$*\\c" 1>&2 + else + echo -e -n "$*" 1>&2 + fi + rm /tmp/shprompt$$ +} + +fatal(){ + echo "" + echo -e "fataler Fehler: $*" + echo "" + echo -e "\t\033[31m\033[1mInstalllation wird abgebrochen\033[m\033[m" + echo "" + exit 1 +} + +error(){ + echo "" + echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*" + echo "" +} + +warn (){ + echo "" + echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" + echo "" +} + +info (){ + echo "" + echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" + echo "" +} + +echo_done() { + echo -e "\033[75G[ \033[32mdone\033[m ]" +} +echo_ok() { + echo -e "\033[75G[ \033[32mok\033[m ]" +} +echo_warning() { + echo -e "\033[75G[ \033[33m\033[1mwarn\033[m ]" +} +echo_failed(){ + echo -e "\033[75G[ \033[1;31mfailed\033[m ]" +} +echo_skipped() { + echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]" +} + + +echo "" + +if [[ "$vhost_dir" = "$target_dir" ]]; then + cp -a $vhost_dir ${vhost_dir}.$_date + vhost_dir=${vhost_dir}.$_date +fi + +declare -a vhost_arr_tmp +while IFS='' read -r -d '' _file ; do + + [[ -h "$_file" ]] && continue + vhost_arr_tmp+=("$_file") + +done < <(find $vhost_dir -mindepth 1 -maxdepth 1 -type f -print0) + +# - Sort array +# - +IFS=$'\n' vhost_arr=($(sort <<<"${vhost_arr_tmp[*]}")) +unset IFS + +declare -a file_suffixe_arr +for _suffix in $file_suffixes ; do + file_suffixe_arr+=("$_suffix") +done + +declare -i number=0 +declare -a file_already_ok_arr +declare -a file_not_converted_arr +declare -a file_ipv4_ok_arr +declare -a file_ipv6_ok_arr +for _file in ${vhost_arr[@]} ; do + + # - For testing + # - + #if [[ $number -gt 3 ]]; then + # break + #fi + + echononl " Working on $(basename $_file) .." + + if [[ "$(basename $_file)" =~ ^00 ]] ; then + echo_skipped + info "File $(basename $_file) left unchanged" + file_not_converted_arr+=("$_file") + continue + fi + + _found=false + for _suffix in ${file_suffixe_arr[@]} ; do + if [[ "$_suffix" = "${_file##*.}" ]]; then + _found=true + break + fi + done + + if ! $_found ; then + echo_failed + error "File $(basename $_file) was not edited. Wrong suffix \"${_file##*.}\"" + file_not_converted_arr+=("$_file") + continue + fi + + + _basename_file=$(basename $_file) + + https_ipv4=false + https_ipv6=false + + if grep -i -E "^\s* /dev/null 2>&1 ; then + https_ipv4=true + fi + if grep -i -E "^\s*" $_file> /dev/null 2>&1 ; then + https_ipv6=true + fi + + if $https_ipv4 && $https_ipv6 ; then + file_already_ok_arr+=("$_file") + echo_skipped + info "File $(basename $_file) already converted.." + continue + fi + + if $https_ipv4 ; then + file_ipv4_ok_arr+=("$_file") + fi + if $https_ipv6 ; then + file_ipv6_ok_arr+=("$_file") + fi + + > $target_dir/${_basename_file}.80 + > $target_dir/${_basename_file}.443 + > $target_dir/${_basename_file} + server_name_found=false + server_name= + vhost_ipv4_80=false + found_custom_log=false + ssl_cert_found=false + ssl_key_found=false + ssl_cert=$_cert_default + ssl_key=$_key_default + server_aliases_arr=() + while IFS='' read -r _line || [[ -n $_line ]] ; do + + if echo "$_line" | grep -i -E "^\s*" > /dev/null 2>&1 ; then + vhost_ipv4_80=false + fi + + if ! $ssl_cert_found && echo "$_line" | grep -E "^\s*SSLCertificateFile\s+" > /dev/null 2>&1 ; then + ssl_cert_found=true + ssl_cert=$(echo $_line | awk '{print$2}') + fi + if ! $ssl_key_found && echo "$_line" | grep -E "^\s*SSLCertificateKeyFile\s+" > /dev/null 2>&1 ; then + ssl_key_found=true + ssl_key=$(echo $_line | awk '{print$2}') + fi + + if echo $_line | grep -e "^\s*ServerAlias" > /dev/null 2>&1 ; then + + server_alias_tmp=$(echo $_line | sed -e "s/ServerAlias//" | sed "s/^\s*//" | sed "s/\s*$//") + + if [[ ${#server_aliases_arr[@]} -eq 0 ]] ; then + for _alias in $server_alias_tmp ; do + server_aliases_arr+=("$_alias") + done + else + for _alias in $server_alias_tmp ; do + containsElement "$_alias" "${server_aliases_arr[@]}" && continue + server_aliases_arr+=("$_alias") + done + fi + fi + + + if $vhost_ipv4_80 ; then + if echo "$_line" | grep -i -E "^\s*CustomLog\s+" > /dev/null 2>&1 && ! $found_custom_log ; then + echo " SSLEngine on" >> $target_dir/${_basename_file}.443 + echo "" >> $target_dir/${_basename_file}.443 + echo " SSLCertificateFile $ssl_cert" >> $target_dir/${_basename_file}.443 + echo " SSLCertificateKeyFile $ssl_key" >> $target_dir/${_basename_file}.443 + echo "" >> $target_dir/${_basename_file}.443 + found_custom_log=true + fi + echo "$_line" >> $target_dir/${_basename_file}.80 + echo "$_line" >> $target_dir/${_basename_file}.443 + fi + + if echo "$_line" | grep -i -E "^\s* /dev/null 2>&1 ; then + vhost_ipv4_80=true + fi + + if ! $server_name_found && echo "$_line" | grep -E "^\s*ServerName\s+" > /dev/null 2>&1 ; then + server_name_found=true + server_name=$(echo $_line | awk '{print$2}') + fi + + done < "$_file" + + if [[ -z "$(cat $target_dir/${_basename_file}.80)" ]] ; then + echo_failed + error "File $(basename $_file) was not edited. Maybe no Configuration (for IPv4) found!" + file_not_converted_arr+=("$_file") + continue + fi + + + let number++ + + if [[ "$ssl_cert" != "$_cert_default" ]]; then + perl -i -n -p -e "s#^(\s*)SSLCertificateFile\s+.*#\1SSLCertificateFile $ssl_cert#" \ + $target_dir/${_basename_file}.443 + fi + if [[ "$ssl_key" != "$_key_default" ]]; then + perl -i -n -p -e "s#^(\s*)SSLCertificateKeyFile\s+.*#\1SSLCertificateKeyFile $ssl_key#" \ + $target_dir/${_basename_file}.443 + fi + + + # - Delete empty lines at the beginning + # - + while [[ "$(head -n 1 $target_dir/${_basename_file}.80)" =~ ^\s*$ ]] ; do + sed -i '1d' $target_dir/${_basename_file}.80 + done + while [[ "$(head -n 1 $target_dir/${_basename_file}.443)" =~ ^\s*$ ]] ; do + sed -i '1d' $target_dir/${_basename_file}.443 + done + + # - Delete empty lines at the end + # - + while [[ "$(tail -n 1 $target_dir/${_basename_file}.80)" =~ ^\s*$ ]] ; do + sed -i '$ d' $target_dir/${_basename_file}.80 + done + while [[ "$(tail -n 1 $target_dir/${_basename_file}.443)" =~ ^\s*$ ]] ; do + sed -i '$ d' $target_dir/${_basename_file}.443 + done + + echo "# --- $server_name" > $target_dir/${_basename_file} + for _alias in "${server_aliases_arr[@]}" ; do + echo "# --- $_alias" >> $target_dir/${_basename_file} + done + echo "" >> $target_dir/$(basename $_file) + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + cat $target_dir/${_basename_file}.80 >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + cat $target_dir/${_basename_file}.443 >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + + perl -i -n -p -e "s#^(\s*)CustomLog\s+/var/log/apache2/ipv4_requests.log\s+.*#\1CustomLog /var/log/apache2/ipv6_requests.log base_requests#" $target_dir/${_basename_file}.443 + + perl -i -n -p -e "s#^(\s*)CustomLog\s+/var/log/apache2/ipv4_requests.log\s+.*#\1CustomLog /var/log/apache2/ipv6_requests.log base_requests#" $target_dir/${_basename_file}.80 + + echo "# ---" >> $target_dir/${_basename_file} + echo "# --- IPv6" >> $target_dir/${_basename_file} + echo "# ---" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + cat $target_dir/${_basename_file}.80 >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + cat $target_dir/${_basename_file}.443 >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + echo "" >> $target_dir/${_basename_file} + + rm $target_dir/${_basename_file}.80 + rm $target_dir/${_basename_file}.443 + + echo_done + +done + +echo +if [[ ${#file_already_ok_arr[@]} -gt 0 ]] ; then + echo "" + echo -e "\033[32m\033[1mFiles left unchanged\033[m:" + for _file in ${file_already_ok_arr[@]} ; do + echo " $(basename $_file)" + done +fi +echo "" + +if [[ ${#file_ipv4_ok_arr[@]} -gt 0 ]]; then + echo "" + echo -e "\033[33m\033[1mIPv6 support was added on files\033[m:" + for _file in ${file_ipv4_ok_arr[@]} ; do + echo " $(basename $_file)" + done +fi +#if [[ ${#file_ipv6_ok_arr[@]} -gt 0 ]]; then +# echo "" +# echo -e "\033[37m\033[1mOriginally, no IPv4 support.\n\033[31m\033[1mFiles not converted:\033[m" +# for _file in ${file_ipv6_ok_arr[@]} ; do +# echo " $(basename $_file)" +# done +#fi + +if [[ ${#file_not_converted_arr[@]} -gt 0 ]]; then + echo "" + echo -e "\033[31m\033[1mFiles ot converted\033[m:" + for _file in ${file_not_converted_arr[@]}; do + echo " $(basename $_file)" + done +fi + +echo "" +exit 0 diff --git a/apache_memory_usage.sh b/apache_memory_usage.sh new file mode 100755 index 0000000..c379e80 --- /dev/null +++ b/apache_memory_usage.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +echo "" +ps -ylC httpd + +echo "" +ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}' +echo "" diff --git a/convert_vhosts_2.4.sh b/convert_vhosts_2.4.sh new file mode 100755 index 0000000..48aac13 --- /dev/null +++ b/convert_vhosts_2.4.sh @@ -0,0 +1,49 @@ +#!/bin/sh + + +#APACHE_CONF_DIR=/usr/local/httpd-2.4.2/conf +APACHE_CONF_DIR="/usr/local/httpd-2.4.9_php-5.3.28/conf" +VHOST_DIR=${APACHE_CONF_DIR}/vhosts + + + +#_conf_files=`find $VHOST_DIR -type f -name *.conf` +_conf_files=`find $VHOST_DIR -type f` + + +for file in $_conf_files ; do + + [ -d "$file" ] && continue + [ -h "$file" ] && continue + + echo "convert \"`basename $file`\".." + + ## - + ## - Order deny,allow + ## - Deny from all --> Require all denied + ## - + ## - Order allow,deny + ## - Allow from all --> Require all granted + ## - + ## - + sed -i.bak -r -e "s/^(\s*NameVirtualHost.*)$/#\1/g" $file + sed -i -r -e "s/^(\s*)(Order\s+[aA]llow\s*,\s*[dD]eny)$/\1#\2/g" $file + sed -i -r -e "s/^(\s*)([aA]llow\s+from\s+[aA][lL]{2}\s*)$/\1#\2\n\1Require all granted/g" $file + sed -i -r -e "s/^(\s*)([dD]eny\s+from\s+[aA][lL]{2}\s*)$/\1#\2\n\1Require all denied/g" $file + sed -i -r -e "s/^(\s*)([dD]eny\s+from\s+[aA][lL]{2}\s*)$/\1#\2\n\1Require all denied/g" $file + + ## - Order Deny,Allow + ## - Deny from all + ## - Allow from 127.0.0.1 192.168.63.40 --> Require ip 127.0.0.1 192.168.63.40 + ## - + sed -i -r -e "s/^(\s*)([aA]llow\s+from)\s+([0-2][0-9]{0,2}\..*)$/\1#\2 \3\n\1Require ip \3/g" $file + + ## - Order Deny,Allow + ## - Deny from all + ## - Allow from example.org --> Require host example.org + ## - + sed -i -r -e "s/^(\s*)([aA]llow\s+from)\s+(.*)$/\1#\2 \3\n\1Require host \3/g" $file +done + +exit 0 + diff --git a/create_vhost_php.sh b/create_vhost_php.sh new file mode 100755 index 0000000..6d870b8 --- /dev/null +++ b/create_vhost_php.sh @@ -0,0 +1,2887 @@ +#!/usr/bin/env bash + +#_COMMON_FCGID_CONFIG_PATH=/var/www/html/projekte/_FCGI_DEFAULT +__CUSTOM_IPV4_LOG=ipv4_requests.log +__CUSTOM_IPV6_LOG=ipv6_requests.log + +function usage() { + echo + [ -n "$1" ] && echo -e "Error: $1\n" + +cat< + Only used if type is fcgi (\"-t FCGID\"). If given, a common + existing configuration directory will be used for FCGI configurations. + if not given, a site-specific configuration directory will be + created. + + -t + One of \"PHP-FPM\", \"FCGID\" or \"MOD_PHP\" + If not give, the site url will be requested. + + -S + Only used if type is php-fpm (\"-t PHP-FPM\"). + + -q + Don't print summary before starting creation the vhost entry + is set + + -u + i.e. www.oopen.de + If not give, the site url will be requested. + + +EOF +exit 1 +} + +## - Determine the installed different PHP major versions +## - +__major_php_verisons="" +_php_installation_dirs=`find /usr/local -mindepth 1 -maxdepth 1 -type l -name "*php-*" -print | sort` +for dir in $_php_installation_dirs ; do + _major_version="${dir##*-}" + __major_php_verisons="$__major_php_verisons $_major_version" +done +_major_php_verisons=`echo "$__major_php_verisons" | sed 's/^ *//'` + +## - Defaults +## - +_suEXEC=false +_auto="" +create_phpinfo_file=true +site_url="" +_type="" +_COMMON_FCGID_CONFIG_PATH="" +_UNIX_FPM_SOCKET="" +major_php_verison="" +_print_summary=true +_create_symlink_web_base_dir=false +_symlink_web_base_dir="" + +while getopts aChp:sS:t:u:v: opt ; do + case $opt in + a) _auto="auto" ;; + C) create_phpinfo_file="false" ;; + h) usage ;; + p) if [ -n "$OPTARG" -a -d "$OPTARG" ]; then + _COMMON_FCGID_CONFIG_PATH=$OPTARG + fi + ;; + q) _print_summary=false ;; + S) if [ -n "$OPTARG" -a -S "$OPTARG" ]; then + unix_socket=$OPTARG + connection="unix_socket" + _connection_msg="Unix Socket" + fi + ;; + t) if [ "$OPTARG" = "PHP-FPM" -o "$OPTARG" = "FCGID" -o "$OPTARG" = "MOD_PHP" ]; then + _type=$OPTARG + fi + ;; + u) site_url=$OPTARG ;; + v) + for _version in $_major_php_verisons ; do + if [ "$OPTARG" = "$_version" ]; then + major_php_verison=$OPTARG + fi + done + ;; + \?) usage + esac +done + +#echo +#echo "_auto..............: $_auto" +#echo "site_url...........: $site_url" +#echo "_type..............: $_type" +#echo "fcgi_common_path...: $_COMMON_FCGID_CONFIG_PATH" +#echo "unix_socket........: $unix_socket" +#echo "major_php_verison..: $major_php_verison" +#echo "_print_summary.....: $_print_summary" +#echo + + +#__ipv4="83.223.86.164" +#__ipv6="2a01:30:1fff:a::164" + +__ipv4="`ifconfig | grep -e \"^\s*inet Adresse\" | grep -v \"127.0.0.1\" | awk '{print$2}' | cut -d\":\" -f2 | sort | head -1`" +__ipv6="`ifconfig | grep -e \"^\s*inet6-Adresse\" | awk '{print$2}' | grep -v -e \"^::1/\" | grep -v -e \"^fe80\" | cut -d\"/\" -f1 | sort | head -1`" + + +## - Needed for PHP-FPM environment +## - +## - Default values +## - +_tcp_host=127.0.0.1 +_tcp_port=9000 + + +## - Determin httpd binary +## - +_httpd_binary="`which httpd`" +if [ -z "$_httpd_binary" ]; then + _httpd_binary="`ps -C httpd -f | grep -e \"^root\" | awk '{print$8}'`" + if [ -z "$_httpd_binary" ]; then + if [ -x "/usr/local/apache2/bin/httpd" ]; then + _httpd_binary="/usr/local/apache2/bin/httpd" + fi + fi +fi + +_base_webserver_info_needed=false +## - Determin websever user +## - +_pass_web_user=false +web_user="`$_httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" +web_group="`$_httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" +if [ -z "$web_user" -o -z "$web_group" ]; then + _base_webserver_info_needed=true +else + _pass_web_user=true +fi + + +## - Determin ServerRoot Directory +## - +_pass_apache_base_dir=false +apache_base_dir=`$_httpd_binary -t -D DUMP_RUN_CFG | grep ServerRoot | awk '{print$2}' | tr -d '"'` +if [ "`realpath /usr/local/apache2`" = "$apache_base_dir" ]; then + apache_base_dir="/usr/local/apache2" + _apache_base_dir_realpath="`realpath $apache_base_dir`" +elif [ -z "$apache_base_dir" ]; then + if [ -d "`realpath /usr/local/apache2`" ];then + apache_base_dir="/usr/local/apache2" + _apache_base_dir_realpath="`realpath $apache_base_dir`" + fi +else + _apache_base_dir_realpath=$apache_base_dir +fi +if [ -z "$apache_base_dir" ];then + _base_webserver_info_needed=true +else + _pass_apache_base_dir=true +fi + + +## - Determin (default) ServerAdmin E-Mail Address" +## - +_pass_server_admin=false +if [ -f "${apache_base_dir}/conf/httpd.conf" ]; then + server_admin="`cat ${apache_base_dir}/conf/httpd.conf | grep ServerAdmin | grep -v -e \"^\s*#\" | awk '{print$2}'`" +fi +if [ -z "$server_admin" ];then + _base_webserver_info_needed=true +else + _pass_server_admin=true +fi + +## - Determine the installed different PHP major versions +## - +#__major_php_verisons="" +#_php_installation_dirs=`find /usr/local -mindepth 1 -maxdepth 1 -type l -name "*php-*" -print | sort` +#for dir in $_php_installation_dirs ; do +# _major_version="${dir##*-}" +# __major_php_verisons="$__major_php_verisons $_major_version" +#done +#_major_php_verisons=`echo "$__major_php_verisons" | sed 's/^ *//'` + + + +## --- Some functions +## --- + +## Check if a given array (parameter 2) contains a given string (parameter 1) +containsElement () { + local e + for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done + return 1 +} + +echononl(){ + echo X\\c > /tmp/shprompt$$ + if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then + echo "$*\\c" 1>&2 + else + echo -e -n "$*" 1>&2 + fi + rm /tmp/shprompt$$ +} + +fatal(){ + echo "" + if [ "X$*" != "X" ]; then + echo -e "\t[ \033[31m\033[1mError\033[m ]: $*" + echo "" + fi + echo -e "\t\033[31m\033[1mExiting installation now..\033[m" + echo "" + exit 1 +} + +info (){ + echo "" + echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" + echo "" +} + +warn (){ + echo "" + echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" + echo "" +} + + +error (){ + echo "" + echo -e "\t[ \033[31m\033[1mError\033[m ]: $*" + echo "" +} + + +echo_ok() { + echo -e "\033[85G[ \033[32mok\033[m ]" + ## echo -e " [ ok ]" +} +echo_failed(){ + echo -e "\033[85G[ \033[1;31mfailed\033[m ]" + ## echo -e " [ failed ]" +} +echo_skipped() { + echo -e "\033[85G[ \033[33m\033[1mskipped\033[m ]" +} +## --- +## --- END: functions + + +## -------------------------------------------------- + +#clear +echo +echo +echo -e "\033[21G\033[32mCreate PHP configuration on webserver \"`hostname -f`\"..\033[m" + +#echo "" +echo "" +echo -e "\033[32m--\033[m" +echo "" +if [ -z "$site_url" ]; then + echo "Insert Site (i.e. www.oopen.de)." + echo "" + echo "" + site_url= + echononl "Site URL: " + read site_url + while [ "X$site_url" = "X" ] ; do + echo -e "\n\t\033[33m\033[1mEingabe erforderlich.\033[m\n" + echononl "Site URL: " + read site_url + done +else + echo "Create Configuration for site \"$site_url\".." +fi + +echo "" +echo -e "\033[32m--\033[m" +echo "" +if [ "$_type" != "PHP-FPM" -a "$_type" != "FCGID" -a "$_type" != "MOD_PHP" ];then + echo "Select PHP implementation configure for ?" + echo "" + echo "[1] PHP-FPM (FastCGI Process Manager)" + echo "[2] mod_fcgid (Apache FastCGI implementation)" + echo "[3] mod_php (Apache PHP Module)" + echo "[4] suEXEC ( using mod_fcgid)" + echo "" + echononl "Your choice: " + while [ "$_type" != "PHP-FPM" -a "$_type" != "FCGID" -a "$_type" != "MOD_PHP" ];do + read OPTION + case $OPTION in + 1) _type="PHP-FPM" + _type_msg="PHP-FPM (FastCGI Process Manager)" + _new_extension=php-fpm + ;; + 2) _type="FCGID" + _type_msg="mod_fcgid (Apache FastCGI implementation)" + _new_extension=mod_fcgid + ;; + 3) _type="MOD_PHP" + _type_msg="mod_php (Apache PHP Module)" + _new_extension=mod_php + ;; + 4) _type="FCGID" + _suEXEC=true + _type_msg="suEXEC (using mod_fcgid)" + _new_extension=suexec + ;; + *) echo "" + echo -e "\t\033[1;33mFalsche Eingabe ! [ 1 = PHP-FPM ; 2 = mod_fcgid , 3 = mod_php ]\033[m" + echo "" + echononl "Your choice: " + ;; + esac + done +else + + if [ "$_type" = "PHP-FPM" ];then + _type_msg="PHP-FPM (FastCGI Process Manager)" + _new_extension=php-fpm + elif [ "$_type" = "FCGID" ]; then + if $_suEXEC ; then + _type_msg="suEXEC (using mod_fcgid)" + _new_extension=suexec + else + _type_msg="mod_fcgid (Apache FastCGI implementation)" + _new_extension=mod_fcgid + fi + elif [ "$_type" = "MOD_PHP" ]; then + _type_msg="mod_php (Apache PHP Module)" + _new_extension=mod_php + fi + + echo "Configure PHP implementation for \"$_type\"" +fi + +if $_base_webserver_info_needed ; then + + + + if ! $_pass_apache_base_dir ; then + echo "" + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Apache ServerRoot directory." + echo "" + echo "" + apache_base_dir= + while [ "X$apache_base_dir" = "X" ] ; do + echononl "Apache ServerRoot Directory [$_apache_base_dir]: " + read apache_base_dir + if [ "X$apache_base_dir" = "X" ]; then + apache_base_dir=$_apache_base_dir + fi + done + _apache_base_dir_realpath=`realpath $apache_base_dir 2> /dev/null` + if [ ! -d "$_apache_base_dir_realpath" ]; then + fatal "Cannot find directory \"$apache_base_dir\"!" + fi + + if [ ! -d "${_apache_base_dir_realpath}/conf/vhosts" ]; then + fatal "Cannot find vhost directory. tried \"${_apache_base_dir_realpath}/conf/vhosts\"" + fi + fi + + if ! $_pass_server_admin ; then + echo "" + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Insert email address for server admin." + echo "" + echo "" + server_admin= + while [ "X$server_admin" = "X" ] ; do + #echo -e "\n\t\033[33m\033[1mEingabe erforderlich!\033[m\n" + echononl "Email Admin [$_server_admin]: " + read server_admin + if [ "X$server_admin" = "X" ]; then + server_admin=$_server_admin + fi + done + fi + + if ! $_pass_web_user ; then + echo "" + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Insert User/Group for apache daemon (httpd)." + echo "" + echo "" + + web_user= + while [ "X$web_user" = "X" ] + do + echononl "apache user [${_web_user}]: " + read web_user + if [ "X$web_user" = "X" ]; then + web_user=$_web_user + fi + done + if [ "$web_user" = "nobody" ]; then + _web_group="nogroup" + else + _web_group=$web_user + fi + while [ "X$web_group" = "X" ] + do + echononl "apache group [$_web_group]: " + read web_group + if [ "X$web_group" = "X" ]; then + web_group=$_web_group + fi + done + fi + +fi # if $_base_webserver_info_needed ; then + + +## - Looking for existent VHost Configuration +## - +#_vhost_config=`grep -l -r -E "(ServerName|ServerAlias)\s+.*$site_url" ${_apache_base_dir_realpath}/conf/vhosts* 2> /dev/null` +_vhost_config=`grep -l -r -E "(ServerName|ServerAlias)\s+$site_url" ${_apache_base_dir_realpath}/conf/vhosts* 2> /dev/null` + +_existing_vhost_config_file="" +if [ -n "$_vhost_config" ]; then + declare -i _count=0 + + for _config_file in $_vhost_config ; do + if [ -z "$_config_file" ]; then + continue + fi + [[ "$_config_file" =~ /DELETED/ ]] && continue + _extension="${_config_file##*.}" + if [ "$_extension" = "swp" ] ; then + continue + fi + if [ "$_extension" = "$_new_extension" ]; then + error "Found configuration file \"$_config_file\".\n\n\t It seems, $_type configuration is already done." + fatal + fi + if [ "$_extension" = "conf" ]; then + _existing_vhost_config_file=`realpath $_config_file` + _new_vhost_config_file=${_config_file}.$_new_extension + _new_vhost=false + break + else + _name="${_config_file%.*}" + if [ "`realpath $_name`" = "$_config_file" ]; then + _existing_vhost_config_file="$_config_file" + _new_vhost_config_file=${_name}.$_new_extension + _new_vhost=false + break + fi + fi + let _count++ + done +fi + +if [ -z "$_existing_vhost_config_file" ]; then + + echo "" + echo "" + echo -e "\033[33m--\033[m" + echo"" + echo -e "\033[21G\033[33mNo configuration file found for site \"$site_url\"..\033[m" + echo "" + echo -e "\033[1;33m--\033[m" + echo "" + echo "" + OK="" + echononl "Create a new $_type vhost entry? [yes/no]: " + read OK + while [ "X$OK" != "Xyes" -a "X$OK" != "XYes" -a "X$OK" != "Xno" -a "X$OK" != "XNo" ]; do + echononl "falsche Angabe! [yes/no]: " + read OK + done + [ $OK = "yes" -o $OK = "Yes" ] || fatal Abbruch durch Benutzer + _new_vhost=true + _config_file_found=false + + + _HOST=`echo $site_url | cut -s -d"." -f 1` + _DOMAIN=`echo $site_url | cut -s -d"." -f 2` + _TDL=`echo $site_url | cut -s -d"." -f 3` + + if [ -z "$_TDL" ]; then + _TDL=$_DOMAIN + _DOMAIN=$_HOST + fi + + if [ -d "/var/www/html/projekte" ]; then + __server_website_root_dir="/var/www/html/projekte" + elif [ -d "/var/www" ]; then + __server_website_root_dir="/var/www" + fi + + #clear + echo "" + if [ "$_HOST" = "www" ]; then + echo -e "\033[21G\033[32mCreate vhost configuration \"${_DOMAIN}.${_TDL}.conf.$_new_extension\"\033[m" + else + echo -e "\033[21G\033[32mCreate vhost configuration \"${site_url}.conf.$_new_extension\"\033[m" + fi + echo "" + echo -e "\033[21GInsert needed Information for VHost Configuration.." + echo "" + + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Servers root directory for websites (i.e. /var/www).." + echo "" + echo "" + _server_website_root_dir= + while [ "X$_server_website_root_dir" = "X" ] ; do + echononl "Root Directory for websites [$__server_website_root_dir]: " + read _doc_root + if [ "X$_server_website_root_dir" = "X" ]; then + _server_website_root_dir=$__server_website_root_dir + fi + if [ -n "$_server_website_root_dir" -a ! -d "$_server_website_root_dir" ]; then + echo -e "\n\t\033[1;33mDirectory \"$_server_website_root_dir\" does not exist.\n\tTry again..\033[m\n" + _server_website_root_dir="" + fi + done + + if [ "$_HOST" = "www" ]; then + __web_base_dir=${_server_website_root_dir}/${_DOMAIN}.$_TDL + else + __web_base_dir=${_server_website_root_dir}/${site_url} + fi + + _server_name=$site_url + if [ "$_HOST" = "www" ]; then + _server_alias=${_DOMAIN}.$_TDL + else + _server_alias="" + fi + + #_doc_root="$document_root" + + + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Insert Website Base Directory (the directory containing" + echo "the Document Root Directory .." + echo "" + echo "" + _web_base_dir= + while [ "X$_web_base_dir" = "X" ] ; do + echononl "Web Base Directory [$__web_base_dir]: " + read _web_base_dir + if [ "X$_web_base_dir" = "X" ]; then + _web_base_dir=$__web_base_dir + fi + done + __document_root=${_web_base_dir}/htdocs + + + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "It is possible to create a symlink for \"`basename $_web_base_dir`\". You can do" + echo "that here bygiving a name for the symlink." + echo "" + echo -e "Type \"\033[33mNone\033[m\" if no symlink is wanted." + echo "" + echo "" + + __symlink_web_base_dir=`basename $_web_base_dir | cut -d '.' -f 1` + echononl "Create Symlink for `basename $_web_base_dir`? [$__symlink_web_base_dir]: " + read _symlink_web_base_dir + if [ "X$_symlink_web_base_dir" = "Xnone" -o "X$_symlink_web_base_dir" = "XNone" ]; then + _create_symlink_web_base_dir=false + else + _create_symlink_web_base_dir=true + fi + if [ "X$_symlink_web_base_dir" = "X" ]; then + _symlink_web_base_dir=$__symlink_web_base_dir + fi + if [ "$_symlink_web_base_dir" = "`basename $_web_base_dir`" ]; then + warn "Given name for symlink is equal to `basename $_web_base_dir`.\n\t No symlink will be created.." + _create_symlink_web_base_dir=false + fi + + + __log_dir=${_web_base_dir}/logs + + __vhost_base_dir=${apache_base_dir}/conf/vhosts + + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Insert Document Root Directory.." + echo "" + echo "" + _doc_root= + while [ "X$_doc_root" = "X" ] ; do + echononl "Document Root Directory [$__document_root]: " + read _doc_root + if [ "X$_doc_root" = "X" ]; then + _doc_root=$__document_root + fi + if [ "`dirname $_doc_root`" != "$_web_base_dir" ]; then + echo -e "\n\t\033[1;33mDocument Root Directory must be a subdirectory of \"$_web_base_dir\".\n\tTry again..\033[m\n" + _doc_root= + fi + done + + + echo "" + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Insert Directory where logfiles should stay.." + echo "" + echo "" + _log_dir= + while [ "X$_log_dir" = "X" ] ; do + echononl "Log Directory [$__log_dir]: " + read _log_dir + if [ "X$_log_dir" = "X" ]; then + _log_dir=$__log_dir + fi + done + if [ "$_HOST" = "www" ]; then + _combined_custom_log="$_log_dir/${_DOMAIN}-access.log" + _error_log="$_log_dir/${_DOMAIN}-error.log" + else + _combined_custom_log="$_log_dir/${site_url}-access.log" + _error_log="$_log_dir/${site_url}-error.log" + fi + + + _custom_ipv4_log="" + echo + if [ -n "$__CUSTOM_IPV4_LOG" ]; then + echo -e "Additional Logfiles - Type \"\033[33mNone\033[m\" if not present" + echononl "\tAdditional Logfile for IPv4 requests [${__CUSTOM_IPV4_LOG}]: " + read _custom_ipv4_log + if [ "X$_custom_ipv4_log" = "X" ]; then + _custom_ipv4_log=$__CUSTOM_IPV4_LOG + fi + if [ "X$_custom_ipv4_log" = "XNone" ]; then + _custom_ipv4_log="" + fi + else + echo "Additional Logfiles - Leave empty if not present" + echononl "\tAdditional Logfile for IPv4 requests: " + read _custom_ipv4_log + fi + + if [ -n "$_custom_ipv4_log" ]; then + if [ "`dirname $_custom_ipv4_log`" = "." ]; then + _custom_ipv4_log=/var/log/apache2/$_custom_ipv4_log + fi + fi + + + _custom_ipv6_log="" + echo "" + if [ -n "$__CUSTOM_IPV6_LOG" ]; then + echo -e "Additional Logfiles - Type \"\033[33mNone\033[m\" if not present" + echononl "\tAdditional Logfile for IPv6 requests [${__CUSTOM_IPV6_LOG}]: " + read _custom_ipv6_log + if [ "X$_custom_ipv6_log" = "X" ]; then + _custom_ipv6_log=$__CUSTOM_IPV6_LOG + fi + if [ "X$_custom_ipv6_log" = "XNone" ]; then + _custom_ipv6_log="" + fi + else + echo "Additional Logfiles - Leave empty if not present" + echononl "\tAdditional Logfile for IPv6 requests : " + read _custom_ipv6_log + fi + + if [ -n "$_custom_ipv6_log" ]; then + #echo "dirname $_custom_ipv6_log: `dirname $_custom_ipv6_log`" + if [ "`dirname $_custom_ipv6_log`" = "." ]; then + _custom_ipv6_log=/var/log/apache2/$_custom_ipv6_log + fi + fi + + + echo "" + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Insert Directory where the vhost configuration file should stay.." + echo "" + echo "" + _vhost_base_dir= + while [ "X$_vhost_base_dir" = "X" ] ; do + echononl "VHost Base Directory [$__vhost_base_dir]: " + read _vhost_base_dir + if [ "X$_vhost_base_dir" = "X" ]; then + _vhost_base_dir=$__vhost_base_dir + fi + if [ ! -d "$_vhost_base_dir" ];then + echo -e "\n\t\033[1;33mDirectory \"${_vhost_base_dir}\" not found! Try again..\033[m\n" + _vhost_base_dir="" + fi + done + if [ "$_HOST" = "www" ]; then + _new_vhost_config_file=${_vhost_base_dir}/${_DOMAIN}.${_TDL}.conf.$_new_extension + else + _new_vhost_config_file=${_vhost_base_dir}/${site_url}.conf.$_new_extension + fi + + echo "" + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Insert the IP-Addresses where the webserver should listen for that site." + echo "" + echo "" + echo "" + + _ipv4= + while [ "X$_ipv4" = "X" ] + do + if [ -z "$__ipv4" ]; then + echononl "IPv4 address: " + read _ipv4 + if [ "X$_ipv4" = "X" ]; then + echo -e "\n\t\033[33m\033[1mEingabe erforderlich!\033[m\n" + fi + else + echononl "IPv4 address [$__ipv4]: " + read _ipv4 + if [ "X$_ipv4" = "X" ]; then + _ipv4=$__ipv4 + fi + fi + + done + + _ipv6= + while [ "X$_ipv6" = "X" ] + do + if [ -z "$__ipv6" ]; then + echononl "IPv6 address: " + read _ipv6 + if [ "X$_ipv6" = "X" ]; then + warn "Disable support for IPv6.." + _ipv6="disabled" + #echononl "Must NOT be empty. Insert again: " + fi + else + echononl "IPv6 address [$__ipv6]: " + read _ipv6 + if [ "X$_ipv6" = "X" ]; then + _ipv6=$__ipv6 + fi + fi + done + + + echo "" + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Insert more hostnames (ServerAlias) for this site..." + echo "" + server_aliases= + if [ "$_HOST" = "www" ]; then + while [ "X$server_aliases" = "X" ]; do + echo -e "Type \"\033[33mskip\033[m\" to omit ServerAlias\n" + echononl "More hostnames: [$_server_alias]: " + read server_aliases + if [ "skip" = "$server_aliases" ]; then + server_aliases= + break + fi + if [ "X$server_aliases" = "X" ];then + server_aliases=$_server_alias + fi + done + else + echo -e "Leave empty to omit ServerAlias\n" + echononl "More hostnames: " + read server_aliases + fi + for _alias in $server_aliases ; do + containsElement "$_alias" "${_server_aliases_arr[@]}" && continue + _server_aliases_arr+=("$_alias") + done + + echo "" + echo "" + echo -e "\033[33m--\033[m" + echo"" + echo -e "\033[21G\033[33mListen on SSL connectons (HTTPS) for \"$site_url\" ?\033[m" + echo "" + echo -e "\033[1;33m--\033[m" + echo "" + echo "" + + OK="" + echononl "Enable SSL? [yes]: " + read OK + while [ "X$OK" != "Xyes" -a "X$OK" != "XYes" -a "X$OK" != "Xno" -a "X$OK" != "XNo" -a "X$OK" != "X" ]; do + echononl "falsche Angabe! [yes]: " + read OK + done + if [ "$OK" = "yes" -o "$OK" = "Yes" -o "X$OK" = "X" ]; then + _https=true + else + _https=false + fi + + if $_https ; then + + _ommit_ssl_chain_file=false + if [ -f "${apache_base_dir}/conf/server-bundle.crt" ]; then + __ssl_cert_file="${apache_base_dir}/conf/server-bundle.crt" + _ommit_ssl_chain_file=true + elif [ -f "${apache_base_dir}/conf/server.crt" ]; then + __ssl_cert_file="${apache_base_dir}/conf/server.crt" + fi + + if [ -f "${apache_base_dir}/conf/server.key" ]; then + __ssl_key_file="${apache_base_dir}/conf/server.key" + fi + + if ! $_ommit_ssl_chain_file ; then + if [ -f "${apache_base_dir}/conf/server-ca-bundle.crt" ]; then + __ssl_chain_file="${apache_base_dir}/conf/server-ca-bundle.crt" + elif [ -f "${apache_base_dir}/conf/StartSSL_SUB_CLASS2.pem" ]; then + __ssl_chain_file="${apache_base_dir}/conf/StartSSL_SUB_CLASS2.pem" + elif [ -f "${apache_base_dir}/conf/sub.class2.server.ca.pem" ]; then + __ssl_chain_file="${apache_base_dir}/conf/sub.class2.server.ca.pem" + elif [ -f "${apache_base_dir}/conf/SSL123_CA_Bundle_SHA2_root_SHA1.pem" ]; then + __ssl_chain_file="${apache_base_dir}/conf/SSL123_CA_Bundle_SHA2_root_SHA1.pem" + elif [ -f "${apache_base_dir}/conf/SSL123_CA_Bundle.pem" ]; then + __ssl_chain_file="${apache_base_dir}/conf/SSL123_CA_Bundle.pem" + fi + fi + + #clear + echo "" + echo -e "\033[21G\033[32mCreate vhost configuration \"${_DOMAIN}.${_TDL}.conf.$_new_extension\"\033[m" + echo "" + echo -e "\033[21GInsert Parameters needed for SSL.." + + echo "" + echo -e "\033[1;32m--\033[m" + echo "" + echo -e "Input SSL Key file.." + echo "" + echo "" + _ssl_key_file= + while [ "X$_ssl_key_file" = "X" ] ; do + if [ -z "$__ssl_key_file" ]; then + echononl "SSL Keyfile: " + read _ssl_key_file + if [ "X$_ssl_key_file" = "X" ]; then + echo -e "\n\t\033[33m\033[1mEingabe erforderlich!\033[m\n" + continue + fi + else + echononl "SSL Keyfile [$__ssl_key_file]:" + read _ssl_key_file + if [ "X$_ssl_key_file" = "X" ]; then + _ssl_key_file=$__ssl_key_file + fi + fi + done + + echo "" + echo "" + echo -e "\033[1;32m--\033[m" + echo "" + echo -e "Input SSL Certification file.." + echo "" + echo "" + _ssl_cert_file= + while [ "X$_ssl_cert_file" = "X" ] ; do + if [ -z "$__ssl_cert_file" ]; then + echononl "SSL certification file: " + read _ssl_cert_file + if [ "X$_ssl_cert_file" = "X" ]; then + echo -e "\n\t\033[33m\033[1mEingabe erforderlich!\033[m\n" + continue + fi + else + echononl "SSL certification file [$__ssl_cert_file]:" + read _ssl_cert_file + if [ "X$_ssl_cert_file" = "X" ]; then + _ssl_cert_file=$__ssl_cert_file + fi + fi + done + + + echo "" + echo "" + echo -e "\033[1;32m--\033[m" + echo "" + echo -e "Input SSL Certification Chain file.." + echo "" + echo "" + _ssl_chain_file= + if ! $_ommit_ssl_chain_file ; then + #while [ "X$_ssl_chain_file" = "X" ] ; do + if [ -z "$__ssl_chain_file" ]; then + echononl "SSL Certification Chain file: " + read _ssl_chain_file + if [ "X$_ssl_chain_file" = "X" ]; then + warn "No SSL Certification Chain file given. \"SSLCertificateChainFile\" Directive will be omitted!" + fi + else + echononl "SSL Certification Chain file [$__ssl_chain_file]: " + read _ssl_chain_file + if [ "X$_ssl_chain_file" = "X" ]; then + _ssl_chain_file=$__ssl_chain_file + fi + fi + #done + fi + + fi + + +else + _config_file_found=true + info "Found configuration file \"`basename $_existing_vhost_config_file`\".\n" + echo -e -n "\tReading configurations from that file.." + + _vhost_base_dir=`dirname $_existing_vhost_config_file` + + declare -i number_errors=0 + declare -i number_warnings=0 + + _server_name="" + _server_name_failed=false + + ## - Create empty array + ## - + _server_aliases_arr=() + _server_alias="" + + _doc_root="" + #_new_doc_root="" + _doc_root_failed=false + + _combined_custom_log="" + _combined_custom_log_failed=false + + _custom_ipv4_log="" + _custom_ipv4_log_failed=false + + _custom_ipv6_log="" + _custom_ipv6_log_failed=false + + _error_log="" + _error_log_failed=false + + _https=false + _ssl_cert_file="" + _ssl_key_file="" + _ssl_chain_file="" + + + while read line ; do + + ## - Get ServerName + ## - + if echo $line | grep -e "^\s*ServerName" > /dev/null ; then + _server_name_tmp=`echo $line | awk '{print$2}'` + if [ -z "$_server_name" ]; then + _server_name=$_server_name_tmp + elif [ "$_server_name" != "$_server_name_tmp" ]; then + if [ $number_errors -eq 0 ]; then + echo + fi + error "Misconfigured ServerName" + _server_name_failed=true + let number_errors++ + fi + continue + fi + + + ## - Get ServerAlias + if echo $line | grep -e "^\s*ServerAlias" > /dev/null ; then + _server_alias_tmp=$(echo $line | sed -e "s/ServerAlias//" | sed "s/^\s*//" | sed "s/\s*$//") + #_server_alias_tmp=`echo $line | awk '{print$2}'` + if [ ${#_server_aliases_arr[@]} -eq 0 ] ; then + for _alias in $_server_alias_tmp ; do + _server_aliases_arr+=("$_alias") + done + else + for _alias in $_server_alias_tmp ; do + containsElement "$_alias" "${_server_aliases_arr[@]}" && continue + _server_aliases_arr+=("$_alias") + done + fi + continue + fi + + + ## - Get DocumentRoot + ## - + if echo $line | grep -e "^\s*DocumentRoot" > /dev/null ; then + _doc_root_tmp=`echo $line | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//'` + if [ -z "$_doc_root" ]; then + _doc_root=$_doc_root_tmp + elif [ "$_doc_root" != "$_doc_root_tmp" ]; then + if [ $number_errors -eq 0 ]; then + echo + fi + error "Misconfigured DocumentRoot" + _doc_root_failed=true + let number_errors++ + fi + continue + fi + + ## - Get CustomLog (combined) + ## - + if echo $line | grep -e "^\s*CustomLog" | grep "combined"> /dev/null ; then + _combined_custom_log_tmp=`echo $line | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//'` + if [ -z "$_combined_custom_log" ]; then + _combined_custom_log=$_combined_custom_log_tmp + elif [ "$_combined_custom_log" != "$_combined_custom_log_tmp" ]; then + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "Misconfigured CustomLog (combined)" + _combined_custom_log_failed=true + let number_warnings++ + fi + continue + fi + + ## - Get additional CustomLog IPv4 requests + ## - + if echo $line | grep -e "^\s*CustomLog" | grep -i "ipv4" > /dev/null ; then + _custom_ipv4_log_tmp=`echo $line | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//'` + if [ -n "$_custom_ipv4_log_tmp" ];then + if [ -z "$_custom_ipv4_log" ]; then + _custom_ipv4_log=$_custom_ipv4_log_tmp + elif [ "$_custom_ipv4_log" != "$_custom_ipv4_log_tmp" ]; then + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "Misconfigured CustomLog IPv4 requests" + _custom_ipv4_log_failed=true + let number_warnings++ + fi + fi + continue + fi + + ## - Get additional CustomLog IPv6 requests + ## - + if echo $line | grep -e "^\s*CustomLog" | grep -i "ipv6" > /dev/null ; then + _custom_ipv6_log_tmp=`echo $line | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//'` + if [ -n "$_custom_ipv6_log_tmp" ];then + if [ -z "$_custom_ipv6_log" ]; then + _custom_ipv6_log=$_custom_ipv6_log_tmp + elif [ "$_custom_ipv6_log" != "$_custom_ipv6_log_tmp" ]; then + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "Misconfigured CustomLog IPv6 requests" + _custom_ipv6_log_failed=true + let number_warnings++ + fi + fi + continue + fi + + ## - Get ErrorLog + ## - + if echo $line | grep -e "^\s*ErrorLog" > /dev/null ; then + _error_log_tmp=`echo $line | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//'` + if [ -z "$_error_log" ]; then + _error_log=$_error_log_tmp + elif [ "$_error_log" != "$_error_log_tmp" ]; then + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "Misconfigured ErrorLog" + _error_log_failed=true + let number_warnings++ + fi + continue + fi + + ## - HTTPS ? + ## - + if echo $line | grep -e "^\s*SSLEngine" > /dev/null ; then + _https=true + continue + fi + + ## - GET SSLCertificateFile + ## - + if echo $line | grep -e "^\s*SSLCertificateFile" > /dev/null ; then + _ssl_cert_file=`echo $line | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//'` + continue + fi + + ## - GET SSLCertificateKeyFile + ## - + if echo $line | grep -e "^\s*SSLCertificateKeyFile" > /dev/null ; then + _ssl_key_file=`echo $line | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//'` + continue + fi + + ## - GET SSLCertificateChainFile + ## - + if echo $line | grep -e "^\s*SSLCertificateChainFile" > /dev/null ; then + _ssl_chain_file=`echo $line | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//'` + continue + fi + + ## - Get IPv4 Address + ## - + if echo $line | grep -e "\s* /dev/null 2>&1 ; then + _ipv4=`echo $line | awk '{print$2}' | cut -d ':' -f 1` + continue + fi + + ## - Get IPv6 Address + ## - + if echo $line | grep -e "\s* /dev/null 2>&1 ; then + _ipv6=`echo $line | awk '{print$2}' | cut -d ']' -f 1 | cut -d '[' -f 2 ` + continue + fi + + done < $_existing_vhost_config_file + + + if ! $_server_name_failed ; then + if [ -z "$_server_name" ] ; then + if [ $number_errors -eq 0 ]; then + echo + fi + error "No ServerName found" + let number_errors++ + #else + # echo -e "\tServerName = $_server_name" + fi + fi + + #if [ ${#_server_aliases_arr[@]} -gt 0 ] ; then + # echo -e "\tServerAlias = ${_server_aliases_arr[@]}" + #fi + + if ! $_doc_root_failed ; then + if [ -z "$_doc_root" ]; then + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "No DocumentRoot found" + let number_warnings++ + else + _web_base_dir=`dirname $_doc_root` + #echo -e "\tDocumentRoot = $_doc_root" + if [ "`basename $_web_base_dir`" = "htdocs" ]; then + _web_base_dir=`dirname $_web_base_dir` + fi + fi + fi + + if ! $_combined_custom_log_failed ; then + _combined_custom_log_dir="`dirname $_combined_custom_log`" + fi + + if ! $_error_log_failed ; then + _error_log_dir="`dirname $_error_log`" + fi + + if [ "$_error_log_dir" != "$_combined_custom_log_dir" ]; then + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "CustomLog and ErrorLog lives in different directories" + let number_warnings++ + else + _log_dir="$_combined_custom_log_dir" + fi + + #if [ -n "$_web_base_dir" ];then + # echo -e "\tWeb base dir = $_web_base_dir" + # echo "" + #fi + + if [ -z "$_ipv4" ];then + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "Keine IPv4 Adresse gefunden." + let number_warnings++ + #else + # echo -e "\tIPv4 = $_ipv4" + fi + + if [ -z "$_ipv6" ];then + _ipv6="disabled" + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "Keine IPv6 Adresse gefunden." + let number_warnings++ + #else + # echo -e "\tIPv6 = $_ipv6" + # echo "" + fi + + if $_https ; then + #echo -e "\tHTTPS = $_https" + if [ -z "$_ssl_cert_file" ]; then + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "No SSLCertificateFile found, but https is on!" + let number_warnings++ + #else + # echo -e "\tSSLCertificateFile = $_ssl_cert_file" + fi + if [ -z "$_ssl_key_file" ]; then + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "No SSLCertificateKeyFile found, but https is on!" + let number_warnings++ + #else + # echo -e "\tSSLCertificateKeyFile = $_ssl_key_file" + fi + if [ -z "$_ssl_chain_file" ]; then + if [ $number_warnings -eq 0 ]; then + echo + fi + warn "No SSLCertificateChainFile found, but https is on!" + let number_warnings++ + #else + # echo -e "\tSSLCertificateChainFile = $_ssl_chain_file" + fi + fi + + if [ $number_warnings -eq 0 -a $number_errors -eq 0 ]; then + + echo_ok + + else + + if [ $number_errors -gt 0 ]; then + #echo_failed + error "$number_warnings Warnings - $number_errors Errors" + fatal + else + info "Reading Parameters finisched with $number_warnings Warnings" + fi + fi + +fi + +if [ "$_type" = "FCGID" ]; then + + echo "" + echo "" + echo -e "\033[33m--\033[m" + echo"" + #echo -e "Use a common (existing) FCGID-configuration?" + #echo "" + #echo -e "\033[1;33m--\033[m" + #echo "" + #echo "" + OK="" + if $_suEXEC ; then + echononl "suEXEC User: " + read suEXEC_user + while [ "X$suEXEC_user" = "X" ]; do + echononl "suEXEC User is mandatory. Try again: " + read suEXEC_user + done + echononl "suEXEC Group [$suEXEC_user]: " + read suEXEC_group + if [ "X$suEXEC_group" = "X" ]; then + suEXEC_group=$suEXEC_user + fi + getent shadow $suEXEC_user > /dev/null + if [ "$?" != "0" ]; then + _suEXEC_passwd_1="X" + _suEXEC_passwd_2="Y" + while [ "$_suEXEC_passwd_1" != "$_suEXEC_passwd_2" ]; do + echononl "Password for User \"$suEXEC_user\": " + read -s _suEXEC_passwd_1 + echo + if [ "X$_suEXEC_passwd_1" = "X" ]; then + echo -e "\n\t\033[33m\033[1mPassword is mandatory!\033[m\n" + continue + fi + echononl "Repeat password for User \"$suEXEC_user\": " + read -s _suEXEC_passwd_2 + echo + if [ "X$_suEXEC_passwd_2" = "X" ]; then + echo -e "\n\t\033[33m\033[1mPasswordretry is mandatory!\033[m\n" + continue + fi + if [ "$_suEXEC_passwd_1" != "$_suEXEC_passwd_2" ]; then + echo -e "\n\t\033[33m\033[1mSorry, passwords do not match\033[m\n" + else + suEXEC_password=$_suEXEC_passwd_1 + fi + done + set_suEXEC_password=true + else + suEXEC_password=false + fi + _COMMON_FCGI_CONFIG=false + else + if [ -n "$_COMMON_FCGID_CONFIG_PATH" -a -d "$_COMMON_FCGID_CONFIG_PATH" ] ; then + if [ "$_auto" = "auto" -o "$_auto" = "full-auto" ]; then + _COMMON_FCGI_CONFIG=true + else + echononl "Use a common (existing) FCGID-configuration? [yes]: " + read OK + while [ "X$OK" != "Xyes" -a "X$OK" != "XYes" -a "X$OK" != "Xno" -a "X$OK" != "XNo" -a "X$OK" != "X" ]; do + echononl "falsche Angabe! [yes/no]: " + read OK + done + if [ "$OK" = "yes" -o "$OK" = "Yes" -o "X$OK" = "X" ]; then + _COMMON_FCGI_CONFIG=true + else + _COMMON_FCGI_CONFIG=false + FCGI_Wrapper="${_web_base_dir}/conf/fcgid .php" + fi + fi + else + echononl "Use a common (existing) FCGID-configuration? [no]: " + read OK + while [ "X$OK" != "Xyes" -a "X$OK" != "XYes" -a "X$OK" != "Xno" -a "X$OK" != "XNo" -a "X$OK" != "X" ]; do + echononl "falsche Angabe! [yes/no]: " + read OK + done + if [ "$OK" = "yes" -o "$OK" = "Yes" ]; then + _COMMON_FCGI_CONFIG=true + else + _COMMON_FCGI_CONFIG=false + FCGI_Wrapper="${_web_base_dir}/conf/fcgid .php" + fi + + fi + fi + echo + + if $_COMMON_FCGI_CONFIG ; then + + if [ -n "$_COMMON_FCGID_CONFIG_PATH" -a -d "$_COMMON_FCGID_CONFIG_PATH" -a "$_auto" = "auto" ]; then + common_fcgi_config_path=$_COMMON_FCGID_CONFIG_PATH + else + + common_fcgi_config_path= + if [ -n "$_COMMON_FCGID_CONFIG_PATH" -a -d "$_COMMON_FCGID_CONFIG_PATH" ] ; then + while [ "X$common_fcgi_config_path" = "X" ] ; do + echononl "Path to common FCGIG configuration [$_COMMON_FCGID_CONFIG_PATH]: " + read common_fcgi_config_path + if [ "X$common_fcgi_config_path" = "X" ]; then + common_fcgi_config_path=$_COMMON_FCGID_CONFIG_PATH + fi + done + else + while [ "X$common_fcgi_config_path" = "X" ] ; do + echononl "Path to common FCGIG configuration: " + read common_fcgi_config_path + if [ -n "$common_fcgi_config_path" -a ! -d "$common_fcgi_config_path" ] ; then + echo -e "\n\t\033[1;33mDiectory \"common_fcgi_config_path\" not found! Try again..\033[m\n" + fi + done + fi + fi + + FCGI_Wrapper="${common_fcgi_config_path}/conf/fcgid .php" + + fi +fi + + +if [ "$_type" != "MOD_PHP" ]; then + + #if ! $_config_file_found ; then + # clear + #fi + echo "" + #echo -e "\033[21G\033[32mCreate vhost configuration \"${_DOMAIN}.${_TDL}.conf.$_new_extension\"\033[m" + echo -e "\033[21G\033[32mCreate vhost configuration \033[m\"`basename $_new_vhost_config_file`\"" + echo "" + if [ "$_type" = "FCGID" -a "$_COMMON_FCGI_CONFIG" = "true" ] ; then + echo -e "\033[21G\033[32mUsing FCGID configuration defined in \033[m\"$common_fcgi_config_path\"" + #sleep 2 + else + + if [ "X$major_php_verison" = "X" ]; then + echo -e "\033[21GInsert Parameters needed for PHP Configuration.." + + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Input PHP major version to use for $site_url (${_major_php_verisons})" + echo "" + echo "" + major_php_verisons= + while [ "X$major_php_verison" = "X" ] ; do + echononl "PHP major version: " + read major_php_verison + if [ "X$major_php_verison" = "X" ]; then + echo -e "\n\t\033[33m\033[1mEingabe erforderlich!\033[m\n" + continue + fi + #if [ ! -d "/usr/local/php-$major_php_verison" -o ! -h "/usr/local/php-$major_php_verison" ];then + if [ ! -d "/usr/local/php-$major_php_verison" ];then + echo -e "\n\t\033[1;33mNo installation for PHP v$major_php_verison found! Try again..\033[m\n" + major_php_verison="" + fi + done + else + echo -e "\033[21G\033[32mUsing PHP Veriosnn \033[m\"$major_php_verison\"" + fi + + if $_suEXEC ; then + FCGI_Wrapper="${_web_base_dir}/conf/fcgid-${major_php_verison} .php" + fi + + fi +else + echo -e "\033[21G\033[32mUsing PHP Version from mod_php at Apache Installation" +fi + +if [ "$_type" = "PHP-FPM" ]; then + + if [ "$connection" != "unix_socket" -a "$connection" != "tcp_connection" ]; then + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Use unix socket or tcp for connection to PHP-FPM ?" + echo "" + echo "[1] Unix Socket" + echo "[2] TCP Conection" + echo "" + echononl "Your choice: " + while [ "$connection" != "unix_socket" -a "$connection" != "tcp_connection" ];do + read OPTION + case $OPTION in + 1) connection="unix_socket" + _connection_msg="Unix Socket" + ;; + 2) connection="tcp_connection" + _connection_msg="TCP Conection" + ;; + *) echo "" + echo -e "\t\033[1;33mFalsche Eingabe ! [ 1 = Unix Socket ; 2 = TCP Conection ]\033[m" + echo "" + echononl "Your choice: " + ;; + esac + done + fi + + if [ "$connection" == "unix_socket" ]; then + + if [ "X$unix_socket" = "X" ] ; then + _unix_socket=`ls /tmp/php-${major_php_verison}*.sock 2>/dev/null` + + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "" + echo "Where to find the unix php-fpm socket.." + echo "" + echo "" + unix_socket= + while [ "X$unix_socket" = "X" ] ; do + echononl "Unix PHP-FPM socket [$_unix_socket]: " + read unix_socket + if [ "X$unix_socket" = "X" ]; then + unix_socket=$_unix_socket + fi + if [ ! -S "$unix_socket" ]; then + echo -e "\n\t\033[1;33mNo Unix Socket found at \"unix_socket\"! Try again..\033[m\n" + unix_socket="" + fi + done + else + echo -e "\033[21G\033[32mUsing Unix Socket \033[m\"$unix_socket\"" + fi + tcp_host=127.0.0.1 + tcp_port=9000 + _proxy_match="^/(.*\.php(/.*)?)\$ unix:$_unix_socket|fcgi://$tcp_host:$tcp_port$_doc_root" + _set_handler_fpm="\"proxy:unix:$_unix_socket|fcgi://$tcp_host\"" + else + echo "" + echo "" + echo "Insert TCP Host and TCP Port for connection to PHP-FPM.." + echo "" + echo "" + tcp_host= + while [ "X$tcp_host" = "X" ] ; do + echononl "TCP Host [$_tcp_host]: " + read tcp_host + if [ "X$tcp_host" = "X" ]; then + tcp_host=$_tcp_host + fi + done + + echo "" + tcp_port= + while [ "X$tcp_port" = "X" ] ; do + echononl "TCP port [$_tcp_port]: " + read tcp_port + if [ "X$tcp_port" = "X" ]; then + tcp_port=$_tcp_port + fi + done + _proxy_match="^/(.*\.php(/.*)?)\$ fcgi://$tcp_host:$tcp_port$_doc_root/\$1" + _set_handler_fpm="\"proxy:fcgi://$tcp_host:$tcp_port\"" + + fi +fi + + +#clear +if $_print_summary ; then + echo "" + echo "" + echo -e "\033[21G\033[32mCreate environment for site \033[m$site_url\033[32m :\033[m" + echo "" + + echo "" + echo -e "PHP environment...................: \033[33m\033[1m${_type_msg}\033[m" + if [ "$_type" = "FCGID" ]; then + if [ "$_type" = "FCGID" -a "$_COMMON_FCGI_CONFIG" = "true" ]; then + echo -e "PHP major version.................: Using from common FCGID configuration" + echo " Common FCGID config directory..: $common_fcgi_config_path" + else + echo -e "PHP major version.................: \033[33m\033[1m$major_php_verison\033[m" + fi + echo " FCGIWrapper Entry..............: $FCGI_Wrapper" + fi + if [ "$_type" = "PHP-FPM" ]; then + + echo -e "PHP major version.................: \033[33m\033[1m$major_php_verison\033[m" + + if [ "$connection" = "unix_socket" ]; then + echo " PHP-FPM using Unix Socket......: $unix_socket" + else + echo " PHP-FPM using TCP Connection...: ${tcp_host}:$tcp_port" + fi + echo " ProxyPassMatch Directive.......: $_proxy_match" + fi + if [ "$_type" = "MOD_PHP" ]; then + echo -e "PHP major version.................: PHP Version from mod_php at Apache Installation" + fi + if $_suEXEC ; then + echo " suEXEC User....................: $suEXEC_user" + echo " suEXEC Group...................: $suEXEC_group" + fi + + echo "" + echo "Apache Installationsverzeichnis...: $apache_base_dir ($_apache_base_dir_realpath)" + echo "Apache User.......................: $web_user" + echo "Apache Group......................: $web_group" + echo "" + echo "IPv4 Address......................: $_ipv4" + echo "IPv6 Address......................: $_ipv6" + echo "" + echo "Listen also for HTTPS connections.: $_https" + if $_https ; then + echo " SSL Key File...................: $_ssl_key_file" + echo " SSL Certificate File...........: $_ssl_cert_file" + if [ -n "$_ssl_chain_file" ]; then + echo " SSL Certificate Chain File.....: $_ssl_chain_file" + else + echo -e " SSL Certificate Chain File.....: [ \033[33m\033[1mNot given!\033[m ]: \"SSLCertificateChainFile\" Directive will be omitted!" + fi + fi + echo "" + echo "Site URL..........................: $site_url" + echo "" + echo "ServerName........................: $_server_name" + echo "ServerAlias(es)...................: ${_server_aliases_arr[@]}" + echo "" + echo "Base Directory for site...........: $_web_base_dir" + if $_create_symlink_web_base_dir ; then + echo "Symlink for Base Directory........: `dirname $_web_base_dir`/$_symlink_web_base_dir" + fi + echo "Document Root Directory...........: $_doc_root" + echo "" + echo "Logfile Directory.................: $_log_dir" + echo " CustomLog......................: $_combined_custom_log" + echo " ErrorLog.......................: $_error_log" + if [ -n "$_custom_ipv4_log" ]; then + echo " Additional Logfile IPv4........: $_custom_ipv4_log" + fi + if [ -n "$_custom_ipv6_log" ]; then + echo " Additional Logfile IPv6........: $_custom_ipv6_log" + fi + echo "" + echo "VHost Base Directory..............: $_vhost_base_dir" + echo "VHost configuration file..........: $_new_vhost_config_file" + echo "" + echo "" + + echo "" + echononl "Parameters ok? [yes/no]: " + read OK + while [ "X$OK" != "Xyes" -a "X$OK" != "XYes" -a "X$OK" != "Xno" -a "X$OK" != "XNo" ] + do + echononl "Wrong entry! [yes/no]: " + read OK + done + [ $OK = "yes" -o $OK = "Yes" ] || fatal Repeat installation with different parameters +fi + + +if $_suEXEC ; then + echo + echo -e "\t---" + echo -e "\t--- Create suEXEC Environment.." + echo -e "\t---" + echo"" + getent passwd $suEXEC_user > /dev/null + if [ "$?" = "0" ]; then + echononl "\tUser/Group for suEXEC already exists.." + echo_skipped + _suEXEC_group=`id -gn $suEXEC_user` + if [ "$_suEXEC_group" != "$suEXEC_group" ]; then + warn "Changing suEXEC Group to \"$_suEXEC_group\"" + suEXEC_group=$_suEXEC_group + fi + else + #if [ "$suEXEC_user" != "$suEXEC_group" ]; then + echononl "\tAdding Group \"$suEXEC_group\".." + getent group $suEXEC_group > /dev/null + if [ "$?" = "0" ]; then + echo_skipped + else + groupadd $suEXEC_group + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot create Group \"$suEXEC_group\"." + fatal + fi + fi + #fi + echononl "\tAdding User \"$suEXEC_user\".." + useradd -g $suEXEC_group -d $_web_base_dir -s /bin/bash -m $suEXEC_user + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot create User \"$suEXEC_user\"." + fatal + fi + fi + echononl "\tSetting Password for user \"$suEXEC_user\".." + if $set_suEXEC_password ; then + echo "${suEXEC_user}:$suEXEC_password" | chpasswd + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fi + else + echo_skipped + fi +fi + + + + +## - Create needed directories +## - +echo +echo -e "\t---" +echo -e "\t--- Create needed Directories" +echo -e "\t---" +echo"" + +#echo "" +#echo "`dirname $_web_base_dir`/$_symlink_web_base_dir" +#echo "" + +if [[ "X${_symlink_web_base_dir}" != "X" ]]; then + + if [ -d "`dirname $_web_base_dir`/$_symlink_web_base_dir" ]; then + echo -e "\tMove `dirname $_web_base_dir`/$_symlink_web_base_dir to" + echononl "\t $(dirname $_web_base_dir)/${_symlink_web_base_dir}.`date +%Y%m%d-%H%M`" + mv `dirname $_web_base_dir`/$_symlink_web_base_dir \ + `dirname $_web_base_dir}`/${_symlink_web_base_dir}.`date +%Y%m%d-%H%M` + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot backup directory $(dirname $_web_base_dir)/${_symlink_web_base_dir}!" + fi + elif [ -f "`dirname $_web_base_dir`/$_symlink_web_base_dir" ]; then + echononl "\tBackup existing file `dirname $_web_base_dir`/$_symlink_web_base_dir" + mv $(dirname $_web_base_dir)/$_symlink_web_base_dir \ + $(dirname $_web_base_dir)/$_symlink_web_base_dir.$(date +%Y%m%d-%H%M) + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot backup file `dirname $_web_base_dir`/`basename $_web_base_dir`!" + fi + fi +fi + +echononl "\tCreate Web Base directory \"$_web_base_dir\".." +if [ ! -d "$_web_base_dir" ]; then + mkdir $_web_base_dir + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot create web base directory \"$_web_base_dir\"." + fatal + fi +else + echo_skipped +fi + + +echononl "\tCreate \"DocumentRoot\" directory.." +if [ ! -d "$_doc_root" ]; then + + mkdir $_doc_root + if [ "$?" = "0" ]; then + echo_ok + + else + echo_failed + error "Cannot create document root directory \"$_doc_root\"." + fatal + fi +else + echo_skipped +fi + +if $_create_symlink_web_base_dir ; then + echononl "\tCreate Symlink $_symlink_web_base_dir --> `basename $_web_base_dir`" + if [ -h "`dirname $_web_base_dir`/$_symlink_web_base_dir" ]; then + echo_skipped + elif [ -d "`dirname $_web_base_dir`/$_symlink_web_base_dir" ]; then + cp -a `dirname $_web_base_dir`/$_symlink_web_base_dir/* + `dirname $_web_base_dir`/$_symlink_web_base_dir.`date +%Y%m%d-%H%M` + else + ln -s `basename $_web_base_dir` `dirname $_web_base_dir`/$_symlink_web_base_dir + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot create Symlink $_symlink_web_base_dir -> `basename $_web_base_dir`." + fi + fi +fi + + +echononl "\tChange owner of \"DocumentRoot\" directory.." +if $_suEXEC ; then + chown -R ${suEXEC_user}:$suEXEC_group $_doc_root +else + chown -R ${web_user}:${web_group} $_doc_root +fi +if [ "$?" = "0" ]; then + echo_ok +else + echo_failed + error "Cannot change owner of directory \"$_doc_root\"" + fatal +fi + +echononl "\tCreate Logfile directory.." +if [ ! -d "$_log_dir" ]; then + mkdir $_log_dir + if [ "$?" = "0" ]; then + echo_ok + + #echononl "\tChange owner for Logfile directory.." + #chown -R ${web_user}:${web_group} $_log_dir + #if [ "$?" = "0" ]; then + # echo_ok + #else + # echo_failed + # error "Cannot change owner for directory \"$_log_dir\"" + # fatal + #fi + + else + echo_failed + error "Cannot create logfile directory \"$_log_dir\"." + fatal + fi +else + echo_skipped +fi + + +if [ "$_type" = "FCGID" -a "$_COMMON_FCGI_CONFIG" = "false" ]; then + + echononl "\tCreate fcgid configuration directory.." + if [ ! -d "${_web_base_dir}/conf" ]; then + mkdir ${_web_base_dir}/conf + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot create fcgid configuration directory \"${_web_base_dir}/conf\"." + fatal + fi + else + echo_skipped + fi + + echononl "\tChange owner of Configuration directory.." + if $_suEXEC ; then + chown -R ${suEXEC_user}:$suEXEC_group ${_web_base_dir}/conf + else + chown -R root:${web_group} ${_web_base_dir}/conf + fi + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot change owner of directory \"${_web_base_dir}/conf\"" + fatal + fi + + #if $_suEXEC ; then + # echononl "\tChange owner of Configuration directory.." + # chown -R ${suEXEC_user}:$suEXEC_group ${_web_base_dir}/conf + # if [ "$?" = "0" ]; then + # echo_ok + # else + # echo_failed + # error "Cannot change owner of directory \"${_web_base_dir}/conf\"" + # fatal + # fi + #fi + + echononl "\tCreate Session directory.." + if [ ! -d "${_web_base_dir}/sessions" ]; then + mkdir ${_web_base_dir}/sessions + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot create session directory \"${_web_base_dir}/sessions\"." + fatal + fi + else + echo_skipped + fi + + echononl "\tChange owner of Session directory.." + if $_suEXEC ; then + chown -R ${suEXEC_user}:$suEXEC_group ${_web_base_dir}/sessions + else + chown -R ${web_user}:${web_group} ${_web_base_dir}/sessions + fi + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot change owner of directory \"${_web_base_dir}/sessions\"" + fatal + fi + + echononl "\tCreate TMP directory.." + if [ ! -d "${_web_base_dir}/tmp" ]; then + mkdir ${_web_base_dir}/tmp + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot create tmp directory \"${_web_base_dir}/tmp\"." + fatal + fi + else + echo_skipped + fi + + echononl "\tChange owner of TMP directory.." + if $_suEXEC ; then + chown -R ${suEXEC_user}:$suEXEC_group ${_web_base_dir}/tmp + else + chown -R ${web_user}:${web_group} ${_web_base_dir}/tmp + fi + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot change owner of directory \"${_web_base_dir}/tmp\"" + fatal + fi + + + ## - Create FCGID-Environment + ## - + echo + echo + echo -e "\t---" + echo -e "\t--- Create \"$_type\"-Environment" + echo -e "\t---" + echo"" + + echononl "\tChange into \"fcgid\" configuration directory.." + cd ${_web_base_dir}/conf + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Cannot change into directory \"${_web_base_dir}/conf\"" + fatal + fi + + + _php_version_link= + for _php_version in $_major_php_verisons ; do + if [ -d /usr/local/php-$_php_version ]; then + if [ -f /usr/local/php-${_php_version}/etc/php.ini ]; then + + _php_ini_file=${_web_base_dir}/conf/php.ini-$_php_version + + if [ -f "$_php_ini_file" ]; then + echononl "\tSichere existierende Konfiguration" + mv $_php_ini_file ${_php_ini_file}.`date +%Y%m%d-%H%M` + if [ "$?" = 0 ]; then + echo_ok + else + echo_failed + error "Kann bestehende Konfigurationsdatei \"$_new_vhost_config_file.\" nicht sichern!" + fatal + fi + fi + + ## - Adjust php.ini-$_php_version + ## - + cp /usr/local/php-${_php_version}/etc/php.ini $_php_ini_file + chmod 640 $_php_ini_file + if $_suEXEC ; then + chown root:$suEXEC_group $_php_ini_file + else + chown root:$web_group $_php_ini_file + fi + + ## - Set error_log = ${_web_base_dir}/logs/php_errors.log + ## - + _key="error_log" + _val="${_web_base_dir}/logs/php_errors.log" + echononl "\tphp.ini-$_php_version: $_val = $_key" + _retval="" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + #sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file + _retval=$? + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file + _retval=$? + fi + if [ -z "$_retval" ]; then + echo_skipped + elif [ "$_retval" = "0" ]; then + echo_ok + else + echo_failed + fi + + touch $_val + if $_suEXEC ; then + chown -R ${suEXEC_user}:$suEXEC_group $_val + else + chown -R ${web_user}:${web_group} $_val + fi + + ## - Set sys_temp_dir = ${_web_base_dir}/tmp + ## - + _key="sys_temp_dir" + _val="${_web_base_dir}/tmp" + echononl "\tphp.ini-$_php_version: $_val = $_key" + _retval="" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file + _retval=$? + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file + _retval=$? + fi + if [ -z "$_retval" ]; then + echo_skipped + elif [ "$_retval" = "0" ]; then + echo_ok + else + echo_failed + fi + + ## - Set upload_tmp_dir = ${_web_base_dir}/tmp + ## - + _key="upload_tmp_dir" + _val="${_web_base_dir}/tmp" + echononl "\tphp.ini-$_php_version: $_val = $_key" + _retval="" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file + _retval=$? + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file + _retval=$? + fi + if [ -z "$_retval" ]; then + echo_skipped + elif [ "$_retval" = "0" ]; then + echo_ok + else + echo_failed + fi + + ## - Set session.save_path = ${_web_base_dir}/sessions + ## - + _key="session.save_path" + _val="${_web_base_dir}/sessions" + echononl "\tphp.ini-$_php_version: $_val = $_key" + _retval="" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file + _retval=$? + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file + _retval=$? + fi + if [ -z "$_retval" ]; then + echo_skipped + elif [ "$_retval" = "0" ]; then + echo_ok + else + echo_failed + fi + + ## - Set soap.wsdl_cache_dir = ${_web_base_dir}/tmp + ## - + _key="soap.wsdl_cache_dir" + _val="${_web_base_dir}/tmp" + echononl "\tphp.ini-$_php_version: $_val = $_key" + _retval="" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file + _retval=$? + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file + _retval=$? + fi + if [ -z "$_retval" ]; then + echo_skipped + elif [ "$_retval" = "0" ]; then + echo_ok + else + echo_failed + fi + + ## - Set opcache.error_log = ${_web_base_dir}/logs/opcache_errors.log + ## - + _key="opcache.error_log" + _val="${_web_base_dir}/logs/opcache_errors.log" + echononl "\tphp.ini-$_php_version: $_val = $_key" + _retval="" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + #sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file + _retval=$? + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file + _retval=$? + fi + if [ -z "$_retval" ]; then + echo_skipped + elif [ "$_retval" = "0" ]; then + echo_ok + else + echo_failed + fi + + touch $_val + if $_suEXEC ; then + chown -R ${suEXEC_user}:$suEXEC_group $_val + else + chown -R ${web_user}:${web_group} $_val + fi + + if [ -f "${_web_base_dir}/conf/fcgid-${_php_version}" ]; then + echononl "\tSichere existierende Scriptdatei .." + mv ${_web_base_dir}/conf/fcgid-${_php_version} \ + ${_web_base_dir}/conf/fcgid-${_php_version}.`date +%Y%m%d-%H%M` + if [ "$?" = 0 ]; then + echo_ok + else + echo_failed + error "Kann bestehende Scriptdate \"${_web_base_dir}/conf/fcgid-${_php_version}\" nicht sichern!" + fatal + fi + fi + + ## - Create fcgid-$_php_version + ## - + echononl "\tCreate ${_web_base_dir}/conf/fcgid-${_php_version}.." + cat < ${_web_base_dir}/conf/fcgid-$_php_version +#!/bin/sh + +export PHPRC="${_web_base_dir}/conf/" +export TMPDIR="${_web_base_dir}/tmp" + +# PHP child process management (PHP_FCGI_CHILDREN) should +# always be disabled with mod_fcgid, which will only route one +# request at a time to application processes it has spawned; +# thus, any child processes created by PHP will not be used +# effectively. (Additionally, the PHP child processes may not +# be terminated properly.) By default, and with the environment +# variable setting PHP_FCGI_CHILDREN=0, PHP child process +# management is disabled. +PHP_FCGI_CHILDREN=0 +export PHP_FCGI_CHILDREN + +exec /usr/local/php-${_php_version}/bin/php-cgi +EOF + if [ "$?" = 0 ]; then + echo_ok + else + echo_failed + error "Kann \"${_web_base_dir}/conf/fcgid-${_php_version}\" nicht erstellen!" + fatal + fi + + echononl "\tÄndere Zugriffsrechte für \"fcgid-$_php_version\"" + chmod 750 ${_web_base_dir}/conf/fcgid-$_php_version + if [ "$?" = 0 ]; then + echo_ok + else + echo_failed + error "Kann Zugriffsrechte für \"fcgid-${_php_version}\" nicht ändern!" + fatal + fi + + echononl "\tBesitzer von \"fcgid-$_php_version\".." + if $_suEXEC ; then + chown ${suEXEC_user}:$suEXEC_group $_val ${_web_base_dir}/conf/fcgid-$_php_version + else + chown root:$web_group ${_web_base_dir}/conf/fcgid-$_php_version + fi + chmod 750 ${_web_base_dir}/conf/fcgid-$_php_version + if [ "$?" = 0 ]; then + echo_ok + else + echo_failed + error "Kann Besitzer für \"fcgid-${_php_version}\" nicht wechseln!" + fatal + fi + + _php_version_link=$_php_version + echo "" + + fi + fi + done + + echo "" + + if [ -h "${_web_base_dir}/conf/php.ini" ]; then + echononl "\tDelete symlink php.ini --> `basename $(realpath ${_web_base_dir}/conf/php.ini)`" + rm ${_web_base_dir}/conf/php.ini + if [ "$?" = 0 ]; then + echo_ok + else + echo_failed + error "Cannot delete symlink \"${_web_base_dir}/conf/php.ini\"" + fatal + fi + fi + + echononl "\tSetze Symlink php.ini --> php.ini-$major_php_verison" + ln -s php.ini-$major_php_verison ${_web_base_dir}/conf/php.ini + if [ "$?" = 0 ]; then + echo_ok + else + echo_failed + error "Kann Symlink \"php.ini --> php.ini-$major_php_verison\" nicht setzen!" + fatal + fi + + if [ -h "${_web_base_dir}/conf/fcgid" ]; then + echononl "\tDelete symlink fcgid --> `basename $(realpath ${_web_base_dir}/conf/fcgid)`" + rm ${_web_base_dir}/conf/fcgid + if [ "$?" = 0 ]; then + echo_ok + else + echo_failed + error "Cannot delete symlink \"${_web_base_dir}/conf/fcgid\"" + fatal + fi + fi + + echononl "\tSetze Symlink fcgid --> fcgid-$major_php_verison" + ln -s fcgid-$major_php_verison ${_web_base_dir}/conf/fcgid + if [ "$?" = 0 ]; then + echo_ok + else + echo_failed + error "Kann Symlink \"fcgid --> fcgid-$major_php_verison\" nicht setzen!" + fatal + fi + + cat < ${_web_base_dir}/conf/changes.php.ini.txt +error_log = "${_web_base_dir}/logs/php_errors.log" +sys_temp_dir = "${_web_base_dir}/tmp" +upload_tmp_dir = "${_web_base_dir}/tmp" +session.save_path = "${_web_base_dir}/sessions" +soap.wsdl_cache_dir = "${_web_base_dir}/tmp" +opcache.error_log = ${_web_base_dir}/logs/opcache_errors.log +EOF +fi + + +## - Create VHost Configuration +## - +echo +echo +echo -e "\t---" +echo -e "\t--- Create VHost Configuration" +echo -e "\t---" +echo"" + +_failed=false + +echononl "\tErstelle VHost Konfiguration \"`basename $_new_vhost_config_file`\".." +cat < ${_new_vhost_config_file} +# --- $site_url +EOF +if [ "$?" != "0" ]; then + _failed=true +fi +for _alias in "${_server_aliases_arr[@]}" ; do + cat <> ${_new_vhost_config_file} +# --- $_alias +EOF + if [ "$?" != "0" ]; then + _failed=true + fi +done +cat <> ${_new_vhost_config_file} + + + + ServerAdmin $server_admin + + ServerName $_server_name +EOF +if [ "$?" != "0" ]; then + _failed=true +fi +for _alias in "${_server_aliases_arr[@]}" ; do + cat <> ${_new_vhost_config_file} + ServerAlias $_alias +EOF + if [ "$?" != "0" ]; then + _failed=true + fi +done + +if $_suEXEC ; then + cat <> ${_new_vhost_config_file} + + SuexecUserGroup $suEXEC_user $suEXEC_group +EOF +fi + +if [ "$_type" = "FCGID" ]; then + cat <> ${_new_vhost_config_file} + + DocumentRoot $_doc_root + + + Require all granted + AllowOverride All + FCGIWrapper $FCGI_Wrapper + + SetHandler fcgid-script + + Options +ExecCGI + +EOF +elif [ "$_type" = "PHP-FPM" ]; then + cat <> ${_new_vhost_config_file} + + #ProxyErrorOverride On + + + SetHandler $_set_handler_fpm + + + + DirectoryIndex index.php index.html index.htm + + + DocumentRoot $_doc_root + + Require all granted + AllowOverride All + +EOF +else + cat <> ${_new_vhost_config_file} + + DocumentRoot $_doc_root + + AllowOverride All + Require all granted + +EOF +fi # if [ "$_type" = "FCGID" ]; then + +if [ -n "$_custom_ipv4_log" ]; then + cat <> ${_new_vhost_config_file} + + CustomLog $_custom_ipv4_log base_requests +EOF +fi +cat <> ${_new_vhost_config_file} + + CustomLog $_combined_custom_log combined + ErrorLog $_error_log + + +EOF + +if [ "$?" != "0" ]; then + _failed=true +fi + +if $_https ; then + + cat <> ${_new_vhost_config_file} + + + + ServerAdmin $server_admin + + ServerName $_server_name +EOF + if [ "$?" != "0" ]; then + _failed=true + fi + for _alias in "${_server_aliases_arr[@]}" ; do + cat <> ${_new_vhost_config_file} + ServerAlias $_alias +EOF + if [ "$?" != "0" ]; then + _failed=true + fi + done + + if $_suEXEC ; then + cat <> ${_new_vhost_config_file} + + SuexecUserGroup $suEXEC_user $suEXEC_group +EOF + fi + + if [ "$_type" = "FCGID" ]; then + cat <> ${_new_vhost_config_file} + + DocumentRoot $_doc_root + + + Require all granted + AllowOverride All + FCGIWrapper $FCGI_Wrapper + + SetHandler fcgid-script + + Options +ExecCGI + +EOF + elif [ "$_type" = "PHP-FPM" ]; then + cat <> ${_new_vhost_config_file} + + #ProxyErrorOverride On + + + SetHandler $_set_handler_fpm + + + + DirectoryIndex index.php index.html index.htm + + + DocumentRoot $_doc_root + + Require all granted + AllowOverride All + +EOF + else + cat <> ${_new_vhost_config_file} + + DocumentRoot $_doc_root + + AllowOverride All + Require all granted + +EOF + fi # if [ "$_type" = "FCGID" ] + + cat <> ${_new_vhost_config_file} + + SSLEngine on + + SSLCertificateFile $_ssl_cert_file + SSLCertificateKeyFile $_ssl_key_file +EOF + if [ -n "$_ssl_chain_file" ]; then + cat <> ${_new_vhost_config_file} + SSLCertificateChainFile $_ssl_chain_file +EOF + fi + + if [ -n "$_custom_ipv4_log" ]; then + cat <> ${_new_vhost_config_file} + + CustomLog $_custom_ipv4_log base_requests +EOF + fi + cat <> ${_new_vhost_config_file} + + CustomLog $_combined_custom_log combined + ErrorLog $_error_log + + +EOF + + if [ "$?" != "0" ]; then + _failed=true + fi + +fi + +if [ "$_ipv6" != "disabled" ]; then + + cat <> ${_new_vhost_config_file} + + +# --- +# --- IPv6 +# --- + + + + ServerAdmin $server_admin + + ServerName $_server_name +EOF + if [ "$?" != "0" ]; then + _failed=true + fi + for _alias in "${_server_aliases_arr[@]}" ; do + cat <> ${_new_vhost_config_file} + ServerAlias $_alias +EOF + if [ "$?" != "0" ]; then + _failed=true + fi + done + + if $_suEXEC ; then + cat <> ${_new_vhost_config_file} + + SuexecUserGroup $suEXEC_user $suEXEC_group +EOF + fi + +if [ "$_type" = "FCGID" ]; then + cat <> ${_new_vhost_config_file} + + DocumentRoot $_doc_root + + + Require all granted + AllowOverride All + FCGIWrapper $FCGI_Wrapper + + SetHandler fcgid-script + + Options +ExecCGI + +EOF + elif [ "$_type" = "PHP-FPM" ]; then + cat <> ${_new_vhost_config_file} + + #ProxyErrorOverride On + + + SetHandler $_set_handler_fpm + + + + DirectoryIndex index.php index.html index.htm + + + DocumentRoot $_doc_root + + Require all granted + AllowOverride All + +EOF + else + cat <> ${_new_vhost_config_file} + + DocumentRoot $_doc_root + + AllowOverride All + Require all granted + +EOF + fi # if [ "$_type" = "FCGID" ]; then + + if [ -n "$_custom_ipv6_log" ]; then + cat <> ${_new_vhost_config_file} + + CustomLog $_custom_ipv6_log base_requests +EOF + fi + cat <> ${_new_vhost_config_file} + + CustomLog $_combined_custom_log combined + ErrorLog $_error_log + + +EOF + + if [ "$?" != "0" ]; then + _failed=true + fi + + if $_https ; then + + cat <> ${_new_vhost_config_file} + + + + ServerAdmin $server_admin + + ServerName $_server_name +EOF + if [ "$?" != "0" ]; then + _failed=true + fi + for _alias in "${_server_aliases_arr[@]}" ; do + cat <> $_new_vhost_config_file + ServerAlias $_alias +EOF + if [ "$?" != "0" ]; then + _failed=true + fi + done + + if $_suEXEC ; then + cat <> ${_new_vhost_config_file} + + SuexecUserGroup $suEXEC_user $suEXEC_group +EOF + fi + + if [ "$_type" = "FCGID" ]; then + cat <> ${_new_vhost_config_file} + + DocumentRoot $_doc_root + + + Require all granted + AllowOverride All + FCGIWrapper $FCGI_Wrapper + + SetHandler fcgid-script + + Options +ExecCGI + +EOF + elif [ "$_type" = "PHP-FPM" ]; then + cat <> ${_new_vhost_config_file} + + #ProxyErrorOverride On + + + SetHandler $_set_handler_fpm + + + + DirectoryIndex index.php index.html index.htm + + + DocumentRoot $_doc_root + + Require all granted + AllowOverride All + +EOF + else + cat <> ${_new_vhost_config_file} + + DocumentRoot $_doc_root + + AllowOverride All + Require all granted + +EOF + fi # if [ "$_type" = "FCGID" ] + + cat <> ${_new_vhost_config_file} + + SSLEngine on + + SSLCertificateFile $_ssl_cert_file + SSLCertificateKeyFile $_ssl_key_file +EOF + if [ -n "$_ssl_chain_file" ]; then + cat <> ${_new_vhost_config_file} + SSLCertificateChainFile $_ssl_chain_file +EOF + fi + + if [ -n "$_custom_ipv6_log" ]; then + cat <> ${_new_vhost_config_file} + + CustomLog $_custom_ipv6_log base_requests +EOF + fi + cat <> ${_new_vhost_config_file} + + CustomLog $_combined_custom_log combined + ErrorLog $_error_log + + +EOF + + if [ "$?" != "0" ]; then + _failed=true + fi + + fi # if $_https ; then + +fi # if [ "$_ipv6" != "disabled" ]; then + +if ! $_failed ; then + echo_ok +else + echo_failed + error "Kann fcgid Konfiguration für site \"$site_url\" nicht erstellen!" + fatal +fi + + +_vhost_file_basename="`basename $_new_vhost_config_file`" +_vhost_file_prefix="${_vhost_file_basename%.*}" + +if [ -h "${_vhost_base_dir}/$_vhost_file_prefix" ]; then + echononl "\tDelete existing symlink \"${_vhost_base_dir}/$_vhost_file_prefix\".." + rm ${_vhost_base_dir}/$_vhost_file_prefix + if [ "$?" = "0" ];then + echo_ok + else + echo_failed + error "Cannot delete symlink \"${_vhost_base_dir}/$_vhost_file_prefix\"" + fatal + fi +elif [ -f "${_vhost_base_dir}/$_vhost_file_prefix" ]; then + echononl "\tMove existing file \"$_vhost_file_prefix\" to \"${_vhost_file_prefix}.mod_php\"" + mv ${_vhost_base_dir}/$_vhost_file_prefix ${_vhost_base_dir}/${_vhost_file_prefix}.mod_php + if [ "$?" = "0" ];then + echo_ok + else + echo_failed + error "Cannot move file \"${_vhost_base_dir}/$_vhost_file_prefix\"" + fatal + fi +fi + + +echononl "\tSet symlink \"$_vhost_file_prefix --> $_vhost_file_basename" +ln -s $_vhost_file_basename ${_vhost_base_dir}/$_vhost_file_prefix +if [ "$?" = "0" ];then + echo_ok +else + echo_failed + error "Setting symlink \"${_vhost_base_dir}/$_vhost_file_prefix -> $_vhost_file_basename\" failed." + fatal +fi + + +echononl "\tCreate initial \"index.html\" file.." +if [ ! -f "${_doc_root}/index.html" -a ! -r "${_doc_root}/index.php" -a ! -f "${_doc_root}/index.htm" ]; then + cat < ${_doc_root}/index.html + + + +Maintenance / Wartungsarbeiten + + + + + + +
+ + + +
+

${_server_name}

+ +

Seite im Aufbau

+

Diese Website wird in Kürze online gehen..

+

Bitte versuchen Sie es später noch einmal.

+

Vielen Dank für Ihr Verständnis!

+ +

Site under construction

+

This website will go online soon.

+

Please try again later.

+

Thank You very much!

+ +
+
+ + + +EOF + if [ "$?" = "0" ];then + echo_ok + + echononl "\tChange ownerchip (${web_user}:${web_group}) of \"index.html\".." + chown ${web_user}:$web_group ${_doc_root}/index.html + if [ "$?" = "0" ];then + echo_ok + else + echo_failed + error "Cannot change ownerchip of file \"index.html\"" + fi + + else + echo_failed + error "Cannot create file \"index.html\"." + fi +else + echo_skipped +fi + +echononl "\tCreate \"phpinfo.php\" file.." +if $create_phpinfo_file ; then + if [ ! -f "${_doc_root}/phpinfo.php" ]; then + cat < ${_doc_root}/phpinfo.php + + + PHP Info + + + + + +EOF + if [ "$?" = "0" ];then + echo_ok + + echononl "\tChange ownerchip (${web_user}:${web_group}) of \"phpinfo.php\".." + chown ${web_user}:$web_group ${_doc_root}/phpinfo.php + if [ "$?" = "0" ];then + echo_ok + else + echo_failed + error "Cannot change ownerchip of file \"phpinfo.php\"." + fi + + else + echo_failed + error "Cannot create file \"phpinfo.php\"." + fi + else + echo_skipped + fi +else + echo_skipped +fi + +_syntax_ok=false +echo "" +echononl "\tCheck Apache Configuration.." +if [ "`apachectl configtest 2>&1`" = "Syntax OK" ]; then + echo_ok + _syntax_ok=true +else + echo_failed +fi + +if $_syntax_ok ; then + echononl "\tGraceful restart Apache Webserver.." + apachectl graceful 2> /dev/null + if [ "$?" = "0" ];then + echo_ok + else + echo_failed + error "Graceful restart of Apache Webserver failed!" + fi +fi + + +echo +echo +exit 0 diff --git a/max_memory_limit_apache.sh b/max_memory_limit_apache.sh new file mode 100755 index 0000000..a77f14c --- /dev/null +++ b/max_memory_limit_apache.sh @@ -0,0 +1,301 @@ +#!/usr/bin/env bash + +ps_output_tmp_file=/tmp/ps.out.$$ + +declare -i http_client_rss_usage_kb=0 +declare -i http_parent_rss_usage_kb=0 +declare -i http_process_max_usage_kb=0 + +declare -i http_server_prozesses=0 + + +## --- + +apache_version=`httpd -v | grep "version" | awk '{print$3}' | cut -d'/' -f2` +apache_major_version=`echo $apache_version | awk -F \. '{ printf "%d", $1; printf "." ; printf "%d", $2 }'` + + +## --- + +#uptime=`wget -q -O - http://127.0.0.1/server-status?auto | grep -i Uptime | awk '{print$2}'` +uptime=`lynx -dump http://127.0.0.1/server-status?auto | awk ' /Uptime/ {print$2}'` + +_now=`date +%s` +_timestamp_start=`expr $_now - $uptime` +starttime=`date -d \@$_timestamp_start +%c` + +days=`echo "scale=0 ; $uptime / 86400" | bc -l` +days_rest=`echo "scale=0 ; $uptime % 86400" | bc -l` +hours=`echo "scale=0 ; $days_rest / 3600" | bc -l` +hours_rest=`echo "scale=0 ; $days_rest % 3600" | bc -l` +minutes=`echo "scale=0 ; $hours_rest / 60" | bc -l` +seconds=`echo "scale=0 ; $hours_rest % 60" | bc -l` +uptime_string="$days days $hours hrs $minutes min $seconds sec" + + +## --- + +scoreborad=`wget -q -O - http://127.0.0.1/server-status?auto | grep -i Scoreboard | awk '{print$2}'` +_scoreborad_in_use=`echo -n "$scoreborad" | sed -e 's/[\.]//g'` +_scoreboard_busy=`echo -n "$_scoreborad_in_use" | sed -e 's/[_]//g'` +_scoreboard_idle=`echo -n "$_scoreborad_in_use" | sed -e 's/[^_]//g'` + +workers_in_use=`echo -n "$_scoreborad_in_use" | wc -m` +idle_workers=`echo -n "$_scoreboard_idle" | wc -m` +busy_workers=`echo -n "$_scoreboard_busy" | wc -m` + +#max_simultanous_connections=`echo -n "$scoreborad" | wc -m` + + +## --- + +mpm=`lynx -dump http://127.0.0.1/server-info?server | awk ' /MPM Name:/ {print tolower($3)}'` +server_root=`lynx -dump http://127.0.0.1/server-info?server | awk ' /Server Root:/ {print$3}'` +config_file=`lynx -dump http://127.0.0.1/server-info?server | awk ' /Config File:/ {print$3}'` +config_file_found=false + + +_default_2_2_prefork_server_limit=256 +_default_2_2_prefork_max_clients=150 +_default_2_2_prefork_max_requests_per_child=0 + +_default_2_2_worker_server_limit=16 +_default_2_2_worker_max_clients=150 +_default_2_2_worker_threads_per_child=25 +_default_2_2_worker_max_requests_per_child=0 + +_default_2_4_prefork_server_limit=250 +_default_2_4_prefork_max_request_workers=25 +_default_2_4_prefork_max_connections_per_child=0 + +_default_2_4_event_server_limit=16 +_default_2_4_event_threads_per_child=25 +_default_2_4_event_max_request_workers=400 +_default_2_4_event_max_connections_per_child=0 + +if grep -i -E "^\s*Include\s+conf/extra/httpd-mpm.conf" $config_file > /dev/null 2>&1 ; then + config_file_found=true + found=false + while read line ; do + if echo $line | grep -i "IfModule mpm_${mpm}_module" > /dev/null 2>&1 ; then + found=true + continue + fi + if $found ; then + if echo $line | grep -i "ServerLimit" > /dev/null 2>&1 ; then + server_limit=`echo $line | grep -i "ServerLimit" | awk '{print$2}'` + fi + if echo $line | grep -i "MaxClients" > /dev/null 2>&1 ; then + max_clients=`echo $line | grep -i "MaxClients" | awk '{print$2}'` + fi + if echo $line | grep -i "ThreadsPerChild" > /dev/null 2>&1 ; then + threads_per_child=`echo $line | grep -i "ThreadsPerChild" | awk '{print$2}'` + fi + if echo $line | grep -i "MaxRequestWorkers" > /dev/null 2>&1 ; then + max_request_workers=`echo $line | grep -i "MaxRequestWorkers" | awk '{print$2}'` + fi + if echo $line | grep -i "MaxConnectionsPerChild" > /dev/null 2>&1 ; then + max_connections_per_child=`echo $line | grep -i "MaxConnectionsPerChild" | awk '{print$2}'` + fi + if echo $line | grep -i "MaxRequestsPerChild" > /dev/null 2>&1 ; then + max_requests_per_child=`echo $line | grep -i "MaxRequestsPerChild" | awk '{print$2}'` + fi + if echo $line | grep -i " /dev/null 2>&1 ; then + break; + fi + fi + done < ${server_root}/conf/extra/httpd-mpm.conf +fi + +if [ "$apache_major_version" = "2.4" ]; then + if [ "$mpm" = "event" ];then + if [ -z "$server_limit" ]; then + server_limit=$_default_2_4_event_server_limit + fi + if [ -z "$threads_per_child" ]; then + threads_per_child=$_default_2_4_event_threads_per_child + fi + if [ -z "$max_request_workers" ]; then + max_request_workers=$_default_2_4_event_max_request_workers + fi + if [ -z "$max_connections_per_child" ]; then + max_connections_per_child=$_default_2_4_event_max_connections_per_child + fi + + max_processes=$server_limit + max_simultanous_connections=`expr $server_limit \* $threads_per_child` + + elif [ "$mpm" = "prefork" ];then + if [ -z "$server_limit" ]; then + server_limit=$_default_2_4_prefork_server_limit + fi + if [ -z "$max_request_workers" ]; then + max_request_workers=$_default_2_4_prefork_max_request_workers + fi + if [ -z "$max_connections_per_child" ]; then + max_connections_per_child=$_default_2_4_prefork_max_connections_per_child + fi + + max_processes=$max_request_workers + max_simultanous_connections=$max_request_workers + max_simultanous_connections_msg="Based on \"Max Request Workers\" NOT \"Server Limit" + + fi +elif [ "$apache_major_version" = "2.2" ]; then + if [ "$mpm" = "worker" ];then + if [ -z "$server_limit" ]; then + server_limit=$_default_2_2_worker_server_limit + fi + if [ -z "$threads_per_child" ]; then + threads_per_child=$_default_2_2_worker_threads_per_child + fi + if [ -z "$max_clients" ]; then + max_clients=$_default_2_2_worker_max_clients + fi + if [ -z "$max_requests_per_child" ]; then + max_requests_per_child=$_default_2_2_worker_max_requests_per_child + fi + + max_processes=$max_clients + max_simultanous_connections=$max_clients + max_simultanous_connections_msg="Based on \"Max Clients\" NOT \"Server Limit" + + elif [ "$mpm" = "prefork" ];then + if [ -z "$server_limit" ]; then + server_limit=$_default_2_2_prefork_server_limit + fi + if [ -z "$max_clients" ]; then + max_clients=$_default_2_2_prefork_max_clients + fi + if [ -z "$max_requests_per_child" ]; then + max_requests_per_child=$_default_2_2_prefork_max_requests_per_child + fi + + max_processes=$max_clients + max_simultanous_connections=$max_clients + max_simultanous_connections_msg="Based on \"Max Clients\" NOT \"Server Limit" + + fi +fi + + + +## --- + +ps --no-headers -ylC httpd | awk '{print$2" "$8}' > $ps_output_tmp_file + +while read _UID _RSS ; do + if [ "$_UID" = "0" ]; then + http_parent_rss_usage_kb=$_RSS + else + http_client_rss_usage_kb=`expr $http_client_rss_usage_kb + $_RSS` + let http_server_prozesses++ + if [ $_RSS -gt $http_process_max_usage_kb ]; then + http_process_max_usage_kb=$http_client_rss_usage_kb + fi + fi +done < $ps_output_tmp_file + +cur_memory_usage_kb=`echo "scale=0; $http_parent_rss_usage_kb + $http_client_rss_usage_kb" | bc -l` +cur_memory_usage_mb=`echo "scale=3; $cur_memory_usage_kb/1024" | bc -l` + +each_process_usage_kb=`echo "scale=3; $http_client_rss_usage_kb/$http_server_prozesses" | bc -l` +each_process_usage_mb=`echo "scale=3; $each_process_usage_kb/1024" | bc -l` + +http_process_max_usage_mb=`echo "scale=3; $http_process_max_usage_kb/1024" | bc -l` + + +declare -i _tmp_val=0 +max_memory_limit_avarage_mb=0 +max_memory_limit_avarage_mb=`echo "scale=3; $each_process_usage_mb * $max_processes" | bc -l` +max_memory_limit_avarage_gb_str="" +_tmp_val=`echo "scale=0; $max_memory_limit_avarage_mb / 1" | bc -l` +if [ $_tmp_val -gt 1023 ]; then + max_memory_limit_avarage_gb=`echo "scale=3; $max_memory_limit_avarage_mb/1024" | bc -l` + max_memory_limit_avarage_gb_str=" ($max_memory_limit_avarage_gb GB)" +fi +max_memory_limit_max_mb=0 +max_memory_limit_max_mb=`echo "scale=3; $http_process_max_usage_mb * $max_processes" | bc -l` +max_memory_limit_max_gb_str="" +_tmp_val=`echo "scale=0; $max_memory_limit_max_mb / 1" | bc -l` +if [ $_tmp_val -gt 1023 ]; then + max_memory_limit_max_gb=`echo "scale=3; $max_memory_limit_max_mb/1024" | bc -l` + max_memory_limit_max_gb_str=" ($max_memory_limit_max_gb GB)" +fi + +## --- + + +echo "" +echo "----- Current Status" +echo "" +echo -e "\tApache Server Version.............: $apache_version" +#echo -e "\tApache Major Version..............: $apache_major_version" +echo "" +echo -e "\tStart Time........................: $starttime" +echo -e "\tUptime............................: $uptime_string" +echo +echo -e "\tMulti-Processing Module (MPM).....: $mpm " +if [ -n "$server_root" ];then + echo "" + echo -e "\tServer Rooot Directory............: $server_root" +fi +if [ -n "config_file" ]; then + echo -e "\tConfig File.......................: $config_file" +fi +echo "" +echo -e "\tNumber Apache (Client) Prozesses..: $http_server_prozesses" +echo "" +echo -e "\tCurrent Memory Usage..............: $cur_memory_usage_mb MB" +echo -e "\tEach Process Usage (Avarage)......: $each_process_usage_mb MB" +echo "" +echo -e "\tWorkers in Use....................: $workers_in_use" +echo -e "\tBusy Workers......................: $busy_workers" +echo -e "\tIdle Workers......................: $idle_workers" +echo "" + +echo "" +if $config_file_found ; then + echo "----- MPM Configuration (read from included config file httpd-mpm.conf)" +else + echo "----- MPM Configuration (config file httpd-mpm.conf NOT included - assuming defaults)" +fi +echo "" +echo -e "\tMulti-Processing Module (MPM).....: $mpm " +echo "" +echo "" +echo -e "\tServer Limit (Processes)..........: $server_limit" +if [ -n "$max_clients" ]; then + echo -e "\tMax Clients.......................: $max_clients" +fi +if [ -n "$threads_per_child" ]; then + echo -e "\tThreads Per Child.................: $threads_per_child" +fi +if [ -n "$max_request_workers" ]; then + echo -e "\tMax Request Workers...............: $max_request_workers" +fi +if [ -n "$max_connections_per_child" ]; then + echo -e "\tMax Connections Per Child.........: $max_connections_per_child" +elif [ -n "$max_requests_per_child" ]; then + echo -e "\tMax Requests Per Child............: $max_requests_per_child" +fi +echo "" +echo -e "\tMax Simultanous Connectons........: $max_simultanous_connections" +if [ -n "$max_simultanous_connections_msg" ];then + echo -e "\t $max_simultanous_connections_msg" +fi +echo "" + +echo "" +echo "----- Memory Limit (estimated values!!)" +echo "" +echo -e "\tMax Memory (based on avarage usage)..: $max_memory_limit_avarage_mb MB$max_memory_limit_avarage_gb_str" +echo "" +echo -e "\tMax Memory (bades on max usage)......: $max_memory_limit_max_mb MB$max_memory_limit_max_gb_str" +echo "" +echo "" + + +rm -f $ps_output_tmp_file + +exit 0