Skip to content

Commit be70e67

Browse files
committed
Added list function for ssl certificates
1 parent 86eba5d commit be70e67

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

bin/v_list_web_domain_ssl

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
# info: listing web ssl certificate
3+
4+
#----------------------------------------------------------#
5+
# Variable&Function #
6+
#----------------------------------------------------------#
7+
8+
# Argument defenition
9+
user=$1
10+
domain=$2
11+
format=${3-shell}
12+
13+
# Importing variables
14+
source $VESTA/conf/vars.conf
15+
source $V_FUNC/shared.func
16+
source $V_FUNC/domain.func
17+
18+
# Json function
19+
json_list_ssl() {
20+
i='1' # iterator
21+
echo '{'
22+
echo -e "\t\"$domain\": {"
23+
echo " \"CRT\": \"$crt\","
24+
echo " \"KEY\": \"$key\","
25+
echo " \"CA\": \"$ca\""
26+
echo -e "\t}\n}"
27+
}
28+
29+
# Shell function
30+
shell_list_ssl() {
31+
if [ ! -z "$crt" ]; then
32+
echo -e "$crt"
33+
fi
34+
if [ ! -z "$key" ]; then
35+
echo -e "\n$key"
36+
37+
fi
38+
if [ ! -z "$ca" ]; then
39+
echo -e "\n$ca"
40+
fi
41+
}
42+
43+
44+
#----------------------------------------------------------#
45+
# Verifications #
46+
#----------------------------------------------------------#
47+
48+
# Checking args
49+
check_args '2' "$#" 'user domain [format]'
50+
51+
# Checking user
52+
is_user_valid
53+
54+
# Checking domain exist
55+
is_web_domain_valid
56+
57+
58+
#----------------------------------------------------------#
59+
# Action #
60+
#----------------------------------------------------------#
61+
if [ -e "$V_USERS/$user/ssl/$domain.crt" ]; then
62+
crt=$(cat $V_USERS/$user/ssl/$domain.crt |sed -e ':a;N;$!ba;s/\n/\\n/g' )
63+
fi
64+
65+
if [ -e "$V_USERS/$user/ssl/$domain.key" ]; then
66+
key=$(cat $V_USERS/$user/ssl/$domain.key |sed -e ':a;N;$!ba;s/\n/\\n/g' )
67+
fi
68+
69+
if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
70+
ca=$(cat $V_USERS/$user/ssl/$domain.ca |sed -e ':a;N;$!ba;s/\n/\\n/g' )
71+
fi
72+
73+
# Listing domains
74+
case $format in
75+
json) json_list_ssl ;;
76+
plain) nohead=1; shell_list_ssl ;;
77+
shell) shell_list_ssl ;;
78+
*) check_args '1' '0' '[format]'
79+
esac
80+
81+
82+
#----------------------------------------------------------#
83+
# Vesta #
84+
#----------------------------------------------------------#
85+
86+
exit

0 commit comments

Comments
 (0)