Skip to content

Commit 5d30b67

Browse files
committed
refactoring: log_event(), is_format_valid()
1 parent d4f30b5 commit 5d30b67

File tree

6 files changed

+344
-92
lines changed

6 files changed

+344
-92
lines changed

func/db.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mysql_connect() {
3030
if [ '0' -ne "$?" ]; then
3131
if [ "$notify" != 'no' ]; then
3232
echo -e "Can't connect to MySQL $HOST\n$(cat $err)" |\
33-
$send_mail -s "$subj" $email
33+
$SENDMAIL -s "$subj" $email
3434
fi
3535
echo "Error: Connection to $HOST failed"
3636
log_event "$E_CONNECT" "$ARGUMENTS"
@@ -49,7 +49,7 @@ mysql_dump() {
4949
rm -rf $tmpdir
5050
if [ "$notify" != 'no' ]; then
5151
echo -e "Can't dump database $database\n$(cat $err)" |\
52-
$send_mail -s "$subj" $email
52+
$SENDMAIL -s "$subj" $email
5353
fi
5454
echo "Error: dump $database failed"
5555
log_event "$E_DB" "$ARGUMENTS"
@@ -72,7 +72,7 @@ psql_connect() {
7272
if [ '0' -ne "$?" ]; then
7373
if [ "$notify" != 'no' ]; then
7474
echo -e "Can't connect to PostgreSQL $HOST\n$(cat /tmp/e.psql)" |\
75-
$send_mail -s "$subj" $email
75+
$SENDMAIL -s "$subj" $email
7676
fi
7777
echo "Error: Connection to $HOST failed"
7878
log_event "$E_CONNECT" "$ARGUMENTS"
@@ -90,7 +90,7 @@ psql_dump() {
9090
rm -rf $tmpdir
9191
if [ "$notify" != 'no' ]; then
9292
echo -e "Can't dump database $database\n$(cat /tmp/e.psql)" |\
93-
$send_mail -s "$subj" $email
93+
$SENDMAIL -s "$subj" $email
9494
fi
9595
echo "Error: dump $database failed"
9696
log_event "$E_DB" "$ARGUMENTS"
@@ -243,8 +243,7 @@ is_dbhost_new() {
243243

244244
# Get database values
245245
get_database_values() {
246-
db_str=$(grep "DB='$database'" $USER_DATA/db.conf)
247-
eval $db_str
246+
eval $(grep "DB='$database'" $USER_DATA/db.conf)
248247
}
249248

250249
# Change MySQL database password

func/domain.sh

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,31 @@
55
# Web template check
66
is_web_template_valid() {
77
if [ ! -z "$WEB_SYSTEM" ]; then
8-
template=$1
9-
if [ -z "$template" ]; then
10-
template=$(grep WEB_TEMPLATE $USER_DATA/user.conf |cut -f2 -d \')
11-
if [ -z "$template" ]; then
12-
template="default"
13-
fi
14-
fi
15-
tpl="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.tpl"
16-
stpl="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.stpl"
8+
tpl="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$1.tpl"
9+
stpl="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$1.stpl"
1710
if [ ! -e "$tpl" ] || [ ! -e "$stpl" ]; then
18-
check_result $E_NOTEXIST "$template web template doesn't exist"
11+
check_result $E_NOTEXIST "$1 web template doesn't exist"
1912
fi
2013
fi
2114
}
2215

2316
# Proxy template check
2417
is_proxy_template_valid() {
2518
if [ ! -z "$PROXY_SYSTEM" ]; then
26-
proxy=$1
27-
if [ -z "$proxy" ]; then
28-
proxy=$(grep PROXY_TEMPLATE $USER_DATA/user.conf |cut -f2 -d \')
29-
if [ -z "$proxy" ]; then
30-
proxy="default"
31-
fi
32-
fi
33-
tpl="$WEBTPL/$PROXY_SYSTEM/$proxy.tpl"
34-
stpl="$WEBTPL/$PROXY_SYSTEM/$proxy.stpl"
19+
tpl="$WEBTPL/$PROXY_SYSTEM/$1.tpl"
20+
stpl="$WEBTPL/$PROXY_SYSTEM/$1.stpl"
3521
if [ ! -e "$tpl" ] || [ ! -e "$stpl" ]; then
36-
check_result $E_NOTEXIST "$proxy proxy template doesn't exist"
22+
check_result $E_NOTEXIST "$1 proxy template doesn't exist"
3723
fi
3824
fi
3925
}
4026

4127
# Backend template check
4228
is_backend_template_valid() {
43-
if [ ! -e "$WEBTPL/$WEB_BACKEND/$1.tpl" ]; then
44-
check_result $E_NOTEXIST "$backend backend template doesn't exist"
29+
if [ ! -z "$WEB_BACKEND" ]; then
30+
if [ ! -e "$WEBTPL/$WEB_BACKEND/$1.tpl" ]; then
31+
check_result $E_NOTEXIST "$1 backend template doesn't exist"
32+
fi
4533
fi
4634
}
4735

@@ -210,7 +198,7 @@ add_web_config() {
210198
-e "s|%proxy_ssl_port%|$PROXY_SSL_PORT|g" \
211199
-e "s/%proxy_extentions%/${PROXY_EXT//,/|}/g" \
212200
-e "s|%user%|$user|g" \
213-
-e "s|%group%|$group|g" \
201+
-e "s|%group%|$user|g" \
214202
-e "s|%home%|$HOMEDIR|g" \
215203
-e "s|%docroot%|$HOMEDIR/$user/web/$domain/public_html|g" \
216204
-e "s|%sdocroot%|$HOMEDIR/$user/web/$domain/public_html|g" \
@@ -225,7 +213,7 @@ add_web_config() {
225213
chmod 640 $conf
226214

227215
if [ -z "$(grep "$conf" /etc/$1/conf.d/vesta.conf)" ]; then
228-
if [ "$WEB_SYSTEM" != 'nginx' ]; then
216+
if [ "$1" != 'nginx' ]; then
229217
echo "Include $conf" >> /etc/$1/conf.d/vesta.conf
230218
else
231219
echo "include $conf;" >> /etc/$1/conf.d/vesta.conf
@@ -265,6 +253,10 @@ get_web_config_lines() {
265253

266254
# Replace web config
267255
replace_web_config() {
256+
conf="$HOMEDIR/$user/conf/web/$1.conf"
257+
if [[ "$2" =~ stpl$ ]]; then
258+
conf="$HOMEDIR/$user/conf/web/s$1.conf"
259+
fi
268260
get_web_config_lines $WEBTPL/$1/$WEB_BACKEND/$2 $conf
269261
sed -i "$top_line,$bottom_line s|$old|$new|g" $conf
270262
}
@@ -355,9 +347,8 @@ is_web_domain_cert_valid() {
355347

356348
# DNS template check
357349
is_dns_template_valid() {
358-
t="$DNSTPL/$template.tpl"
359-
if [ ! -e $t ]; then
360-
check_result $E_NOTEXIST "dns template $template doesn't exist"
350+
if [ ! -e "$DNSTPL/$1.tpl" ]; then
351+
check_result $E_NOTEXIST "$1 dns template doesn't exist"
361352
fi
362353
}
363354

func/ip.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ is_ip_key_empty() {
3333
eval $string
3434
eval value="$key"
3535
if [ ! -z "$value" ] && [ "$value" != '0' ]; then
36-
check_result $E_EXISTS "$key is not empty = $value"
36+
key="$(echo $key|sed -e "s/\$U_//")"
37+
check_result $E_EXISTS "IP is in use / $key = $value"
3738
fi
3839
}
3940

@@ -133,7 +134,6 @@ get_ip_value() {
133134
}
134135

135136

136-
137137
# Get real ip address
138138
get_real_ip() {
139139
if [ -e "$VESTA/data/ips/$1" ]; then
@@ -142,8 +142,6 @@ get_real_ip() {
142142
nat=$(grep -H "^NAT='$1'" $VESTA/data/ips/*)
143143
if [ ! -z "$nat" ]; then
144144
echo "$nat" |cut -f 1 -d : |cut -f 7 -d /
145-
else
146-
get_user_ip
147145
fi
148146
fi
149147
}
@@ -222,17 +220,22 @@ get_user_ip() {
222220

223221
# Validate ip address
224222
is_ip_valid() {
225-
if [ ! -z $1 ]; then
226-
if [ -e "$VESTA/data/ips/$1" ]; then
227-
ip_data=$(cat $VESTA/data/ips/$1)
228-
local_ip="$1"
223+
local_ip="$1"
224+
if [ ! -e "$VESTA/data/ips/$1" ]; then
225+
nat=$(grep -H "^NAT='$1'" $VESTA/data/ips/*)
226+
if [ -z "$nat" ]; then
227+
check_result $E_NOTEXIST "IP $1 doesn't exist"
229228
else
230-
nat=$(grep -H "^NAT='$1'" $VESTA/data/ips/*)
231-
check_result $? "IP $1 doesn't exist" $E_NOTEXIST
232229
nat=$(echo "$nat" |cut -f1 -d: |cut -f7 -d/)
233-
ip_data=$(cat $VESTA/data/ips/$nat)
234230
local_ip=$nat
235231
fi
232+
fi
233+
if [ ! -z $2 ]; then
234+
if [ -z "$nat" ]; then
235+
ip_data=$(cat $VESTA/data/ips/$1)
236+
else
237+
ip_data=$(cat $VESTA/data/ips/$nat)
238+
fi
236239
ip_owner=$(echo "$ip_data" |grep OWNER= |cut -f2 -d \')
237240
ip_status=$(echo "$ip_data" |grep STATUS= |cut -f2 -d \')
238241
if [ "$ip_owner" != "$user" ] && [ "$ip_status" = 'dedicated' ]; then
@@ -242,7 +245,5 @@ is_ip_valid() {
242245
if [ "$ip_owner" != "$user" ] && [ "$ip_owner" != "$owner" ]; then
243246
check_result $E_FORBIDEN "$user user can't use IP $1"
244247
fi
245-
else
246-
get_user_ip
247248
fi
248249
}

0 commit comments

Comments
 (0)