mirror of
https://github.com/serghey-rodin/vesta.git
synced 2026-02-09 16:07:04 +01:00
109 lines
2.9 KiB
Bash
Executable File
109 lines
2.9 KiB
Bash
Executable File
#!/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/conf/vesta.conf
|
|
source $VESTA/func/main.sh
|
|
source $VESTA/func/ip.sh
|
|
source $VESTA/func/domain.sh
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# 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
|
|
rm -f /etc/sysconfig/network-scripts/ifcfg-$interface
|
|
fi
|
|
|
|
# Deleting vesta ip
|
|
rm -f $VESTA/data/ips/$ip
|
|
|
|
# Disable virtual ip hosting support
|
|
web_conf="/etc/$WEB_SYSTEM/conf.d/vesta.conf"
|
|
if [ ! -z "$WEB_SYSTEM" ]; then
|
|
sed -i "/NameVirtualHost $ip:/d" $web_conf
|
|
sed -i "/Listen $ip:/d" $web_conf
|
|
fi
|
|
|
|
# Deleting proxy config
|
|
if [ ! -z "$PROXY_SYSTEM" ]; then
|
|
rm -f /etc/$PROXY_SYSTEM/conf.d/$ip.conf
|
|
|
|
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 -e "s/$ip//" )
|
|
sed -i "s/$ips/$new_ips/g" $fw_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
|
|
$BIN/v-restart-proxy
|
|
|
|
# Logging
|
|
log_history "deleted system ip address $ip"
|
|
log_event "$OK" "$EVENT"
|
|
|
|
exit
|