| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- #!/bin/bash
- # info: delete system ip
- # options: IP
- #
- # example: v-delete-sys-ip 212.42.76.210
- #
- # This 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.
- #----------------------------------------------------------#
- # Variables & Functions #
- #----------------------------------------------------------#
- # Argument definition
- ip=$1
- # Includes
- # shellcheck source=/etc/hestiacp/hestia.conf
- source /etc/hestiacp/hestia.conf
- # shellcheck source=/usr/local/hestia/func/main.sh
- source $HESTIA/func/main.sh
- # shellcheck source=/usr/local/hestia/func/ip.sh
- source $HESTIA/func/ip.sh
- # shellcheck source=/usr/local/hestia/func/domain.sh
- source $HESTIA/func/domain.sh
- # load config file
- source_conf "$HESTIA/conf/hestia.conf"
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- check_args '1' "$#" 'IP'
- is_format_valid 'ip'
- is_ip_valid "$ip"
- is_ip_key_empty '$U_WEB_DOMAINS'
- is_ip_key_empty '$U_SYS_USERS'
- # Perform verification if read-only mode is enabled
- check_hestia_demo_mode
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Import ip variables
- source $HESTIA/data/ips/$ip
- cidr=$(convert_netmask "$NETMASK")
- main_ip=$(hostname -i)
- # Checking main ip on the interface
- interface=$(/sbin/ip addr | grep "$ip$cidr" | awk '{print $NF}')
- if [ -n "$interface" ] && [ "$ip" = "$main_ip" ]; then
- echo "Error: can't delete main IP address"
- log_event "$E_FORBIDEN" "$ARGUMENTS"
- exit "$E_FORBIDEN"
- fi
- # Deleting system ip
- if [ -n "$interface" ]; then
- /sbin/ip addr del "$ip$cidr" dev "$INTERFACE"
- if [ "$?" -ne 0 ]; then
- echo "Error: can't delete system ip"
- log_event "$E_FORBIDEN" "$ARGUMENTS"
- exit $E_FORBIDEN
- fi
- fi
- # 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 [ -f "/etc/netplan/60-hestia.yaml" ]; then
- sed -i "/$ip/d" /etc/netplan/60-hestia.yaml
- if ! grep -q '-' /etc/netplan/60-hestia.yaml; then
- rm /etc/netplan/60-hestia.yaml
- fi
- elif [ -e "/etc/network/interfaces" ]; then
- ip_str=$(grep -n $ip$ /etc/network/interfaces | cut -f1 -d:)
- if [ -n "$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
- # Deleting hestia ip
- rm -f $HESTIA/data/ips/$ip
- # Deleting web config
- if [ -n "$WEB_SYSTEM" ]; then
- rm -f /etc/$WEB_SYSTEM/conf.d/$ip.conf
- fi
- # Deleting proxy config
- if [ -n "$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 "$ips" | sed "s/ $ip//")
- sed -i "s/$ips/$new_ips/g" "$rpaf_conf"
- # Remove RPAFproxy_ips line when ip list is empty
- [ "$(grep RPAFproxy_ips $rpaf_conf | sed 's/^[[:space:]]*//g')" = "RPAFproxy_ips" ] && sed -i "/RPAFproxy_ips/d" $rpaf_conf
- fi
- #mod_remoteip
- remoteip_conf="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
- if [ -e "$remoteip_conf" ]; then
- sed -i "/RemoteIPInternalProxy $ip\$/d" "$remoteip_conf"
- fi
- fi
- #----------------------------------------------------------#
- # Hestia #
- #----------------------------------------------------------#
- # Updating user conf
- if [ -n "$OWNER" ]; then
- decrease_user_value "$OWNER" '$IP_OWNED'
- fi
- if [ "$OWNER" = 'admin' ]; then
- if [ "$STATUS" = 'shared' ]; then
- for hestia_user in $($BIN/v-list-sys-users plain); do
- decrease_user_value "$hestia_user" '$IP_AVAIL'
- done
- else
- decrease_user_value "$OWNER" '$IP_AVAIL'
- fi
- else
- decrease_user_value "$OWNER" '$IP_AVAIL'
- fi
- # Restarting web server
- $BIN/v-restart-web
- check_result $? "Web restart failed" > /dev/null
- # Restarting proxy server
- if [ -n "$PROXY_SYSTEM" ]; then
- $BIN/v-restart-proxy
- check_result $? "Proxy restart failed" > /dev/null
- fi
- # Restarting firewall
- if [ -n "$FIREWALL_SYSTEM" ]; then
- $BIN/v-update-firewall
- fi
- # Logging
- $BIN/v-log-action "system" "Info" "System" "IP address deleted (IP: $ip)."
- log_event "$OK" "$ARGUMENTS"
- exit
|