forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-add-sys-ip
More file actions
executable file
·140 lines (120 loc) · 4.17 KB
/
v-add-sys-ip
File metadata and controls
executable file
·140 lines (120 loc) · 4.17 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
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
# info: add system ip address
# options: IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]
#
# The function adds ip address into a system. It also creates rc scripts. You
# can specify ip name which will be used as root domain for temporary aliases.
# For example, if you set a1.myhosting.com as name, each new domain created on
# this ip will automaticaly receive alias $domain.a1.myhosting.com. Of course
# you must have wildcard record *.a1.myhosting.com pointed to ip. This feature
# is very handy when customer wants to test domain before dns migration.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
ip=${1// /}
mask=$2
interface="${3-eth0}"
user="${4-admin}"
ip_status="${5-shared}" # status can be dedicated
ip_name=$6
nat_ip=$7
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/ip.sh
source $VESTA/func/domain.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]'
validate_format 'ip' 'mask' 'interface' 'user' 'ip_status'
is_ip_free
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
if [ ! -z "$ip_name" ] ; then
validate_format 'ip_name'
fi
if [ ! -z "$nat_ip" ] ; then
validate_format 'nat_ip'
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
get_ip_iface
sys_ip_check=$(/sbin/ifconfig | grep "addr:$ip ")
if [ -z "$sys_ip_check" ]; then
/sbin/ifconfig "$iface" "$ip" netmask "$mask"
# Adding startup script
sys_ip="# Added by vesta"
sys_ip="$sys_ip\nDEVICE=$iface"
sys_ip="$sys_ip\nBOOTPROTO=static"
sys_ip="$sys_ip\nONBOOT=yes"
sys_ip="$sys_ip\nIPADDR=$ip"
sys_ip="$sys_ip\nNETMASK=$mask"
echo -e $sys_ip > /etc/sysconfig/network-scripts/ifcfg-$iface
fi
# Adding vesta ip
echo "OWNER='$user'
STATUS='$ip_status'
NAME='$ip_name'
U_SYS_USERS=''
U_WEB_DOMAINS='0'
INTERFACE='$interface'
NETMASK='$mask'
NAT='$nat_ip'
TIME='$TIME'
DATE='$DATE'" > $VESTA/data/ips/$ip
chmod 660 $VESTA/data/ips/$ip
# WEB support
web_conf="/etc/$WEB_SYSTEM/conf.d/vesta.conf"
if [ "$WEB_SYSTEM" = 'httpd' ]; then
conf_ins='1'
conf_line=$(grep -n NameVirtual $web_conf | tail -n1 | cut -f1 -d:)
if [ ! -z "$conf_line" ]; then
conf_ins=$((conf_line + 1))
fi
if [ "$WEB_SSL" = 'mod_ssl' ]; then
sed -i "$conf_ins i NameVirtualHost $ip:$WEB_SSL_PORT" $web_conf
sed -i "$conf_ins i Listen $ip:$WEB_SSL_PORT" $web_conf
fi
sed -i "$conf_ins i NameVirtualHost $ip:$WEB_PORT" $web_conf
sed -i "$conf_ins i Listen $ip:$WEB_PORT" $web_conf
fi
# Proxy support
if [ ! -z "$PROXY_SYSTEM" ]; then
cat $WEBTPL/$PROXY_SYSTEM/proxy_ip.tpl |\
sed -e "s/%ip%/$ip/g" \
-e "s/%web_port%/$WEB_PORT/g" \
-e "s/%proxy_port%/$PROXY_PORT/g" \
> /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 ' $fw_conf | grep -v '#' | head -n1)
sed -i "s/$ips/$ips $ip/g" $fw_conf
fi
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating user counters
increase_user_value "$user" '$IP_OWNED'
if [ "$user" = 'admin' ]; then
if [ "$ip_status" = 'shared' ]; then
for user in $(ls $VESTA/data/users); do
increase_user_value "$user" '$IP_AVAIL'
done
else
increase_user_value 'admin' '$IP_AVAIL'
fi
else
increase_user_value "$user" '$IP_AVAIL'
increase_user_value 'admin' '$IP_AVAIL'
fi
# Restart web server
$BIN/v-restart-web
$BIN/v-restart-proxy
# Logging
log_history "added system ip address $ip" '' 'admin'
log_event "$OK" "$EVENT"
exit