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
·130 lines (103 loc) · 3.52 KB
/
Copy pathv-delete-sys-ip
File metadata and controls
executable file
·130 lines (103 loc) · 3.52 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/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
# 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 -e "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 -e "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
$BIN/v-restart-proxy
# Logging
log_history "deleted system ip address $ip"
log_event "$OK" "$EVENT"
exit