setup-ip.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. hestia_module_web_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. web_conf="/etc/$WEB_SYSTEM/conf.d/$ip.conf"
  9. hestia_safe_rm $web_conf
  10. if [ "$WEB_SYSTEM" = 'httpd' ] || [ "$WEB_SYSTEM" = 'apache2' ]; then
  11. if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
  12. # FIXME: this will break with Apache > 2.4
  13. echo "NameVirtualHost $ip:$WEB_PORT" > $web_conf
  14. fi
  15. echo "Listen $ip:$WEB_PORT" >> $web_conf
  16. cat $HESTIA_INSTALL_DIR/$WEB_SYSTEM/unassigned.conf >> $web_conf
  17. sed -i 's/directIP/'$ip'/g' $web_conf
  18. sed -i 's/directPORT/'$WEB_PORT'/g' $web_conf
  19. elif [ "$WEB_SYSTEM" = 'nginx' ]; then
  20. cp -f $HESTIA_INSTALL_DIR/nginx/unassigned.inc $web_conf
  21. sed -i 's/directIP/'$ip'/g' $web_conf
  22. fi
  23. if [ "$WEB_SSL" = 'mod_ssl' ]; then
  24. if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
  25. # FIXME: this will break with Apache > 2.4
  26. sed -i "1s/^/NameVirtualHost $ip:$WEB_SSL_PORT\n/" $web_conf
  27. fi
  28. sed -i "1s/^/Listen $ip:$WEB_SSL_PORT\n/" $web_conf
  29. sed -i 's/directSSLPORT/'$WEB_SSL_PORT'/g' $web_conf
  30. fi
  31. fi
  32. # Proxy support
  33. if [ ! -z "$PROXY_SYSTEM" ]; then
  34. cat $WEBTPL/$PROXY_SYSTEM/proxy_ip.tpl |\
  35. sed -e "s/%ip%/$ip/g" \
  36. -e "s/%web_port%/$WEB_PORT/g" \
  37. -e "s/%proxy_port%/$PROXY_PORT/g" \
  38. > /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  39. # mod_extract_forwarded
  40. fw_conf="$OSAL_PATH_APACHE_CONF_D/mod_extract_forwarded.conf"
  41. if [ -e "$fw_conf" ]; then
  42. ips=$(grep 'MEFaccept ' $fw_conf | grep -v '#' | head -n1)
  43. sed -i "s/$ips/$ips $ip/g" $fw_conf
  44. fi
  45. # mod_rpaf
  46. rpaf_conf="$OSAL_PATH_APACHE_MODS_ENABLED/rpaf.conf"
  47. if [ -e "$rpaf_conf" ]; then
  48. rpaf_str=$(grep RPAFproxy_ips $rpaf_conf)
  49. [ -z "$rpaf_str" ] && sed -i 's|</IfModule>|RPAFproxy_ips\n</IfModule>|' $rpaf_conf && rpaf_str='RPAFproxy_ips'
  50. rpaf_str="$rpaf_str $ip"
  51. sed -i "s/.*RPAFproxy_ips.*/$rpaf_str/" $rpaf_conf
  52. fi
  53. #mod_remoteip
  54. remoteip_conf="$OSAL_PATH_APACHE_MODS_ENABLED/remoteip.conf"
  55. if [ -e "$remoteip_conf" ]; then
  56. if [ $( grep -ic "$ip" $remoteip_conf ) -eq 0 ]; then
  57. sed -i "s/<\/IfModule>/RemoteIPInternalProxy $ip\n<\/IfModule>/g" $remoteip_conf
  58. fi
  59. fi
  60. fi
  61. }