Skip to content

Commit f197bc8

Browse files
committed
fix for userlist
1 parent 095a9f1 commit f197bc8

File tree

4 files changed

+54
-55
lines changed

4 files changed

+54
-55
lines changed

bin/v-backup-users

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $BIN/v-check-vesta-license >/dev/null
2727
if [ -z "$BACKUP_SYSTEM" ]; then
2828
exit
2929
fi
30-
for user in $(ls $VESTA/data/users); do
30+
for user in $(grep '@' /etc/passwd |cut -f1 -d:); do
3131
check_suspend=$(grep "SUSPENDED='no'" $VESTA/data/users/$user/user.conf)
3232
log=$VESTA/log/backup.log
3333
if [ ! -z "$check_suspend" ]; then

bin/v-check-letsencrypt-domain

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ encode_base64() {
2929
#----------------------------------------------------------#
3030

3131
check_args '2' "$#" 'USER DOMAIN'
32-
is_format_valid 'user' 'domain'
32+
validate_format 'user' 'domain'
3333
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
3434
is_object_valid 'user' 'USER' "$user"
3535
is_object_unsuspended 'user' 'USER' "$user"
3636
if [ ! -e "$USER_DATA/ssl/le.conf" ]; then
3737
check_result $E_NOTEXIST "LetsEncrypt key doesn't exist"
3838
fi
39-
check_domain=$(grep -w "$domain'" $USER_DATA/web.conf)
39+
check_domain=$(grep -w "$domain" $USER_DATA/web.conf)
4040
if [ -z "$check_domain" ]; then
4141
check_result $E_NOTEXIST "domain $domain doesn't exist"
4242
fi
@@ -48,7 +48,7 @@ fi
4848

4949
source $USER_DATA/ssl/le.conf
5050
api='https://acme-v01.api.letsencrypt.org'
51-
r_domain=$(echo "$check_domain" |cut -f 2 -d \')
51+
r_domain=$(echo "$check_domain" |cut -f 2 -d \'|tail -n1)
5252
key="$USER_DATA/ssl/user.key"
5353
exponent="$EXPONENT"
5454
modulus="$MODULUS"
@@ -77,16 +77,15 @@ answer=$(curl -s -i -d "$data" "$api/acme/new-authz")
7777
# Checking http answer status
7878
status=$(echo "$answer" |grep HTTP/1.1 |tail -n1 |cut -f2 -d ' ')
7979
if [[ "$status" -ne "201" ]]; then
80+
echo -e "$(date) $domain $status\n$answer\n$(dig @8.8.8.8 $domain +short)" >> /tmp/le-log.txt
8081
check_result $E_CONNECT "LetsEncrypt challenge request $status"
8182
fi
8283

8384
# Parsing domain nonce,token and uri
8485
nonce=$(echo "$answer" |grep Nonce |cut -f2 -d \ |tr -d '\r\n')
8586
protected=$(echo -n '{"nonce":"'"$nonce"'"}' |encode_base64)
86-
token=$(echo "$answer" |tr ',' '\n' |grep -A 3 http-01 |grep token)
87-
token=$(echo "$token" |cut -f 4 -d \")
88-
uri=$(echo "$answer" |tr ',' '\n' |grep -A 3 http-01 |grep uri)
89-
uri=$(echo "$uri" |cut -f 4 -d \")
87+
token=$(echo "$answer" |grep -A 3 http-01 |grep token |cut -f 4 -d \")
88+
uri=$(echo "$answer" |grep -A 3 http-01 |grep uri |cut -f 4 -d \")
9089

9190
# Adding location wrapper for request challenge
9291
if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
@@ -96,20 +95,26 @@ if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
9695
echo ' default_type text/plain;' >> $conf
9796
echo ' return 200 "$1.'$thumb'";' >> $conf
9897
echo '}' >> $conf
99-
if [ ! -z "$PROXY_SYSTEM" ]; then
100-
$BIN/v-restart-proxy
101-
check_result $? "Proxy restart failed" >/dev/null
102-
else
103-
$BIN/v-restart-web
104-
check_result $? "Web restart failed" >/dev/null
105-
fi
10698
fi
99+
echo $conf
107100
else
108101
acme="$HOMEDIR/$user/web/$r_domain/public_html/.well-known/acme-challenge"
109102
echo "$token" > $acme/$token.$thumb
110103
chown -R $user:$user $HOMEDIR/$user/web/$r_domain/public_html/.well-known
111104
fi
112105

106+
# Restarting web server
107+
if [ -z "$PROXY_SYSTEM" ]; then
108+
$BIN/v-restart-web
109+
check_result $? "Proxy restart failed" >/dev/null
110+
else
111+
$BIN/v-restart-proxy
112+
$BIN/v-restart-web
113+
check_result $? "Web restart failed" >/dev/null
114+
fi
115+
116+
sleep 30
117+
113118
# Defining ACME query (request validation)
114119
query='{"resource":"challenge","type":"http-01","keyAuthorization"'
115120
query=$query':"'$token.$thumb'","token":"'$token'"}'
@@ -123,7 +128,7 @@ data=$data'"payload":"'"$payload"'","signature":"'"$signature"'"}'
123128
answer=$(curl -s -i -d "$data" "$uri")
124129

125130
# Checking domain validation status
126-
status=$(echo $answer |tr ',' '\n' |grep status |cut -f 4 -d \")
131+
status=$(echo $answer |grep status |cut -f 4 -d \")
127132
location=$(echo "$answer" |grep Location: |awk '{print $2}' |tr -d '\r\n')
128133
while [ "$status" = 'pending' ] ; do
129134
answer=$(curl -s -i "$location")
@@ -140,6 +145,6 @@ fi
140145
#----------------------------------------------------------#
141146

142147
# Logging
143-
log_event "$OK" "$ARGUMENTS"
148+
log_event "$OK" "$EVENT"
144149

145150
exit

bin/v-list-letsencrypt-user

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,33 @@ format=${2-shell}
1616
# Includes
1717
source $VESTA/func/main.sh
1818

19-
# JSON list function
20-
json_list() {
21-
echo '{'
22-
echo ' "'$user'": {
23-
"EMAIL": "'$EMAIL'",
24-
"EXPONENT": "'$EXPONENT'",
25-
"MODULUS": "'$MODULUS'",
26-
"THUMB: "'$THUMB'"
27-
}'
28-
echo '}'
19+
# Json function
20+
json_list_conf() {
21+
lines=$(wc -l $USER_DATA/ssl/le.conf | cut -f 1 -d ' ')
22+
i='0'
23+
IFS=$'\n'
24+
echo -e "{\n\t\"LETSENCRYPT\": {"
25+
for str in $(cat $USER_DATA/ssl/le.conf); do
26+
(( ++i))
27+
key=${str%%=*}
28+
value=${str#*=}
29+
if [ "$i" -lt "$lines" ]; then
30+
echo -e "\t\t\"$key\": \"${value//\'/}\","
31+
else
32+
echo -e "\t\t\"$key\": \"${value//\'/}\""
33+
fi
34+
done
35+
echo -e "\t}\n}"
2936
}
3037

31-
# SHELL list function
32-
shell_list() {
33-
echo "USER: $user"
34-
echo "EMAIL: $EMAIL"
35-
echo "THUMB: $THUMB"
36-
echo "EXPONENT: $EXPONENT"
37-
echo "MODULUS: $MODULUS"
38-
}
39-
40-
# PLAIN list function
41-
plain_list() {
42-
echo -e "$user\t$EMAIL\t$EXPONENT\t$MODULUS\t$THUMB"
43-
}
44-
45-
# CSV list function
46-
csv_list() {
47-
echo "USER,EMAIL,EXPONENT,MODULUS,THUMB"
48-
echo "$user,$EMAIL,$EXPONENT,$MODULUS,$THUMB"
38+
# Shell function
39+
shell_list_conf() {
40+
IFS=$'\n'
41+
for str in $(cat $USER_DATA/ssl/le.conf); do
42+
key=${str%%=*}
43+
value=${str#*=}
44+
echo "$key: ${value//\'/}"
45+
done
4946
}
5047

5148

@@ -56,22 +53,19 @@ csv_list() {
5653
check_args '1' "$#" 'USER [FORMAT]'
5754
is_object_valid 'user' 'USER' "$user"
5855
if [ ! -e "$USER_DATA/ssl/le.conf" ]; then
59-
check_result $E_NOTEXIST "LetsEncrypt user account doesn't exist"
56+
check_result $E_NOTEXIST "LetsEncrypt user account doesn't exist"
6057
fi
6158

6259

6360
#----------------------------------------------------------#
6461
# Action #
6562
#----------------------------------------------------------#
6663

67-
source $USER_DATA/ssl/le.conf
68-
69-
# Listing data
70-
case $format in
71-
json) json_list ;;
72-
plain) plain_list ;;
73-
csv) csv_list ;;
74-
shell) shell_list ;;
64+
# Listing system config
65+
case $format in
66+
json) json_list_conf ;;
67+
plain) shell_list_conf ;;
68+
shell) shell_list_conf | column -t ;;
7569
esac
7670

7771

bin/v-update-user-stats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fi
3939

4040
# Creating user_list
4141
if [ -z "$user" ]; then
42-
user_list=$(ls $VESTA/data/users)
42+
user_list=$(grep '@' /etc/passwd |cut -f1 -d:)
4343
else
4444
user_list="$user"
4545
fi

0 commit comments

Comments
 (0)