setup-ip.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. hestia_package_web-server_setup-ip() {
  3. source $HESTIA/bin/module/func.inc
  4. ip=$1
  5. echo "Configuring web for IP address $ip"
  6. # Web support
  7. if [ ! -z "$WEB_SYSTEM" ]; then
  8. echo " Creating web server ($WEB_SYSTEM) IP config for $ip:$WEB_PORT"
  9. web_conf="/etc/$WEB_SYSTEM/conf.d/$ip.conf"
  10. hestia_safe_rm $web_conf
  11. if [ "$WEB_SYSTEM" = 'httpd' ] || [ "$WEB_SYSTEM" = 'apache2' ]; then
  12. echo "# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS" > $web_conf
  13. if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
  14. # FIXME: this will break with Apache > 2.4
  15. echo "NameVirtualHost $ip:$WEB_PORT" >> $web_conf
  16. fi
  17. echo "Listen $ip:$WEB_PORT" >> $web_conf
  18. cat $HESTIA_INSTALL_DIR/$WEB_SYSTEM/unassigned.conf >> $web_conf
  19. sed -i 's/directIP/'$ip'/g' $web_conf
  20. sed -i 's/directPORT/'$WEB_PORT'/g' $web_conf
  21. elif [ "$WEB_SYSTEM" = 'nginx' ]; then
  22. cp -f $HESTIA_INSTALL_DIR/nginx/unassigned.inc $web_conf
  23. sed -i 's/directIP/'$ip'/g' $web_conf
  24. fi
  25. if [ "$WEB_SSL" = 'mod_ssl' ]; then
  26. if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
  27. # FIXME: this will break with Apache > 2.4
  28. sed -i "1s/^/NameVirtualHost $ip:$WEB_SSL_PORT\n/" $web_conf
  29. fi
  30. sed -i "1s/^/Listen $ip:$WEB_SSL_PORT\n/" $web_conf
  31. sed -i 's/directSSLPORT/'$WEB_SSL_PORT'/g' $web_conf
  32. fi
  33. fi
  34. # Proxy support
  35. if [ ! -z "$PROXY_SYSTEM" ]; then
  36. echo " Creating proxy ($PROXY_SYSTEM) IP config for $ip:$PROXY_PORT"
  37. cat $WEBTPL/$PROXY_SYSTEM/proxy_ip.tpl |\
  38. sed -e "s/%ip%/$ip/g" \
  39. -e "s/%web_port%/$WEB_PORT/g" \
  40. -e "s/%proxy_port%/$PROXY_PORT/g" \
  41. -e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
  42. > /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  43. # mod_extract_forwarded
  44. fw_conf="$OSAL_PATH_APACHE_CONF_D/mod_extract_forwarded.conf"
  45. if [ -e "$fw_conf" ]; then
  46. ips=$(grep 'MEFaccept ' $fw_conf | grep -v '#' | head -n1)
  47. sed -i "s/$ips/$ips $ip/g" $fw_conf
  48. fi
  49. # mod_rpaf
  50. rpaf_conf="$OSAL_PATH_APACHE_MODS_ENABLED/rpaf.conf"
  51. if [ -e "$rpaf_conf" ]; then
  52. rpaf_str=$(grep RPAFproxy_ips $rpaf_conf)
  53. [ -z "$rpaf_str" ] && sed -i 's|</IfModule>|RPAFproxy_ips\n</IfModule>|' $rpaf_conf && rpaf_str='RPAFproxy_ips'
  54. rpaf_str="$rpaf_str $ip"
  55. sed -i "s/.*RPAFproxy_ips.*/$rpaf_str/" $rpaf_conf
  56. fi
  57. #mod_remoteip
  58. remoteip_conf="$OSAL_PATH_APACHE_MODS_ENABLED/remoteip.conf"
  59. if [ -e "$remoteip_conf" ]; then
  60. if [ $( grep -ic "$ip" $remoteip_conf ) -eq 0 ]; then
  61. sed -i "s/<\/IfModule>/RemoteIPInternalProxy $ip\n<\/IfModule>/g" $remoteip_conf
  62. fi
  63. fi
  64. fi
  65. }