| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #!/bin/bash
- # info: delete system ip
- # options: IP
- #
- # The function for deleting a system ip. It does not allow to delete first ip
- # on interface and do not allow to delete ip which is used by a web domain.
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument defenition
- ip=$1
- # Includes
- source $VESTA/func/main.sh
- source $VESTA/func/ip.sh
- source $VESTA/func/domain.sh
- source $VESTA/conf/vesta.conf
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- check_args '1' "$#" 'IP'
- validate_format 'ip'
- is_ip_valid "$ip"
- is_ip_key_empty '$U_WEB_DOMAINS'
- is_ip_key_empty '$U_SYS_USERS'
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Get ip owner
- user="$(get_ip_value '$OWNER')"
- ip_status="$(get_ip_value '$STATUS')"
- # Deleting interface
- interface=$(/sbin/ifconfig | grep -B1 "dr:$ip " | head -n1 | cut -f1 -d \ )
- if [ ! -z "$interface" ] && [ -z "$(echo $interface |cut -s -f2 -d :)" ]; then
- echo "Error: can't delete main IP address"
- log_event "$E_FORBIDEN" "$EVENT"
- exit $E_FORBIDEN
- fi
- if [ ! -z "$interface" ]; then
- /sbin/ifconfig $interface down
- # Deleting startup conf on RHEL/CentOS/Fedora
- if [ -e "/etc/sysconfig/network-scripts/ifcfg-$interface" ]; then
- rm -f /etc/sysconfig/network-scripts/ifcfg-$interface
- fi
- # Deleting startup conf on Debian/Ubuntu
- if [ -e "/etc/network/interfaces" ]; then
- ip_str=$(grep -n $ip$ /etc/network/interfaces |cut -f1 -d:)
- if [ ! -z "$ip_str" ]; then
- first_str=$((ip_str - 3))
- last_str=$((ip_str + 1))
- sed -i "$first_str,$last_str d" /etc/network/interfaces
- fi
- fi
- fi
- # Deleting vesta ip
- rm -f $VESTA/data/ips/$ip
- # Deleting web config
- if [ ! -z "$WEB_SYSTEM" ]; then
- rm -f /etc/$WEB_SYSTEM/conf.d/$ip.conf
- fi
- # Deleting proxy config
- if [ ! -z "$PROXY_SYSTEM" ]; then
- rm -f /etc/$PROXY_SYSTEM/conf.d/$ip.conf
- # mod_extract_forwarded
- fw_conf="/etc/$WEB_SYSTEM/conf.d/mod_extract_forwarded.conf"
- if [ -e "$fw_conf" ]; then
- ips=$(grep 'MEFaccept 127.0.0.1' $fw_conf)
- new_ips=$(echo "$ips" | sed "s/$ip//" )
- sed -i "s/$ips/$new_ips/g" $fw_conf
- fi
- # mod_rpaf
- rpaf_conf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
- if [ -e "$rpaf_conf" ]; then
- ips=$(grep RPAFproxy_ips $rpaf_conf)
- new_ips=$(echo "$rpaf_str" | sed "s/$ip//")
- sed -i "s/$ips/$new_ips/g" $rpaf_conf
- fi
- fi
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- # Updating user conf
- if [ ! -z "$user" ]; then
- decrease_user_value "$user" '$IP_OWNED'
- fi
- if [ "$user" = 'admin' ]; then
- if [ "$ip_status" = 'shared' ]; then
- for user in $(ls $VESTA/data/users/); do
- decrease_user_value "$user" '$IP_AVAIL'
- done
- else
- decrease_user_value 'admin' '$IP_AVAIL'
- fi
- else
- decrease_user_value "$user" '$IP_AVAIL'
- decrease_user_value 'admin' '$IP_AVAIL'
- fi
- # Adding task to the vesta pipe
- $BIN/v-restart-web
- if [ $? -ne 0 ]; then
- exit E_RESTART
- fi
- $BIN/v-restart-proxy
- if [ $? -ne 0 ]; then
- exit E_RESTART
- fi
- # Logging
- log_history "deleted system ip address $ip"
- log_event "$OK" "$EVENT"
- exit
|