| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #!/bin/bash
- # info: update system ip
- # options: [NONE]
- #
- # The function scans configured ip in the system and register them with hestia
- # internal database. This call is intended for use on vps servers, where ip is
- # set by hypervizor.
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Importing system variables
- source /etc/profile
- # Includes
- source $HESTIA/func/main.sh
- source $HESTIA/func/ip.sh
- source $HESTIA/conf/hestia.conf
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Listing system ip addresses
- ips=$(/sbin/ip addr |grep 'inet ' |grep global |awk '{print $2}' |cut -f1 -d/)
- v_ips=$(ls $HESTIA/data/ips/)
- ip_num=$(echo "$ips" |wc -l)
- v_ip_num=$(echo "$v_ips" |wc -l)
- # Checking primary IP change
- if [[ "$ip_num" -eq '1' ]] && [[ "$v_ip_num" -eq 1 ]]; then
- if [ "$ips" != "$v_ips" ]; then
- new=$ips
- old=$v_ips
- fi
- fi
- # Updating configs
- if [ ! -z "$new" ]; then
- mv $HESTIA/data/ips/$old $HESTIA/data/ips/$new
- # Updating PROXY
- if [ ! -z "$PROXY_SYSTEM" ]; then
- cd /etc/$PROXY_SYSTEM/conf.d
- if [ -e "$old.conf" ]; then
- mv $old.conf $new.conf
- sed -i "s/$old/$new/g" $new.conf
- fi
- fi
- # Updating WEB
- if [ ! -z "$WEB_SYSTEM" ]; then
- cd /etc/$WEB_SYSTEM/conf.d
- if [ -e "$old.conf" ]; then
- mv $old.conf $new.conf
- sed -i "s/$old/$new/g" $new.conf
- fi
- sed -i "s/$old/$new/g" $HESTIA/data/users/*/web.conf
- for user in $(ls $HESTIA/data/users/); do
- $BIN/v-rebuild-web-domains $user no
- done
- $BIN/v-restart-proxy
- $BIN/v-restart-web
- fi
- # Updating DNS
- if [ ! -z "$DNS_SYSTEM" ]; then
- sed -i "s/$old/$new/g" $HESTIA/data/users/*/dns.conf
- sed -i "s/$old/$new/g" $HESTIA/data/users/*/dns/*.conf
- for user in $(ls $HESTIA/data/users/); do
- $BIN/v-rebuild-dns-domains $user no
- done
- $BIN/v-restart-dns
- fi
- # Updating FTP
- if [ ! -z "$FTP_SYSTEM" ] && [ "$FTP_SYSTEM" = 'vsftpd' ]; then
- conf=$(find /etc/ -maxdepth 2 -name $FTP_SYSTEM.conf)
- if [ ! -z "$conf" ]; then
- sed -i "s/$old/$new/g" $conf
- $BIN/v-restart-ftp
- fi
- fi
- # Updating firewall
- if [ ! -z "$FIREWALL_SYSTEM" ]; then
- sed -i "s/$old/$new/g" $HESTIA/data/firewall/*.conf
- $BIN/v-update-firewall
- fi
- fi
- # Adding system IP
- for ip in $ips; do
- check_ifconfig=$(/sbin/ifconfig |grep "$ip")
- if [ ! -e "$HESTIA/data/ips/$ip" ] && [ ! -z "$check_ifconfig" ]; then
- interface=$(/sbin/ip addr |grep $ip |awk '{print $NF}' |uniq)
- interface=$(echo "$interface" |cut -f 1 -d : |head -n 1)
- netmask=$(/sbin/ip addr |grep $ip |cut -f 2 -d / |cut -f 1 -d \ )
- netmask=$(convert_cidr $netmask)
- $BIN/v-add-sys-ip $ip $netmask $interface
- fi
- done
- # Updating NAT
- pub_ip=$(curl -s https://www.hestiacp.com/what-is-my-ip/)
- if [ ! -e "$HESTIA/data/ips/$pub_ip" ]; then
- if [ -z "$(grep -R "$pub_ip" $HESTIA/data/ips/)" ]; then
- ip=$(ls -t $HESTIA/data/ips/ |head -n1)
- $BIN/v-change-sys-ip-nat $ip $pub_ip
- fi
- fi
- #----------------------------------------------------------#
- # Hestia #
- #----------------------------------------------------------#
- exit
|