forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-delete-sys-ip
More file actions
executable file
·108 lines (85 loc) · 2.87 KB
/
v-delete-sys-ip
File metadata and controls
executable file
·108 lines (85 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/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