setup-ips.inc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. hestia_module_web_setup-ips() {
  3. source $HESTIA/bin/module/func.inc
  4. if [ "$OS_BASE" = 'debian' ]; then
  5. remoteip_conf=$OSAL_PATH_APACHE_MODS_AVAILABLE/remoteip.conf
  6. else
  7. remoteip_conf=$OSAL_PATH_APACHE_CONF_D/remoteip.conf
  8. fi
  9. # Get main IP
  10. local_ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  11. pub_ip=$(curl --ipv4 -s https://ip.hestiacp.com/)
  12. echo "Configuring web IP addresses (local: $local_ip, public: $pub_ip)"
  13. # FIXME: the following line should be: if WEB_SYSTEM is apache and PROXY_SYSTEM is something (i.e. not [ null or 'no' ])
  14. if ( [ "$WEB_SYSTEM" = 'apache2' ] || [ "$WEB_SYSTEM" = 'httpd' ] ) && [ "$PROXY_SYSTEM" = 'nginx' ]; then
  15. echo "Configuring remoteip apache module"
  16. # If we are using web server and proxy server, configure mod_remoteip
  17. echo "<IfModule mod_remoteip.c>" > $remoteip_conf
  18. echo " RemoteIPHeader X-Real-IP" >> $remoteip_conf
  19. if [ "$local_ip" != "127.0.0.1" ] && [ "$pub_ip" != "127.0.0.1" ]; then
  20. echo " RemoteIPInternalProxy 127.0.0.1" >> $remoteip_conf
  21. fi
  22. if [ ! -z "$local_ip" ] && [ "$local_ip" != "$pub_ip" ]; then
  23. echo " RemoteIPInternalProxy $local_ip" >> $remoteip_conf
  24. fi
  25. if [ ! -z "$pub_ip" ]; then
  26. echo " RemoteIPInternalProxy $pub_ip" >> $remoteip_conf
  27. fi
  28. echo "</IfModule>" >> $remoteip_conf
  29. sed -i "s/LogFormat \"%h/LogFormat \"%a/g" $OSAL_PATH_APACHE_CONF/${OSAL_PKG_APACHE}.conf
  30. else
  31. # Unconfigure remoteip
  32. [ -f $remoteip_conf ] && rm $remoteip_conf
  33. sed -i "s/LogFormat \"%a/LogFormat \"%h/g" $OSAL_PATH_APACHE_CONF/${OSAL_PKG_APACHE}.conf
  34. fi
  35. if [ "$OS_BASE" = 'debian' ]; then
  36. osal_apache_module_enable remoteip
  37. fi
  38. for ip_conf in $HESTIA/data/ips/*; do
  39. ip=$(basename $ip_conf)
  40. hestia module web setup-ip "$ip"
  41. done
  42. }