/
v-list-web-domain-errorlog
executable file
·95 lines (80 loc) · 2.11 KB
/
v-list-web-domain-errorlog
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
#!/bin/bash
# info: list web domain error log
# options: USER DOMAIN [LINES] [FORMAT]
#
# example: v-list-web-domain-errorlog admin acme.com
#
# This function of obtaining raw error web domain logs.
#----------------------------------------------------------#
# Variables & Functions #
#----------------------------------------------------------#
# Argument definition
user=$1
domain=$2
ttl=${3-70}
format=${4-shell}
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"
# JSON list function
json_list() {
i=1
objects=$(echo "$lines" | wc -l)
echo '['
for str in $lines; do
str=$(echo "$str" | sed -e 's/"/\\"/g')
if [ "$i" -lt "$objects" ]; then
echo -e "\t\"$str\","
else
echo -e "\t\"$str\""
fi
((++i))
done
echo "]"
}
# SHELL list function
shell_list() {
echo "$lines"
}
# PLAIN list function
plain_list() {
echo "$lines"
}
# CSV list function
csv_list() {
echo "LOG"
echo "$lines"
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [LINES] [FORMAT]'
is_format_valid 'user' 'domain' 'ttl'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Check number of output lines
if [ "$ttl" -gt '3000' ]; then
read_cmd="cat"
else
read_cmd="tail -n $ttl"
fi
lines=$($read_cmd /var/log/$WEB_SYSTEM/domains/$domain.error.log)
IFS=$'\n'
# Listing data
case $format in
json) json_list ;;
plain) plain_list ;;
csv) csv_list ;;
shell) shell_list ;;
esac
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
exit